Skip to content

Commit a72a726

Browse files
committed
refactor: update API documentation to reflect changes in cryptographic methods, error handling, and introduce endpoint health check functionality
1 parent 8288952 commit a72a726

8 files changed

Lines changed: 1088 additions & 104 deletions

File tree

‎API.md‎

Lines changed: 85 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ sequenceDiagram
2828
SDK->>SDK: Solve PoW puzzle (12-1024KB)
2929
3030
SDK->>API: HTTP request with PoW signature
31-
Note over SDK,API: AES-GCM encrypted<br/>Ed25519 signed<br/>Anonymized data
31+
Note over SDK,API: AES-GCM encrypted<br/>AES-CBC signed<br/>Anonymized data
3232
3333
API->>API: Validate PoW & license
3434
API->>API: Process request
@@ -44,16 +44,16 @@ sequenceDiagram
4444

4545
- **PoW System**: Memory-hard challenges (12-1024KB, 800-4000 AES iterations) with dynamic parameters for FPGA resistance
4646
- **Data Anonymization**: Comprehensive PII/secrets masking before AI troubleshooting transmission
47-
- **Cryptographic Validation**: Ed25519 signatures with SHA-512 hashing ensure data integrity
47+
- **Cryptographic Validation**: Ed25519 + SHA-512 signatures validate **package downloads**; AES-GCM authentication tags protect every request/response chunk
4848
- **Type Safety**: 24 strongly-typed call patterns with built-in Go model validation
49-
- **Streaming Architecture**: Memory-efficient processing with AES-GCM chunk encryption
49+
- **Streaming Architecture**: Memory-efficient processing with AES-GCM chunk encryption (16KB default)
5050

5151
## Authentication & Security
5252

5353
All API endpoints require:
5454
- **PoW Challenge**: Memory-hard proof-of-work with more than 206M parameter combinations
5555
- **License Validation**: Cryptographic license verification with tier-based access control
56-
- **End-to-End Encryption**: AES-GCM streaming encryption with 1KB chunks
56+
- **End-to-End Encryption**: AES-128-GCM streaming encryption with 16KB chunks
5757
- **Forward Secrecy**: Daily server key rotation with deterministic derivation
5858
- **Data Anonymization**: Mandatory PII/secrets masking for all AI troubleshooting requests
5959

@@ -95,16 +95,17 @@ Before using any API endpoints, ensure you understand and comply with all applic
9595
2. **Function Generation**: SDK creates typed functions for each endpoint
9696
3. **Data Anonymization**: Mandatory PII/secrets masking for support services
9797
4. **PoW Challenge**: Automatic challenge solving before each request
98-
5. **Request Signing**: Ed25519 signature generation with installation ID
99-
6. **Encryption**: AES-GCM encryption of request/response bodies
100-
7. **Type Validation**: Go models ensure data integrity throughout
98+
5. **Request Signing**: AES-CBC signature (nonce + timestamp + content length + CRC32) with installation ID XOR-masking
99+
6. **Key Exchange**: NaCL box (Curve25519) encrypts the ephemeral session key to the server
100+
7. **Encryption**: AES-128-GCM streaming encryption of request/response bodies (16KB chunks)
101+
8. **Type Validation**: Go models ensure data integrity throughout
101102

102103
### Core Components
103104

104105
- **Call Patterns**: 24 function types handle different request/response scenarios
105106
- **Data Anonymizer**: Mandatory PII/secrets masking engine with 300+ pattern recognition
106107
- **Transport Layer**: HTTP/2 with connection pooling and custom TLS configuration
107-
- **Cryptographic Engine**: Ed25519 + AES-GCM for signatures and encryption
108+
- **Cryptographic Engine**: NaCL box (Curve25519) for session-key exchange + AES-128-GCM for body encryption + AES-128-CBC for PoW request signatures; Ed25519 + SHA-512 used only for package-integrity validation (`models/signature.go`)
108109
- **PoW Solver**: Memory-hard algorithm implementation with configurable timeout
109110
- **License Manager**: Cryptographic license validation and tier enforcement
110111

@@ -228,29 +229,49 @@ type TicketSettings struct {
228229

229230
## Error Handling
230231

231-
All endpoints return structured error responses:
232+
All endpoints return structured error responses. The SDK parses them into typed Go errors:
232233

233234
```json
234235
{
235236
"status": "error",
236-
"code": "RATE_LIMIT_EXCEEDED",
237-
"message": "Request rate limit exceeded",
238-
"details": {
239-
"current_usage": "exceeded",
240-
"limit": "tier_based",
241-
"reset_time": "2025-09-17T15:30:00Z"
242-
}
237+
"code": "TooManyRequestsRPM"
243238
}
244239
```
245240

246-
Common error codes:
247-
- `INVALID_LICENSE`: License validation failed
248-
- `POW_REQUIRED`: Proof-of-work challenge not solved
249-
- `RATE_LIMIT_EXCEEDED`: Request rate limit exceeded
250-
- `INSUFFICIENT_TIER`: Feature requires higher access tier
251-
- `INVALID_REQUEST`: Malformed request data
241+
### Error Codes
242+
243+
| Server Code | SDK Error | Retry | Notes |
244+
|-------------|-----------|-------|-------|
245+
| `BadGateway` | `sdk.ErrBadGateway` | Yes (3s) | Temporary backend overload |
246+
| `Internal` | `sdk.ErrServerInternal` | Yes (3s) | Temporary server error |
247+
| `BadRequest` | `sdk.ErrBadRequest` | No | Invalid request format |
248+
| `Forbidden` | `sdk.ErrForbidden` | No | Invalid license or authentication |
249+
| `NotFound` | `sdk.ErrNotFound` | No | Unknown endpoint |
250+
| `TooManyRequests` | `*sdk.RateLimitError` (General) | Yes (5s) | General rate limit |
251+
| `TooManyRequestsRPM` | `*sdk.RateLimitError` (RPM) | Yes (Retry-After, max 10s) | Per-minute window |
252+
| `TooManyRequestsRPH` | `*sdk.RateLimitError` (RPH) | No | Per-hour window — too long to auto-retry |
253+
| `TooManyRequestsRPD` | `*sdk.RateLimitError` (RPD) | No | Per-day window — too long to auto-retry |
254+
| `QuotaBlocked` | `*sdk.QuotaError` (Blocked) | Never | Endpoint unavailable for this license tier |
255+
| `QuotaExceededDaily` | `*sdk.QuotaError` (Daily) | No (Retry-After) | Daily quota exhausted |
256+
| `QuotaExceededMonthly` | `*sdk.QuotaError` (Monthly) | No (Retry-After) | Monthly quota exhausted |
257+
258+
### Retry-After Header
259+
260+
Rate-limit and quota responses carry a `Retry-After: <seconds>` header. The SDK embeds it in
261+
`*RateLimitError.RetryAfter` and `*QuotaError.RetryAfter`. Use `sdk.RetryAfterOf(err)` to read it
262+
from any error without type-asserting:
252263

253-
## SDK Integration
264+
```go
265+
if wait := sdk.RetryAfterOf(err); wait > 0 {
266+
time.Sleep(wait) // server-suggested cooldown
267+
}
268+
```
269+
270+
`*RateLimitError` wraps temporary rate-limit sentinels (General/RPM are auto-retried by the SDK;
271+
RPH/RPD are surfaced to the caller). `*QuotaError` wraps license-tier quota sentinels — all quota
272+
errors are fatal and never auto-retried.
273+
274+
### SDK Integration
254275

255276
Use the VXControl Cloud SDK for seamless integration with the platform:
256277

@@ -293,6 +314,29 @@ err := sdk.Build(configs,
293314
)
294315
```
295316

317+
### Endpoint Health Check
318+
319+
Use `sdk.Check()` to probe endpoint reachability and inspect allowed RPM **without making an actual API call**. Useful at startup or in health-check routines:
320+
321+
```go
322+
statuses, err := sdk.Check(ctx, configs,
323+
sdk.WithClient("MySecTool", "1.0.0"),
324+
sdk.WithLicenseKey("XXXX-XXXX-XXXX-XXXX"),
325+
)
326+
if err != nil {
327+
log.Fatal("SDK setup failed:", err)
328+
}
329+
330+
for name, s := range statuses {
331+
log.Printf("[%s] reachable=%v allowedRPM=%d err=%v",
332+
name, s.IsReachable(), s.AllowedRPM(), s.LastError())
333+
}
334+
335+
// Re-probe later (e.g. after a rate-limit cooldown)
336+
_ = statuses["check-updates"].Recheck(ctx)
337+
```
338+
```
339+
296340
### Working Examples
297341
298342
Production-ready examples are available in the [examples/](examples/) directory:
@@ -404,14 +448,23 @@ The platform uses a dynamic reverse proxy for unified API management:
404448

405449
### Request Headers
406450

407-
All API requests include these headers:
451+
Ticket request (`GET /api/v1/ticket/:name`):
452+
```
453+
X-Installation-ID: <stable-machine-uuid>
454+
X-Request-ID: <random-uuid>
455+
X-Request-Key: <base64(clientPublicKey[32] + nonce[24] + encrypted(sessionKey+sessionIV+ts+len)[64])>
456+
X-License-Key: <base64-encrypted-license> (optional)
457+
User-Agent: MyApp/1.0.0 sdk/1.0.0
458+
```
459+
460+
Main API request:
408461
```
409-
X-Client-Name: YourApp/1.0.0
410-
X-Installation-ID: stable-machine-uuid (from system.GetInstallationID())
411-
X-Request-ID: challenge-request-id
412-
X-Request-Sign: base64-encoded-pow-signature
413-
X-License-Key: encrypted-license-key (optional)
414-
Content-Type: application/json
462+
X-Installation-ID: <stable-machine-uuid>
463+
X-Request-ID: <pow-derived-request-uuid>
464+
X-Request-Sign: <base64-AES-CBC-signature[48]>
465+
X-License-Key: <base64-encrypted-license> (optional)
466+
User-Agent: MyApp/1.0.0 sdk/1.0.0
467+
Content-Type: application/json (when body is present)
415468
```
416469

417470
### Installation ID Generation
@@ -446,16 +499,11 @@ Successful responses return JSON data:
446499
}
447500
```
448501

449-
Error responses include structured details:
502+
Error responses contain only `status` and `code` (see [Error Handling](#error-handling) for all codes):
450503
```json
451504
{
452505
"status": "error",
453-
"code": "RATE_LIMIT_EXCEEDED",
454-
"message": "Request rate limit exceeded",
455-
"details": {
456-
"retry_after": "server_defined",
457-
"quota_reset": "2025-09-26T15:30:00Z"
458-
}
506+
"code": "TooManyRequestsRPM"
459507
}
460508
```
461509

0 commit comments

Comments
 (0)