@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.
- package/AGENTS.md +778 -0
- package/LICENSE.md +27 -0
- package/README.md +400 -0
- package/dist-standalone/_deps/crypto/base64.d.ts +29 -0
- package/dist-standalone/_deps/crypto/base64.js +97 -0
- package/dist-standalone/_deps/crypto/cjs/base64.js +103 -0
- package/dist-standalone/_deps/crypto/cjs/errors.js +119 -0
- package/dist-standalone/_deps/crypto/cjs/hmac.js +71 -0
- package/dist-standalone/_deps/crypto/cjs/index.js +86 -0
- package/dist-standalone/_deps/crypto/cjs/padding.js +57 -0
- package/dist-standalone/_deps/crypto/cjs/share-header.js +68 -0
- package/dist-standalone/_deps/crypto/cjs/shares.js +152 -0
- package/dist-standalone/_deps/crypto/cjs/tlv.js +199 -0
- package/dist-standalone/_deps/crypto/cjs/uuid.js +61 -0
- package/dist-standalone/_deps/crypto/cjs/verify.js +24 -0
- package/dist-standalone/_deps/crypto/cjs/xorida.js +221 -0
- package/dist-standalone/_deps/crypto/errors.d.ts +51 -0
- package/dist-standalone/_deps/crypto/errors.js +109 -0
- package/dist-standalone/_deps/crypto/hmac.d.ts +39 -0
- package/dist-standalone/_deps/crypto/hmac.js +66 -0
- package/dist-standalone/_deps/crypto/index.d.ts +20 -0
- package/dist-standalone/_deps/crypto/index.js +45 -0
- package/dist-standalone/_deps/crypto/padding.d.ts +19 -0
- package/dist-standalone/_deps/crypto/padding.js +53 -0
- package/dist-standalone/_deps/crypto/share-header.d.ts +44 -0
- package/dist-standalone/_deps/crypto/share-header.js +63 -0
- package/dist-standalone/_deps/crypto/shares.d.ts +27 -0
- package/dist-standalone/_deps/crypto/shares.js +148 -0
- package/dist-standalone/_deps/crypto/tlv.d.ts +26 -0
- package/dist-standalone/_deps/crypto/tlv.js +195 -0
- package/dist-standalone/_deps/crypto/uuid.d.ts +22 -0
- package/dist-standalone/_deps/crypto/uuid.js +56 -0
- package/dist-standalone/_deps/crypto/verify.d.ts +15 -0
- package/dist-standalone/_deps/crypto/verify.js +15 -0
- package/dist-standalone/_deps/crypto/xorida.d.ts +44 -0
- package/dist-standalone/_deps/crypto/xorida.js +215 -0
- package/dist-standalone/_deps/mldsa-wasm/LICENSE +24 -0
- package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1920 -0
- package/dist-standalone/_deps/mldsa-wasm/package.json +46 -0
- package/dist-standalone/_deps/mldsa-wasm/types/mldsa.d.ts +30 -0
- package/dist-standalone/_deps/shared/cjs/errors.js +582 -0
- package/dist-standalone/_deps/shared/cjs/index.js +492 -0
- package/dist-standalone/_deps/shared/cjs/package.json +1 -0
- package/dist-standalone/_deps/shared/cjs/types.js +403 -0
- package/dist-standalone/_deps/shared/errors.d.ts +48 -0
- package/dist-standalone/_deps/shared/errors.d.ts.map +1 -0
- package/dist-standalone/_deps/shared/errors.js +192 -0
- package/dist-standalone/_deps/shared/errors.js.map +1 -0
- package/dist-standalone/_deps/shared/index.d.ts +4 -0
- package/dist-standalone/_deps/shared/index.d.ts.map +1 -0
- package/dist-standalone/_deps/shared/index.js +78 -0
- package/dist-standalone/_deps/shared/index.js.map +1 -0
- package/dist-standalone/_deps/shared/types.d.ts +1097 -0
- package/dist-standalone/_deps/shared/types.d.ts.map +1 -0
- package/dist-standalone/_deps/shared/types.js +89 -0
- package/dist-standalone/_deps/shared/types.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts +115 -0
- package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/errors.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts +13 -0
- package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/index.js +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/index.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/package.json +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts +39 -0
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +83 -0
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts +99 -0
- package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/progress.js +143 -0
- package/dist-standalone/_deps/ux-helpers/cjs/progress.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts +32 -0
- package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/search.js +119 -0
- package/dist-standalone/_deps/ux-helpers/cjs/search.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts +109 -0
- package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/types.js +8 -0
- package/dist-standalone/_deps/ux-helpers/cjs/types.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/errors.d.ts +115 -0
- package/dist-standalone/_deps/ux-helpers/errors.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/errors.js +253 -0
- package/dist-standalone/_deps/ux-helpers/errors.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/index.d.ts +13 -0
- package/dist-standalone/_deps/ux-helpers/index.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/index.js +16 -0
- package/dist-standalone/_deps/ux-helpers/index.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/pagination.d.ts +39 -0
- package/dist-standalone/_deps/ux-helpers/pagination.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/pagination.js +79 -0
- package/dist-standalone/_deps/ux-helpers/pagination.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/progress.d.ts +99 -0
- package/dist-standalone/_deps/ux-helpers/progress.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/progress.js +138 -0
- package/dist-standalone/_deps/ux-helpers/progress.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/search.d.ts +32 -0
- package/dist-standalone/_deps/ux-helpers/search.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/search.js +116 -0
- package/dist-standalone/_deps/ux-helpers/search.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/types.d.ts +109 -0
- package/dist-standalone/_deps/ux-helpers/types.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/types.js +7 -0
- package/dist-standalone/_deps/ux-helpers/types.js.map +1 -0
- package/dist-standalone/_deps/xchange/auto-accept.d.ts +127 -0
- package/dist-standalone/_deps/xchange/auto-accept.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/auto-accept.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/errors.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/index.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/invite-client.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/lazy-init.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/package.json +1 -0
- package/dist-standalone/_deps/xchange/cjs/trust-integration.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/xchange.js +1 -0
- package/dist-standalone/_deps/xchange/errors.d.ts +69 -0
- package/dist-standalone/_deps/xchange/errors.js +1 -0
- package/dist-standalone/_deps/xchange/index.d.ts +15 -0
- package/dist-standalone/_deps/xchange/index.js +1 -0
- package/dist-standalone/_deps/xchange/invite-client.d.ts +178 -0
- package/dist-standalone/_deps/xchange/invite-client.js +1 -0
- package/dist-standalone/_deps/xchange/lazy-init.d.ts +176 -0
- package/dist-standalone/_deps/xchange/lazy-init.js +1 -0
- package/dist-standalone/_deps/xchange/trust-integration.d.ts +102 -0
- package/dist-standalone/_deps/xchange/trust-integration.js +1 -0
- package/dist-standalone/_deps/xchange/xchange.d.ts +60 -0
- package/dist-standalone/_deps/xchange/xchange.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/discovery.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/errors.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/index.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/package.json +1 -0
- package/dist-standalone/_deps/xregistry/cjs/registry.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/schema.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/types.js +1 -0
- package/dist-standalone/_deps/xregistry/discovery.d.ts +126 -0
- package/dist-standalone/_deps/xregistry/discovery.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/discovery.js +1 -0
- package/dist-standalone/_deps/xregistry/discovery.js.map +1 -0
- package/dist-standalone/_deps/xregistry/errors.d.ts +41 -0
- package/dist-standalone/_deps/xregistry/errors.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/errors.js +1 -0
- package/dist-standalone/_deps/xregistry/errors.js.map +1 -0
- package/dist-standalone/_deps/xregistry/index.d.ts +8 -0
- package/dist-standalone/_deps/xregistry/index.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/index.js +1 -0
- package/dist-standalone/_deps/xregistry/index.js.map +1 -0
- package/dist-standalone/_deps/xregistry/registry.d.ts +85 -0
- package/dist-standalone/_deps/xregistry/registry.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/registry.js +1 -0
- package/dist-standalone/_deps/xregistry/registry.js.map +1 -0
- package/dist-standalone/_deps/xregistry/schema.d.ts +81 -0
- package/dist-standalone/_deps/xregistry/schema.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/schema.js +1 -0
- package/dist-standalone/_deps/xregistry/schema.js.map +1 -0
- package/dist-standalone/_deps/xregistry/types.d.ts +95 -0
- package/dist-standalone/_deps/xregistry/types.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/types.js +1 -0
- package/dist-standalone/_deps/xregistry/types.js.map +1 -0
- package/dist-standalone/agent-call.d.ts +286 -0
- package/dist-standalone/agent-call.js +642 -0
- package/dist-standalone/agent-sdk.d.ts +207 -0
- package/dist-standalone/agent-sdk.js +328 -0
- package/dist-standalone/agent.d.ts +670 -0
- package/dist-standalone/agent.js +1529 -0
- package/dist-standalone/approval.d.ts +145 -0
- package/dist-standalone/approval.js +193 -0
- package/dist-standalone/auth.d.ts +75 -0
- package/dist-standalone/auth.js +219 -0
- package/dist-standalone/auto-accept.d.ts +102 -0
- package/dist-standalone/auto-accept.js +229 -0
- package/dist-standalone/backup-config.d.ts +150 -0
- package/dist-standalone/backup-config.js +201 -0
- package/dist-standalone/checkpoint.d.ts +125 -0
- package/dist-standalone/checkpoint.js +186 -0
- package/dist-standalone/cjs/agent-call.js +651 -0
- package/dist-standalone/cjs/agent-sdk.js +332 -0
- package/dist-standalone/cjs/agent.js +1566 -0
- package/dist-standalone/cjs/approval.js +199 -0
- package/dist-standalone/cjs/auth.js +225 -0
- package/dist-standalone/cjs/auto-accept.js +233 -0
- package/dist-standalone/cjs/backup-config.js +207 -0
- package/dist-standalone/cjs/checkpoint.js +193 -0
- package/dist-standalone/cjs/cli/init.js +487 -0
- package/dist-standalone/cjs/connect.js +312 -0
- package/dist-standalone/cjs/did-document.js +101 -0
- package/dist-standalone/cjs/did-privateme.js +130 -0
- package/dist-standalone/cjs/did-web.js +201 -0
- package/dist-standalone/cjs/discovery.js +462 -0
- package/dist-standalone/cjs/dual-mode.js +251 -0
- package/dist-standalone/cjs/email-templates.js +313 -0
- package/dist-standalone/cjs/email-transport.js +239 -0
- package/dist-standalone/cjs/envelope.js +510 -0
- package/dist-standalone/cjs/errors.js +562 -0
- package/dist-standalone/cjs/gateway-state.js +55 -0
- package/dist-standalone/cjs/gateway-transport.js +120 -0
- package/dist-standalone/cjs/guardrails.js +223 -0
- package/dist-standalone/cjs/http-compat.js +272 -0
- package/dist-standalone/cjs/identity.js +541 -0
- package/dist-standalone/cjs/index.js +224 -0
- package/dist-standalone/cjs/invitation.js +421 -0
- package/dist-standalone/cjs/invite.js +328 -0
- package/dist-standalone/cjs/key-agreement.js +246 -0
- package/dist-standalone/cjs/lazy-init.js +300 -0
- package/dist-standalone/cjs/mdns-discovery.js +202 -0
- package/dist-standalone/cjs/nonce-store.js +66 -0
- package/dist-standalone/cjs/package.json +3 -0
- package/dist-standalone/cjs/pairing-manager.js +223 -0
- package/dist-standalone/cjs/policy.js +320 -0
- package/dist-standalone/cjs/redis-nonce-store.js +76 -0
- package/dist-standalone/cjs/registry-middleware.js +50 -0
- package/dist-standalone/cjs/retry-transport.js +102 -0
- package/dist-standalone/cjs/security-policy.js +204 -0
- package/dist-standalone/cjs/split-channel.js +177 -0
- package/dist-standalone/cjs/subscription-proof.js +230 -0
- package/dist-standalone/cjs/succession.js +148 -0
- package/dist-standalone/cjs/transport.js +63 -0
- package/dist-standalone/cjs/trust-registry.js +742 -0
- package/dist-standalone/cjs/verify.js +25 -0
- package/dist-standalone/cjs/xfetch.js +252 -0
- package/dist-standalone/cli/init.d.ts +63 -0
- package/dist-standalone/cli/init.js +450 -0
- package/dist-standalone/connect.d.ts +143 -0
- package/dist-standalone/connect.js +274 -0
- package/dist-standalone/did-document.d.ts +65 -0
- package/dist-standalone/did-document.js +96 -0
- package/dist-standalone/did-privateme.d.ts +70 -0
- package/dist-standalone/did-privateme.js +121 -0
- package/dist-standalone/did-web.d.ts +73 -0
- package/dist-standalone/did-web.js +196 -0
- package/dist-standalone/discovery.d.ts +176 -0
- package/dist-standalone/discovery.js +458 -0
- package/dist-standalone/dual-mode.d.ts +145 -0
- package/dist-standalone/dual-mode.js +247 -0
- package/dist-standalone/email-templates.d.ts +41 -0
- package/dist-standalone/email-templates.js +309 -0
- package/dist-standalone/email-transport.d.ts +139 -0
- package/dist-standalone/email-transport.js +232 -0
- package/dist-standalone/envelope.d.ts +288 -0
- package/dist-standalone/envelope.js +497 -0
- package/dist-standalone/errors.d.ts +74 -0
- package/dist-standalone/errors.js +548 -0
- package/dist-standalone/gateway-state.d.ts +32 -0
- package/dist-standalone/gateway-state.js +51 -0
- package/dist-standalone/gateway-transport.d.ts +59 -0
- package/dist-standalone/gateway-transport.js +116 -0
- package/dist-standalone/guardrails.d.ts +136 -0
- package/dist-standalone/guardrails.js +216 -0
- package/dist-standalone/http-compat.d.ts +150 -0
- package/dist-standalone/http-compat.js +267 -0
- package/dist-standalone/identity.d.ts +176 -0
- package/dist-standalone/identity.js +516 -0
- package/dist-standalone/index.d.ts +83 -0
- package/dist-standalone/index.js +51 -0
- package/dist-standalone/invitation.d.ts +211 -0
- package/dist-standalone/invitation.js +415 -0
- package/dist-standalone/invite.d.ts +192 -0
- package/dist-standalone/invite.js +324 -0
- package/dist-standalone/key-agreement.d.ts +122 -0
- package/dist-standalone/key-agreement.js +236 -0
- package/dist-standalone/lazy-init.d.ts +167 -0
- package/dist-standalone/lazy-init.js +295 -0
- package/dist-standalone/mdns-discovery.d.ts +117 -0
- package/dist-standalone/mdns-discovery.js +195 -0
- package/dist-standalone/nonce-store.d.ts +39 -0
- package/dist-standalone/nonce-store.js +62 -0
- package/dist-standalone/package.json +11 -0
- package/dist-standalone/pairing-manager.d.ts +147 -0
- package/dist-standalone/pairing-manager.js +219 -0
- package/dist-standalone/policy.d.ts +150 -0
- package/dist-standalone/policy.js +315 -0
- package/dist-standalone/redis-nonce-store.d.ts +93 -0
- package/dist-standalone/redis-nonce-store.js +72 -0
- package/dist-standalone/registry-middleware.d.ts +38 -0
- package/dist-standalone/registry-middleware.js +47 -0
- package/dist-standalone/retry-transport.d.ts +76 -0
- package/dist-standalone/retry-transport.js +98 -0
- package/dist-standalone/security-policy.d.ts +146 -0
- package/dist-standalone/security-policy.js +198 -0
- package/dist-standalone/split-channel.d.ts +69 -0
- package/dist-standalone/split-channel.js +171 -0
- package/dist-standalone/subscription-proof.d.ts +103 -0
- package/dist-standalone/subscription-proof.js +224 -0
- package/dist-standalone/succession.d.ts +57 -0
- package/dist-standalone/succession.js +142 -0
- package/dist-standalone/transport.d.ts +50 -0
- package/dist-standalone/transport.js +59 -0
- package/dist-standalone/trust-registry.d.ts +286 -0
- package/dist-standalone/trust-registry.js +702 -0
- package/dist-standalone/verify.d.ts +16 -0
- package/dist-standalone/verify.js +16 -0
- package/dist-standalone/xfetch.d.ts +129 -0
- package/dist-standalone/xfetch.js +247 -0
- package/llms.txt +800 -0
- package/package.json +79 -0
- 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
|
+
}
|