@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,548 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module errors
|
|
3
|
+
* Named error class hierarchy for xBind agent-sdk.
|
|
4
|
+
*
|
|
5
|
+
* These classes are supplementary — existing `Result<T, E>` string codes are
|
|
6
|
+
* unchanged. Use `toXBindError()` to convert a string error code into a
|
|
7
|
+
* class-based error for try/catch consumers.
|
|
8
|
+
*/
|
|
9
|
+
import { createDetailedError } from"./_deps/ux-helpers/index.js";
|
|
10
|
+
const DOC_BASE = 'https://private.me/docs/xbind';
|
|
11
|
+
/** Base error class for all XBind errors. */
|
|
12
|
+
export class XBindError extends Error {
|
|
13
|
+
/** Machine-readable error code matching the Result<T,E> string unions. */
|
|
14
|
+
code;
|
|
15
|
+
/** Sub-code parsed from colon-separated codes (e.g. 'DECRYPTION' from 'DECRYPT_FAILED:DECRYPTION'). */
|
|
16
|
+
subCode;
|
|
17
|
+
/** URL to relevant documentation for this error. */
|
|
18
|
+
docUrl;
|
|
19
|
+
constructor(code, message, docUrl) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.name = 'XBindError';
|
|
22
|
+
const parts = code.split(':');
|
|
23
|
+
this.code = parts[0] ?? code;
|
|
24
|
+
this.subCode = parts.length > 1 ? parts.slice(1).join(':') : undefined;
|
|
25
|
+
this.docUrl = docUrl;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Ed25519/X25519 identity errors (keygen, sign, verify, DID, import/export). */
|
|
29
|
+
export class XBindIdentityError extends XBindError {
|
|
30
|
+
constructor(code, message) {
|
|
31
|
+
super(code, message, `${DOC_BASE}#identity`);
|
|
32
|
+
this.name = 'XBindIdentityError';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** Envelope creation, encryption, decryption, and parsing errors. */
|
|
36
|
+
export class XBindEnvelopeError extends XBindError {
|
|
37
|
+
constructor(code, message) {
|
|
38
|
+
super(code, message, `${DOC_BASE}#envelope`);
|
|
39
|
+
this.name = 'XBindEnvelopeError';
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** Transport-layer errors (send failures, network, timeouts). */
|
|
43
|
+
export class XBindTransportError extends XBindError {
|
|
44
|
+
constructor(code, message) {
|
|
45
|
+
super(code, message, `${DOC_BASE}#transport`);
|
|
46
|
+
this.name = 'XBindTransportError';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Trust registry errors (lookup, registration, revocation). */
|
|
50
|
+
export class XBindRegistryError extends XBindError {
|
|
51
|
+
constructor(code, message) {
|
|
52
|
+
super(code, message, `${DOC_BASE}#registry`);
|
|
53
|
+
this.name = 'XBindRegistryError';
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** X25519 ECDH key agreement errors. */
|
|
57
|
+
export class XBindKeyAgreementError extends XBindError {
|
|
58
|
+
constructor(code, message) {
|
|
59
|
+
super(code, message, `${DOC_BASE}#key-agreement`);
|
|
60
|
+
this.name = 'XBindKeyAgreementError';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** XorIDA split-channel errors (split, reconstruct, HMAC, shares). */
|
|
64
|
+
export class XBindSplitChannelError extends XBindError {
|
|
65
|
+
constructor(code, message) {
|
|
66
|
+
super(code, message, `${DOC_BASE}#split-channel`);
|
|
67
|
+
this.name = 'XBindSplitChannelError';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** High-level Agent errors (wraps subsystem errors with context). */
|
|
71
|
+
export class XBindAgentError extends XBindError {
|
|
72
|
+
constructor(code, message) {
|
|
73
|
+
super(code, message, `${DOC_BASE}#agent`);
|
|
74
|
+
this.name = 'XBindAgentError';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Create detailed error information for a given error code.
|
|
79
|
+
*
|
|
80
|
+
* @param code - Error code (e.g., 'INVALID_DID')
|
|
81
|
+
* @param additionalContext - Optional context (field name, custom hint)
|
|
82
|
+
* @returns ACIErrorDetail with code, message, hint, field, and docs
|
|
83
|
+
*/
|
|
84
|
+
export function createXBindErrorDetail(code, additionalContext) {
|
|
85
|
+
const baseCode = code.split(':')[0] ?? code;
|
|
86
|
+
const entry = ERROR_DETAILS[baseCode];
|
|
87
|
+
if (entry) {
|
|
88
|
+
return createDetailedError(code, entry.message, {
|
|
89
|
+
hint: additionalContext?.hint ?? entry.hint,
|
|
90
|
+
field: additionalContext?.field ?? entry.field,
|
|
91
|
+
docs: entry.docs,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
// Fallback for unknown codes
|
|
95
|
+
return createDetailedError(code, `XBind error: ${code}`, {
|
|
96
|
+
docs: DOC_BASE,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/** Detailed error information for each error code. */
|
|
100
|
+
const ERROR_DETAILS = {
|
|
101
|
+
// Identity
|
|
102
|
+
KEYGEN_FAILED: {
|
|
103
|
+
message: 'Key generation failed',
|
|
104
|
+
hint: 'Actions: (1) Verify Web Crypto API available (browser/Node.js 15+), (2) Check security context (HTTPS or localhost), (3) Retry operation',
|
|
105
|
+
suggested_action: 'Verify runtime environment supports Web Crypto API and retry key generation',
|
|
106
|
+
severity: 'critical',
|
|
107
|
+
docs: `${DOC_BASE}#identity`,
|
|
108
|
+
},
|
|
109
|
+
SIGN_FAILED: {
|
|
110
|
+
message: 'Signing failed',
|
|
111
|
+
hint: 'Actions: (1) Verify private key is valid and not corrupted, (2) Check key format (must be PKCS8), (3) Ensure key was properly imported',
|
|
112
|
+
suggested_action: 'Verify private key is valid and properly imported with extractable flag',
|
|
113
|
+
severity: 'high',
|
|
114
|
+
docs: `${DOC_BASE}#identity`,
|
|
115
|
+
},
|
|
116
|
+
VERIFY_FAILED: {
|
|
117
|
+
message: 'Signature verification failed',
|
|
118
|
+
hint: 'Actions: (1) Verify public key matches sender, (2) Check message integrity (not truncated/modified), (3) Confirm signature format is valid base64',
|
|
119
|
+
suggested_action: 'Verify sender public key and message integrity before retrying',
|
|
120
|
+
severity: 'critical',
|
|
121
|
+
docs: `${DOC_BASE}#identity`,
|
|
122
|
+
},
|
|
123
|
+
INVALID_DID: {
|
|
124
|
+
message: 'DID format is invalid',
|
|
125
|
+
hint: 'Actions: (1) Verify DID starts with "did:" prefix, (2) Check method is valid (e.g., did:key:z6Mk...), (3) Use validateDID() helper before processing',
|
|
126
|
+
field: 'did',
|
|
127
|
+
suggested_action: 'Use validateDID() helper to verify format before processing',
|
|
128
|
+
severity: 'high',
|
|
129
|
+
docs: `${DOC_BASE}#identity`,
|
|
130
|
+
},
|
|
131
|
+
INVALID_KEY_LENGTH: {
|
|
132
|
+
message: 'Key material has incorrect length',
|
|
133
|
+
hint: 'Actions: (1) Verify X25519 key is exactly 32 bytes, (2) Check base64 decoding result, (3) Log key.length to confirm size mismatch',
|
|
134
|
+
suggested_action: 'Verify key is exactly 32 bytes and properly base64-decoded',
|
|
135
|
+
severity: 'high',
|
|
136
|
+
docs: `${DOC_BASE}#key-agreement`,
|
|
137
|
+
},
|
|
138
|
+
EXPORT_FAILED: {
|
|
139
|
+
message: 'PKCS8 export failed',
|
|
140
|
+
hint: 'Actions: (1) Verify key was created with extractable:true, (2) Check browser/Node.js supports PKCS8 export, (3) Use Web Crypto API docs: https://mdn.io/SubtleCrypto.exportKey',
|
|
141
|
+
suggested_action: 'Create key with extractable:true flag and verify Web Crypto API support',
|
|
142
|
+
severity: 'medium',
|
|
143
|
+
docs: `${DOC_BASE}#identity`,
|
|
144
|
+
},
|
|
145
|
+
IMPORT_FAILED: {
|
|
146
|
+
message: 'PKCS8 import failed',
|
|
147
|
+
hint: 'Actions: (1) Validate PKCS8 format (PEM or raw bytes), (2) Decode base64 if needed, (3) Check algorithm matches (Ed25519/X25519), (4) Verify key data is not corrupted',
|
|
148
|
+
suggested_action: 'Validate PKCS8 format and verify key data is not corrupted',
|
|
149
|
+
severity: 'high',
|
|
150
|
+
docs: `${DOC_BASE}#identity`,
|
|
151
|
+
},
|
|
152
|
+
// Envelope
|
|
153
|
+
INVALID_VERSION: {
|
|
154
|
+
message: 'Unsupported envelope version',
|
|
155
|
+
hint: 'Actions: (1) Check envelope.version field, (2) Verify sender uses compatible version (v1-v4 supported), (3) Update SDK or request sender upgrade',
|
|
156
|
+
field: 'version',
|
|
157
|
+
suggested_action: 'Update SDK or request sender to use compatible version (v1-v4)',
|
|
158
|
+
severity: 'high',
|
|
159
|
+
docs: `${DOC_BASE}#envelope`,
|
|
160
|
+
},
|
|
161
|
+
INVALID_ALG: {
|
|
162
|
+
message: 'Unknown encryption algorithm',
|
|
163
|
+
hint: 'Actions: (1) Verify envelope.alg === "AES-256-GCM", (2) Check sender uses correct algorithm, (3) Log algorithm value to confirm mismatch',
|
|
164
|
+
field: 'alg',
|
|
165
|
+
suggested_action: 'Verify sender uses AES-256-GCM algorithm',
|
|
166
|
+
severity: 'high',
|
|
167
|
+
docs: `${DOC_BASE}#envelope`,
|
|
168
|
+
},
|
|
169
|
+
INVALID_NONCE: {
|
|
170
|
+
message: 'Nonce is missing or invalid',
|
|
171
|
+
hint: 'Actions: (1) Verify nonce exists and is 12 bytes, (2) Check base64 decoding, (3) Ensure nonce is unique per envelope (check replay buffer)',
|
|
172
|
+
field: 'nonce',
|
|
173
|
+
suggested_action: 'Verify nonce is 12 bytes and properly base64-encoded',
|
|
174
|
+
severity: 'critical',
|
|
175
|
+
docs: `${DOC_BASE}#envelope`,
|
|
176
|
+
},
|
|
177
|
+
INVALID_FIELDS: {
|
|
178
|
+
message: 'Required envelope fields are missing',
|
|
179
|
+
hint: 'Actions: (1) Verify sender/recipient DIDs present, (2) Check payload is not empty, (3) Validate envelope has: version, alg, nonce, ciphertext, tag',
|
|
180
|
+
suggested_action: 'Validate all required envelope fields are present',
|
|
181
|
+
severity: 'high',
|
|
182
|
+
docs: `${DOC_BASE}#envelope`,
|
|
183
|
+
},
|
|
184
|
+
ENCRYPT_FAILED: {
|
|
185
|
+
message: 'AES-256-GCM encryption failed',
|
|
186
|
+
hint: 'Actions: (1) Verify shared key is exactly 32 bytes, (2) Check plaintext is valid UTF-8, (3) Ensure nonce is 12 bytes, (4) Review Web Crypto error details',
|
|
187
|
+
suggested_action: 'Verify key is 32 bytes and nonce is 12 bytes before encryption',
|
|
188
|
+
severity: 'high',
|
|
189
|
+
docs: `${DOC_BASE}#envelope`,
|
|
190
|
+
},
|
|
191
|
+
DECRYPT_FAILED: {
|
|
192
|
+
message: 'Decryption failed',
|
|
193
|
+
hint: 'Actions: (1) Verify correct key is being used, (2) Check ciphertext integrity (not truncated), (3) Confirm authentication tag is valid, (4) Verify sender used same algorithm',
|
|
194
|
+
suggested_action: 'Verify correct key and check ciphertext integrity',
|
|
195
|
+
severity: 'critical',
|
|
196
|
+
docs: `${DOC_BASE}#envelope`,
|
|
197
|
+
},
|
|
198
|
+
PARSE_FAILED: {
|
|
199
|
+
message: 'Envelope deserialization failed',
|
|
200
|
+
hint: 'Actions: (1) Validate JSON structure, (2) Check for truncation or corruption in data, (3) Verify base64 encoding of nested fields, (4) Use JSON.parse() to identify syntax error',
|
|
201
|
+
suggested_action: 'Validate JSON structure and check for data corruption',
|
|
202
|
+
severity: 'high',
|
|
203
|
+
docs: `${DOC_BASE}#envelope`,
|
|
204
|
+
},
|
|
205
|
+
// Transport
|
|
206
|
+
SEND_FAILED: {
|
|
207
|
+
message: 'Message send failed',
|
|
208
|
+
hint: 'Actions: (1) Check network connectivity (ping registry), (2) Verify recipient email is valid, (3) Confirm recipient is registered in trust registry, (4) Retry with exponential backoff',
|
|
209
|
+
suggested_action: 'Check network connectivity and retry with exponential backoff',
|
|
210
|
+
severity: 'high',
|
|
211
|
+
docs: `${DOC_BASE}#transport`,
|
|
212
|
+
},
|
|
213
|
+
NETWORK_ERROR: {
|
|
214
|
+
message: 'Network request failed',
|
|
215
|
+
hint: 'Actions: (1) Verify internet connection, (2) Check DNS resolution, (3) Try pinging registry endpoint, (4) Implement retry with exponential backoff (2s, 4s, 8s)',
|
|
216
|
+
suggested_action: 'Verify internet connection and implement exponential backoff retry',
|
|
217
|
+
severity: 'high',
|
|
218
|
+
docs: `${DOC_BASE}#transport`,
|
|
219
|
+
},
|
|
220
|
+
RECIPIENT_UNREACHABLE: {
|
|
221
|
+
message: 'Recipient is unreachable',
|
|
222
|
+
hint: 'Actions: (1) Verify recipient email address is spelled correctly, (2) Check if recipient is registered with xBind, (3) Confirm recipient is online, (4) Ask recipient to check their registration status',
|
|
223
|
+
field: 'to',
|
|
224
|
+
suggested_action: 'Verify recipient is registered with xBind and online',
|
|
225
|
+
severity: 'medium',
|
|
226
|
+
docs: `${DOC_BASE}#transport`,
|
|
227
|
+
},
|
|
228
|
+
TIMEOUT: {
|
|
229
|
+
message: 'Transport operation timed out',
|
|
230
|
+
hint: 'Actions: (1) Increase timeout threshold (default: 30s), (2) Check network latency (ping registry), (3) Retry operation, (4) Verify registry is responsive',
|
|
231
|
+
suggested_action: 'Increase timeout threshold and check network latency',
|
|
232
|
+
severity: 'medium',
|
|
233
|
+
docs: `${DOC_BASE}#transport`,
|
|
234
|
+
},
|
|
235
|
+
// Registry
|
|
236
|
+
NOT_FOUND: {
|
|
237
|
+
message: 'Agent not found in trust registry',
|
|
238
|
+
hint: 'Actions: (1) Ask recipient to join XBind and register, (2) Verify recipient email is correct, (3) Query registry with recipient DID/email, (4) Check registration timestamp on recipient side',
|
|
239
|
+
field: 'to',
|
|
240
|
+
suggested_action: 'Ask recipient to register with xBind',
|
|
241
|
+
severity: 'medium',
|
|
242
|
+
docs: `${DOC_BASE}#registry`,
|
|
243
|
+
},
|
|
244
|
+
ALREADY_REGISTERED: {
|
|
245
|
+
message: 'Agent is already registered',
|
|
246
|
+
hint: 'Actions: (1) Use updateAgent() instead of registerAgent(), (2) Provide new public keys or metadata, (3) Verify DID matches existing registration, (4) Check for duplicate registrations',
|
|
247
|
+
suggested_action: 'Use updateAgent() instead of registerAgent()',
|
|
248
|
+
severity: 'low',
|
|
249
|
+
docs: `${DOC_BASE}#registry`,
|
|
250
|
+
},
|
|
251
|
+
REVOKED: {
|
|
252
|
+
message: 'Agent has been revoked from the registry',
|
|
253
|
+
hint: 'Actions: (1) Contact registry administrator, (2) Check revocation timestamp and reason, (3) Request re-registration if revocation was accidental, (4) Verify agent identity with admin',
|
|
254
|
+
suggested_action: 'Contact registry administrator to resolve revocation',
|
|
255
|
+
severity: 'high',
|
|
256
|
+
docs: `${DOC_BASE}#registry`,
|
|
257
|
+
},
|
|
258
|
+
// Key agreement
|
|
259
|
+
DERIVE_FAILED: {
|
|
260
|
+
message: 'ECDH key derivation failed',
|
|
261
|
+
hint: 'Actions: (1) Verify peer public key is valid X25519 (32 bytes), (2) Check key is not corrupted, (3) Confirm algorithm is X25519 ECDH, (4) Review Web Crypto error details',
|
|
262
|
+
suggested_action: 'Verify peer public key is valid X25519 and not corrupted',
|
|
263
|
+
severity: 'high',
|
|
264
|
+
docs: `${DOC_BASE}#key-agreement`,
|
|
265
|
+
},
|
|
266
|
+
KEM_ENCAPSULATE_FAILED: {
|
|
267
|
+
message: 'ML-KEM-768 encapsulation failed',
|
|
268
|
+
hint: 'Actions: (1) Verify recipient public key is valid ML-KEM-768, (2) Check key encoding (must be valid format), (3) Confirm post-quantum support enabled, (4) Validate key length and structure',
|
|
269
|
+
suggested_action: 'Verify recipient ML-KEM-768 public key and post-quantum support',
|
|
270
|
+
severity: 'high',
|
|
271
|
+
docs: `${DOC_BASE}#key-agreement`,
|
|
272
|
+
},
|
|
273
|
+
KEM_DECAPSULATE_FAILED: {
|
|
274
|
+
message: 'ML-KEM-768 decapsulation failed',
|
|
275
|
+
hint: 'Actions: (1) Verify ciphertext integrity (not truncated), (2) Check secret key is valid, (3) Confirm ciphertext matches secret key, (4) Verify ML-KEM library is initialized',
|
|
276
|
+
suggested_action: 'Verify ciphertext integrity and ML-KEM secret key',
|
|
277
|
+
severity: 'high',
|
|
278
|
+
docs: `${DOC_BASE}#key-agreement`,
|
|
279
|
+
},
|
|
280
|
+
HKDF_FAILED: {
|
|
281
|
+
message: 'HKDF key derivation failed',
|
|
282
|
+
hint: 'Actions: (1) Verify both ECDH and KEM shared secrets are valid, (2) Check HKDF input size, (3) Ensure hash algorithm (SHA-256) is available, (4) Review Web Crypto HKDF implementation',
|
|
283
|
+
suggested_action: 'Verify shared secrets are valid and SHA-256 is available',
|
|
284
|
+
severity: 'high',
|
|
285
|
+
docs: `${DOC_BASE}#key-agreement`,
|
|
286
|
+
},
|
|
287
|
+
MLKEM_NOT_AVAILABLE: {
|
|
288
|
+
message: 'ML-KEM-768 key not available',
|
|
289
|
+
hint: 'Actions: (1) Enable post-quantum: Agent.create({postQuantum: true}), (2) Check runtime supports ML-KEM-768, (3) Verify agent was initialized with PQ keys, (4) Regenerate identity with PQ enabled',
|
|
290
|
+
suggested_action: 'Create agent with postQuantum: true',
|
|
291
|
+
severity: 'medium',
|
|
292
|
+
docs: `${DOC_BASE}#key-agreement`,
|
|
293
|
+
},
|
|
294
|
+
PQ_SIGN_FAILED: {
|
|
295
|
+
message: 'ML-DSA-65 signing failed',
|
|
296
|
+
hint: 'Actions: (1) Verify ML-DSA-65 secret key is valid and not corrupted, (2) Check post-quantum support is enabled, (3) Ensure message to sign is not empty, (4) Review ML-DSA library logs',
|
|
297
|
+
suggested_action: 'Verify ML-DSA-65 secret key and post-quantum support',
|
|
298
|
+
severity: 'high',
|
|
299
|
+
docs: `${DOC_BASE}#identity`,
|
|
300
|
+
},
|
|
301
|
+
PQ_VERIFY_FAILED: {
|
|
302
|
+
message: 'ML-DSA-65 verification failed',
|
|
303
|
+
hint: 'Actions: (1) Verify public key matches signer, (2) Check signature format and encoding, (3) Confirm message matches what was signed, (4) Ensure post-quantum keys are synchronized',
|
|
304
|
+
suggested_action: 'Verify signer public key and signature format',
|
|
305
|
+
severity: 'high',
|
|
306
|
+
docs: `${DOC_BASE}#identity`,
|
|
307
|
+
},
|
|
308
|
+
// Split-channel
|
|
309
|
+
SPLIT_FAILED: {
|
|
310
|
+
message: 'XorIDA split failed',
|
|
311
|
+
hint: 'Actions: (1) Verify threshold <= shareCount, (2) Check threshold >= 2, (3) Validate payload size < 1MB, (4) Ensure sufficient memory for split operation',
|
|
312
|
+
suggested_action: 'Verify threshold parameters and payload size',
|
|
313
|
+
severity: 'high',
|
|
314
|
+
docs: `${DOC_BASE}#split-channel`,
|
|
315
|
+
},
|
|
316
|
+
INSUFFICIENT_SHARES: {
|
|
317
|
+
message: 'Not enough shares to reconstruct',
|
|
318
|
+
hint: 'Actions: (1) Log number of shares collected, (2) Check threshold requirement, (3) Collect more shares from recipients, (4) Verify shares are from same split (group ID match)',
|
|
319
|
+
suggested_action: 'Collect more shares to meet threshold requirement',
|
|
320
|
+
severity: 'high',
|
|
321
|
+
docs: `${DOC_BASE}#split-channel`,
|
|
322
|
+
},
|
|
323
|
+
INCONSISTENT_SHARES: {
|
|
324
|
+
message: 'Shares have mismatched group IDs or lengths',
|
|
325
|
+
hint: 'Actions: (1) Verify all shares are from same split, (2) Check group IDs match, (3) Ensure shares have same length, (4) Discard mismatched shares and request correct ones',
|
|
326
|
+
suggested_action: 'Verify all shares are from the same split operation',
|
|
327
|
+
severity: 'high',
|
|
328
|
+
docs: `${DOC_BASE}#split-channel`,
|
|
329
|
+
},
|
|
330
|
+
HMAC_VERIFICATION_FAILED: {
|
|
331
|
+
message: 'Share HMAC check failed',
|
|
332
|
+
hint: 'Actions: (1) Check share data is not corrupted in transit, (2) Verify share was not tampered with, (3) Confirm sender used correct HMAC key, (4) Request fresh share from sender',
|
|
333
|
+
suggested_action: 'Request fresh share from sender',
|
|
334
|
+
severity: 'critical',
|
|
335
|
+
docs: `${DOC_BASE}#split-channel`,
|
|
336
|
+
},
|
|
337
|
+
UNPAD_FAILED: {
|
|
338
|
+
message: 'Padding removal failed after reconstruction',
|
|
339
|
+
hint: 'Actions: (1) Verify reconstruction succeeded before unpadding, (2) Check reconstructed data is valid UTF-8, (3) Confirm padding algorithm matches (PKCS7), (4) Inspect raw reconstructed bytes',
|
|
340
|
+
suggested_action: 'Verify reconstruction succeeded and data is valid UTF-8',
|
|
341
|
+
severity: 'high',
|
|
342
|
+
docs: `${DOC_BASE}#split-channel`,
|
|
343
|
+
},
|
|
344
|
+
INVALID_SHARE_DATA: {
|
|
345
|
+
message: 'Share data is malformed',
|
|
346
|
+
hint: 'Actions: (1) Verify share is valid base64, (2) Check share structure (TLV format if applicable), (3) Log raw share bytes to inspect, (4) Request correctly-formatted share from sender',
|
|
347
|
+
suggested_action: 'Verify share is valid base64 and request correctly-formatted share',
|
|
348
|
+
severity: 'high',
|
|
349
|
+
docs: `${DOC_BASE}#split-channel`,
|
|
350
|
+
},
|
|
351
|
+
// Xchange
|
|
352
|
+
XCHANGE_KEYGEN_FAILED: {
|
|
353
|
+
message: 'Xchange key generation failed',
|
|
354
|
+
hint: 'Actions: (1) Verify Web Crypto API available (HTTPS/localhost), (2) Check runtime supports key generation, (3) Ensure sufficient entropy, (4) Retry with fresh context',
|
|
355
|
+
suggested_action: 'Verify Web Crypto API available and retry',
|
|
356
|
+
severity: 'high',
|
|
357
|
+
docs: `${DOC_BASE}#xchange`,
|
|
358
|
+
},
|
|
359
|
+
XCHANGE_ENCRYPT_FAILED: {
|
|
360
|
+
message: 'Xchange bundle encryption failed',
|
|
361
|
+
hint: 'Actions: (1) Check payload size < 64KB, (2) Verify encryption key is 32 bytes, (3) Ensure bundle structure is valid, (4) Review payload for null bytes',
|
|
362
|
+
suggested_action: 'Verify payload size and encryption key length',
|
|
363
|
+
severity: 'high',
|
|
364
|
+
docs: `${DOC_BASE}#xchange`,
|
|
365
|
+
},
|
|
366
|
+
XCHANGE_DECRYPT_FAILED: {
|
|
367
|
+
message: 'Xchange bundle decryption failed',
|
|
368
|
+
hint: 'Actions: (1) Verify reconstruction completed before decryption, (2) Check decryption key matches encryption key, (3) Confirm bundle integrity (auth tag valid), (4) Inspect bundle format',
|
|
369
|
+
suggested_action: 'Verify reconstruction completed and decryption key is correct',
|
|
370
|
+
severity: 'high',
|
|
371
|
+
docs: `${DOC_BASE}#xchange`,
|
|
372
|
+
},
|
|
373
|
+
INVALID_BUNDLE: {
|
|
374
|
+
message: 'Xchange bundle is malformed',
|
|
375
|
+
hint: 'Actions: (1) Verify bundle size >= 60 bytes (32B key + 12B IV + 16B tag), (2) Check bundle structure, (3) Decode and inspect bundle contents, (4) Request correctly-formed bundle',
|
|
376
|
+
suggested_action: 'Verify bundle size and request correctly-formed bundle',
|
|
377
|
+
severity: 'high',
|
|
378
|
+
docs: `${DOC_BASE}#xchange`,
|
|
379
|
+
},
|
|
380
|
+
// Agent (high-level)
|
|
381
|
+
IDENTITY_FAILED: {
|
|
382
|
+
message: 'Agent identity creation failed',
|
|
383
|
+
hint: 'Actions: (1) Verify Web Crypto API available, (2) Check HTTPS or localhost context, (3) Ensure runtime is Node.js 15+ or modern browser, (4) Retry agent initialization',
|
|
384
|
+
suggested_action: 'Verify Web Crypto API available and retry agent initialization',
|
|
385
|
+
severity: 'critical',
|
|
386
|
+
docs: `${DOC_BASE}#agent`,
|
|
387
|
+
},
|
|
388
|
+
REGISTRATION_FAILED: {
|
|
389
|
+
message: 'Agent registration with trust registry failed',
|
|
390
|
+
hint: 'Actions: (1) Verify registry URL is correct and reachable, (2) Check auth token is valid and not expired, (3) Confirm registry is online (status page), (4) Retry with exponential backoff',
|
|
391
|
+
suggested_action: 'Verify registry URL and auth token, then retry with exponential backoff',
|
|
392
|
+
severity: 'high',
|
|
393
|
+
docs: `${DOC_BASE}#agent`,
|
|
394
|
+
},
|
|
395
|
+
RECIPIENT_NOT_FOUND: {
|
|
396
|
+
message: 'Recipient agent not found in registry',
|
|
397
|
+
hint: 'Actions: (1) Verify recipient email/DID is correct, (2) Ask recipient to register with XBind first, (3) Check registration on recipient side (inspect registry), (4) Wait for registration to propagate',
|
|
398
|
+
field: 'to',
|
|
399
|
+
suggested_action: 'Ask recipient to register with xBind',
|
|
400
|
+
severity: 'medium',
|
|
401
|
+
docs: `${DOC_BASE}#agent`,
|
|
402
|
+
},
|
|
403
|
+
RECIPIENT_REVOKED: {
|
|
404
|
+
message: 'Recipient agent has been revoked',
|
|
405
|
+
hint: 'Actions: (1) Inform recipient to contact registry admin, (2) Verify revocation reason, (3) Request re-registration if accidental, (4) Confirm revocation status via registry lookup',
|
|
406
|
+
field: 'to',
|
|
407
|
+
suggested_action: 'Inform recipient to contact registry administrator',
|
|
408
|
+
severity: 'high',
|
|
409
|
+
docs: `${DOC_BASE}#agent`,
|
|
410
|
+
},
|
|
411
|
+
KEY_AGREEMENT_FAILED: {
|
|
412
|
+
message: 'ECDH key agreement with recipient failed',
|
|
413
|
+
hint: 'Actions: (1) Verify recipient public key is valid, (2) Check key format (X25519, 32 bytes), (3) Confirm keys from same algorithm family, (4) Request fresh key from recipient',
|
|
414
|
+
suggested_action: 'Request fresh key from recipient',
|
|
415
|
+
severity: 'high',
|
|
416
|
+
docs: `${DOC_BASE}#agent`,
|
|
417
|
+
},
|
|
418
|
+
ENVELOPE_FAILED: {
|
|
419
|
+
message: 'Envelope creation failed',
|
|
420
|
+
hint: 'Actions: (1) Check payload size < 10MB, (2) Verify recipient DID is valid, (3) Confirm sender identity is set, (4) Validate all required fields present',
|
|
421
|
+
suggested_action: 'Verify payload size and recipient DID',
|
|
422
|
+
severity: 'high',
|
|
423
|
+
docs: `${DOC_BASE}#agent`,
|
|
424
|
+
},
|
|
425
|
+
VERIFICATION_FAILED: {
|
|
426
|
+
message: 'Incoming envelope verification failed',
|
|
427
|
+
hint: 'Actions: (1) Check sender DID is in trust registry, (2) Verify sender signature is valid, (3) Confirm sender is not revoked, (4) Review trust policy settings',
|
|
428
|
+
suggested_action: 'Verify sender is in trust registry and not revoked',
|
|
429
|
+
severity: 'critical',
|
|
430
|
+
docs: `${DOC_BASE}#agent`,
|
|
431
|
+
},
|
|
432
|
+
REPLAY_DETECTED: {
|
|
433
|
+
message: 'Duplicate nonce detected — possible replay attack',
|
|
434
|
+
hint: 'Actions: (1) DISCARD MESSAGE for security, (2) Log nonce and sender DID, (3) Alert user to potential attack, (4) Check for compromised sender account',
|
|
435
|
+
suggested_action: 'DISCARD MESSAGE and alert user to potential replay attack',
|
|
436
|
+
severity: 'critical',
|
|
437
|
+
docs: `${DOC_BASE}#agent`,
|
|
438
|
+
},
|
|
439
|
+
SCOPE_DENIED: {
|
|
440
|
+
message: 'Sender does not have permission for the requested scope',
|
|
441
|
+
hint: 'Actions: (1) Check sender scope permissions in registry, (2) Verify scope value is correct, (3) Contact registry admin to grant permission, (4) Confirm sender registered with requested scope',
|
|
442
|
+
field: 'scope',
|
|
443
|
+
suggested_action: 'Contact registry admin to grant permission',
|
|
444
|
+
severity: 'medium',
|
|
445
|
+
docs: `${DOC_BASE}#agent`,
|
|
446
|
+
},
|
|
447
|
+
RECEIVER_SCOPE_DENIED: {
|
|
448
|
+
message: 'Recipient does not accept messages with this scope',
|
|
449
|
+
hint: 'Actions: (1) Check recipient receive scope settings, (2) Verify scope matches recipient policy, (3) Ask recipient to enable scope in settings, (4) Confirm recipient registry entry',
|
|
450
|
+
field: 'scope',
|
|
451
|
+
suggested_action: 'Ask recipient to enable scope in settings',
|
|
452
|
+
severity: 'medium',
|
|
453
|
+
docs: `${DOC_BASE}#agent`,
|
|
454
|
+
},
|
|
455
|
+
TIMESTAMP_EXPIRED: {
|
|
456
|
+
message: 'Envelope timestamp is outside the allowed window',
|
|
457
|
+
hint: 'Actions: (1) Synchronize system clocks (NTP), (2) Check time difference between sender and receiver, (3) Increase timestamp window (if configurable), (4) Verify no system time drift',
|
|
458
|
+
suggested_action: 'Synchronize system clocks using NTP',
|
|
459
|
+
severity: 'medium',
|
|
460
|
+
docs: `${DOC_BASE}#agent`,
|
|
461
|
+
},
|
|
462
|
+
};
|
|
463
|
+
/** Error messages keyed by code. Includes what happened and what to do next. */
|
|
464
|
+
const ERROR_MESSAGES = {
|
|
465
|
+
// Identity
|
|
466
|
+
KEYGEN_FAILED: [XBindIdentityError, 'Key generation failed. Actions: (1) Verify Web Crypto API is available in HTTPS or localhost, (2) Check runtime is Node.js 15+ or modern browser, (3) Retry initialization.'],
|
|
467
|
+
SIGN_FAILED: [XBindIdentityError, 'Signing failed. Actions: (1) Verify private key is valid and not corrupted, (2) Check key was properly imported, (3) Ensure key is extractable.'],
|
|
468
|
+
VERIFY_FAILED: [XBindIdentityError, 'Signature verification failed. Actions: (1) Confirm public key matches signer, (2) Check message integrity, (3) Verify signature format is valid base64.'],
|
|
469
|
+
INVALID_DID: [XBindIdentityError, 'The DID string is malformed. Actions: (1) Verify format: did:key:z6Mk..., (2) Check no extra whitespace, (3) Use validateDID() helper.'],
|
|
470
|
+
INVALID_KEY_LENGTH: [XBindKeyAgreementError, 'Key material is the wrong length. Actions: (1) Verify X25519 key is exactly 32 bytes, (2) Check base64 decoding, (3) Log key.length to confirm.'],
|
|
471
|
+
EXPORT_FAILED: [XBindIdentityError, 'PKCS8 export failed. Actions: (1) Create key with extractable:true, (2) Check Web Crypto support, (3) See: https://mdn.io/SubtleCrypto.exportKey.'],
|
|
472
|
+
IMPORT_FAILED: [XBindIdentityError, 'PKCS8 import failed. Actions: (1) Validate PKCS8 format (PEM or bytes), (2) Decode base64 if needed, (3) Check algorithm (Ed25519/X25519).'],
|
|
473
|
+
// Envelope
|
|
474
|
+
INVALID_VERSION: [XBindEnvelopeError, 'Unsupported envelope version. Actions: (1) Check envelope.version field, (2) Verify sender uses v1-v4, (3) Request sender SDK update.'],
|
|
475
|
+
INVALID_ALG: [XBindEnvelopeError, 'Unknown encryption algorithm. Actions: (1) Verify envelope.alg === "AES-256-GCM", (2) Log alg value to debug, (3) Check sender SDK version.'],
|
|
476
|
+
INVALID_NONCE: [XBindEnvelopeError, 'Nonce is missing or invalid. Actions: (1) Verify nonce exists and is 12 bytes, (2) Check base64 decoding, (3) Inspect replay buffer.'],
|
|
477
|
+
INVALID_FIELDS: [XBindEnvelopeError, 'Required envelope fields are missing. Actions: (1) Verify sender/recipient DIDs, (2) Check payload exists, (3) Validate: version, alg, nonce, ciphertext, tag.'],
|
|
478
|
+
ENCRYPT_FAILED: [XBindEnvelopeError, 'AES-256-GCM encryption failed. Actions: (1) Verify key is exactly 32 bytes, (2) Check plaintext is valid, (3) Ensure nonce is 12 bytes.'],
|
|
479
|
+
DECRYPT_FAILED: [XBindEnvelopeError, 'Decryption failed. Actions: (1) Verify correct key is being used, (2) Check ciphertext integrity, (3) Confirm auth tag is valid.'],
|
|
480
|
+
PARSE_FAILED: [XBindEnvelopeError, 'Envelope deserialization failed. Actions: (1) Validate JSON structure, (2) Check for truncation, (3) Verify base64 encoding of fields.'],
|
|
481
|
+
// Transport
|
|
482
|
+
SEND_FAILED: [XBindTransportError, 'Message send failed. Actions: (1) Check network connectivity (ping registry), (2) Verify recipient address, (3) Confirm recipient registered, (4) Retry with backoff.'],
|
|
483
|
+
NETWORK_ERROR: [XBindTransportError, 'Network request failed. Actions: (1) Verify internet connection, (2) Check DNS resolution, (3) Ping registry endpoint, (4) Implement exponential backoff (2s, 4s, 8s).'],
|
|
484
|
+
RECIPIENT_UNREACHABLE: [XBindTransportError, 'Recipient is unreachable. Actions: (1) Verify recipient email is correct, (2) Check if recipient is registered, (3) Confirm recipient is online, (4) Provide human follow-up.'],
|
|
485
|
+
TIMEOUT: [XBindTransportError, 'Transport operation timed out. Actions: (1) Increase timeout threshold, (2) Check network latency, (3) Verify registry responsiveness, (4) Retry operation.'],
|
|
486
|
+
// Registry
|
|
487
|
+
NOT_FOUND: [XBindRegistryError, 'Agent not found in trust registry. Actions: (1) Ask recipient to register with xBind, (2) Verify recipient email/DID, (3) Check registration status, (4) Retry after propagation.'],
|
|
488
|
+
ALREADY_REGISTERED: [XBindRegistryError, 'Agent is already registered. Actions: (1) Use updateAgent() instead, (2) Provide new keys or metadata, (3) Verify DID matches existing entry.'],
|
|
489
|
+
REVOKED: [XBindRegistryError, 'Agent has been revoked from the registry. Actions: (1) Contact registry admin, (2) Check revocation reason, (3) Request re-registration if accidental.'],
|
|
490
|
+
// Key agreement
|
|
491
|
+
DERIVE_FAILED: [XBindKeyAgreementError, 'ECDH key derivation failed. Actions: (1) Verify peer public key is valid X25519 (32 bytes), (2) Check key is not corrupted, (3) Confirm X25519 ECDH support.'],
|
|
492
|
+
KEM_ENCAPSULATE_FAILED: [XBindKeyAgreementError, 'ML-KEM-768 encapsulation failed. Actions: (1) Verify recipient key is valid ML-KEM-768, (2) Check key format, (3) Confirm post-quantum support enabled.'],
|
|
493
|
+
KEM_DECAPSULATE_FAILED: [XBindKeyAgreementError, 'ML-KEM-768 decapsulation failed. Actions: (1) Verify ciphertext integrity, (2) Check secret key is valid, (3) Confirm ciphertext matches key.'],
|
|
494
|
+
HKDF_FAILED: [XBindKeyAgreementError, 'HKDF key derivation failed. Actions: (1) Verify both shared secrets are valid, (2) Check HKDF input size, (3) Ensure SHA-256 support.'],
|
|
495
|
+
MLKEM_NOT_AVAILABLE: [XBindKeyAgreementError, 'ML-KEM-768 key not available. Actions: (1) Create agent with postQuantum: true, (2) Check runtime supports ML-KEM-768, (3) Regenerate identity with PQ enabled.'],
|
|
496
|
+
PQ_SIGN_FAILED: [XBindIdentityError, 'ML-DSA-65 signing failed. Actions: (1) Verify secret key is valid, (2) Check post-quantum support enabled, (3) Ensure message is not empty.'],
|
|
497
|
+
PQ_VERIFY_FAILED: [XBindIdentityError, 'ML-DSA-65 verification failed. Actions: (1) Verify public key matches signer, (2) Check signature format, (3) Confirm message integrity.'],
|
|
498
|
+
// Split-channel
|
|
499
|
+
SPLIT_FAILED: [XBindSplitChannelError, 'XorIDA split failed. Actions: (1) Verify threshold <= shareCount, (2) Check threshold >= 2, (3) Validate payload < 1MB.'],
|
|
500
|
+
INSUFFICIENT_SHARES: [XBindSplitChannelError, 'Not enough shares to reconstruct. Actions: (1) Log number of shares collected, (2) Check threshold requirement, (3) Collect more shares.'],
|
|
501
|
+
INCONSISTENT_SHARES: [XBindSplitChannelError, 'Shares have mismatched group IDs or lengths. Actions: (1) Verify all from same split, (2) Check group IDs match, (3) Discard mismatched shares.'],
|
|
502
|
+
HMAC_VERIFICATION_FAILED: [XBindSplitChannelError, 'Share HMAC check failed. Actions: (1) Check share integrity in transit, (2) Verify not tampered with, (3) Request fresh share.'],
|
|
503
|
+
UNPAD_FAILED: [XBindSplitChannelError, 'Padding removal failed after reconstruction. Actions: (1) Verify reconstruction succeeded, (2) Check data is valid UTF-8, (3) Inspect raw bytes.'],
|
|
504
|
+
INVALID_SHARE_DATA: [XBindSplitChannelError, 'Share data is malformed. Actions: (1) Verify share is valid base64, (2) Check TLV structure, (3) Log raw bytes to inspect.'],
|
|
505
|
+
// Xchange (XorIDA key transport)
|
|
506
|
+
XCHANGE_KEYGEN_FAILED: [XBindKeyAgreementError, 'Xchange key generation failed. Actions: (1) Verify Web Crypto available (HTTPS/localhost), (2) Check runtime support, (3) Ensure entropy.'],
|
|
507
|
+
XCHANGE_ENCRYPT_FAILED: [XBindEnvelopeError, 'Xchange bundle encryption failed. Actions: (1) Check payload < 64KB, (2) Verify key is 32 bytes, (3) Validate bundle structure.'],
|
|
508
|
+
XCHANGE_DECRYPT_FAILED: [XBindEnvelopeError, 'Xchange bundle decryption failed. Actions: (1) Verify reconstruction succeeded, (2) Check key matches encryption key, (3) Confirm bundle integrity.'],
|
|
509
|
+
INVALID_BUNDLE: [XBindSplitChannelError, 'Xchange bundle is malformed. Actions: (1) Verify size >= 60 bytes (32B + 12B + 16B), (2) Check structure, (3) Decode to inspect.'],
|
|
510
|
+
// Agent (high-level)
|
|
511
|
+
IDENTITY_FAILED: [XBindAgentError, 'Agent identity creation failed. Actions: (1) Verify Web Crypto available, (2) Check HTTPS/localhost, (3) Ensure Node.js 15+ or modern browser.'],
|
|
512
|
+
REGISTRATION_FAILED: [XBindAgentError, 'Agent registration with trust registry failed. Actions: (1) Verify registry URL is correct, (2) Check auth token valid/not expired, (3) Confirm registry online.'],
|
|
513
|
+
RECIPIENT_NOT_FOUND: [XBindAgentError, 'Recipient agent not found in registry. Actions: (1) Verify recipient email/DID, (2) Ask recipient to register first, (3) Wait for propagation.'],
|
|
514
|
+
RECIPIENT_REVOKED: [XBindAgentError, 'Recipient agent has been revoked. Actions: (1) Inform recipient to contact admin, (2) Verify revocation reason, (3) Request re-registration.'],
|
|
515
|
+
KEY_AGREEMENT_FAILED: [XBindAgentError, 'ECDH key agreement with recipient failed. Actions: (1) Verify recipient key valid, (2) Check key format (X25519, 32B), (3) Request fresh key.'],
|
|
516
|
+
ENVELOPE_FAILED: [XBindAgentError, 'Envelope creation failed. Actions: (1) Check payload < 10MB, (2) Verify recipient DID valid, (3) Confirm sender identity set.'],
|
|
517
|
+
VERIFICATION_FAILED: [XBindAgentError, 'Incoming envelope verification failed. Actions: (1) Check sender in registry, (2) Verify signature valid, (3) Confirm sender not revoked.'],
|
|
518
|
+
REPLAY_DETECTED: [XBindAgentError, 'Duplicate nonce detected — possible replay attack. Actions: (1) DISCARD message, (2) Log nonce/sender, (3) Alert user to potential attack.'],
|
|
519
|
+
SCOPE_DENIED: [XBindAgentError, 'Sender does not have permission for the requested scope. Actions: (1) Check sender scope in registry, (2) Contact admin to grant, (3) Verify scope value.'],
|
|
520
|
+
RECEIVER_SCOPE_DENIED: [XBindAgentError, 'Recipient does not accept messages with this scope. Actions: (1) Check recipient receive scope settings, (2) Ask to enable scope, (3) Verify registry entry.'],
|
|
521
|
+
TIMESTAMP_EXPIRED: [XBindAgentError, 'Envelope timestamp is outside the allowed window. Actions: (1) Synchronize system clocks (NTP), (2) Check time difference, (3) Verify no time drift.'],
|
|
522
|
+
};
|
|
523
|
+
/**
|
|
524
|
+
* Convert a string error code to a typed XBindError instance.
|
|
525
|
+
* Handles colon-separated sub-codes (e.g. 'DECRYPT_FAILED:KEY_AGREEMENT').
|
|
526
|
+
* Falls back to base XBindError for unknown codes.
|
|
527
|
+
*
|
|
528
|
+
* @param code - Error code string from Result<T,E> (e.g. 'REPLAY_DETECTED')
|
|
529
|
+
* @returns Typed XBindError subclass instance
|
|
530
|
+
*/
|
|
531
|
+
export function toXBindError(code) {
|
|
532
|
+
const baseCode = code.split(':')[0] ?? code;
|
|
533
|
+
const entry = ERROR_MESSAGES[baseCode];
|
|
534
|
+
if (entry) {
|
|
535
|
+
const [ErrorClass, message] = entry;
|
|
536
|
+
return new ErrorClass(code, message);
|
|
537
|
+
}
|
|
538
|
+
return new XBindError(code, `XBind error: ${code}`);
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Type guard for XBindError instances.
|
|
542
|
+
*
|
|
543
|
+
* @param err - Unknown value to check
|
|
544
|
+
* @returns True if err is a XBindError instance
|
|
545
|
+
*/
|
|
546
|
+
export function isXBindError(err) {
|
|
547
|
+
return err instanceof XBindError;
|
|
548
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
type AnyWebSocket = any;
|
|
2
|
+
/**
|
|
3
|
+
* Gateway connection state manager.
|
|
4
|
+
*
|
|
5
|
+
* Online-only model: State evaporates immediately on disconnect.
|
|
6
|
+
* No 12-hour windows, no persistent state.
|
|
7
|
+
*
|
|
8
|
+
* Note: WebSocket type is runtime-dependent (browser WebSocket or 'ws' package).
|
|
9
|
+
*/
|
|
10
|
+
export declare class GatewayConnectionState {
|
|
11
|
+
private connections;
|
|
12
|
+
/**
|
|
13
|
+
* Register agent connection.
|
|
14
|
+
*
|
|
15
|
+
* @param did - DID of the connecting agent
|
|
16
|
+
* @param socket - WebSocket connection (browser or Node.js 'ws' package)
|
|
17
|
+
*/
|
|
18
|
+
connect(did: string, socket: AnyWebSocket): void;
|
|
19
|
+
/**
|
|
20
|
+
* Check if agent is currently online.
|
|
21
|
+
*/
|
|
22
|
+
isOnline(did: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Get WebSocket for online agent (or null if offline).
|
|
25
|
+
*/
|
|
26
|
+
getSocket(did: string): AnyWebSocket | null;
|
|
27
|
+
/**
|
|
28
|
+
* Get all online DIDs.
|
|
29
|
+
*/
|
|
30
|
+
getOnlineDids(): string[];
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gateway connection state manager.
|
|
3
|
+
*
|
|
4
|
+
* Online-only model: State evaporates immediately on disconnect.
|
|
5
|
+
* No 12-hour windows, no persistent state.
|
|
6
|
+
*
|
|
7
|
+
* Note: WebSocket type is runtime-dependent (browser WebSocket or 'ws' package).
|
|
8
|
+
*/
|
|
9
|
+
export class GatewayConnectionState {
|
|
10
|
+
connections = new Map(); // did → socket
|
|
11
|
+
/**
|
|
12
|
+
* Register agent connection.
|
|
13
|
+
*
|
|
14
|
+
* @param did - DID of the connecting agent
|
|
15
|
+
* @param socket - WebSocket connection (browser or Node.js 'ws' package)
|
|
16
|
+
*/
|
|
17
|
+
connect(did, socket) {
|
|
18
|
+
this.connections.set(did, socket);
|
|
19
|
+
// Handle close event (works for both browser and Node.js ws)
|
|
20
|
+
if (typeof socket.on === 'function') {
|
|
21
|
+
// Node.js 'ws' package style
|
|
22
|
+
socket.on('close', () => {
|
|
23
|
+
this.connections.delete(did); // Immediate evaporation
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
else if (socket.addEventListener) {
|
|
27
|
+
// Browser WebSocket style
|
|
28
|
+
socket.addEventListener('close', () => {
|
|
29
|
+
this.connections.delete(did);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Check if agent is currently online.
|
|
35
|
+
*/
|
|
36
|
+
isOnline(did) {
|
|
37
|
+
return this.connections.has(did);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get WebSocket for online agent (or null if offline).
|
|
41
|
+
*/
|
|
42
|
+
getSocket(did) {
|
|
43
|
+
return this.connections.get(did) ?? null;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get all online DIDs.
|
|
47
|
+
*/
|
|
48
|
+
getOnlineDids() {
|
|
49
|
+
return Array.from(this.connections.keys());
|
|
50
|
+
}
|
|
51
|
+
}
|