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