@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,312 @@
1
+ "use strict";
2
+ /**
3
+ * @module connect
4
+ * High-level connect() API for zero-config XBind connections.
5
+ *
6
+ * Enables: `const service = await connect('payments-service')`
7
+ *
8
+ * Combines:
9
+ * - Service discovery
10
+ * - Trust verification
11
+ * - Agent creation
12
+ * - Connection establishment
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { connect } from '@private.me/xbind';
17
+ *
18
+ * // Connect by name (uses registry):
19
+ * const payments = await connect('payments-service');
20
+ *
21
+ * // Connect by domain (uses .well-known):
22
+ * const payments = await connect('payments.example.com');
23
+ *
24
+ * // Connect by URL (direct):
25
+ * const payments = await connect('https://api.payments.com/xbind');
26
+ *
27
+ * // Use the connection:
28
+ * await payments.send({
29
+ * to: payments.did,
30
+ * payload: { action: 'createCharge', amount: 100 },
31
+ * scope: 'payments',
32
+ * });
33
+ * ```
34
+ */
35
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
36
+ if (k2 === undefined) k2 = k;
37
+ var desc = Object.getOwnPropertyDescriptor(m, k);
38
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
39
+ desc = { enumerable: true, get: function() { return m[k]; } };
40
+ }
41
+ Object.defineProperty(o, k2, desc);
42
+ }) : (function(o, m, k, k2) {
43
+ if (k2 === undefined) k2 = k;
44
+ o[k2] = m[k];
45
+ }));
46
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
47
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
48
+ }) : function(o, v) {
49
+ o["default"] = v;
50
+ });
51
+ var __importStar = (this && this.__importStar) || (function () {
52
+ var ownKeys = function(o) {
53
+ ownKeys = Object.getOwnPropertyNames || function (o) {
54
+ var ar = [];
55
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
56
+ return ar;
57
+ };
58
+ return ownKeys(o);
59
+ };
60
+ return function (mod) {
61
+ if (mod && mod.__esModule) return mod;
62
+ var result = {};
63
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
64
+ __setModuleDefault(result, mod);
65
+ return result;
66
+ };
67
+ })();
68
+ Object.defineProperty(exports, "__esModule", { value: true });
69
+ exports.ConnectErrorCode = void 0;
70
+ exports.connect = connect;
71
+ exports.acceptInvite = acceptInvite;
72
+ const shared_1 = require("../_deps/shared/index.js");
73
+ const crypto_1 = require("../_deps/crypto/index.js");
74
+ const agent_js_1 = require("./agent.js");
75
+ const discovery_js_1 = require("./discovery.js");
76
+ const transport_js_1 = require("./transport.js");
77
+ const trust_registry_js_1 = require("./trust-registry.js");
78
+ const identity_js_1 = require("./identity.js");
79
+ /**
80
+ * Connect error codes.
81
+ */
82
+ var ConnectErrorCode;
83
+ (function (ConnectErrorCode) {
84
+ ConnectErrorCode["DISCOVERY_FAILED"] = "CONNECT_DISCOVERY_FAILED";
85
+ ConnectErrorCode["AGENT_CREATION_FAILED"] = "CONNECT_AGENT_CREATION_FAILED";
86
+ ConnectErrorCode["TRUST_VERIFICATION_FAILED"] = "CONNECT_TRUST_VERIFICATION_FAILED";
87
+ ConnectErrorCode["INVALID_SERVICE_INFO"] = "CONNECT_INVALID_SERVICE_INFO";
88
+ })(ConnectErrorCode || (exports.ConnectErrorCode = ConnectErrorCode = {}));
89
+ /**
90
+ * Connect to a service with zero configuration.
91
+ *
92
+ * @param nameOrUrl - Service name, domain, or URL
93
+ * @param options - Connection options
94
+ * @returns Connection or error
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * // Minimal:
99
+ * const connection = await connect('payments-service');
100
+ * if (connection.ok) {
101
+ * await connection.value.agent.send({
102
+ * to: connection.value.did,
103
+ * payload: { action: 'test' },
104
+ * scope: 'test',
105
+ * });
106
+ * }
107
+ *
108
+ * // With options:
109
+ * const connection = await connect('payments-service', {
110
+ * name: 'billing-service',
111
+ * xchange: true, // Use faster Xchange mode
112
+ * splitChannel: true, // Use split-channel by default
113
+ * });
114
+ * ```
115
+ */
116
+ async function connect(nameOrUrl, options = {}) {
117
+ // Step 1: Discover service
118
+ const discovery = options.discovery || new discovery_js_1.ServiceDiscovery();
119
+ const serviceResult = await discovery.discover(nameOrUrl);
120
+ if (!serviceResult.ok) {
121
+ return (0, shared_1.err)({
122
+ code: ConnectErrorCode.DISCOVERY_FAILED,
123
+ message: `Failed to discover service: ${serviceResult.error.message}`,
124
+ hint: serviceResult.error.hint,
125
+ cause: serviceResult.error,
126
+ });
127
+ }
128
+ const service = serviceResult.value;
129
+ // Step 2: Validate service info
130
+ if (!service.did || !service.endpoint || !service.publicKey) {
131
+ return (0, shared_1.err)({
132
+ code: ConnectErrorCode.INVALID_SERVICE_INFO,
133
+ message: 'Service info missing required fields (did, endpoint, publicKey)',
134
+ hint: 'Service must provide complete metadata',
135
+ });
136
+ }
137
+ // Step 3: Create trust registry and add service
138
+ const registry = options.registry || new trust_registry_js_1.MemoryTrustRegistry();
139
+ try {
140
+ // Import public key (convert from base64 string)
141
+ const publicKeyBytes = (0, crypto_1.fromBase64)(service.publicKey);
142
+ const publicKeyResult = await (0, identity_js_1.importPublicKey)(publicKeyBytes);
143
+ if (!publicKeyResult.ok) {
144
+ return (0, shared_1.err)({
145
+ code: ConnectErrorCode.TRUST_VERIFICATION_FAILED,
146
+ message: 'Invalid service public key',
147
+ cause: publicKeyResult.error,
148
+ });
149
+ }
150
+ // Add to trust registry
151
+ await registry.add({
152
+ did: service.did,
153
+ publicKey: publicKeyResult.value,
154
+ x25519PublicKey: service.x25519PublicKey
155
+ ? await (0, identity_js_1.importPublicKey)((0, crypto_1.fromBase64)(service.x25519PublicKey)).then(r => r.ok ? r.value : undefined)
156
+ : undefined,
157
+ mlKemPublicKey: service.mlKemPublicKey
158
+ ? (0, crypto_1.fromBase64)(service.mlKemPublicKey)
159
+ : undefined,
160
+ });
161
+ }
162
+ catch (error) {
163
+ return (0, shared_1.err)({
164
+ code: ConnectErrorCode.TRUST_VERIFICATION_FAILED,
165
+ message: 'Failed to verify service public key',
166
+ cause: error,
167
+ });
168
+ }
169
+ // Step 4: Create transport
170
+ const transport = options.transport || new transport_js_1.HttpsTransportAdapter({
171
+ baseUrl: service.endpoint,
172
+ });
173
+ // Step 5: Create agent
174
+ const agentName = options.name || `client-${Date.now()}`;
175
+ const agentOptions = {
176
+ name: agentName,
177
+ registry,
178
+ transport,
179
+ xchange: options.xchange,
180
+ postQuantumSig: options.postQuantumSig,
181
+ };
182
+ const agentResult = await agent_js_1.Agent.create(agentOptions);
183
+ if (!agentResult.ok) {
184
+ return (0, shared_1.err)({
185
+ code: ConnectErrorCode.AGENT_CREATION_FAILED,
186
+ message: 'Failed to create agent',
187
+ cause: agentResult.error,
188
+ });
189
+ }
190
+ // Step 6: Return connection
191
+ return (0, shared_1.ok)({
192
+ agent: agentResult.value,
193
+ service,
194
+ did: service.did,
195
+ endpoint: service.endpoint,
196
+ });
197
+ }
198
+ /**
199
+ * Accept an invite and establish connection.
200
+ *
201
+ * @param inviteUrl - Invite URL
202
+ * @param options - Connection options
203
+ * @returns Connection or error
204
+ *
205
+ * @example
206
+ * ```ts
207
+ * const connection = await acceptInvite('https://xbind.to/invite/abc123', {
208
+ * name: 'my-service',
209
+ * });
210
+ *
211
+ * if (connection.ok) {
212
+ * console.log('Connected to:', connection.value.service.name);
213
+ * }
214
+ * ```
215
+ */
216
+ async function acceptInvite(inviteUrl, options = {}) {
217
+ const { InviteService } = await Promise.resolve().then(() => __importStar(require('./invite.js')));
218
+ const inviteService = new InviteService();
219
+ // Get invite details
220
+ const inviteResult = await inviteService.get(inviteUrl);
221
+ if (!inviteResult.ok) {
222
+ return (0, shared_1.err)({
223
+ code: ConnectErrorCode.DISCOVERY_FAILED,
224
+ message: `Failed to get invite: ${inviteResult.error.message}`,
225
+ cause: inviteResult.error,
226
+ });
227
+ }
228
+ const invite = inviteResult.value;
229
+ // Convert invite.from to ServiceInfo
230
+ const service = {
231
+ name: invite.from.name,
232
+ did: invite.from.did,
233
+ endpoint: invite.from.endpoint,
234
+ publicKey: invite.from.publicKey,
235
+ x25519PublicKey: invite.from.x25519PublicKey,
236
+ mlKemPublicKey: invite.from.mlKemPublicKey,
237
+ };
238
+ // Connect to service (same as connect())
239
+ // Create trust registry and add service
240
+ const registry = options.registry || new trust_registry_js_1.MemoryTrustRegistry();
241
+ try {
242
+ // Import public key (convert from base64 string)
243
+ const publicKeyBytes = (0, crypto_1.fromBase64)(service.publicKey);
244
+ const publicKeyResult = await (0, identity_js_1.importPublicKey)(publicKeyBytes);
245
+ if (!publicKeyResult.ok) {
246
+ return (0, shared_1.err)({
247
+ code: ConnectErrorCode.TRUST_VERIFICATION_FAILED,
248
+ message: 'Invalid service public key',
249
+ cause: publicKeyResult.error,
250
+ });
251
+ }
252
+ await registry.add({
253
+ did: service.did,
254
+ publicKey: publicKeyResult.value,
255
+ x25519PublicKey: service.x25519PublicKey
256
+ ? await (0, identity_js_1.importPublicKey)((0, crypto_1.fromBase64)(service.x25519PublicKey)).then(r => r.ok ? r.value : undefined)
257
+ : undefined,
258
+ mlKemPublicKey: service.mlKemPublicKey
259
+ ? (0, crypto_1.fromBase64)(service.mlKemPublicKey)
260
+ : undefined,
261
+ });
262
+ }
263
+ catch (error) {
264
+ return (0, shared_1.err)({
265
+ code: ConnectErrorCode.TRUST_VERIFICATION_FAILED,
266
+ message: 'Failed to verify service public key',
267
+ cause: error,
268
+ });
269
+ }
270
+ const transport = options.transport || new transport_js_1.HttpsTransportAdapter({
271
+ baseUrl: service.endpoint,
272
+ });
273
+ const agentName = options.name || `client-${Date.now()}`;
274
+ const agentOptions = {
275
+ name: agentName,
276
+ registry,
277
+ transport,
278
+ xchange: options.xchange,
279
+ postQuantumSig: options.postQuantumSig,
280
+ };
281
+ const agentResult = await agent_js_1.Agent.create(agentOptions);
282
+ if (!agentResult.ok) {
283
+ return (0, shared_1.err)({
284
+ code: ConnectErrorCode.AGENT_CREATION_FAILED,
285
+ message: 'Failed to create agent',
286
+ cause: agentResult.error,
287
+ });
288
+ }
289
+ // Accept the invite
290
+ const acceptResult = await inviteService.accept({
291
+ inviteUrl,
292
+ acceptor: {
293
+ name: agentOptions.name,
294
+ did: agentResult.value.did,
295
+ endpoint: options.endpoint || '', // Agent's endpoint (where it can be reached), empty for client-only agents
296
+ publicKey: (0, crypto_1.toBase64)(agentResult.value.identity.rawPublicKey),
297
+ x25519PublicKey: agentResult.value.identity.rawX25519PublicKey
298
+ ? (0, crypto_1.toBase64)(agentResult.value.identity.rawX25519PublicKey)
299
+ : undefined,
300
+ },
301
+ });
302
+ if (!acceptResult.ok) {
303
+ // Connection created but invite acceptance failed - still return connection
304
+ // (invite acceptance is for tracking/notification, not required for connectivity)
305
+ }
306
+ return (0, shared_1.ok)({
307
+ agent: agentResult.value,
308
+ service,
309
+ did: service.did,
310
+ endpoint: service.endpoint,
311
+ });
312
+ }
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateDidDocument = generateDidDocument;
4
+ exports.resolveDid = resolveDid;
5
+ exports.getServiceEndpoints = getServiceEndpoints;
6
+ const shared_1 = require("../_deps/shared/index.js");
7
+ const crypto_1 = require("../_deps/crypto/index.js");
8
+ /**
9
+ * Generate a DID document for a given DID.
10
+ *
11
+ * Includes service endpoints that advertise PRIVATE.ME/xBind.
12
+ * Both did:key and did:privateme DIDs generate the same service endpoints.
13
+ *
14
+ * @param did - The DID (did:key:z... or did:privateme:z...)
15
+ * @param rawPublicKey - The 32-byte Ed25519 public key
16
+ * @param name - Optional name for the identity
17
+ * @returns DID document with service endpoints
18
+ */
19
+ function generateDidDocument(did, rawPublicKey, name) {
20
+ if (!did.startsWith('did:key:') && !did.startsWith('did:privateme:')) {
21
+ return (0, shared_1.err)('INVALID_DID_FORMAT');
22
+ }
23
+ // Convert public key to base64 for inclusion in document
24
+ const publicKeyBase64 = (0, crypto_1.toBase64)(rawPublicKey);
25
+ const document = {
26
+ '@context': [
27
+ 'https://www.w3.org/ns/did/v1',
28
+ 'https://w3id.org/security/suites/ed25519-2020/v1',
29
+ ],
30
+ id: did,
31
+ publicKey: [
32
+ {
33
+ id: `${did}#key-1`,
34
+ type: 'Ed25519VerificationKey2020',
35
+ controller: did,
36
+ publicKeyBase64,
37
+ },
38
+ ],
39
+ authentication: [`${did}#key-1`],
40
+ assertionMethod: [`${did}#key-1`],
41
+ keyAgreement: [`${did}#key-1`],
42
+ service: [
43
+ {
44
+ id: `${did}#identity-provider`,
45
+ type: 'IdentityProvider',
46
+ serviceEndpoint: 'https://private.me',
47
+ description: 'PRIVATE.ME xBind Agent - M2M identity authentication',
48
+ },
49
+ {
50
+ id: `${did}#documentation`,
51
+ type: 'Documentation',
52
+ serviceEndpoint: 'https://private.me/docs/xbind.html',
53
+ description: 'Learn more about PRIVATE.ME/xBind protocol',
54
+ },
55
+ ],
56
+ ...(name ? { name } : {}),
57
+ };
58
+ return (0, shared_1.ok)(document);
59
+ }
60
+ /**
61
+ * Resolve a DID to its document (simulated).
62
+ *
63
+ * In a production system, this would query a DID resolver.
64
+ * For now, this generates a synthetic document based on the DID.
65
+ *
66
+ * @param did - The DID to resolve
67
+ * @param rawPublicKey - The 32-byte Ed25519 public key
68
+ * @returns DID document or error
69
+ */
70
+ async function resolveDid(did, rawPublicKey) {
71
+ // In a production system, this would make an HTTP request to a DID resolver
72
+ // For now, generate a synthetic document
73
+ return generateDidDocument(did, rawPublicKey);
74
+ }
75
+ /**
76
+ * Extract service endpoints from a DID document.
77
+ *
78
+ * Filters for PRIVATE.ME service endpoints to provide discovery information.
79
+ *
80
+ * @param document - The DID document
81
+ * @returns Array of service endpoints advertising PRIVATE.ME services
82
+ */
83
+ function getServiceEndpoints(document) {
84
+ if (!document.service)
85
+ return [];
86
+ return document.service
87
+ .filter((svc) => {
88
+ const endpoint = typeof svc.serviceEndpoint === 'string' ? svc.serviceEndpoint : '';
89
+ return (endpoint.includes('private.me') ||
90
+ svc.type.includes('PRIVATE.ME') ||
91
+ svc.type === 'IdentityProvider' ||
92
+ svc.type === 'Documentation');
93
+ })
94
+ .map((svc) => ({
95
+ type: svc.type,
96
+ endpoint: typeof svc.serviceEndpoint === 'string'
97
+ ? svc.serviceEndpoint
98
+ : JSON.stringify(svc.serviceEndpoint),
99
+ description: svc.description,
100
+ }));
101
+ }
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.publicKeyToPrivateMeDid = publicKeyToPrivateMeDid;
4
+ exports.privateMeDidToPublicKeyBytes = privateMeDidToPublicKeyBytes;
5
+ exports.isPrivateMeDid = isPrivateMeDid;
6
+ exports.isDidKeyFormat = isDidKeyFormat;
7
+ exports.convertDidFormat = convertDidFormat;
8
+ exports.normalizeDid = normalizeDid;
9
+ exports.parseDid = parseDid;
10
+ const shared_1 = require("../_deps/shared/index.js");
11
+ const identity_js_1 = require("./identity.js");
12
+ /**
13
+ * Mechanism 4: Convert Ed25519 public key to did:privateme DID.
14
+ *
15
+ * Format: did:privateme:z + base58btc(0xed01 || publicKey)
16
+ *
17
+ * This is a new DID method identifier for PRIVATE.ME ACIs.
18
+ * It uses the same base58btc encoding as did:key for compatibility,
19
+ * but signals that the identity is backed by PRIVATE.ME infrastructure.
20
+ *
21
+ * Backward compatible: agents accept both did:key and did:privateme formats.
22
+ *
23
+ * @param rawPublicKey - 32-byte Ed25519 public key
24
+ * @returns DID in format did:privateme:z...
25
+ */
26
+ function publicKeyToPrivateMeDid(rawPublicKey) {
27
+ // Use same encoding as did:key, but with privateme method
28
+ const didKeyFormat = (0, identity_js_1.publicKeyToDid)(rawPublicKey);
29
+ // Replace did:key: with did:privateme:
30
+ return didKeyFormat.replace(/^did:key:/, 'did:privateme:');
31
+ }
32
+ /**
33
+ * Extract raw 32-byte public key from a did:privateme DID.
34
+ *
35
+ * Format: did:privateme:z + base58btc(0xed01 || publicKey)
36
+ *
37
+ * @param did - DID in format did:privateme:z...
38
+ * @returns 32-byte public key or error
39
+ */
40
+ function privateMeDidToPublicKeyBytes(did) {
41
+ if (!did.startsWith('did:privateme:z')) {
42
+ return (0, shared_1.err)('INVALID_DID_FORMAT');
43
+ }
44
+ // Convert to did:key format temporarily for parsing
45
+ const didKeyFormat = did.replace(/^did:privateme:/, 'did:key:');
46
+ // Use the existing parser
47
+ const result = (0, identity_js_1.didToPublicKeyBytes)(didKeyFormat);
48
+ if (!result.ok) {
49
+ return (0, shared_1.err)(result.error);
50
+ }
51
+ return (0, shared_1.ok)(result.value);
52
+ }
53
+ /**
54
+ * Determine if a DID is in the new did:privateme format.
55
+ *
56
+ * @param did - The DID to check
57
+ * @returns true if DID is did:privateme format, false otherwise
58
+ */
59
+ function isPrivateMeDid(did) {
60
+ return did.startsWith('did:privateme:');
61
+ }
62
+ /**
63
+ * Determine if a DID is in the did:key format.
64
+ *
65
+ * @param did - The DID to check
66
+ * @returns true if DID is did:key format, false otherwise
67
+ */
68
+ function isDidKeyFormat(did) {
69
+ return did.startsWith('did:key:');
70
+ }
71
+ /**
72
+ * Convert between DID formats (did:key ↔ did:privateme).
73
+ *
74
+ * Allows backward compatibility between old did:key and new did:privateme formats.
75
+ * The public key remains the same; only the method identifier changes.
76
+ *
77
+ * @param did - Source DID in either format
78
+ * @returns Converted DID in the other format, or error
79
+ */
80
+ function convertDidFormat(did) {
81
+ if (isDidKeyFormat(did)) {
82
+ // Convert did:key to did:privateme
83
+ return (0, shared_1.ok)(did.replace(/^did:key:/, 'did:privateme:'));
84
+ }
85
+ if (isPrivateMeDid(did)) {
86
+ // Convert did:privateme to did:key
87
+ return (0, shared_1.ok)(did.replace(/^did:privateme:/, 'did:key:'));
88
+ }
89
+ return (0, shared_1.err)('UNSUPPORTED_DID_FORMAT');
90
+ }
91
+ /**
92
+ * Normalize a DID to the canonical format (did:privateme).
93
+ *
94
+ * All DIDs are converted to did:privateme format for consistency.
95
+ * Existing did:key DIDs are automatically upgraded.
96
+ *
97
+ * @param did - Source DID in any supported format
98
+ * @returns Normalized DID in did:privateme format
99
+ */
100
+ function normalizeDid(did) {
101
+ if (isPrivateMeDid(did)) {
102
+ // Already in target format
103
+ return (0, shared_1.ok)(did);
104
+ }
105
+ if (isDidKeyFormat(did)) {
106
+ // Convert to did:privateme
107
+ return (0, shared_1.ok)(did.replace(/^did:key:/, 'did:privateme:'));
108
+ }
109
+ return (0, shared_1.err)('UNSUPPORTED_DID_FORMAT');
110
+ }
111
+ /**
112
+ * Parse a DID into method, identifier, and fragment.
113
+ *
114
+ * @param did - Full DID string
115
+ * @returns Parsed DID components or error
116
+ */
117
+ function parseDid(did) {
118
+ const fragmentMatch = did.indexOf('#');
119
+ const base = fragmentMatch >= 0 ? did.substring(0, fragmentMatch) : did;
120
+ const fragment = fragmentMatch >= 0 ? did.substring(fragmentMatch + 1) : undefined;
121
+ const parts = base.split(':');
122
+ if (parts.length < 3 || parts[0] !== 'did') {
123
+ return (0, shared_1.err)('INVALID_DID_FORMAT');
124
+ }
125
+ return (0, shared_1.ok)({
126
+ method: parts[1],
127
+ identifier: parts.slice(2).join(':'),
128
+ fragment,
129
+ });
130
+ }