@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,670 @@
|
|
|
1
|
+
import type { Result } from '@private.me/shared';
|
|
2
|
+
import type { AgentIdentity } from './identity.js';
|
|
3
|
+
import { generateSharedKey } from './envelope.js';
|
|
4
|
+
import type { TransportEnvelopeV4, AnyTransportEnvelope } from './envelope.js';
|
|
5
|
+
import type { NonceStore } from './nonce-store.js';
|
|
6
|
+
import type { SplitChannelConfig } from './split-channel.js';
|
|
7
|
+
import type { XailTransportAdapter, TransportError } from './transport.js';
|
|
8
|
+
import type { TrustRegistry } from './trust-registry.js';
|
|
9
|
+
import type { ProgressCallback } from '@private.me/ux-helpers';
|
|
10
|
+
import type { SecurityPolicy, SecurityLevel, SecurityDecision } from './security-policy.js';
|
|
11
|
+
/**
|
|
12
|
+
* Simplified options for Agent constructor (agent-first API).
|
|
13
|
+
*
|
|
14
|
+
* For full control, use Agent.create() with AgentCreateOptions.
|
|
15
|
+
*/
|
|
16
|
+
export interface AgentOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Identity mode:
|
|
19
|
+
* - 'persistent': Long-lived DID, registered with trust registry
|
|
20
|
+
* - 'ephemeral': Short-lived DID, auto-cleanup after TTL expires
|
|
21
|
+
*/
|
|
22
|
+
readonly identity?: 'persistent' | 'ephemeral';
|
|
23
|
+
/**
|
|
24
|
+
* Time-to-live for ephemeral identities (milliseconds).
|
|
25
|
+
*
|
|
26
|
+
* After this duration, the identity is auto-deregistered and cleaned up.
|
|
27
|
+
* Only applies when identity === 'ephemeral'.
|
|
28
|
+
*
|
|
29
|
+
* Default: 3600000 (1 hour)
|
|
30
|
+
*/
|
|
31
|
+
readonly identityTTL?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Trust registry (instance or URL for HttpTrustRegistry).
|
|
34
|
+
*
|
|
35
|
+
* Optional for ephemeral identities (uses MemoryTrustRegistry by default).
|
|
36
|
+
* Required for persistent identities.
|
|
37
|
+
*/
|
|
38
|
+
readonly registry?: TrustRegistry | string;
|
|
39
|
+
/**
|
|
40
|
+
* Transport adapter(s) for envelope delivery.
|
|
41
|
+
*
|
|
42
|
+
* Optional - uses HttpsTransportAdapter by default.
|
|
43
|
+
*/
|
|
44
|
+
readonly transport?: XailTransportAdapter | XailTransportAdapter[];
|
|
45
|
+
/**
|
|
46
|
+
* Security policy for automatic risk-based Xorida activation.
|
|
47
|
+
*
|
|
48
|
+
* Uses DefaultSecurityPolicy if omitted.
|
|
49
|
+
*/
|
|
50
|
+
readonly securityPolicy?: SecurityPolicy;
|
|
51
|
+
/**
|
|
52
|
+
* Enable post-quantum signatures (ML-DSA-65).
|
|
53
|
+
*
|
|
54
|
+
* Default: false
|
|
55
|
+
*/
|
|
56
|
+
readonly postQuantumSig?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* XorIDA backup configuration for key splitting.
|
|
59
|
+
*
|
|
60
|
+
* Uses DEFAULT_BACKUP_CONFIG (k=2, n=3) if omitted.
|
|
61
|
+
*/
|
|
62
|
+
readonly backupConfig?: import('./backup-config.js').BackupConfig;
|
|
63
|
+
}
|
|
64
|
+
/** Options for Agent.create() (full-featured API). */
|
|
65
|
+
export interface AgentCreateOptions {
|
|
66
|
+
/** Display name for the agent. */
|
|
67
|
+
readonly name: string;
|
|
68
|
+
/** Trust registry (instance or URL for HttpTrustRegistry). */
|
|
69
|
+
readonly registry: TrustRegistry;
|
|
70
|
+
/**
|
|
71
|
+
* Transport adapter(s) for envelope delivery.
|
|
72
|
+
*
|
|
73
|
+
* For split-channel security, provide one transport per share channel.
|
|
74
|
+
* Each share routes to transports[shareIndex % transports.length].
|
|
75
|
+
* With a single transport, all shares travel the same channel —
|
|
76
|
+
* data is split but channel separation is not achieved.
|
|
77
|
+
*/
|
|
78
|
+
readonly transport: XailTransportAdapter | XailTransportAdapter[];
|
|
79
|
+
/** NonceStore for replay prevention. Uses MemoryNonceStore if omitted. */
|
|
80
|
+
readonly nonceStore?: NonceStore;
|
|
81
|
+
/** Scopes this agent requests. */
|
|
82
|
+
readonly scopes?: string[];
|
|
83
|
+
/** Timestamp validity window in ms. Default 30 000 (30 s). */
|
|
84
|
+
readonly timestampWindowMs?: number;
|
|
85
|
+
/** Enable ML-DSA-65 post-quantum signatures (v3 envelopes). Default: false. */
|
|
86
|
+
readonly postQuantumSig?: boolean;
|
|
87
|
+
/** Advertise Xchange mode support. Default: false. When true, peers MAY send Xchange envelopes (faster, single security layer). */
|
|
88
|
+
readonly xchange?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Security policy for automatic risk-based Xorida activation.
|
|
91
|
+
*
|
|
92
|
+
* Uses DefaultSecurityPolicy if omitted. Enterprise users can provide
|
|
93
|
+
* EnterpriseSecurityPolicy with custom rules.
|
|
94
|
+
*/
|
|
95
|
+
readonly securityPolicy?: SecurityPolicy;
|
|
96
|
+
}
|
|
97
|
+
/** Options for agent.send(). */
|
|
98
|
+
export interface AgentSendOptions {
|
|
99
|
+
/** Recipient DID. */
|
|
100
|
+
readonly to: string;
|
|
101
|
+
/** Payload (serialized to JSON). */
|
|
102
|
+
readonly payload: unknown;
|
|
103
|
+
/** Permission scope. */
|
|
104
|
+
readonly scope: string;
|
|
105
|
+
/**
|
|
106
|
+
* Action being performed (e.g., 'transfer', 'execute', 'send').
|
|
107
|
+
*
|
|
108
|
+
* Used by security policy to determine when to auto-apply XorIDA split-channel.
|
|
109
|
+
* If omitted, defaults to 'send'.
|
|
110
|
+
*/
|
|
111
|
+
readonly action?: string;
|
|
112
|
+
/**
|
|
113
|
+
* Security level override.
|
|
114
|
+
*
|
|
115
|
+
* - 'auto' (default): Let security policy decide based on action + params
|
|
116
|
+
* - 'standard': Force standard encrypted transport (disable auto-upgrade)
|
|
117
|
+
* - 'high': Force multi-party approval (3 shares, 2-of-3 threshold)
|
|
118
|
+
* - 'critical': Force critical security (5 shares, 3-of-5 threshold)
|
|
119
|
+
*
|
|
120
|
+
* Most users should use 'auto' and let the system decide.
|
|
121
|
+
*/
|
|
122
|
+
readonly security?: SecurityLevel;
|
|
123
|
+
/**
|
|
124
|
+
* Enable XorIDA split-channel.
|
|
125
|
+
*
|
|
126
|
+
* @deprecated Use `security: 'high'` instead. This field is maintained for
|
|
127
|
+
* backward compatibility but will be removed in v3.0.
|
|
128
|
+
*/
|
|
129
|
+
readonly splitChannel?: boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Split-channel configuration (totalShares, threshold).
|
|
132
|
+
*
|
|
133
|
+
* @deprecated Security policy now determines share configuration automatically.
|
|
134
|
+
* This field is maintained for backward compatibility but will be removed in v3.0.
|
|
135
|
+
*/
|
|
136
|
+
readonly splitChannelConfig?: SplitChannelConfig;
|
|
137
|
+
/**
|
|
138
|
+
* Use Xchange mode (faster, single security layer instead of three).
|
|
139
|
+
*
|
|
140
|
+
* @deprecated Set `payload.xchange: true` instead. The security policy will
|
|
141
|
+
* detect this and apply Xchange mode automatically.
|
|
142
|
+
*/
|
|
143
|
+
readonly xchange?: boolean;
|
|
144
|
+
/** Optional progress callback for long-running operations. */
|
|
145
|
+
readonly onProgress?: ProgressCallback;
|
|
146
|
+
}
|
|
147
|
+
/** Verified message from receive/middleware. */
|
|
148
|
+
export interface AgentMessage {
|
|
149
|
+
readonly sender: string;
|
|
150
|
+
readonly payload: unknown;
|
|
151
|
+
readonly scope: string;
|
|
152
|
+
readonly timestamp: number;
|
|
153
|
+
/** Protocol metadata for viral exposure */
|
|
154
|
+
readonly metadata?: {
|
|
155
|
+
readonly protocol: string;
|
|
156
|
+
readonly documentationUrl: string;
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/** Options for agent.receive(). */
|
|
160
|
+
export interface AgentReceiveOptions {
|
|
161
|
+
/**
|
|
162
|
+
* When true, accept signed-but-unencrypted envelopes as cleartext.
|
|
163
|
+
*
|
|
164
|
+
* If decryption fails, the payload is parsed as plaintext JSON instead
|
|
165
|
+
* of returning a decryption error. Useful for IoT gateways that accept
|
|
166
|
+
* both encrypted and signed-only telemetry.
|
|
167
|
+
*/
|
|
168
|
+
readonly allowCleartext?: boolean;
|
|
169
|
+
/** Optional progress callback for long-running operations. */
|
|
170
|
+
readonly onProgress?: ProgressCallback;
|
|
171
|
+
}
|
|
172
|
+
/** Parsed error detail with step context. */
|
|
173
|
+
export interface AgentErrorDetail {
|
|
174
|
+
/** Base error code (e.g. 'TIMESTAMP_EXPIRED'). */
|
|
175
|
+
readonly code: string;
|
|
176
|
+
/** Sub-code if present (e.g. 'DECRYPTION' from 'DECRYPT_FAILED:DECRYPTION'). */
|
|
177
|
+
readonly subCode?: string;
|
|
178
|
+
/** Human-readable diagnostic detail from the verification step. */
|
|
179
|
+
readonly step?: string;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Parse an AgentError string into structured detail.
|
|
183
|
+
*
|
|
184
|
+
* Splits colon-separated error codes into base code and sub-code.
|
|
185
|
+
*
|
|
186
|
+
* @param error - An AgentError string (e.g. 'DECRYPT_FAILED:KEY_AGREEMENT').
|
|
187
|
+
* @returns Parsed error detail.
|
|
188
|
+
*/
|
|
189
|
+
export declare function parseAgentError(error: string): AgentErrorDetail;
|
|
190
|
+
/** Agent-level error codes. Sub-codes give precise failure context. */
|
|
191
|
+
export type AgentError = TransportError | 'IDENTITY_FAILED' | 'IDENTITY_FAILED:KEYGEN' | 'REGISTRATION_FAILED' | 'REGISTRATION_FAILED:ALREADY_REGISTERED' | 'REGISTRATION_FAILED:NETWORK_ERROR' | 'RECIPIENT_NOT_FOUND' | 'RECIPIENT_REVOKED' | 'KEY_AGREEMENT_FAILED' | 'KEY_AGREEMENT_FAILED:RECIPIENT_HAS_NO_X25519_KEY' | 'ENVELOPE_FAILED' | 'ENVELOPE_FAILED:ENCRYPT' | 'ENVELOPE_FAILED:SIGN' | 'ENVELOPE_FAILED:SPLIT' | 'VERIFICATION_FAILED' | 'VERIFICATION_FAILED:UNSUPPORTED_VERSION' | 'VERIFICATION_FAILED:DID_NOT_IN_REGISTRY' | 'VERIFICATION_FAILED:KEY_IMPORT_FAILED' | 'VERIFICATION_FAILED:SIGNATURE_MISMATCH' | 'VERIFICATION_FAILED:PQ_KEY_MISSING' | 'VERIFICATION_FAILED:PQ_SIGNATURE_MISMATCH' | 'ENVELOPE_FAILED:PQ_KEY_MISSING' | 'REPLAY_DETECTED' | 'SCOPE_DENIED' | 'RECEIVER_SCOPE_DENIED' | 'TIMESTAMP_EXPIRED' | 'DECRYPT_FAILED' | 'DECRYPT_FAILED:KEY_AGREEMENT' | 'DECRYPT_FAILED:NO_EPHEMERAL_KEY' | 'DECRYPT_FAILED:DECRYPTION' | 'DECRYPT_FAILED:PARSE' | 'SEND_FAILED:BELOW_THRESHOLD';
|
|
192
|
+
/**
|
|
193
|
+
* Top-level Xail Agent SDK API.
|
|
194
|
+
*
|
|
195
|
+
* Matches xail.io/sdk specification:
|
|
196
|
+
* - Agent.create({ name, registry }) — generate identity + register
|
|
197
|
+
* - agent.send({ to, payload, scope }) — encrypt, sign, deliver
|
|
198
|
+
* - agent.receive(envelope) — verify, decrypt, return message
|
|
199
|
+
*/
|
|
200
|
+
export declare class Agent {
|
|
201
|
+
readonly identity: AgentIdentity;
|
|
202
|
+
readonly name: string;
|
|
203
|
+
private readonly registry;
|
|
204
|
+
private readonly transports;
|
|
205
|
+
private readonly nonceStore;
|
|
206
|
+
private readonly timestampWindowMs;
|
|
207
|
+
private readonly securityPolicy;
|
|
208
|
+
private readonly backupConfig;
|
|
209
|
+
/** Accumulates split-channel shares by groupId until threshold is met. */
|
|
210
|
+
private readonly shareAccumulator;
|
|
211
|
+
/** Diagnostic detail from the last failed verification step. */
|
|
212
|
+
private lastDetail;
|
|
213
|
+
/** Last security decision made by the policy (for debugging/logging). */
|
|
214
|
+
private lastSecurityDecision?;
|
|
215
|
+
/** Timer for ephemeral agent auto-cleanup. */
|
|
216
|
+
private cleanupTimer?;
|
|
217
|
+
/**
|
|
218
|
+
* Human-readable diagnostic from the last failed receive/verify call.
|
|
219
|
+
*
|
|
220
|
+
* Populated during verification with context like age vs max window.
|
|
221
|
+
* Empty string if no error has occurred or after a successful call.
|
|
222
|
+
*/
|
|
223
|
+
get lastErrorDetail(): string;
|
|
224
|
+
/**
|
|
225
|
+
* Last security decision made by the security policy.
|
|
226
|
+
*
|
|
227
|
+
* Shows which security mode was selected and why. Useful for debugging
|
|
228
|
+
* and understanding when/why Xorida split-channel was activated.
|
|
229
|
+
*
|
|
230
|
+
* Returns undefined if no send() has been called yet.
|
|
231
|
+
*/
|
|
232
|
+
get lastSecurity(): SecurityDecision | undefined;
|
|
233
|
+
private constructor();
|
|
234
|
+
/** The agent's DID. */
|
|
235
|
+
get did(): string;
|
|
236
|
+
/**
|
|
237
|
+
* Check whether the runtime supports the SDK's crypto requirements.
|
|
238
|
+
*
|
|
239
|
+
* Verifies that `crypto.subtle` is available and supports Ed25519 +
|
|
240
|
+
* AES-256-GCM. Call this before lazy-loading the SDK in middleware
|
|
241
|
+
* to avoid failing on the first `Agent.create()` call.
|
|
242
|
+
*
|
|
243
|
+
* @returns `true` if the runtime has the required Web Crypto APIs.
|
|
244
|
+
*/
|
|
245
|
+
static isSupported(): boolean;
|
|
246
|
+
/**
|
|
247
|
+
* Create an Agent from a persisted identity (skips keygen + registration).
|
|
248
|
+
*
|
|
249
|
+
* Use this with importFromPKCS8 or importIdentity to restore a
|
|
250
|
+
* previously created agent across process restarts.
|
|
251
|
+
*
|
|
252
|
+
* @param identity - A previously exported AgentIdentity.
|
|
253
|
+
* @param opts - Agent options (registry, transport, etc.).
|
|
254
|
+
* @returns Agent instance or error.
|
|
255
|
+
*/
|
|
256
|
+
static fromIdentity(identity: AgentIdentity, opts: Omit<AgentCreateOptions, 'name'> & {
|
|
257
|
+
name?: string;
|
|
258
|
+
backupConfig?: import('./backup-config.js').BackupConfig;
|
|
259
|
+
}): Promise<Result<Agent, AgentError>>;
|
|
260
|
+
/**
|
|
261
|
+
* Build an Agent from pre-constructed parts (synchronous).
|
|
262
|
+
*
|
|
263
|
+
* Unlike `create()` this does NOT generate keys or register with the
|
|
264
|
+
* registry — the caller is responsible for both. Useful when identity
|
|
265
|
+
* is provisioned in a factory step, registration is handled by an
|
|
266
|
+
* external system, or transport is wired up at runtime.
|
|
267
|
+
*
|
|
268
|
+
* @param identity - A previously generated or imported AgentIdentity.
|
|
269
|
+
* @param registry - Trust registry the agent will query for peers.
|
|
270
|
+
* @param transport - Transport adapter for envelope delivery.
|
|
271
|
+
* @param opts - Optional overrides (name, nonceStore, timestampWindowMs).
|
|
272
|
+
* @returns A fully wired Agent instance.
|
|
273
|
+
*/
|
|
274
|
+
static fromParts(identity: AgentIdentity, registry: TrustRegistry, transport: XailTransportAdapter | XailTransportAdapter[], opts?: {
|
|
275
|
+
name?: string;
|
|
276
|
+
nonceStore?: NonceStore;
|
|
277
|
+
timestampWindowMs?: number;
|
|
278
|
+
securityPolicy?: SecurityPolicy;
|
|
279
|
+
backupConfig?: import('./backup-config.js').BackupConfig;
|
|
280
|
+
}): Agent;
|
|
281
|
+
/**
|
|
282
|
+
* Create an Agent from a deterministic 32-byte seed.
|
|
283
|
+
*
|
|
284
|
+
* Uses HKDF-SHA256 to derive Ed25519 + X25519 keys from the seed.
|
|
285
|
+
* The same seed always produces the same DID and keys. Skips registry
|
|
286
|
+
* registration — the caller is responsible for registering externally.
|
|
287
|
+
*
|
|
288
|
+
* Ideal for IoT: factory burns seed → field deploys → boot derives identity.
|
|
289
|
+
*
|
|
290
|
+
* @param seed - Exactly 32 bytes of high-entropy key material.
|
|
291
|
+
* @param opts - Agent options (registry, transport, etc.).
|
|
292
|
+
* @returns Agent instance or error.
|
|
293
|
+
*/
|
|
294
|
+
static fromSeed(seed: Uint8Array, opts: Omit<AgentCreateOptions, 'name'> & {
|
|
295
|
+
name?: string;
|
|
296
|
+
backupConfig?: import('./backup-config.js').BackupConfig;
|
|
297
|
+
}): Promise<Result<Agent, AgentError>>;
|
|
298
|
+
/**
|
|
299
|
+
* Create a lazy agent that initializes on first use (zero-click onboarding).
|
|
300
|
+
*
|
|
301
|
+
* Defers invite acceptance and identity generation until first send/receive.
|
|
302
|
+
* Reads invite code from XBIND_INVITE_CODE environment variable.
|
|
303
|
+
* Auto-accepts invite and configures registry/transport automatically.
|
|
304
|
+
*
|
|
305
|
+
* @param config - Lazy agent configuration (name required).
|
|
306
|
+
* @returns Lazy agent wrapper (synchronous).
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```ts
|
|
310
|
+
* // Environment: XBIND_INVITE_CODE=XBD-abc123, XBIND_AUTO_ACCEPT=true
|
|
311
|
+
*
|
|
312
|
+
* // Synchronous construction (no await):
|
|
313
|
+
* const agent = Agent.lazy({ name: 'my-service' });
|
|
314
|
+
*
|
|
315
|
+
* // Auto-accept happens on first send/receive:
|
|
316
|
+
* await agent.send({
|
|
317
|
+
* to: 'did:key:z6Mk...',
|
|
318
|
+
* payload: { action: 'test' },
|
|
319
|
+
* scope: 'test',
|
|
320
|
+
* });
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
323
|
+
static lazy(config: {
|
|
324
|
+
name: string;
|
|
325
|
+
inviteCode?: string;
|
|
326
|
+
endpoint?: string;
|
|
327
|
+
postQuantumSig?: boolean;
|
|
328
|
+
xchange?: boolean;
|
|
329
|
+
}): Promise<import('./lazy-init.js').LazyAgent>;
|
|
330
|
+
/**
|
|
331
|
+
* Check whether this agent is fully initialized and ready to send/receive.
|
|
332
|
+
*
|
|
333
|
+
* Returns `true` if identity, registry, and transport are all present.
|
|
334
|
+
* Construction always produces a ready agent (invalid inputs cause the
|
|
335
|
+
* factory to return an error instead), so this is primarily useful in
|
|
336
|
+
* middleware that lazily initializes agents and needs a guard.
|
|
337
|
+
*
|
|
338
|
+
* @returns `true` if the agent can send and receive messages.
|
|
339
|
+
*/
|
|
340
|
+
isReady(): boolean;
|
|
341
|
+
/** Create a new agent, generate identity, register with trust registry. */
|
|
342
|
+
static create(opts: AgentCreateOptions): Promise<Result<Agent, AgentError>>;
|
|
343
|
+
/**
|
|
344
|
+
* Quickstart: create an agent with zero configuration.
|
|
345
|
+
*
|
|
346
|
+
* Creates an ephemeral agent with auto-cleanup after 1 hour. No policy
|
|
347
|
+
* restrictions by default (allow all operations). Ideal for getting
|
|
348
|
+
* started, prototyping, and simple use cases.
|
|
349
|
+
*
|
|
350
|
+
* Uses in-memory registry and default transport. Identity auto-expires
|
|
351
|
+
* and is deregistered after TTL.
|
|
352
|
+
*
|
|
353
|
+
* @param opts - Optional configuration (name only)
|
|
354
|
+
* @returns Agent instance (throws on error for simpler API)
|
|
355
|
+
*
|
|
356
|
+
* @example
|
|
357
|
+
* ```ts
|
|
358
|
+
* // Zero config (ephemeral identity, 1-hour TTL):
|
|
359
|
+
* const agent = await Agent.quickstart();
|
|
360
|
+
*
|
|
361
|
+
* // With custom name:
|
|
362
|
+
* const agent = await Agent.quickstart({ name: 'my-service' });
|
|
363
|
+
*
|
|
364
|
+
* // Agent is ready to use immediately:
|
|
365
|
+
* await agent.send({
|
|
366
|
+
* to: 'did:key:z6Mk...',
|
|
367
|
+
* payload: { action: 'test' },
|
|
368
|
+
* scope: 'test',
|
|
369
|
+
* });
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
static quickstart(opts?: {
|
|
373
|
+
/** Agent name (default: auto-generated) */
|
|
374
|
+
name?: string;
|
|
375
|
+
}): Promise<Agent>;
|
|
376
|
+
/**
|
|
377
|
+
* Create agent from simplified options (async factory).
|
|
378
|
+
*
|
|
379
|
+
* This is the async-safe way to construct agents with AgentOptions.
|
|
380
|
+
*
|
|
381
|
+
* @param options - Agent configuration
|
|
382
|
+
* @returns Agent instance
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* ```typescript
|
|
386
|
+
* import { Agent } from '@private.me/xbind';
|
|
387
|
+
*
|
|
388
|
+
* // Ephemeral agent (auto-cleanup after 1 hour)
|
|
389
|
+
* const agent = await Agent.from({
|
|
390
|
+
* identity: 'ephemeral',
|
|
391
|
+
* identityTTL: 3600, // seconds
|
|
392
|
+
* });
|
|
393
|
+
*
|
|
394
|
+
* // Use the agent
|
|
395
|
+
* await agent.send({ to, payload, scope: 'read' });
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
398
|
+
static from(options?: AgentOptions): Promise<Agent>;
|
|
399
|
+
/** Send a message to a recipient. */
|
|
400
|
+
send(opts: AgentSendOptions): Promise<Result<void, AgentError>>;
|
|
401
|
+
/**
|
|
402
|
+
* Verify and decrypt an incoming encrypted envelope (v1 or v2).
|
|
403
|
+
*
|
|
404
|
+
* @param envelope - Incoming transport envelope.
|
|
405
|
+
* @param opts - Optional receive options (e.g. allowCleartext).
|
|
406
|
+
*/
|
|
407
|
+
receive(envelope: AnyTransportEnvelope, opts?: AgentReceiveOptions): Promise<Result<AgentMessage, AgentError>>;
|
|
408
|
+
/**
|
|
409
|
+
* Verify only the signature on an envelope without consuming the nonce.
|
|
410
|
+
*
|
|
411
|
+
* Does NOT check timestamp, nonce, or scope. Use this for pre-screening
|
|
412
|
+
* or audit logging where you need to confirm the sender but don't want
|
|
413
|
+
* to consume replay-prevention state.
|
|
414
|
+
*
|
|
415
|
+
* @param envelope - The envelope to verify.
|
|
416
|
+
* @returns `{ sender, valid }` or error if the DID cannot be resolved.
|
|
417
|
+
*/
|
|
418
|
+
verifySignature(envelope: AnyTransportEnvelope): Promise<Result<{
|
|
419
|
+
sender: string;
|
|
420
|
+
valid: boolean;
|
|
421
|
+
}, AgentError>>;
|
|
422
|
+
/**
|
|
423
|
+
* Export the raw 32-byte private key seeds for both Ed25519 and X25519.
|
|
424
|
+
*
|
|
425
|
+
* These are the raw private key bytes extracted from PKCS8, NOT the
|
|
426
|
+
* original HKDF seed (that derivation is one-way). Use these for
|
|
427
|
+
* persistence or cross-device transfer.
|
|
428
|
+
*
|
|
429
|
+
* @returns Two 32-byte Uint8Arrays or error.
|
|
430
|
+
*/
|
|
431
|
+
exportSeeds(): Promise<Result<{
|
|
432
|
+
ed25519: Uint8Array;
|
|
433
|
+
x25519: Uint8Array;
|
|
434
|
+
mlKemSecretKey?: Uint8Array;
|
|
435
|
+
mlKemPublicKey?: Uint8Array;
|
|
436
|
+
}, AgentError>>;
|
|
437
|
+
/**
|
|
438
|
+
* Split a cryptographic key into backup shares using XorIDA.
|
|
439
|
+
*
|
|
440
|
+
* Uses the agent's backup configuration (default: k=2, n=3).
|
|
441
|
+
* Any `threshold` shares can reconstruct the original key.
|
|
442
|
+
* Each share reveals zero information (information-theoretic security).
|
|
443
|
+
*
|
|
444
|
+
* @param key - The key to split (32 or 64 bytes typical).
|
|
445
|
+
* @returns Array of backup shares or error.
|
|
446
|
+
*
|
|
447
|
+
* @example
|
|
448
|
+
* ```typescript
|
|
449
|
+
* // Generate a key and split it
|
|
450
|
+
* const key = crypto.getRandomValues(new Uint8Array(32));
|
|
451
|
+
* const shares = await agent.splitKey(key);
|
|
452
|
+
*
|
|
453
|
+
* if (shares.ok) {
|
|
454
|
+
* // Store shares in separate locations
|
|
455
|
+
* shares.value.forEach((share, i) => {
|
|
456
|
+
* storeShare(`backup-${i}.json`, JSON.stringify(share));
|
|
457
|
+
* });
|
|
458
|
+
* }
|
|
459
|
+
* ```
|
|
460
|
+
*/
|
|
461
|
+
splitKey(key: Uint8Array): Promise<Result<import('./backup-config.js').BackupShare[], AgentError>>;
|
|
462
|
+
/**
|
|
463
|
+
* Reconstruct a cryptographic key from backup shares.
|
|
464
|
+
*
|
|
465
|
+
* Requires at least `threshold` shares. Verifies HMAC before returning
|
|
466
|
+
* the reconstructed key to prevent tampering.
|
|
467
|
+
*
|
|
468
|
+
* @param shares - Backup shares (must be >= threshold).
|
|
469
|
+
* @returns Reconstructed key or error.
|
|
470
|
+
*
|
|
471
|
+
* @example
|
|
472
|
+
* ```typescript
|
|
473
|
+
* // Load shares from storage
|
|
474
|
+
* const share0 = JSON.parse(loadShare('backup-0.json'));
|
|
475
|
+
* const share1 = JSON.parse(loadShare('backup-1.json'));
|
|
476
|
+
*
|
|
477
|
+
* // Reconstruct from any 2 shares (threshold=2)
|
|
478
|
+
* const key = await agent.reconstructKey([share0, share1]);
|
|
479
|
+
*
|
|
480
|
+
* if (key.ok) {
|
|
481
|
+
* // Use reconstructed key
|
|
482
|
+
* console.log('Key recovered:', key.value);
|
|
483
|
+
* }
|
|
484
|
+
* ```
|
|
485
|
+
*/
|
|
486
|
+
reconstructKey(shares: import('./backup-config.js').BackupShare[]): Promise<Result<Uint8Array, AgentError>>;
|
|
487
|
+
/**
|
|
488
|
+
* Verify a signed (unencrypted) envelope and return the message.
|
|
489
|
+
*
|
|
490
|
+
* Use for envelopes created with createSignedEnvelope().
|
|
491
|
+
* Verifies signature, timestamp, nonce, and scope — skips decryption.
|
|
492
|
+
*
|
|
493
|
+
* @param envelope - A signed (unencrypted) transport envelope.
|
|
494
|
+
* @returns Verified message or error with sub-code.
|
|
495
|
+
*/
|
|
496
|
+
receiveSigned(envelope: AnyTransportEnvelope): Promise<Result<AgentMessage, AgentError>>;
|
|
497
|
+
/**
|
|
498
|
+
* Discover available tools in the registry.
|
|
499
|
+
*
|
|
500
|
+
* Query xRegistry for tools matching the given service prefix or capability.
|
|
501
|
+
* Returns tool metadata including name, description, schema, and trust level.
|
|
502
|
+
*
|
|
503
|
+
* @param service - Optional service prefix to filter by (e.g., "payments")
|
|
504
|
+
* @returns Array of tool metadata or empty array if none found
|
|
505
|
+
*
|
|
506
|
+
* @example
|
|
507
|
+
* ```typescript
|
|
508
|
+
* import { Agent } from '@private.me/xbind';
|
|
509
|
+
* import { ToolRegistry } from '@private.me/xregistry';
|
|
510
|
+
* import { setToolRegistry } from '@private.me/xbind/agent-call';
|
|
511
|
+
*
|
|
512
|
+
* const registry = new ToolRegistry();
|
|
513
|
+
* registry.register({
|
|
514
|
+
* name: 'payments:createCharge',
|
|
515
|
+
* description: 'Create a payment charge',
|
|
516
|
+
* schema: { type: 'object', properties: { amount: { type: 'number' } } },
|
|
517
|
+
* trustLevel: 'verified',
|
|
518
|
+
* endpoint: 'https://api.stripe.com/v1/charges',
|
|
519
|
+
* capabilities: ['payment', 'charge']
|
|
520
|
+
* });
|
|
521
|
+
*
|
|
522
|
+
* setToolRegistry(registry);
|
|
523
|
+
*
|
|
524
|
+
* const agent = await Agent.quickstart();
|
|
525
|
+
*
|
|
526
|
+
* // Discover all payment tools
|
|
527
|
+
* const tools = await agent.discover('payments');
|
|
528
|
+
* console.log(tools); // [{ name: 'payments:createCharge', ... }]
|
|
529
|
+
*
|
|
530
|
+
* // Discover all tools
|
|
531
|
+
* const allTools = await agent.discover();
|
|
532
|
+
* ```
|
|
533
|
+
*/
|
|
534
|
+
discover(service?: string): Promise<readonly import('@private.me/xregistry').ToolMetadata[]>;
|
|
535
|
+
/** Generate an Express-compatible middleware handler. */
|
|
536
|
+
middleware(): (req: {
|
|
537
|
+
body?: unknown;
|
|
538
|
+
}, res: {
|
|
539
|
+
status: (code: number) => {
|
|
540
|
+
json: (data: unknown) => void;
|
|
541
|
+
};
|
|
542
|
+
}, next: (err?: unknown) => void) => Promise<void>;
|
|
543
|
+
/**
|
|
544
|
+
* Cleanup resources (timers, handlers, etc.)
|
|
545
|
+
*
|
|
546
|
+
* Call this in tests or when disposing an agent to prevent timer leaks.
|
|
547
|
+
* Clears the ephemeral identity auto-cleanup timer if present.
|
|
548
|
+
*/
|
|
549
|
+
cleanup(): void;
|
|
550
|
+
/**
|
|
551
|
+
* Dispose of agent resources (alias for cleanup)
|
|
552
|
+
*
|
|
553
|
+
* Provided for compatibility with test cleanup patterns.
|
|
554
|
+
*/
|
|
555
|
+
dispose(): void;
|
|
556
|
+
/**
|
|
557
|
+
* Attempt sender-side key agreement.
|
|
558
|
+
*
|
|
559
|
+
* If both sides support ML-KEM-768, uses hybrid (X25519 + ML-KEM-768).
|
|
560
|
+
* Otherwise falls back to X25519-only ECDH.
|
|
561
|
+
* Returns null if recipient has no X25519 key registered.
|
|
562
|
+
* Also returns whether recipient supports ML-DSA-65 for v3 envelopes.
|
|
563
|
+
*/
|
|
564
|
+
private trySenderECDH;
|
|
565
|
+
/** Send with ECDH forward secrecy (ephemeral key in envelope). */
|
|
566
|
+
private sendWithECDH;
|
|
567
|
+
/** Send with hybrid KEM (X25519 + ML-KEM-768) via v2 envelope. */
|
|
568
|
+
private sendWithHybrid;
|
|
569
|
+
/** Send with hybrid KEM + dual signatures via v3 envelope. */
|
|
570
|
+
private sendWithHybridV3;
|
|
571
|
+
private sendDirect;
|
|
572
|
+
/**
|
|
573
|
+
* Check whether the recipient supports Xchange (XorIDA key transport).
|
|
574
|
+
*
|
|
575
|
+
* @param recipientDid - Recipient DID to check.
|
|
576
|
+
* @returns True if recipient has xchange: true in registry.
|
|
577
|
+
*/
|
|
578
|
+
private canUseXchange;
|
|
579
|
+
/**
|
|
580
|
+
* Send via Xchange mode: random key + AES-GCM encrypt, bundle, XorIDA split, v4 envelopes.
|
|
581
|
+
*
|
|
582
|
+
* Opt-in performance mode. No KEM, no key agreement — the random key is
|
|
583
|
+
* embedded in the bundle and split across channels. Single security layer
|
|
584
|
+
* (information-theoretic) + Ed25519 authentication. ~180x faster than V3.
|
|
585
|
+
*/
|
|
586
|
+
private sendXchange;
|
|
587
|
+
/**
|
|
588
|
+
* Split plaintext via XorIDA and send each share as a separate V3 envelope.
|
|
589
|
+
*
|
|
590
|
+
* Default split-channel path with three independent cryptographic layers:
|
|
591
|
+
* XorIDA payload split, hybrid PQ KEM, and dual signatures.
|
|
592
|
+
* Returns ok() if at least threshold sends succeed.
|
|
593
|
+
*/
|
|
594
|
+
private sendSplitChannel;
|
|
595
|
+
/**
|
|
596
|
+
* Create and send an envelope for each share independently.
|
|
597
|
+
*
|
|
598
|
+
* Routes share[i] to transports[i % transports.length] for channel separation.
|
|
599
|
+
*/
|
|
600
|
+
private sendShareEnvelopes;
|
|
601
|
+
/**
|
|
602
|
+
* Receive and accumulate a split-channel share envelope.
|
|
603
|
+
*
|
|
604
|
+
* Verifies the envelope, extracts share metadata, accumulates shares.
|
|
605
|
+
* When threshold is reached, reconstructs the original plaintext.
|
|
606
|
+
*
|
|
607
|
+
* @param envelope - A share envelope with split-channel metadata
|
|
608
|
+
* @returns AgentMessage if threshold met, null if more shares needed
|
|
609
|
+
*/
|
|
610
|
+
receiveSplitShare(envelope: AnyTransportEnvelope): Promise<Result<AgentMessage | null, AgentError>>;
|
|
611
|
+
/**
|
|
612
|
+
* Receive and accumulate a v4 Xchange share envelope.
|
|
613
|
+
*
|
|
614
|
+
* Verifies Ed25519 signature, extracts raw share data (no decryption —
|
|
615
|
+
* the XorIDA share IS the payload). When threshold is reached,
|
|
616
|
+
* reconstructs and decrypts via Xchange.
|
|
617
|
+
*
|
|
618
|
+
* @param envelope - A v4 Xchange envelope with share metadata.
|
|
619
|
+
* @returns AgentMessage if threshold met, null if more shares needed.
|
|
620
|
+
*/
|
|
621
|
+
receiveXchangeShare(envelope: TransportEnvelopeV4): Promise<Result<AgentMessage | null, AgentError>>;
|
|
622
|
+
/**
|
|
623
|
+
* Accumulate a Xchange share and attempt reconstruction + decryption.
|
|
624
|
+
*
|
|
625
|
+
* When threshold is met:
|
|
626
|
+
* 1. Reconstruct padded bundle from XorIDA shares
|
|
627
|
+
* 2. Verify HMAC (BEFORE decrypt — CRITICAL)
|
|
628
|
+
* 3. Unpad → extract bundle → xchangeDecrypt → plaintext
|
|
629
|
+
*/
|
|
630
|
+
private accumulateXchangeShare;
|
|
631
|
+
/**
|
|
632
|
+
* Accumulate a share and attempt reconstruction when threshold is met.
|
|
633
|
+
*/
|
|
634
|
+
private accumulateShare;
|
|
635
|
+
/**
|
|
636
|
+
* Common envelope verification: version, timestamp, nonce, DID, signature, scope.
|
|
637
|
+
*
|
|
638
|
+
* Used by receive(), receiveSigned(), and receiveRaw() to avoid duplication.
|
|
639
|
+
* Consumes the nonce on success (replay prevention).
|
|
640
|
+
*/
|
|
641
|
+
private verifyEnvelope;
|
|
642
|
+
/**
|
|
643
|
+
* Verify and decrypt an envelope, returning raw text (no JSON parse).
|
|
644
|
+
* Used by receiveSplitShare to get the raw decrypted share data.
|
|
645
|
+
*/
|
|
646
|
+
private receiveRaw;
|
|
647
|
+
/**
|
|
648
|
+
* Send email invitation to establish connection.
|
|
649
|
+
*
|
|
650
|
+
* Uses email transport to send branded invitation with one-click acceptance.
|
|
651
|
+
* Requires EmailTransport to be configured in agent options.
|
|
652
|
+
*
|
|
653
|
+
* @param opts - Invitation options
|
|
654
|
+
* @returns Result with success status
|
|
655
|
+
*
|
|
656
|
+
* @example
|
|
657
|
+
* ```ts
|
|
658
|
+
* await agent.invite({
|
|
659
|
+
* to: 'fulfillment@acme.com',
|
|
660
|
+
* message: 'Connect our payment systems'
|
|
661
|
+
* });
|
|
662
|
+
* ```
|
|
663
|
+
*/
|
|
664
|
+
invite(opts: {
|
|
665
|
+
to: string;
|
|
666
|
+
message?: string;
|
|
667
|
+
template?: string;
|
|
668
|
+
}): Promise<Result<void, AgentError>>;
|
|
669
|
+
}
|
|
670
|
+
export { generateSharedKey };
|