@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,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* XorIDA Backup Configuration for Key Splitting
|
|
4
|
+
*
|
|
5
|
+
* Provides default backup configuration (k=2, n=3) and utilities for
|
|
6
|
+
* splitting cryptographic keys across multiple shares using information-
|
|
7
|
+
* theoretic threshold secret sharing.
|
|
8
|
+
*
|
|
9
|
+
* @module backup-config
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DEFAULT_BACKUP_CONFIG = void 0;
|
|
13
|
+
exports.validateBackupConfig = validateBackupConfig;
|
|
14
|
+
exports.splitKeyWithBackup = splitKeyWithBackup;
|
|
15
|
+
exports.reconstructKeyFromBackup = reconstructKeyFromBackup;
|
|
16
|
+
const shared_1 = require("../_deps/shared/index.js");
|
|
17
|
+
const crypto_1 = require("../_deps/crypto/index.js");
|
|
18
|
+
/* ── Constants ── */
|
|
19
|
+
/**
|
|
20
|
+
* Default backup configuration: 2-of-3 threshold sharing.
|
|
21
|
+
*
|
|
22
|
+
* - 3 shares generated
|
|
23
|
+
* - Any 2 shares can reconstruct the key
|
|
24
|
+
* - Lose 1 share and still recover (fault tolerance)
|
|
25
|
+
* - Information-theoretic security (each share reveals zero information)
|
|
26
|
+
*/
|
|
27
|
+
exports.DEFAULT_BACKUP_CONFIG = {
|
|
28
|
+
threshold: 2,
|
|
29
|
+
totalShares: 3,
|
|
30
|
+
};
|
|
31
|
+
/* ── Validation ── */
|
|
32
|
+
/**
|
|
33
|
+
* Validate backup configuration parameters.
|
|
34
|
+
*
|
|
35
|
+
* Rules:
|
|
36
|
+
* - threshold must be >= 2 (single share = no threshold)
|
|
37
|
+
* - totalShares must be >= threshold
|
|
38
|
+
* - totalShares must be <= 255 (XorIDA limit)
|
|
39
|
+
*
|
|
40
|
+
* @param config - Backup configuration to validate.
|
|
41
|
+
* @returns Ok if valid, error otherwise.
|
|
42
|
+
*/
|
|
43
|
+
function validateBackupConfig(config) {
|
|
44
|
+
if (config.threshold < 2) {
|
|
45
|
+
return (0, shared_1.err)('INVALID_CONFIG');
|
|
46
|
+
}
|
|
47
|
+
if (config.totalShares < config.threshold) {
|
|
48
|
+
return (0, shared_1.err)('INVALID_CONFIG');
|
|
49
|
+
}
|
|
50
|
+
if (config.totalShares > 255) {
|
|
51
|
+
return (0, shared_1.err)('INVALID_CONFIG');
|
|
52
|
+
}
|
|
53
|
+
return (0, shared_1.ok)(undefined);
|
|
54
|
+
}
|
|
55
|
+
/* ── Key Splitting ── */
|
|
56
|
+
/**
|
|
57
|
+
* Split a cryptographic key into backup shares using XorIDA.
|
|
58
|
+
*
|
|
59
|
+
* The key is padded, split via information-theoretic threshold sharing,
|
|
60
|
+
* and returned as BackupShare objects with HMAC integrity protection.
|
|
61
|
+
*
|
|
62
|
+
* Any `threshold` shares can reconstruct the original key. Each share
|
|
63
|
+
* reveals zero information about the key (information-theoretic security).
|
|
64
|
+
*
|
|
65
|
+
* @param key - The key to split (32 or 64 bytes typical).
|
|
66
|
+
* @param config - Backup configuration (defaults to 2-of-3).
|
|
67
|
+
* @returns Array of backup shares or error.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* import { splitKeyWithBackup, DEFAULT_BACKUP_CONFIG } from '@private.me/xbind';
|
|
72
|
+
*
|
|
73
|
+
* const key = crypto.getRandomValues(new Uint8Array(32));
|
|
74
|
+
*
|
|
75
|
+
* // Use defaults (2-of-3)
|
|
76
|
+
* const shares = await splitKeyWithBackup(key);
|
|
77
|
+
*
|
|
78
|
+
* // Custom config (3-of-5)
|
|
79
|
+
* const shares2 = await splitKeyWithBackup(key, {
|
|
80
|
+
* threshold: 3,
|
|
81
|
+
* totalShares: 5
|
|
82
|
+
* });
|
|
83
|
+
*
|
|
84
|
+
* if (shares.ok) {
|
|
85
|
+
* // Store shares in separate locations
|
|
86
|
+
* shares.value.forEach((share, i) => {
|
|
87
|
+
* storeShare(`backup-${i}.json`, JSON.stringify(share));
|
|
88
|
+
* });
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
async function splitKeyWithBackup(key, config = exports.DEFAULT_BACKUP_CONFIG) {
|
|
93
|
+
const validation = validateBackupConfig(config);
|
|
94
|
+
if (!validation.ok)
|
|
95
|
+
return validation;
|
|
96
|
+
if (key.length === 0) {
|
|
97
|
+
return (0, shared_1.err)('INVALID_KEY_LENGTH');
|
|
98
|
+
}
|
|
99
|
+
const n = config.totalShares;
|
|
100
|
+
const k = config.threshold;
|
|
101
|
+
const p = (0, crypto_1.nextOddPrime)(n);
|
|
102
|
+
const blockSize = p - 1;
|
|
103
|
+
// Pad to block size
|
|
104
|
+
const padded = (0, crypto_1.pkcs7Pad)(key, blockSize);
|
|
105
|
+
// Generate HMAC for integrity verification
|
|
106
|
+
const { key: hmacKey, signature: hmacSig } = await (0, crypto_1.generateHMAC)(padded);
|
|
107
|
+
const hmacKeyB64 = (0, crypto_1.toBase64)(hmacKey);
|
|
108
|
+
const hmacSigB64 = (0, crypto_1.toBase64)(hmacSig);
|
|
109
|
+
// Split via XorIDA
|
|
110
|
+
let shareArrays;
|
|
111
|
+
try {
|
|
112
|
+
shareArrays = (0, crypto_1.splitXorIDA)(padded, n, k);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return (0, shared_1.err)('SPLIT_FAILED');
|
|
116
|
+
}
|
|
117
|
+
// Package as BackupShare objects
|
|
118
|
+
const shares = shareArrays.map((data, index) => ({
|
|
119
|
+
index,
|
|
120
|
+
data: (0, crypto_1.toBase64)(data),
|
|
121
|
+
total: n,
|
|
122
|
+
threshold: k,
|
|
123
|
+
hmacKey: hmacKeyB64,
|
|
124
|
+
hmacSig: hmacSigB64,
|
|
125
|
+
}));
|
|
126
|
+
return (0, shared_1.ok)(shares);
|
|
127
|
+
}
|
|
128
|
+
/* ── Key Reconstruction ── */
|
|
129
|
+
/**
|
|
130
|
+
* Reconstruct a cryptographic key from backup shares.
|
|
131
|
+
*
|
|
132
|
+
* Requires at least `threshold` shares. Verifies HMAC before returning
|
|
133
|
+
* the reconstructed key to prevent tampering.
|
|
134
|
+
*
|
|
135
|
+
* @param shares - Backup shares (must be >= threshold).
|
|
136
|
+
* @returns Reconstructed key or error.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* import { reconstructKeyFromBackup } from '@private.me/xbind';
|
|
141
|
+
*
|
|
142
|
+
* // Load shares from storage
|
|
143
|
+
* const share0 = JSON.parse(loadShare('backup-0.json'));
|
|
144
|
+
* const share1 = JSON.parse(loadShare('backup-1.json'));
|
|
145
|
+
*
|
|
146
|
+
* // Reconstruct from any 2 shares (threshold=2)
|
|
147
|
+
* const key = await reconstructKeyFromBackup([share0, share1]);
|
|
148
|
+
*
|
|
149
|
+
* if (key.ok) {
|
|
150
|
+
* // Use reconstructed key
|
|
151
|
+
* const agent = await Agent.fromSeed(key.value, opts);
|
|
152
|
+
* } else {
|
|
153
|
+
* console.error('Reconstruction failed:', key.error);
|
|
154
|
+
* }
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
async function reconstructKeyFromBackup(shares) {
|
|
158
|
+
if (shares.length === 0) {
|
|
159
|
+
return (0, shared_1.err)('INSUFFICIENT_SHARES');
|
|
160
|
+
}
|
|
161
|
+
const threshold = shares[0].threshold;
|
|
162
|
+
const total = shares[0].total;
|
|
163
|
+
if (shares.length < threshold) {
|
|
164
|
+
return (0, shared_1.err)('INSUFFICIENT_SHARES');
|
|
165
|
+
}
|
|
166
|
+
// Use first `threshold` shares
|
|
167
|
+
const usedShares = shares.slice(0, threshold);
|
|
168
|
+
// Decode share data
|
|
169
|
+
let shareData;
|
|
170
|
+
try {
|
|
171
|
+
shareData = usedShares.map((s) => (0, crypto_1.fromBase64)(s.data));
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return (0, shared_1.err)('INVALID_SHARE_DATA');
|
|
175
|
+
}
|
|
176
|
+
const indices = usedShares.map((s) => s.index);
|
|
177
|
+
// Reconstruct padded key
|
|
178
|
+
let padded;
|
|
179
|
+
try {
|
|
180
|
+
padded = (0, crypto_1.reconstructXorIDA)(shareData, indices, total, threshold);
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
return (0, shared_1.err)('RECONSTRUCT_FAILED');
|
|
184
|
+
}
|
|
185
|
+
// Verify HMAC
|
|
186
|
+
let hmacKey;
|
|
187
|
+
let hmacSig;
|
|
188
|
+
try {
|
|
189
|
+
hmacKey = (0, crypto_1.fromBase64)(usedShares[0].hmacKey);
|
|
190
|
+
hmacSig = (0, crypto_1.fromBase64)(usedShares[0].hmacSig);
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
return (0, shared_1.err)('INVALID_SHARE_DATA');
|
|
194
|
+
}
|
|
195
|
+
const hmacValid = await (0, crypto_1.verifyHMAC)(hmacKey, padded, hmacSig);
|
|
196
|
+
if (!hmacValid) {
|
|
197
|
+
return (0, shared_1.err)('HMAC_VERIFICATION_FAILED');
|
|
198
|
+
}
|
|
199
|
+
// Unpad to recover original key
|
|
200
|
+
const p = (0, crypto_1.nextOddPrime)(total);
|
|
201
|
+
const blockSize = p - 1;
|
|
202
|
+
const unpadResult = (0, crypto_1.pkcs7Unpad)(padded, blockSize);
|
|
203
|
+
if (!unpadResult.ok) {
|
|
204
|
+
return (0, shared_1.err)('RECONSTRUCT_FAILED');
|
|
205
|
+
}
|
|
206
|
+
return (0, shared_1.ok)(unpadResult.value);
|
|
207
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCheckpoint = createCheckpoint;
|
|
4
|
+
exports.verifyCheckpoint = verifyCheckpoint;
|
|
5
|
+
exports.isCacheStale = isCacheStale;
|
|
6
|
+
exports.encodeCheckpoint = encodeCheckpoint;
|
|
7
|
+
exports.decodeCheckpoint = decodeCheckpoint;
|
|
8
|
+
const shared_1 = require("../_deps/shared/index.js");
|
|
9
|
+
const identity_js_1 = require("./identity.js");
|
|
10
|
+
/* ── Checkpoint Creation (Gateway-side) ── */
|
|
11
|
+
/**
|
|
12
|
+
* Create a signed checkpoint for a DID (gateway-side operation).
|
|
13
|
+
*
|
|
14
|
+
* Gateway signs the DID state snapshot using its ML-DSA-65 private key.
|
|
15
|
+
* Clients verify this signature using the gateway's published public key.
|
|
16
|
+
*
|
|
17
|
+
* @param subject - DID being checkpointed
|
|
18
|
+
* @param publicKey - Current public key bytes
|
|
19
|
+
* @param revoked - Current revocation status
|
|
20
|
+
* @param rotationSequence - Current rotation sequence counter
|
|
21
|
+
* @param gatewayPrivateKey - Gateway's ML-DSA-65 secret key (32-byte seed or 4032-byte expanded)
|
|
22
|
+
* @returns Signed checkpoint or error
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const checkpoint = await createCheckpoint(
|
|
27
|
+
* 'did:key:z6Mk...',
|
|
28
|
+
* publicKeyBytes,
|
|
29
|
+
* false,
|
|
30
|
+
* 5,
|
|
31
|
+
* gatewaySecretKey
|
|
32
|
+
* );
|
|
33
|
+
* if (checkpoint.ok) {
|
|
34
|
+
* // Send checkpoint to client for staleness detection
|
|
35
|
+
* sendToClient(checkpoint.value);
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
async function createCheckpoint(subject, publicKey, revoked, rotationSequence, gatewayPrivateKey) {
|
|
40
|
+
const timestamp = Date.now();
|
|
41
|
+
// Construct canonical message to sign
|
|
42
|
+
const publicKeyB64 = Buffer.from(publicKey).toString('base64');
|
|
43
|
+
const message = `DIDStateCheckpoint||1.0||${subject}||${publicKeyB64}||${revoked}||${rotationSequence}||${timestamp}`;
|
|
44
|
+
const messageBytes = new TextEncoder().encode(message);
|
|
45
|
+
// Sign using gateway's ML-DSA-65 key
|
|
46
|
+
const sigResult = await (0, identity_js_1.signMlDsa65)(gatewayPrivateKey, messageBytes);
|
|
47
|
+
if (!sigResult.ok) {
|
|
48
|
+
return (0, shared_1.err)('SIGN_FAILED');
|
|
49
|
+
}
|
|
50
|
+
return (0, shared_1.ok)({
|
|
51
|
+
type: 'DIDStateCheckpoint',
|
|
52
|
+
version: '1.0',
|
|
53
|
+
subject,
|
|
54
|
+
current_public_key: publicKeyB64,
|
|
55
|
+
revoked,
|
|
56
|
+
rotation_sequence: rotationSequence,
|
|
57
|
+
timestamp,
|
|
58
|
+
checkpoint_signature_algorithm: 'ML-DSA-65',
|
|
59
|
+
checkpoint_signature: Buffer.from(sigResult.value).toString('base64')
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/* ── Checkpoint Verification (Client-side) ── */
|
|
63
|
+
/**
|
|
64
|
+
* Verify a checkpoint signature (client-side operation).
|
|
65
|
+
*
|
|
66
|
+
* Clients MUST verify checkpoint signatures before trusting the state.
|
|
67
|
+
* Uses gateway's published ML-DSA-65 public key to verify signature.
|
|
68
|
+
*
|
|
69
|
+
* @param checkpoint - Checkpoint to verify
|
|
70
|
+
* @param gatewayPublicKey - Gateway's ML-DSA-65 public key (1952 bytes)
|
|
71
|
+
* @returns true if signature valid, false if invalid, error if verification fails
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const valid = await verifyCheckpoint(checkpoint, gatewayPubKey);
|
|
76
|
+
* if (valid.ok && valid.value) {
|
|
77
|
+
* // Checkpoint is authentic - safe to use for staleness detection
|
|
78
|
+
* if (isCacheStale(localCache, checkpoint)) {
|
|
79
|
+
* // Refresh local cache
|
|
80
|
+
* }
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
async function verifyCheckpoint(checkpoint, gatewayPublicKey) {
|
|
85
|
+
// Validate checkpoint format
|
|
86
|
+
if (checkpoint.type !== 'DIDStateCheckpoint') {
|
|
87
|
+
return (0, shared_1.err)('INVALID_FORMAT');
|
|
88
|
+
}
|
|
89
|
+
if (checkpoint.version !== '1.0') {
|
|
90
|
+
return (0, shared_1.err)('INVALID_FORMAT');
|
|
91
|
+
}
|
|
92
|
+
if (!checkpoint.subject || !checkpoint.current_public_key) {
|
|
93
|
+
return (0, shared_1.err)('INVALID_FORMAT');
|
|
94
|
+
}
|
|
95
|
+
if (typeof checkpoint.rotation_sequence !== 'number' || checkpoint.rotation_sequence < 0) {
|
|
96
|
+
return (0, shared_1.err)('INVALID_FORMAT');
|
|
97
|
+
}
|
|
98
|
+
if (typeof checkpoint.timestamp !== 'number' || checkpoint.timestamp <= 0) {
|
|
99
|
+
return (0, shared_1.err)('INVALID_TIMESTAMP');
|
|
100
|
+
}
|
|
101
|
+
if (checkpoint.checkpoint_signature_algorithm !== 'ML-DSA-65') {
|
|
102
|
+
return (0, shared_1.err)('INVALID_FORMAT');
|
|
103
|
+
}
|
|
104
|
+
// Reconstruct canonical message
|
|
105
|
+
const message = `DIDStateCheckpoint||1.0||${checkpoint.subject}||${checkpoint.current_public_key}||${checkpoint.revoked}||${checkpoint.rotation_sequence}||${checkpoint.timestamp}`;
|
|
106
|
+
const messageBytes = new TextEncoder().encode(message);
|
|
107
|
+
// Decode signature
|
|
108
|
+
let signature;
|
|
109
|
+
try {
|
|
110
|
+
signature = Buffer.from(checkpoint.checkpoint_signature, 'base64');
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return (0, shared_1.err)('INVALID_SIGNATURE');
|
|
114
|
+
}
|
|
115
|
+
// Verify signature using gateway public key
|
|
116
|
+
const verifyResult = await (0, identity_js_1.verifyMlDsa65)(gatewayPublicKey, signature, messageBytes);
|
|
117
|
+
if (!verifyResult.ok) {
|
|
118
|
+
return (0, shared_1.err)('VERIFY_FAILED');
|
|
119
|
+
}
|
|
120
|
+
return (0, shared_1.ok)(verifyResult.value);
|
|
121
|
+
}
|
|
122
|
+
/* ── Staleness Detection ── */
|
|
123
|
+
/**
|
|
124
|
+
* Detect if local cache is stale compared to gateway checkpoint.
|
|
125
|
+
*
|
|
126
|
+
* Cache is stale if:
|
|
127
|
+
* 1. Checkpoint rotation_sequence > local rotationSequence (key rotated)
|
|
128
|
+
* 2. Checkpoint revoked !== local revoked (revocation status changed)
|
|
129
|
+
* 3. Checkpoint public key !== local publicKey (state drift)
|
|
130
|
+
*
|
|
131
|
+
* @param localCache - Local cache entry for DID
|
|
132
|
+
* @param checkpoint - Verified checkpoint from gateway
|
|
133
|
+
* @returns true if cache needs refresh, false if cache is current
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* if (isCacheStale(localCache, checkpoint)) {
|
|
138
|
+
* // Local cache is outdated - fetch fresh state from gateway
|
|
139
|
+
* const freshState = await registry.getEntry(did);
|
|
140
|
+
* }
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
function isCacheStale(localCache, checkpoint) {
|
|
144
|
+
// Sequence number mismatch indicates key rotation
|
|
145
|
+
if (checkpoint.rotation_sequence > localCache.rotationSequence) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
// Revocation status changed
|
|
149
|
+
if (checkpoint.revoked !== localCache.revoked) {
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
// Public key mismatch indicates state drift
|
|
153
|
+
const checkpointPubKey = Buffer.from(checkpoint.current_public_key, 'base64');
|
|
154
|
+
if (!Buffer.from(localCache.publicKey).equals(checkpointPubKey)) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
/* ── Encoding/Decoding ── */
|
|
160
|
+
/**
|
|
161
|
+
* Encode checkpoint to JSON string for wire transport.
|
|
162
|
+
*
|
|
163
|
+
* @param checkpoint - Checkpoint to encode
|
|
164
|
+
* @returns JSON string
|
|
165
|
+
*/
|
|
166
|
+
function encodeCheckpoint(checkpoint) {
|
|
167
|
+
return JSON.stringify(checkpoint);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Decode checkpoint from JSON string.
|
|
171
|
+
*
|
|
172
|
+
* @param encoded - JSON string
|
|
173
|
+
* @returns Parsed checkpoint or error
|
|
174
|
+
*/
|
|
175
|
+
function decodeCheckpoint(encoded) {
|
|
176
|
+
try {
|
|
177
|
+
const parsed = JSON.parse(encoded);
|
|
178
|
+
// Basic validation
|
|
179
|
+
if (parsed.type !== 'DIDStateCheckpoint') {
|
|
180
|
+
return (0, shared_1.err)('INVALID_FORMAT');
|
|
181
|
+
}
|
|
182
|
+
if (parsed.version !== '1.0') {
|
|
183
|
+
return (0, shared_1.err)('INVALID_FORMAT');
|
|
184
|
+
}
|
|
185
|
+
if (!parsed.subject || !parsed.current_public_key || !parsed.checkpoint_signature) {
|
|
186
|
+
return (0, shared_1.err)('INVALID_FORMAT');
|
|
187
|
+
}
|
|
188
|
+
return (0, shared_1.ok)(parsed);
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
return (0, shared_1.err)('INVALID_FORMAT');
|
|
192
|
+
}
|
|
193
|
+
}
|