@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,201 @@
1
+ "use strict";
2
+ /**
3
+ * did:web resolver — resolves DIDs hosted on developer domains.
4
+ *
5
+ * Implements the W3C did:web method:
6
+ * did:web:example.com -> https://example.com/.well-known/did.json
7
+ * did:web:example.com:path:to -> https://example.com/path/to/did.json
8
+ *
9
+ * Enables direct agent-to-agent communication without a centralized registry.
10
+ * Implements TrustRegistry interface for drop-in use with Agent class.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.DidWebResolver = void 0;
14
+ exports.didWebToUrl = didWebToUrl;
15
+ const shared_1 = require("../_deps/shared/index.js");
16
+ const crypto_1 = require("../_deps/crypto/index.js");
17
+ /**
18
+ * Resolve did:web DIDs by fetching DID documents from the hosting domain.
19
+ *
20
+ * Implements TrustRegistry interface so it can be used as a drop-in
21
+ * replacement for MemoryTrustRegistry or HttpTrustRegistry.
22
+ */
23
+ class DidWebResolver {
24
+ fetchFn;
25
+ cacheTtlMs;
26
+ cache = new Map();
27
+ constructor(opts) {
28
+ this.fetchFn = opts?.fetch ?? globalThis.fetch.bind(globalThis);
29
+ this.cacheTtlMs = opts?.cacheTtlMs ?? 300_000;
30
+ }
31
+ /** Registration not supported for did:web (developers host their own). */
32
+ async register(_did, _publicKey, _name, _scopes, _x25519PublicKey) {
33
+ return (0, shared_1.err)('ALREADY_REGISTERED');
34
+ }
35
+ /**
36
+ * Resolve a did:web DID to its raw public key bytes.
37
+ * @param did - A did:web DID string.
38
+ * @returns Public key bytes or error.
39
+ */
40
+ async resolve(did) {
41
+ const entry = await this.fetchEntry(did);
42
+ if (!entry.ok)
43
+ return entry;
44
+ if (entry.value.revoked)
45
+ return (0, shared_1.err)('REVOKED');
46
+ return (0, shared_1.ok)(entry.value.publicKey);
47
+ }
48
+ /**
49
+ * Check if a did:web DID has a specific scope.
50
+ * @param did - The DID to check.
51
+ * @param scope - The scope to verify.
52
+ * @returns True if scope is granted.
53
+ */
54
+ async hasScope(did, scope) {
55
+ const entry = await this.fetchEntry(did);
56
+ if (!entry.ok)
57
+ return false;
58
+ return entry.value.scopes.has(scope);
59
+ }
60
+ /**
61
+ * Check if a did:web DID has a specific receive scope.
62
+ * @param did - The DID to check.
63
+ * @param scope - The scope to verify.
64
+ * @returns True if receive scope is granted.
65
+ */
66
+ async hasReceiveScope(did, scope) {
67
+ const entry = await this.fetchEntry(did);
68
+ if (!entry.ok)
69
+ return false;
70
+ // Undefined = accept all scopes (backward compatibility)
71
+ if (!entry.value.receiveScopes)
72
+ return true;
73
+ return entry.value.receiveScopes.has(scope);
74
+ }
75
+ /** Revocation not supported for did:web (developer controls their domain). */
76
+ async revoke(_did) {
77
+ return (0, shared_1.err)('NOT_FOUND');
78
+ }
79
+ /**
80
+ * Get the full registry entry for a did:web DID.
81
+ * @param did - The DID to look up.
82
+ * @returns Full entry or error.
83
+ */
84
+ async getEntry(did) {
85
+ return this.fetchEntry(did);
86
+ }
87
+ /** Number of cached entries (for testing). */
88
+ get cacheSize() {
89
+ return this.cache.size;
90
+ }
91
+ /** Fetch and parse a DID document, with caching. */
92
+ async fetchEntry(did) {
93
+ // Check cache
94
+ const cached = this.cache.get(did);
95
+ if (cached && Date.now() - cached.fetchedAt < this.cacheTtlMs) {
96
+ return (0, shared_1.ok)(cached.entry);
97
+ }
98
+ const url = didWebToUrl(did);
99
+ if (!url)
100
+ return (0, shared_1.err)('NOT_FOUND');
101
+ try {
102
+ const res = await this.fetchFn(url);
103
+ if (!res.ok)
104
+ return (0, shared_1.err)('NOT_FOUND');
105
+ const doc = (await res.json());
106
+ const entry = parseDidDocument(did, doc);
107
+ if (!entry)
108
+ return (0, shared_1.err)('NOT_FOUND');
109
+ this.cache.set(did, { entry, fetchedAt: Date.now() });
110
+ return (0, shared_1.ok)(entry);
111
+ }
112
+ catch {
113
+ return (0, shared_1.err)('NETWORK_ERROR');
114
+ }
115
+ }
116
+ }
117
+ exports.DidWebResolver = DidWebResolver;
118
+ /**
119
+ * Convert a did:web DID to its HTTPS URL.
120
+ * did:web:example.com -> https://example.com/.well-known/did.json
121
+ * did:web:example.com:path:to -> https://example.com/path/to/did.json
122
+ * @param did - The did:web DID string.
123
+ * @returns HTTPS URL or null if invalid.
124
+ */
125
+ function didWebToUrl(did) {
126
+ if (!did.startsWith('did:web:'))
127
+ return null;
128
+ const parts = did.slice('did:web:'.length).split(':');
129
+ if (parts.length === 0 || !parts[0])
130
+ return null;
131
+ const domain = decodeURIComponent(parts[0]);
132
+ if (parts.length === 1) {
133
+ return `https://${domain}/.well-known/did.json`;
134
+ }
135
+ const path = parts.slice(1).map(decodeURIComponent).join('/');
136
+ return `https://${domain}/${path}/did.json`;
137
+ }
138
+ /** Parse a DID document into a RegistryEntry. */
139
+ function parseDidDocument(did, doc) {
140
+ if (!doc.verificationMethod || doc.verificationMethod.length === 0) {
141
+ return null;
142
+ }
143
+ const vm = doc.verificationMethod[0];
144
+ if (!vm)
145
+ return null;
146
+ let publicKey = null;
147
+ if (vm.publicKeyMultibase) {
148
+ publicKey = decodeMultibase(vm.publicKeyMultibase);
149
+ }
150
+ else if (vm.publicKeyBase64) {
151
+ publicKey = (0, crypto_1.fromBase64)(vm.publicKeyBase64);
152
+ }
153
+ if (!publicKey)
154
+ return null;
155
+ return {
156
+ did,
157
+ publicKey,
158
+ name: doc.xailName ?? did,
159
+ scopes: new Set(doc.xailScopes ?? []),
160
+ revoked: doc.deactivated === true,
161
+ rotation_sequence: 1, // DID documents don't track rotation, default to 1
162
+ };
163
+ }
164
+ /** Decode z-prefixed base58btc multibase to bytes. */
165
+ function decodeMultibase(mb) {
166
+ if (!mb.startsWith('z'))
167
+ return null;
168
+ return base58Decode(mb.slice(1));
169
+ }
170
+ /** Base58 decode (Bitcoin alphabet). */
171
+ function base58Decode(s) {
172
+ const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
173
+ const BASE = BigInt(58);
174
+ let num = BigInt(0);
175
+ for (const char of s) {
176
+ const idx = ALPHABET.indexOf(char);
177
+ if (idx < 0)
178
+ return new Uint8Array(0);
179
+ num = num * BASE + BigInt(idx);
180
+ }
181
+ const hex = num.toString(16);
182
+ const padded = hex.length % 2 ? '0' + hex : hex;
183
+ const bytes = new Uint8Array(padded.length / 2);
184
+ for (let i = 0; i < bytes.length; i++) {
185
+ bytes[i] = parseInt(padded.slice(i * 2, i * 2 + 2), 16);
186
+ }
187
+ // Handle leading zeros (base58 "1" = 0x00)
188
+ let leadingZeros = 0;
189
+ for (const c of s) {
190
+ if (c === '1')
191
+ leadingZeros++;
192
+ else
193
+ break;
194
+ }
195
+ if (leadingZeros > 0) {
196
+ const result = new Uint8Array(leadingZeros + bytes.length);
197
+ result.set(bytes, leadingZeros);
198
+ return result;
199
+ }
200
+ return bytes;
201
+ }
@@ -0,0 +1,462 @@
1
+ "use strict";
2
+ /**
3
+ * @module discovery
4
+ * Service discovery for zero-config XBind connections.
5
+ *
6
+ * Enables: `xbind connect payments-service`
7
+ *
8
+ * Four-tier discovery:
9
+ * 1. Public registry (xbind.registry.io)
10
+ * 2. Well-known URL (https://service.com/.well-known/xbind)
11
+ * 3. DNS TXT record (_xbind.service.com)
12
+ * 4. Direct URL/QR code
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ServiceDiscovery = exports.DiscoveryErrorCode = void 0;
16
+ const shared_1 = require("../_deps/shared/index.js");
17
+ const dns_1 = require("dns");
18
+ /**
19
+ * Discovery error codes.
20
+ */
21
+ var DiscoveryErrorCode;
22
+ (function (DiscoveryErrorCode) {
23
+ DiscoveryErrorCode["SERVICE_NOT_FOUND"] = "DISCOVERY_SERVICE_NOT_FOUND";
24
+ DiscoveryErrorCode["REGISTRY_UNREACHABLE"] = "DISCOVERY_REGISTRY_UNREACHABLE";
25
+ DiscoveryErrorCode["INVALID_RESPONSE"] = "DISCOVERY_INVALID_RESPONSE";
26
+ DiscoveryErrorCode["NETWORK_ERROR"] = "DISCOVERY_NETWORK_ERROR";
27
+ DiscoveryErrorCode["INVALID_SERVICE_NAME"] = "DISCOVERY_INVALID_SERVICE_NAME";
28
+ DiscoveryErrorCode["DNS_ERROR"] = "DISCOVERY_DNS_ERROR";
29
+ DiscoveryErrorCode["INVALID_EMAIL"] = "DISCOVERY_INVALID_EMAIL";
30
+ DiscoveryErrorCode["PERSONAL_EMAIL_DOMAIN"] = "DISCOVERY_PERSONAL_EMAIL_DOMAIN";
31
+ })(DiscoveryErrorCode || (exports.DiscoveryErrorCode = DiscoveryErrorCode = {}));
32
+ /**
33
+ * Personal email domains that are blacklisted from discovery.
34
+ * Corporate services should use their own domain, not personal email.
35
+ */
36
+ const PERSONAL_EMAIL_DOMAINS = new Set([
37
+ 'gmail.com',
38
+ 'googlemail.com',
39
+ 'outlook.com',
40
+ 'hotmail.com',
41
+ 'live.com',
42
+ 'yahoo.com',
43
+ 'ymail.com',
44
+ 'icloud.com',
45
+ 'me.com',
46
+ 'protonmail.com',
47
+ 'proton.me',
48
+ 'aol.com',
49
+ 'mail.com',
50
+ 'zoho.com',
51
+ 'gmx.com',
52
+ 'tutanota.com',
53
+ 'fastmail.com',
54
+ ]);
55
+ /**
56
+ * Discovery client for finding services.
57
+ */
58
+ class ServiceDiscovery {
59
+ registryUrl;
60
+ dnsCache;
61
+ /**
62
+ * Create a discovery client.
63
+ *
64
+ * @param options - Configuration options
65
+ * @param options.registryUrl - Registry URL (default: https://xbind.registry.io)
66
+ */
67
+ constructor(options = {}) {
68
+ this.registryUrl = options.registryUrl || 'https://xbind.registry.io';
69
+ this.dnsCache = new Map();
70
+ }
71
+ /**
72
+ * Discover a service by name.
73
+ *
74
+ * Tries:
75
+ * 1. Email-based discovery (extracts domain from email)
76
+ * 2. Public registry lookup
77
+ * 3. Well-known URL if name is a domain
78
+ * 4. DNS TXT record (_xbind.domain)
79
+ * 5. Direct URL if name is a full URL
80
+ *
81
+ * @param nameOrUrl - Service name, email, domain, or URL
82
+ * @returns Service info or error
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * const discovery = new ServiceDiscovery();
87
+ *
88
+ * // By name (registry lookup):
89
+ * const result = await discovery.discover('payments-service');
90
+ *
91
+ * // By email (domain extraction):
92
+ * const result = await discovery.discover('alice@company.com');
93
+ *
94
+ * // By domain (well-known):
95
+ * const result = await discovery.discover('payments.example.com');
96
+ *
97
+ * // By URL (direct):
98
+ * const result = await discovery.discover('https://api.payments.com/xbind');
99
+ * ```
100
+ */
101
+ async discover(nameOrUrl) {
102
+ // Validate input
103
+ if (!nameOrUrl || nameOrUrl.trim().length === 0) {
104
+ return (0, shared_1.err)({
105
+ code: DiscoveryErrorCode.INVALID_SERVICE_NAME,
106
+ message: 'Service name cannot be empty',
107
+ hint: 'Provide a service name, domain, email, or URL',
108
+ });
109
+ }
110
+ nameOrUrl = nameOrUrl.trim();
111
+ // If full URL, try direct
112
+ if (nameOrUrl.startsWith('http://') || nameOrUrl.startsWith('https://')) {
113
+ return this.discoverDirect(nameOrUrl);
114
+ }
115
+ // If email address, extract domain and discover
116
+ if (nameOrUrl.includes('@') && !nameOrUrl.includes('/')) {
117
+ return this.discoverEmail(nameOrUrl);
118
+ }
119
+ // If looks like domain, try well-known first, then DNS TXT
120
+ if (nameOrUrl.includes('.') && !nameOrUrl.includes('/')) {
121
+ const wellKnownResult = await this.discoverWellKnown(nameOrUrl);
122
+ if (wellKnownResult.ok) {
123
+ return wellKnownResult;
124
+ }
125
+ // Try DNS TXT as fallback
126
+ const dnsTxtResult = await this.discoverDnsTxt(nameOrUrl);
127
+ if (dnsTxtResult.ok) {
128
+ return dnsTxtResult;
129
+ }
130
+ // Fall through to registry if both fail
131
+ }
132
+ // Try registry lookup
133
+ return this.discoverRegistry(nameOrUrl);
134
+ }
135
+ /**
136
+ * Look up service in public registry.
137
+ *
138
+ * GET https://xbind.registry.io/lookup/:name
139
+ */
140
+ async discoverRegistry(name) {
141
+ try {
142
+ const url = `${this.registryUrl}/lookup/${encodeURIComponent(name)}`;
143
+ const response = await fetch(url, {
144
+ headers: {
145
+ 'Accept': 'application/json',
146
+ },
147
+ });
148
+ if (response.status === 404) {
149
+ return (0, shared_1.err)({
150
+ code: DiscoveryErrorCode.SERVICE_NOT_FOUND,
151
+ message: `Service "${name}" not found in registry`,
152
+ hint: 'Check service name or register at xbind.registry.io',
153
+ });
154
+ }
155
+ if (!response.ok) {
156
+ return (0, shared_1.err)({
157
+ code: DiscoveryErrorCode.REGISTRY_UNREACHABLE,
158
+ message: `Registry returned ${response.status}`,
159
+ hint: 'Try again later or use direct URL',
160
+ });
161
+ }
162
+ const data = await response.json();
163
+ return (0, shared_1.ok)(data);
164
+ }
165
+ catch (error) {
166
+ return (0, shared_1.err)({
167
+ code: DiscoveryErrorCode.NETWORK_ERROR,
168
+ message: error instanceof Error ? error.message : 'Network error',
169
+ hint: 'Check internet connection',
170
+ });
171
+ }
172
+ }
173
+ /**
174
+ * Discover via .well-known/xbind.
175
+ *
176
+ * GET https://domain/.well-known/xbind
177
+ */
178
+ async discoverWellKnown(domain) {
179
+ try {
180
+ const url = `https://${domain}/.well-known/xbind`;
181
+ const response = await fetch(url, {
182
+ headers: {
183
+ 'Accept': 'application/json',
184
+ },
185
+ });
186
+ if (!response.ok) {
187
+ return (0, shared_1.err)({
188
+ code: DiscoveryErrorCode.SERVICE_NOT_FOUND,
189
+ message: `No .well-known/xbind found at ${domain}`,
190
+ });
191
+ }
192
+ const data = await response.json();
193
+ return (0, shared_1.ok)(data);
194
+ }
195
+ catch (error) {
196
+ return (0, shared_1.err)({
197
+ code: DiscoveryErrorCode.NETWORK_ERROR,
198
+ message: error instanceof Error ? error.message : 'Network error',
199
+ });
200
+ }
201
+ }
202
+ /**
203
+ * Discover via direct URL.
204
+ */
205
+ async discoverDirect(url) {
206
+ try {
207
+ const response = await fetch(url, {
208
+ headers: {
209
+ 'Accept': 'application/json',
210
+ },
211
+ });
212
+ if (!response.ok) {
213
+ return (0, shared_1.err)({
214
+ code: DiscoveryErrorCode.SERVICE_NOT_FOUND,
215
+ message: `Service not found at ${url}`,
216
+ });
217
+ }
218
+ const data = await response.json();
219
+ return (0, shared_1.ok)(data);
220
+ }
221
+ catch (error) {
222
+ return (0, shared_1.err)({
223
+ code: DiscoveryErrorCode.NETWORK_ERROR,
224
+ message: error instanceof Error ? error.message : 'Network error',
225
+ });
226
+ }
227
+ }
228
+ /**
229
+ * Discover via DNS TXT record.
230
+ *
231
+ * Looks up TXT record at _xbind.domain
232
+ *
233
+ * Supports two formats:
234
+ * 1. Full record: "xbind-endpoint=https://...;did=did:web:...;publicKey=..." (all fields in DNS)
235
+ * 2. Simple redirect: "xbind=https://api.example.com/xbind" (fetch from endpoint)
236
+ *
237
+ * Includes 5-minute caching to reduce DNS queries.
238
+ */
239
+ async discoverDnsTxt(domain) {
240
+ // Check cache first (5 minute TTL)
241
+ const cached = this.dnsCache.get(domain);
242
+ if (cached && cached.expiry > Date.now()) {
243
+ return (0, shared_1.ok)(cached.info);
244
+ }
245
+ try {
246
+ const txtRecords = await dns_1.promises.resolveTxt(`_xbind.${domain}`);
247
+ // Find xbind record
248
+ for (const record of txtRecords) {
249
+ const txt = record.join('');
250
+ // Format 1: Full record with all fields
251
+ if (txt.includes('xbind-endpoint=')) {
252
+ const parsed = this.parseDnsTxtRecord(txt, domain);
253
+ if (parsed.ok) {
254
+ // Cache for 5 minutes
255
+ this.dnsCache.set(domain, {
256
+ info: parsed.value,
257
+ expiry: Date.now() + 5 * 60 * 1000,
258
+ });
259
+ return parsed;
260
+ }
261
+ }
262
+ // Format 2: Simple redirect to endpoint
263
+ if (txt.startsWith('xbind=')) {
264
+ const endpoint = txt.substring(6);
265
+ // Fetch service info from endpoint
266
+ const result = await this.discoverDirect(endpoint);
267
+ if (result.ok) {
268
+ // Cache for 5 minutes
269
+ this.dnsCache.set(domain, {
270
+ info: result.value,
271
+ expiry: Date.now() + 5 * 60 * 1000,
272
+ });
273
+ }
274
+ return result;
275
+ }
276
+ }
277
+ return (0, shared_1.err)({
278
+ code: DiscoveryErrorCode.SERVICE_NOT_FOUND,
279
+ message: `No _xbind TXT record found for ${domain}`,
280
+ hint: 'Add DNS TXT record: _xbind.example.com IN TXT "xbind-endpoint=https://...;did=did:web:...;publicKey=..."',
281
+ });
282
+ }
283
+ catch (error) {
284
+ // Handle DNS-specific errors
285
+ if (error && typeof error === 'object' && 'code' in error) {
286
+ const dnsError = error;
287
+ if (dnsError.code === 'ENOTFOUND' || dnsError.code === 'ENODATA') {
288
+ return (0, shared_1.err)({
289
+ code: DiscoveryErrorCode.SERVICE_NOT_FOUND,
290
+ message: `No DNS TXT record found for _xbind.${domain}`,
291
+ });
292
+ }
293
+ if (dnsError.code === 'ETIMEOUT') {
294
+ return (0, shared_1.err)({
295
+ code: DiscoveryErrorCode.DNS_ERROR,
296
+ message: 'DNS query timeout',
297
+ hint: 'Check network connection or try again',
298
+ });
299
+ }
300
+ }
301
+ return (0, shared_1.err)({
302
+ code: DiscoveryErrorCode.DNS_ERROR,
303
+ message: error instanceof Error ? error.message : 'DNS lookup failed',
304
+ hint: 'Check domain name and DNS configuration',
305
+ });
306
+ }
307
+ }
308
+ /**
309
+ * Parse DNS TXT record into ServiceInfo.
310
+ *
311
+ * Expected format:
312
+ * xbind-endpoint=https://...;did=did:web:...;publicKey=...;version=1.0
313
+ *
314
+ * Optional fields:
315
+ * x25519PublicKey=...;mlKemPublicKey=...;description=...;logo=...;docs=...
316
+ */
317
+ parseDnsTxtRecord(txtRecord, domain) {
318
+ try {
319
+ const fields = new Map();
320
+ // Split by semicolon and parse key=value pairs
321
+ const parts = txtRecord.split(';').map(p => p.trim()).filter(p => p.length > 0);
322
+ for (const part of parts) {
323
+ const eqIndex = part.indexOf('=');
324
+ if (eqIndex === -1)
325
+ continue;
326
+ const key = part.substring(0, eqIndex).trim();
327
+ const value = part.substring(eqIndex + 1).trim();
328
+ fields.set(key, value);
329
+ }
330
+ // Validate required fields
331
+ const endpoint = fields.get('xbind-endpoint');
332
+ const did = fields.get('did');
333
+ const publicKey = fields.get('publicKey');
334
+ if (!endpoint || !did || !publicKey) {
335
+ return (0, shared_1.err)({
336
+ code: DiscoveryErrorCode.INVALID_RESPONSE,
337
+ message: 'DNS TXT record missing required fields',
338
+ hint: 'Required: xbind-endpoint, did, publicKey',
339
+ });
340
+ }
341
+ // Build ServiceInfo
342
+ const info = {
343
+ name: domain,
344
+ endpoint,
345
+ did,
346
+ publicKey,
347
+ };
348
+ // Add optional fields
349
+ if (fields.has('x25519PublicKey')) {
350
+ info.x25519PublicKey = fields.get('x25519PublicKey');
351
+ }
352
+ if (fields.has('mlKemPublicKey')) {
353
+ info.mlKemPublicKey = fields.get('mlKemPublicKey');
354
+ }
355
+ if (fields.has('description')) {
356
+ info.description = fields.get('description');
357
+ }
358
+ if (fields.has('logo')) {
359
+ info.logo = fields.get('logo');
360
+ }
361
+ if (fields.has('docs')) {
362
+ info.docs = fields.get('docs');
363
+ }
364
+ return (0, shared_1.ok)(info);
365
+ }
366
+ catch (error) {
367
+ return (0, shared_1.err)({
368
+ code: DiscoveryErrorCode.INVALID_RESPONSE,
369
+ message: error instanceof Error ? error.message : 'Failed to parse DNS TXT record',
370
+ });
371
+ }
372
+ }
373
+ /**
374
+ * Discover service via email address.
375
+ *
376
+ * Extracts domain from email and performs discovery.
377
+ * Personal email domains (gmail.com, outlook.com, etc.) are rejected.
378
+ *
379
+ * @param email - Email address (e.g., "alice@company.com")
380
+ * @returns Service info or error
381
+ *
382
+ * @example
383
+ * ```ts
384
+ * const discovery = new ServiceDiscovery();
385
+ * const result = await discovery.discoverEmail('alice@company.com');
386
+ * // Discovers service at company.com
387
+ * ```
388
+ */
389
+ async discoverEmail(email) {
390
+ // Validate email format
391
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
392
+ if (!emailRegex.test(email)) {
393
+ return (0, shared_1.err)({
394
+ code: DiscoveryErrorCode.INVALID_EMAIL,
395
+ message: `Invalid email format: ${email}`,
396
+ hint: 'Provide a valid email address (e.g., alice@company.com)',
397
+ });
398
+ }
399
+ // Extract domain (everything after @)
400
+ const domain = this.extractDomain(email);
401
+ if (!domain) {
402
+ return (0, shared_1.err)({
403
+ code: DiscoveryErrorCode.INVALID_EMAIL,
404
+ message: `Could not extract domain from email: ${email}`,
405
+ hint: 'Check email format',
406
+ });
407
+ }
408
+ // Check for personal email domains
409
+ if (PERSONAL_EMAIL_DOMAINS.has(domain.toLowerCase())) {
410
+ return (0, shared_1.err)({
411
+ code: DiscoveryErrorCode.PERSONAL_EMAIL_DOMAIN,
412
+ message: `Personal email domains not supported for discovery: ${domain}`,
413
+ hint: 'Use a corporate email address or provide the company domain directly',
414
+ });
415
+ }
416
+ // Discover using the extracted domain
417
+ // Try well-known first, then DNS TXT, then registry
418
+ const wellKnownResult = await this.discoverWellKnown(domain);
419
+ if (wellKnownResult.ok) {
420
+ return wellKnownResult;
421
+ }
422
+ const dnsTxtResult = await this.discoverDnsTxt(domain);
423
+ if (dnsTxtResult.ok) {
424
+ return dnsTxtResult;
425
+ }
426
+ // Try registry with domain
427
+ return this.discoverRegistry(domain);
428
+ }
429
+ /**
430
+ * Extract domain from email address.
431
+ * Handles edge cases: subdomains, plus addressing, etc.
432
+ *
433
+ * @param email - Email address
434
+ * @returns Domain or null if extraction fails
435
+ *
436
+ * @example
437
+ * ```ts
438
+ * extractDomain('alice@company.com') // 'company.com'
439
+ * extractDomain('alice+label@company.com') // 'company.com'
440
+ * extractDomain('alice@mail.company.com') // 'mail.company.com'
441
+ * ```
442
+ */
443
+ extractDomain(email) {
444
+ const parts = email.split('@');
445
+ if (parts.length !== 2 || !parts[1]) {
446
+ return null;
447
+ }
448
+ // Domain is everything after @
449
+ const domain = parts[1].trim().toLowerCase();
450
+ // Validate domain has at least one dot and valid characters
451
+ if (!domain.includes('.') || domain.length < 3) {
452
+ return null;
453
+ }
454
+ // Basic domain validation (alphanumeric, dots, hyphens)
455
+ const domainRegex = /^[a-z0-9][a-z0-9-]*(\.[a-z0-9][a-z0-9-]*)+$/;
456
+ if (!domainRegex.test(domain)) {
457
+ return null;
458
+ }
459
+ return domain;
460
+ }
461
+ }
462
+ exports.ServiceDiscovery = ServiceDiscovery;