@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,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module verify
|
|
4
|
+
* Lightweight sub-path export for verification-only use cases.
|
|
5
|
+
*
|
|
6
|
+
* Import as `@private.me/xbind/verify` for tree-shaking on edge/serverless:
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { verify, importPublicKey, validateEnvelope } from '@private.me/xbind/verify';
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* This module re-exports only the functions needed to verify signatures
|
|
12
|
+
* and validate envelopes — no key generation, no encryption, no transport.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.openSignedEnvelope = exports.deserializeEnvelope = exports.validateEnvelope = exports.didToPublicKeyBytes = exports.importPublicKey = exports.verify = void 0;
|
|
16
|
+
// Identity — verify + key import only
|
|
17
|
+
var identity_js_1 = require("./identity.js");
|
|
18
|
+
Object.defineProperty(exports, "verify", { enumerable: true, get: function () { return identity_js_1.verify; } });
|
|
19
|
+
Object.defineProperty(exports, "importPublicKey", { enumerable: true, get: function () { return identity_js_1.importPublicKey; } });
|
|
20
|
+
Object.defineProperty(exports, "didToPublicKeyBytes", { enumerable: true, get: function () { return identity_js_1.didToPublicKeyBytes; } });
|
|
21
|
+
// Envelope — validation + signed envelope verification
|
|
22
|
+
var envelope_js_1 = require("./envelope.js");
|
|
23
|
+
Object.defineProperty(exports, "validateEnvelope", { enumerable: true, get: function () { return envelope_js_1.validateEnvelope; } });
|
|
24
|
+
Object.defineProperty(exports, "deserializeEnvelope", { enumerable: true, get: function () { return envelope_js_1.deserializeEnvelope; } });
|
|
25
|
+
Object.defineProperty(exports, "openSignedEnvelope", { enumerable: true, get: function () { return envelope_js_1.openSignedEnvelope; } });
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module xfetch
|
|
4
|
+
* Drop-in fetch() replacement with auto-upgrade to xBind
|
|
5
|
+
*
|
|
6
|
+
* Provides transparent upgrade from HTTP to xBind when both parties support it.
|
|
7
|
+
* Falls back to regular HTTP fetch() when xBind is not available.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.xfetch = xfetch;
|
|
11
|
+
exports.isXBindSupported = isXBindSupported;
|
|
12
|
+
exports.getXBindCapability = getXBindCapability;
|
|
13
|
+
const agent_js_1 = require("./agent.js");
|
|
14
|
+
const agent_call_js_1 = require("./agent-call.js");
|
|
15
|
+
/**
|
|
16
|
+
* Check if endpoint supports xBind
|
|
17
|
+
*
|
|
18
|
+
* Sends OPTIONS request with xBind capability header.
|
|
19
|
+
* Endpoint responds with xBind-Support header if available.
|
|
20
|
+
*
|
|
21
|
+
* @param url - Target URL
|
|
22
|
+
* @returns Capability check result
|
|
23
|
+
*/
|
|
24
|
+
async function checkXBindSupport(url) {
|
|
25
|
+
try {
|
|
26
|
+
const response = await fetch(url, {
|
|
27
|
+
method: 'OPTIONS',
|
|
28
|
+
headers: {
|
|
29
|
+
'X-Capability-Check': 'xbind',
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
const supported = response.headers.get('X-xBind-Support') === 'true';
|
|
33
|
+
if (!supported) {
|
|
34
|
+
return { supported: false };
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
supported: true,
|
|
38
|
+
endpoint: response.headers.get('X-xBind-Endpoint') || undefined,
|
|
39
|
+
peerDID: response.headers.get('X-xBind-DID') || undefined,
|
|
40
|
+
version: response.headers.get('X-xBind-Version') || undefined,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
// Network error or CORS - assume no xBind support
|
|
45
|
+
return { supported: false };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Send request via xBind transport
|
|
50
|
+
*
|
|
51
|
+
* @param url - Target URL
|
|
52
|
+
* @param capability - xBind capability info
|
|
53
|
+
* @param options - Request options
|
|
54
|
+
* @param agent - Agent instance
|
|
55
|
+
* @returns xBind response
|
|
56
|
+
*/
|
|
57
|
+
async function sendViaXBind(url, capability, options, agent) {
|
|
58
|
+
const startTime = Date.now();
|
|
59
|
+
// TODO: Integrate with Agent.send() when transport layer is ready
|
|
60
|
+
// For now, placeholder that will be completed by transport layer work
|
|
61
|
+
throw new agent_call_js_1.AgentError(agent_call_js_1.AgentErrorCode.NETWORK_ERROR, 'xBind transport not yet implemented - requires transport layer (xchange/xfetch integration)', {
|
|
62
|
+
url,
|
|
63
|
+
peerDID: capability.peerDID,
|
|
64
|
+
nextSteps: [
|
|
65
|
+
'Complete Agent.send() integration',
|
|
66
|
+
'Implement xBind message envelope',
|
|
67
|
+
'Add DID-based authentication',
|
|
68
|
+
],
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Send request via standard HTTP fetch
|
|
73
|
+
*
|
|
74
|
+
* @param url - Target URL
|
|
75
|
+
* @param options - Request options
|
|
76
|
+
* @returns HTTP response wrapped as XFetchResponse
|
|
77
|
+
*/
|
|
78
|
+
async function sendViaHTTP(url, options) {
|
|
79
|
+
const startTime = Date.now();
|
|
80
|
+
// Remove xFetch-specific options before passing to fetch
|
|
81
|
+
const { forceXBind, disableXBind, agent, retry, ...fetchOptions } = options;
|
|
82
|
+
const response = await fetch(url, fetchOptions);
|
|
83
|
+
const latency = Date.now() - startTime;
|
|
84
|
+
// Wrap Response with xFetch metadata
|
|
85
|
+
return Object.assign(response, {
|
|
86
|
+
usedXBind: false,
|
|
87
|
+
transport: {
|
|
88
|
+
protocol: url.startsWith('https') ? 'https' : 'http',
|
|
89
|
+
latency,
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Retry logic with exponential backoff
|
|
95
|
+
*
|
|
96
|
+
* @param fn - Function to retry
|
|
97
|
+
* @param options - Retry configuration
|
|
98
|
+
* @returns Result of function
|
|
99
|
+
*/
|
|
100
|
+
async function withRetry(fn, options) {
|
|
101
|
+
const maxAttempts = options?.maxAttempts ?? 3;
|
|
102
|
+
const initialDelay = options?.initialDelay ?? 1000;
|
|
103
|
+
const multiplier = options?.multiplier ?? 2;
|
|
104
|
+
let lastError;
|
|
105
|
+
let delay = initialDelay;
|
|
106
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
107
|
+
try {
|
|
108
|
+
return await fn();
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
112
|
+
// Don't retry on client errors (4xx)
|
|
113
|
+
if (error instanceof Response && error.status >= 400 && error.status < 500) {
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
if (attempt < maxAttempts) {
|
|
117
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
118
|
+
delay *= multiplier;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
throw lastError;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* xFetch - Drop-in fetch() replacement with auto-upgrade to xBind
|
|
126
|
+
*
|
|
127
|
+
* @param url - Target URL
|
|
128
|
+
* @param options - Request options (extends fetch RequestInit)
|
|
129
|
+
* @returns Response with xBind metadata
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* // Basic usage (auto-upgrades to xBind if supported)
|
|
134
|
+
* const response = await xfetch('https://api.example.com/data');
|
|
135
|
+
* console.log('Used xBind?', response.usedXBind);
|
|
136
|
+
* const data = await response.json();
|
|
137
|
+
* ```
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* // Force xBind (fail if not supported)
|
|
142
|
+
* const response = await xfetch('https://api.example.com/secure', {
|
|
143
|
+
* forceXBind: true,
|
|
144
|
+
* });
|
|
145
|
+
* ```
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* // Disable xBind (HTTP only)
|
|
150
|
+
* const response = await xfetch('https://api.example.com/public', {
|
|
151
|
+
* disableXBind: true,
|
|
152
|
+
* });
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* // With retry and timeout
|
|
158
|
+
* const response = await xfetch('https://api.example.com/data', {
|
|
159
|
+
* timeout: 10000,
|
|
160
|
+
* retry: {
|
|
161
|
+
* maxAttempts: 5,
|
|
162
|
+
* initialDelay: 500,
|
|
163
|
+
* multiplier: 2,
|
|
164
|
+
* },
|
|
165
|
+
* });
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
async function xfetch(url, options = {}) {
|
|
169
|
+
// Validate URL
|
|
170
|
+
let parsedURL;
|
|
171
|
+
try {
|
|
172
|
+
parsedURL = new URL(url);
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
throw new agent_call_js_1.AgentError(agent_call_js_1.AgentErrorCode.INVALID_PARAMS, `Invalid URL: ${url}`, { url, error });
|
|
176
|
+
}
|
|
177
|
+
// Only support HTTP(S) protocols
|
|
178
|
+
if (!['http:', 'https:'].includes(parsedURL.protocol)) {
|
|
179
|
+
throw new agent_call_js_1.AgentError(agent_call_js_1.AgentErrorCode.INVALID_PARAMS, `Unsupported protocol: ${parsedURL.protocol}`, { url, protocol: parsedURL.protocol });
|
|
180
|
+
}
|
|
181
|
+
// Apply timeout if specified
|
|
182
|
+
const timeout = options.timeout ?? 30000;
|
|
183
|
+
const controller = new AbortController();
|
|
184
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
185
|
+
try {
|
|
186
|
+
// Merge abort signals if user provided one
|
|
187
|
+
const signal = options.signal
|
|
188
|
+
? AbortSignal.any?.([options.signal, controller.signal]) ?? controller.signal
|
|
189
|
+
: controller.signal;
|
|
190
|
+
const requestOptions = {
|
|
191
|
+
...options,
|
|
192
|
+
signal,
|
|
193
|
+
};
|
|
194
|
+
// If xBind is explicitly disabled, use HTTP directly
|
|
195
|
+
if (options.disableXBind) {
|
|
196
|
+
return await withRetry(() => sendViaHTTP(url, requestOptions), options.retry);
|
|
197
|
+
}
|
|
198
|
+
// Check if endpoint supports xBind
|
|
199
|
+
const capability = await checkXBindSupport(url);
|
|
200
|
+
// If xBind is forced but not supported, fail
|
|
201
|
+
if (options.forceXBind && !capability.supported) {
|
|
202
|
+
throw new agent_call_js_1.AgentError(agent_call_js_1.AgentErrorCode.NETWORK_ERROR, `xBind required but endpoint does not support it: ${url}`, { url, forceXBind: true, capability });
|
|
203
|
+
}
|
|
204
|
+
// If xBind is supported, use it
|
|
205
|
+
if (capability.supported) {
|
|
206
|
+
// Create or use provided agent
|
|
207
|
+
const agent = options.agent ?? await agent_js_1.Agent.from({ identity: 'ephemeral', identityTTL: 3600000 });
|
|
208
|
+
return await withRetry(() => sendViaXBind(url, capability, requestOptions, agent), options.retry);
|
|
209
|
+
}
|
|
210
|
+
// Fallback to HTTP
|
|
211
|
+
return await withRetry(() => sendViaHTTP(url, requestOptions), options.retry);
|
|
212
|
+
}
|
|
213
|
+
finally {
|
|
214
|
+
clearTimeout(timeoutId);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Check if a URL supports xBind
|
|
219
|
+
*
|
|
220
|
+
* Utility function for checking xBind support before making a request.
|
|
221
|
+
*
|
|
222
|
+
* @param url - URL to check
|
|
223
|
+
* @returns True if endpoint supports xBind
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```typescript
|
|
227
|
+
* const supported = await isXBindSupported('https://api.example.com');
|
|
228
|
+
* if (supported) {
|
|
229
|
+
* console.log('Endpoint supports xBind - request will be upgraded');
|
|
230
|
+
* }
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
async function isXBindSupported(url) {
|
|
234
|
+
const capability = await checkXBindSupport(url);
|
|
235
|
+
return capability.supported;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Get xBind capability information for a URL
|
|
239
|
+
*
|
|
240
|
+
* @param url - URL to check
|
|
241
|
+
* @returns Capability information
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```typescript
|
|
245
|
+
* const info = await getXBindCapability('https://api.example.com');
|
|
246
|
+
* console.log('Peer DID:', info.peerDID);
|
|
247
|
+
* console.log('xBind version:', info.version);
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
async function getXBindCapability(url) {
|
|
251
|
+
return checkXBindSupport(url);
|
|
252
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* @module cli/init
|
|
4
|
+
* One-line CLI setup for XBind connections.
|
|
5
|
+
*
|
|
6
|
+
* Enables: npx xbind-init --invite <code>
|
|
7
|
+
*
|
|
8
|
+
* Flow:
|
|
9
|
+
* 1. Parse invite URL or code
|
|
10
|
+
* 2. Fetch invite details from registry server
|
|
11
|
+
* 3. Interactive prompts for: project name, runtime, TypeScript vs JavaScript
|
|
12
|
+
* 4. Generate project directory with template files
|
|
13
|
+
* 5. Install dependencies
|
|
14
|
+
* 6. Write .env file with XBIND_INVITE_CODE
|
|
15
|
+
* 7. Register with XBind registry (auto-accept flow)
|
|
16
|
+
* 8. Print success message with next steps
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```bash
|
|
20
|
+
* npx xbind-init --invite https://xbind.to/invite/XBD-abc123
|
|
21
|
+
*
|
|
22
|
+
* # Prompts:
|
|
23
|
+
* # → Project name: my-xbind-app
|
|
24
|
+
* # → Runtime: node-typescript
|
|
25
|
+
* # Creating project...
|
|
26
|
+
* # Installing dependencies...
|
|
27
|
+
* # Registering with XBind...
|
|
28
|
+
* # ✅ Ready! Run: cd my-xbind-app && npm start
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Runtime template types.
|
|
33
|
+
*/
|
|
34
|
+
export type RuntimeTemplate = 'node-typescript' | 'node-javascript' | 'deno' | 'cloudflare-worker' | 'vercel-function';
|
|
35
|
+
/**
|
|
36
|
+
* Init command options.
|
|
37
|
+
*/
|
|
38
|
+
export interface InitOptions {
|
|
39
|
+
/** Invite URL or code */
|
|
40
|
+
invite?: string;
|
|
41
|
+
/** Project name */
|
|
42
|
+
name?: string;
|
|
43
|
+
/** Runtime template */
|
|
44
|
+
runtime?: RuntimeTemplate;
|
|
45
|
+
/** Skip interactive prompts */
|
|
46
|
+
yes?: boolean;
|
|
47
|
+
/** Registry URL (default: https://xbind.to) */
|
|
48
|
+
registryUrl?: string;
|
|
49
|
+
/** Registry URL (kebab-case for CLI parsing) - same as registryUrl */
|
|
50
|
+
'registry-url'?: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Main init command.
|
|
54
|
+
*
|
|
55
|
+
* @param options - Init options
|
|
56
|
+
*/
|
|
57
|
+
export declare function initCommand(options?: InitOptions): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* CLI entry point.
|
|
60
|
+
*
|
|
61
|
+
* @param argv - Command-line arguments
|
|
62
|
+
*/
|
|
63
|
+
export declare function main(argv?: string[]): Promise<void>;
|