@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,300 @@
1
+ "use strict";
2
+ /**
3
+ * @module lazy-init
4
+ * Lazy agent initialization for zero-click onboarding.
5
+ *
6
+ * Defers invite acceptance and identity generation until first
7
+ * send/receive call. Enables: `Agent.lazy({ name: 'my-service' })`
8
+ * with no async/await at construction time.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * // Environment: XBIND_INVITE_CODE=XBD-abc123
13
+ *
14
+ * // Old way (explicit):
15
+ * const agent = await Agent.create({ name: 'my-service', registry, transport });
16
+ *
17
+ * // New way (lazy):
18
+ * const agent = Agent.lazy({ name: 'my-service' });
19
+ * // No await, no async — agent is constructed synchronously.
20
+ * // Invite auto-accepts on first send/receive:
21
+ * await agent.send({ to: partnerDid, payload: data, scope: 'test' });
22
+ * ```
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.LazyAgent = exports.LazyAgentErrorCode = void 0;
26
+ exports.createLazyAgent = createLazyAgent;
27
+ const shared_1 = require("../_deps/shared/index.js");
28
+ const agent_js_1 = require("./agent.js");
29
+ const auto_accept_js_1 = require("./auto-accept.js");
30
+ const trust_registry_js_1 = require("./trust-registry.js");
31
+ const transport_js_1 = require("./transport.js");
32
+ const crypto_1 = require("../_deps/crypto/index.js");
33
+ /**
34
+ * Lazy agent error codes.
35
+ */
36
+ var LazyAgentErrorCode;
37
+ (function (LazyAgentErrorCode) {
38
+ LazyAgentErrorCode["INIT_FAILED"] = "LAZY_AGENT_INIT_FAILED";
39
+ LazyAgentErrorCode["AUTO_ACCEPT_FAILED"] = "LAZY_AGENT_AUTO_ACCEPT_FAILED";
40
+ LazyAgentErrorCode["AGENT_CREATION_FAILED"] = "LAZY_AGENT_AGENT_CREATION_FAILED";
41
+ })(LazyAgentErrorCode || (exports.LazyAgentErrorCode = LazyAgentErrorCode = {}));
42
+ /**
43
+ * Lazy agent wrapper.
44
+ *
45
+ * Proxies all Agent methods and initializes on first call.
46
+ * Caches the initialized agent for subsequent calls.
47
+ */
48
+ class LazyAgent {
49
+ config;
50
+ agent = null;
51
+ initPromise = null;
52
+ lastError = null;
53
+ constructor(config) {
54
+ this.config = config;
55
+ }
56
+ /**
57
+ * Get the agent's DID.
58
+ *
59
+ * Triggers initialization if not already initialized.
60
+ * Throws if initialization fails.
61
+ */
62
+ get did() {
63
+ if (!this.agent) {
64
+ throw new Error('Agent not initialized. Call send/receive first or await ensureInitialized().');
65
+ }
66
+ return this.agent.did;
67
+ }
68
+ /**
69
+ * Check if agent is ready (initialized).
70
+ */
71
+ isReady() {
72
+ return this.agent !== null;
73
+ }
74
+ /**
75
+ * Get last initialization error (if any).
76
+ */
77
+ getLastError() {
78
+ return this.lastError;
79
+ }
80
+ /**
81
+ * Ensure agent is initialized.
82
+ *
83
+ * Can be called explicitly to trigger init before first send/receive.
84
+ * Safe to call multiple times — subsequent calls return cached agent.
85
+ *
86
+ * @returns Agent instance or error
87
+ */
88
+ async ensureInitialized() {
89
+ // If already initialized, return cached agent
90
+ if (this.agent) {
91
+ return (0, shared_1.ok)(this.agent);
92
+ }
93
+ // If initialization is in progress, wait for it
94
+ if (this.initPromise) {
95
+ return this.initPromise;
96
+ }
97
+ // Start initialization
98
+ this.initPromise = this.initialize();
99
+ const result = await this.initPromise;
100
+ // Clear promise after completion (success or failure)
101
+ this.initPromise = null;
102
+ if (result.ok) {
103
+ this.agent = result.value;
104
+ this.lastError = null;
105
+ }
106
+ else {
107
+ this.lastError = {
108
+ code: LazyAgentErrorCode.INIT_FAILED,
109
+ message: `Agent initialization failed: ${result.error}`,
110
+ cause: result.error,
111
+ };
112
+ }
113
+ return result;
114
+ }
115
+ /**
116
+ * Internal initialization logic.
117
+ *
118
+ * 1. Auto-accept invite (if XBIND_INVITE_CODE set)
119
+ * 2. Create agent identity
120
+ * 3. Configure registry and transport
121
+ * 4. Return initialized agent
122
+ */
123
+ async initialize() {
124
+ // Step 1: Attempt auto-accept if invite code is available
125
+ const inviteCode = this.config.inviteCode ?? this.getEnv('XBIND_INVITE_CODE');
126
+ let registry = this.config.registry;
127
+ let transport = this.config.transport;
128
+ const endpoint = this.config.endpoint ?? this.getEnv('XBIND_ENDPOINT') ?? '';
129
+ if (inviteCode) {
130
+ // Create temporary agent to get DID and public key for invite acceptance
131
+ const tempAgentResult = await agent_js_1.Agent.create({
132
+ name: this.config.name,
133
+ registry: new trust_registry_js_1.MemoryTrustRegistry(),
134
+ transport: new transport_js_1.HttpsTransportAdapter({ baseUrl: 'http://localhost' }), // Placeholder
135
+ postQuantumSig: this.config.postQuantumSig,
136
+ xchange: this.config.xchange,
137
+ });
138
+ if (!tempAgentResult.ok) {
139
+ return (0, shared_1.err)(tempAgentResult.error);
140
+ }
141
+ const tempAgent = tempAgentResult.value;
142
+ // Export public key for invite acceptance
143
+ const seedsResult = await tempAgent.exportSeeds();
144
+ if (!seedsResult.ok) {
145
+ return (0, shared_1.err)('IDENTITY_FAILED');
146
+ }
147
+ const publicKey = (0, crypto_1.toBase64)(tempAgent.identity.rawPublicKey);
148
+ const x25519PublicKey = tempAgent.identity.rawX25519PublicKey
149
+ ? (0, crypto_1.toBase64)(tempAgent.identity.rawX25519PublicKey)
150
+ : undefined;
151
+ // Auto-accept invite
152
+ const acceptResult = await (0, auto_accept_js_1.autoAcceptInvite)({
153
+ inviteCode,
154
+ enabled: true,
155
+ registry: this.config.autoAccept?.registry,
156
+ inviteApiUrl: this.config.autoAccept?.inviteApiUrl,
157
+ }, {
158
+ name: this.config.name,
159
+ did: tempAgent.did,
160
+ endpoint,
161
+ publicKey,
162
+ x25519PublicKey,
163
+ });
164
+ if (!acceptResult.ok) {
165
+ this.lastError = {
166
+ code: LazyAgentErrorCode.AUTO_ACCEPT_FAILED,
167
+ message: acceptResult.error.message,
168
+ hint: acceptResult.error.hint,
169
+ cause: acceptResult.error,
170
+ };
171
+ // Non-fatal: continue with temp agent even if auto-accept fails
172
+ // (registry may already be configured)
173
+ }
174
+ else {
175
+ // Use auto-configured registry if not provided
176
+ if (!registry && acceptResult.value.registryAutoconfigured) {
177
+ // Registry was already configured by autoAcceptInvite
178
+ registry = this.config.autoAccept?.registry ?? new trust_registry_js_1.MemoryTrustRegistry();
179
+ }
180
+ // Use inviter's endpoint as default transport if not provided
181
+ if (!transport) {
182
+ transport = new transport_js_1.HttpsTransportAdapter({
183
+ baseUrl: acceptResult.value.from.endpoint,
184
+ });
185
+ }
186
+ }
187
+ // Return temp agent as initialized agent
188
+ this.agent = tempAgent;
189
+ return (0, shared_1.ok)(tempAgent);
190
+ }
191
+ // Step 2: No invite code — create agent normally
192
+ const defaultRegistry = registry ?? new trust_registry_js_1.MemoryTrustRegistry();
193
+ const defaultTransport = transport ?? new transport_js_1.HttpsTransportAdapter({
194
+ baseUrl: endpoint || 'http://localhost',
195
+ });
196
+ const agentResult = await agent_js_1.Agent.create({
197
+ name: this.config.name,
198
+ registry: defaultRegistry,
199
+ transport: defaultTransport,
200
+ postQuantumSig: this.config.postQuantumSig,
201
+ xchange: this.config.xchange,
202
+ });
203
+ if (!agentResult.ok) {
204
+ this.lastError = {
205
+ code: LazyAgentErrorCode.AGENT_CREATION_FAILED,
206
+ message: `Agent creation failed: ${agentResult.error}`,
207
+ cause: agentResult.error,
208
+ };
209
+ return agentResult;
210
+ }
211
+ this.agent = agentResult.value;
212
+ return (0, shared_1.ok)(this.agent);
213
+ }
214
+ /**
215
+ * Send a message (proxied to underlying agent).
216
+ *
217
+ * Automatically initializes agent on first call.
218
+ */
219
+ async send(opts) {
220
+ const agentResult = await this.ensureInitialized();
221
+ if (!agentResult.ok) {
222
+ return agentResult;
223
+ }
224
+ return agentResult.value.send(opts);
225
+ }
226
+ /**
227
+ * Receive a message (proxied to underlying agent).
228
+ *
229
+ * Automatically initializes agent on first call.
230
+ */
231
+ async receive(envelope, opts) {
232
+ const agentResult = await this.ensureInitialized();
233
+ if (!agentResult.ok) {
234
+ return (0, shared_1.err)(agentResult.error);
235
+ }
236
+ return agentResult.value.receive(envelope, opts);
237
+ }
238
+ /**
239
+ * Receive a split-channel share (proxied to underlying agent).
240
+ *
241
+ * Automatically initializes agent on first call.
242
+ */
243
+ async receiveSplitShare(envelope) {
244
+ const agentResult = await this.ensureInitialized();
245
+ if (!agentResult.ok) {
246
+ return (0, shared_1.err)(agentResult.error);
247
+ }
248
+ return agentResult.value.receiveSplitShare(envelope);
249
+ }
250
+ /**
251
+ * Get environment variable value.
252
+ *
253
+ * @param key - Environment variable name
254
+ * @returns Environment variable value or empty string
255
+ */
256
+ getEnv(key) {
257
+ // SAFETY: Check for Node.js environment before accessing process
258
+ if (typeof process !== 'undefined' && typeof process.env !== 'undefined') {
259
+ return process.env[key] ?? '';
260
+ }
261
+ return '';
262
+ }
263
+ /**
264
+ * Export the underlying agent (for advanced use cases).
265
+ *
266
+ * Throws if agent is not initialized.
267
+ */
268
+ getAgent() {
269
+ if (!this.agent) {
270
+ throw new Error('Agent not initialized. Call send/receive first or await ensureInitialized().');
271
+ }
272
+ return this.agent;
273
+ }
274
+ }
275
+ exports.LazyAgent = LazyAgent;
276
+ /**
277
+ * Create a lazy agent that initializes on first use.
278
+ *
279
+ * Extension method for Agent class. Adds `Agent.lazy()` factory.
280
+ *
281
+ * @param config - Lazy agent configuration
282
+ * @returns Lazy agent wrapper
283
+ *
284
+ * @example
285
+ * ```ts
286
+ * // Environment: XBIND_INVITE_CODE=XBD-abc123
287
+ *
288
+ * const agent = createLazyAgent({ name: 'my-service' });
289
+ *
290
+ * // No initialization yet — happens on first send:
291
+ * await agent.send({
292
+ * to: 'did:key:z6Mk...',
293
+ * payload: { action: 'test' },
294
+ * scope: 'test',
295
+ * });
296
+ * ```
297
+ */
298
+ function createLazyAgent(config) {
299
+ return new LazyAgent(config);
300
+ }
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+ /**
3
+ * @module mdns-discovery
4
+ * mDNS service discovery for local network device pairing.
5
+ *
6
+ * Service Type: _privateme._tcp.local (RFC 6763 compliant)
7
+ * Port: 58472 (dynamic range 58000-58999)
8
+ * TXT Record: did=z6Mk..., endpoint=http://192.168.1.5:58472, name=Desktop
9
+ *
10
+ * Security properties:
11
+ * - Physical proximity required (same LAN)
12
+ * - User confirmation on both devices
13
+ * - Nonce-based challenge-response
14
+ * - 60-second timeout
15
+ * - Gold Standard compliant (GS-CONNECT requirement #26)
16
+ */
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.MdnsDiscoveryManager = exports.DiscoveryErrorCode = void 0;
22
+ const bonjour_service_1 = __importDefault(require("bonjour-service"));
23
+ const shared_1 = require("../_deps/shared/index.js");
24
+ /**
25
+ * Discovery error types.
26
+ */
27
+ var DiscoveryErrorCode;
28
+ (function (DiscoveryErrorCode) {
29
+ DiscoveryErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
30
+ DiscoveryErrorCode["TIMEOUT"] = "TIMEOUT";
31
+ DiscoveryErrorCode["NO_SERVICES"] = "NO_SERVICES";
32
+ DiscoveryErrorCode["INVALID_SERVICE"] = "INVALID_SERVICE";
33
+ })(DiscoveryErrorCode || (exports.DiscoveryErrorCode = DiscoveryErrorCode = {}));
34
+ /**
35
+ * mDNS discovery manager.
36
+ *
37
+ * Advertises service on local network and scans for other devices.
38
+ * Uses bonjour-service library (RFC 6763/6762 compliant).
39
+ */
40
+ class MdnsDiscoveryManager {
41
+ bonjour;
42
+ service = null;
43
+ serviceType = 'privateme';
44
+ protocol = 'tcp';
45
+ port = 58472;
46
+ constructor() {
47
+ this.bonjour = new bonjour_service_1.default();
48
+ }
49
+ /**
50
+ * Advertise service on local network.
51
+ *
52
+ * Broadcasts mDNS announcement with device DID and HTTP endpoint.
53
+ * Other devices on the same LAN can discover this service via scan().
54
+ *
55
+ * @param name - Device name (e.g., "Desktop", "MacBook Pro")
56
+ * @param did - Device DID
57
+ * @param port - Local HTTP server port (default: 58472)
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const manager = new MdnsDiscoveryManager();
62
+ * manager.advertise('Desktop', 'did:key:z6Mk...', 58472);
63
+ * // Service now visible to other devices on LAN
64
+ * ```
65
+ */
66
+ advertise(name, did, port = this.port) {
67
+ // Stop existing advertisement
68
+ if (this.service) {
69
+ this.service.stop?.();
70
+ }
71
+ // Publish service
72
+ this.service = this.bonjour.publish({
73
+ name,
74
+ type: this.serviceType,
75
+ protocol: this.protocol,
76
+ port,
77
+ txt: {
78
+ did,
79
+ endpoint: `http://localhost:${port}`, // Will be replaced with actual IP by Bonjour
80
+ name,
81
+ },
82
+ });
83
+ }
84
+ /**
85
+ * Scan local network for services.
86
+ *
87
+ * Discovers all Private.Me devices on the same LAN.
88
+ * Filters out own DID from results (can't pair with self).
89
+ *
90
+ * @param ownDid - Own device DID (to filter out)
91
+ * @param timeoutMs - Scan timeout in milliseconds (default: 5000ms)
92
+ * @returns Array of discovered services
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * const manager = new MdnsDiscoveryManager();
97
+ * const result = await manager.scan('did:key:z6Mk...myDid', 5000);
98
+ * if (result.ok) {
99
+ * console.log(`Found ${result.value.length} devices`);
100
+ * for (const service of result.value) {
101
+ * console.log(`${service.name} - ${service.did}`);
102
+ * }
103
+ * }
104
+ * ```
105
+ */
106
+ async scan(ownDid, timeoutMs = 5000) {
107
+ return new Promise((resolve) => {
108
+ const discovered = new Map();
109
+ let resolved = false;
110
+ // Browse for services
111
+ const browser = this.bonjour.find({
112
+ type: this.serviceType,
113
+ protocol: this.protocol,
114
+ });
115
+ // Handle service discovery
116
+ browser.on('up', (service) => {
117
+ try {
118
+ // Parse TXT record
119
+ const txt = service.txt;
120
+ if (!txt || !txt.did || !txt.name) {
121
+ return; // Invalid service - missing required fields
122
+ }
123
+ // Filter out own DID
124
+ if (txt.did === ownDid) {
125
+ return;
126
+ }
127
+ // Extract endpoint
128
+ const endpoint = txt.endpoint || `http://${service.host || 'localhost'}:${service.port}`;
129
+ // Extract addresses (filter IPv4 only)
130
+ const addresses = (service.addresses || []).filter((addr) => {
131
+ // Simple IPv4 check (contains dots, not colons)
132
+ return addr.includes('.') && !addr.includes(':');
133
+ });
134
+ const info = {
135
+ name: txt.name,
136
+ did: txt.did,
137
+ endpoint,
138
+ addresses,
139
+ port: service.port || this.port,
140
+ };
141
+ discovered.set(txt.did, info);
142
+ }
143
+ catch (error) {
144
+ // Ignore invalid service
145
+ }
146
+ });
147
+ // Timeout after specified duration
148
+ const timeoutId = setTimeout(() => {
149
+ if (resolved)
150
+ return;
151
+ resolved = true;
152
+ browser.stop();
153
+ if (discovered.size === 0) {
154
+ resolve((0, shared_1.err)({
155
+ code: DiscoveryErrorCode.NO_SERVICES,
156
+ message: 'No devices found on local network',
157
+ hint: 'Ensure both devices are on the same Wi-Fi network',
158
+ }));
159
+ }
160
+ else {
161
+ resolve((0, shared_1.ok)(Array.from(discovered.values())));
162
+ }
163
+ }, timeoutMs);
164
+ // Allow cleanup if promise resolves early
165
+ browser.on('error', (error) => {
166
+ if (resolved)
167
+ return;
168
+ resolved = true;
169
+ clearTimeout(timeoutId);
170
+ browser.stop();
171
+ resolve((0, shared_1.err)({
172
+ code: DiscoveryErrorCode.NETWORK_ERROR,
173
+ message: error.message,
174
+ hint: 'Check firewall settings and network connectivity',
175
+ }));
176
+ });
177
+ });
178
+ }
179
+ /**
180
+ * Stop advertising service.
181
+ *
182
+ * Removes mDNS announcement from local network.
183
+ * Other devices will no longer see this service.
184
+ */
185
+ stopAdvertising() {
186
+ if (this.service) {
187
+ this.service.stop?.();
188
+ this.service = null;
189
+ }
190
+ }
191
+ /**
192
+ * Release resources.
193
+ *
194
+ * Stops advertising and cleans up Bonjour instance.
195
+ * Call this when shutting down the application.
196
+ */
197
+ destroy() {
198
+ this.stopAdvertising();
199
+ this.bonjour.destroy();
200
+ }
201
+ }
202
+ exports.MdnsDiscoveryManager = MdnsDiscoveryManager;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ /* ── NonceStore — Replay Prevention ── */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.MemoryNonceStore = void 0;
5
+ /** Default TTL for nonce entries: 10 minutes. */
6
+ const DEFAULT_TTL_MS = 10 * 60 * 1000;
7
+ /** Default cleanup interval: 60 seconds. */
8
+ const DEFAULT_CLEANUP_INTERVAL_MS = 60 * 1000;
9
+ /**
10
+ * In-memory nonce store for development and single-process deployments.
11
+ *
12
+ * Stores nonces in a Map keyed by "senderDid:nonce" with expiry timestamps.
13
+ * Periodic cleanup removes expired entries to prevent unbounded growth.
14
+ */
15
+ class MemoryNonceStore {
16
+ seen = new Map();
17
+ ttlMs;
18
+ cleanupIntervalMs;
19
+ timer = null;
20
+ constructor(opts) {
21
+ this.ttlMs = opts?.ttlMs ?? DEFAULT_TTL_MS;
22
+ this.cleanupIntervalMs = opts?.cleanupIntervalMs ?? DEFAULT_CLEANUP_INTERVAL_MS;
23
+ // Timer starts lazily on first check() to avoid blocking process exit in tests
24
+ }
25
+ /** Start cleanup timer on first use. */
26
+ ensureTimer() {
27
+ if (this.timer !== null)
28
+ return;
29
+ const t = setInterval(() => this.cleanup(), this.cleanupIntervalMs);
30
+ // Unref so the timer doesn't block Node.js process exit
31
+ if (typeof t === 'object' && 'unref' in t) {
32
+ t.unref(); // SAFETY: runtime check guards access
33
+ }
34
+ this.timer = t;
35
+ }
36
+ async check(nonce, senderDid) {
37
+ this.ensureTimer();
38
+ const key = `${senderDid}:${nonce}`;
39
+ const existing = this.seen.get(key);
40
+ const now = Date.now();
41
+ if (existing !== undefined && existing > now) {
42
+ return false;
43
+ }
44
+ this.seen.set(key, now + this.ttlMs);
45
+ return true;
46
+ }
47
+ cleanup() {
48
+ const now = Date.now();
49
+ for (const [key, expiry] of this.seen) {
50
+ if (expiry <= now)
51
+ this.seen.delete(key);
52
+ }
53
+ }
54
+ dispose() {
55
+ if (this.timer !== null) {
56
+ clearInterval(this.timer);
57
+ this.timer = null;
58
+ }
59
+ this.seen.clear();
60
+ }
61
+ /** Number of active (non-expired) entries. Useful for testing. */
62
+ get size() {
63
+ return this.seen.size;
64
+ }
65
+ }
66
+ exports.MemoryNonceStore = MemoryNonceStore;
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }