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