@private.me/xbind 1.3.5 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSES.md +212 -0
- package/README.md +388 -6
- package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1 -1920
- package/dist-standalone/_deps/shared/cjs/errors.js +1 -639
- package/dist-standalone/_deps/shared/cjs/index.js +1 -496
- package/dist-standalone/_deps/shared/cjs/types.js +1 -317
- package/dist-standalone/_deps/shared/errors.js +1 -255
- package/dist-standalone/_deps/shared/index.js +1 -74
- package/dist-standalone/_deps/shared/types.js +1 -90
- package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/index.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/progress.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/search.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/types.js +1 -1
- package/dist-standalone/_deps/ux-helpers/errors.js +1 -1
- package/dist-standalone/_deps/ux-helpers/index.js +1 -1
- package/dist-standalone/_deps/ux-helpers/pagination.js +1 -1
- package/dist-standalone/_deps/ux-helpers/progress.js +1 -1
- package/dist-standalone/_deps/ux-helpers/search.js +1 -1
- package/dist-standalone/_deps/xchange/auto-accept.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/auto-accept.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/errors.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/index.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/invite-client.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/lazy-init.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/trust-integration.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/xchange.js +1 -1
- package/dist-standalone/_deps/xchange/errors.js +1 -1
- package/dist-standalone/_deps/xchange/index.js +1 -1
- package/dist-standalone/_deps/xchange/invite-client.js +1 -1
- package/dist-standalone/_deps/xchange/lazy-init.js +1 -1
- package/dist-standalone/_deps/xchange/trust-integration.js +1 -1
- package/dist-standalone/_deps/xchange/xchange.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/discovery.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/errors.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/index.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/registry.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/schema.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/types.js +1 -1
- package/dist-standalone/_deps/xregistry/discovery.js +1 -1
- package/dist-standalone/_deps/xregistry/errors.js +1 -1
- package/dist-standalone/_deps/xregistry/index.js +1 -1
- package/dist-standalone/_deps/xregistry/registry.js +1 -1
- package/dist-standalone/_deps/xregistry/schema.js +1 -1
- package/dist-standalone/_deps/xregistry/types.js +1 -1
- package/dist-standalone/agent-call.js +1 -642
- package/dist-standalone/agent-sdk.js +1 -328
- package/dist-standalone/agent.d.ts +95 -5
- package/dist-standalone/agent.js +1 -1545
- package/dist-standalone/approval.js +1 -193
- package/dist-standalone/async-iterators.d.ts +275 -0
- package/dist-standalone/async-iterators.js +1 -0
- package/dist-standalone/auth.js +1 -219
- package/dist-standalone/auto-accept.js +1 -229
- package/dist-standalone/backup-config.js +1 -201
- package/dist-standalone/backup.d.ts +114 -0
- package/dist-standalone/backup.js +1 -0
- package/dist-standalone/batch-operations.d.ts +297 -0
- package/dist-standalone/batch-operations.js +1 -0
- package/dist-standalone/cancellation.d.ts +301 -0
- package/dist-standalone/cancellation.js +1 -0
- package/dist-standalone/checkpoint.js +1 -186
- package/dist-standalone/circuit-breaker.d.ts +351 -0
- package/dist-standalone/circuit-breaker.js +1 -0
- package/dist-standalone/cjs/agent-call.js +1 -651
- package/dist-standalone/cjs/agent-sdk.js +1 -332
- package/dist-standalone/cjs/agent.js +1 -1582
- package/dist-standalone/cjs/approval.js +1 -199
- package/dist-standalone/cjs/async-iterators.js +1 -0
- package/dist-standalone/cjs/auth.js +1 -225
- package/dist-standalone/cjs/auto-accept.js +1 -233
- package/dist-standalone/cjs/backup-config.js +1 -207
- package/dist-standalone/cjs/backup.js +1 -0
- package/dist-standalone/cjs/batch-operations.js +1 -0
- package/dist-standalone/cjs/cancellation.js +1 -0
- package/dist-standalone/cjs/checkpoint.js +1 -193
- package/dist-standalone/cjs/circuit-breaker.js +1 -0
- package/dist-standalone/cjs/cli/init.js +1 -486
- package/dist-standalone/cjs/config-validation.js +1 -0
- package/dist-standalone/cjs/connect.js +1 -312
- package/dist-standalone/cjs/connection-pool.js +1 -0
- package/dist-standalone/cjs/correlation-id.js +1 -339
- package/dist-standalone/cjs/crypto-utils.js +1 -0
- package/dist-standalone/cjs/debug-mode.js +1 -0
- package/dist-standalone/cjs/did-document.js +1 -101
- package/dist-standalone/cjs/did-privateme.js +1 -130
- package/dist-standalone/cjs/did-web.js +1 -201
- package/dist-standalone/cjs/discovery.js +1 -462
- package/dist-standalone/cjs/dual-mode.js +1 -251
- package/dist-standalone/cjs/email-templates.js +1 -313
- package/dist-standalone/cjs/email-transport.js +1 -239
- package/dist-standalone/cjs/envelope.js +1 -510
- package/dist-standalone/cjs/errors.js +1 -826
- package/dist-standalone/cjs/event-emitter.js +1 -0
- package/dist-standalone/cjs/gateway-state.js +1 -55
- package/dist-standalone/cjs/gateway-transport.js +1 -120
- package/dist-standalone/cjs/graceful-degradation.js +1 -0
- package/dist-standalone/cjs/guardrails.js +1 -223
- package/dist-standalone/cjs/health-check.js +1 -0
- package/dist-standalone/cjs/http-compat.js +1 -272
- package/dist-standalone/cjs/http-status-map.js +1 -571
- package/dist-standalone/cjs/identity.js +1 -540
- package/dist-standalone/cjs/index.js +1 -237
- package/dist-standalone/cjs/invitation.js +1 -421
- package/dist-standalone/cjs/invite.js +1 -328
- package/dist-standalone/cjs/key-agreement.js +1 -246
- package/dist-standalone/cjs/lazy-init.js +1 -300
- package/dist-standalone/cjs/logger.js +1 -0
- package/dist-standalone/cjs/mdns-discovery.js +1 -202
- package/dist-standalone/cjs/nonce-store.js +1 -66
- package/dist-standalone/cjs/pairing-manager.js +1 -223
- package/dist-standalone/cjs/plugin-system.js +1 -0
- package/dist-standalone/cjs/plugins/logging.js +1 -0
- package/dist-standalone/cjs/plugins/metrics.js +1 -0
- package/dist-standalone/cjs/plugins/validation.js +1 -0
- package/dist-standalone/cjs/policy.js +1 -320
- package/dist-standalone/cjs/progress-callbacks.js +1 -0
- package/dist-standalone/cjs/redis-nonce-store.js +1 -76
- package/dist-standalone/cjs/registry-middleware.js +1 -50
- package/dist-standalone/cjs/retry-strategies.js +1 -0
- package/dist-standalone/cjs/retry-transport.js +1 -102
- package/dist-standalone/cjs/runtime/browser.js +1 -0
- package/dist-standalone/cjs/runtime/edge.js +1 -0
- package/dist-standalone/cjs/runtime/react-native.js +1 -0
- package/dist-standalone/cjs/security-policy.js +1 -245
- package/dist-standalone/cjs/serialization.js +1 -0
- package/dist-standalone/cjs/split-channel.js +1 -177
- package/dist-standalone/cjs/subscription-proof.js +1 -230
- package/dist-standalone/cjs/succession.js +1 -148
- package/dist-standalone/cjs/timeouts.js +1 -0
- package/dist-standalone/cjs/trace-context.js +1 -0
- package/dist-standalone/cjs/trace-spans.js +1 -0
- package/dist-standalone/cjs/transport.js +1 -63
- package/dist-standalone/cjs/trust-registry.js +1 -742
- package/dist-standalone/cjs/types/error-response.js +1 -56
- package/dist-standalone/cjs/vault-auth.js +1 -0
- package/dist-standalone/cjs/vault-store-loader.js +1 -0
- package/dist-standalone/cjs/verify.js +1 -25
- package/dist-standalone/cjs/version-info.js +1 -0
- package/dist-standalone/cjs/xfetch.js +1 -252
- package/dist-standalone/cli/init.js +1 -449
- package/dist-standalone/cli/setup.js +1 -514
- package/dist-standalone/cli/types.js +1 -27
- package/dist-standalone/cli/xbind.js +1 -148
- package/dist-standalone/config-validation.d.ts +185 -0
- package/dist-standalone/config-validation.js +1 -0
- package/dist-standalone/connect.js +1 -274
- package/dist-standalone/connection-pool.d.ts +251 -0
- package/dist-standalone/connection-pool.js +1 -0
- package/dist-standalone/correlation-id.js +1 -326
- package/dist-standalone/crypto-utils.d.ts +60 -0
- package/dist-standalone/crypto-utils.js +1 -0
- package/dist-standalone/debug-mode.d.ts +286 -0
- package/dist-standalone/debug-mode.js +1 -0
- package/dist-standalone/did-document.js +1 -96
- package/dist-standalone/did-privateme.js +1 -121
- package/dist-standalone/did-web.js +1 -196
- package/dist-standalone/discovery.js +1 -458
- package/dist-standalone/dual-mode.js +1 -247
- package/dist-standalone/email-templates.js +1 -309
- package/dist-standalone/email-transport.js +1 -232
- package/dist-standalone/envelope.d.ts +29 -1
- package/dist-standalone/envelope.js +1 -497
- package/dist-standalone/errors.d.ts +10 -0
- package/dist-standalone/errors.js +1 -811
- package/dist-standalone/event-emitter.d.ts +395 -0
- package/dist-standalone/event-emitter.js +1 -0
- package/dist-standalone/gateway-state.js +1 -51
- package/dist-standalone/gateway-transport.js +1 -116
- package/dist-standalone/graceful-degradation.d.ts +246 -0
- package/dist-standalone/graceful-degradation.js +1 -0
- package/dist-standalone/guardrails.js +1 -216
- package/dist-standalone/health-check.d.ts +150 -0
- package/dist-standalone/health-check.js +1 -0
- package/dist-standalone/http-compat.js +1 -267
- package/dist-standalone/http-status-map.js +1 -561
- package/dist-standalone/identity.d.ts +64 -1
- package/dist-standalone/identity.js +1 -515
- package/dist-standalone/index.d.ts +45 -3
- package/dist-standalone/index.js +1 -52
- package/dist-standalone/invitation.js +1 -415
- package/dist-standalone/invite.js +1 -324
- package/dist-standalone/key-agreement.d.ts +61 -13
- package/dist-standalone/key-agreement.js +1 -236
- package/dist-standalone/lazy-init.js +1 -295
- package/dist-standalone/logger.d.ts +77 -0
- package/dist-standalone/logger.js +1 -0
- package/dist-standalone/mdns-discovery.js +1 -195
- package/dist-standalone/nonce-store.d.ts +16 -3
- package/dist-standalone/nonce-store.js +1 -62
- package/dist-standalone/package.json +0 -1
- package/dist-standalone/pairing-manager.js +1 -219
- package/dist-standalone/plugin-system.d.ts +145 -0
- package/dist-standalone/plugin-system.js +1 -0
- package/dist-standalone/policy.js +1 -315
- package/dist-standalone/progress-callbacks.d.ts +394 -0
- package/dist-standalone/progress-callbacks.js +1 -0
- package/dist-standalone/redis-nonce-store.js +1 -72
- package/dist-standalone/registry-middleware.js +1 -47
- package/dist-standalone/retry-strategies.d.ts +382 -0
- package/dist-standalone/retry-strategies.js +1 -0
- package/dist-standalone/retry-transport.js +1 -98
- package/dist-standalone/security-policy.js +1 -239
- package/dist-standalone/serialization.d.ts +244 -0
- package/dist-standalone/serialization.js +1 -0
- package/dist-standalone/split-channel.d.ts +49 -1
- package/dist-standalone/split-channel.js +1 -171
- package/dist-standalone/subscription-proof.js +1 -224
- package/dist-standalone/succession.js +1 -142
- package/dist-standalone/timeouts.d.ts +275 -0
- package/dist-standalone/timeouts.js +1 -0
- package/dist-standalone/trace-context.d.ts +252 -0
- package/dist-standalone/trace-context.js +1 -0
- package/dist-standalone/trace-spans.d.ts +360 -0
- package/dist-standalone/trace-spans.js +1 -0
- package/dist-standalone/transport.js +1 -59
- package/dist-standalone/trust-registry.d.ts +106 -5
- package/dist-standalone/trust-registry.js +1 -702
- package/dist-standalone/vault-auth.d.ts +91 -0
- package/dist-standalone/vault-auth.js +1 -0
- package/dist-standalone/vault-store-loader.d.ts +110 -0
- package/dist-standalone/vault-store-loader.js +1 -0
- package/dist-standalone/verify.js +1 -16
- package/dist-standalone/version-info.d.ts +259 -0
- package/dist-standalone/version-info.js +1 -0
- package/dist-standalone/xfetch.js +1 -247
- package/llms.txt +1 -0
- package/package.json +65 -5
- package/share1.dat +0 -0
- package/dist-standalone/_deps/crypto/base64.d.ts +0 -29
- package/dist-standalone/_deps/crypto/base64.js +0 -222
- package/dist-standalone/_deps/crypto/cjs/base64.js +0 -665
- package/dist-standalone/_deps/crypto/cjs/errors.js +0 -675
- package/dist-standalone/_deps/crypto/cjs/hmac.js +0 -473
- package/dist-standalone/_deps/crypto/cjs/index.js +0 -852
- package/dist-standalone/_deps/crypto/cjs/package.json +0 -1
- package/dist-standalone/_deps/crypto/cjs/padding.js +0 -511
- package/dist-standalone/_deps/crypto/cjs/share-header.js +0 -372
- package/dist-standalone/_deps/crypto/cjs/shares.js +0 -874
- package/dist-standalone/_deps/crypto/cjs/tlv.js +0 -1021
- package/dist-standalone/_deps/crypto/cjs/uuid.js +0 -443
- package/dist-standalone/_deps/crypto/cjs/verify.js +0 -414
- package/dist-standalone/_deps/crypto/cjs/xorida.js +0 -923
- package/dist-standalone/_deps/crypto/errors.d.ts +0 -51
- package/dist-standalone/_deps/crypto/errors.js +0 -199
- package/dist-standalone/_deps/crypto/hmac.d.ts +0 -39
- package/dist-standalone/_deps/crypto/hmac.js +0 -134
- package/dist-standalone/_deps/crypto/index.d.ts +0 -20
- package/dist-standalone/_deps/crypto/index.js +0 -145
- package/dist-standalone/_deps/crypto/padding.d.ts +0 -19
- package/dist-standalone/_deps/crypto/padding.js +0 -159
- package/dist-standalone/_deps/crypto/share-header.d.ts +0 -44
- package/dist-standalone/_deps/crypto/share-header.js +0 -92
- package/dist-standalone/_deps/crypto/shares.d.ts +0 -27
- package/dist-standalone/_deps/crypto/shares.js +0 -295
- package/dist-standalone/_deps/crypto/tlv.d.ts +0 -26
- package/dist-standalone/_deps/crypto/tlv.js +0 -364
- package/dist-standalone/_deps/crypto/uuid.d.ts +0 -22
- package/dist-standalone/_deps/crypto/uuid.js +0 -136
- package/dist-standalone/_deps/crypto/verify.d.ts +0 -15
- package/dist-standalone/_deps/crypto/verify.js +0 -71
- package/dist-standalone/_deps/crypto/xorida.d.ts +0 -44
- package/dist-standalone/_deps/crypto/xorida.js +0 -366
- package/dist-standalone/_deps/shared/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/shared/errors.js.map +0 -1
- package/dist-standalone/_deps/shared/index.d.ts.map +0 -1
- package/dist-standalone/_deps/shared/index.js.map +0 -1
- package/dist-standalone/_deps/shared/types.d.ts.map +0 -1
- package/dist-standalone/_deps/shared/types.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/errors.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/index.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/progress.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/search.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/types.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/errors.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/index.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/index.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/pagination.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/pagination.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/progress.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/progress.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/search.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/search.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/types.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/types.js.map +0 -1
- package/dist-standalone/_deps/xregistry/discovery.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/discovery.js.map +0 -1
- package/dist-standalone/_deps/xregistry/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/errors.js.map +0 -1
- package/dist-standalone/_deps/xregistry/index.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/index.js.map +0 -1
- package/dist-standalone/_deps/xregistry/registry.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/registry.js.map +0 -1
- package/dist-standalone/_deps/xregistry/schema.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/schema.js.map +0 -1
- package/dist-standalone/_deps/xregistry/types.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/types.js.map +0 -1
|
@@ -1,561 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @module http-status-map
|
|
3
|
-
* Maps xBind error codes to HTTP status codes for REST API responses.
|
|
4
|
-
*
|
|
5
|
-
* This mapping provides:
|
|
6
|
-
* - Consistent HTTP status codes for all 52 xBind error codes
|
|
7
|
-
* - Retryability information for client retry logic
|
|
8
|
-
* - Error categorization (client vs server errors)
|
|
9
|
-
* - Human-readable status text
|
|
10
|
-
*
|
|
11
|
-
* Based on RFC 9110 HTTP Semantics and REST API best practices.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* import { getHttpStatus, isRetryable } from '@private.me/xbind/http-status-map';
|
|
16
|
-
*
|
|
17
|
-
* const status = getHttpStatus('VERIFY_FAILED'); // 401
|
|
18
|
-
* const canRetry = isRetryable('NETWORK_ERROR'); // true
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
/**
|
|
22
|
-
* Complete mapping of xBind error codes to HTTP status codes.
|
|
23
|
-
* All 52 error codes are mapped for 100% coverage.
|
|
24
|
-
*/
|
|
25
|
-
export const HTTP_STATUS_MAP = {
|
|
26
|
-
// ============================================================================
|
|
27
|
-
// IDENTITY (8 error codes)
|
|
28
|
-
// ============================================================================
|
|
29
|
-
KEYGEN_FAILED: {
|
|
30
|
-
statusCode: 500,
|
|
31
|
-
statusText: 'Internal Server Error',
|
|
32
|
-
retryable: true,
|
|
33
|
-
errorType: 'Server',
|
|
34
|
-
category: 'Identity',
|
|
35
|
-
rationale: 'Server crypto initialization failure - client should retry',
|
|
36
|
-
},
|
|
37
|
-
SIGN_FAILED: {
|
|
38
|
-
statusCode: 500,
|
|
39
|
-
statusText: 'Internal Server Error',
|
|
40
|
-
retryable: false,
|
|
41
|
-
errorType: 'Server',
|
|
42
|
-
category: 'Identity',
|
|
43
|
-
rationale: 'Server key corruption - requires admin intervention',
|
|
44
|
-
},
|
|
45
|
-
VERIFY_FAILED: {
|
|
46
|
-
statusCode: 401,
|
|
47
|
-
statusText: 'Unauthorized',
|
|
48
|
-
retryable: false,
|
|
49
|
-
errorType: 'Client',
|
|
50
|
-
category: 'Identity',
|
|
51
|
-
rationale: 'Invalid signature - authentication failure',
|
|
52
|
-
},
|
|
53
|
-
INVALID_DID: {
|
|
54
|
-
statusCode: 400,
|
|
55
|
-
statusText: 'Bad Request',
|
|
56
|
-
retryable: false,
|
|
57
|
-
errorType: 'Client',
|
|
58
|
-
category: 'Identity',
|
|
59
|
-
rationale: 'Malformed DID format - client validation error',
|
|
60
|
-
},
|
|
61
|
-
INVALID_KEY_LENGTH: {
|
|
62
|
-
statusCode: 400,
|
|
63
|
-
statusText: 'Bad Request',
|
|
64
|
-
retryable: false,
|
|
65
|
-
errorType: 'Client',
|
|
66
|
-
category: 'Identity',
|
|
67
|
-
rationale: 'Invalid key material size - client validation error',
|
|
68
|
-
},
|
|
69
|
-
EXPORT_FAILED: {
|
|
70
|
-
statusCode: 500,
|
|
71
|
-
statusText: 'Internal Server Error',
|
|
72
|
-
retryable: true,
|
|
73
|
-
errorType: 'Server',
|
|
74
|
-
category: 'Identity',
|
|
75
|
-
rationale: 'Crypto API failure - transient server issue',
|
|
76
|
-
},
|
|
77
|
-
IMPORT_FAILED: {
|
|
78
|
-
statusCode: 400,
|
|
79
|
-
statusText: 'Bad Request',
|
|
80
|
-
retryable: false,
|
|
81
|
-
errorType: 'Client',
|
|
82
|
-
category: 'Identity',
|
|
83
|
-
rationale: 'Invalid PKCS8 format - client validation error',
|
|
84
|
-
},
|
|
85
|
-
// ============================================================================
|
|
86
|
-
// ENVELOPE (7 error codes)
|
|
87
|
-
// ============================================================================
|
|
88
|
-
INVALID_VERSION: {
|
|
89
|
-
statusCode: 400,
|
|
90
|
-
statusText: 'Bad Request',
|
|
91
|
-
retryable: false,
|
|
92
|
-
errorType: 'Client',
|
|
93
|
-
category: 'Envelope',
|
|
94
|
-
rationale: 'Unsupported protocol version - client must upgrade',
|
|
95
|
-
},
|
|
96
|
-
INVALID_ALG: {
|
|
97
|
-
statusCode: 400,
|
|
98
|
-
statusText: 'Bad Request',
|
|
99
|
-
retryable: false,
|
|
100
|
-
errorType: 'Client',
|
|
101
|
-
category: 'Envelope',
|
|
102
|
-
rationale: 'Unsupported algorithm - client must use AES-256-GCM',
|
|
103
|
-
},
|
|
104
|
-
INVALID_NONCE: {
|
|
105
|
-
statusCode: 400,
|
|
106
|
-
statusText: 'Bad Request',
|
|
107
|
-
retryable: false,
|
|
108
|
-
errorType: 'Client',
|
|
109
|
-
category: 'Envelope',
|
|
110
|
-
rationale: 'Missing or invalid nonce - client validation error',
|
|
111
|
-
},
|
|
112
|
-
INVALID_FIELDS: {
|
|
113
|
-
statusCode: 400,
|
|
114
|
-
statusText: 'Bad Request',
|
|
115
|
-
retryable: false,
|
|
116
|
-
errorType: 'Client',
|
|
117
|
-
category: 'Envelope',
|
|
118
|
-
rationale: 'Missing required envelope fields - client validation error',
|
|
119
|
-
},
|
|
120
|
-
ENCRYPT_FAILED: {
|
|
121
|
-
statusCode: 500,
|
|
122
|
-
statusText: 'Internal Server Error',
|
|
123
|
-
retryable: true,
|
|
124
|
-
errorType: 'Server',
|
|
125
|
-
category: 'Envelope',
|
|
126
|
-
rationale: 'Server encryption failure - transient issue',
|
|
127
|
-
},
|
|
128
|
-
DECRYPT_FAILED: {
|
|
129
|
-
statusCode: 401,
|
|
130
|
-
statusText: 'Unauthorized',
|
|
131
|
-
retryable: false,
|
|
132
|
-
errorType: 'Client',
|
|
133
|
-
category: 'Envelope',
|
|
134
|
-
rationale: 'Decryption failed - wrong key or corrupted data',
|
|
135
|
-
},
|
|
136
|
-
PARSE_FAILED: {
|
|
137
|
-
statusCode: 400,
|
|
138
|
-
statusText: 'Bad Request',
|
|
139
|
-
retryable: false,
|
|
140
|
-
errorType: 'Client',
|
|
141
|
-
category: 'Envelope',
|
|
142
|
-
rationale: 'Malformed JSON envelope - client validation error',
|
|
143
|
-
},
|
|
144
|
-
// ============================================================================
|
|
145
|
-
// TRANSPORT (4 error codes)
|
|
146
|
-
// ============================================================================
|
|
147
|
-
SEND_FAILED: {
|
|
148
|
-
statusCode: 503,
|
|
149
|
-
statusText: 'Service Unavailable',
|
|
150
|
-
retryable: true,
|
|
151
|
-
errorType: 'Server',
|
|
152
|
-
category: 'Transport',
|
|
153
|
-
rationale: 'Network send failure - retry with backoff',
|
|
154
|
-
},
|
|
155
|
-
NETWORK_ERROR: {
|
|
156
|
-
statusCode: 503,
|
|
157
|
-
statusText: 'Service Unavailable',
|
|
158
|
-
retryable: true,
|
|
159
|
-
errorType: 'Server',
|
|
160
|
-
category: 'Transport',
|
|
161
|
-
rationale: 'Network connectivity issue - retry with backoff',
|
|
162
|
-
},
|
|
163
|
-
RECIPIENT_UNREACHABLE: {
|
|
164
|
-
statusCode: 503,
|
|
165
|
-
statusText: 'Service Unavailable',
|
|
166
|
-
retryable: true,
|
|
167
|
-
errorType: 'Server',
|
|
168
|
-
category: 'Transport',
|
|
169
|
-
rationale: 'Recipient offline or unreachable - retry later',
|
|
170
|
-
},
|
|
171
|
-
TIMEOUT: {
|
|
172
|
-
statusCode: 504,
|
|
173
|
-
statusText: 'Gateway Timeout',
|
|
174
|
-
retryable: true,
|
|
175
|
-
errorType: 'Server',
|
|
176
|
-
category: 'Transport',
|
|
177
|
-
rationale: 'Request timed out - increase timeout and retry',
|
|
178
|
-
},
|
|
179
|
-
// ============================================================================
|
|
180
|
-
// REGISTRY (3 error codes)
|
|
181
|
-
// ============================================================================
|
|
182
|
-
NOT_FOUND: {
|
|
183
|
-
statusCode: 404,
|
|
184
|
-
statusText: 'Not Found',
|
|
185
|
-
retryable: false,
|
|
186
|
-
errorType: 'Client',
|
|
187
|
-
category: 'Registry',
|
|
188
|
-
rationale: 'Agent not in registry - recipient must register first',
|
|
189
|
-
},
|
|
190
|
-
ALREADY_REGISTERED: {
|
|
191
|
-
statusCode: 409,
|
|
192
|
-
statusText: 'Conflict',
|
|
193
|
-
retryable: false,
|
|
194
|
-
errorType: 'Client',
|
|
195
|
-
category: 'Registry',
|
|
196
|
-
rationale: 'DID already exists - use updateAgent instead',
|
|
197
|
-
},
|
|
198
|
-
REVOKED: {
|
|
199
|
-
statusCode: 403,
|
|
200
|
-
statusText: 'Forbidden',
|
|
201
|
-
retryable: false,
|
|
202
|
-
errorType: 'Client',
|
|
203
|
-
category: 'Registry',
|
|
204
|
-
rationale: 'Agent revoked - contact admin for re-registration',
|
|
205
|
-
},
|
|
206
|
-
// ============================================================================
|
|
207
|
-
// KEY AGREEMENT (8 error codes)
|
|
208
|
-
// ============================================================================
|
|
209
|
-
DERIVE_FAILED: {
|
|
210
|
-
statusCode: 500,
|
|
211
|
-
statusText: 'Internal Server Error',
|
|
212
|
-
retryable: true,
|
|
213
|
-
errorType: 'Server',
|
|
214
|
-
category: 'Key Agreement',
|
|
215
|
-
rationale: 'ECDH derivation failure - transient crypto issue',
|
|
216
|
-
},
|
|
217
|
-
KEM_ENCAPSULATE_FAILED: {
|
|
218
|
-
statusCode: 500,
|
|
219
|
-
statusText: 'Internal Server Error',
|
|
220
|
-
retryable: true,
|
|
221
|
-
errorType: 'Server',
|
|
222
|
-
category: 'Key Agreement',
|
|
223
|
-
rationale: 'ML-KEM encapsulation failure - transient crypto issue',
|
|
224
|
-
},
|
|
225
|
-
KEM_DECAPSULATE_FAILED: {
|
|
226
|
-
statusCode: 401,
|
|
227
|
-
statusText: 'Unauthorized',
|
|
228
|
-
retryable: false,
|
|
229
|
-
errorType: 'Client',
|
|
230
|
-
category: 'Key Agreement',
|
|
231
|
-
rationale: 'ML-KEM decapsulation failed - wrong ciphertext',
|
|
232
|
-
},
|
|
233
|
-
HKDF_FAILED: {
|
|
234
|
-
statusCode: 500,
|
|
235
|
-
statusText: 'Internal Server Error',
|
|
236
|
-
retryable: true,
|
|
237
|
-
errorType: 'Server',
|
|
238
|
-
category: 'Key Agreement',
|
|
239
|
-
rationale: 'HKDF derivation failure - transient crypto issue',
|
|
240
|
-
},
|
|
241
|
-
MLKEM_NOT_AVAILABLE: {
|
|
242
|
-
statusCode: 400,
|
|
243
|
-
statusText: 'Bad Request',
|
|
244
|
-
retryable: false,
|
|
245
|
-
errorType: 'Client',
|
|
246
|
-
category: 'Key Agreement',
|
|
247
|
-
rationale: 'Post-quantum not enabled - client must configure',
|
|
248
|
-
},
|
|
249
|
-
PQ_SIGN_FAILED: {
|
|
250
|
-
statusCode: 500,
|
|
251
|
-
statusText: 'Internal Server Error',
|
|
252
|
-
retryable: true,
|
|
253
|
-
errorType: 'Server',
|
|
254
|
-
category: 'Key Agreement',
|
|
255
|
-
rationale: 'ML-DSA signing failure - transient crypto issue',
|
|
256
|
-
},
|
|
257
|
-
PQ_VERIFY_FAILED: {
|
|
258
|
-
statusCode: 401,
|
|
259
|
-
statusText: 'Unauthorized',
|
|
260
|
-
retryable: false,
|
|
261
|
-
errorType: 'Client',
|
|
262
|
-
category: 'Key Agreement',
|
|
263
|
-
rationale: 'ML-DSA verification failed - invalid signature',
|
|
264
|
-
},
|
|
265
|
-
// ============================================================================
|
|
266
|
-
// SPLIT CHANNEL (6 error codes)
|
|
267
|
-
// ============================================================================
|
|
268
|
-
SPLIT_FAILED: {
|
|
269
|
-
statusCode: 500,
|
|
270
|
-
statusText: 'Internal Server Error',
|
|
271
|
-
retryable: true,
|
|
272
|
-
errorType: 'Server',
|
|
273
|
-
category: 'Split Channel',
|
|
274
|
-
rationale: 'XorIDA split failure - transient issue',
|
|
275
|
-
},
|
|
276
|
-
INSUFFICIENT_SHARES: {
|
|
277
|
-
statusCode: 400,
|
|
278
|
-
statusText: 'Bad Request',
|
|
279
|
-
retryable: false,
|
|
280
|
-
errorType: 'Client',
|
|
281
|
-
category: 'Split Channel',
|
|
282
|
-
rationale: 'Not enough shares - client must collect more',
|
|
283
|
-
},
|
|
284
|
-
INCONSISTENT_SHARES: {
|
|
285
|
-
statusCode: 400,
|
|
286
|
-
statusText: 'Bad Request',
|
|
287
|
-
retryable: false,
|
|
288
|
-
errorType: 'Client',
|
|
289
|
-
category: 'Split Channel',
|
|
290
|
-
rationale: 'Mismatched shares - client validation error',
|
|
291
|
-
},
|
|
292
|
-
HMAC_VERIFICATION_FAILED: {
|
|
293
|
-
statusCode: 401,
|
|
294
|
-
statusText: 'Unauthorized',
|
|
295
|
-
retryable: false,
|
|
296
|
-
errorType: 'Client',
|
|
297
|
-
category: 'Split Channel',
|
|
298
|
-
rationale: 'Share tampered with - security violation',
|
|
299
|
-
},
|
|
300
|
-
UNPAD_FAILED: {
|
|
301
|
-
statusCode: 500,
|
|
302
|
-
statusText: 'Internal Server Error',
|
|
303
|
-
retryable: false,
|
|
304
|
-
errorType: 'Server',
|
|
305
|
-
category: 'Split Channel',
|
|
306
|
-
rationale: 'Padding removal error - data corruption',
|
|
307
|
-
},
|
|
308
|
-
INVALID_SHARE_DATA: {
|
|
309
|
-
statusCode: 400,
|
|
310
|
-
statusText: 'Bad Request',
|
|
311
|
-
retryable: false,
|
|
312
|
-
errorType: 'Client',
|
|
313
|
-
category: 'Split Channel',
|
|
314
|
-
rationale: 'Malformed share format - client validation error',
|
|
315
|
-
},
|
|
316
|
-
// ============================================================================
|
|
317
|
-
// XCHANGE (4 error codes)
|
|
318
|
-
// ============================================================================
|
|
319
|
-
XCHANGE_KEYGEN_FAILED: {
|
|
320
|
-
statusCode: 500,
|
|
321
|
-
statusText: 'Internal Server Error',
|
|
322
|
-
retryable: true,
|
|
323
|
-
errorType: 'Server',
|
|
324
|
-
category: 'Xchange',
|
|
325
|
-
rationale: 'Key generation failure - transient crypto issue',
|
|
326
|
-
},
|
|
327
|
-
XCHANGE_ENCRYPT_FAILED: {
|
|
328
|
-
statusCode: 500,
|
|
329
|
-
statusText: 'Internal Server Error',
|
|
330
|
-
retryable: true,
|
|
331
|
-
errorType: 'Server',
|
|
332
|
-
category: 'Xchange',
|
|
333
|
-
rationale: 'Bundle encryption failure - transient crypto issue',
|
|
334
|
-
},
|
|
335
|
-
XCHANGE_DECRYPT_FAILED: {
|
|
336
|
-
statusCode: 401,
|
|
337
|
-
statusText: 'Unauthorized',
|
|
338
|
-
retryable: false,
|
|
339
|
-
errorType: 'Client',
|
|
340
|
-
category: 'Xchange',
|
|
341
|
-
rationale: 'Bundle decryption failed - wrong key',
|
|
342
|
-
},
|
|
343
|
-
INVALID_BUNDLE: {
|
|
344
|
-
statusCode: 400,
|
|
345
|
-
statusText: 'Bad Request',
|
|
346
|
-
retryable: false,
|
|
347
|
-
errorType: 'Client',
|
|
348
|
-
category: 'Xchange',
|
|
349
|
-
rationale: 'Malformed bundle format - client validation error',
|
|
350
|
-
},
|
|
351
|
-
// ============================================================================
|
|
352
|
-
// AGENT (12 error codes)
|
|
353
|
-
// ============================================================================
|
|
354
|
-
IDENTITY_FAILED: {
|
|
355
|
-
statusCode: 500,
|
|
356
|
-
statusText: 'Internal Server Error',
|
|
357
|
-
retryable: true,
|
|
358
|
-
errorType: 'Server',
|
|
359
|
-
category: 'Agent',
|
|
360
|
-
rationale: 'Agent identity creation failed - transient issue',
|
|
361
|
-
},
|
|
362
|
-
REGISTRATION_FAILED: {
|
|
363
|
-
statusCode: 503,
|
|
364
|
-
statusText: 'Service Unavailable',
|
|
365
|
-
retryable: true,
|
|
366
|
-
errorType: 'Server',
|
|
367
|
-
category: 'Agent',
|
|
368
|
-
rationale: 'Registry unavailable - retry with backoff',
|
|
369
|
-
},
|
|
370
|
-
RECIPIENT_NOT_FOUND: {
|
|
371
|
-
statusCode: 404,
|
|
372
|
-
statusText: 'Not Found',
|
|
373
|
-
retryable: false,
|
|
374
|
-
errorType: 'Client',
|
|
375
|
-
category: 'Agent',
|
|
376
|
-
rationale: 'Recipient not in registry - recipient must register',
|
|
377
|
-
},
|
|
378
|
-
RECIPIENT_REVOKED: {
|
|
379
|
-
statusCode: 403,
|
|
380
|
-
statusText: 'Forbidden',
|
|
381
|
-
retryable: false,
|
|
382
|
-
errorType: 'Client',
|
|
383
|
-
category: 'Agent',
|
|
384
|
-
rationale: 'Recipient revoked - contact admin',
|
|
385
|
-
},
|
|
386
|
-
KEY_AGREEMENT_FAILED: {
|
|
387
|
-
statusCode: 500,
|
|
388
|
-
statusText: 'Internal Server Error',
|
|
389
|
-
retryable: true,
|
|
390
|
-
errorType: 'Server',
|
|
391
|
-
category: 'Agent',
|
|
392
|
-
rationale: 'Key agreement failure - transient crypto issue',
|
|
393
|
-
},
|
|
394
|
-
ENVELOPE_FAILED: {
|
|
395
|
-
statusCode: 500,
|
|
396
|
-
statusText: 'Internal Server Error',
|
|
397
|
-
retryable: true,
|
|
398
|
-
errorType: 'Server',
|
|
399
|
-
category: 'Agent',
|
|
400
|
-
rationale: 'Envelope creation failed - transient issue',
|
|
401
|
-
},
|
|
402
|
-
VERIFICATION_FAILED: {
|
|
403
|
-
statusCode: 401,
|
|
404
|
-
statusText: 'Unauthorized',
|
|
405
|
-
retryable: false,
|
|
406
|
-
errorType: 'Client',
|
|
407
|
-
category: 'Agent',
|
|
408
|
-
rationale: 'Envelope verification failed - authentication error',
|
|
409
|
-
},
|
|
410
|
-
REPLAY_DETECTED: {
|
|
411
|
-
statusCode: 403,
|
|
412
|
-
statusText: 'Forbidden',
|
|
413
|
-
retryable: false,
|
|
414
|
-
errorType: 'Client',
|
|
415
|
-
category: 'Agent',
|
|
416
|
-
rationale: 'Replay attack detected - security violation',
|
|
417
|
-
},
|
|
418
|
-
SCOPE_DENIED: {
|
|
419
|
-
statusCode: 403,
|
|
420
|
-
statusText: 'Forbidden',
|
|
421
|
-
retryable: false,
|
|
422
|
-
errorType: 'Client',
|
|
423
|
-
category: 'Agent',
|
|
424
|
-
rationale: 'Sender lacks scope permission - authorization failure',
|
|
425
|
-
},
|
|
426
|
-
RECEIVER_SCOPE_DENIED: {
|
|
427
|
-
statusCode: 403,
|
|
428
|
-
statusText: 'Forbidden',
|
|
429
|
-
retryable: false,
|
|
430
|
-
errorType: 'Client',
|
|
431
|
-
category: 'Agent',
|
|
432
|
-
rationale: 'Recipient rejects scope - authorization failure',
|
|
433
|
-
},
|
|
434
|
-
TIMESTAMP_EXPIRED: {
|
|
435
|
-
statusCode: 400,
|
|
436
|
-
statusText: 'Bad Request',
|
|
437
|
-
retryable: true,
|
|
438
|
-
errorType: 'Client',
|
|
439
|
-
category: 'Agent',
|
|
440
|
-
rationale: 'Timestamp outside window - clock sync issue (retryable)',
|
|
441
|
-
},
|
|
442
|
-
};
|
|
443
|
-
/**
|
|
444
|
-
* Get HTTP status code for a given xBind error code.
|
|
445
|
-
* Handles colon-separated sub-codes (e.g., 'DECRYPT_FAILED:KEY_AGREEMENT').
|
|
446
|
-
*
|
|
447
|
-
* @param errorCode - xBind error code (e.g., 'VERIFY_FAILED')
|
|
448
|
-
* @returns HTTP status code (e.g., 401) or 500 if unknown
|
|
449
|
-
*
|
|
450
|
-
* @example
|
|
451
|
-
* ```typescript
|
|
452
|
-
* getHttpStatus('VERIFY_FAILED') // 401
|
|
453
|
-
* getHttpStatus('DECRYPT_FAILED:NETWORK') // 401 (ignores sub-code)
|
|
454
|
-
* getHttpStatus('UNKNOWN_ERROR') // 500 (fallback)
|
|
455
|
-
* ```
|
|
456
|
-
*/
|
|
457
|
-
export function getHttpStatus(errorCode) {
|
|
458
|
-
const baseCode = errorCode.split(':')[0] ?? errorCode;
|
|
459
|
-
const mapping = HTTP_STATUS_MAP[baseCode];
|
|
460
|
-
return mapping?.statusCode ?? 500; // Default to 500 for unknown errors
|
|
461
|
-
}
|
|
462
|
-
/**
|
|
463
|
-
* Get HTTP status text for a given xBind error code.
|
|
464
|
-
*
|
|
465
|
-
* @param errorCode - xBind error code (e.g., 'VERIFY_FAILED')
|
|
466
|
-
* @returns HTTP status text (e.g., 'Unauthorized') or 'Internal Server Error' if unknown
|
|
467
|
-
*
|
|
468
|
-
* @example
|
|
469
|
-
* ```typescript
|
|
470
|
-
* getStatusText('VERIFY_FAILED') // 'Unauthorized'
|
|
471
|
-
* getStatusText('NOT_FOUND') // 'Not Found'
|
|
472
|
-
* ```
|
|
473
|
-
*/
|
|
474
|
-
export function getStatusText(errorCode) {
|
|
475
|
-
const baseCode = errorCode.split(':')[0] ?? errorCode;
|
|
476
|
-
const mapping = HTTP_STATUS_MAP[baseCode];
|
|
477
|
-
return mapping?.statusText ?? 'Internal Server Error';
|
|
478
|
-
}
|
|
479
|
-
/**
|
|
480
|
-
* Check if an error is retryable by the client.
|
|
481
|
-
*
|
|
482
|
-
* @param errorCode - xBind error code (e.g., 'NETWORK_ERROR')
|
|
483
|
-
* @returns True if the client should retry the operation
|
|
484
|
-
*
|
|
485
|
-
* @example
|
|
486
|
-
* ```typescript
|
|
487
|
-
* isRetryable('NETWORK_ERROR') // true (503 - retry with backoff)
|
|
488
|
-
* isRetryable('VERIFY_FAILED') // false (401 - authentication failure)
|
|
489
|
-
* isRetryable('KEYGEN_FAILED') // true (500 - transient server issue)
|
|
490
|
-
* ```
|
|
491
|
-
*/
|
|
492
|
-
export function isRetryable(errorCode) {
|
|
493
|
-
const baseCode = errorCode.split(':')[0] ?? errorCode;
|
|
494
|
-
const mapping = HTTP_STATUS_MAP[baseCode];
|
|
495
|
-
return mapping?.retryable ?? false; // Default to non-retryable for unknown errors
|
|
496
|
-
}
|
|
497
|
-
/**
|
|
498
|
-
* Get complete mapping information for an error code.
|
|
499
|
-
*
|
|
500
|
-
* @param errorCode - xBind error code (e.g., 'VERIFY_FAILED')
|
|
501
|
-
* @returns Complete mapping information or null if not found
|
|
502
|
-
*
|
|
503
|
-
* @example
|
|
504
|
-
* ```typescript
|
|
505
|
-
* const mapping = getMapping('VERIFY_FAILED');
|
|
506
|
-
* if (mapping) {
|
|
507
|
-
* console.log(`${mapping.statusCode} ${mapping.statusText}`);
|
|
508
|
-
* console.log(`Retryable: ${mapping.retryable}`);
|
|
509
|
-
* console.log(`Rationale: ${mapping.rationale}`);
|
|
510
|
-
* }
|
|
511
|
-
* ```
|
|
512
|
-
*/
|
|
513
|
-
export function getMapping(errorCode) {
|
|
514
|
-
const baseCode = errorCode.split(':')[0] ?? errorCode;
|
|
515
|
-
return HTTP_STATUS_MAP[baseCode] ?? null;
|
|
516
|
-
}
|
|
517
|
-
/**
|
|
518
|
-
* Get all error codes in a specific category.
|
|
519
|
-
*
|
|
520
|
-
* @param category - Error category (e.g., 'Identity', 'Transport')
|
|
521
|
-
* @returns Array of error codes in that category
|
|
522
|
-
*
|
|
523
|
-
* @example
|
|
524
|
-
* ```typescript
|
|
525
|
-
* const identityErrors = getErrorCodesByCategory('Identity');
|
|
526
|
-
* // ['KEYGEN_FAILED', 'SIGN_FAILED', 'VERIFY_FAILED', ...]
|
|
527
|
-
* ```
|
|
528
|
-
*/
|
|
529
|
-
export function getErrorCodesByCategory(category) {
|
|
530
|
-
return Object.entries(HTTP_STATUS_MAP)
|
|
531
|
-
.filter(([_, mapping]) => mapping.category === category)
|
|
532
|
-
.map(([code]) => code);
|
|
533
|
-
}
|
|
534
|
-
/**
|
|
535
|
-
* Get all retryable error codes.
|
|
536
|
-
*
|
|
537
|
-
* @returns Array of error codes that are retryable
|
|
538
|
-
*
|
|
539
|
-
* @example
|
|
540
|
-
* ```typescript
|
|
541
|
-
* const retryableErrors = getRetryableErrorCodes();
|
|
542
|
-
* // ['KEYGEN_FAILED', 'EXPORT_FAILED', 'ENCRYPT_FAILED', ...]
|
|
543
|
-
* ```
|
|
544
|
-
*/
|
|
545
|
-
export function getRetryableErrorCodes() {
|
|
546
|
-
return Object.entries(HTTP_STATUS_MAP)
|
|
547
|
-
.filter(([_, mapping]) => mapping.retryable)
|
|
548
|
-
.map(([code]) => code);
|
|
549
|
-
}
|
|
550
|
-
/**
|
|
551
|
-
* Validate that all error codes from the CSV are mapped.
|
|
552
|
-
* This function is used for testing purposes to ensure 100% coverage.
|
|
553
|
-
*
|
|
554
|
-
* @param csvErrorCodes - Array of error codes from the CSV file
|
|
555
|
-
* @returns Array of missing error codes (empty if all mapped)
|
|
556
|
-
*
|
|
557
|
-
* @internal
|
|
558
|
-
*/
|
|
559
|
-
export function validateCoverage(csvErrorCodes) {
|
|
560
|
-
return csvErrorCodes.filter((code) => !HTTP_STATUS_MAP[code]);
|
|
561
|
-
}
|
|
1
|
+
export const HTTP_STATUS_MAP={KEYGEN_FAILED:{statusCode:500,statusText:"Internal Server Error",retryable:!0,errorType:"Server",category:"Identity",rationale:"Server crypto initialization failure - client should retry"},SIGN_FAILED:{statusCode:500,statusText:"Internal Server Error",retryable:!1,errorType:"Server",category:"Identity",rationale:"Server key corruption - requires admin intervention"},VERIFY_FAILED:{statusCode:401,statusText:"Unauthorized",retryable:!1,errorType:"Client",category:"Identity",rationale:"Invalid signature - authentication failure"},INVALID_DID:{statusCode:400,statusText:"Bad Request",retryable:!1,errorType:"Client",category:"Identity",rationale:"Malformed DID format - client validation error"},INVALID_KEY_LENGTH:{statusCode:400,statusText:"Bad Request",retryable:!1,errorType:"Client",category:"Identity",rationale:"Invalid key material size - client validation error"},EXPORT_FAILED:{statusCode:500,statusText:"Internal Server Error",retryable:!0,errorType:"Server",category:"Identity",rationale:"Crypto API failure - transient server issue"},IMPORT_FAILED:{statusCode:400,statusText:"Bad Request",retryable:!1,errorType:"Client",category:"Identity",rationale:"Invalid PKCS8 format - client validation error"},INVALID_VERSION:{statusCode:400,statusText:"Bad Request",retryable:!1,errorType:"Client",category:"Envelope",rationale:"Unsupported protocol version - client must upgrade"},INVALID_ALG:{statusCode:400,statusText:"Bad Request",retryable:!1,errorType:"Client",category:"Envelope",rationale:"Unsupported algorithm - client must use AES-256-GCM"},INVALID_NONCE:{statusCode:400,statusText:"Bad Request",retryable:!1,errorType:"Client",category:"Envelope",rationale:"Missing or invalid nonce - client validation error"},INVALID_FIELDS:{statusCode:400,statusText:"Bad Request",retryable:!1,errorType:"Client",category:"Envelope",rationale:"Missing required envelope fields - client validation error"},ENCRYPT_FAILED:{statusCode:500,statusText:"Internal Server Error",retryable:!0,errorType:"Server",category:"Envelope",rationale:"Server encryption failure - transient issue"},DECRYPT_FAILED:{statusCode:401,statusText:"Unauthorized",retryable:!1,errorType:"Client",category:"Envelope",rationale:"Decryption failed - wrong key or corrupted data"},PARSE_FAILED:{statusCode:400,statusText:"Bad Request",retryable:!1,errorType:"Client",category:"Envelope",rationale:"Malformed JSON envelope - client validation error"},SEND_FAILED:{statusCode:503,statusText:"Service Unavailable",retryable:!0,errorType:"Server",category:"Transport",rationale:"Network send failure - retry with backoff"},NETWORK_ERROR:{statusCode:503,statusText:"Service Unavailable",retryable:!0,errorType:"Server",category:"Transport",rationale:"Network connectivity issue - retry with backoff"},RECIPIENT_UNREACHABLE:{statusCode:503,statusText:"Service Unavailable",retryable:!0,errorType:"Server",category:"Transport",rationale:"Recipient offline or unreachable - retry later"},TIMEOUT:{statusCode:504,statusText:"Gateway Timeout",retryable:!0,errorType:"Server",category:"Transport",rationale:"Request timed out - increase timeout and retry"},NOT_FOUND:{statusCode:404,statusText:"Not Found",retryable:!1,errorType:"Client",category:"Registry",rationale:"Agent not in registry - recipient must register first"},ALREADY_REGISTERED:{statusCode:409,statusText:"Conflict",retryable:!1,errorType:"Client",category:"Registry",rationale:"DID already exists - use updateAgent instead"},REVOKED:{statusCode:403,statusText:"Forbidden",retryable:!1,errorType:"Client",category:"Registry",rationale:"Agent revoked - contact admin for re-registration"},DERIVE_FAILED:{statusCode:500,statusText:"Internal Server Error",retryable:!0,errorType:"Server",category:"Key Agreement",rationale:"ECDH derivation failure - transient crypto issue"},KEM_ENCAPSULATE_FAILED:{statusCode:500,statusText:"Internal Server Error",retryable:!0,errorType:"Server",category:"Key Agreement",rationale:"ML-KEM encapsulation failure - transient crypto issue"},KEM_DECAPSULATE_FAILED:{statusCode:401,statusText:"Unauthorized",retryable:!1,errorType:"Client",category:"Key Agreement",rationale:"ML-KEM decapsulation failed - wrong ciphertext"},HKDF_FAILED:{statusCode:500,statusText:"Internal Server Error",retryable:!0,errorType:"Server",category:"Key Agreement",rationale:"HKDF derivation failure - transient crypto issue"},MLKEM_NOT_AVAILABLE:{statusCode:400,statusText:"Bad Request",retryable:!1,errorType:"Client",category:"Key Agreement",rationale:"Post-quantum not enabled - client must configure"},PQ_SIGN_FAILED:{statusCode:500,statusText:"Internal Server Error",retryable:!0,errorType:"Server",category:"Key Agreement",rationale:"ML-DSA signing failure - transient crypto issue"},PQ_VERIFY_FAILED:{statusCode:401,statusText:"Unauthorized",retryable:!1,errorType:"Client",category:"Key Agreement",rationale:"ML-DSA verification failed - invalid signature"},SPLIT_FAILED:{statusCode:500,statusText:"Internal Server Error",retryable:!0,errorType:"Server",category:"Split Channel",rationale:"XorIDA split failure - transient issue"},INSUFFICIENT_SHARES:{statusCode:400,statusText:"Bad Request",retryable:!1,errorType:"Client",category:"Split Channel",rationale:"Not enough shares - client must collect more"},INCONSISTENT_SHARES:{statusCode:400,statusText:"Bad Request",retryable:!1,errorType:"Client",category:"Split Channel",rationale:"Mismatched shares - client validation error"},HMAC_VERIFICATION_FAILED:{statusCode:401,statusText:"Unauthorized",retryable:!1,errorType:"Client",category:"Split Channel",rationale:"Share tampered with - security violation"},UNPAD_FAILED:{statusCode:500,statusText:"Internal Server Error",retryable:!1,errorType:"Server",category:"Split Channel",rationale:"Padding removal error - data corruption"},INVALID_SHARE_DATA:{statusCode:400,statusText:"Bad Request",retryable:!1,errorType:"Client",category:"Split Channel",rationale:"Malformed share format - client validation error"},XCHANGE_KEYGEN_FAILED:{statusCode:500,statusText:"Internal Server Error",retryable:!0,errorType:"Server",category:"Xchange",rationale:"Key generation failure - transient crypto issue"},XCHANGE_ENCRYPT_FAILED:{statusCode:500,statusText:"Internal Server Error",retryable:!0,errorType:"Server",category:"Xchange",rationale:"Bundle encryption failure - transient crypto issue"},XCHANGE_DECRYPT_FAILED:{statusCode:401,statusText:"Unauthorized",retryable:!1,errorType:"Client",category:"Xchange",rationale:"Bundle decryption failed - wrong key"},INVALID_BUNDLE:{statusCode:400,statusText:"Bad Request",retryable:!1,errorType:"Client",category:"Xchange",rationale:"Malformed bundle format - client validation error"},IDENTITY_FAILED:{statusCode:500,statusText:"Internal Server Error",retryable:!0,errorType:"Server",category:"Agent",rationale:"Agent identity creation failed - transient issue"},REGISTRATION_FAILED:{statusCode:503,statusText:"Service Unavailable",retryable:!0,errorType:"Server",category:"Agent",rationale:"Registry unavailable - retry with backoff"},RECIPIENT_NOT_FOUND:{statusCode:404,statusText:"Not Found",retryable:!1,errorType:"Client",category:"Agent",rationale:"Recipient not in registry - recipient must register"},RECIPIENT_REVOKED:{statusCode:403,statusText:"Forbidden",retryable:!1,errorType:"Client",category:"Agent",rationale:"Recipient revoked - contact admin"},KEY_AGREEMENT_FAILED:{statusCode:500,statusText:"Internal Server Error",retryable:!0,errorType:"Server",category:"Agent",rationale:"Key agreement failure - transient crypto issue"},ENVELOPE_FAILED:{statusCode:500,statusText:"Internal Server Error",retryable:!0,errorType:"Server",category:"Agent",rationale:"Envelope creation failed - transient issue"},VERIFICATION_FAILED:{statusCode:401,statusText:"Unauthorized",retryable:!1,errorType:"Client",category:"Agent",rationale:"Envelope verification failed - authentication error"},REPLAY_DETECTED:{statusCode:403,statusText:"Forbidden",retryable:!1,errorType:"Client",category:"Agent",rationale:"Replay attack detected - security violation"},SCOPE_DENIED:{statusCode:403,statusText:"Forbidden",retryable:!1,errorType:"Client",category:"Agent",rationale:"Sender lacks scope permission - authorization failure"},RECEIVER_SCOPE_DENIED:{statusCode:403,statusText:"Forbidden",retryable:!1,errorType:"Client",category:"Agent",rationale:"Recipient rejects scope - authorization failure"},TIMESTAMP_EXPIRED:{statusCode:400,statusText:"Bad Request",retryable:!0,errorType:"Client",category:"Agent",rationale:"Timestamp outside window - clock sync issue (retryable)"}};export function getHttpStatus(e){const t=e.split(":")[0]??e,r=HTTP_STATUS_MAP[t];return r?.statusCode??500}export function getStatusText(e){const t=e.split(":")[0]??e,r=HTTP_STATUS_MAP[t];return r?.statusText??"Internal Server Error"}export function isRetryable(e){const t=e.split(":")[0]??e,r=HTTP_STATUS_MAP[t];return r?.retryable??!1}export function getMapping(e){const t=e.split(":")[0]??e;return HTTP_STATUS_MAP[t]??null}export function getErrorCodesByCategory(e){return Object.entries(HTTP_STATUS_MAP).filter(([t,r])=>r.category===e).map(([e])=>e)}export function getRetryableErrorCodes(){return Object.entries(HTTP_STATUS_MAP).filter(([e,t])=>t.retryable).map(([e])=>e)}export function validateCoverage(e){return e.filter(e=>!HTTP_STATUS_MAP[e])}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import type { Result } from '@private.me/shared';
|
|
2
|
+
/** Rotated key material (preserved for decryption of old messages). */
|
|
3
|
+
export interface RotatedKeys {
|
|
4
|
+
/** Timestamp when keys were rotated (milliseconds since epoch). */
|
|
5
|
+
readonly rotatedAt: number;
|
|
6
|
+
/** Previous X25519 private key for decrypting messages encrypted with old key. */
|
|
7
|
+
readonly x25519PrivateKey: CryptoKey;
|
|
8
|
+
/** Previous ML-KEM-768 secret key for hybrid decryption. */
|
|
9
|
+
readonly mlKemSecretKey?: Uint8Array;
|
|
10
|
+
}
|
|
2
11
|
/** Agent cryptographic identity backed by Ed25519 keypair. */
|
|
3
12
|
export interface AgentIdentity {
|
|
4
13
|
/** Decentralized identifier: did:key:z6Mk... */
|
|
@@ -23,12 +32,37 @@ export interface AgentIdentity {
|
|
|
23
32
|
readonly mlDsaPublicKey?: Uint8Array;
|
|
24
33
|
/** ML-DSA-65 secret key (4032 bytes) for hybrid post-quantum signatures. */
|
|
25
34
|
readonly mlDsaSecretKey?: Uint8Array;
|
|
35
|
+
/** Previous rotated keys (for backward-compatible decryption). */
|
|
36
|
+
readonly rotatedKeys?: RotatedKeys[];
|
|
26
37
|
}
|
|
27
38
|
/** Error codes for identity operations. */
|
|
28
|
-
export type IdentityError = 'KEYGEN_FAILED' | 'SIGN_FAILED' | 'VERIFY_FAILED' | 'INVALID_DID' | 'INVALID_KEY_LENGTH' | 'EXPORT_FAILED' | 'IMPORT_FAILED';
|
|
39
|
+
export type IdentityError = 'KEYGEN_FAILED' | 'SIGN_FAILED' | 'VERIFY_FAILED' | 'INVALID_DID' | 'INVALID_KEY_LENGTH' | 'EXPORT_FAILED' | 'IMPORT_FAILED' | 'ROTATION_FAILED';
|
|
29
40
|
/**
|
|
30
41
|
* Generate a new Ed25519 agent identity.
|
|
31
42
|
* Creates keypair via Web Crypto API, derives did:key DID.
|
|
43
|
+
*
|
|
44
|
+
* @param opts - Optional configuration
|
|
45
|
+
* @param opts.postQuantumSig - Enable ML-DSA-65 post-quantum signatures (default: false)
|
|
46
|
+
* @returns Result containing the agent identity or error
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* import { generateIdentity } from '@private.me/xbind';
|
|
51
|
+
*
|
|
52
|
+
* // Generate identity with classical cryptography only
|
|
53
|
+
* const identity = await generateIdentity();
|
|
54
|
+
* if (!identity.ok) {
|
|
55
|
+
* throw new Error(`Failed to generate identity: ${identity.error}`);
|
|
56
|
+
* }
|
|
57
|
+
* console.log('DID:', identity.value.did);
|
|
58
|
+
*
|
|
59
|
+
* // Generate identity with post-quantum signatures
|
|
60
|
+
* const pqIdentity = await generateIdentity({ postQuantumSig: true });
|
|
61
|
+
* if (pqIdentity.ok) {
|
|
62
|
+
* console.log('Post-quantum DID:', pqIdentity.value.did);
|
|
63
|
+
* console.log('Has ML-DSA key:', !!pqIdentity.value.mlDsaPublicKey);
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
32
66
|
*/
|
|
33
67
|
export declare function generateIdentity(opts?: {
|
|
34
68
|
postQuantumSig?: boolean;
|
|
@@ -174,3 +208,32 @@ export declare function extractRawEd25519(pkcs8: Uint8Array): Result<Uint8Array,
|
|
|
174
208
|
* @returns 32-byte raw private key or error.
|
|
175
209
|
*/
|
|
176
210
|
export declare function extractRawX25519(pkcs8: Uint8Array): Result<Uint8Array, IdentityError>;
|
|
211
|
+
/**
|
|
212
|
+
* Rotate ML-KEM + X25519 keys while preserving old keys for decryption.
|
|
213
|
+
*
|
|
214
|
+
* Generates new X25519 and ML-KEM-768 keypairs. Saves the old keys
|
|
215
|
+
* in rotatedKeys array (with timestamp) for backward-compatible decryption
|
|
216
|
+
* of messages encrypted with the old keys. Ed25519 keys (for signing) are
|
|
217
|
+
* NOT rotated — they remain constant for persistent identity.
|
|
218
|
+
*
|
|
219
|
+
* After rotation:
|
|
220
|
+
* - New messages use the new X25519 + ML-KEM keys
|
|
221
|
+
* - Old messages decrypt using preserved rotatedKeys
|
|
222
|
+
* - DID remains unchanged (anchored to Ed25519 public key)
|
|
223
|
+
* - Registry must be updated with new X25519 + ML-KEM public keys
|
|
224
|
+
*
|
|
225
|
+
* @param identity - Current identity with keys to rotate
|
|
226
|
+
* @returns Updated identity with new keys + old keys in rotatedKeys array, or error
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```ts
|
|
230
|
+
* const rotated = await identity.rotateKeys();
|
|
231
|
+
* if (rotated.ok) {
|
|
232
|
+
* // New keys are active; old keys preserved for decryption
|
|
233
|
+
* console.log('Rotated at:', rotated.value.rotatedKeys?.[0]?.rotatedAt);
|
|
234
|
+
* // Update registry with new X25519 + ML-KEM public keys
|
|
235
|
+
* await registry.updateKeys(rotated.value.did, rotated.value.rawX25519PublicKey, rotated.value.mlKemPublicKey);
|
|
236
|
+
* }
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
export declare function rotateKeys(identity: AgentIdentity): Promise<Result<AgentIdentity, IdentityError>>;
|