@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,199 +0,0 @@
1
- "use strict";
2
- /**
3
- * TLV (Type-Length-Value) serialization for Xail messages.
4
- *
5
- * Format: [Type: 1 byte][Length: 4 bytes uint32 BE][Value: Length bytes]
6
- *
7
- * Serialization order: MESSAGE_UUID, SENDER_ID, TIMESTAMP, CONTENT_TYPE,
8
- * MESSAGE_BODY, ATTACHMENT(s).
9
- *
10
- * HMAC key/signature and per-share metadata are NOT in the TLV payload —
11
- * they travel in the share envelope.
12
- */
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.serializeMessage = serializeMessage;
15
- exports.deserializeMessage = deserializeMessage;
16
- const shared_1 = require("../../shared/index.js");
17
- const uuid_js_1 = require("./uuid.js");
18
- const TEXT_ENCODER = new TextEncoder();
19
- const TEXT_DECODER = new TextDecoder();
20
- /**
21
- * Serialize a XailMessage into a TLV byte stream.
22
- *
23
- * @param message - Message to serialize
24
- * @returns TLV-encoded byte array
25
- */
26
- function serializeMessage(message) {
27
- const parts = [];
28
- // MESSAGE_UUID
29
- parts.push(encodeTlv(shared_1.TLV_TYPE.MESSAGE_UUID, (0, uuid_js_1.uuidToBytes)(message.uuid)));
30
- // SENDER_ID
31
- parts.push(encodeTlv(shared_1.TLV_TYPE.SENDER_ID, TEXT_ENCODER.encode(message.sender.name)));
32
- // SENDER_EMAIL (optional — preserves sender's email across reconstruction)
33
- const senderEmail = message.sender.channels[0]?.email;
34
- if (senderEmail) {
35
- parts.push(encodeTlv(shared_1.TLV_TYPE.SENDER_EMAIL, TEXT_ENCODER.encode(senderEmail)));
36
- }
37
- // TIMESTAMP (8 bytes, uint64 big-endian)
38
- const tsBuf = new Uint8Array(8);
39
- const tsView = new DataView(tsBuf.buffer);
40
- // Split into high 32 and low 32 bits
41
- tsView.setUint32(0, Math.floor(message.timestamp / 0x100000000));
42
- tsView.setUint32(4, message.timestamp >>> 0);
43
- parts.push(encodeTlv(shared_1.TLV_TYPE.TIMESTAMP, tsBuf));
44
- // CONTENT_TYPE
45
- parts.push(encodeTlv(shared_1.TLV_TYPE.CONTENT_TYPE, TEXT_ENCODER.encode(message.contentType)));
46
- // MESSAGE_SUBJECT (optional)
47
- if (message.subject) {
48
- parts.push(encodeTlv(shared_1.TLV_TYPE.MESSAGE_SUBJECT, TEXT_ENCODER.encode(message.subject)));
49
- }
50
- // MESSAGE_BODY
51
- parts.push(encodeTlv(shared_1.TLV_TYPE.MESSAGE_BODY, TEXT_ENCODER.encode(message.body)));
52
- // ATTACHMENTs
53
- for (const att of message.attachments) {
54
- parts.push(encodeTlv(shared_1.TLV_TYPE.ATTACHMENT, encodeAttachment(att)));
55
- }
56
- // Concatenate all parts
57
- const totalLen = parts.reduce((sum, p) => sum + p.length, 0);
58
- const result = new Uint8Array(totalLen);
59
- let offset = 0;
60
- for (const part of parts) {
61
- result.set(part, offset);
62
- offset += part.length;
63
- }
64
- return result;
65
- }
66
- /**
67
- * Deserialize a TLV byte stream into a XailMessage.
68
- *
69
- * @param data - TLV-encoded byte array
70
- * @returns Deserialized message, or SerializationError if invalid
71
- */
72
- function deserializeMessage(data) {
73
- let uuid = '';
74
- let senderName = '';
75
- let senderEmail = '';
76
- let subject = '';
77
- let timestamp = 0;
78
- let contentType = 'text/plain';
79
- let body = '';
80
- const attachments = [];
81
- let offset = 0;
82
- while (offset < data.length) {
83
- if (offset + 5 > data.length) {
84
- return (0, shared_1.err)({ code: 'INVALID_TLV', message: 'Truncated TLV header' });
85
- }
86
- const type = data[offset];
87
- const view = new DataView(data.buffer, data.byteOffset + offset + 1, 4);
88
- const length = view.getUint32(0);
89
- offset += 5;
90
- if (offset + length > data.length) {
91
- return (0, shared_1.err)({ code: 'BUFFER_OVERFLOW', message: `TLV value exceeds data length at type 0x${type.toString(16)}` });
92
- }
93
- const value = data.slice(offset, offset + length);
94
- offset += length;
95
- switch (type) {
96
- case shared_1.TLV_TYPE.MESSAGE_UUID:
97
- if (value.length !== 16) {
98
- return (0, shared_1.err)({ code: 'INVALID_TLV', message: 'UUID must be 16 bytes' });
99
- }
100
- uuid = (0, uuid_js_1.bytesToUuid)(value);
101
- break;
102
- case shared_1.TLV_TYPE.SENDER_ID:
103
- senderName = TEXT_DECODER.decode(value);
104
- break;
105
- case shared_1.TLV_TYPE.SENDER_EMAIL:
106
- senderEmail = TEXT_DECODER.decode(value);
107
- break;
108
- case shared_1.TLV_TYPE.TIMESTAMP: {
109
- if (value.length !== 8) {
110
- return (0, shared_1.err)({ code: 'INVALID_TLV', message: 'Timestamp must be 8 bytes' });
111
- }
112
- const tsView = new DataView(value.buffer, value.byteOffset, 8);
113
- const hi = tsView.getUint32(0);
114
- const lo = tsView.getUint32(4);
115
- timestamp = hi * 0x100000000 + lo;
116
- break;
117
- }
118
- case shared_1.TLV_TYPE.CONTENT_TYPE: {
119
- const ct = TEXT_DECODER.decode(value);
120
- if (ct === 'text/plain' || ct === 'text/html') {
121
- contentType = ct;
122
- }
123
- break;
124
- }
125
- case shared_1.TLV_TYPE.MESSAGE_SUBJECT:
126
- subject = TEXT_DECODER.decode(value);
127
- break;
128
- case shared_1.TLV_TYPE.MESSAGE_BODY:
129
- body = TEXT_DECODER.decode(value);
130
- break;
131
- case shared_1.TLV_TYPE.ATTACHMENT:
132
- attachments.push(decodeAttachment(value));
133
- break;
134
- default:
135
- // Unknown type — skip (forward compatibility)
136
- break;
137
- }
138
- }
139
- if (!uuid) {
140
- return (0, shared_1.err)({ code: 'MISSING_FIELD', message: 'Missing MESSAGE_UUID' });
141
- }
142
- return (0, shared_1.ok)({
143
- uuid,
144
- sender: {
145
- name: senderName,
146
- channels: senderEmail
147
- ? [{ provider: 'imap', email: senderEmail }]
148
- : [],
149
- securityTier: null,
150
- isEnterprise: false,
151
- },
152
- recipients: [],
153
- ...(subject ? { subject } : {}),
154
- body,
155
- contentType,
156
- attachments,
157
- timestamp,
158
- messageType: 'secure',
159
- });
160
- }
161
- /** Encode a single TLV entry. */
162
- function encodeTlv(type, value) {
163
- const entry = new Uint8Array(5 + value.length);
164
- entry[0] = type;
165
- const view = new DataView(entry.buffer, 1, 4);
166
- view.setUint32(0, value.length);
167
- entry.set(value, 5);
168
- return entry;
169
- }
170
- /**
171
- * Encode an attachment: filename (null-terminated, up to 255 bytes) + content.
172
- */
173
- function encodeAttachment(att) {
174
- const nameBytes = TEXT_ENCODER.encode(att.filename);
175
- const mimeBytes = TEXT_ENCODER.encode(att.mimeType);
176
- // Format: [nameLen:1][name][mimeLen:1][mime][data]
177
- const result = new Uint8Array(1 + nameBytes.length + 1 + mimeBytes.length + att.data.length);
178
- let off = 0;
179
- result[off++] = nameBytes.length;
180
- result.set(nameBytes, off);
181
- off += nameBytes.length;
182
- result[off++] = mimeBytes.length;
183
- result.set(mimeBytes, off);
184
- off += mimeBytes.length;
185
- result.set(att.data, off);
186
- return result;
187
- }
188
- /** Decode an attachment from the encoded format. */
189
- function decodeAttachment(data) {
190
- let off = 0;
191
- const nameLen = data[off++];
192
- const filename = TEXT_DECODER.decode(data.slice(off, off + nameLen));
193
- off += nameLen;
194
- const mimeLen = data[off++];
195
- const mimeType = TEXT_DECODER.decode(data.slice(off, off + mimeLen));
196
- off += mimeLen;
197
- const content = data.slice(off);
198
- return { filename, mimeType, data: content };
199
- }
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateUUID = generateUUID;
4
- exports.uuidToBytes = uuidToBytes;
5
- exports.bytesToUuid = bytesToUuid;
6
- /**
7
- * Generate a RFC 4122 Version 4 UUID (128-bit random).
8
- * Uses crypto.randomUUID() when available, otherwise constructs manually
9
- * from crypto.getRandomValues() with proper version/variant bits.
10
- *
11
- * @returns UUID string in standard 8-4-4-4-12 hex format
12
- */
13
- function generateUUID() {
14
- if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
15
- return crypto.randomUUID();
16
- }
17
- const bytes = new Uint8Array(16);
18
- crypto.getRandomValues(bytes);
19
- // Set version 4 (bits 12-15 of time_hi_and_version)
20
- bytes[6] = (bytes[6] & 0x0f) | 0x40;
21
- // Set variant 10xx (bits 6-7 of clock_seq_hi_and_reserved)
22
- bytes[8] = (bytes[8] & 0x3f) | 0x80;
23
- const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');
24
- return [
25
- hex.slice(0, 8),
26
- hex.slice(8, 12),
27
- hex.slice(12, 16),
28
- hex.slice(16, 20),
29
- hex.slice(20, 32),
30
- ].join('-');
31
- }
32
- /**
33
- * Parse a UUID string into its raw 16 bytes.
34
- *
35
- * @param uuid - UUID string in 8-4-4-4-12 hex format
36
- * @returns 16-byte Uint8Array
37
- */
38
- function uuidToBytes(uuid) {
39
- const hex = uuid.replace(/-/g, '');
40
- const bytes = new Uint8Array(16);
41
- for (let i = 0; i < 16; i++) {
42
- bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
43
- }
44
- return bytes;
45
- }
46
- /**
47
- * Convert raw 16 UUID bytes to the standard string format.
48
- *
49
- * @param bytes - 16-byte Uint8Array
50
- * @returns UUID string in 8-4-4-4-12 hex format
51
- */
52
- function bytesToUuid(bytes) {
53
- const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');
54
- return [
55
- hex.slice(0, 8),
56
- hex.slice(8, 12),
57
- hex.slice(12, 16),
58
- hex.slice(16, 20),
59
- hex.slice(20, 32),
60
- ].join('-');
61
- }
@@ -1,24 +0,0 @@
1
- "use strict";
2
- /**
3
- * @module verify
4
- * Lightweight sub-path export for verification-only use cases.
5
- *
6
- * Import as `@private.me/crypto/verify` for tree-shaking:
7
- * ```ts
8
- * import { verifyHMAC, fromBase64, isSupported } from '@private.me/crypto/verify';
9
- * ```
10
- *
11
- * This module re-exports only HMAC verification, base64 decoding,
12
- * and the capability check — no splitting, no reconstruction, no padding.
13
- */
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.isSupported = exports.toBase64Url = exports.fromBase64Url = exports.toBase64 = exports.fromBase64 = exports.verifyHMAC = void 0;
16
- var hmac_js_1 = require("./hmac.js");
17
- Object.defineProperty(exports, "verifyHMAC", { enumerable: true, get: function () { return hmac_js_1.verifyHMAC; } });
18
- var base64_js_1 = require("./base64.js");
19
- Object.defineProperty(exports, "fromBase64", { enumerable: true, get: function () { return base64_js_1.fromBase64; } });
20
- Object.defineProperty(exports, "toBase64", { enumerable: true, get: function () { return base64_js_1.toBase64; } });
21
- Object.defineProperty(exports, "fromBase64Url", { enumerable: true, get: function () { return base64_js_1.fromBase64Url; } });
22
- Object.defineProperty(exports, "toBase64Url", { enumerable: true, get: function () { return base64_js_1.toBase64Url; } });
23
- var index_js_1 = require("./index.js");
24
- Object.defineProperty(exports, "isSupported", { enumerable: true, get: function () { return index_js_1.isSupported; } });
@@ -1,221 +0,0 @@
1
- "use strict";
2
- /**
3
- * XorIDA Threshold Secret Sharing over GF(2).
4
- *
5
- * Proprietary, patent-protected (k,n)-threshold secret sharing construction.
6
- *
7
- * All arithmetic is XOR (GF(2)). The generator matrix is constructed from a cyclic
8
- * index formula using NextOddPrime(n). Any k-of-n shares reconstruct the original
9
- * message via Gaussian elimination on the restricted generator matrix.
10
- */
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.nextOddPrime = nextOddPrime;
13
- exports.splitXorIDA = splitXorIDA;
14
- exports.splitWithRandom = splitWithRandom;
15
- exports.reconstructXorIDA = reconstructXorIDA;
16
- /**
17
- * Find the smallest odd prime >= n.
18
- * Used to determine the cyclic group Z_p for generator matrix construction.
19
- *
20
- * @param n - Total number of shares
21
- * @returns Smallest odd prime >= n
22
- */
23
- function nextOddPrime(n) {
24
- let i = n;
25
- while (true) {
26
- if (i >= 2 && isOddPrime(i))
27
- return i;
28
- i++;
29
- }
30
- }
31
- /** Max bytes per crypto.getRandomValues call (Web Crypto API limit). */
32
- const MAX_RANDOM_CHUNK = 65536;
33
- /** Fill a Uint8Array with cryptographic random bytes, chunked to respect API limits. */
34
- function fillRandom(arr) {
35
- for (let offset = 0; offset < arr.length; offset += MAX_RANDOM_CHUNK) {
36
- const end = Math.min(offset + MAX_RANDOM_CHUNK, arr.length);
37
- crypto.getRandomValues(arr.subarray(offset, end));
38
- }
39
- }
40
- /** Check if a number is an odd prime. */
41
- function isOddPrime(n) {
42
- if (n < 2)
43
- return false;
44
- if (n === 2)
45
- return false; // even
46
- if (n === 3)
47
- return true;
48
- if (n % 2 === 0)
49
- return false;
50
- for (let d = 3; d * d <= n; d += 2) {
51
- if (n % d === 0)
52
- return false;
53
- }
54
- return true;
55
- }
56
- /**
57
- * Split a padded message into n shares using XorIDA threshold sharing.
58
- *
59
- * The message length must be a multiple of b = NextOddPrime(n) - 1.
60
- * Each share is the same length as the input message.
61
- *
62
- * @param paddedMessage - PKCS#7-padded message (length must be multiple of b)
63
- * @param n - Total number of shares to produce
64
- * @param k - Threshold: minimum shares needed for reconstruction
65
- * @returns Array of n shares, each the same length as paddedMessage
66
- */
67
- function splitXorIDA(paddedMessage, n, k) {
68
- const p = nextOddPrime(n);
69
- const b = p - 1;
70
- if (paddedMessage.length === 0 || paddedMessage.length % b !== 0) {
71
- throw new Error(`Message length ${paddedMessage.length} is not a multiple of block size ${b}`);
72
- }
73
- return splitWithRandom(paddedMessage, n, k, p, b);
74
- }
75
- /**
76
- * Split with externally provided random source arrays (for testing with known vectors).
77
- * @internal Exported for testing only.
78
- */
79
- function splitWithRandom(paddedMessage, n, k, p, b, randomArrays) {
80
- const msgLen = paddedMessage.length;
81
- const numBlocks = msgLen / b;
82
- // Step 1: Create k source arrays — (k-1) random + message
83
- const sourceArrays = [];
84
- for (let i = 0; i < k - 1; i++) {
85
- const provided = randomArrays?.[i];
86
- if (provided) {
87
- sourceArrays.push(provided);
88
- }
89
- else {
90
- const rand = new Uint8Array(msgLen);
91
- fillRandom(rand);
92
- sourceArrays.push(rand);
93
- }
94
- }
95
- sourceArrays.push(paddedMessage);
96
- // Step 2: Construct each share using the generator matrix index formula
97
- const shares = [];
98
- for (let shareIdx = 0; shareIdx < n; shareIdx++) {
99
- const share = new Uint8Array(msgLen);
100
- for (let blockIdx = 0; blockIdx < numBlocks; blockIdx++) {
101
- const blockOffset = blockIdx * b;
102
- for (let destRow = 0; destRow < b; destRow++) {
103
- for (let srcCol = 0; srcCol < k; srcCol++) {
104
- const srcRow = (destRow + shareIdx * srcCol) % p;
105
- if (srcRow < b) {
106
- share[blockOffset + destRow] ^=
107
- sourceArrays[srcCol][blockOffset + srcRow];
108
- }
109
- }
110
- }
111
- }
112
- shares.push(share);
113
- }
114
- return shares;
115
- }
116
- /**
117
- * Reconstruct the padded message from k shares via GF(2) Gaussian elimination.
118
- *
119
- * @param shares - Array of k share byte arrays
120
- * @param indices - Original indices (0-based) of the provided shares
121
- * @param n - Total number of shares that were produced
122
- * @param k - Threshold used during splitting
123
- * @returns Reconstructed padded message
124
- */
125
- function reconstructXorIDA(shares, indices, n, k) {
126
- if (shares.length !== k || indices.length !== k) {
127
- throw new Error(`Expected ${k} shares, got ${shares.length}`);
128
- }
129
- const p = nextOddPrime(n);
130
- const b = p - 1;
131
- const shareLen = shares[0].length;
132
- const numBlocks = shareLen / b;
133
- // Step 1: Build restricted generator matrix G (k*b rows × k*b cols)
134
- const numRows = k * b;
135
- const numCols = k * b;
136
- const recoveryMatrix = buildAndSolve(indices, k, p, b, numRows, numCols);
137
- // Step 2: Apply recovery matrix to extract message bytes
138
- const result = new Uint8Array(shareLen);
139
- for (let blockIdx = 0; blockIdx < numBlocks; blockIdx++) {
140
- const blockOffset = blockIdx * b;
141
- for (let destByte = 0; destByte < b; destByte++) {
142
- // Skip random rows, use message rows: row index = (k-1)*b + destByte
143
- const recoveryRow = (k - 1) * b + destByte;
144
- let val = 0;
145
- for (let c = 0; c < numRows; c++) {
146
- if (recoveryMatrix[recoveryRow][c]) {
147
- const localShareIdx = Math.floor(c / b);
148
- const byteInBlock = c % b;
149
- val ^= shares[localShareIdx][blockOffset + byteInBlock];
150
- }
151
- }
152
- result[blockOffset + destByte] = val;
153
- }
154
- }
155
- return result;
156
- }
157
- /**
158
- * Build the restricted generator matrix and solve via Gaussian elimination.
159
- * Returns the recovery matrix (right portion of [G|I] after elimination).
160
- */
161
- function buildAndSolve(shareIndices, k, p, b, numRows, numCols) {
162
- // Build augmented matrix [G | I] using Uint8Array rows
163
- const totalCols = numCols + numRows;
164
- const aug = [];
165
- for (let i = 0; i < k; i++) {
166
- const shareIdx = shareIndices[i];
167
- for (let rowInShare = 0; rowInShare < b; rowInShare++) {
168
- const row = new Uint8Array(totalCols);
169
- const destRow = i * b + rowInShare;
170
- // Fill generator matrix portion
171
- for (let srcCol = 0; srcCol < k; srcCol++) {
172
- const srcRow = (rowInShare + shareIdx * srcCol) % p;
173
- if (srcRow < b) {
174
- row[srcCol * b + srcRow] = 1;
175
- }
176
- }
177
- // Fill identity portion
178
- row[numCols + destRow] = 1;
179
- aug.push(row);
180
- }
181
- }
182
- // Gaussian elimination over GF(2)
183
- let pivotRow = 0;
184
- for (let col = 0; col < numCols; col++) {
185
- // Find pivot
186
- let found = -1;
187
- for (let r = pivotRow; r < numRows; r++) {
188
- if (aug[r][col]) {
189
- found = r;
190
- break;
191
- }
192
- }
193
- if (found === -1)
194
- continue;
195
- // Swap
196
- if (found !== pivotRow) {
197
- const tmp = aug[found];
198
- aug[found] = aug[pivotRow];
199
- aug[pivotRow] = tmp;
200
- }
201
- // Eliminate
202
- for (let r = 0; r < numRows; r++) {
203
- if (r !== pivotRow && aug[r][col]) {
204
- xorRow(aug[r], aug[pivotRow]);
205
- }
206
- }
207
- pivotRow++;
208
- }
209
- // Extract recovery matrix (right portion)
210
- const recovery = [];
211
- for (let r = 0; r < numRows; r++) {
212
- recovery.push(aug[r].slice(numCols));
213
- }
214
- return recovery;
215
- }
216
- /** XOR row b into row a (in-place). */
217
- function xorRow(a, b) {
218
- for (let i = 0; i < a.length; i++) {
219
- a[i] ^= b[i];
220
- }
221
- }
@@ -1,51 +0,0 @@
1
- /**
2
- * @module errors
3
- * Named error class hierarchy for @private.me/crypto.
4
- *
5
- * Provides structured error types for XorIDA threshold sharing,
6
- * HMAC integrity verification, PKCS#7 padding, and TLV serialization.
7
- */
8
- /** Base error class for all crypto operations. */
9
- export declare class CryptoError extends Error {
10
- readonly code: string;
11
- readonly subCode?: string;
12
- readonly docUrl?: string;
13
- constructor(code: string, message: string, docUrl?: string);
14
- }
15
- /** Error thrown during XorIDA split or reconstruction operations. */
16
- export declare class CryptoSplitError extends CryptoError {
17
- constructor(code: string, message: string);
18
- }
19
- /** Error thrown when HMAC integrity verification fails. */
20
- export declare class CryptoIntegrityError extends CryptoError {
21
- constructor(code: string, message: string);
22
- }
23
- /** Error thrown for PKCS#7 padding issues. */
24
- export declare class CryptoPaddingError extends CryptoError {
25
- constructor(code: string, message: string);
26
- }
27
- /** Error thrown during TLV serialization or deserialization. */
28
- export declare class CryptoSerializationError extends CryptoError {
29
- constructor(code: string, message: string);
30
- }
31
- /** Human-readable messages for each error code. */
32
- export declare const ERROR_MESSAGES: Record<string, string>;
33
- /**
34
- * Detailed descriptions for each error code.
35
- * Maps error codes to comprehensive explanations including cause and resolution.
36
- */
37
- export declare const ERROR_DETAILS: Record<string, string>;
38
- /**
39
- * Convert an unknown error into a CryptoError.
40
- *
41
- * @param error - The unknown error to convert
42
- * @returns A CryptoError instance
43
- */
44
- export declare function toCryptoError(error: unknown): CryptoError;
45
- /**
46
- * Type guard to check if an error is a CryptoError.
47
- *
48
- * @param error - The value to check
49
- * @returns true if the value is a CryptoError instance
50
- */
51
- export declare function isCryptoError(error: unknown): error is CryptoError;
@@ -1,109 +0,0 @@
1
- /**
2
- * @module errors
3
- * Named error class hierarchy for @private.me/crypto.
4
- *
5
- * Provides structured error types for XorIDA threshold sharing,
6
- * HMAC integrity verification, PKCS#7 padding, and TLV serialization.
7
- */
8
- const DOC_BASE = 'https://private.me/docs/packages/crypto';
9
- /** Base error class for all crypto operations. */
10
- export class CryptoError extends Error {
11
- code;
12
- subCode;
13
- docUrl;
14
- constructor(code, message, docUrl) {
15
- super(message);
16
- this.name = 'CryptoError';
17
- const parts = code.split(':');
18
- this.code = parts[0] ?? code;
19
- this.subCode = parts.length > 1 ? parts.slice(1).join(':') : undefined;
20
- this.docUrl = docUrl;
21
- }
22
- }
23
- /** Error thrown during XorIDA split or reconstruction operations. */
24
- export class CryptoSplitError extends CryptoError {
25
- constructor(code, message) {
26
- super(code, message, `${DOC_BASE}#splitting`);
27
- this.name = 'CryptoSplitError';
28
- }
29
- }
30
- /** Error thrown when HMAC integrity verification fails. */
31
- export class CryptoIntegrityError extends CryptoError {
32
- constructor(code, message) {
33
- super(code, message, `${DOC_BASE}#integrity`);
34
- this.name = 'CryptoIntegrityError';
35
- }
36
- }
37
- /** Error thrown for PKCS#7 padding issues. */
38
- export class CryptoPaddingError extends CryptoError {
39
- constructor(code, message) {
40
- super(code, message, `${DOC_BASE}#padding`);
41
- this.name = 'CryptoPaddingError';
42
- }
43
- }
44
- /** Error thrown during TLV serialization or deserialization. */
45
- export class CryptoSerializationError extends CryptoError {
46
- constructor(code, message) {
47
- super(code, message, `${DOC_BASE}#serialization`);
48
- this.name = 'CryptoSerializationError';
49
- }
50
- }
51
- /** Human-readable messages for each error code. */
52
- export const ERROR_MESSAGES = {
53
- SPLIT_FAILED: 'XorIDA split operation failed',
54
- RECONSTRUCTION_FAILED: 'XorIDA reconstruction failed',
55
- INSUFFICIENT_SHARES: 'Not enough shares provided for reconstruction',
56
- INVALID_SHARES: 'Shares have inconsistent UUID, n, or k values',
57
- INVALID_INDEX: 'Share index is out of range or duplicated',
58
- HMAC_FAILURE: 'HMAC integrity verification failed -- data may be corrupted',
59
- UUID_MISMATCH: 'Envelope UUID does not match TLV payload UUID',
60
- INVALID_PADDING: 'PKCS#7 padding is invalid or corrupted',
61
- INVALID_TLV: 'TLV buffer is malformed or truncated',
62
- BUFFER_OVERFLOW: 'TLV value length exceeds buffer bounds',
63
- MISSING_FIELD: 'Required TLV field is missing from serialized data',
64
- INVALID_CONFIG: 'Split configuration is invalid (n < 2, k < 2, or k > n)',
65
- };
66
- /**
67
- * Detailed descriptions for each error code.
68
- * Maps error codes to comprehensive explanations including cause and resolution.
69
- */
70
- export const ERROR_DETAILS = {
71
- INVALID_PADDING: 'PKCS#7 padding bytes are invalid or inconsistent. Data may be corrupted.',
72
- HMAC_FAILURE: 'HMAC-SHA256 verification failed during reconstruction. One or more shares have been tampered with.',
73
- INVALID_SHARES: 'Shares have inconsistent lengths, duplicate indices, or mismatched parameters.',
74
- INSUFFICIENT_SHARES: 'Fewer shares provided than the required threshold k.',
75
- INVALID_INDEX: 'A share index is out of range (must be 0 to n-1).',
76
- UUID_MISMATCH: 'Shares reference different message UUIDs and cannot be combined.',
77
- INVALID_TLV: 'TLV data is malformed or truncated.',
78
- BUFFER_OVERFLOW: 'TLV length field exceeds available data.',
79
- MISSING_FIELD: 'A required TLV field (e.g., MESSAGE_UUID) is absent.',
80
- INVALID_TYPE: 'An unrecognized TLV type tag was encountered in a required position.',
81
- HMAC_MISMATCH: 'Standalone HMAC verification failed. Data or key is incorrect.',
82
- KEY_ERROR: 'HMAC key import failed (invalid length or format).',
83
- SPLIT_FAILED: 'XorIDA split operation failed due to invalid input or configuration.',
84
- RECONSTRUCTION_FAILED: 'XorIDA reconstruction failed. Check share integrity and parameters.',
85
- INVALID_CONFIG: 'Split configuration is invalid. Requires n >= 2, k >= 2, and k <= n.',
86
- };
87
- /**
88
- * Convert an unknown error into a CryptoError.
89
- *
90
- * @param error - The unknown error to convert
91
- * @returns A CryptoError instance
92
- */
93
- export function toCryptoError(error) {
94
- if (error instanceof CryptoError)
95
- return error;
96
- if (error instanceof Error) {
97
- return new CryptoError('SPLIT_FAILED', error.message);
98
- }
99
- return new CryptoError('SPLIT_FAILED', String(error));
100
- }
101
- /**
102
- * Type guard to check if an error is a CryptoError.
103
- *
104
- * @param error - The value to check
105
- * @returns true if the value is a CryptoError instance
106
- */
107
- export function isCryptoError(error) {
108
- return error instanceof CryptoError;
109
- }