@private.me/xbind 3.0.2 → 3.0.3

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.
Files changed (221) hide show
  1. package/README.md +2366 -204
  2. package/README.md.backup +2121 -0
  3. package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1 -1920
  4. package/dist-standalone/_deps/shared/cjs/errors.js +1 -729
  5. package/dist-standalone/_deps/shared/cjs/index.js +1 -463
  6. package/dist-standalone/_deps/shared/cjs/types.js +1 -315
  7. package/dist-standalone/_deps/shared/errors.js +1 -244
  8. package/dist-standalone/_deps/shared/index.js +1 -72
  9. package/dist-standalone/_deps/shared/types.js +1 -86
  10. package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -1
  11. package/dist-standalone/_deps/ux-helpers/cjs/index.js +1 -1
  12. package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +1 -1
  13. package/dist-standalone/_deps/ux-helpers/cjs/progress.js +1 -1
  14. package/dist-standalone/_deps/ux-helpers/cjs/search.js +1 -1
  15. package/dist-standalone/_deps/ux-helpers/cjs/types.js +1 -1
  16. package/dist-standalone/_deps/ux-helpers/errors.js +1 -1
  17. package/dist-standalone/_deps/ux-helpers/index.js +1 -1
  18. package/dist-standalone/_deps/ux-helpers/pagination.js +1 -1
  19. package/dist-standalone/_deps/ux-helpers/progress.js +1 -1
  20. package/dist-standalone/_deps/ux-helpers/search.js +1 -1
  21. package/dist-standalone/_deps/xchange/auto-accept.js +1 -1
  22. package/dist-standalone/_deps/xchange/cjs/auto-accept.js +1 -1
  23. package/dist-standalone/_deps/xchange/cjs/errors.js +1 -1
  24. package/dist-standalone/_deps/xchange/cjs/index.js +1 -1
  25. package/dist-standalone/_deps/xchange/cjs/invite-client.js +1 -1
  26. package/dist-standalone/_deps/xchange/cjs/lazy-init.js +1 -1
  27. package/dist-standalone/_deps/xchange/cjs/trust-integration.js +1 -1
  28. package/dist-standalone/_deps/xchange/cjs/xchange.js +1 -1
  29. package/dist-standalone/_deps/xchange/errors.js +1 -1
  30. package/dist-standalone/_deps/xchange/index.js +1 -1
  31. package/dist-standalone/_deps/xchange/invite-client.js +1 -1
  32. package/dist-standalone/_deps/xchange/lazy-init.js +1 -1
  33. package/dist-standalone/_deps/xchange/trust-integration.js +1 -1
  34. package/dist-standalone/_deps/xchange/xchange.js +1 -1
  35. package/dist-standalone/_deps/xregistry/cjs/discovery.js +1 -1
  36. package/dist-standalone/_deps/xregistry/cjs/errors.js +1 -1
  37. package/dist-standalone/_deps/xregistry/cjs/index.js +1 -1
  38. package/dist-standalone/_deps/xregistry/cjs/registry.js +1 -1
  39. package/dist-standalone/_deps/xregistry/cjs/schema.js +1 -1
  40. package/dist-standalone/_deps/xregistry/cjs/types.js +1 -1
  41. package/dist-standalone/_deps/xregistry/discovery.js +1 -1
  42. package/dist-standalone/_deps/xregistry/errors.js +1 -1
  43. package/dist-standalone/_deps/xregistry/index.js +1 -1
  44. package/dist-standalone/_deps/xregistry/registry.js +1 -1
  45. package/dist-standalone/_deps/xregistry/schema.js +1 -1
  46. package/dist-standalone/_deps/xregistry/types.js +1 -1
  47. package/dist-standalone/agent-call.d.ts +2 -2
  48. package/dist-standalone/agent-call.js +1 -659
  49. package/dist-standalone/agent-sdk.js +1 -328
  50. package/dist-standalone/agent.d.ts +2 -0
  51. package/dist-standalone/agent.js +1 -1800
  52. package/dist-standalone/approval.js +1 -193
  53. package/dist-standalone/async-iterators.d.ts +3 -3
  54. package/dist-standalone/async-iterators.js +1 -382
  55. package/dist-standalone/auth.js +1 -219
  56. package/dist-standalone/auto-accept.js +1 -229
  57. package/dist-standalone/backup-config.js +1 -201
  58. package/dist-standalone/backup.js +1 -326
  59. package/dist-standalone/batch-operations.js +1 -388
  60. package/dist-standalone/cancellation.js +1 -477
  61. package/dist-standalone/checkpoint.js +1 -186
  62. package/dist-standalone/circuit-breaker.js +1 -468
  63. package/dist-standalone/cjs/agent-call.js +1 -701
  64. package/dist-standalone/cjs/agent-sdk.js +1 -332
  65. package/dist-standalone/cjs/agent.js +1 -1837
  66. package/dist-standalone/cjs/approval.js +1 -199
  67. package/dist-standalone/cjs/async-iterators.js +1 -392
  68. package/dist-standalone/cjs/auth.js +1 -225
  69. package/dist-standalone/cjs/auto-accept.js +1 -233
  70. package/dist-standalone/cjs/backup-config.js +1 -207
  71. package/dist-standalone/cjs/backup.js +1 -330
  72. package/dist-standalone/cjs/batch-operations.js +1 -397
  73. package/dist-standalone/cjs/cancellation.js +1 -490
  74. package/dist-standalone/cjs/checkpoint.js +1 -193
  75. package/dist-standalone/cjs/circuit-breaker.js +1 -476
  76. package/dist-standalone/cjs/cli/init.js +1 -492
  77. package/dist-standalone/cjs/config-validation.js +1 -522
  78. package/dist-standalone/cjs/connect.js +1 -312
  79. package/dist-standalone/cjs/connection-pool.js +1 -506
  80. package/dist-standalone/cjs/correlation-id.js +1 -339
  81. package/dist-standalone/cjs/crypto-utils.js +1 -176
  82. package/dist-standalone/cjs/debug-mode.js +1 -534
  83. package/dist-standalone/cjs/did-document.js +1 -101
  84. package/dist-standalone/cjs/did-privateme.js +1 -130
  85. package/dist-standalone/cjs/did-web.js +1 -201
  86. package/dist-standalone/cjs/discovery.js +1 -462
  87. package/dist-standalone/cjs/dual-mode.js +1 -251
  88. package/dist-standalone/cjs/email-templates.js +1 -313
  89. package/dist-standalone/cjs/email-transport.js +1 -239
  90. package/dist-standalone/cjs/envelope.js +1 -538
  91. package/dist-standalone/cjs/errors.js +1 -913
  92. package/dist-standalone/cjs/event-emitter.js +1 -461
  93. package/dist-standalone/cjs/gateway-state.js +1 -55
  94. package/dist-standalone/cjs/gateway-transport.js +1 -120
  95. package/dist-standalone/cjs/graceful-degradation.js +1 -403
  96. package/dist-standalone/cjs/guardrails.js +1 -223
  97. package/dist-standalone/cjs/health-check.js +1 -336
  98. package/dist-standalone/cjs/http-compat.js +1 -272
  99. package/dist-standalone/cjs/http-status-map.js +1 -571
  100. package/dist-standalone/cjs/identity.js +1 -645
  101. package/dist-standalone/cjs/index.js +1 -406
  102. package/dist-standalone/cjs/invitation.js +1 -421
  103. package/dist-standalone/cjs/invite.js +1 -328
  104. package/dist-standalone/cjs/key-agreement.js +1 -335
  105. package/dist-standalone/cjs/lazy-init.js +1 -300
  106. package/dist-standalone/cjs/logger.js +1 -291
  107. package/dist-standalone/cjs/loopback-transport.js +1 -0
  108. package/dist-standalone/cjs/mdns-discovery.js +1 -202
  109. package/dist-standalone/cjs/nonce-store.js +1 -80
  110. package/dist-standalone/cjs/pairing-manager.js +1 -223
  111. package/dist-standalone/cjs/plugin-system.js +1 -264
  112. package/dist-standalone/cjs/plugins/logging.js +1 -168
  113. package/dist-standalone/cjs/plugins/metrics.js +1 -181
  114. package/dist-standalone/cjs/plugins/validation.js +1 -302
  115. package/dist-standalone/cjs/policy.js +1 -320
  116. package/dist-standalone/cjs/progress-callbacks.js +1 -583
  117. package/dist-standalone/cjs/redis-nonce-store.js +1 -76
  118. package/dist-standalone/cjs/registry-middleware.js +1 -50
  119. package/dist-standalone/cjs/retry-strategies.js +1 -544
  120. package/dist-standalone/cjs/retry-transport.js +1 -102
  121. package/dist-standalone/cjs/runtime/browser.js +1 -533
  122. package/dist-standalone/cjs/runtime/edge.js +1 -526
  123. package/dist-standalone/cjs/runtime/react-native.js +1 -394
  124. package/dist-standalone/cjs/security-policy.js +1 -245
  125. package/dist-standalone/cjs/serialization.js +1 -1040
  126. package/dist-standalone/cjs/split-channel.js +1 -225
  127. package/dist-standalone/cjs/subscription-proof.js +1 -230
  128. package/dist-standalone/cjs/succession.js +1 -148
  129. package/dist-standalone/cjs/timeouts.js +1 -412
  130. package/dist-standalone/cjs/trace-context.js +1 -424
  131. package/dist-standalone/cjs/trace-spans.js +1 -495
  132. package/dist-standalone/cjs/transport.js +1 -63
  133. package/dist-standalone/cjs/trust-registry.js +1 -991
  134. package/dist-standalone/cjs/types/error-response.js +1 -56
  135. package/dist-standalone/cjs/vault-auth.js +1 -178
  136. package/dist-standalone/cjs/vault-store-loader.js +1 -194
  137. package/dist-standalone/cjs/verify.js +1 -25
  138. package/dist-standalone/cjs/version-info.js +1 -543
  139. package/dist-standalone/cjs/xfetch.js +1 -340
  140. package/dist-standalone/cli/init.js +1 -455
  141. package/dist-standalone/cli/setup.js +1 -514
  142. package/dist-standalone/cli/types.js +1 -27
  143. package/dist-standalone/cli/xbind.js +1 -148
  144. package/dist-standalone/config-validation.js +1 -513
  145. package/dist-standalone/connect.js +1 -274
  146. package/dist-standalone/connection-pool.js +1 -500
  147. package/dist-standalone/correlation-id.js +1 -326
  148. package/dist-standalone/crypto-utils.d.ts +2 -7
  149. package/dist-standalone/crypto-utils.js +1 -157
  150. package/dist-standalone/debug-mode.js +1 -510
  151. package/dist-standalone/did-document.js +1 -96
  152. package/dist-standalone/did-privateme.js +1 -121
  153. package/dist-standalone/did-web.js +1 -196
  154. package/dist-standalone/discovery.js +1 -458
  155. package/dist-standalone/dual-mode.js +1 -247
  156. package/dist-standalone/email-templates.js +1 -309
  157. package/dist-standalone/email-transport.d.ts +2 -2
  158. package/dist-standalone/email-transport.js +1 -232
  159. package/dist-standalone/envelope.js +1 -525
  160. package/dist-standalone/errors.d.ts +13 -3
  161. package/dist-standalone/errors.js +1 -896
  162. package/dist-standalone/event-emitter.js +1 -456
  163. package/dist-standalone/gateway-state.d.ts +1 -1
  164. package/dist-standalone/gateway-state.js +1 -51
  165. package/dist-standalone/gateway-transport.js +1 -116
  166. package/dist-standalone/graceful-degradation.js +1 -396
  167. package/dist-standalone/guardrails.js +1 -216
  168. package/dist-standalone/health-check.d.ts +5 -1
  169. package/dist-standalone/health-check.js +1 -332
  170. package/dist-standalone/http-compat.d.ts +1 -1
  171. package/dist-standalone/http-compat.js +1 -267
  172. package/dist-standalone/http-status-map.js +1 -561
  173. package/dist-standalone/identity.js +1 -619
  174. package/dist-standalone/index.d.ts +15 -4
  175. package/dist-standalone/index.js +1 -78
  176. package/dist-standalone/invitation.js +1 -415
  177. package/dist-standalone/invite.js +1 -324
  178. package/dist-standalone/key-agreement.js +1 -325
  179. package/dist-standalone/lazy-init.d.ts +11 -6
  180. package/dist-standalone/lazy-init.js +1 -295
  181. package/dist-standalone/logger.js +1 -285
  182. package/dist-standalone/loopback-transport.d.ts +87 -0
  183. package/dist-standalone/loopback-transport.js +1 -0
  184. package/dist-standalone/mdns-discovery.js +1 -195
  185. package/dist-standalone/nonce-store.js +1 -76
  186. package/dist-standalone/pairing-manager.js +1 -219
  187. package/dist-standalone/plugin-system.js +1 -257
  188. package/dist-standalone/plugins/logging.js +1 -163
  189. package/dist-standalone/plugins/metrics.d.ts +4 -4
  190. package/dist-standalone/plugins/metrics.js +1 -176
  191. package/dist-standalone/plugins/validation.js +1 -297
  192. package/dist-standalone/policy.js +1 -315
  193. package/dist-standalone/progress-callbacks.js +1 -576
  194. package/dist-standalone/redis-nonce-store.js +1 -72
  195. package/dist-standalone/registry-middleware.js +1 -47
  196. package/dist-standalone/retry-strategies.js +1 -534
  197. package/dist-standalone/retry-transport.js +1 -98
  198. package/dist-standalone/runtime/browser.js +1 -516
  199. package/dist-standalone/runtime/edge.js +1 -511
  200. package/dist-standalone/runtime/react-native.d.ts +1 -1
  201. package/dist-standalone/runtime/react-native.js +1 -383
  202. package/dist-standalone/security-policy.js +1 -239
  203. package/dist-standalone/serialization.js +1 -1031
  204. package/dist-standalone/split-channel.js +1 -219
  205. package/dist-standalone/subscription-proof.js +1 -224
  206. package/dist-standalone/succession.js +1 -142
  207. package/dist-standalone/timeouts.js +1 -398
  208. package/dist-standalone/trace-context.js +1 -414
  209. package/dist-standalone/trace-spans.js +1 -488
  210. package/dist-standalone/transport.js +1 -59
  211. package/dist-standalone/trust-registry.d.ts +3 -3
  212. package/dist-standalone/trust-registry.js +1 -950
  213. package/dist-standalone/types/error-response.js +1 -52
  214. package/dist-standalone/vault-auth.js +1 -174
  215. package/dist-standalone/vault-store-loader.d.ts +9 -0
  216. package/dist-standalone/vault-store-loader.js +1 -187
  217. package/dist-standalone/verify.js +1 -16
  218. package/dist-standalone/version-info.js +1 -530
  219. package/dist-standalone/xfetch.js +1 -335
  220. package/package.json +1 -1
  221. package/share1.dat +0 -0
@@ -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])}