@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,742 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.FileTrustRegistry = exports.HttpTrustRegistry = exports.MemoryTrustRegistry = void 0;
37
+ exports.createEnterpriseTrustRegistry = createEnterpriseTrustRegistry;
38
+ const shared_1 = require("../_deps/shared/index.js");
39
+ const fs = __importStar(require("node:fs/promises"));
40
+ const path = __importStar(require("node:path"));
41
+ /* ── Memory Implementation ── */
42
+ /**
43
+ * In-memory trust registry for development and testing.
44
+ */
45
+ class MemoryTrustRegistry {
46
+ entries = new Map();
47
+ async register(did, publicKey, name, scopes, x25519PublicKey, mlKemPublicKey, mlDsaPublicKey, xchange, receiveScopes) {
48
+ if (this.entries.has(did))
49
+ return (0, shared_1.err)('ALREADY_REGISTERED');
50
+ this.entries.set(did, {
51
+ did,
52
+ publicKey,
53
+ name,
54
+ scopes: new Set(scopes ?? []),
55
+ receiveScopes: receiveScopes ? new Set(receiveScopes) : undefined,
56
+ revoked: false,
57
+ rotation_sequence: 1, // Initial sequence starts at 1
58
+ x25519PublicKey,
59
+ mlKemPublicKey,
60
+ mlDsaPublicKey,
61
+ xchange,
62
+ });
63
+ return (0, shared_1.ok)(undefined);
64
+ }
65
+ async resolve(did) {
66
+ const entry = this.entries.get(did);
67
+ if (!entry)
68
+ return (0, shared_1.err)('NOT_FOUND');
69
+ if (entry.revoked)
70
+ return (0, shared_1.err)('REVOKED');
71
+ return (0, shared_1.ok)(entry.publicKey);
72
+ }
73
+ async hasScope(did, scope) {
74
+ const entry = this.entries.get(did);
75
+ if (!entry || entry.revoked)
76
+ return false;
77
+ return entry.scopes.has(scope);
78
+ }
79
+ async hasReceiveScope(did, scope) {
80
+ const entry = this.entries.get(did);
81
+ if (!entry || entry.revoked)
82
+ return false;
83
+ // Undefined = accept all scopes (backward compatibility)
84
+ if (!entry.receiveScopes)
85
+ return true;
86
+ return entry.receiveScopes.has(scope);
87
+ }
88
+ async revoke(did) {
89
+ const entry = this.entries.get(did);
90
+ if (!entry)
91
+ return (0, shared_1.err)('NOT_FOUND');
92
+ this.entries.set(did, { ...entry, revoked: true });
93
+ return (0, shared_1.ok)(undefined);
94
+ }
95
+ async getEntry(did) {
96
+ const entry = this.entries.get(did);
97
+ if (!entry)
98
+ return (0, shared_1.err)('NOT_FOUND');
99
+ return (0, shared_1.ok)(entry);
100
+ }
101
+ async updateScopes(did, scopes) {
102
+ const entry = this.entries.get(did);
103
+ if (!entry)
104
+ return (0, shared_1.err)('NOT_FOUND');
105
+ if (entry.revoked)
106
+ return (0, shared_1.err)('REVOKED');
107
+ this.entries.set(did, { ...entry, scopes: new Set(scopes) });
108
+ return (0, shared_1.ok)(undefined);
109
+ }
110
+ /** Number of entries (for testing). */
111
+ get size() {
112
+ return this.entries.size;
113
+ }
114
+ }
115
+ exports.MemoryTrustRegistry = MemoryTrustRegistry;
116
+ /**
117
+ * HTTP-backed trust registry for production use.
118
+ * Delegates to a remote atelier.xail.io service.
119
+ */
120
+ class HttpTrustRegistry {
121
+ baseUrl;
122
+ fetchFn;
123
+ cacheTtlMs;
124
+ cacheFailureMode;
125
+ enablePush;
126
+ bloomFilterSize;
127
+ bloomFilterFpr;
128
+ resolveCache = new Map();
129
+ entryCache = new Map();
130
+ constructor(opts) {
131
+ this.baseUrl = opts.baseUrl.replace(/\/$/, '');
132
+ this.fetchFn = opts.fetch ?? globalThis.fetch.bind(globalThis);
133
+ this.cacheTtlMs = opts.cacheTtlMs ?? 30_000;
134
+ this.cacheFailureMode = opts.cacheFailureMode ?? 'fail-secure';
135
+ this.enablePush = opts.enablePush ?? false;
136
+ this.bloomFilterSize = opts.bloomFilterSize ?? 10_000;
137
+ this.bloomFilterFpr = opts.bloomFilterFpr ?? 0.01;
138
+ }
139
+ /** Clear all cached entries. Call after registration or revocation. */
140
+ clearCache() {
141
+ this.resolveCache.clear();
142
+ this.entryCache.clear();
143
+ }
144
+ async register(did, publicKey, name, scopes, x25519PublicKey, mlKemPublicKey, mlDsaPublicKey, xchange, receiveScopes) {
145
+ try {
146
+ const res = await this.fetchFn(`${this.baseUrl}/registry/register`, {
147
+ method: 'POST',
148
+ headers: { 'Content-Type': 'application/json' },
149
+ body: JSON.stringify({
150
+ did,
151
+ publicKey: Array.from(publicKey),
152
+ name,
153
+ scopes: scopes ?? [],
154
+ ...(receiveScopes
155
+ ? { receiveScopes }
156
+ : {}),
157
+ ...(x25519PublicKey
158
+ ? { x25519PublicKey: Array.from(x25519PublicKey) }
159
+ : {}),
160
+ ...(mlKemPublicKey
161
+ ? { mlKemPublicKey: Array.from(mlKemPublicKey) }
162
+ : {}),
163
+ ...(mlDsaPublicKey
164
+ ? { mlDsaPublicKey: Array.from(mlDsaPublicKey) }
165
+ : {}),
166
+ ...(xchange !== undefined
167
+ ? { xchange }
168
+ : {}),
169
+ }),
170
+ });
171
+ if (res.status === 409)
172
+ return (0, shared_1.err)('ALREADY_REGISTERED');
173
+ if (!res.ok)
174
+ return (0, shared_1.err)('NETWORK_ERROR');
175
+ return (0, shared_1.ok)(undefined);
176
+ }
177
+ catch {
178
+ return (0, shared_1.err)('NETWORK_ERROR');
179
+ }
180
+ }
181
+ async resolve(did) {
182
+ // Check cache first
183
+ if (this.cacheTtlMs > 0) {
184
+ const cached = this.resolveCache.get(did);
185
+ if (cached && cached.expiry > Date.now())
186
+ return cached.value;
187
+ }
188
+ let result;
189
+ try {
190
+ const res = await this.fetchFn(`${this.baseUrl}/registry/resolve/${encodeURIComponent(did)}`);
191
+ if (res.status === 404)
192
+ result = (0, shared_1.err)('NOT_FOUND');
193
+ else if (res.status === 410)
194
+ result = (0, shared_1.err)('REVOKED');
195
+ else if (!res.ok)
196
+ result = (0, shared_1.err)('NETWORK_ERROR');
197
+ else {
198
+ const data = (await res.json());
199
+ result = (0, shared_1.ok)(new Uint8Array(data.publicKey));
200
+ }
201
+ }
202
+ catch {
203
+ // Network failure - apply cache failure mode
204
+ const staleCache = this.resolveCache.get(did);
205
+ if (this.cacheFailureMode === 'fail-secure') {
206
+ // Fail-secure: reject on cache refresh failure (default)
207
+ result = (0, shared_1.err)('NETWORK_ERROR');
208
+ }
209
+ else {
210
+ // Fail-open: accept stale cache if available
211
+ if (staleCache) {
212
+ // Return stale cached value
213
+ return staleCache.value;
214
+ }
215
+ result = (0, shared_1.err)('NETWORK_ERROR');
216
+ }
217
+ }
218
+ // Update cache with fresh result (only if cache enabled)
219
+ if (this.cacheTtlMs > 0) {
220
+ this.resolveCache.set(did, { value: result, expiry: Date.now() + this.cacheTtlMs });
221
+ }
222
+ return result;
223
+ }
224
+ async hasScope(did, scope) {
225
+ try {
226
+ const res = await this.fetchFn(`${this.baseUrl}/registry/scope/${encodeURIComponent(did)}/${encodeURIComponent(scope)}`);
227
+ return res.ok;
228
+ }
229
+ catch {
230
+ return false;
231
+ }
232
+ }
233
+ async hasReceiveScope(did, scope) {
234
+ try {
235
+ const res = await this.fetchFn(`${this.baseUrl}/registry/receive-scope/${encodeURIComponent(did)}/${encodeURIComponent(scope)}`);
236
+ return res.ok;
237
+ }
238
+ catch {
239
+ return false;
240
+ }
241
+ }
242
+ async revoke(did) {
243
+ try {
244
+ const res = await this.fetchFn(`${this.baseUrl}/registry/revoke/${encodeURIComponent(did)}`, { method: 'POST' });
245
+ if (res.status === 404)
246
+ return (0, shared_1.err)('NOT_FOUND');
247
+ if (!res.ok)
248
+ return (0, shared_1.err)('NETWORK_ERROR');
249
+ return (0, shared_1.ok)(undefined);
250
+ }
251
+ catch {
252
+ return (0, shared_1.err)('NETWORK_ERROR');
253
+ }
254
+ }
255
+ async getEntry(did) {
256
+ if (this.cacheTtlMs > 0) {
257
+ const cached = this.entryCache.get(did);
258
+ if (cached && cached.expiry > Date.now())
259
+ return cached.value;
260
+ }
261
+ let result;
262
+ try {
263
+ const res = await this.fetchFn(`${this.baseUrl}/registry/entry/${encodeURIComponent(did)}`);
264
+ if (res.status === 404)
265
+ result = (0, shared_1.err)('NOT_FOUND');
266
+ else if (!res.ok)
267
+ result = (0, shared_1.err)('NETWORK_ERROR');
268
+ else {
269
+ const data = (await res.json());
270
+ result = (0, shared_1.ok)({
271
+ did: data.did,
272
+ publicKey: new Uint8Array(data.publicKey),
273
+ name: data.name,
274
+ scopes: new Set(data.scopes),
275
+ receiveScopes: data.receiveScopes ? new Set(data.receiveScopes) : undefined,
276
+ revoked: data.revoked,
277
+ rotation_sequence: data.rotation_sequence ?? 1,
278
+ x25519PublicKey: data.x25519PublicKey
279
+ ? new Uint8Array(data.x25519PublicKey)
280
+ : undefined,
281
+ mlKemPublicKey: data.mlKemPublicKey
282
+ ? new Uint8Array(data.mlKemPublicKey)
283
+ : undefined,
284
+ mlDsaPublicKey: data.mlDsaPublicKey
285
+ ? new Uint8Array(data.mlDsaPublicKey)
286
+ : undefined,
287
+ xchange: data.xchange,
288
+ });
289
+ }
290
+ }
291
+ catch {
292
+ result = (0, shared_1.err)('NETWORK_ERROR');
293
+ }
294
+ if (this.cacheTtlMs > 0) {
295
+ this.entryCache.set(did, { value: result, expiry: Date.now() + this.cacheTtlMs });
296
+ }
297
+ return result;
298
+ }
299
+ /**
300
+ * Rotate a DID to a new public key with cryptographic proof.
301
+ *
302
+ * Sends rotation request to gateway and invalidates local cache.
303
+ *
304
+ * @param did - DID being rotated (old key)
305
+ * @param newPublicKey - New public key bytes
306
+ * @param proof - Succession announcement (dual signatures from old and new keys)
307
+ * @param rotationSequence - Monotonically increasing sequence number (prevents rollback)
308
+ */
309
+ async rotate(did, newPublicKey, proof, rotationSequence) {
310
+ const res = await this.fetchFn(`${this.baseUrl}/registry/rotate`, {
311
+ method: 'POST',
312
+ headers: { 'Content-Type': 'application/json' },
313
+ body: JSON.stringify({
314
+ did,
315
+ newPublicKey: Array.from(newPublicKey),
316
+ proof: Array.from(proof),
317
+ rotationSequence,
318
+ }),
319
+ });
320
+ if (!res.ok) {
321
+ throw new Error(`Key rotation failed: ${res.status} ${res.statusText}`);
322
+ }
323
+ // Invalidate cache for this DID
324
+ this.resolveCache.delete(did);
325
+ this.entryCache.delete(did);
326
+ }
327
+ /**
328
+ * Subscribe to real-time trust events (revocation, key rotation).
329
+ *
330
+ * Creates a bloom filter from DIDs and connects WebSocket to gateway.
331
+ * Events matching subscribed DIDs trigger the callback and invalidate cache.
332
+ *
333
+ * @param dids - Array of DIDs to monitor
334
+ * @param callback - Function called when trust events occur
335
+ * @returns Unsubscribe function to stop watching
336
+ *
337
+ * @throws Error if push notifications not enabled (enablePush: true)
338
+ */
339
+ async subscribe(dids, callback) {
340
+ if (!this.enablePush) {
341
+ throw new Error('Push notifications not enabled (set enablePush: true in HttpTrustRegistryOptions)');
342
+ }
343
+ // Simple bloom filter: hash each DID to track subscriptions
344
+ // Production implementation would use full bloom filter library
345
+ const bloomSet = new Set(dids.map(did => this.hashDid(did)));
346
+ // Convert HTTP URL to WebSocket URL
347
+ const wsUrl = this.baseUrl.replace(/^http/, 'ws') + '/trust/events';
348
+ // SAFETY: WebSocket is a standard browser/Node.js API
349
+ const ws = new globalThis.WebSocket(wsUrl);
350
+ ws.addEventListener('open', () => {
351
+ // Send subscription with bloom filter
352
+ ws.send(JSON.stringify({
353
+ type: 'subscribe',
354
+ dids: dids, // Simple implementation sends full DID list
355
+ bloomSize: this.bloomFilterSize,
356
+ bloomFpr: this.bloomFilterFpr,
357
+ }));
358
+ });
359
+ ws.addEventListener('message', (event) => {
360
+ try {
361
+ const trustEvent = JSON.parse(event.data);
362
+ // Check if event DID matches our subscription
363
+ const eventHash = this.hashDid(trustEvent.did);
364
+ if (bloomSet.has(eventHash)) {
365
+ // Invalidate cache for this DID
366
+ if (trustEvent.type === 'revocation' || trustEvent.type === 'succession') {
367
+ this.resolveCache.delete(trustEvent.did);
368
+ this.entryCache.delete(trustEvent.did);
369
+ }
370
+ // Notify callback
371
+ callback(trustEvent);
372
+ }
373
+ }
374
+ catch (error) {
375
+ // Ignore malformed events
376
+ console.warn('Failed to parse trust event:', error);
377
+ }
378
+ });
379
+ ws.addEventListener('error', (error) => {
380
+ console.error('WebSocket error:', error);
381
+ });
382
+ // Return unsubscribe function
383
+ return () => {
384
+ if (ws.readyState === globalThis.WebSocket.OPEN) {
385
+ ws.close();
386
+ }
387
+ };
388
+ }
389
+ /**
390
+ * Simple hash function for bloom filter (DID → number).
391
+ * Production implementation would use proper bloom filter hashing.
392
+ */
393
+ hashDid(did) {
394
+ let hash = 0;
395
+ for (let i = 0; i < did.length; i++) {
396
+ hash = ((hash << 5) - hash) + did.charCodeAt(i);
397
+ hash = hash & hash; // Convert to 32-bit integer
398
+ }
399
+ return hash;
400
+ }
401
+ /**
402
+ * Resume subscriptions on this gateway using proofs from another gateway.
403
+ *
404
+ * Allows clients to migrate between gateways without re-subscribing.
405
+ * Validates proofs and restores subscription state.
406
+ *
407
+ * @param proofs - Array of subscription proofs from previous gateway.
408
+ * @returns Success or error.
409
+ *
410
+ * @example
411
+ * ```typescript
412
+ * const registry = new HttpTrustRegistry({ baseUrl: 'https://atelier2.xail.io' });
413
+ * const result = await registry.resumeSubscriptions([proof1, proof2]);
414
+ * ```
415
+ */
416
+ async resumeSubscriptions(proofs) {
417
+ try {
418
+ const res = await this.fetchFn(`${this.baseUrl}/trust/resume-batch`, {
419
+ method: 'POST',
420
+ headers: { 'Content-Type': 'application/json' },
421
+ body: JSON.stringify({ proofs }),
422
+ });
423
+ if (!res.ok)
424
+ return (0, shared_1.err)('NETWORK_ERROR');
425
+ return (0, shared_1.ok)(undefined);
426
+ }
427
+ catch {
428
+ return (0, shared_1.err)('NETWORK_ERROR');
429
+ }
430
+ }
431
+ /**
432
+ * Fetch signed checkpoint for a DID (freshness primitive).
433
+ *
434
+ * Checkpoints provide cryptographic proof of DID state at a specific timestamp.
435
+ * Clients verify checkpoint signature and compare rotation_sequence to detect staleness.
436
+ *
437
+ * @param did - DID to fetch checkpoint for
438
+ * @returns Signed checkpoint or error
439
+ *
440
+ * @example
441
+ * ```typescript
442
+ * const checkpoint = await registry.fetchCheckpoint('did:key:z6Mk...');
443
+ * if (checkpoint.ok) {
444
+ * const verified = await verifyCheckpoint(checkpoint.value, gatewayPubKey);
445
+ * if (verified.ok && verified.value) {
446
+ * // Use checkpoint for staleness detection
447
+ * if (isCacheStale(localCache, checkpoint.value)) {
448
+ * // Refresh cache
449
+ * }
450
+ * }
451
+ * }
452
+ * ```
453
+ */
454
+ async fetchCheckpoint(did) {
455
+ try {
456
+ const res = await this.fetchFn(`${this.baseUrl}/registry/checkpoint/${encodeURIComponent(did)}`);
457
+ if (res.status === 404)
458
+ return (0, shared_1.err)('NOT_FOUND');
459
+ if (!res.ok)
460
+ return (0, shared_1.err)('NETWORK_ERROR');
461
+ const checkpoint = (await res.json());
462
+ return (0, shared_1.ok)(checkpoint);
463
+ }
464
+ catch {
465
+ return (0, shared_1.err)('NETWORK_ERROR');
466
+ }
467
+ }
468
+ async updateScopes(did, scopes) {
469
+ try {
470
+ const res = await this.fetchFn(`${this.baseUrl}/registry/${encodeURIComponent(did)}/scopes`, {
471
+ method: 'POST',
472
+ headers: { 'Content-Type': 'application/json' },
473
+ body: JSON.stringify({ scopes }),
474
+ });
475
+ if (res.status === 404)
476
+ return (0, shared_1.err)('NOT_FOUND');
477
+ if (res.status === 410)
478
+ return (0, shared_1.err)('REVOKED');
479
+ if (!res.ok)
480
+ return (0, shared_1.err)('NETWORK_ERROR');
481
+ // Clear cache for this DID
482
+ this.resolveCache.delete(did);
483
+ this.entryCache.delete(did);
484
+ return (0, shared_1.ok)(undefined);
485
+ }
486
+ catch {
487
+ return (0, shared_1.err)('NETWORK_ERROR');
488
+ }
489
+ }
490
+ }
491
+ exports.HttpTrustRegistry = HttpTrustRegistry;
492
+ /**
493
+ * File-based trust registry using JSONL append-only log.
494
+ * Replays all entries on initialization, keeps in-memory Map for fast access.
495
+ * Suitable for production deployments with local persistence.
496
+ */
497
+ class FileTrustRegistry {
498
+ path;
499
+ entries = new Map();
500
+ initialized = false;
501
+ constructor(opts) {
502
+ this.path = opts.path;
503
+ }
504
+ /** Initialize by replaying JSONL log. Called automatically on first operation. */
505
+ async init() {
506
+ if (this.initialized)
507
+ return;
508
+ try {
509
+ // Ensure directory exists
510
+ await fs.mkdir(path.dirname(this.path), { recursive: true });
511
+ // Read and replay JSONL file
512
+ const content = await fs.readFile(this.path, 'utf-8').catch(() => '');
513
+ const lines = content.split('\n').filter((line) => line.trim());
514
+ for (const line of lines) {
515
+ const record = JSON.parse(line);
516
+ if (record.type === 'register' && record.publicKey && record.name) {
517
+ this.entries.set(record.did, {
518
+ did: record.did,
519
+ publicKey: new Uint8Array(record.publicKey),
520
+ name: record.name,
521
+ scopes: new Set(record.scopes ?? []),
522
+ receiveScopes: record.receiveScopes ? new Set(record.receiveScopes) : undefined,
523
+ revoked: false,
524
+ rotation_sequence: record.rotation_sequence ?? 1,
525
+ x25519PublicKey: record.x25519PublicKey
526
+ ? new Uint8Array(record.x25519PublicKey)
527
+ : undefined,
528
+ mlKemPublicKey: record.mlKemPublicKey
529
+ ? new Uint8Array(record.mlKemPublicKey)
530
+ : undefined,
531
+ mlDsaPublicKey: record.mlDsaPublicKey
532
+ ? new Uint8Array(record.mlDsaPublicKey)
533
+ : undefined,
534
+ xchange: record.xchange,
535
+ });
536
+ }
537
+ else if (record.type === 'revoke') {
538
+ const entry = this.entries.get(record.did);
539
+ if (entry) {
540
+ this.entries.set(record.did, { ...entry, revoked: true });
541
+ }
542
+ }
543
+ else if (record.type === 'update-scopes') {
544
+ const entry = this.entries.get(record.did);
545
+ if (entry) {
546
+ this.entries.set(record.did, { ...entry, scopes: new Set(record.scopes ?? []) });
547
+ }
548
+ }
549
+ else if (record.type === 'rotate' && record.publicKey && record.rotation_sequence) {
550
+ const entry = this.entries.get(record.did);
551
+ if (entry) {
552
+ // Only apply rotation if sequence is greater (prevents replaying stale rotations)
553
+ if (record.rotation_sequence > entry.rotation_sequence) {
554
+ this.entries.set(record.did, {
555
+ ...entry,
556
+ publicKey: new Uint8Array(record.publicKey),
557
+ rotation_sequence: record.rotation_sequence,
558
+ });
559
+ }
560
+ }
561
+ }
562
+ }
563
+ }
564
+ catch (error) {
565
+ // If file doesn't exist yet, that's OK - it will be created on first write
566
+ }
567
+ this.initialized = true;
568
+ }
569
+ /** Append record to JSONL file. */
570
+ async append(record) {
571
+ await fs.appendFile(this.path, JSON.stringify(record) + '\n', 'utf-8');
572
+ }
573
+ async register(did, publicKey, name, scopes, x25519PublicKey, mlKemPublicKey, mlDsaPublicKey, xchange, receiveScopes) {
574
+ await this.init();
575
+ if (this.entries.has(did))
576
+ return (0, shared_1.err)('ALREADY_REGISTERED');
577
+ const entry = {
578
+ did,
579
+ publicKey,
580
+ name,
581
+ scopes: new Set(scopes ?? []),
582
+ receiveScopes: receiveScopes ? new Set(receiveScopes) : undefined,
583
+ revoked: false,
584
+ rotation_sequence: 1, // Initial sequence starts at 1
585
+ x25519PublicKey,
586
+ mlKemPublicKey,
587
+ mlDsaPublicKey,
588
+ xchange,
589
+ };
590
+ this.entries.set(did, entry);
591
+ // Append to JSONL
592
+ await this.append({
593
+ type: 'register',
594
+ did,
595
+ publicKey: Array.from(publicKey),
596
+ name,
597
+ scopes: scopes ?? [],
598
+ rotation_sequence: 1,
599
+ ...(receiveScopes ? { receiveScopes } : {}),
600
+ ...(x25519PublicKey ? { x25519PublicKey: Array.from(x25519PublicKey) } : {}),
601
+ ...(mlKemPublicKey ? { mlKemPublicKey: Array.from(mlKemPublicKey) } : {}),
602
+ ...(mlDsaPublicKey ? { mlDsaPublicKey: Array.from(mlDsaPublicKey) } : {}),
603
+ ...(xchange !== undefined ? { xchange } : {}),
604
+ });
605
+ return (0, shared_1.ok)(undefined);
606
+ }
607
+ async resolve(did) {
608
+ await this.init();
609
+ const entry = this.entries.get(did);
610
+ if (!entry)
611
+ return (0, shared_1.err)('NOT_FOUND');
612
+ if (entry.revoked)
613
+ return (0, shared_1.err)('REVOKED');
614
+ return (0, shared_1.ok)(entry.publicKey);
615
+ }
616
+ async hasScope(did, scope) {
617
+ await this.init();
618
+ const entry = this.entries.get(did);
619
+ if (!entry || entry.revoked)
620
+ return false;
621
+ return entry.scopes.has(scope);
622
+ }
623
+ async hasReceiveScope(did, scope) {
624
+ await this.init();
625
+ const entry = this.entries.get(did);
626
+ if (!entry || entry.revoked)
627
+ return false;
628
+ // Undefined = accept all scopes (backward compatibility)
629
+ if (!entry.receiveScopes)
630
+ return true;
631
+ return entry.receiveScopes.has(scope);
632
+ }
633
+ async revoke(did) {
634
+ await this.init();
635
+ const entry = this.entries.get(did);
636
+ if (!entry)
637
+ return (0, shared_1.err)('NOT_FOUND');
638
+ this.entries.set(did, { ...entry, revoked: true });
639
+ await this.append({ type: 'revoke', did });
640
+ return (0, shared_1.ok)(undefined);
641
+ }
642
+ async getEntry(did) {
643
+ await this.init();
644
+ const entry = this.entries.get(did);
645
+ if (!entry)
646
+ return (0, shared_1.err)('NOT_FOUND');
647
+ return (0, shared_1.ok)(entry);
648
+ }
649
+ async updateScopes(did, scopes) {
650
+ await this.init();
651
+ const entry = this.entries.get(did);
652
+ if (!entry)
653
+ return (0, shared_1.err)('NOT_FOUND');
654
+ if (entry.revoked)
655
+ return (0, shared_1.err)('REVOKED');
656
+ this.entries.set(did, { ...entry, scopes: new Set(scopes) });
657
+ await this.append({ type: 'update-scopes', did, scopes });
658
+ return (0, shared_1.ok)(undefined);
659
+ }
660
+ /**
661
+ * Rotate a DID to a new public key with rollback protection.
662
+ *
663
+ * Validates that rotationSequence is greater than current sequence to prevent
664
+ * rollback attacks. Appends rotation event to JSONL and updates in-memory state.
665
+ *
666
+ * @param did - DID being rotated
667
+ * @param newPublicKey - New public key bytes
668
+ * @param proof - Cryptographic proof (e.g., signature from old key)
669
+ * @param rotationSequence - Monotonically increasing sequence number
670
+ * @throws Error if DID not found or sequence validation fails
671
+ */
672
+ async rotate(did, newPublicKey, proof, rotationSequence) {
673
+ await this.init();
674
+ const entry = this.entries.get(did);
675
+ if (!entry) {
676
+ throw new Error(`DID not found: ${did}`);
677
+ }
678
+ // Rollback protection: new sequence must be greater than current
679
+ if (rotationSequence <= entry.rotation_sequence) {
680
+ throw new Error(`Rotation sequence ${rotationSequence} must be > current ${entry.rotation_sequence} (rollback attack prevented)`);
681
+ }
682
+ // Append rotation event to JSONL
683
+ await this.append({
684
+ type: 'rotate',
685
+ did,
686
+ publicKey: Array.from(newPublicKey),
687
+ proof: Array.from(proof),
688
+ rotation_sequence: rotationSequence,
689
+ timestamp: Date.now(),
690
+ });
691
+ // Update in-memory entry
692
+ this.entries.set(did, {
693
+ ...entry,
694
+ publicKey: newPublicKey,
695
+ rotation_sequence: rotationSequence,
696
+ });
697
+ }
698
+ /** Number of entries (for testing). */
699
+ get size() {
700
+ return this.entries.size;
701
+ }
702
+ }
703
+ exports.FileTrustRegistry = FileTrustRegistry;
704
+ /* ── Enterprise Factory ── */
705
+ /**
706
+ * Create an enterprise trust registry with optional pre-population.
707
+ * Suitable for corporate deployments with centralized trust management.
708
+ *
709
+ * @example
710
+ * ```typescript
711
+ * const registry = await TrustRegistry.enterprise({
712
+ * storage: 'file',
713
+ * path: '/opt/corp/trust.jsonl',
714
+ * preload: [
715
+ * { did: 'did:web:corp.example.com', publicKey: ..., name: 'Corporate Gateway' }
716
+ * ]
717
+ * });
718
+ * ```
719
+ */
720
+ async function createEnterpriseTrustRegistry(opts) {
721
+ let registry;
722
+ if (opts.storage === 'file') {
723
+ if (!opts.path)
724
+ throw new Error('FileTrustRegistry requires path option');
725
+ registry = new FileTrustRegistry({ path: opts.path });
726
+ }
727
+ else if (opts.storage === 'http') {
728
+ if (!opts.baseUrl)
729
+ throw new Error('HttpTrustRegistry requires baseUrl option');
730
+ registry = new HttpTrustRegistry({ baseUrl: opts.baseUrl });
731
+ }
732
+ else {
733
+ registry = new MemoryTrustRegistry();
734
+ }
735
+ // Pre-populate if requested
736
+ if (opts.preload) {
737
+ for (const entry of opts.preload) {
738
+ await registry.register(entry.did, entry.publicKey, entry.name, entry.scopes, entry.x25519PublicKey, entry.mlKemPublicKey, entry.mlDsaPublicKey, entry.xchange, entry.receiveScopes);
739
+ }
740
+ }
741
+ return registry;
742
+ }