@private.me/xbind 1.3.5 → 3.0.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 (306) hide show
  1. package/LICENSES.md +212 -0
  2. package/README.md +388 -6
  3. package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1 -1920
  4. package/dist-standalone/_deps/shared/cjs/errors.js +1 -639
  5. package/dist-standalone/_deps/shared/cjs/index.js +1 -496
  6. package/dist-standalone/_deps/shared/cjs/types.js +1 -317
  7. package/dist-standalone/_deps/shared/errors.js +1 -255
  8. package/dist-standalone/_deps/shared/index.js +1 -74
  9. package/dist-standalone/_deps/shared/types.js +1 -90
  10. package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -1
  11. package/dist-standalone/_deps/ux-helpers/cjs/index.js +1 -1
  12. package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +1 -1
  13. package/dist-standalone/_deps/ux-helpers/cjs/progress.js +1 -1
  14. package/dist-standalone/_deps/ux-helpers/cjs/search.js +1 -1
  15. package/dist-standalone/_deps/ux-helpers/cjs/types.js +1 -1
  16. package/dist-standalone/_deps/ux-helpers/errors.js +1 -1
  17. package/dist-standalone/_deps/ux-helpers/index.js +1 -1
  18. package/dist-standalone/_deps/ux-helpers/pagination.js +1 -1
  19. package/dist-standalone/_deps/ux-helpers/progress.js +1 -1
  20. package/dist-standalone/_deps/ux-helpers/search.js +1 -1
  21. package/dist-standalone/_deps/xchange/auto-accept.js +1 -1
  22. package/dist-standalone/_deps/xchange/cjs/auto-accept.js +1 -1
  23. package/dist-standalone/_deps/xchange/cjs/errors.js +1 -1
  24. package/dist-standalone/_deps/xchange/cjs/index.js +1 -1
  25. package/dist-standalone/_deps/xchange/cjs/invite-client.js +1 -1
  26. package/dist-standalone/_deps/xchange/cjs/lazy-init.js +1 -1
  27. package/dist-standalone/_deps/xchange/cjs/trust-integration.js +1 -1
  28. package/dist-standalone/_deps/xchange/cjs/xchange.js +1 -1
  29. package/dist-standalone/_deps/xchange/errors.js +1 -1
  30. package/dist-standalone/_deps/xchange/index.js +1 -1
  31. package/dist-standalone/_deps/xchange/invite-client.js +1 -1
  32. package/dist-standalone/_deps/xchange/lazy-init.js +1 -1
  33. package/dist-standalone/_deps/xchange/trust-integration.js +1 -1
  34. package/dist-standalone/_deps/xchange/xchange.js +1 -1
  35. package/dist-standalone/_deps/xregistry/cjs/discovery.js +1 -1
  36. package/dist-standalone/_deps/xregistry/cjs/errors.js +1 -1
  37. package/dist-standalone/_deps/xregistry/cjs/index.js +1 -1
  38. package/dist-standalone/_deps/xregistry/cjs/registry.js +1 -1
  39. package/dist-standalone/_deps/xregistry/cjs/schema.js +1 -1
  40. package/dist-standalone/_deps/xregistry/cjs/types.js +1 -1
  41. package/dist-standalone/_deps/xregistry/discovery.js +1 -1
  42. package/dist-standalone/_deps/xregistry/errors.js +1 -1
  43. package/dist-standalone/_deps/xregistry/index.js +1 -1
  44. package/dist-standalone/_deps/xregistry/registry.js +1 -1
  45. package/dist-standalone/_deps/xregistry/schema.js +1 -1
  46. package/dist-standalone/_deps/xregistry/types.js +1 -1
  47. package/dist-standalone/agent-call.js +1 -642
  48. package/dist-standalone/agent-sdk.js +1 -328
  49. package/dist-standalone/agent.d.ts +95 -5
  50. package/dist-standalone/agent.js +1 -1545
  51. package/dist-standalone/approval.js +1 -193
  52. package/dist-standalone/async-iterators.d.ts +275 -0
  53. package/dist-standalone/async-iterators.js +1 -0
  54. package/dist-standalone/auth.js +1 -219
  55. package/dist-standalone/auto-accept.js +1 -229
  56. package/dist-standalone/backup-config.js +1 -201
  57. package/dist-standalone/backup.d.ts +114 -0
  58. package/dist-standalone/backup.js +1 -0
  59. package/dist-standalone/batch-operations.d.ts +297 -0
  60. package/dist-standalone/batch-operations.js +1 -0
  61. package/dist-standalone/cancellation.d.ts +301 -0
  62. package/dist-standalone/cancellation.js +1 -0
  63. package/dist-standalone/checkpoint.js +1 -186
  64. package/dist-standalone/circuit-breaker.d.ts +351 -0
  65. package/dist-standalone/circuit-breaker.js +1 -0
  66. package/dist-standalone/cjs/agent-call.js +1 -651
  67. package/dist-standalone/cjs/agent-sdk.js +1 -332
  68. package/dist-standalone/cjs/agent.js +1 -1582
  69. package/dist-standalone/cjs/approval.js +1 -199
  70. package/dist-standalone/cjs/async-iterators.js +1 -0
  71. package/dist-standalone/cjs/auth.js +1 -225
  72. package/dist-standalone/cjs/auto-accept.js +1 -233
  73. package/dist-standalone/cjs/backup-config.js +1 -207
  74. package/dist-standalone/cjs/backup.js +1 -0
  75. package/dist-standalone/cjs/batch-operations.js +1 -0
  76. package/dist-standalone/cjs/cancellation.js +1 -0
  77. package/dist-standalone/cjs/checkpoint.js +1 -193
  78. package/dist-standalone/cjs/circuit-breaker.js +1 -0
  79. package/dist-standalone/cjs/cli/init.js +1 -486
  80. package/dist-standalone/cjs/config-validation.js +1 -0
  81. package/dist-standalone/cjs/connect.js +1 -312
  82. package/dist-standalone/cjs/connection-pool.js +1 -0
  83. package/dist-standalone/cjs/correlation-id.js +1 -339
  84. package/dist-standalone/cjs/crypto-utils.js +1 -0
  85. package/dist-standalone/cjs/debug-mode.js +1 -0
  86. package/dist-standalone/cjs/did-document.js +1 -101
  87. package/dist-standalone/cjs/did-privateme.js +1 -130
  88. package/dist-standalone/cjs/did-web.js +1 -201
  89. package/dist-standalone/cjs/discovery.js +1 -462
  90. package/dist-standalone/cjs/dual-mode.js +1 -251
  91. package/dist-standalone/cjs/email-templates.js +1 -313
  92. package/dist-standalone/cjs/email-transport.js +1 -239
  93. package/dist-standalone/cjs/envelope.js +1 -510
  94. package/dist-standalone/cjs/errors.js +1 -826
  95. package/dist-standalone/cjs/event-emitter.js +1 -0
  96. package/dist-standalone/cjs/gateway-state.js +1 -55
  97. package/dist-standalone/cjs/gateway-transport.js +1 -120
  98. package/dist-standalone/cjs/graceful-degradation.js +1 -0
  99. package/dist-standalone/cjs/guardrails.js +1 -223
  100. package/dist-standalone/cjs/health-check.js +1 -0
  101. package/dist-standalone/cjs/http-compat.js +1 -272
  102. package/dist-standalone/cjs/http-status-map.js +1 -571
  103. package/dist-standalone/cjs/identity.js +1 -540
  104. package/dist-standalone/cjs/index.js +1 -237
  105. package/dist-standalone/cjs/invitation.js +1 -421
  106. package/dist-standalone/cjs/invite.js +1 -328
  107. package/dist-standalone/cjs/key-agreement.js +1 -246
  108. package/dist-standalone/cjs/lazy-init.js +1 -300
  109. package/dist-standalone/cjs/logger.js +1 -0
  110. package/dist-standalone/cjs/mdns-discovery.js +1 -202
  111. package/dist-standalone/cjs/nonce-store.js +1 -66
  112. package/dist-standalone/cjs/pairing-manager.js +1 -223
  113. package/dist-standalone/cjs/plugin-system.js +1 -0
  114. package/dist-standalone/cjs/plugins/logging.js +1 -0
  115. package/dist-standalone/cjs/plugins/metrics.js +1 -0
  116. package/dist-standalone/cjs/plugins/validation.js +1 -0
  117. package/dist-standalone/cjs/policy.js +1 -320
  118. package/dist-standalone/cjs/progress-callbacks.js +1 -0
  119. package/dist-standalone/cjs/redis-nonce-store.js +1 -76
  120. package/dist-standalone/cjs/registry-middleware.js +1 -50
  121. package/dist-standalone/cjs/retry-strategies.js +1 -0
  122. package/dist-standalone/cjs/retry-transport.js +1 -102
  123. package/dist-standalone/cjs/runtime/browser.js +1 -0
  124. package/dist-standalone/cjs/runtime/edge.js +1 -0
  125. package/dist-standalone/cjs/runtime/react-native.js +1 -0
  126. package/dist-standalone/cjs/security-policy.js +1 -245
  127. package/dist-standalone/cjs/serialization.js +1 -0
  128. package/dist-standalone/cjs/split-channel.js +1 -177
  129. package/dist-standalone/cjs/subscription-proof.js +1 -230
  130. package/dist-standalone/cjs/succession.js +1 -148
  131. package/dist-standalone/cjs/timeouts.js +1 -0
  132. package/dist-standalone/cjs/trace-context.js +1 -0
  133. package/dist-standalone/cjs/trace-spans.js +1 -0
  134. package/dist-standalone/cjs/transport.js +1 -63
  135. package/dist-standalone/cjs/trust-registry.js +1 -742
  136. package/dist-standalone/cjs/types/error-response.js +1 -56
  137. package/dist-standalone/cjs/vault-auth.js +1 -0
  138. package/dist-standalone/cjs/vault-store-loader.js +1 -0
  139. package/dist-standalone/cjs/verify.js +1 -25
  140. package/dist-standalone/cjs/version-info.js +1 -0
  141. package/dist-standalone/cjs/xfetch.js +1 -252
  142. package/dist-standalone/cli/init.js +1 -449
  143. package/dist-standalone/cli/setup.js +1 -514
  144. package/dist-standalone/cli/types.js +1 -27
  145. package/dist-standalone/cli/xbind.js +1 -148
  146. package/dist-standalone/config-validation.d.ts +185 -0
  147. package/dist-standalone/config-validation.js +1 -0
  148. package/dist-standalone/connect.js +1 -274
  149. package/dist-standalone/connection-pool.d.ts +251 -0
  150. package/dist-standalone/connection-pool.js +1 -0
  151. package/dist-standalone/correlation-id.js +1 -326
  152. package/dist-standalone/crypto-utils.d.ts +60 -0
  153. package/dist-standalone/crypto-utils.js +1 -0
  154. package/dist-standalone/debug-mode.d.ts +286 -0
  155. package/dist-standalone/debug-mode.js +1 -0
  156. package/dist-standalone/did-document.js +1 -96
  157. package/dist-standalone/did-privateme.js +1 -121
  158. package/dist-standalone/did-web.js +1 -196
  159. package/dist-standalone/discovery.js +1 -458
  160. package/dist-standalone/dual-mode.js +1 -247
  161. package/dist-standalone/email-templates.js +1 -309
  162. package/dist-standalone/email-transport.js +1 -232
  163. package/dist-standalone/envelope.d.ts +29 -1
  164. package/dist-standalone/envelope.js +1 -497
  165. package/dist-standalone/errors.d.ts +10 -0
  166. package/dist-standalone/errors.js +1 -811
  167. package/dist-standalone/event-emitter.d.ts +395 -0
  168. package/dist-standalone/event-emitter.js +1 -0
  169. package/dist-standalone/gateway-state.js +1 -51
  170. package/dist-standalone/gateway-transport.js +1 -116
  171. package/dist-standalone/graceful-degradation.d.ts +246 -0
  172. package/dist-standalone/graceful-degradation.js +1 -0
  173. package/dist-standalone/guardrails.js +1 -216
  174. package/dist-standalone/health-check.d.ts +150 -0
  175. package/dist-standalone/health-check.js +1 -0
  176. package/dist-standalone/http-compat.js +1 -267
  177. package/dist-standalone/http-status-map.js +1 -561
  178. package/dist-standalone/identity.d.ts +64 -1
  179. package/dist-standalone/identity.js +1 -515
  180. package/dist-standalone/index.d.ts +45 -3
  181. package/dist-standalone/index.js +1 -52
  182. package/dist-standalone/invitation.js +1 -415
  183. package/dist-standalone/invite.js +1 -324
  184. package/dist-standalone/key-agreement.d.ts +61 -13
  185. package/dist-standalone/key-agreement.js +1 -236
  186. package/dist-standalone/lazy-init.js +1 -295
  187. package/dist-standalone/logger.d.ts +77 -0
  188. package/dist-standalone/logger.js +1 -0
  189. package/dist-standalone/mdns-discovery.js +1 -195
  190. package/dist-standalone/nonce-store.d.ts +16 -3
  191. package/dist-standalone/nonce-store.js +1 -62
  192. package/dist-standalone/package.json +0 -1
  193. package/dist-standalone/pairing-manager.js +1 -219
  194. package/dist-standalone/plugin-system.d.ts +145 -0
  195. package/dist-standalone/plugin-system.js +1 -0
  196. package/dist-standalone/policy.js +1 -315
  197. package/dist-standalone/progress-callbacks.d.ts +394 -0
  198. package/dist-standalone/progress-callbacks.js +1 -0
  199. package/dist-standalone/redis-nonce-store.js +1 -72
  200. package/dist-standalone/registry-middleware.js +1 -47
  201. package/dist-standalone/retry-strategies.d.ts +382 -0
  202. package/dist-standalone/retry-strategies.js +1 -0
  203. package/dist-standalone/retry-transport.js +1 -98
  204. package/dist-standalone/security-policy.js +1 -239
  205. package/dist-standalone/serialization.d.ts +244 -0
  206. package/dist-standalone/serialization.js +1 -0
  207. package/dist-standalone/split-channel.d.ts +49 -1
  208. package/dist-standalone/split-channel.js +1 -171
  209. package/dist-standalone/subscription-proof.js +1 -224
  210. package/dist-standalone/succession.js +1 -142
  211. package/dist-standalone/timeouts.d.ts +275 -0
  212. package/dist-standalone/timeouts.js +1 -0
  213. package/dist-standalone/trace-context.d.ts +252 -0
  214. package/dist-standalone/trace-context.js +1 -0
  215. package/dist-standalone/trace-spans.d.ts +360 -0
  216. package/dist-standalone/trace-spans.js +1 -0
  217. package/dist-standalone/transport.js +1 -59
  218. package/dist-standalone/trust-registry.d.ts +106 -5
  219. package/dist-standalone/trust-registry.js +1 -702
  220. package/dist-standalone/vault-auth.d.ts +91 -0
  221. package/dist-standalone/vault-auth.js +1 -0
  222. package/dist-standalone/vault-store-loader.d.ts +110 -0
  223. package/dist-standalone/vault-store-loader.js +1 -0
  224. package/dist-standalone/verify.js +1 -16
  225. package/dist-standalone/version-info.d.ts +259 -0
  226. package/dist-standalone/version-info.js +1 -0
  227. package/dist-standalone/xfetch.js +1 -247
  228. package/llms.txt +1 -0
  229. package/package.json +65 -5
  230. package/share1.dat +0 -0
  231. package/dist-standalone/_deps/crypto/base64.d.ts +0 -29
  232. package/dist-standalone/_deps/crypto/base64.js +0 -222
  233. package/dist-standalone/_deps/crypto/cjs/base64.js +0 -665
  234. package/dist-standalone/_deps/crypto/cjs/errors.js +0 -675
  235. package/dist-standalone/_deps/crypto/cjs/hmac.js +0 -473
  236. package/dist-standalone/_deps/crypto/cjs/index.js +0 -852
  237. package/dist-standalone/_deps/crypto/cjs/package.json +0 -1
  238. package/dist-standalone/_deps/crypto/cjs/padding.js +0 -511
  239. package/dist-standalone/_deps/crypto/cjs/share-header.js +0 -372
  240. package/dist-standalone/_deps/crypto/cjs/shares.js +0 -874
  241. package/dist-standalone/_deps/crypto/cjs/tlv.js +0 -1021
  242. package/dist-standalone/_deps/crypto/cjs/uuid.js +0 -443
  243. package/dist-standalone/_deps/crypto/cjs/verify.js +0 -414
  244. package/dist-standalone/_deps/crypto/cjs/xorida.js +0 -923
  245. package/dist-standalone/_deps/crypto/errors.d.ts +0 -51
  246. package/dist-standalone/_deps/crypto/errors.js +0 -199
  247. package/dist-standalone/_deps/crypto/hmac.d.ts +0 -39
  248. package/dist-standalone/_deps/crypto/hmac.js +0 -134
  249. package/dist-standalone/_deps/crypto/index.d.ts +0 -20
  250. package/dist-standalone/_deps/crypto/index.js +0 -145
  251. package/dist-standalone/_deps/crypto/padding.d.ts +0 -19
  252. package/dist-standalone/_deps/crypto/padding.js +0 -159
  253. package/dist-standalone/_deps/crypto/share-header.d.ts +0 -44
  254. package/dist-standalone/_deps/crypto/share-header.js +0 -92
  255. package/dist-standalone/_deps/crypto/shares.d.ts +0 -27
  256. package/dist-standalone/_deps/crypto/shares.js +0 -295
  257. package/dist-standalone/_deps/crypto/tlv.d.ts +0 -26
  258. package/dist-standalone/_deps/crypto/tlv.js +0 -364
  259. package/dist-standalone/_deps/crypto/uuid.d.ts +0 -22
  260. package/dist-standalone/_deps/crypto/uuid.js +0 -136
  261. package/dist-standalone/_deps/crypto/verify.d.ts +0 -15
  262. package/dist-standalone/_deps/crypto/verify.js +0 -71
  263. package/dist-standalone/_deps/crypto/xorida.d.ts +0 -44
  264. package/dist-standalone/_deps/crypto/xorida.js +0 -366
  265. package/dist-standalone/_deps/shared/errors.d.ts.map +0 -1
  266. package/dist-standalone/_deps/shared/errors.js.map +0 -1
  267. package/dist-standalone/_deps/shared/index.d.ts.map +0 -1
  268. package/dist-standalone/_deps/shared/index.js.map +0 -1
  269. package/dist-standalone/_deps/shared/types.d.ts.map +0 -1
  270. package/dist-standalone/_deps/shared/types.js.map +0 -1
  271. package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts.map +0 -1
  272. package/dist-standalone/_deps/ux-helpers/cjs/errors.js.map +0 -1
  273. package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts.map +0 -1
  274. package/dist-standalone/_deps/ux-helpers/cjs/index.js.map +0 -1
  275. package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts.map +0 -1
  276. package/dist-standalone/_deps/ux-helpers/cjs/pagination.js.map +0 -1
  277. package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts.map +0 -1
  278. package/dist-standalone/_deps/ux-helpers/cjs/progress.js.map +0 -1
  279. package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts.map +0 -1
  280. package/dist-standalone/_deps/ux-helpers/cjs/search.js.map +0 -1
  281. package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts.map +0 -1
  282. package/dist-standalone/_deps/ux-helpers/cjs/types.js.map +0 -1
  283. package/dist-standalone/_deps/ux-helpers/errors.d.ts.map +0 -1
  284. package/dist-standalone/_deps/ux-helpers/errors.js.map +0 -1
  285. package/dist-standalone/_deps/ux-helpers/index.d.ts.map +0 -1
  286. package/dist-standalone/_deps/ux-helpers/index.js.map +0 -1
  287. package/dist-standalone/_deps/ux-helpers/pagination.d.ts.map +0 -1
  288. package/dist-standalone/_deps/ux-helpers/pagination.js.map +0 -1
  289. package/dist-standalone/_deps/ux-helpers/progress.d.ts.map +0 -1
  290. package/dist-standalone/_deps/ux-helpers/progress.js.map +0 -1
  291. package/dist-standalone/_deps/ux-helpers/search.d.ts.map +0 -1
  292. package/dist-standalone/_deps/ux-helpers/search.js.map +0 -1
  293. package/dist-standalone/_deps/ux-helpers/types.d.ts.map +0 -1
  294. package/dist-standalone/_deps/ux-helpers/types.js.map +0 -1
  295. package/dist-standalone/_deps/xregistry/discovery.d.ts.map +0 -1
  296. package/dist-standalone/_deps/xregistry/discovery.js.map +0 -1
  297. package/dist-standalone/_deps/xregistry/errors.d.ts.map +0 -1
  298. package/dist-standalone/_deps/xregistry/errors.js.map +0 -1
  299. package/dist-standalone/_deps/xregistry/index.d.ts.map +0 -1
  300. package/dist-standalone/_deps/xregistry/index.js.map +0 -1
  301. package/dist-standalone/_deps/xregistry/registry.d.ts.map +0 -1
  302. package/dist-standalone/_deps/xregistry/registry.js.map +0 -1
  303. package/dist-standalone/_deps/xregistry/schema.d.ts.map +0 -1
  304. package/dist-standalone/_deps/xregistry/schema.js.map +0 -1
  305. package/dist-standalone/_deps/xregistry/types.d.ts.map +0 -1
  306. package/dist-standalone/_deps/xregistry/types.js.map +0 -1
@@ -1,742 +1 @@
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
- }
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,s){void 0===s&&(s=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,s,i)}:function(e,t,r,s){void 0===s&&(s=r),e[s]=t[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(){var e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},e(t)};return function(t){if(t&&t.__esModule)return t;var r={};if(null!=t)for(var s=e(t),i=0;i<s.length;i++)"default"!==s[i]&&__createBinding(r,t,s[i]);return __setModuleDefault(r,t),r}}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.FileTrustRegistry=exports.HttpTrustRegistry=exports.MemoryTrustRegistry=exports.RegistrationRateLimiter=void 0,exports.createEnterpriseTrustRegistry=createEnterpriseTrustRegistry;const shared_1=require("../_deps/shared/index.js"),fs=__importStar(require("node:fs/promises")),path=__importStar(require("node:path"));function isExpired(e){return!!e.expiresAt&&Date.now()>e.expiresAt}class RegistrationRateLimiter{perIPTimestamps=new Map;globalTimestamps=[];perIPLimit;globalLimit;windowMs;cleanupInterval=null;constructor(e=10,t=1e3,r=36e5){this.perIPLimit=e,this.globalLimit=t,this.windowMs=r,this.cleanupInterval=setInterval(()=>this.cleanup(),3e5)}checkLimit(e){const t=Date.now()-this.windowMs;if((this.perIPTimestamps.get(e)||[]).filter(e=>e>t).length>=this.perIPLimit)return!1;return!(this.globalTimestamps.filter(e=>e>t).length>=this.globalLimit)}recordRegistration(e){const t=Date.now(),r=this.perIPTimestamps.get(e)||[];r.push(t),this.perIPTimestamps.set(e,r),this.globalTimestamps.push(t)}getRemainingForIP(e){const t=Date.now()-this.windowMs,r=(this.perIPTimestamps.get(e)||[]).filter(e=>e>t);return Math.max(0,this.perIPLimit-r.length)}getRemainingGlobal(){const e=Date.now()-this.windowMs,t=this.globalTimestamps.filter(t=>t>e);return Math.max(0,this.globalLimit-t.length)}getResetTimeForIP(e){const t=this.perIPTimestamps.get(e)||[];if(0===t.length)return null;const r=t[0];return r?r+this.windowMs:null}cleanup(){const e=Date.now()-this.windowMs;for(const[t,r]of this.perIPTimestamps.entries()){const s=r.filter(t=>t>e);0===s.length?this.perIPTimestamps.delete(t):this.perIPTimestamps.set(t,s)}const t=this.globalTimestamps.filter(t=>t>e);this.globalTimestamps.length=0,this.globalTimestamps.push(...t)}destroy(){this.cleanupInterval&&(clearInterval(this.cleanupInterval),this.cleanupInterval=null)}reset(){this.perIPTimestamps.clear(),this.globalTimestamps.length=0}}exports.RegistrationRateLimiter=RegistrationRateLimiter;class MemoryTrustRegistry{entries=new Map;rateLimiter;constructor(e){e?.enableRateLimiting&&(this.rateLimiter=e.rateLimiter||new RegistrationRateLimiter)}async register(e,t,r,s,i,n,a,o,c,h,l,d,p,u){if(this.rateLimiter&&u&&!this.rateLimiter.checkLimit(u))return(0,shared_1.err)("RATE_LIMIT_EXCEEDED");if(this.entries.has(e))return(0,shared_1.err)("ALREADY_REGISTERED");const y=p?Date.now()+p:void 0;return this.entries.set(e,{did:e,publicKey:t,name:r,scopes:new Set(s??[]),receiveScopes:c?new Set(c):void 0,revoked:!1,rotation_sequence:1,x25519PublicKey:i,mlKemPublicKey:n,mlDsaPublicKey:a,xchange:o,sdkVersion:h,minEnvelopeVersion:l,maxEnvelopeVersion:d,expiresAt:y}),this.rateLimiter&&u&&this.rateLimiter.recordRegistration(u),(0,shared_1.ok)(void 0)}async resolve(e){const t=this.entries.get(e);return t?isExpired(t)?(0,shared_1.err)("EXPIRED"):t.revoked?(0,shared_1.err)("REVOKED"):(0,shared_1.ok)(t.publicKey):(0,shared_1.err)("NOT_FOUND")}async hasScope(e,t){const r=this.entries.get(e);return!(!r||isExpired(r)||r.revoked)&&r.scopes.has(t)}async hasReceiveScope(e,t){const r=this.entries.get(e);return!(!r||isExpired(r)||r.revoked)&&(!r.receiveScopes||r.receiveScopes.has(t))}async revoke(e){const t=this.entries.get(e);return t?(this.entries.set(e,{...t,revoked:!0}),(0,shared_1.ok)(void 0)):(0,shared_1.err)("NOT_FOUND")}async getEntry(e){const t=this.entries.get(e);return t?isExpired(t)?(0,shared_1.err)("EXPIRED"):(0,shared_1.ok)(t):(0,shared_1.err)("NOT_FOUND")}async updateScopes(e,t){const r=this.entries.get(e);return r?isExpired(r)?(0,shared_1.err)("EXPIRED"):r.revoked?(0,shared_1.err)("REVOKED"):(this.entries.set(e,{...r,scopes:new Set(t)}),(0,shared_1.ok)(void 0)):(0,shared_1.err)("NOT_FOUND")}async cleanup(){let e=0;const t=Date.now();for(const[r,s]of this.entries)s.expiresAt&&t>s.expiresAt&&(this.entries.delete(r),e++);return e}get size(){return this.entries.size}}exports.MemoryTrustRegistry=MemoryTrustRegistry;class HttpTrustRegistry{baseUrl;fetchFn;cacheTtlMs;cacheFailureMode;enablePush;bloomFilterSize;bloomFilterFpr;resolveCache=new Map;entryCache=new Map;constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,""),this.fetchFn=e.fetch??globalThis.fetch.bind(globalThis),this.cacheTtlMs=e.cacheTtlMs??3e4,this.cacheFailureMode=e.cacheFailureMode??"fail-secure",this.enablePush=e.enablePush??!1,this.bloomFilterSize=e.bloomFilterSize??1e4,this.bloomFilterFpr=e.bloomFilterFpr??.01}clearCache(){this.resolveCache.clear(),this.entryCache.clear()}async register(e,t,r,s,i,n,a,o,c,h,l,d,p,u){try{const u=await this.fetchFn(`${this.baseUrl}/registry/register`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({did:e,publicKey:Array.from(t),name:r,scopes:s??[],...c?{receiveScopes:c}:{},...i?{x25519PublicKey:Array.from(i)}:{},...n?{mlKemPublicKey:Array.from(n)}:{},...a?{mlDsaPublicKey:Array.from(a)}:{},...void 0!==o?{xchange:o}:{},...void 0!==h?{sdkVersion:h}:{},...void 0!==l?{minEnvelopeVersion:l}:{},...void 0!==d?{maxEnvelopeVersion:d}:{},...void 0!==p?{ttlMs:p}:{}})});return 409===u.status?(0,shared_1.err)("ALREADY_REGISTERED"):429===u.status?(0,shared_1.err)("RATE_LIMIT_EXCEEDED"):u.ok?(0,shared_1.ok)(void 0):(0,shared_1.err)("NETWORK_ERROR")}catch{return(0,shared_1.err)("NETWORK_ERROR")}}async resolve(e){if(this.cacheTtlMs>0){const t=this.resolveCache.get(e);if(t&&t.expiry>Date.now())return t.value}let t;try{const r=await this.fetchFn(`${this.baseUrl}/registry/resolve/${encodeURIComponent(e)}`);if(404===r.status)t=(0,shared_1.err)("NOT_FOUND");else if(408===r.status)t=(0,shared_1.err)("EXPIRED");else if(410===r.status)t=(0,shared_1.err)("REVOKED");else if(r.ok){const e=await r.json();t=(0,shared_1.ok)(new Uint8Array(e.publicKey))}else t=(0,shared_1.err)("NETWORK_ERROR")}catch{const r=this.resolveCache.get(e);if("fail-secure"===this.cacheFailureMode)t=(0,shared_1.err)("NETWORK_ERROR");else{if(r)return r.value;t=(0,shared_1.err)("NETWORK_ERROR")}}return this.cacheTtlMs>0&&this.resolveCache.set(e,{value:t,expiry:Date.now()+this.cacheTtlMs}),t}async hasScope(e,t){try{return(await this.fetchFn(`${this.baseUrl}/registry/scope/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)).ok}catch{return!1}}async hasReceiveScope(e,t){try{return(await this.fetchFn(`${this.baseUrl}/registry/receive-scope/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)).ok}catch{return!1}}async revoke(e){try{const t=await this.fetchFn(`${this.baseUrl}/registry/revoke/${encodeURIComponent(e)}`,{method:"POST"});return 404===t.status?(0,shared_1.err)("NOT_FOUND"):t.ok?(0,shared_1.ok)(void 0):(0,shared_1.err)("NETWORK_ERROR")}catch{return(0,shared_1.err)("NETWORK_ERROR")}}async getEntry(e){if(this.cacheTtlMs>0){const t=this.entryCache.get(e);if(t&&t.expiry>Date.now())return t.value}let t;try{const r=await this.fetchFn(`${this.baseUrl}/registry/entry/${encodeURIComponent(e)}`);if(404===r.status)t=(0,shared_1.err)("NOT_FOUND");else if(408===r.status)t=(0,shared_1.err)("EXPIRED");else if(r.ok){const e=await r.json();t=(0,shared_1.ok)({did:e.did,publicKey:new Uint8Array(e.publicKey),name:e.name,scopes:new Set(e.scopes),receiveScopes:e.receiveScopes?new Set(e.receiveScopes):void 0,revoked:e.revoked,rotation_sequence:e.rotation_sequence??1,x25519PublicKey:e.x25519PublicKey?new Uint8Array(e.x25519PublicKey):void 0,mlKemPublicKey:e.mlKemPublicKey?new Uint8Array(e.mlKemPublicKey):void 0,mlDsaPublicKey:e.mlDsaPublicKey?new Uint8Array(e.mlDsaPublicKey):void 0,xchange:e.xchange,sdkVersion:e.sdkVersion,minEnvelopeVersion:e.minEnvelopeVersion,maxEnvelopeVersion:e.maxEnvelopeVersion,expiresAt:e.expiresAt})}else t=(0,shared_1.err)("NETWORK_ERROR")}catch{t=(0,shared_1.err)("NETWORK_ERROR")}return this.cacheTtlMs>0&&this.entryCache.set(e,{value:t,expiry:Date.now()+this.cacheTtlMs}),t}async rotate(e,t,r,s){const i=await this.fetchFn(`${this.baseUrl}/registry/rotate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({did:e,newPublicKey:Array.from(t),proof:Array.from(r),rotationSequence:s})});if(!i.ok)throw new Error(`Key rotation failed: ${i.status} ${i.statusText}`);this.resolveCache.delete(e),this.entryCache.delete(e)}async subscribe(e,t){if(!this.enablePush)throw new Error("Push notifications not enabled (set enablePush: true in HttpTrustRegistryOptions)");const r=new Set(e.map(e=>this.hashDid(e))),s=this.baseUrl.replace(/^http/,"ws")+"/trust/events",i=new globalThis.WebSocket(s);return i.addEventListener("open",()=>{i.send(JSON.stringify({type:"subscribe",dids:e,bloomSize:this.bloomFilterSize,bloomFpr:this.bloomFilterFpr}))}),i.addEventListener("message",e=>{try{const s=JSON.parse(e.data),i=this.hashDid(s.did);r.has(i)&&("revocation"!==s.type&&"succession"!==s.type||(this.resolveCache.delete(s.did),this.entryCache.delete(s.did)),t(s))}catch(e){console.warn("Failed to parse trust event:",e)}}),i.addEventListener("error",e=>{console.error("WebSocket error:",e)}),()=>{i.readyState===globalThis.WebSocket.OPEN&&i.close()}}hashDid(e){let t=0;for(let r=0;r<e.length;r++)t=(t<<5)-t+e.charCodeAt(r),t&=t;return t}async resumeSubscriptions(e){try{return(await this.fetchFn(`${this.baseUrl}/trust/resume-batch`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({proofs:e})})).ok?(0,shared_1.ok)(void 0):(0,shared_1.err)("NETWORK_ERROR")}catch{return(0,shared_1.err)("NETWORK_ERROR")}}async fetchCheckpoint(e){try{const t=await this.fetchFn(`${this.baseUrl}/registry/checkpoint/${encodeURIComponent(e)}`);if(404===t.status)return(0,shared_1.err)("NOT_FOUND");if(!t.ok)return(0,shared_1.err)("NETWORK_ERROR");const r=await t.json();return(0,shared_1.ok)(r)}catch{return(0,shared_1.err)("NETWORK_ERROR")}}async updateScopes(e,t){try{const r=await this.fetchFn(`${this.baseUrl}/registry/${encodeURIComponent(e)}/scopes`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scopes:t})});return 404===r.status?(0,shared_1.err)("NOT_FOUND"):410===r.status?(0,shared_1.err)("REVOKED"):r.ok?(this.resolveCache.delete(e),this.entryCache.delete(e),(0,shared_1.ok)(void 0)):(0,shared_1.err)("NETWORK_ERROR")}catch{return(0,shared_1.err)("NETWORK_ERROR")}}}exports.HttpTrustRegistry=HttpTrustRegistry;class FileTrustRegistry{path;entries=new Map;initialized=!1;constructor(e){this.path=e.path}async init(){if(!this.initialized){try{await fs.mkdir(path.dirname(this.path),{recursive:!0});const e=(await fs.readFile(this.path,"utf-8").catch(()=>"")).split("\n").filter(e=>e.trim());for(const t of e){const e=JSON.parse(t);if("register"===e.type&&e.publicKey&&e.name)this.entries.set(e.did,{did:e.did,publicKey:new Uint8Array(e.publicKey),name:e.name,scopes:new Set(e.scopes??[]),receiveScopes:e.receiveScopes?new Set(e.receiveScopes):void 0,revoked:!1,rotation_sequence:e.rotation_sequence??1,x25519PublicKey:e.x25519PublicKey?new Uint8Array(e.x25519PublicKey):void 0,mlKemPublicKey:e.mlKemPublicKey?new Uint8Array(e.mlKemPublicKey):void 0,mlDsaPublicKey:e.mlDsaPublicKey?new Uint8Array(e.mlDsaPublicKey):void 0,xchange:e.xchange,sdkVersion:e.sdkVersion,minEnvelopeVersion:e.minEnvelopeVersion,maxEnvelopeVersion:e.maxEnvelopeVersion,expiresAt:e.expiresAt});else if("revoke"===e.type){const t=this.entries.get(e.did);t&&this.entries.set(e.did,{...t,revoked:!0})}else if("update-scopes"===e.type){const t=this.entries.get(e.did);t&&this.entries.set(e.did,{...t,scopes:new Set(e.scopes??[])})}else if("rotate"===e.type&&e.publicKey&&e.rotation_sequence){const t=this.entries.get(e.did);t&&e.rotation_sequence>t.rotation_sequence&&this.entries.set(e.did,{...t,publicKey:new Uint8Array(e.publicKey),rotation_sequence:e.rotation_sequence})}}}catch(e){}this.initialized=!0}}async append(e){await fs.appendFile(this.path,JSON.stringify(e)+"\n","utf-8")}async register(e,t,r,s,i,n,a,o,c,h,l,d,p,u){if(await this.init(),this.entries.has(e))return(0,shared_1.err)("ALREADY_REGISTERED");const y=p?Date.now()+p:void 0,m={did:e,publicKey:t,name:r,scopes:new Set(s??[]),receiveScopes:c?new Set(c):void 0,revoked:!1,rotation_sequence:1,x25519PublicKey:i,mlKemPublicKey:n,mlDsaPublicKey:a,xchange:o,sdkVersion:h,minEnvelopeVersion:l,maxEnvelopeVersion:d,expiresAt:y};return this.entries.set(e,m),await this.append({type:"register",did:e,publicKey:Array.from(t),name:r,scopes:s??[],rotation_sequence:1,...c?{receiveScopes:c}:{},...i?{x25519PublicKey:Array.from(i)}:{},...n?{mlKemPublicKey:Array.from(n)}:{},...a?{mlDsaPublicKey:Array.from(a)}:{},...void 0!==o?{xchange:o}:{},...void 0!==h?{sdkVersion:h}:{},...void 0!==l?{minEnvelopeVersion:l}:{},...void 0!==d?{maxEnvelopeVersion:d}:{},...void 0!==y?{expiresAt:y}:{}}),(0,shared_1.ok)(void 0)}async resolve(e){await this.init();const t=this.entries.get(e);return t?isExpired(t)?(0,shared_1.err)("EXPIRED"):t.revoked?(0,shared_1.err)("REVOKED"):(0,shared_1.ok)(t.publicKey):(0,shared_1.err)("NOT_FOUND")}async hasScope(e,t){await this.init();const r=this.entries.get(e);return!(!r||isExpired(r)||r.revoked)&&r.scopes.has(t)}async hasReceiveScope(e,t){await this.init();const r=this.entries.get(e);return!(!r||isExpired(r)||r.revoked)&&(!r.receiveScopes||r.receiveScopes.has(t))}async revoke(e){await this.init();const t=this.entries.get(e);return t?(this.entries.set(e,{...t,revoked:!0}),await this.append({type:"revoke",did:e}),(0,shared_1.ok)(void 0)):(0,shared_1.err)("NOT_FOUND")}async getEntry(e){await this.init();const t=this.entries.get(e);return t?isExpired(t)?(0,shared_1.err)("EXPIRED"):(0,shared_1.ok)(t):(0,shared_1.err)("NOT_FOUND")}async updateScopes(e,t){await this.init();const r=this.entries.get(e);return r?isExpired(r)?(0,shared_1.err)("EXPIRED"):r.revoked?(0,shared_1.err)("REVOKED"):(this.entries.set(e,{...r,scopes:new Set(t)}),await this.append({type:"update-scopes",did:e,scopes:t}),(0,shared_1.ok)(void 0)):(0,shared_1.err)("NOT_FOUND")}async cleanup(){await this.init();let e=0;const t=Date.now();for(const[r,s]of this.entries)s.expiresAt&&t>s.expiresAt&&(this.entries.delete(r),e++);return e}async rotate(e,t,r,s){await this.init();const i=this.entries.get(e);if(!i)throw new Error(`DID not found: ${e}`);if(s<=i.rotation_sequence)throw new Error(`Rotation sequence ${s} must be > current ${i.rotation_sequence} (rollback attack prevented)`);await this.append({type:"rotate",did:e,publicKey:Array.from(t),proof:Array.from(r),rotation_sequence:s,timestamp:Date.now()}),this.entries.set(e,{...i,publicKey:t,rotation_sequence:s})}get size(){return this.entries.size}}async function createEnterpriseTrustRegistry(e){let t;if("file"===e.storage){if(!e.path)throw new Error("FileTrustRegistry requires path option");t=new FileTrustRegistry({path:e.path})}else if("http"===e.storage){if(!e.baseUrl)throw new Error("HttpTrustRegistry requires baseUrl option");t=new HttpTrustRegistry({baseUrl:e.baseUrl})}else t=new MemoryTrustRegistry;if(e.preload)for(const r of e.preload)await t.register(r.did,r.publicKey,r.name,r.scopes,r.x25519PublicKey,r.mlKemPublicKey,r.mlDsaPublicKey,r.xchange,r.receiveScopes,r.sdkVersion,r.minEnvelopeVersion,r.maxEnvelopeVersion);return t}exports.FileTrustRegistry=FileTrustRegistry;