@private.me/xbind 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (295) hide show
  1. package/AGENTS.md +778 -0
  2. package/LICENSE.md +27 -0
  3. package/README.md +400 -0
  4. package/dist-standalone/_deps/crypto/base64.d.ts +29 -0
  5. package/dist-standalone/_deps/crypto/base64.js +97 -0
  6. package/dist-standalone/_deps/crypto/cjs/base64.js +103 -0
  7. package/dist-standalone/_deps/crypto/cjs/errors.js +119 -0
  8. package/dist-standalone/_deps/crypto/cjs/hmac.js +71 -0
  9. package/dist-standalone/_deps/crypto/cjs/index.js +86 -0
  10. package/dist-standalone/_deps/crypto/cjs/padding.js +57 -0
  11. package/dist-standalone/_deps/crypto/cjs/share-header.js +68 -0
  12. package/dist-standalone/_deps/crypto/cjs/shares.js +152 -0
  13. package/dist-standalone/_deps/crypto/cjs/tlv.js +199 -0
  14. package/dist-standalone/_deps/crypto/cjs/uuid.js +61 -0
  15. package/dist-standalone/_deps/crypto/cjs/verify.js +24 -0
  16. package/dist-standalone/_deps/crypto/cjs/xorida.js +221 -0
  17. package/dist-standalone/_deps/crypto/errors.d.ts +51 -0
  18. package/dist-standalone/_deps/crypto/errors.js +109 -0
  19. package/dist-standalone/_deps/crypto/hmac.d.ts +39 -0
  20. package/dist-standalone/_deps/crypto/hmac.js +66 -0
  21. package/dist-standalone/_deps/crypto/index.d.ts +20 -0
  22. package/dist-standalone/_deps/crypto/index.js +45 -0
  23. package/dist-standalone/_deps/crypto/padding.d.ts +19 -0
  24. package/dist-standalone/_deps/crypto/padding.js +53 -0
  25. package/dist-standalone/_deps/crypto/share-header.d.ts +44 -0
  26. package/dist-standalone/_deps/crypto/share-header.js +63 -0
  27. package/dist-standalone/_deps/crypto/shares.d.ts +27 -0
  28. package/dist-standalone/_deps/crypto/shares.js +148 -0
  29. package/dist-standalone/_deps/crypto/tlv.d.ts +26 -0
  30. package/dist-standalone/_deps/crypto/tlv.js +195 -0
  31. package/dist-standalone/_deps/crypto/uuid.d.ts +22 -0
  32. package/dist-standalone/_deps/crypto/uuid.js +56 -0
  33. package/dist-standalone/_deps/crypto/verify.d.ts +15 -0
  34. package/dist-standalone/_deps/crypto/verify.js +15 -0
  35. package/dist-standalone/_deps/crypto/xorida.d.ts +44 -0
  36. package/dist-standalone/_deps/crypto/xorida.js +215 -0
  37. package/dist-standalone/_deps/mldsa-wasm/LICENSE +24 -0
  38. package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1920 -0
  39. package/dist-standalone/_deps/mldsa-wasm/package.json +46 -0
  40. package/dist-standalone/_deps/mldsa-wasm/types/mldsa.d.ts +30 -0
  41. package/dist-standalone/_deps/shared/cjs/errors.js +582 -0
  42. package/dist-standalone/_deps/shared/cjs/index.js +492 -0
  43. package/dist-standalone/_deps/shared/cjs/package.json +1 -0
  44. package/dist-standalone/_deps/shared/cjs/types.js +403 -0
  45. package/dist-standalone/_deps/shared/errors.d.ts +48 -0
  46. package/dist-standalone/_deps/shared/errors.d.ts.map +1 -0
  47. package/dist-standalone/_deps/shared/errors.js +192 -0
  48. package/dist-standalone/_deps/shared/errors.js.map +1 -0
  49. package/dist-standalone/_deps/shared/index.d.ts +4 -0
  50. package/dist-standalone/_deps/shared/index.d.ts.map +1 -0
  51. package/dist-standalone/_deps/shared/index.js +78 -0
  52. package/dist-standalone/_deps/shared/index.js.map +1 -0
  53. package/dist-standalone/_deps/shared/types.d.ts +1097 -0
  54. package/dist-standalone/_deps/shared/types.d.ts.map +1 -0
  55. package/dist-standalone/_deps/shared/types.js +89 -0
  56. package/dist-standalone/_deps/shared/types.js.map +1 -0
  57. package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts +115 -0
  58. package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts.map +1 -0
  59. package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -0
  60. package/dist-standalone/_deps/ux-helpers/cjs/errors.js.map +1 -0
  61. package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts +13 -0
  62. package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts.map +1 -0
  63. package/dist-standalone/_deps/ux-helpers/cjs/index.js +1 -0
  64. package/dist-standalone/_deps/ux-helpers/cjs/index.js.map +1 -0
  65. package/dist-standalone/_deps/ux-helpers/cjs/package.json +1 -0
  66. package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts +39 -0
  67. package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts.map +1 -0
  68. package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +83 -0
  69. package/dist-standalone/_deps/ux-helpers/cjs/pagination.js.map +1 -0
  70. package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts +99 -0
  71. package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts.map +1 -0
  72. package/dist-standalone/_deps/ux-helpers/cjs/progress.js +143 -0
  73. package/dist-standalone/_deps/ux-helpers/cjs/progress.js.map +1 -0
  74. package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts +32 -0
  75. package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts.map +1 -0
  76. package/dist-standalone/_deps/ux-helpers/cjs/search.js +119 -0
  77. package/dist-standalone/_deps/ux-helpers/cjs/search.js.map +1 -0
  78. package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts +109 -0
  79. package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts.map +1 -0
  80. package/dist-standalone/_deps/ux-helpers/cjs/types.js +8 -0
  81. package/dist-standalone/_deps/ux-helpers/cjs/types.js.map +1 -0
  82. package/dist-standalone/_deps/ux-helpers/errors.d.ts +115 -0
  83. package/dist-standalone/_deps/ux-helpers/errors.d.ts.map +1 -0
  84. package/dist-standalone/_deps/ux-helpers/errors.js +253 -0
  85. package/dist-standalone/_deps/ux-helpers/errors.js.map +1 -0
  86. package/dist-standalone/_deps/ux-helpers/index.d.ts +13 -0
  87. package/dist-standalone/_deps/ux-helpers/index.d.ts.map +1 -0
  88. package/dist-standalone/_deps/ux-helpers/index.js +16 -0
  89. package/dist-standalone/_deps/ux-helpers/index.js.map +1 -0
  90. package/dist-standalone/_deps/ux-helpers/pagination.d.ts +39 -0
  91. package/dist-standalone/_deps/ux-helpers/pagination.d.ts.map +1 -0
  92. package/dist-standalone/_deps/ux-helpers/pagination.js +79 -0
  93. package/dist-standalone/_deps/ux-helpers/pagination.js.map +1 -0
  94. package/dist-standalone/_deps/ux-helpers/progress.d.ts +99 -0
  95. package/dist-standalone/_deps/ux-helpers/progress.d.ts.map +1 -0
  96. package/dist-standalone/_deps/ux-helpers/progress.js +138 -0
  97. package/dist-standalone/_deps/ux-helpers/progress.js.map +1 -0
  98. package/dist-standalone/_deps/ux-helpers/search.d.ts +32 -0
  99. package/dist-standalone/_deps/ux-helpers/search.d.ts.map +1 -0
  100. package/dist-standalone/_deps/ux-helpers/search.js +116 -0
  101. package/dist-standalone/_deps/ux-helpers/search.js.map +1 -0
  102. package/dist-standalone/_deps/ux-helpers/types.d.ts +109 -0
  103. package/dist-standalone/_deps/ux-helpers/types.d.ts.map +1 -0
  104. package/dist-standalone/_deps/ux-helpers/types.js +7 -0
  105. package/dist-standalone/_deps/ux-helpers/types.js.map +1 -0
  106. package/dist-standalone/_deps/xchange/auto-accept.d.ts +127 -0
  107. package/dist-standalone/_deps/xchange/auto-accept.js +1 -0
  108. package/dist-standalone/_deps/xchange/cjs/auto-accept.js +1 -0
  109. package/dist-standalone/_deps/xchange/cjs/errors.js +1 -0
  110. package/dist-standalone/_deps/xchange/cjs/index.js +1 -0
  111. package/dist-standalone/_deps/xchange/cjs/invite-client.js +1 -0
  112. package/dist-standalone/_deps/xchange/cjs/lazy-init.js +1 -0
  113. package/dist-standalone/_deps/xchange/cjs/package.json +1 -0
  114. package/dist-standalone/_deps/xchange/cjs/trust-integration.js +1 -0
  115. package/dist-standalone/_deps/xchange/cjs/xchange.js +1 -0
  116. package/dist-standalone/_deps/xchange/errors.d.ts +69 -0
  117. package/dist-standalone/_deps/xchange/errors.js +1 -0
  118. package/dist-standalone/_deps/xchange/index.d.ts +15 -0
  119. package/dist-standalone/_deps/xchange/index.js +1 -0
  120. package/dist-standalone/_deps/xchange/invite-client.d.ts +178 -0
  121. package/dist-standalone/_deps/xchange/invite-client.js +1 -0
  122. package/dist-standalone/_deps/xchange/lazy-init.d.ts +176 -0
  123. package/dist-standalone/_deps/xchange/lazy-init.js +1 -0
  124. package/dist-standalone/_deps/xchange/trust-integration.d.ts +102 -0
  125. package/dist-standalone/_deps/xchange/trust-integration.js +1 -0
  126. package/dist-standalone/_deps/xchange/xchange.d.ts +60 -0
  127. package/dist-standalone/_deps/xchange/xchange.js +1 -0
  128. package/dist-standalone/_deps/xregistry/cjs/discovery.js +1 -0
  129. package/dist-standalone/_deps/xregistry/cjs/errors.js +1 -0
  130. package/dist-standalone/_deps/xregistry/cjs/index.js +1 -0
  131. package/dist-standalone/_deps/xregistry/cjs/package.json +1 -0
  132. package/dist-standalone/_deps/xregistry/cjs/registry.js +1 -0
  133. package/dist-standalone/_deps/xregistry/cjs/schema.js +1 -0
  134. package/dist-standalone/_deps/xregistry/cjs/types.js +1 -0
  135. package/dist-standalone/_deps/xregistry/discovery.d.ts +126 -0
  136. package/dist-standalone/_deps/xregistry/discovery.d.ts.map +1 -0
  137. package/dist-standalone/_deps/xregistry/discovery.js +1 -0
  138. package/dist-standalone/_deps/xregistry/discovery.js.map +1 -0
  139. package/dist-standalone/_deps/xregistry/errors.d.ts +41 -0
  140. package/dist-standalone/_deps/xregistry/errors.d.ts.map +1 -0
  141. package/dist-standalone/_deps/xregistry/errors.js +1 -0
  142. package/dist-standalone/_deps/xregistry/errors.js.map +1 -0
  143. package/dist-standalone/_deps/xregistry/index.d.ts +8 -0
  144. package/dist-standalone/_deps/xregistry/index.d.ts.map +1 -0
  145. package/dist-standalone/_deps/xregistry/index.js +1 -0
  146. package/dist-standalone/_deps/xregistry/index.js.map +1 -0
  147. package/dist-standalone/_deps/xregistry/registry.d.ts +85 -0
  148. package/dist-standalone/_deps/xregistry/registry.d.ts.map +1 -0
  149. package/dist-standalone/_deps/xregistry/registry.js +1 -0
  150. package/dist-standalone/_deps/xregistry/registry.js.map +1 -0
  151. package/dist-standalone/_deps/xregistry/schema.d.ts +81 -0
  152. package/dist-standalone/_deps/xregistry/schema.d.ts.map +1 -0
  153. package/dist-standalone/_deps/xregistry/schema.js +1 -0
  154. package/dist-standalone/_deps/xregistry/schema.js.map +1 -0
  155. package/dist-standalone/_deps/xregistry/types.d.ts +95 -0
  156. package/dist-standalone/_deps/xregistry/types.d.ts.map +1 -0
  157. package/dist-standalone/_deps/xregistry/types.js +1 -0
  158. package/dist-standalone/_deps/xregistry/types.js.map +1 -0
  159. package/dist-standalone/agent-call.d.ts +286 -0
  160. package/dist-standalone/agent-call.js +642 -0
  161. package/dist-standalone/agent-sdk.d.ts +207 -0
  162. package/dist-standalone/agent-sdk.js +328 -0
  163. package/dist-standalone/agent.d.ts +670 -0
  164. package/dist-standalone/agent.js +1529 -0
  165. package/dist-standalone/approval.d.ts +145 -0
  166. package/dist-standalone/approval.js +193 -0
  167. package/dist-standalone/auth.d.ts +75 -0
  168. package/dist-standalone/auth.js +219 -0
  169. package/dist-standalone/auto-accept.d.ts +102 -0
  170. package/dist-standalone/auto-accept.js +229 -0
  171. package/dist-standalone/backup-config.d.ts +150 -0
  172. package/dist-standalone/backup-config.js +201 -0
  173. package/dist-standalone/checkpoint.d.ts +125 -0
  174. package/dist-standalone/checkpoint.js +186 -0
  175. package/dist-standalone/cjs/agent-call.js +651 -0
  176. package/dist-standalone/cjs/agent-sdk.js +332 -0
  177. package/dist-standalone/cjs/agent.js +1566 -0
  178. package/dist-standalone/cjs/approval.js +199 -0
  179. package/dist-standalone/cjs/auth.js +225 -0
  180. package/dist-standalone/cjs/auto-accept.js +233 -0
  181. package/dist-standalone/cjs/backup-config.js +207 -0
  182. package/dist-standalone/cjs/checkpoint.js +193 -0
  183. package/dist-standalone/cjs/cli/init.js +487 -0
  184. package/dist-standalone/cjs/connect.js +312 -0
  185. package/dist-standalone/cjs/did-document.js +101 -0
  186. package/dist-standalone/cjs/did-privateme.js +130 -0
  187. package/dist-standalone/cjs/did-web.js +201 -0
  188. package/dist-standalone/cjs/discovery.js +462 -0
  189. package/dist-standalone/cjs/dual-mode.js +251 -0
  190. package/dist-standalone/cjs/email-templates.js +313 -0
  191. package/dist-standalone/cjs/email-transport.js +239 -0
  192. package/dist-standalone/cjs/envelope.js +510 -0
  193. package/dist-standalone/cjs/errors.js +562 -0
  194. package/dist-standalone/cjs/gateway-state.js +55 -0
  195. package/dist-standalone/cjs/gateway-transport.js +120 -0
  196. package/dist-standalone/cjs/guardrails.js +223 -0
  197. package/dist-standalone/cjs/http-compat.js +272 -0
  198. package/dist-standalone/cjs/identity.js +541 -0
  199. package/dist-standalone/cjs/index.js +224 -0
  200. package/dist-standalone/cjs/invitation.js +421 -0
  201. package/dist-standalone/cjs/invite.js +328 -0
  202. package/dist-standalone/cjs/key-agreement.js +246 -0
  203. package/dist-standalone/cjs/lazy-init.js +300 -0
  204. package/dist-standalone/cjs/mdns-discovery.js +202 -0
  205. package/dist-standalone/cjs/nonce-store.js +66 -0
  206. package/dist-standalone/cjs/package.json +3 -0
  207. package/dist-standalone/cjs/pairing-manager.js +223 -0
  208. package/dist-standalone/cjs/policy.js +320 -0
  209. package/dist-standalone/cjs/redis-nonce-store.js +76 -0
  210. package/dist-standalone/cjs/registry-middleware.js +50 -0
  211. package/dist-standalone/cjs/retry-transport.js +102 -0
  212. package/dist-standalone/cjs/security-policy.js +204 -0
  213. package/dist-standalone/cjs/split-channel.js +177 -0
  214. package/dist-standalone/cjs/subscription-proof.js +230 -0
  215. package/dist-standalone/cjs/succession.js +148 -0
  216. package/dist-standalone/cjs/transport.js +63 -0
  217. package/dist-standalone/cjs/trust-registry.js +742 -0
  218. package/dist-standalone/cjs/verify.js +25 -0
  219. package/dist-standalone/cjs/xfetch.js +252 -0
  220. package/dist-standalone/cli/init.d.ts +63 -0
  221. package/dist-standalone/cli/init.js +450 -0
  222. package/dist-standalone/connect.d.ts +143 -0
  223. package/dist-standalone/connect.js +274 -0
  224. package/dist-standalone/did-document.d.ts +65 -0
  225. package/dist-standalone/did-document.js +96 -0
  226. package/dist-standalone/did-privateme.d.ts +70 -0
  227. package/dist-standalone/did-privateme.js +121 -0
  228. package/dist-standalone/did-web.d.ts +73 -0
  229. package/dist-standalone/did-web.js +196 -0
  230. package/dist-standalone/discovery.d.ts +176 -0
  231. package/dist-standalone/discovery.js +458 -0
  232. package/dist-standalone/dual-mode.d.ts +145 -0
  233. package/dist-standalone/dual-mode.js +247 -0
  234. package/dist-standalone/email-templates.d.ts +41 -0
  235. package/dist-standalone/email-templates.js +309 -0
  236. package/dist-standalone/email-transport.d.ts +139 -0
  237. package/dist-standalone/email-transport.js +232 -0
  238. package/dist-standalone/envelope.d.ts +288 -0
  239. package/dist-standalone/envelope.js +497 -0
  240. package/dist-standalone/errors.d.ts +74 -0
  241. package/dist-standalone/errors.js +548 -0
  242. package/dist-standalone/gateway-state.d.ts +32 -0
  243. package/dist-standalone/gateway-state.js +51 -0
  244. package/dist-standalone/gateway-transport.d.ts +59 -0
  245. package/dist-standalone/gateway-transport.js +116 -0
  246. package/dist-standalone/guardrails.d.ts +136 -0
  247. package/dist-standalone/guardrails.js +216 -0
  248. package/dist-standalone/http-compat.d.ts +150 -0
  249. package/dist-standalone/http-compat.js +267 -0
  250. package/dist-standalone/identity.d.ts +176 -0
  251. package/dist-standalone/identity.js +516 -0
  252. package/dist-standalone/index.d.ts +83 -0
  253. package/dist-standalone/index.js +51 -0
  254. package/dist-standalone/invitation.d.ts +211 -0
  255. package/dist-standalone/invitation.js +415 -0
  256. package/dist-standalone/invite.d.ts +192 -0
  257. package/dist-standalone/invite.js +324 -0
  258. package/dist-standalone/key-agreement.d.ts +122 -0
  259. package/dist-standalone/key-agreement.js +236 -0
  260. package/dist-standalone/lazy-init.d.ts +167 -0
  261. package/dist-standalone/lazy-init.js +295 -0
  262. package/dist-standalone/mdns-discovery.d.ts +117 -0
  263. package/dist-standalone/mdns-discovery.js +195 -0
  264. package/dist-standalone/nonce-store.d.ts +39 -0
  265. package/dist-standalone/nonce-store.js +62 -0
  266. package/dist-standalone/package.json +11 -0
  267. package/dist-standalone/pairing-manager.d.ts +147 -0
  268. package/dist-standalone/pairing-manager.js +219 -0
  269. package/dist-standalone/policy.d.ts +150 -0
  270. package/dist-standalone/policy.js +315 -0
  271. package/dist-standalone/redis-nonce-store.d.ts +93 -0
  272. package/dist-standalone/redis-nonce-store.js +72 -0
  273. package/dist-standalone/registry-middleware.d.ts +38 -0
  274. package/dist-standalone/registry-middleware.js +47 -0
  275. package/dist-standalone/retry-transport.d.ts +76 -0
  276. package/dist-standalone/retry-transport.js +98 -0
  277. package/dist-standalone/security-policy.d.ts +146 -0
  278. package/dist-standalone/security-policy.js +198 -0
  279. package/dist-standalone/split-channel.d.ts +69 -0
  280. package/dist-standalone/split-channel.js +171 -0
  281. package/dist-standalone/subscription-proof.d.ts +103 -0
  282. package/dist-standalone/subscription-proof.js +224 -0
  283. package/dist-standalone/succession.d.ts +57 -0
  284. package/dist-standalone/succession.js +142 -0
  285. package/dist-standalone/transport.d.ts +50 -0
  286. package/dist-standalone/transport.js +59 -0
  287. package/dist-standalone/trust-registry.d.ts +286 -0
  288. package/dist-standalone/trust-registry.js +702 -0
  289. package/dist-standalone/verify.d.ts +16 -0
  290. package/dist-standalone/verify.js +16 -0
  291. package/dist-standalone/xfetch.d.ts +129 -0
  292. package/dist-standalone/xfetch.js +247 -0
  293. package/llms.txt +800 -0
  294. package/package.json +79 -0
  295. package/share1.dat +0 -0
@@ -0,0 +1,198 @@
1
+ /**
2
+ * Security policy interface for automatic risk-based Xorida activation.
3
+ *
4
+ * Determines when to apply information-theoretic security (XorIDA split-channel)
5
+ * vs standard encrypted transport based on action semantics and parameters.
6
+ *
7
+ * Design principle: Security should be invisible to users. The policy classifies
8
+ * risk automatically so developers don't need to understand threshold cryptography.
9
+ */
10
+ /**
11
+ * Default security policy for basic XBind.
12
+ *
13
+ * Rules:
14
+ * - Transfers over $100,000: High security (3 shares, 2-of-3 threshold)
15
+ * - Cross-entity communication: High security (3 shares, 2-of-3 threshold)
16
+ * - Explicit 'high' override: High security (3 shares, 2-of-3 threshold)
17
+ * - Explicit 'critical' override: Critical security (5 shares, 3-of-5 threshold)
18
+ * - Everything else: Standard encrypted transport (V3 hybrid PQ)
19
+ *
20
+ * Enterprise and Government variants extend this with custom rules.
21
+ */
22
+ export class DefaultSecurityPolicy {
23
+ options;
24
+ /**
25
+ * Create a default security policy.
26
+ *
27
+ * @param options - Optional configuration
28
+ * @param options.highValueThreshold - Amount threshold for high security (default: 100000)
29
+ * @param options.enableXchange - Allow Xchange mode for performance (default: false)
30
+ */
31
+ constructor(options = {}) {
32
+ this.options = options;
33
+ }
34
+ classify(context) {
35
+ const { action, params, securityOverride } = context;
36
+ const threshold = this.options.highValueThreshold ?? 100_000;
37
+ // Explicit override: critical
38
+ if (securityOverride === 'critical') {
39
+ return {
40
+ mode: { type: 'split', shares: 5, threshold: 3 },
41
+ reason: 'User requested critical security level (5 shares, 3-of-5 threshold)',
42
+ wasOverridden: true,
43
+ };
44
+ }
45
+ // Explicit override: high
46
+ if (securityOverride === 'high') {
47
+ return {
48
+ mode: { type: 'split', shares: 3, threshold: 2 },
49
+ reason: 'User requested high security level (3 shares, 2-of-3 threshold)',
50
+ wasOverridden: true,
51
+ };
52
+ }
53
+ // Explicit override: standard
54
+ if (securityOverride === 'standard') {
55
+ return {
56
+ mode: { type: 'standard' },
57
+ reason: 'User requested standard security level (encrypted transport)',
58
+ wasOverridden: true,
59
+ };
60
+ }
61
+ // Auto-detection: High-value transfer
62
+ if ((action === 'transfer' || action === 'execute') &&
63
+ typeof params.amount === 'number' &&
64
+ params.amount > threshold) {
65
+ return {
66
+ mode: { type: 'split', shares: 3, threshold: 2 },
67
+ reason: `High-value transfer ($${params.amount.toLocaleString()}) requires multi-party approval (2 of 3)`,
68
+ wasOverridden: false,
69
+ };
70
+ }
71
+ // Auto-detection: Cross-entity communication
72
+ if (params.crossEntity === true) {
73
+ return {
74
+ mode: { type: 'split', shares: 3, threshold: 2 },
75
+ reason: 'Cross-organization communication requires multi-party approval (2 of 3)',
76
+ wasOverridden: false,
77
+ };
78
+ }
79
+ // Auto-detection: Sensitive scopes
80
+ if (context.scope.includes('admin') ||
81
+ context.scope.includes('custody') ||
82
+ context.scope.includes('settlement')) {
83
+ return {
84
+ mode: { type: 'split', shares: 3, threshold: 2 },
85
+ reason: `Sensitive scope "${context.scope}" requires multi-party approval (2 of 3)`,
86
+ wasOverridden: false,
87
+ };
88
+ }
89
+ // Xchange mode: opt-in performance mode (if enabled)
90
+ if (this.options.enableXchange && params.xchange === true) {
91
+ return {
92
+ mode: { type: 'xchange' },
93
+ reason: 'Xchange mode enabled for performance (~180x faster)',
94
+ wasOverridden: false,
95
+ };
96
+ }
97
+ // Default: Standard encrypted transport
98
+ return {
99
+ mode: { type: 'standard' },
100
+ reason: 'Standard encrypted transport (hybrid post-quantum)',
101
+ wasOverridden: false,
102
+ };
103
+ }
104
+ }
105
+ /**
106
+ * Get a human-readable security mode description.
107
+ *
108
+ * Used for logging and user feedback.
109
+ *
110
+ * @param mode - Security mode
111
+ * @returns User-friendly description
112
+ *
113
+ * @deprecated Use describeSecurityModeStructured() for new code. This function remains for backward compatibility.
114
+ */
115
+ export function describeSecurityMode(mode) {
116
+ switch (mode.type) {
117
+ case 'standard':
118
+ return 'Standard (encrypted)';
119
+ case 'split':
120
+ return `Multi-party approval (${mode.threshold} of ${mode.shares})`;
121
+ case 'xchange':
122
+ return 'Xchange (fast mode)';
123
+ }
124
+ }
125
+ /**
126
+ * Get a structured security mode description with multiple formats.
127
+ *
128
+ * Returns an object with the security classification and formatted descriptions
129
+ * optimized for different use cases (display, logging, APIs, docs).
130
+ *
131
+ * @param mode - Security mode
132
+ * @returns Security mode description with formats
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * const mode: SecurityMode = { type: 'split', shares: 3, threshold: 2 };
137
+ * const description = describeSecurityModeStructured(mode);
138
+ *
139
+ * console.log(description.formats.singleline);
140
+ * // "high | split | 2-of-3"
141
+ *
142
+ * console.log(description.formats.multiline);
143
+ * // "Security Level: High
144
+ * // Mode: Split-channel (XorIDA)
145
+ * // Shares: 3 total, 2 required"
146
+ *
147
+ * console.log(description.shares);
148
+ * // { total: 3, threshold: 2 }
149
+ * ```
150
+ */
151
+ export function describeSecurityModeStructured(mode) {
152
+ let level;
153
+ let multiline;
154
+ let singleline;
155
+ let markdown;
156
+ let shares;
157
+ switch (mode.type) {
158
+ case 'standard':
159
+ level = 'standard';
160
+ multiline = 'Security Level: Standard\nMode: Encrypted transport (hybrid post-quantum)';
161
+ singleline = 'standard | encrypted';
162
+ markdown = '**Security Level:** Standard\n\n**Mode:** Encrypted transport (hybrid post-quantum)';
163
+ break;
164
+ case 'split':
165
+ // Classify split mode as high or critical based on threshold
166
+ level = mode.shares >= 5 ? 'critical' : 'high';
167
+ shares = { total: mode.shares, threshold: mode.threshold };
168
+ multiline = `Security Level: ${level === 'critical' ? 'Critical' : 'High'}\nMode: Split-channel (XorIDA)\nShares: ${mode.shares} total, ${mode.threshold} required`;
169
+ singleline = `${level} | split | ${mode.threshold}-of-${mode.shares}`;
170
+ markdown = `**Security Level:** ${level === 'critical' ? 'Critical' : 'High'}\n\n**Mode:** Split-channel (XorIDA)\n\n**Shares:** ${mode.shares} total, ${mode.threshold} required`;
171
+ break;
172
+ case 'xchange':
173
+ level = 'performance';
174
+ multiline = 'Security Level: Performance\nMode: Xchange (single IT layer, ~180x faster)';
175
+ singleline = 'performance | xchange';
176
+ markdown = '**Security Level:** Performance\n\n**Mode:** Xchange (single IT layer, ~180x faster)';
177
+ break;
178
+ }
179
+ const jsonObj = {
180
+ type: mode.type,
181
+ level,
182
+ };
183
+ if (shares) {
184
+ jsonObj.shares = shares;
185
+ }
186
+ const json = JSON.stringify(jsonObj);
187
+ return {
188
+ type: mode.type,
189
+ level,
190
+ shares,
191
+ formats: {
192
+ multiline,
193
+ singleline,
194
+ json,
195
+ markdown,
196
+ },
197
+ };
198
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * XorIDA split-channel bridge for @private.me/xbind.
3
+ *
4
+ * Bridges @private.me/crypto threshold sharing with the agent-sdk
5
+ * TransportEnvelope format. Splits plaintext into n shares with HMAC
6
+ * integrity, each share wrapped in its own envelope for independent routing.
7
+ *
8
+ * Pipeline:
9
+ * split: pad -> HMAC -> XorIDA split -> share Uint8Arrays with metadata
10
+ * reconstruct: collect k shares -> XorIDA reconstruct -> HMAC verify -> unpad
11
+ */
12
+ import type { Result } from '@private.me/shared';
13
+ /** Configuration for split-channel delivery. */
14
+ export interface SplitChannelConfig {
15
+ /** Total number of shares to produce. Default: 3. */
16
+ readonly totalShares: number;
17
+ /** Minimum shares needed for reconstruction. Default: 2. */
18
+ readonly threshold: number;
19
+ }
20
+ /** Serialized share with metadata for transport. */
21
+ export interface ChannelShare {
22
+ /** Base64-encoded share data. */
23
+ readonly data: string;
24
+ /** Share index (0-based). */
25
+ readonly index: number;
26
+ /** Total shares produced. */
27
+ readonly total: number;
28
+ /** Threshold for reconstruction. */
29
+ readonly threshold: number;
30
+ /** UUID linking all shares of this message. */
31
+ readonly groupId: string;
32
+ /** Base64-encoded HMAC key (needed for verification on reconstruct). */
33
+ readonly hmacKey: string;
34
+ /** Base64-encoded HMAC signature over the padded plaintext. */
35
+ readonly hmacSig: string;
36
+ }
37
+ /** Error codes for split-channel operations. Sub-codes give context. */
38
+ export type SplitChannelError = 'SPLIT_FAILED' | 'SPLIT_FAILED:INVALID_PARAMS' | 'SPLIT_FAILED:RECONSTRUCT' | 'INSUFFICIENT_SHARES' | 'INCONSISTENT_SHARES' | 'HMAC_VERIFICATION_FAILED' | 'UNPAD_FAILED' | 'INVALID_SHARE_DATA' | 'INVALID_SHARE_DATA:BASE64' | 'INVALID_SHARE_DATA:HMAC_DECODE';
39
+ /** Default split-channel configuration: 3 shares, threshold 2. */
40
+ export declare const DEFAULT_SPLIT_CONFIG: SplitChannelConfig;
41
+ /**
42
+ * Split plaintext into n shares via XorIDA with HMAC integrity.
43
+ *
44
+ * Pipeline: pad(PKCS#7) -> HMAC(padded) -> XorIDA split -> ChannelShare[]
45
+ *
46
+ * @param plaintext - Raw plaintext bytes to split
47
+ * @param config - Split configuration (totalShares, threshold)
48
+ * @returns Array of n ChannelShare objects ready for envelope wrapping
49
+ */
50
+ export declare function splitForChannel(plaintext: Uint8Array, config?: SplitChannelConfig): Promise<Result<ChannelShare[], SplitChannelError>>;
51
+ /**
52
+ * Split plaintext with a specific groupId (for testability).
53
+ *
54
+ * @param plaintext - Raw plaintext bytes
55
+ * @param config - Split configuration
56
+ * @param groupId - UUID to use for the share group
57
+ * @returns Array of ChannelShare objects
58
+ */
59
+ export declare function splitForChannelWithGroupId(plaintext: Uint8Array, config: SplitChannelConfig, groupId: string): Promise<Result<ChannelShare[], SplitChannelError>>;
60
+ /**
61
+ * Reconstruct plaintext from k-of-n shares.
62
+ *
63
+ * Pipeline: validate -> XorIDA reconstruct -> HMAC verify -> unpad -> plaintext
64
+ * HMAC verification happens BEFORE the data is trusted.
65
+ *
66
+ * @param shares - Array of at least k ChannelShare objects
67
+ * @returns Reconstructed plaintext bytes
68
+ */
69
+ export declare function reconstructFromChannel(shares: readonly ChannelShare[]): Promise<Result<Uint8Array, SplitChannelError>>;
@@ -0,0 +1,171 @@
1
+ /**
2
+ * XorIDA split-channel bridge for @private.me/xbind.
3
+ *
4
+ * Bridges @private.me/crypto threshold sharing with the agent-sdk
5
+ * TransportEnvelope format. Splits plaintext into n shares with HMAC
6
+ * integrity, each share wrapped in its own envelope for independent routing.
7
+ *
8
+ * Pipeline:
9
+ * split: pad -> HMAC -> XorIDA split -> share Uint8Arrays with metadata
10
+ * reconstruct: collect k shares -> XorIDA reconstruct -> HMAC verify -> unpad
11
+ */
12
+ import { ok, err } from"./_deps/shared/index.js";
13
+ import { splitXorIDA, reconstructXorIDA, nextOddPrime, pkcs7Pad, pkcs7Unpad, generateHMAC, verifyHMAC, toBase64, fromBase64, generateUUID, formatShareHeader, parseShareHeader, } from"./_deps/crypto/index.js";
14
+ /** Default split-channel configuration: 3 shares, threshold 2. */
15
+ export const DEFAULT_SPLIT_CONFIG = {
16
+ totalShares: 3,
17
+ threshold: 2,
18
+ };
19
+ /* ── Split ── */
20
+ /**
21
+ * Split plaintext into n shares via XorIDA with HMAC integrity.
22
+ *
23
+ * Pipeline: pad(PKCS#7) -> HMAC(padded) -> XorIDA split -> ChannelShare[]
24
+ *
25
+ * @param plaintext - Raw plaintext bytes to split
26
+ * @param config - Split configuration (totalShares, threshold)
27
+ * @returns Array of n ChannelShare objects ready for envelope wrapping
28
+ */
29
+ export async function splitForChannel(plaintext, config = DEFAULT_SPLIT_CONFIG) {
30
+ const { totalShares: n, threshold: k } = config;
31
+ if (n < 2 || k < 2 || k > n) {
32
+ return err('SPLIT_FAILED:INVALID_PARAMS');
33
+ }
34
+ const groupId = generateUUID();
35
+ return splitForChannelWithGroupId(plaintext, config, groupId);
36
+ }
37
+ /**
38
+ * Split plaintext with a specific groupId (for testability).
39
+ *
40
+ * @param plaintext - Raw plaintext bytes
41
+ * @param config - Split configuration
42
+ * @param groupId - UUID to use for the share group
43
+ * @returns Array of ChannelShare objects
44
+ */
45
+ export async function splitForChannelWithGroupId(plaintext, config, groupId) {
46
+ const { totalShares: n, threshold: k } = config;
47
+ if (n < 2 || k < 2 || k > n) {
48
+ return err('SPLIT_FAILED:INVALID_PARAMS');
49
+ }
50
+ const p = nextOddPrime(n);
51
+ const blockSize = p - 1;
52
+ const padded = pkcs7Pad(plaintext, blockSize);
53
+ const { key: hmacKey, signature: hmacSig } = await generateHMAC(padded);
54
+ let shareArrays;
55
+ try {
56
+ shareArrays = splitXorIDA(padded, n, k);
57
+ }
58
+ catch {
59
+ return err('SPLIT_FAILED');
60
+ }
61
+ const hmacKeyB64 = toBase64(hmacKey);
62
+ const hmacSigB64 = toBase64(hmacSig);
63
+ const shares = shareArrays.map((data, index) => ({
64
+ data: formatShareHeader(toBase64(data)),
65
+ index,
66
+ total: n,
67
+ threshold: k,
68
+ groupId,
69
+ hmacKey: hmacKeyB64,
70
+ hmacSig: hmacSigB64,
71
+ }));
72
+ return ok(shares);
73
+ }
74
+ /* ── Reconstruct ── */
75
+ /**
76
+ * Reconstruct plaintext from k-of-n shares.
77
+ *
78
+ * Pipeline: validate -> XorIDA reconstruct -> HMAC verify -> unpad -> plaintext
79
+ * HMAC verification happens BEFORE the data is trusted.
80
+ *
81
+ * @param shares - Array of at least k ChannelShare objects
82
+ * @returns Reconstructed plaintext bytes
83
+ */
84
+ export async function reconstructFromChannel(shares) {
85
+ const validationResult = validateShares(shares);
86
+ if (!validationResult.ok)
87
+ return validationResult;
88
+ const { k, n } = validationResult.value;
89
+ const usedShares = shares.slice(0, k);
90
+ return reconstructValidated(usedShares, n, k);
91
+ }
92
+ /**
93
+ * Validate share consistency before reconstruction.
94
+ *
95
+ * @param shares - Shares to validate
96
+ * @returns Validated parameters or error
97
+ */
98
+ function validateShares(shares) {
99
+ if (shares.length === 0) {
100
+ return err('INSUFFICIENT_SHARES');
101
+ }
102
+ const first = shares[0];
103
+ const k = first.threshold;
104
+ const n = first.total;
105
+ if (shares.length < k) {
106
+ return err('INSUFFICIENT_SHARES');
107
+ }
108
+ const indexSet = new Set();
109
+ for (const share of shares) {
110
+ if (share.groupId !== first.groupId) {
111
+ return err('INCONSISTENT_SHARES');
112
+ }
113
+ if (share.total !== n || share.threshold !== k) {
114
+ return err('INCONSISTENT_SHARES');
115
+ }
116
+ if (share.index < 0 || share.index >= n) {
117
+ return err('INVALID_SHARE_DATA');
118
+ }
119
+ if (indexSet.has(share.index)) {
120
+ return err('INVALID_SHARE_DATA');
121
+ }
122
+ indexSet.add(share.index);
123
+ }
124
+ return ok({ k, n, groupId: first.groupId });
125
+ }
126
+ /**
127
+ * Perform XorIDA reconstruction and HMAC verification.
128
+ *
129
+ * @param usedShares - Exactly k validated shares
130
+ * @param n - Total shares
131
+ * @param k - Threshold
132
+ * @returns Reconstructed plaintext
133
+ */
134
+ async function reconstructValidated(usedShares, n, k) {
135
+ let shareData;
136
+ try {
137
+ shareData = usedShares.map((s) => fromBase64(parseShareHeader(s.data)));
138
+ }
139
+ catch {
140
+ return err('INVALID_SHARE_DATA:BASE64');
141
+ }
142
+ const indices = usedShares.map((s) => s.index);
143
+ let padded;
144
+ try {
145
+ padded = reconstructXorIDA(shareData, indices, n, k);
146
+ }
147
+ catch {
148
+ return err('SPLIT_FAILED:RECONSTRUCT');
149
+ }
150
+ const first = usedShares[0];
151
+ let hmacKey;
152
+ let hmacSig;
153
+ try {
154
+ hmacKey = fromBase64(first.hmacKey);
155
+ hmacSig = fromBase64(first.hmacSig);
156
+ }
157
+ catch {
158
+ return err('INVALID_SHARE_DATA:HMAC_DECODE');
159
+ }
160
+ const hmacValid = await verifyHMAC(hmacKey, padded, hmacSig);
161
+ if (!hmacValid) {
162
+ return err('HMAC_VERIFICATION_FAILED');
163
+ }
164
+ const p = nextOddPrime(n);
165
+ const blockSize = p - 1;
166
+ const unpadResult = pkcs7Unpad(padded, blockSize);
167
+ if (!unpadResult.ok) {
168
+ return err('UNPAD_FAILED');
169
+ }
170
+ return ok(unpadResult.value);
171
+ }
@@ -0,0 +1,103 @@
1
+ import type { Result } from '@private.me/shared';
2
+ /** Error codes for subscription proof operations. */
3
+ export type ProofError = 'INVALID_PROOF' | 'EXPIRED' | 'SIGNATURE_VERIFICATION_FAILED' | 'HASH_FAILED' | 'NETWORK_ERROR' | 'INVALID_DID';
4
+ /**
5
+ * Subscription proof format (peer-signed).
6
+ *
7
+ * Enables gateway portability: clients can resume subscriptions on a new
8
+ * gateway by presenting a proof that they previously subscribed to a bloom
9
+ * filter covering specific DIDs.
10
+ */
11
+ export interface SubscriptionProof {
12
+ /** Proof type identifier. */
13
+ readonly type: 'SubscriptionProof';
14
+ /** Proof format version. */
15
+ readonly version: '1.0';
16
+ /** Subscriber's DID (did:key:z6Mk... or did:privateme:...). */
17
+ readonly peer_did: string;
18
+ /** SHA-256 hash of the bloom filter (hex string). */
19
+ readonly bloom_filter_hash: string;
20
+ /** Unix timestamp (ms) when proof was created. */
21
+ readonly asserted_at: number;
22
+ /** Unix timestamp (ms) when proof expires. */
23
+ readonly expires_at: number;
24
+ /** Signature algorithm used. */
25
+ readonly peer_signature_algorithm: 'ML-DSA-65';
26
+ /** Base64-encoded ML-DSA-65 signature (3309 bytes). */
27
+ readonly peer_signature: string;
28
+ }
29
+ /**
30
+ * Create a subscription proof (client-side).
31
+ *
32
+ * Signs a bloom filter hash with the peer's ML-DSA-65 private key, creating
33
+ * a portable proof that can be used to resume subscriptions on a new gateway.
34
+ *
35
+ * @param peerDid - Subscriber's DID (must match the private key).
36
+ * @param bloomFilterHash - SHA-256 hash of the bloom filter (hex string).
37
+ * @param privateKey - 32-byte ML-DSA-65 secret key seed.
38
+ * @param expiresAt - Optional expiration timestamp (ms). Default: 30 days from now.
39
+ * @returns Subscription proof with ML-DSA-65 signature.
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * const proof = await createSubscriptionProof(
44
+ * 'did:key:z6Mk...',
45
+ * 'a1b2c3...',
46
+ * mlDsaPrivateKey,
47
+ * Date.now() + 30 * 24 * 60 * 60 * 1000
48
+ * );
49
+ * ```
50
+ */
51
+ export declare function createSubscriptionProof(peerDid: string, bloomFilterHash: string, privateKey: Uint8Array, expiresAt?: number): Promise<Result<SubscriptionProof, ProofError>>;
52
+ /**
53
+ * Verify a subscription proof (gateway-side).
54
+ *
55
+ * Validates the ML-DSA-65 signature and checks expiration.
56
+ *
57
+ * @param proof - Subscription proof to verify.
58
+ * @param peerPublicKey - 1952-byte ML-DSA-65 public key of the subscriber.
59
+ * @returns true if valid, false if invalid or expired.
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * const isValid = await verifySubscriptionProof(proof, mlDsaPublicKey);
64
+ * if (isValid.ok && isValid.value) {
65
+ * // Resume subscription
66
+ * }
67
+ * ```
68
+ */
69
+ export declare function verifySubscriptionProof(proof: SubscriptionProof, peerPublicKey: Uint8Array): Promise<Result<boolean, ProofError>>;
70
+ /**
71
+ * Resume subscription on a new gateway using a proof.
72
+ *
73
+ * Presents the subscription proof to the new gateway, allowing the client
74
+ * to resume receiving trust events without re-subscribing.
75
+ *
76
+ * @param proof - Valid subscription proof.
77
+ * @param newGatewayUrl - Base URL of the new gateway (e.g., https://atelier2.xail.io).
78
+ * @returns Success or network error.
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * const result = await resumeSubscription(proof, 'https://atelier2.xail.io');
83
+ * if (result.ok) {
84
+ * console.log('Subscription resumed on new gateway');
85
+ * }
86
+ * ```
87
+ */
88
+ export declare function resumeSubscription(proof: SubscriptionProof, newGatewayUrl: string): Promise<Result<void, ProofError>>;
89
+ /**
90
+ * Compute SHA-256 hash of a bloom filter for proof creation.
91
+ *
92
+ * @param bloomFilter - Bloom filter bytes.
93
+ * @returns Hex-encoded SHA-256 hash.
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * const hash = await hashBloomFilter(bloomFilterBytes);
98
+ * if (hash.ok) {
99
+ * const proof = await createSubscriptionProof(did, hash.value, privateKey);
100
+ * }
101
+ * ```
102
+ */
103
+ export declare function hashBloomFilter(bloomFilter: Uint8Array): Promise<Result<string, ProofError>>;