@private.me/xbind 1.3.0 → 2.3.4

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 (305) hide show
  1. package/LICENSES.md +212 -0
  2. package/README.md +388 -6
  3. package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1 -1920
  4. package/dist-standalone/_deps/shared/cjs/errors.js +1 -275
  5. package/dist-standalone/_deps/shared/cjs/index.js +1 -138
  6. package/dist-standalone/_deps/shared/cjs/types.js +1 -90
  7. package/dist-standalone/_deps/shared/errors.js +1 -262
  8. package/dist-standalone/_deps/shared/index.js +1 -77
  9. package/dist-standalone/_deps/shared/types.js +1 -91
  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.js +1 -642
  48. package/dist-standalone/agent-sdk.js +1 -328
  49. package/dist-standalone/agent.d.ts +95 -5
  50. package/dist-standalone/agent.js +1 -1545
  51. package/dist-standalone/approval.js +1 -193
  52. package/dist-standalone/async-iterators.d.ts +275 -0
  53. package/dist-standalone/async-iterators.js +1 -0
  54. package/dist-standalone/auth.js +1 -219
  55. package/dist-standalone/auto-accept.js +1 -229
  56. package/dist-standalone/backup-config.js +1 -201
  57. package/dist-standalone/backup.d.ts +114 -0
  58. package/dist-standalone/backup.js +1 -0
  59. package/dist-standalone/batch-operations.d.ts +297 -0
  60. package/dist-standalone/batch-operations.js +1 -0
  61. package/dist-standalone/cancellation.d.ts +301 -0
  62. package/dist-standalone/cancellation.js +1 -0
  63. package/dist-standalone/checkpoint.js +1 -186
  64. package/dist-standalone/circuit-breaker.d.ts +351 -0
  65. package/dist-standalone/circuit-breaker.js +1 -0
  66. package/dist-standalone/cjs/agent-call.js +1 -651
  67. package/dist-standalone/cjs/agent-sdk.js +1 -332
  68. package/dist-standalone/cjs/agent.js +1 -1582
  69. package/dist-standalone/cjs/approval.js +1 -199
  70. package/dist-standalone/cjs/async-iterators.js +1 -0
  71. package/dist-standalone/cjs/auth.js +1 -225
  72. package/dist-standalone/cjs/auto-accept.js +1 -233
  73. package/dist-standalone/cjs/backup-config.js +1 -207
  74. package/dist-standalone/cjs/backup.js +1 -0
  75. package/dist-standalone/cjs/batch-operations.js +1 -0
  76. package/dist-standalone/cjs/cancellation.js +1 -0
  77. package/dist-standalone/cjs/checkpoint.js +1 -193
  78. package/dist-standalone/cjs/circuit-breaker.js +1 -0
  79. package/dist-standalone/cjs/cli/init.js +1 -486
  80. package/dist-standalone/cjs/config-validation.js +1 -0
  81. package/dist-standalone/cjs/connect.js +1 -312
  82. package/dist-standalone/cjs/connection-pool.js +1 -0
  83. package/dist-standalone/cjs/correlation-id.js +1 -339
  84. package/dist-standalone/cjs/crypto-utils.js +1 -0
  85. package/dist-standalone/cjs/debug-mode.js +1 -0
  86. package/dist-standalone/cjs/did-document.js +1 -101
  87. package/dist-standalone/cjs/did-privateme.js +1 -130
  88. package/dist-standalone/cjs/did-web.js +1 -201
  89. package/dist-standalone/cjs/discovery.js +1 -462
  90. package/dist-standalone/cjs/dual-mode.js +1 -251
  91. package/dist-standalone/cjs/email-templates.js +1 -313
  92. package/dist-standalone/cjs/email-transport.js +1 -239
  93. package/dist-standalone/cjs/envelope.js +1 -510
  94. package/dist-standalone/cjs/errors.js +1 -826
  95. package/dist-standalone/cjs/event-emitter.js +1 -0
  96. package/dist-standalone/cjs/gateway-state.js +1 -55
  97. package/dist-standalone/cjs/gateway-transport.js +1 -120
  98. package/dist-standalone/cjs/graceful-degradation.js +1 -0
  99. package/dist-standalone/cjs/guardrails.js +1 -223
  100. package/dist-standalone/cjs/health-check.js +1 -0
  101. package/dist-standalone/cjs/http-compat.js +1 -272
  102. package/dist-standalone/cjs/http-status-map.js +1 -571
  103. package/dist-standalone/cjs/identity.js +1 -541
  104. package/dist-standalone/cjs/index.js +1 -237
  105. package/dist-standalone/cjs/invitation.js +1 -421
  106. package/dist-standalone/cjs/invite.js +1 -328
  107. package/dist-standalone/cjs/key-agreement.js +1 -246
  108. package/dist-standalone/cjs/lazy-init.js +1 -300
  109. package/dist-standalone/cjs/logger.js +1 -0
  110. package/dist-standalone/cjs/mdns-discovery.js +1 -202
  111. package/dist-standalone/cjs/nonce-store.js +1 -66
  112. package/dist-standalone/cjs/pairing-manager.js +1 -223
  113. package/dist-standalone/cjs/plugin-system.js +1 -0
  114. package/dist-standalone/cjs/plugins/logging.js +1 -0
  115. package/dist-standalone/cjs/plugins/metrics.js +1 -0
  116. package/dist-standalone/cjs/plugins/validation.js +1 -0
  117. package/dist-standalone/cjs/policy.js +1 -320
  118. package/dist-standalone/cjs/progress-callbacks.js +1 -0
  119. package/dist-standalone/cjs/redis-nonce-store.js +1 -76
  120. package/dist-standalone/cjs/registry-middleware.js +1 -50
  121. package/dist-standalone/cjs/retry-strategies.js +1 -0
  122. package/dist-standalone/cjs/retry-transport.js +1 -102
  123. package/dist-standalone/cjs/runtime/browser.js +1 -0
  124. package/dist-standalone/cjs/runtime/edge.js +1 -0
  125. package/dist-standalone/cjs/runtime/react-native.js +1 -0
  126. package/dist-standalone/cjs/security-policy.js +1 -245
  127. package/dist-standalone/cjs/serialization.js +1 -0
  128. package/dist-standalone/cjs/split-channel.js +1 -177
  129. package/dist-standalone/cjs/subscription-proof.js +1 -230
  130. package/dist-standalone/cjs/succession.js +1 -148
  131. package/dist-standalone/cjs/timeouts.js +1 -0
  132. package/dist-standalone/cjs/trace-context.js +1 -0
  133. package/dist-standalone/cjs/trace-spans.js +1 -0
  134. package/dist-standalone/cjs/transport.js +1 -63
  135. package/dist-standalone/cjs/trust-registry.js +1 -742
  136. package/dist-standalone/cjs/types/error-response.js +1 -56
  137. package/dist-standalone/cjs/vault-auth.js +1 -0
  138. package/dist-standalone/cjs/vault-store-loader.js +1 -0
  139. package/dist-standalone/cjs/verify.js +1 -25
  140. package/dist-standalone/cjs/version-info.js +1 -0
  141. package/dist-standalone/cjs/xfetch.js +1 -252
  142. package/dist-standalone/cli/init.js +1 -449
  143. package/dist-standalone/cli/setup.js +1 -514
  144. package/dist-standalone/cli/types.js +1 -27
  145. package/dist-standalone/cli/xbind.js +1 -148
  146. package/dist-standalone/config-validation.d.ts +185 -0
  147. package/dist-standalone/config-validation.js +1 -0
  148. package/dist-standalone/connect.js +1 -274
  149. package/dist-standalone/connection-pool.d.ts +251 -0
  150. package/dist-standalone/connection-pool.js +1 -0
  151. package/dist-standalone/correlation-id.js +1 -326
  152. package/dist-standalone/crypto-utils.d.ts +60 -0
  153. package/dist-standalone/crypto-utils.js +1 -0
  154. package/dist-standalone/debug-mode.d.ts +286 -0
  155. package/dist-standalone/debug-mode.js +1 -0
  156. package/dist-standalone/did-document.js +1 -96
  157. package/dist-standalone/did-privateme.js +1 -121
  158. package/dist-standalone/did-web.js +1 -196
  159. package/dist-standalone/discovery.js +1 -458
  160. package/dist-standalone/dual-mode.js +1 -247
  161. package/dist-standalone/email-templates.js +1 -309
  162. package/dist-standalone/email-transport.js +1 -232
  163. package/dist-standalone/envelope.d.ts +29 -1
  164. package/dist-standalone/envelope.js +1 -497
  165. package/dist-standalone/errors.d.ts +10 -0
  166. package/dist-standalone/errors.js +1 -811
  167. package/dist-standalone/event-emitter.d.ts +395 -0
  168. package/dist-standalone/event-emitter.js +1 -0
  169. package/dist-standalone/gateway-state.js +1 -51
  170. package/dist-standalone/gateway-transport.js +1 -116
  171. package/dist-standalone/graceful-degradation.d.ts +246 -0
  172. package/dist-standalone/graceful-degradation.js +1 -0
  173. package/dist-standalone/guardrails.js +1 -216
  174. package/dist-standalone/health-check.d.ts +150 -0
  175. package/dist-standalone/health-check.js +1 -0
  176. package/dist-standalone/http-compat.js +1 -267
  177. package/dist-standalone/http-status-map.js +1 -561
  178. package/dist-standalone/identity.d.ts +64 -1
  179. package/dist-standalone/identity.js +1 -516
  180. package/dist-standalone/index.d.ts +45 -3
  181. package/dist-standalone/index.js +1 -52
  182. package/dist-standalone/invitation.js +1 -415
  183. package/dist-standalone/invite.js +1 -324
  184. package/dist-standalone/key-agreement.d.ts +61 -13
  185. package/dist-standalone/key-agreement.js +1 -236
  186. package/dist-standalone/lazy-init.js +1 -295
  187. package/dist-standalone/logger.d.ts +77 -0
  188. package/dist-standalone/logger.js +1 -0
  189. package/dist-standalone/mdns-discovery.js +1 -195
  190. package/dist-standalone/nonce-store.d.ts +16 -3
  191. package/dist-standalone/nonce-store.js +1 -62
  192. package/dist-standalone/package.json +0 -1
  193. package/dist-standalone/pairing-manager.js +1 -219
  194. package/dist-standalone/plugin-system.d.ts +145 -0
  195. package/dist-standalone/plugin-system.js +1 -0
  196. package/dist-standalone/policy.js +1 -315
  197. package/dist-standalone/progress-callbacks.d.ts +394 -0
  198. package/dist-standalone/progress-callbacks.js +1 -0
  199. package/dist-standalone/redis-nonce-store.js +1 -72
  200. package/dist-standalone/registry-middleware.js +1 -47
  201. package/dist-standalone/retry-strategies.d.ts +382 -0
  202. package/dist-standalone/retry-strategies.js +1 -0
  203. package/dist-standalone/retry-transport.js +1 -98
  204. package/dist-standalone/security-policy.js +1 -239
  205. package/dist-standalone/serialization.d.ts +244 -0
  206. package/dist-standalone/serialization.js +1 -0
  207. package/dist-standalone/split-channel.d.ts +49 -1
  208. package/dist-standalone/split-channel.js +1 -171
  209. package/dist-standalone/subscription-proof.js +1 -224
  210. package/dist-standalone/succession.js +1 -142
  211. package/dist-standalone/timeouts.d.ts +275 -0
  212. package/dist-standalone/timeouts.js +1 -0
  213. package/dist-standalone/trace-context.d.ts +252 -0
  214. package/dist-standalone/trace-context.js +1 -0
  215. package/dist-standalone/trace-spans.d.ts +360 -0
  216. package/dist-standalone/trace-spans.js +1 -0
  217. package/dist-standalone/transport.js +1 -59
  218. package/dist-standalone/trust-registry.d.ts +106 -5
  219. package/dist-standalone/trust-registry.js +1 -702
  220. package/dist-standalone/vault-auth.d.ts +91 -0
  221. package/dist-standalone/vault-auth.js +1 -0
  222. package/dist-standalone/vault-store-loader.d.ts +110 -0
  223. package/dist-standalone/vault-store-loader.js +1 -0
  224. package/dist-standalone/verify.js +1 -16
  225. package/dist-standalone/version-info.d.ts +259 -0
  226. package/dist-standalone/version-info.js +1 -0
  227. package/dist-standalone/xfetch.js +1 -247
  228. package/llms.txt +1 -0
  229. package/package.json +66 -5
  230. package/share1.dat +0 -0
  231. package/dist-standalone/_deps/crypto/base64.d.ts +0 -29
  232. package/dist-standalone/_deps/crypto/base64.js +0 -209
  233. package/dist-standalone/_deps/crypto/cjs/base64.js +0 -103
  234. package/dist-standalone/_deps/crypto/cjs/errors.js +0 -119
  235. package/dist-standalone/_deps/crypto/cjs/hmac.js +0 -71
  236. package/dist-standalone/_deps/crypto/cjs/index.js +0 -86
  237. package/dist-standalone/_deps/crypto/cjs/padding.js +0 -57
  238. package/dist-standalone/_deps/crypto/cjs/share-header.js +0 -68
  239. package/dist-standalone/_deps/crypto/cjs/shares.js +0 -152
  240. package/dist-standalone/_deps/crypto/cjs/tlv.js +0 -199
  241. package/dist-standalone/_deps/crypto/cjs/uuid.js +0 -61
  242. package/dist-standalone/_deps/crypto/cjs/verify.js +0 -24
  243. package/dist-standalone/_deps/crypto/cjs/xorida.js +0 -221
  244. package/dist-standalone/_deps/crypto/errors.d.ts +0 -51
  245. package/dist-standalone/_deps/crypto/errors.js +0 -109
  246. package/dist-standalone/_deps/crypto/hmac.d.ts +0 -39
  247. package/dist-standalone/_deps/crypto/hmac.js +0 -66
  248. package/dist-standalone/_deps/crypto/index.d.ts +0 -20
  249. package/dist-standalone/_deps/crypto/index.js +0 -45
  250. package/dist-standalone/_deps/crypto/padding.d.ts +0 -19
  251. package/dist-standalone/_deps/crypto/padding.js +0 -53
  252. package/dist-standalone/_deps/crypto/share-header.d.ts +0 -44
  253. package/dist-standalone/_deps/crypto/share-header.js +0 -63
  254. package/dist-standalone/_deps/crypto/shares.d.ts +0 -27
  255. package/dist-standalone/_deps/crypto/shares.js +0 -148
  256. package/dist-standalone/_deps/crypto/tlv.d.ts +0 -26
  257. package/dist-standalone/_deps/crypto/tlv.js +0 -195
  258. package/dist-standalone/_deps/crypto/uuid.d.ts +0 -22
  259. package/dist-standalone/_deps/crypto/uuid.js +0 -56
  260. package/dist-standalone/_deps/crypto/verify.d.ts +0 -15
  261. package/dist-standalone/_deps/crypto/verify.js +0 -15
  262. package/dist-standalone/_deps/crypto/xorida.d.ts +0 -44
  263. package/dist-standalone/_deps/crypto/xorida.js +0 -215
  264. package/dist-standalone/_deps/shared/errors.d.ts.map +0 -1
  265. package/dist-standalone/_deps/shared/errors.js.map +0 -1
  266. package/dist-standalone/_deps/shared/index.d.ts.map +0 -1
  267. package/dist-standalone/_deps/shared/index.js.map +0 -1
  268. package/dist-standalone/_deps/shared/types.d.ts.map +0 -1
  269. package/dist-standalone/_deps/shared/types.js.map +0 -1
  270. package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts.map +0 -1
  271. package/dist-standalone/_deps/ux-helpers/cjs/errors.js.map +0 -1
  272. package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts.map +0 -1
  273. package/dist-standalone/_deps/ux-helpers/cjs/index.js.map +0 -1
  274. package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts.map +0 -1
  275. package/dist-standalone/_deps/ux-helpers/cjs/pagination.js.map +0 -1
  276. package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts.map +0 -1
  277. package/dist-standalone/_deps/ux-helpers/cjs/progress.js.map +0 -1
  278. package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts.map +0 -1
  279. package/dist-standalone/_deps/ux-helpers/cjs/search.js.map +0 -1
  280. package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts.map +0 -1
  281. package/dist-standalone/_deps/ux-helpers/cjs/types.js.map +0 -1
  282. package/dist-standalone/_deps/ux-helpers/errors.d.ts.map +0 -1
  283. package/dist-standalone/_deps/ux-helpers/errors.js.map +0 -1
  284. package/dist-standalone/_deps/ux-helpers/index.d.ts.map +0 -1
  285. package/dist-standalone/_deps/ux-helpers/index.js.map +0 -1
  286. package/dist-standalone/_deps/ux-helpers/pagination.d.ts.map +0 -1
  287. package/dist-standalone/_deps/ux-helpers/pagination.js.map +0 -1
  288. package/dist-standalone/_deps/ux-helpers/progress.d.ts.map +0 -1
  289. package/dist-standalone/_deps/ux-helpers/progress.js.map +0 -1
  290. package/dist-standalone/_deps/ux-helpers/search.d.ts.map +0 -1
  291. package/dist-standalone/_deps/ux-helpers/search.js.map +0 -1
  292. package/dist-standalone/_deps/ux-helpers/types.d.ts.map +0 -1
  293. package/dist-standalone/_deps/ux-helpers/types.js.map +0 -1
  294. package/dist-standalone/_deps/xregistry/discovery.d.ts.map +0 -1
  295. package/dist-standalone/_deps/xregistry/discovery.js.map +0 -1
  296. package/dist-standalone/_deps/xregistry/errors.d.ts.map +0 -1
  297. package/dist-standalone/_deps/xregistry/errors.js.map +0 -1
  298. package/dist-standalone/_deps/xregistry/index.d.ts.map +0 -1
  299. package/dist-standalone/_deps/xregistry/index.js.map +0 -1
  300. package/dist-standalone/_deps/xregistry/registry.d.ts.map +0 -1
  301. package/dist-standalone/_deps/xregistry/registry.js.map +0 -1
  302. package/dist-standalone/_deps/xregistry/schema.d.ts.map +0 -1
  303. package/dist-standalone/_deps/xregistry/schema.js.map +0 -1
  304. package/dist-standalone/_deps/xregistry/types.d.ts.map +0 -1
  305. package/dist-standalone/_deps/xregistry/types.js.map +0 -1
@@ -1,39 +0,0 @@
1
- /**
2
- * HMAC-SHA256 integrity verification using Web Crypto API.
3
- *
4
- * Provides message-level integrity for the XorIDA pipeline.
5
- * The HMAC is computed over the padded payload (after TLV serialization + PKCS#7 padding)
6
- * and verified after reconstruction, before unpadding.
7
- *
8
- * Uses crypto.subtle for constant-time verification (no manual byte comparison).
9
- */
10
- /**
11
- * Generate a fresh random HMAC key and sign data with HMAC-SHA256.
12
- *
13
- * @param data - Bytes to sign (the padded payload)
14
- * @returns Object containing the raw key bytes and the 32-byte signature
15
- */
16
- export declare function generateHMAC(data: Uint8Array): Promise<{
17
- key: Uint8Array;
18
- signature: Uint8Array;
19
- }>;
20
- /**
21
- * Verify an HMAC-SHA256 signature using constant-time comparison.
22
- *
23
- * Uses crypto.subtle.verify() which is constant-time by specification.
24
- * NEVER manually compare HMAC bytes (timing attack risk).
25
- *
26
- * @param key - Raw HMAC key bytes (32 bytes)
27
- * @param data - Data that was signed
28
- * @param signature - Expected HMAC-SHA256 signature (32 bytes)
29
- * @returns true if signature is valid, false otherwise
30
- */
31
- export declare function verifyHMAC(key: Uint8Array, data: Uint8Array, signature: Uint8Array): Promise<boolean>;
32
- /**
33
- * Sign data with a provided HMAC key (for cases where the key is already known).
34
- *
35
- * @param key - Raw HMAC key bytes (32 bytes)
36
- * @param data - Bytes to sign
37
- * @returns 32-byte HMAC-SHA256 signature
38
- */
39
- export declare function signHMAC(key: Uint8Array, data: Uint8Array): Promise<Uint8Array>;
@@ -1,66 +0,0 @@
1
- /**
2
- * HMAC-SHA256 integrity verification using Web Crypto API.
3
- *
4
- * Provides message-level integrity for the XorIDA pipeline.
5
- * The HMAC is computed over the padded payload (after TLV serialization + PKCS#7 padding)
6
- * and verified after reconstruction, before unpadding.
7
- *
8
- * Uses crypto.subtle for constant-time verification (no manual byte comparison).
9
- */
10
- /** HMAC key length in bytes. */
11
- const HMAC_KEY_LENGTH = 32;
12
- /** HMAC algorithm config. */
13
- const HMAC_ALGO = { name: 'HMAC', hash: 'SHA-256' };
14
- /** Copy a Uint8Array into a fresh ArrayBuffer (avoids SharedArrayBuffer type issues). */
15
- function toArrayBuffer(data) {
16
- const buf = new ArrayBuffer(data.byteLength);
17
- new Uint8Array(buf).set(data);
18
- return buf;
19
- }
20
- /**
21
- * Import a raw key buffer for HMAC operations.
22
- * Copies to a fresh ArrayBuffer to satisfy Web Crypto API typing.
23
- */
24
- async function importKey(keyBytes, usage) {
25
- return crypto.subtle.importKey('raw', toArrayBuffer(keyBytes), HMAC_ALGO, false, [usage]);
26
- }
27
- /**
28
- * Generate a fresh random HMAC key and sign data with HMAC-SHA256.
29
- *
30
- * @param data - Bytes to sign (the padded payload)
31
- * @returns Object containing the raw key bytes and the 32-byte signature
32
- */
33
- export async function generateHMAC(data) {
34
- const keyBytes = new Uint8Array(HMAC_KEY_LENGTH);
35
- crypto.getRandomValues(keyBytes);
36
- const cryptoKey = await importKey(keyBytes, 'sign');
37
- const sig = await crypto.subtle.sign('HMAC', cryptoKey, toArrayBuffer(data));
38
- return { key: keyBytes, signature: new Uint8Array(sig) };
39
- }
40
- /**
41
- * Verify an HMAC-SHA256 signature using constant-time comparison.
42
- *
43
- * Uses crypto.subtle.verify() which is constant-time by specification.
44
- * NEVER manually compare HMAC bytes (timing attack risk).
45
- *
46
- * @param key - Raw HMAC key bytes (32 bytes)
47
- * @param data - Data that was signed
48
- * @param signature - Expected HMAC-SHA256 signature (32 bytes)
49
- * @returns true if signature is valid, false otherwise
50
- */
51
- export async function verifyHMAC(key, data, signature) {
52
- const cryptoKey = await importKey(key, 'verify');
53
- return crypto.subtle.verify('HMAC', cryptoKey, toArrayBuffer(signature), toArrayBuffer(data));
54
- }
55
- /**
56
- * Sign data with a provided HMAC key (for cases where the key is already known).
57
- *
58
- * @param key - Raw HMAC key bytes (32 bytes)
59
- * @param data - Bytes to sign
60
- * @returns 32-byte HMAC-SHA256 signature
61
- */
62
- export async function signHMAC(key, data) {
63
- const cryptoKey = await importKey(key, 'sign');
64
- const sig = await crypto.subtle.sign('HMAC', cryptoKey, toArrayBuffer(data));
65
- return new Uint8Array(sig);
66
- }
@@ -1,20 +0,0 @@
1
- export * from './errors.js';
2
- export { splitXorIDA, reconstructXorIDA, nextOddPrime } from './xorida.js';
3
- export { pkcs7Pad, pkcs7Unpad } from './padding.js';
4
- export { generateHMAC, verifyHMAC, signHMAC } from './hmac.js';
5
- export { serializeMessage, deserializeMessage } from './tlv.js';
6
- export { generateUUID, uuidToBytes, bytesToUuid } from './uuid.js';
7
- export { toBase64, fromBase64, toBase64Url, fromBase64Url } from './base64.js';
8
- export { createShares, reconstructMessage } from './shares.js';
9
- export { formatShareHeader, parseShareHeader, hasShareHeader } from './share-header.js';
10
- /**
11
- * Check if the runtime supports the required Web Crypto APIs.
12
- *
13
- * Verifies that `crypto.subtle` is available with HMAC, AES-GCM,
14
- * and `crypto.getRandomValues`. Call this before using any crypto
15
- * operations to provide a clear error message on unsupported runtimes.
16
- *
17
- * @returns `true` if the runtime has the required Web Crypto APIs.
18
- */
19
- export declare function isSupported(): boolean;
20
- export { splitWithRandom } from './xorida.js';
@@ -1,45 +0,0 @@
1
- // @private.me/crypto — public API
2
- // Errors
3
- export * from './errors.js';
4
- // XorIDA Threshold Sharing
5
- export { splitXorIDA, reconstructXorIDA, nextOddPrime } from './xorida.js';
6
- // Padding
7
- export { pkcs7Pad, pkcs7Unpad } from './padding.js';
8
- // Integrity
9
- export { generateHMAC, verifyHMAC, signHMAC } from './hmac.js';
10
- // Serialization
11
- export { serializeMessage, deserializeMessage } from './tlv.js';
12
- // UUID
13
- export { generateUUID, uuidToBytes, bytesToUuid } from './uuid.js';
14
- // Base64
15
- export { toBase64, fromBase64, toBase64Url, fromBase64Url } from './base64.js';
16
- // High-level API
17
- export { createShares, reconstructMessage } from './shares.js';
18
- // Branded Share Header (IDA5 copyright layer)
19
- export { formatShareHeader, parseShareHeader, hasShareHeader } from './share-header.js';
20
- // Capability check
21
- /**
22
- * Check if the runtime supports the required Web Crypto APIs.
23
- *
24
- * Verifies that `crypto.subtle` is available with HMAC, AES-GCM,
25
- * and `crypto.getRandomValues`. Call this before using any crypto
26
- * operations to provide a clear error message on unsupported runtimes.
27
- *
28
- * @returns `true` if the runtime has the required Web Crypto APIs.
29
- */
30
- export function isSupported() {
31
- try {
32
- return (typeof globalThis.crypto !== 'undefined' &&
33
- typeof globalThis.crypto.subtle !== 'undefined' &&
34
- typeof globalThis.crypto.subtle.importKey === 'function' &&
35
- typeof globalThis.crypto.subtle.sign === 'function' &&
36
- typeof globalThis.crypto.subtle.verify === 'function' &&
37
- typeof globalThis.crypto.subtle.encrypt === 'function' &&
38
- typeof globalThis.crypto.getRandomValues === 'function');
39
- }
40
- catch {
41
- return false;
42
- }
43
- }
44
- // Re-export for testing (internal, not part of public API contract)
45
- export { splitWithRandom } from './xorida.js';
@@ -1,19 +0,0 @@
1
- import type { Result, PaddingError } from '@private.me/shared';
2
- /**
3
- * PKCS#7 pad data to a multiple of blockSize bytes.
4
- * Always adds at least 1 byte of padding, even when already aligned.
5
- *
6
- * @param data - Input bytes to pad
7
- * @param blockSize - Block size in bytes (must be 1–255)
8
- * @returns Padded byte array
9
- */
10
- export declare function pkcs7Pad(data: Uint8Array, blockSize: number): Uint8Array;
11
- /**
12
- * Remove PKCS#7 padding. Validates that padding bytes are consistent.
13
- * Returns an error if padding is invalid (possible tampering).
14
- *
15
- * @param data - Padded byte array
16
- * @param blockSize - Block size used during padding (must be 1–255)
17
- * @returns Unpadded bytes, or PaddingError if invalid
18
- */
19
- export declare function pkcs7Unpad(data: Uint8Array, blockSize: number): Result<Uint8Array, PaddingError>;
@@ -1,53 +0,0 @@
1
- import { ok, err } from"../shared/index.js";
2
- /**
3
- * PKCS#7 pad data to a multiple of blockSize bytes.
4
- * Always adds at least 1 byte of padding, even when already aligned.
5
- *
6
- * @param data - Input bytes to pad
7
- * @param blockSize - Block size in bytes (must be 1–255)
8
- * @returns Padded byte array
9
- */
10
- export function pkcs7Pad(data, blockSize) {
11
- const padLen = blockSize - (data.length % blockSize);
12
- const padded = new Uint8Array(data.length + padLen);
13
- padded.set(data);
14
- for (let i = data.length; i < padded.length; i++) {
15
- padded[i] = padLen;
16
- }
17
- return padded;
18
- }
19
- /**
20
- * Remove PKCS#7 padding. Validates that padding bytes are consistent.
21
- * Returns an error if padding is invalid (possible tampering).
22
- *
23
- * @param data - Padded byte array
24
- * @param blockSize - Block size used during padding (must be 1–255)
25
- * @returns Unpadded bytes, or PaddingError if invalid
26
- */
27
- export function pkcs7Unpad(data, blockSize) {
28
- if (data.length === 0) {
29
- return err({ code: 'INVALID_PADDING', message: 'Input is empty' });
30
- }
31
- if (data.length % blockSize !== 0) {
32
- return err({
33
- code: 'INVALID_PADDING',
34
- message: 'Input length is not a multiple of block size',
35
- });
36
- }
37
- const padLen = data[data.length - 1];
38
- if (padLen === undefined || padLen < 1 || padLen > blockSize) {
39
- return err({
40
- code: 'INVALID_PADDING',
41
- message: `Invalid padding value: ${padLen}`,
42
- });
43
- }
44
- for (let i = data.length - padLen; i < data.length; i++) {
45
- if (data[i] !== padLen) {
46
- return err({
47
- code: 'INVALID_PADDING',
48
- message: 'Inconsistent padding bytes',
49
- });
50
- }
51
- }
52
- return ok(data.slice(0, data.length - padLen));
53
- }
@@ -1,44 +0,0 @@
1
- /**
2
- * Branded share header — IDA5 copyright layer.
3
- *
4
- * Wraps every XorIDA share output with the patent-locked branded string:
5
- *
6
- * Xecret (TM) -> PRIVATE .ME (R) -> IDA5 -> Encrypted:// [data] => Generated by Xecret (TM)
7
- *
8
- * This provides triple legal protection on every share artifact:
9
- * - Patent (20 years): XorIDA algorithm and split-channel architecture
10
- * - Copyright (95 years): the literal branded header expression
11
- * - Trademark (indefinite): Xecret(TM) and PRIVATE .ME(R) marks
12
- *
13
- * NEVER modify the header format. It is patent-locked.
14
- */
15
- /**
16
- * Wrap share data with the branded IDA5 copyright header.
17
- *
18
- * Output format (patent-locked, NEVER change):
19
- * Xecret (TM) -> PRIVATE .ME (R) -> IDA5 -> Encrypted:// [data] => Generated by Xecret (TM)
20
- *
21
- * @param data - Base64-encoded share data (or any string payload)
22
- * @returns Branded string with copyright header wrapping the data
23
- */
24
- export declare function formatShareHeader(data: string): string;
25
- /**
26
- * Extract share data from a branded IDA5 header string.
27
- *
28
- * Backward-compatible: if the branded markers are not found, returns
29
- * the input string trimmed (handles legacy headerless shares).
30
- *
31
- * @param input - Branded share string or legacy raw data
32
- * @returns Extracted share data with whitespace trimmed
33
- */
34
- export declare function parseShareHeader(input: string): string;
35
- /**
36
- * Check whether a string contains the branded IDA5 share header.
37
- *
38
- * Useful for format detection — distinguishing branded shares from
39
- * legacy raw base64 shares.
40
- *
41
- * @param input - String to check
42
- * @returns true if the branded markers are present
43
- */
44
- export declare function hasShareHeader(input: string): boolean;
@@ -1,63 +0,0 @@
1
- /**
2
- * Branded share header — IDA5 copyright layer.
3
- *
4
- * Wraps every XorIDA share output with the patent-locked branded string:
5
- *
6
- * Xecret (TM) -> PRIVATE .ME (R) -> IDA5 -> Encrypted:// [data] => Generated by Xecret (TM)
7
- *
8
- * This provides triple legal protection on every share artifact:
9
- * - Patent (20 years): XorIDA algorithm and split-channel architecture
10
- * - Copyright (95 years): the literal branded header expression
11
- * - Trademark (indefinite): Xecret(TM) and PRIVATE .ME(R) marks
12
- *
13
- * NEVER modify the header format. It is patent-locked.
14
- */
15
- /** Start marker for the branded share data region. */
16
- const START_MARKER = 'Encrypted://';
17
- /** End marker for the branded share data region. */
18
- const END_MARKER = '=> Generated by Xecret (TM)';
19
- /** Branded prefix before the start marker. */
20
- const BRAND_PREFIX = 'Xecret (TM) -> PRIVATE .ME (R) -> IDA5 -> ';
21
- /**
22
- * Wrap share data with the branded IDA5 copyright header.
23
- *
24
- * Output format (patent-locked, NEVER change):
25
- * Xecret (TM) -> PRIVATE .ME (R) -> IDA5 -> Encrypted:// [data] => Generated by Xecret (TM)
26
- *
27
- * @param data - Base64-encoded share data (or any string payload)
28
- * @returns Branded string with copyright header wrapping the data
29
- */
30
- export function formatShareHeader(data) {
31
- return `${BRAND_PREFIX}${START_MARKER} ${data} ${END_MARKER}`;
32
- }
33
- /**
34
- * Extract share data from a branded IDA5 header string.
35
- *
36
- * Backward-compatible: if the branded markers are not found, returns
37
- * the input string trimmed (handles legacy headerless shares).
38
- *
39
- * @param input - Branded share string or legacy raw data
40
- * @returns Extracted share data with whitespace trimmed
41
- */
42
- export function parseShareHeader(input) {
43
- const startIdx = input.indexOf(START_MARKER);
44
- if (startIdx < 0)
45
- return input.trim();
46
- const dataStart = startIdx + START_MARKER.length;
47
- const endIdx = input.indexOf(END_MARKER, dataStart);
48
- if (endIdx < 0)
49
- return input.trim();
50
- return input.substring(dataStart, endIdx).trim();
51
- }
52
- /**
53
- * Check whether a string contains the branded IDA5 share header.
54
- *
55
- * Useful for format detection — distinguishing branded shares from
56
- * legacy raw base64 shares.
57
- *
58
- * @param input - String to check
59
- * @returns true if the branded markers are present
60
- */
61
- export function hasShareHeader(input) {
62
- return input.includes(START_MARKER) && input.includes(END_MARKER);
63
- }
@@ -1,27 +0,0 @@
1
- /**
2
- * High-level share creation and reconstruction API.
3
- *
4
- * Sender pipeline: serialize (TLV) → pad (PKCS#7) → HMAC (sign) → split (XorIDA)
5
- * Receiver pipeline: reconstruct (XorIDA) → verify (HMAC) → unpad (PKCS#7) → deserialize (TLV)
6
- */
7
- import type { Result, XailMessage, XailShare, ReconstructionError } from '@private.me/shared';
8
- /**
9
- * Create shares from a XailMessage.
10
- *
11
- * Pipeline: serialize → pad → HMAC → split → package as XailShare[]
12
- *
13
- * @param message - The message to split into shares
14
- * @param n - Total number of shares to produce
15
- * @param k - Threshold: minimum shares needed for reconstruction
16
- * @returns Array of n XailShare objects ready for transport
17
- */
18
- export declare function createShares(message: XailMessage, n: number, k: number): Promise<XailShare[]>;
19
- /**
20
- * Reconstruct a XailMessage from k shares.
21
- *
22
- * Pipeline: validate → reconstruct → verify HMAC → unpad → deserialize
23
- *
24
- * @param shares - Array of k XailShare objects (must share the same UUID)
25
- * @returns Reconstructed message, or ReconstructionError
26
- */
27
- export declare function reconstructMessage(shares: readonly XailShare[]): Promise<Result<XailMessage, ReconstructionError>>;
@@ -1,148 +0,0 @@
1
- /**
2
- * High-level share creation and reconstruction API.
3
- *
4
- * Sender pipeline: serialize (TLV) → pad (PKCS#7) → HMAC (sign) → split (XorIDA)
5
- * Receiver pipeline: reconstruct (XorIDA) → verify (HMAC) → unpad (PKCS#7) → deserialize (TLV)
6
- */
7
- import { ok, err } from"../shared/index.js";
8
- import { serializeMessage, deserializeMessage } from './tlv.js';
9
- import { pkcs7Pad, pkcs7Unpad } from './padding.js';
10
- import { generateHMAC, verifyHMAC } from './hmac.js';
11
- import { splitXorIDA, reconstructXorIDA, nextOddPrime } from './xorida.js';
12
- import { generateUUID } from './uuid.js';
13
- /**
14
- * Create shares from a XailMessage.
15
- *
16
- * Pipeline: serialize → pad → HMAC → split → package as XailShare[]
17
- *
18
- * @param message - The message to split into shares
19
- * @param n - Total number of shares to produce
20
- * @param k - Threshold: minimum shares needed for reconstruction
21
- * @returns Array of n XailShare objects ready for transport
22
- */
23
- export async function createShares(message, n, k) {
24
- // Ensure UUID is set before serialization so TLV and share headers match.
25
- const uuid = message.uuid || generateUUID();
26
- const messageWithUuid = uuid !== message.uuid ? { ...message, uuid } : message;
27
- // Step 1: Serialize to TLV
28
- const tlvPayload = serializeMessage(messageWithUuid);
29
- // Step 2: Pad to XorIDA block boundary
30
- const p = nextOddPrime(n);
31
- const blockSize = p - 1;
32
- const padded = pkcs7Pad(tlvPayload, blockSize);
33
- // Step 3: HMAC the padded payload
34
- const { key: hmacKey, signature: hmacSignature } = await generateHMAC(padded);
35
- // Step 4: Split via XorIDA
36
- const shareDataArrays = splitXorIDA(padded, n, k);
37
- const shares = shareDataArrays.map((data, index) => ({
38
- uuid,
39
- index,
40
- totalShares: n,
41
- threshold: k,
42
- data,
43
- hmacKey: hmacKey.slice(), // each share carries a copy
44
- hmacSignature: hmacSignature.slice(),
45
- }));
46
- return shares;
47
- }
48
- /**
49
- * Reconstruct a XailMessage from k shares.
50
- *
51
- * Pipeline: validate → reconstruct → verify HMAC → unpad → deserialize
52
- *
53
- * @param shares - Array of k XailShare objects (must share the same UUID)
54
- * @returns Reconstructed message, or ReconstructionError
55
- */
56
- export async function reconstructMessage(shares) {
57
- // Validation: need at least k shares
58
- if (shares.length === 0) {
59
- return err({ code: 'INSUFFICIENT_SHARES', message: 'No shares provided' });
60
- }
61
- const first = shares[0];
62
- const k = first.threshold;
63
- const n = first.totalShares;
64
- if (shares.length < k) {
65
- return err({
66
- code: 'INSUFFICIENT_SHARES',
67
- message: `Need ${k} shares, got ${shares.length}`,
68
- });
69
- }
70
- // Validate consistency
71
- const indices = [];
72
- const indexSet = new Set();
73
- for (const share of shares) {
74
- if (share.uuid !== first.uuid) {
75
- return err({
76
- code: 'INVALID_SHARES',
77
- message: 'Shares have different UUIDs',
78
- });
79
- }
80
- if (share.totalShares !== n || share.threshold !== k) {
81
- return err({
82
- code: 'INVALID_SHARES',
83
- message: 'Shares have inconsistent n/k values',
84
- });
85
- }
86
- if (share.index < 0 || share.index >= n) {
87
- return err({
88
- code: 'INVALID_INDEX',
89
- message: `Share index ${share.index} out of range [0, ${n})`,
90
- });
91
- }
92
- if (indexSet.has(share.index)) {
93
- return err({
94
- code: 'INVALID_INDEX',
95
- message: `Duplicate share index ${share.index}`,
96
- });
97
- }
98
- indexSet.add(share.index);
99
- indices.push(share.index);
100
- }
101
- // Take first k shares
102
- const usedShares = shares.slice(0, k);
103
- const usedIndices = indices.slice(0, k);
104
- const shareData = usedShares.map((s) => s.data);
105
- // Step 1: Reconstruct padded payload
106
- const padded = reconstructXorIDA(shareData, usedIndices, n, k);
107
- // Step 2: Verify HMAC (before unpadding — fail closed)
108
- const hmacValid = await verifyHMAC(first.hmacKey, padded, first.hmacSignature);
109
- if (!hmacValid) {
110
- return err({
111
- code: 'HMAC_FAILURE',
112
- message: 'HMAC verification failed — data may be corrupted or tampered',
113
- });
114
- }
115
- // Step 3: Unpad
116
- const p = nextOddPrime(n);
117
- const blockSize = p - 1;
118
- const unpadResult = pkcs7Unpad(padded, blockSize);
119
- if (!unpadResult.ok) {
120
- return err({
121
- code: 'HMAC_FAILURE',
122
- message: `Unpadding failed: ${unpadResult.error.message}`,
123
- });
124
- }
125
- // Step 4: Deserialize TLV
126
- const msgResult = deserializeMessage(unpadResult.value);
127
- if (!msgResult.ok) {
128
- return err({
129
- code: 'INVALID_SHARES',
130
- message: `Deserialization failed: ${msgResult.error.message}`,
131
- });
132
- }
133
- // UUID cross-check: if the TLV payload contains a UUID, it must match the envelope UUID.
134
- // Normalize both to lowercase+trimmed — bytesToUuid() always returns lowercase,
135
- // but envelope UUIDs from email headers may differ in casing or have whitespace.
136
- const tlvUuid = msgResult.value.uuid;
137
- if (tlvUuid && tlvUuid.toLowerCase().trim() !== first.uuid.toLowerCase().trim()) {
138
- return err({
139
- code: 'UUID_MISMATCH',
140
- message: 'TLV UUID does not match envelope UUID',
141
- });
142
- }
143
- // The share headers carry the authoritative UUID (X-Xail-UUID).
144
- // The TLV payload may have a stale or empty UUID if the sender didn't
145
- // pre-populate message.uuid before calling createShares(). Stamp the
146
- // share-header UUID onto the reconstructed message.
147
- return ok({ ...msgResult.value, uuid: first.uuid });
148
- }
@@ -1,26 +0,0 @@
1
- /**
2
- * TLV (Type-Length-Value) serialization for Xail messages.
3
- *
4
- * Format: [Type: 1 byte][Length: 4 bytes uint32 BE][Value: Length bytes]
5
- *
6
- * Serialization order: MESSAGE_UUID, SENDER_ID, TIMESTAMP, CONTENT_TYPE,
7
- * MESSAGE_BODY, ATTACHMENT(s).
8
- *
9
- * HMAC key/signature and per-share metadata are NOT in the TLV payload —
10
- * they travel in the share envelope.
11
- */
12
- import type { Result, SerializationError, XailMessage } from '@private.me/shared';
13
- /**
14
- * Serialize a XailMessage into a TLV byte stream.
15
- *
16
- * @param message - Message to serialize
17
- * @returns TLV-encoded byte array
18
- */
19
- export declare function serializeMessage(message: XailMessage): Uint8Array;
20
- /**
21
- * Deserialize a TLV byte stream into a XailMessage.
22
- *
23
- * @param data - TLV-encoded byte array
24
- * @returns Deserialized message, or SerializationError if invalid
25
- */
26
- export declare function deserializeMessage(data: Uint8Array): Result<XailMessage, SerializationError>;