@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,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RetryTransportAdapter = void 0;
|
|
4
|
+
/* ── Implementation ── */
|
|
5
|
+
/**
|
|
6
|
+
* Decorator that adds exponential backoff retry logic to any transport adapter.
|
|
7
|
+
*
|
|
8
|
+
* Retry delays follow exponential backoff with jitter:
|
|
9
|
+
* - Formula: 2^attempt * baseDelay + jitter
|
|
10
|
+
* - Jitter: Math.random() * maxJitter * 2 - maxJitter
|
|
11
|
+
* - Default delays: 1s, 2s, 4s (with ±200ms jitter)
|
|
12
|
+
*
|
|
13
|
+
* Use case: Push notification delivery failures requiring automatic retry.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const transport = new RetryTransportAdapter(baseTransport, {
|
|
18
|
+
* maxRetries: 3,
|
|
19
|
+
* baseDelayMs: 1000,
|
|
20
|
+
* maxJitterMs: 200
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
class RetryTransportAdapter {
|
|
25
|
+
inner;
|
|
26
|
+
maxRetries;
|
|
27
|
+
baseDelayMs;
|
|
28
|
+
maxJitterMs;
|
|
29
|
+
/**
|
|
30
|
+
* Create a new RetryTransportAdapter wrapping an existing transport.
|
|
31
|
+
*
|
|
32
|
+
* @param inner - The transport adapter to wrap with retry logic
|
|
33
|
+
* @param options - Retry configuration options
|
|
34
|
+
*/
|
|
35
|
+
constructor(inner, options = {}) {
|
|
36
|
+
this.inner = inner;
|
|
37
|
+
this.maxRetries = options.maxRetries ?? 3;
|
|
38
|
+
this.baseDelayMs = options.baseDelayMs ?? 1000;
|
|
39
|
+
this.maxJitterMs = options.maxJitterMs ?? 200;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Send an envelope with exponential backoff retry logic.
|
|
43
|
+
*
|
|
44
|
+
* Retries on all error types (SEND_FAILED, NETWORK_ERROR, RECIPIENT_UNREACHABLE, TIMEOUT).
|
|
45
|
+
* Throws error after all retries are exhausted.
|
|
46
|
+
*
|
|
47
|
+
* @param envelope - The envelope to send
|
|
48
|
+
* @param recipientDid - The recipient's DID
|
|
49
|
+
* @returns Result with void on success, or TransportError on failure
|
|
50
|
+
* @throws Error if all retry attempts are exhausted
|
|
51
|
+
*/
|
|
52
|
+
async send(envelope, recipientDid) {
|
|
53
|
+
let lastError;
|
|
54
|
+
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
55
|
+
const result = await this.inner.send(envelope, recipientDid);
|
|
56
|
+
// Success - return immediately
|
|
57
|
+
if (result.ok) {
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
// Store error for final throw
|
|
61
|
+
lastError = result.error;
|
|
62
|
+
// Don't delay after final attempt
|
|
63
|
+
if (attempt < this.maxRetries) {
|
|
64
|
+
// Exponential backoff: 2^attempt * baseDelay + jitter
|
|
65
|
+
const delay = Math.pow(2, attempt) * this.baseDelayMs;
|
|
66
|
+
// SAFETY: Using crypto.getRandomValues for OWASP-compliant secure random jitter
|
|
67
|
+
const jitterArray = new Uint32Array(1);
|
|
68
|
+
crypto.getRandomValues(jitterArray);
|
|
69
|
+
const jitter = (jitterArray[0] / 0xffffffff) * this.maxJitterMs * 2 -
|
|
70
|
+
this.maxJitterMs;
|
|
71
|
+
await this.sleep(delay + jitter);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// All retries exhausted - throw error with clear message
|
|
75
|
+
throw new Error(`Failed after ${this.maxRetries} retries: ${lastError ?? 'unknown error'}`);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Register a handler for incoming envelopes.
|
|
79
|
+
* Delegates directly to the inner transport.
|
|
80
|
+
*
|
|
81
|
+
* @param handler - The envelope handler function
|
|
82
|
+
*/
|
|
83
|
+
onReceive(handler) {
|
|
84
|
+
this.inner.onReceive(handler);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Shut down the transport.
|
|
88
|
+
* Delegates directly to the inner transport.
|
|
89
|
+
*/
|
|
90
|
+
dispose() {
|
|
91
|
+
this.inner.dispose();
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Sleep for a specified duration.
|
|
95
|
+
*
|
|
96
|
+
* @param ms - Duration in milliseconds
|
|
97
|
+
*/
|
|
98
|
+
sleep(ms) {
|
|
99
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.RetryTransportAdapter = RetryTransportAdapter;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Security policy interface for automatic risk-based Xorida activation.
|
|
4
|
+
*
|
|
5
|
+
* Determines when to apply information-theoretic security (XorIDA split-channel)
|
|
6
|
+
* vs standard encrypted transport based on action semantics and parameters.
|
|
7
|
+
*
|
|
8
|
+
* Design principle: Security should be invisible to users. The policy classifies
|
|
9
|
+
* risk automatically so developers don't need to understand threshold cryptography.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DefaultSecurityPolicy = void 0;
|
|
13
|
+
exports.describeSecurityMode = describeSecurityMode;
|
|
14
|
+
exports.describeSecurityModeStructured = describeSecurityModeStructured;
|
|
15
|
+
/**
|
|
16
|
+
* Default security policy for basic XBind.
|
|
17
|
+
*
|
|
18
|
+
* Rules:
|
|
19
|
+
* - Transfers over $100,000: High security (3 shares, 2-of-3 threshold)
|
|
20
|
+
* - Cross-entity communication: High security (3 shares, 2-of-3 threshold)
|
|
21
|
+
* - Explicit 'high' override: High security (3 shares, 2-of-3 threshold)
|
|
22
|
+
* - Explicit 'critical' override: Critical security (5 shares, 3-of-5 threshold)
|
|
23
|
+
* - Everything else: Standard encrypted transport (V3 hybrid PQ)
|
|
24
|
+
*
|
|
25
|
+
* Enterprise and Government variants extend this with custom rules.
|
|
26
|
+
*/
|
|
27
|
+
class DefaultSecurityPolicy {
|
|
28
|
+
options;
|
|
29
|
+
/**
|
|
30
|
+
* Create a default security policy.
|
|
31
|
+
*
|
|
32
|
+
* @param options - Optional configuration
|
|
33
|
+
* @param options.highValueThreshold - Amount threshold for high security (default: 100000)
|
|
34
|
+
* @param options.enableXchange - Allow Xchange mode for performance (default: false)
|
|
35
|
+
*/
|
|
36
|
+
constructor(options = {}) {
|
|
37
|
+
this.options = options;
|
|
38
|
+
}
|
|
39
|
+
classify(context) {
|
|
40
|
+
const { action, params, securityOverride } = context;
|
|
41
|
+
const threshold = this.options.highValueThreshold ?? 100_000;
|
|
42
|
+
// Explicit override: critical
|
|
43
|
+
if (securityOverride === 'critical') {
|
|
44
|
+
return {
|
|
45
|
+
mode: { type: 'split', shares: 5, threshold: 3 },
|
|
46
|
+
reason: 'User requested critical security level (5 shares, 3-of-5 threshold)',
|
|
47
|
+
wasOverridden: true,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// Explicit override: high
|
|
51
|
+
if (securityOverride === 'high') {
|
|
52
|
+
return {
|
|
53
|
+
mode: { type: 'split', shares: 3, threshold: 2 },
|
|
54
|
+
reason: 'User requested high security level (3 shares, 2-of-3 threshold)',
|
|
55
|
+
wasOverridden: true,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
// Explicit override: standard
|
|
59
|
+
if (securityOverride === 'standard') {
|
|
60
|
+
return {
|
|
61
|
+
mode: { type: 'standard' },
|
|
62
|
+
reason: 'User requested standard security level (encrypted transport)',
|
|
63
|
+
wasOverridden: true,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
// Auto-detection: High-value transfer
|
|
67
|
+
if ((action === 'transfer' || action === 'execute') &&
|
|
68
|
+
typeof params.amount === 'number' &&
|
|
69
|
+
params.amount > threshold) {
|
|
70
|
+
return {
|
|
71
|
+
mode: { type: 'split', shares: 3, threshold: 2 },
|
|
72
|
+
reason: `High-value transfer ($${params.amount.toLocaleString()}) requires multi-party approval (2 of 3)`,
|
|
73
|
+
wasOverridden: false,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
// Auto-detection: Cross-entity communication
|
|
77
|
+
if (params.crossEntity === true) {
|
|
78
|
+
return {
|
|
79
|
+
mode: { type: 'split', shares: 3, threshold: 2 },
|
|
80
|
+
reason: 'Cross-organization communication requires multi-party approval (2 of 3)',
|
|
81
|
+
wasOverridden: false,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
// Auto-detection: Sensitive scopes
|
|
85
|
+
if (context.scope.includes('admin') ||
|
|
86
|
+
context.scope.includes('custody') ||
|
|
87
|
+
context.scope.includes('settlement')) {
|
|
88
|
+
return {
|
|
89
|
+
mode: { type: 'split', shares: 3, threshold: 2 },
|
|
90
|
+
reason: `Sensitive scope "${context.scope}" requires multi-party approval (2 of 3)`,
|
|
91
|
+
wasOverridden: false,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
// Xchange mode: opt-in performance mode (if enabled)
|
|
95
|
+
if (this.options.enableXchange && params.xchange === true) {
|
|
96
|
+
return {
|
|
97
|
+
mode: { type: 'xchange' },
|
|
98
|
+
reason: 'Xchange mode enabled for performance (~180x faster)',
|
|
99
|
+
wasOverridden: false,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
// Default: Standard encrypted transport
|
|
103
|
+
return {
|
|
104
|
+
mode: { type: 'standard' },
|
|
105
|
+
reason: 'Standard encrypted transport (hybrid post-quantum)',
|
|
106
|
+
wasOverridden: false,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.DefaultSecurityPolicy = DefaultSecurityPolicy;
|
|
111
|
+
/**
|
|
112
|
+
* Get a human-readable security mode description.
|
|
113
|
+
*
|
|
114
|
+
* Used for logging and user feedback.
|
|
115
|
+
*
|
|
116
|
+
* @param mode - Security mode
|
|
117
|
+
* @returns User-friendly description
|
|
118
|
+
*
|
|
119
|
+
* @deprecated Use describeSecurityModeStructured() for new code. This function remains for backward compatibility.
|
|
120
|
+
*/
|
|
121
|
+
function describeSecurityMode(mode) {
|
|
122
|
+
switch (mode.type) {
|
|
123
|
+
case 'standard':
|
|
124
|
+
return 'Standard (encrypted)';
|
|
125
|
+
case 'split':
|
|
126
|
+
return `Multi-party approval (${mode.threshold} of ${mode.shares})`;
|
|
127
|
+
case 'xchange':
|
|
128
|
+
return 'Xchange (fast mode)';
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Get a structured security mode description with multiple formats.
|
|
133
|
+
*
|
|
134
|
+
* Returns an object with the security classification and formatted descriptions
|
|
135
|
+
* optimized for different use cases (display, logging, APIs, docs).
|
|
136
|
+
*
|
|
137
|
+
* @param mode - Security mode
|
|
138
|
+
* @returns Security mode description with formats
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const mode: SecurityMode = { type: 'split', shares: 3, threshold: 2 };
|
|
143
|
+
* const description = describeSecurityModeStructured(mode);
|
|
144
|
+
*
|
|
145
|
+
* console.log(description.formats.singleline);
|
|
146
|
+
* // "high | split | 2-of-3"
|
|
147
|
+
*
|
|
148
|
+
* console.log(description.formats.multiline);
|
|
149
|
+
* // "Security Level: High
|
|
150
|
+
* // Mode: Split-channel (XorIDA)
|
|
151
|
+
* // Shares: 3 total, 2 required"
|
|
152
|
+
*
|
|
153
|
+
* console.log(description.shares);
|
|
154
|
+
* // { total: 3, threshold: 2 }
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
function describeSecurityModeStructured(mode) {
|
|
158
|
+
let level;
|
|
159
|
+
let multiline;
|
|
160
|
+
let singleline;
|
|
161
|
+
let markdown;
|
|
162
|
+
let shares;
|
|
163
|
+
switch (mode.type) {
|
|
164
|
+
case 'standard':
|
|
165
|
+
level = 'standard';
|
|
166
|
+
multiline = 'Security Level: Standard\nMode: Encrypted transport (hybrid post-quantum)';
|
|
167
|
+
singleline = 'standard | encrypted';
|
|
168
|
+
markdown = '**Security Level:** Standard\n\n**Mode:** Encrypted transport (hybrid post-quantum)';
|
|
169
|
+
break;
|
|
170
|
+
case 'split':
|
|
171
|
+
// Classify split mode as high or critical based on threshold
|
|
172
|
+
level = mode.shares >= 5 ? 'critical' : 'high';
|
|
173
|
+
shares = { total: mode.shares, threshold: mode.threshold };
|
|
174
|
+
multiline = `Security Level: ${level === 'critical' ? 'Critical' : 'High'}\nMode: Split-channel (XorIDA)\nShares: ${mode.shares} total, ${mode.threshold} required`;
|
|
175
|
+
singleline = `${level} | split | ${mode.threshold}-of-${mode.shares}`;
|
|
176
|
+
markdown = `**Security Level:** ${level === 'critical' ? 'Critical' : 'High'}\n\n**Mode:** Split-channel (XorIDA)\n\n**Shares:** ${mode.shares} total, ${mode.threshold} required`;
|
|
177
|
+
break;
|
|
178
|
+
case 'xchange':
|
|
179
|
+
level = 'performance';
|
|
180
|
+
multiline = 'Security Level: Performance\nMode: Xchange (single IT layer, ~180x faster)';
|
|
181
|
+
singleline = 'performance | xchange';
|
|
182
|
+
markdown = '**Security Level:** Performance\n\n**Mode:** Xchange (single IT layer, ~180x faster)';
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
const jsonObj = {
|
|
186
|
+
type: mode.type,
|
|
187
|
+
level,
|
|
188
|
+
};
|
|
189
|
+
if (shares) {
|
|
190
|
+
jsonObj.shares = shares;
|
|
191
|
+
}
|
|
192
|
+
const json = JSON.stringify(jsonObj);
|
|
193
|
+
return {
|
|
194
|
+
type: mode.type,
|
|
195
|
+
level,
|
|
196
|
+
shares,
|
|
197
|
+
formats: {
|
|
198
|
+
multiline,
|
|
199
|
+
singleline,
|
|
200
|
+
json,
|
|
201
|
+
markdown,
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* XorIDA split-channel bridge for @private.me/xbind.
|
|
4
|
+
*
|
|
5
|
+
* Bridges @private.me/crypto threshold sharing with the agent-sdk
|
|
6
|
+
* TransportEnvelope format. Splits plaintext into n shares with HMAC
|
|
7
|
+
* integrity, each share wrapped in its own envelope for independent routing.
|
|
8
|
+
*
|
|
9
|
+
* Pipeline:
|
|
10
|
+
* split: pad -> HMAC -> XorIDA split -> share Uint8Arrays with metadata
|
|
11
|
+
* reconstruct: collect k shares -> XorIDA reconstruct -> HMAC verify -> unpad
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.DEFAULT_SPLIT_CONFIG = void 0;
|
|
15
|
+
exports.splitForChannel = splitForChannel;
|
|
16
|
+
exports.splitForChannelWithGroupId = splitForChannelWithGroupId;
|
|
17
|
+
exports.reconstructFromChannel = reconstructFromChannel;
|
|
18
|
+
const shared_1 = require("../_deps/shared/index.js");
|
|
19
|
+
const crypto_1 = require("../_deps/crypto/index.js");
|
|
20
|
+
/** Default split-channel configuration: 3 shares, threshold 2. */
|
|
21
|
+
exports.DEFAULT_SPLIT_CONFIG = {
|
|
22
|
+
totalShares: 3,
|
|
23
|
+
threshold: 2,
|
|
24
|
+
};
|
|
25
|
+
/* ── Split ── */
|
|
26
|
+
/**
|
|
27
|
+
* Split plaintext into n shares via XorIDA with HMAC integrity.
|
|
28
|
+
*
|
|
29
|
+
* Pipeline: pad(PKCS#7) -> HMAC(padded) -> XorIDA split -> ChannelShare[]
|
|
30
|
+
*
|
|
31
|
+
* @param plaintext - Raw plaintext bytes to split
|
|
32
|
+
* @param config - Split configuration (totalShares, threshold)
|
|
33
|
+
* @returns Array of n ChannelShare objects ready for envelope wrapping
|
|
34
|
+
*/
|
|
35
|
+
async function splitForChannel(plaintext, config = exports.DEFAULT_SPLIT_CONFIG) {
|
|
36
|
+
const { totalShares: n, threshold: k } = config;
|
|
37
|
+
if (n < 2 || k < 2 || k > n) {
|
|
38
|
+
return (0, shared_1.err)('SPLIT_FAILED:INVALID_PARAMS');
|
|
39
|
+
}
|
|
40
|
+
const groupId = (0, crypto_1.generateUUID)();
|
|
41
|
+
return splitForChannelWithGroupId(plaintext, config, groupId);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Split plaintext with a specific groupId (for testability).
|
|
45
|
+
*
|
|
46
|
+
* @param plaintext - Raw plaintext bytes
|
|
47
|
+
* @param config - Split configuration
|
|
48
|
+
* @param groupId - UUID to use for the share group
|
|
49
|
+
* @returns Array of ChannelShare objects
|
|
50
|
+
*/
|
|
51
|
+
async function splitForChannelWithGroupId(plaintext, config, groupId) {
|
|
52
|
+
const { totalShares: n, threshold: k } = config;
|
|
53
|
+
if (n < 2 || k < 2 || k > n) {
|
|
54
|
+
return (0, shared_1.err)('SPLIT_FAILED:INVALID_PARAMS');
|
|
55
|
+
}
|
|
56
|
+
const p = (0, crypto_1.nextOddPrime)(n);
|
|
57
|
+
const blockSize = p - 1;
|
|
58
|
+
const padded = (0, crypto_1.pkcs7Pad)(plaintext, blockSize);
|
|
59
|
+
const { key: hmacKey, signature: hmacSig } = await (0, crypto_1.generateHMAC)(padded);
|
|
60
|
+
let shareArrays;
|
|
61
|
+
try {
|
|
62
|
+
shareArrays = (0, crypto_1.splitXorIDA)(padded, n, k);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return (0, shared_1.err)('SPLIT_FAILED');
|
|
66
|
+
}
|
|
67
|
+
const hmacKeyB64 = (0, crypto_1.toBase64)(hmacKey);
|
|
68
|
+
const hmacSigB64 = (0, crypto_1.toBase64)(hmacSig);
|
|
69
|
+
const shares = shareArrays.map((data, index) => ({
|
|
70
|
+
data: (0, crypto_1.formatShareHeader)((0, crypto_1.toBase64)(data)),
|
|
71
|
+
index,
|
|
72
|
+
total: n,
|
|
73
|
+
threshold: k,
|
|
74
|
+
groupId,
|
|
75
|
+
hmacKey: hmacKeyB64,
|
|
76
|
+
hmacSig: hmacSigB64,
|
|
77
|
+
}));
|
|
78
|
+
return (0, shared_1.ok)(shares);
|
|
79
|
+
}
|
|
80
|
+
/* ── Reconstruct ── */
|
|
81
|
+
/**
|
|
82
|
+
* Reconstruct plaintext from k-of-n shares.
|
|
83
|
+
*
|
|
84
|
+
* Pipeline: validate -> XorIDA reconstruct -> HMAC verify -> unpad -> plaintext
|
|
85
|
+
* HMAC verification happens BEFORE the data is trusted.
|
|
86
|
+
*
|
|
87
|
+
* @param shares - Array of at least k ChannelShare objects
|
|
88
|
+
* @returns Reconstructed plaintext bytes
|
|
89
|
+
*/
|
|
90
|
+
async function reconstructFromChannel(shares) {
|
|
91
|
+
const validationResult = validateShares(shares);
|
|
92
|
+
if (!validationResult.ok)
|
|
93
|
+
return validationResult;
|
|
94
|
+
const { k, n } = validationResult.value;
|
|
95
|
+
const usedShares = shares.slice(0, k);
|
|
96
|
+
return reconstructValidated(usedShares, n, k);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Validate share consistency before reconstruction.
|
|
100
|
+
*
|
|
101
|
+
* @param shares - Shares to validate
|
|
102
|
+
* @returns Validated parameters or error
|
|
103
|
+
*/
|
|
104
|
+
function validateShares(shares) {
|
|
105
|
+
if (shares.length === 0) {
|
|
106
|
+
return (0, shared_1.err)('INSUFFICIENT_SHARES');
|
|
107
|
+
}
|
|
108
|
+
const first = shares[0];
|
|
109
|
+
const k = first.threshold;
|
|
110
|
+
const n = first.total;
|
|
111
|
+
if (shares.length < k) {
|
|
112
|
+
return (0, shared_1.err)('INSUFFICIENT_SHARES');
|
|
113
|
+
}
|
|
114
|
+
const indexSet = new Set();
|
|
115
|
+
for (const share of shares) {
|
|
116
|
+
if (share.groupId !== first.groupId) {
|
|
117
|
+
return (0, shared_1.err)('INCONSISTENT_SHARES');
|
|
118
|
+
}
|
|
119
|
+
if (share.total !== n || share.threshold !== k) {
|
|
120
|
+
return (0, shared_1.err)('INCONSISTENT_SHARES');
|
|
121
|
+
}
|
|
122
|
+
if (share.index < 0 || share.index >= n) {
|
|
123
|
+
return (0, shared_1.err)('INVALID_SHARE_DATA');
|
|
124
|
+
}
|
|
125
|
+
if (indexSet.has(share.index)) {
|
|
126
|
+
return (0, shared_1.err)('INVALID_SHARE_DATA');
|
|
127
|
+
}
|
|
128
|
+
indexSet.add(share.index);
|
|
129
|
+
}
|
|
130
|
+
return (0, shared_1.ok)({ k, n, groupId: first.groupId });
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Perform XorIDA reconstruction and HMAC verification.
|
|
134
|
+
*
|
|
135
|
+
* @param usedShares - Exactly k validated shares
|
|
136
|
+
* @param n - Total shares
|
|
137
|
+
* @param k - Threshold
|
|
138
|
+
* @returns Reconstructed plaintext
|
|
139
|
+
*/
|
|
140
|
+
async function reconstructValidated(usedShares, n, k) {
|
|
141
|
+
let shareData;
|
|
142
|
+
try {
|
|
143
|
+
shareData = usedShares.map((s) => (0, crypto_1.fromBase64)((0, crypto_1.parseShareHeader)(s.data)));
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
return (0, shared_1.err)('INVALID_SHARE_DATA:BASE64');
|
|
147
|
+
}
|
|
148
|
+
const indices = usedShares.map((s) => s.index);
|
|
149
|
+
let padded;
|
|
150
|
+
try {
|
|
151
|
+
padded = (0, crypto_1.reconstructXorIDA)(shareData, indices, n, k);
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
return (0, shared_1.err)('SPLIT_FAILED:RECONSTRUCT');
|
|
155
|
+
}
|
|
156
|
+
const first = usedShares[0];
|
|
157
|
+
let hmacKey;
|
|
158
|
+
let hmacSig;
|
|
159
|
+
try {
|
|
160
|
+
hmacKey = (0, crypto_1.fromBase64)(first.hmacKey);
|
|
161
|
+
hmacSig = (0, crypto_1.fromBase64)(first.hmacSig);
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return (0, shared_1.err)('INVALID_SHARE_DATA:HMAC_DECODE');
|
|
165
|
+
}
|
|
166
|
+
const hmacValid = await (0, crypto_1.verifyHMAC)(hmacKey, padded, hmacSig);
|
|
167
|
+
if (!hmacValid) {
|
|
168
|
+
return (0, shared_1.err)('HMAC_VERIFICATION_FAILED');
|
|
169
|
+
}
|
|
170
|
+
const p = (0, crypto_1.nextOddPrime)(n);
|
|
171
|
+
const blockSize = p - 1;
|
|
172
|
+
const unpadResult = (0, crypto_1.pkcs7Unpad)(padded, blockSize);
|
|
173
|
+
if (!unpadResult.ok) {
|
|
174
|
+
return (0, shared_1.err)('UNPAD_FAILED');
|
|
175
|
+
}
|
|
176
|
+
return (0, shared_1.ok)(unpadResult.value);
|
|
177
|
+
}
|