@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,525 +1 @@
1
- import { ok, err } from"./_deps/shared/index.js";
2
- import { toBase64, fromBase64 } from './crypto-utils.js';
3
- import { sign as ed25519Sign, verify as ed25519Verify, signMlDsa65 } from './identity.js';
4
- /* ── Constants ── */
5
- const NONCE_BYTES = 16;
6
- const AES_IV_BYTES = 12;
7
- const AES_ALGO = 'AES-GCM';
8
- /** ML-KEM-768 ciphertext length in bytes. */
9
- const KEM_CIPHERTEXT_BYTES = 1088;
10
- /** ML-DSA-65 signature length in bytes. */
11
- const ML_DSA65_SIG_BYTES = 3309;
12
- /* ── Helpers ── */
13
- /** Copy Uint8Array to fresh ArrayBuffer. */
14
- function toArrayBuffer(data) {
15
- const buf = new ArrayBuffer(data.byteLength);
16
- new Uint8Array(buf).set(data);
17
- return buf;
18
- }
19
- /**
20
- * Create canonical representation of envelope fields for signing.
21
- *
22
- * SECURITY FIX (v1.1.3): Sign ALL envelope metadata (nonce, timestamp, sender,
23
- * recipient, scope, payload) to prevent replay attacks via nonce substitution.
24
- *
25
- * Previous versions only signed the payload, allowing attackers to:
26
- * 1. Capture an envelope
27
- * 2. Change the nonce to a fresh value
28
- * 3. Replay the message (signature still verified)
29
- *
30
- * Canonical format: UTF-8 JSON with sorted keys, no whitespace.
31
- * Example: {"alg":"Ed25519","nonce":"...","payload":"...","recipient":"...","scope":"...","sender":"...","timestamp":1234567890,"v":1}
32
- */
33
- function createSignedData(envelope) {
34
- // Create canonical JSON representation (sorted keys)
35
- const canonical = JSON.stringify({
36
- v: envelope.v,
37
- alg: envelope.alg,
38
- sender: envelope.sender,
39
- recipient: envelope.recipient,
40
- timestamp: envelope.timestamp,
41
- nonce: envelope.nonce,
42
- scope: envelope.scope,
43
- payload: envelope.payload,
44
- });
45
- return new TextEncoder().encode(canonical);
46
- }
47
- /* ── Envelope Creation ── */
48
- /**
49
- * Create a signed, encrypted TransportEnvelope (version 1).
50
- *
51
- * Encrypt-then-sign: AES-256-GCM encrypts payload, Ed25519 signs ciphertext.
52
- * All envelope metadata (nonce, timestamp, sender, recipient, scope) is included
53
- * in the signature to prevent replay attacks.
54
- *
55
- * @param opts - Envelope creation options
56
- * @returns Result containing the envelope or error
57
- *
58
- * @example
59
- * ```typescript
60
- * import { createEnvelope, generateSharedKey } from '@private.me/xbind';
61
- *
62
- * // Generate shared key (typically from ECDH key agreement)
63
- * const sharedKey = await generateSharedKey(senderDid, recipientDid);
64
- * if (!sharedKey.ok) throw new Error(sharedKey.error);
65
- *
66
- * // Create encrypted envelope
67
- * const envelope = await createEnvelope({
68
- * sender: 'did:key:z6Mk...',
69
- * recipient: 'did:key:z6Mk...',
70
- * plaintext: new TextEncoder().encode(JSON.stringify({ message: 'Hello' })),
71
- * sharedKey: sharedKey.value,
72
- * privateKey: senderPrivateKey,
73
- * scope: 'read:messages'
74
- * });
75
- *
76
- * if (envelope.ok) {
77
- * console.log('Envelope created:', envelope.value);
78
- * }
79
- * ```
80
- */
81
- export async function createEnvelope(opts) {
82
- const nonce = new Uint8Array(NONCE_BYTES);
83
- crypto.getRandomValues(nonce);
84
- const iv = new Uint8Array(AES_IV_BYTES);
85
- crypto.getRandomValues(iv);
86
- let ciphertext;
87
- try {
88
- const encrypted = await crypto.subtle.encrypt({ name: AES_ALGO, iv: toArrayBuffer(iv) }, opts.sharedKey, toArrayBuffer(opts.plaintext));
89
- const ivAndCipher = new Uint8Array(iv.length + encrypted.byteLength);
90
- ivAndCipher.set(iv);
91
- ivAndCipher.set(new Uint8Array(encrypted), iv.length);
92
- ciphertext = ivAndCipher;
93
- }
94
- catch {
95
- return err('ENCRYPT_FAILED');
96
- }
97
- // SECURITY FIX (v1.1.3): Sign canonical representation of ENTIRE envelope
98
- // (not just payload) to prevent replay attacks via nonce substitution
99
- const timestamp = Date.now();
100
- const envelopeFields = {
101
- v: 1,
102
- alg: 'Ed25519',
103
- sender: opts.senderDid,
104
- recipient: opts.recipientDid,
105
- timestamp,
106
- nonce: toBase64(nonce),
107
- scope: opts.scope,
108
- payload: toBase64(ciphertext),
109
- };
110
- const signedData = createSignedData(envelopeFields);
111
- const sigResult = await ed25519Sign(opts.privateKey, signedData);
112
- if (!sigResult.ok)
113
- return err('SIGN_FAILED');
114
- const envelope = {
115
- ...envelopeFields,
116
- signature: toBase64(sigResult.value),
117
- ...(opts.ephemeralPublicKey
118
- ? { ephemeralPub: toBase64(opts.ephemeralPublicKey) }
119
- : {}),
120
- ...(opts.shareIndex !== undefined
121
- ? {
122
- shareIndex: opts.shareIndex,
123
- shareTotal: opts.shareTotal,
124
- shareThreshold: opts.shareThreshold,
125
- shareGroupId: opts.shareGroupId,
126
- shareHmacKey: opts.shareHmacKey,
127
- shareHmacSig: opts.shareHmacSig,
128
- }
129
- : {}),
130
- protocol: 'PRIVATE.ME/xBind/v3',
131
- documentationUrl: 'https://private.me/docs/xbind.html',
132
- };
133
- return ok(envelope);
134
- }
135
- /* ── V2 Envelope Creation ── */
136
- /**
137
- * Create a signed, encrypted TransportEnvelopeV2 with hybrid KEM.
138
- *
139
- * Same encrypt-then-sign as v1, but includes ML-KEM-768 ciphertext.
140
- */
141
- export async function createEnvelopeV2(opts) {
142
- const nonce = new Uint8Array(NONCE_BYTES);
143
- crypto.getRandomValues(nonce);
144
- const iv = new Uint8Array(AES_IV_BYTES);
145
- crypto.getRandomValues(iv);
146
- let ciphertext;
147
- try {
148
- const encrypted = await crypto.subtle.encrypt({ name: AES_ALGO, iv: toArrayBuffer(iv) }, opts.sharedKey, toArrayBuffer(opts.plaintext));
149
- const ivAndCipher = new Uint8Array(iv.length + encrypted.byteLength);
150
- ivAndCipher.set(iv);
151
- ivAndCipher.set(new Uint8Array(encrypted), iv.length);
152
- ciphertext = ivAndCipher;
153
- }
154
- catch {
155
- return err('ENCRYPT_FAILED');
156
- }
157
- // SECURITY FIX (v1.1.3): Sign canonical representation of ENTIRE envelope
158
- const timestamp = Date.now();
159
- const envelopeFields = {
160
- v: 2,
161
- alg: 'Ed25519',
162
- sender: opts.senderDid,
163
- recipient: opts.recipientDid,
164
- timestamp,
165
- nonce: toBase64(nonce),
166
- scope: opts.scope,
167
- payload: toBase64(ciphertext),
168
- };
169
- const signedData = createSignedData(envelopeFields);
170
- const sigResult = await ed25519Sign(opts.privateKey, signedData);
171
- if (!sigResult.ok)
172
- return err('SIGN_FAILED');
173
- const envelope = {
174
- ...envelopeFields,
175
- kem: 'X25519-MLKEM768',
176
- signature: toBase64(sigResult.value),
177
- ephemeralPub: toBase64(opts.ephemeralPublicKey),
178
- kemCiphertext: toBase64(opts.kemCiphertext),
179
- ...(opts.shareIndex !== undefined
180
- ? {
181
- shareIndex: opts.shareIndex,
182
- shareTotal: opts.shareTotal,
183
- shareThreshold: opts.shareThreshold,
184
- shareGroupId: opts.shareGroupId,
185
- shareHmacKey: opts.shareHmacKey,
186
- shareHmacSig: opts.shareHmacSig,
187
- }
188
- : {}),
189
- protocol: 'PRIVATE.ME/xBind/v3',
190
- documentationUrl: 'https://private.me/docs/xbind.html',
191
- };
192
- return ok(envelope);
193
- }
194
- /* ── V3 Envelope Creation ── */
195
- /**
196
- * Create a signed, encrypted TransportEnvelopeV3 with hybrid KEM + dual signatures.
197
- *
198
- * Encrypt-then-sign: AES-256-GCM encrypts payload, Ed25519 AND ML-DSA-65 sign ciphertext.
199
- * Both signatures must verify for the envelope to be accepted.
200
- */
201
- export async function createEnvelopeV3(opts) {
202
- const nonce = new Uint8Array(NONCE_BYTES);
203
- crypto.getRandomValues(nonce);
204
- const iv = new Uint8Array(AES_IV_BYTES);
205
- crypto.getRandomValues(iv);
206
- let ciphertext;
207
- try {
208
- const encrypted = await crypto.subtle.encrypt({ name: AES_ALGO, iv: toArrayBuffer(iv) }, opts.sharedKey, toArrayBuffer(opts.plaintext));
209
- const ivAndCipher = new Uint8Array(iv.length + encrypted.byteLength);
210
- ivAndCipher.set(iv);
211
- ivAndCipher.set(new Uint8Array(encrypted), iv.length);
212
- ciphertext = ivAndCipher;
213
- }
214
- catch {
215
- return err('ENCRYPT_FAILED');
216
- }
217
- // SECURITY FIX (v1.1.3): Sign canonical representation of ENTIRE envelope
218
- const timestamp = Date.now();
219
- const envelopeFields = {
220
- v: 3,
221
- alg: 'Ed25519',
222
- sender: opts.senderDid,
223
- recipient: opts.recipientDid,
224
- timestamp,
225
- nonce: toBase64(nonce),
226
- scope: opts.scope,
227
- payload: toBase64(ciphertext),
228
- };
229
- const signedData = createSignedData(envelopeFields);
230
- const sigResult = await ed25519Sign(opts.privateKey, signedData);
231
- if (!sigResult.ok)
232
- return err('SIGN_FAILED');
233
- const pqSigResult = await signMlDsa65(opts.mlDsaSecretKey, signedData);
234
- if (!pqSigResult.ok)
235
- return err('PQ_SIGN_FAILED');
236
- const envelope = {
237
- ...envelopeFields,
238
- sig: 'Ed25519+MLDSA65',
239
- kem: 'X25519-MLKEM768',
240
- signature: toBase64(sigResult.value),
241
- pqSignature: toBase64(pqSigResult.value),
242
- ephemeralPub: toBase64(opts.ephemeralPublicKey),
243
- kemCiphertext: toBase64(opts.kemCiphertext),
244
- ...(opts.shareIndex !== undefined
245
- ? {
246
- shareIndex: opts.shareIndex,
247
- shareTotal: opts.shareTotal,
248
- shareThreshold: opts.shareThreshold,
249
- shareGroupId: opts.shareGroupId,
250
- shareHmacKey: opts.shareHmacKey,
251
- shareHmacSig: opts.shareHmacSig,
252
- }
253
- : {}),
254
- protocol: 'PRIVATE.ME/xBind/v3',
255
- documentationUrl: 'https://private.me/docs/xbind.html',
256
- };
257
- return ok(envelope);
258
- }
259
- /* ── Xchange Mode Envelope Creation ── */
260
- /**
261
- * Create a signed Xchange mode envelope (v4 wire format).
262
- *
263
- * Opt-in performance mode. No encryption — the share IS the payload.
264
- * Ed25519 signs the raw share data for sender authentication.
265
- * The XorIDA split provides confidentiality (information-theoretic).
266
- */
267
- export async function createEnvelopeV4(opts) {
268
- const nonce = new Uint8Array(NONCE_BYTES);
269
- crypto.getRandomValues(nonce);
270
- // SECURITY FIX (v1.1.3): Sign canonical representation of ENTIRE envelope
271
- const timestamp = Date.now();
272
- const envelopeFields = {
273
- v: 4,
274
- alg: 'Ed25519',
275
- sender: opts.senderDid,
276
- recipient: opts.recipientDid,
277
- timestamp,
278
- nonce: toBase64(nonce),
279
- scope: opts.scope,
280
- payload: toBase64(opts.shareData),
281
- };
282
- const signedData = createSignedData(envelopeFields);
283
- const sigResult = await ed25519Sign(opts.privateKey, signedData);
284
- if (!sigResult.ok)
285
- return err('SIGN_FAILED');
286
- const envelope = {
287
- ...envelopeFields,
288
- kem: 'Xchange',
289
- signature: toBase64(sigResult.value),
290
- shareIndex: opts.shareIndex,
291
- shareTotal: opts.shareTotal,
292
- shareThreshold: opts.shareThreshold,
293
- shareGroupId: opts.shareGroupId,
294
- shareHmacKey: opts.shareHmacKey,
295
- shareHmacSig: opts.shareHmacSig,
296
- protocol: 'PRIVATE.ME/xBind/v3',
297
- documentationUrl: 'https://private.me/docs/xbind.html',
298
- };
299
- return ok(envelope);
300
- }
301
- /* ── Decryption ── */
302
- /**
303
- * Decrypt the payload from a v1, v2, or v3 TransportEnvelope.
304
- * Caller must verify signature before calling this.
305
- */
306
- export async function decryptPayload(envelope, sharedKey) {
307
- try {
308
- const ciphertext = fromBase64(envelope.payload);
309
- const iv = ciphertext.slice(0, AES_IV_BYTES);
310
- const data = ciphertext.slice(AES_IV_BYTES);
311
- const decrypted = await crypto.subtle.decrypt({ name: AES_ALGO, iv: toArrayBuffer(iv) }, sharedKey, toArrayBuffer(data));
312
- return ok(new Uint8Array(decrypted));
313
- }
314
- catch {
315
- return err('DECRYPT_FAILED');
316
- }
317
- }
318
- /* ── Serialization ── */
319
- /** Serialize envelope to UTF-8 bytes. */
320
- export function serializeEnvelope(envelope) {
321
- return new TextEncoder().encode(JSON.stringify(envelope));
322
- }
323
- /** Deserialize bytes to a validated v1 or v2 TransportEnvelope. */
324
- export function deserializeEnvelope(bytes) {
325
- let parsed;
326
- try {
327
- parsed = JSON.parse(new TextDecoder().decode(bytes));
328
- }
329
- catch {
330
- return err('PARSE_FAILED');
331
- }
332
- return validateEnvelope(parsed);
333
- }
334
- /* ── Validation ── */
335
- /** Validate a parsed object is a valid v1 or v2 TransportEnvelope. */
336
- export function validateEnvelope(obj) {
337
- if (typeof obj !== 'object' || obj === null)
338
- return err('PARSE_FAILED');
339
- const e = obj;
340
- if (e['v'] !== 1 && e['v'] !== 2 && e['v'] !== 3 && e['v'] !== 4)
341
- return err('INVALID_VERSION');
342
- if (e['alg'] !== 'Ed25519')
343
- return err('INVALID_ALG');
344
- if (typeof e['sender'] !== 'string' || !e['sender'].startsWith('did:'))
345
- return err('INVALID_DID');
346
- if (typeof e['recipient'] !== 'string' || !e['recipient'].startsWith('did:'))
347
- return err('INVALID_DID');
348
- if (typeof e['timestamp'] !== 'number')
349
- return err('INVALID_FIELDS');
350
- if (typeof e['scope'] !== 'string')
351
- return err('INVALID_FIELDS');
352
- if (typeof e['payload'] !== 'string')
353
- return err('INVALID_FIELDS');
354
- if (typeof e['signature'] !== 'string')
355
- return err('INVALID_FIELDS');
356
- if (typeof e['nonce'] !== 'string')
357
- return err('INVALID_NONCE');
358
- try {
359
- const nonceBytes = fromBase64(e['nonce']);
360
- if (nonceBytes.length !== NONCE_BYTES)
361
- return err('INVALID_NONCE');
362
- }
363
- catch {
364
- return err('INVALID_NONCE');
365
- }
366
- if (e['ephemeralPub'] !== undefined && typeof e['ephemeralPub'] !== 'string') {
367
- return err('INVALID_FIELDS');
368
- }
369
- // V2-specific validation
370
- if (e['v'] === 2) {
371
- if (e['kem'] !== 'X25519-MLKEM768')
372
- return err('INVALID_KEM');
373
- if (typeof e['ephemeralPub'] !== 'string')
374
- return err('INVALID_FIELDS');
375
- if (typeof e['kemCiphertext'] !== 'string')
376
- return err('INVALID_FIELDS');
377
- try {
378
- const kemBytes = fromBase64(e['kemCiphertext']);
379
- if (kemBytes.length !== KEM_CIPHERTEXT_BYTES)
380
- return err('INVALID_FIELDS');
381
- }
382
- catch {
383
- return err('INVALID_FIELDS');
384
- }
385
- }
386
- // V3-specific validation (hybrid KEM + dual signatures)
387
- if (e['v'] === 3) {
388
- if (e['sig'] !== 'Ed25519+MLDSA65')
389
- return err('INVALID_ALG');
390
- if (e['kem'] !== 'X25519-MLKEM768')
391
- return err('INVALID_KEM');
392
- if (typeof e['ephemeralPub'] !== 'string')
393
- return err('INVALID_FIELDS');
394
- if (typeof e['kemCiphertext'] !== 'string')
395
- return err('INVALID_FIELDS');
396
- if (typeof e['pqSignature'] !== 'string')
397
- return err('INVALID_FIELDS');
398
- try {
399
- const kemBytes = fromBase64(e['kemCiphertext']);
400
- if (kemBytes.length !== KEM_CIPHERTEXT_BYTES)
401
- return err('INVALID_FIELDS');
402
- }
403
- catch {
404
- return err('INVALID_FIELDS');
405
- }
406
- try {
407
- const pqSigBytes = fromBase64(e['pqSignature']);
408
- if (pqSigBytes.length !== ML_DSA65_SIG_BYTES)
409
- return err('INVALID_FIELDS');
410
- }
411
- catch {
412
- return err('INVALID_FIELDS');
413
- }
414
- }
415
- // V4-specific validation (Xchange — no encryption, share metadata required)
416
- if (e['v'] === 4) {
417
- if (e['kem'] !== 'Xchange')
418
- return err('INVALID_KEM');
419
- if (typeof e['shareIndex'] !== 'number')
420
- return err('INVALID_FIELDS');
421
- if (typeof e['shareTotal'] !== 'number')
422
- return err('INVALID_FIELDS');
423
- if (typeof e['shareThreshold'] !== 'number')
424
- return err('INVALID_FIELDS');
425
- if (typeof e['shareGroupId'] !== 'string')
426
- return err('INVALID_FIELDS');
427
- if (typeof e['shareHmacKey'] !== 'string')
428
- return err('INVALID_FIELDS');
429
- if (typeof e['shareHmacSig'] !== 'string')
430
- return err('INVALID_FIELDS');
431
- return ok(e);
432
- }
433
- if (e['shareIndex'] !== undefined && typeof e['shareIndex'] !== 'number') {
434
- return err('INVALID_FIELDS');
435
- }
436
- if (e['shareTotal'] !== undefined && typeof e['shareTotal'] !== 'number') {
437
- return err('INVALID_FIELDS');
438
- }
439
- if (e['shareThreshold'] !== undefined && typeof e['shareThreshold'] !== 'number') {
440
- return err('INVALID_FIELDS');
441
- }
442
- if (e['shareGroupId'] !== undefined && typeof e['shareGroupId'] !== 'string') {
443
- return err('INVALID_FIELDS');
444
- }
445
- if (e['shareHmacKey'] !== undefined && typeof e['shareHmacKey'] !== 'string') {
446
- return err('INVALID_FIELDS');
447
- }
448
- if (e['shareHmacSig'] !== undefined && typeof e['shareHmacSig'] !== 'string') {
449
- return err('INVALID_FIELDS');
450
- }
451
- return ok(e);
452
- }
453
- /** Generate an AES-256-GCM key for envelope encryption. */
454
- export async function generateSharedKey() {
455
- return crypto.subtle.generateKey({ name: AES_ALGO, length: 256 }, true, ['encrypt', 'decrypt']);
456
- }
457
- /* ── Signed (Unencrypted) Envelopes ── */
458
- /**
459
- * Create a signed but unencrypted TransportEnvelope.
460
- *
461
- * Payload is base64-encoded plaintext (NOT encrypted).
462
- * Signature covers the raw plaintext bytes.
463
- * Use for public announcements, audit logs, or telemetry where
464
- * confidentiality is not required but integrity is.
465
- *
466
- * @param opts - Sender, recipient, scope, plaintext, and signing key.
467
- * @returns Signed envelope or error.
468
- */
469
- export async function createSignedEnvelope(opts) {
470
- const nonce = new Uint8Array(NONCE_BYTES);
471
- crypto.getRandomValues(nonce);
472
- const timestamp = Date.now();
473
- const payloadBase64 = toBase64(opts.plaintext);
474
- const nonceBase64 = toBase64(nonce);
475
- // SECURITY FIX (v1.1.3): Sign canonical representation of ENTIRE envelope
476
- // (not just payload) to prevent replay attacks via nonce/timestamp mutation
477
- const envelopeFields = {
478
- v: 1,
479
- alg: 'Ed25519',
480
- sender: opts.senderDid,
481
- recipient: opts.recipientDid,
482
- timestamp,
483
- nonce: nonceBase64,
484
- scope: opts.scope,
485
- payload: payloadBase64,
486
- };
487
- const signedData = createSignedData(envelopeFields);
488
- const sigResult = await ed25519Sign(opts.privateKey, signedData);
489
- if (!sigResult.ok)
490
- return err('SIGN_FAILED');
491
- const envelope = {
492
- ...envelopeFields,
493
- signature: toBase64(sigResult.value),
494
- };
495
- return ok(envelope);
496
- }
497
- /**
498
- * Verify signature on a signed (unencrypted) envelope and return plaintext.
499
- *
500
- * @param envelope - The signed envelope to verify.
501
- * @param senderPublicKey - The sender's Ed25519 public key.
502
- * @returns Plaintext bytes if signature is valid, error otherwise.
503
- */
504
- export async function openSignedEnvelope(envelope, senderPublicKey) {
505
- const payloadBytes = fromBase64(envelope.payload);
506
- const sigBytes = fromBase64(envelope.signature);
507
- // SECURITY FIX (v1.1.3): Verify canonical representation (not just payload)
508
- const canonicalData = JSON.stringify({
509
- v: envelope.v,
510
- alg: envelope.alg,
511
- sender: envelope.sender,
512
- recipient: envelope.recipient,
513
- timestamp: envelope.timestamp,
514
- nonce: envelope.nonce,
515
- scope: envelope.scope,
516
- payload: envelope.payload,
517
- });
518
- const canonicalBytes = new TextEncoder().encode(canonicalData);
519
- const valid = await ed25519Verify(senderPublicKey, sigBytes, canonicalBytes);
520
- if (!valid.ok)
521
- return err('VERIFY_FAILED');
522
- if (!valid.value)
523
- return err('VERIFY_FAILED');
524
- return ok(payloadBytes);
525
- }
1
+ import{ok,err}from"./_deps/shared/index.js";import{toBase64,fromBase64}from"./crypto-utils.js";import{sign as ed25519Sign,verify as ed25519Verify,signMlDsa65}from"./identity.js";const NONCE_BYTES=16,AES_IV_BYTES=12,AES_ALGO="AES-GCM",KEM_CIPHERTEXT_BYTES=1088,ML_DSA65_SIG_BYTES=3309;function toArrayBuffer(e){const r=new ArrayBuffer(e.byteLength);return new Uint8Array(r).set(e),r}function createSignedData(e){const r=JSON.stringify({v:e.v,alg:e.alg,sender:e.sender,recipient:e.recipient,timestamp:e.timestamp,nonce:e.nonce,scope:e.scope,payload:e.payload});return(new TextEncoder).encode(r)}export async function createEnvelope(e){const r=new Uint8Array(16);crypto.getRandomValues(r);const t=new Uint8Array(12);let a;crypto.getRandomValues(t);try{const r=await crypto.subtle.encrypt({name:AES_ALGO,iv:toArrayBuffer(t)},e.sharedKey,toArrayBuffer(e.plaintext)),n=new Uint8Array(t.length+r.byteLength);n.set(t),n.set(new Uint8Array(r),t.length),a=n}catch{return err("ENCRYPT_FAILED")}const n=Date.now(),o={v:1,alg:"Ed25519",sender:e.senderDid,recipient:e.recipientDid,timestamp:n,nonce:toBase64(r),scope:e.scope,payload:toBase64(a)},s=createSignedData(o),i=await ed25519Sign(e.privateKey,s);if(!i.ok)return err("SIGN_FAILED");const c={...o,signature:toBase64(i.value),...e.ephemeralPublicKey?{ephemeralPub:toBase64(e.ephemeralPublicKey)}:{},...void 0!==e.shareIndex?{shareIndex:e.shareIndex,shareTotal:e.shareTotal,shareThreshold:e.shareThreshold,shareGroupId:e.shareGroupId,shareHmacKey:e.shareHmacKey,shareHmacSig:e.shareHmacSig}:{},protocol:"PRIVATE.ME/xBind/v3",documentationUrl:"https://private.me/docs/xbind.html"};return ok(c)}export async function createEnvelopeV2(e){const r=new Uint8Array(16);crypto.getRandomValues(r);const t=new Uint8Array(12);let a;crypto.getRandomValues(t);try{const r=await crypto.subtle.encrypt({name:AES_ALGO,iv:toArrayBuffer(t)},e.sharedKey,toArrayBuffer(e.plaintext)),n=new Uint8Array(t.length+r.byteLength);n.set(t),n.set(new Uint8Array(r),t.length),a=n}catch{return err("ENCRYPT_FAILED")}const n=Date.now(),o={v:2,alg:"Ed25519",sender:e.senderDid,recipient:e.recipientDid,timestamp:n,nonce:toBase64(r),scope:e.scope,payload:toBase64(a)},s=createSignedData(o),i=await ed25519Sign(e.privateKey,s);if(!i.ok)return err("SIGN_FAILED");const c={...o,kem:"X25519-MLKEM768",signature:toBase64(i.value),ephemeralPub:toBase64(e.ephemeralPublicKey),kemCiphertext:toBase64(e.kemCiphertext),...void 0!==e.shareIndex?{shareIndex:e.shareIndex,shareTotal:e.shareTotal,shareThreshold:e.shareThreshold,shareGroupId:e.shareGroupId,shareHmacKey:e.shareHmacKey,shareHmacSig:e.shareHmacSig}:{},protocol:"PRIVATE.ME/xBind/v3",documentationUrl:"https://private.me/docs/xbind.html"};return ok(c)}export async function createEnvelopeV3(e){const r=new Uint8Array(16);crypto.getRandomValues(r);const t=new Uint8Array(12);let a;crypto.getRandomValues(t);try{const r=await crypto.subtle.encrypt({name:AES_ALGO,iv:toArrayBuffer(t)},e.sharedKey,toArrayBuffer(e.plaintext)),n=new Uint8Array(t.length+r.byteLength);n.set(t),n.set(new Uint8Array(r),t.length),a=n}catch{return err("ENCRYPT_FAILED")}const n=Date.now(),o={v:3,alg:"Ed25519",sender:e.senderDid,recipient:e.recipientDid,timestamp:n,nonce:toBase64(r),scope:e.scope,payload:toBase64(a)},s=createSignedData(o),i=await ed25519Sign(e.privateKey,s);if(!i.ok)return err("SIGN_FAILED");const c=await signMlDsa65(e.mlDsaSecretKey,s);if(!c.ok)return err("PQ_SIGN_FAILED");const p={...o,sig:"Ed25519+MLDSA65",kem:"X25519-MLKEM768",signature:toBase64(i.value),pqSignature:toBase64(c.value),ephemeralPub:toBase64(e.ephemeralPublicKey),kemCiphertext:toBase64(e.kemCiphertext),...void 0!==e.shareIndex?{shareIndex:e.shareIndex,shareTotal:e.shareTotal,shareThreshold:e.shareThreshold,shareGroupId:e.shareGroupId,shareHmacKey:e.shareHmacKey,shareHmacSig:e.shareHmacSig}:{},protocol:"PRIVATE.ME/xBind/v3",documentationUrl:"https://private.me/docs/xbind.html"};return ok(p)}export async function createEnvelopeV4(e){const r=new Uint8Array(16);crypto.getRandomValues(r);const t=Date.now(),a={v:4,alg:"Ed25519",sender:e.senderDid,recipient:e.recipientDid,timestamp:t,nonce:toBase64(r),scope:e.scope,payload:toBase64(e.shareData)},n=createSignedData(a),o=await ed25519Sign(e.privateKey,n);if(!o.ok)return err("SIGN_FAILED");const s={...a,kem:"Xchange",signature:toBase64(o.value),shareIndex:e.shareIndex,shareTotal:e.shareTotal,shareThreshold:e.shareThreshold,shareGroupId:e.shareGroupId,shareHmacKey:e.shareHmacKey,shareHmacSig:e.shareHmacSig,protocol:"PRIVATE.ME/xBind/v3",documentationUrl:"https://private.me/docs/xbind.html"};return ok(s)}export async function decryptPayload(e,r){try{const t=fromBase64(e.payload),a=t.slice(0,12),n=t.slice(12),o=await crypto.subtle.decrypt({name:AES_ALGO,iv:toArrayBuffer(a)},r,toArrayBuffer(n));return ok(new Uint8Array(o))}catch{return err("DECRYPT_FAILED")}}export function serializeEnvelope(e){return(new TextEncoder).encode(JSON.stringify(e))}export function deserializeEnvelope(e){let r;try{r=JSON.parse((new TextDecoder).decode(e))}catch{return err("PARSE_FAILED")}return validateEnvelope(r)}export function validateEnvelope(e){if("object"!=typeof e||null===e)return err("PARSE_FAILED");const r=e;if(1!==r.v&&2!==r.v&&3!==r.v&&4!==r.v)return err("INVALID_VERSION");if("Ed25519"!==r.alg)return err("INVALID_ALG");if("string"!=typeof r.sender||!r.sender.startsWith("did:"))return err("INVALID_DID");if("string"!=typeof r.recipient||!r.recipient.startsWith("did:"))return err("INVALID_DID");if("number"!=typeof r.timestamp)return err("INVALID_FIELDS");if("string"!=typeof r.scope)return err("INVALID_FIELDS");if("string"!=typeof r.payload)return err("INVALID_FIELDS");if("string"!=typeof r.signature)return err("INVALID_FIELDS");if("string"!=typeof r.nonce)return err("INVALID_NONCE");try{if(16!==fromBase64(r.nonce).length)return err("INVALID_NONCE")}catch{return err("INVALID_NONCE")}if(void 0!==r.ephemeralPub&&"string"!=typeof r.ephemeralPub)return err("INVALID_FIELDS");if(2===r.v){if("X25519-MLKEM768"!==r.kem)return err("INVALID_KEM");if("string"!=typeof r.ephemeralPub)return err("INVALID_FIELDS");if("string"!=typeof r.kemCiphertext)return err("INVALID_FIELDS");try{if(1088!==fromBase64(r.kemCiphertext).length)return err("INVALID_FIELDS")}catch{return err("INVALID_FIELDS")}}if(3===r.v){if("Ed25519+MLDSA65"!==r.sig)return err("INVALID_ALG");if("X25519-MLKEM768"!==r.kem)return err("INVALID_KEM");if("string"!=typeof r.ephemeralPub)return err("INVALID_FIELDS");if("string"!=typeof r.kemCiphertext)return err("INVALID_FIELDS");if("string"!=typeof r.pqSignature)return err("INVALID_FIELDS");try{if(1088!==fromBase64(r.kemCiphertext).length)return err("INVALID_FIELDS")}catch{return err("INVALID_FIELDS")}try{if(3309!==fromBase64(r.pqSignature).length)return err("INVALID_FIELDS")}catch{return err("INVALID_FIELDS")}}return 4===r.v?"Xchange"!==r.kem?err("INVALID_KEM"):"number"!=typeof r.shareIndex||"number"!=typeof r.shareTotal||"number"!=typeof r.shareThreshold||"string"!=typeof r.shareGroupId||"string"!=typeof r.shareHmacKey||"string"!=typeof r.shareHmacSig?err("INVALID_FIELDS"):ok(r):void 0!==r.shareIndex&&"number"!=typeof r.shareIndex||void 0!==r.shareTotal&&"number"!=typeof r.shareTotal||void 0!==r.shareThreshold&&"number"!=typeof r.shareThreshold||void 0!==r.shareGroupId&&"string"!=typeof r.shareGroupId||void 0!==r.shareHmacKey&&"string"!=typeof r.shareHmacKey||void 0!==r.shareHmacSig&&"string"!=typeof r.shareHmacSig?err("INVALID_FIELDS"):ok(r)}export async function generateSharedKey(){return crypto.subtle.generateKey({name:AES_ALGO,length:256},!0,["encrypt","decrypt"])}export async function createSignedEnvelope(e){const r=new Uint8Array(16);crypto.getRandomValues(r);const t=Date.now(),a=toBase64(e.plaintext),n=toBase64(r),o={v:1,alg:"Ed25519",sender:e.senderDid,recipient:e.recipientDid,timestamp:t,nonce:n,scope:e.scope,payload:a},s=createSignedData(o),i=await ed25519Sign(e.privateKey,s);if(!i.ok)return err("SIGN_FAILED");const c={...o,signature:toBase64(i.value)};return ok(c)}export async function openSignedEnvelope(e,r){const t=fromBase64(e.payload),a=fromBase64(e.signature),n=JSON.stringify({v:e.v,alg:e.alg,sender:e.sender,recipient:e.recipient,timestamp:e.timestamp,nonce:e.nonce,scope:e.scope,payload:e.payload}),o=(new TextEncoder).encode(n),s=await ed25519Verify(r,a,o);return s.ok&&s.value?ok(t):err("VERIFY_FAILED")}
@@ -57,18 +57,28 @@ export declare class VaultStoreError extends XBindError {
57
57
  export declare class QuotaExceededError extends XBindBillingError {
58
58
  /** Upgrade URL for Pro tier */
59
59
  readonly upgradeUrl: string;
60
- constructor(message: string, upgradeUrl?: string);
60
+ constructor(code: string, message: string, upgradeUrl?: string);
61
61
  }
62
62
  /**
63
63
  * Create detailed error information for a given error code.
64
64
  *
65
+ * Implements white paper's "Developer experience focus - structured error details".
66
+ * Every error includes:
67
+ * - code: Machine-readable identifier (e.g., 'INVALID_DID')
68
+ * - message: Human-readable description of the failure
69
+ * - cause: Root cause explanation (from 'hint' field)
70
+ * - resolution: Actionable suggestion for resolution (from 'suggested_action')
71
+ * - field: Specific field that caused the error (when applicable)
72
+ * - docs: Documentation URL for additional context
73
+ *
65
74
  * @param code - Error code (e.g., 'INVALID_DID')
66
- * @param additionalContext - Optional context (field name, custom hint)
67
- * @returns ACIErrorDetail with code, message, hint, field, and docs
75
+ * @param additionalContext - Optional context (field name, custom hint/resolution)
76
+ * @returns ACIErrorDetail with code, message, cause, resolution, field, and docs
68
77
  */
69
78
  export declare function createXBindErrorDetail(code: string, additionalContext?: {
70
79
  field?: string;
71
80
  hint?: string;
81
+ resolution?: string;
72
82
  }): ACIErrorDetail;
73
83
  /**
74
84
  * Convert a string error code to a typed XBindError instance.