@ocap/mpc-hsm 0.0.0-stage → 1.33.7
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/esm/bip39-english-wordlist.d.mts +11 -0
- package/esm/bip39-english-wordlist.mjs +31 -0
- package/esm/constants.d.mts +140 -0
- package/esm/constants.mjs +142 -0
- package/esm/dkg.d.mts +279 -0
- package/esm/dkg.mjs +903 -0
- package/esm/index.d.mts +17 -0
- package/esm/index.mjs +18 -0
- package/esm/mta.d.mts +63 -0
- package/esm/mta.mjs +275 -0
- package/esm/ocap-clear-signing.d.mts +125 -0
- package/esm/ocap-clear-signing.mjs +1170 -0
- package/esm/offline-ceremony.d.mts +127 -0
- package/esm/offline-ceremony.mjs +481 -0
- package/esm/ot.d.mts +193 -0
- package/esm/ot.mjs +726 -0
- package/esm/personal-vault.d.mts +1292 -0
- package/esm/personal-vault.mjs +3615 -0
- package/esm/personal.d.mts +10 -0
- package/esm/personal.mjs +11 -0
- package/esm/presign.d.mts +242 -0
- package/esm/presign.mjs +951 -0
- package/esm/rlp-eip1559.d.mts +75 -0
- package/esm/rlp-eip1559.mjs +293 -0
- package/esm/secp256k1-scalar.d.mts +141 -0
- package/esm/secp256k1-scalar.mjs +474 -0
- package/esm/sign.d.mts +113 -0
- package/esm/sign.mjs +225 -0
- package/esm/steel-mnemonic.d.mts +55 -0
- package/esm/steel-mnemonic.mjs +247 -0
- package/esm/tweak.d.mts +100 -0
- package/esm/tweak.mjs +168 -0
- package/esm/ves-backup.d.mts +296 -0
- package/esm/ves-backup.mjs +1025 -0
- package/esm/x402-agent-guard.d.mts +111 -0
- package/esm/x402-agent-guard.mjs +780 -0
- package/lib/bip39-english-wordlist.cjs +33 -0
- package/lib/bip39-english-wordlist.d.cts +11 -0
- package/lib/constants.cjs +264 -0
- package/lib/constants.d.cts +140 -0
- package/lib/dkg.cjs +910 -0
- package/lib/dkg.d.cts +279 -0
- package/lib/index.cjs +420 -0
- package/lib/index.d.cts +17 -0
- package/lib/mta.cjs +280 -0
- package/lib/mta.d.cts +63 -0
- package/lib/ocap-clear-signing.cjs +1176 -0
- package/lib/ocap-clear-signing.d.cts +125 -0
- package/lib/offline-ceremony.cjs +487 -0
- package/lib/offline-ceremony.d.cts +127 -0
- package/lib/ot.cjs +744 -0
- package/lib/ot.d.cts +193 -0
- package/lib/personal-vault.cjs +3725 -0
- package/lib/personal-vault.d.cts +1292 -0
- package/lib/personal.cjs +338 -0
- package/lib/personal.d.cts +10 -0
- package/lib/presign.cjs +954 -0
- package/lib/presign.d.cts +242 -0
- package/lib/rlp-eip1559.cjs +303 -0
- package/lib/rlp-eip1559.d.cts +75 -0
- package/lib/secp256k1-scalar.cjs +527 -0
- package/lib/secp256k1-scalar.d.cts +141 -0
- package/lib/sign.cjs +233 -0
- package/lib/sign.d.cts +113 -0
- package/lib/steel-mnemonic.cjs +253 -0
- package/lib/steel-mnemonic.d.cts +55 -0
- package/lib/tweak.cjs +178 -0
- package/lib/tweak.d.cts +100 -0
- package/lib/ves-backup.cjs +1053 -0
- package/lib/ves-backup.d.cts +296 -0
- package/lib/x402-agent-guard.cjs +788 -0
- package/lib/x402-agent-guard.d.cts +111 -0
- package/package.json +80 -4
- package/README.md +0 -3
package/esm/tweak.mjs
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { DST_CHILD_TWEAK_V1, DST_RULE_TWEAK_V1, FORBIDDEN_ONLINE_ROLE_ESCAPE_CANARY, MpcProtocolError, SECP256K1_N } from "./constants.mjs";
|
|
2
|
+
import { H_scalar, bytesToHex, decodePointCompressed, encodePointCompressed, hexToBytes, mulBaseG, normalizeHexBytes, scalarToBytes32, secp256k1, u64be, utf8Bytes } from "./secp256k1-scalar.mjs";
|
|
3
|
+
import { keccak_256 } from "@noble/hashes/sha3.js";
|
|
4
|
+
|
|
5
|
+
//#region src/tweak.ts
|
|
6
|
+
const ETH_ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
7
|
+
function toEip55ChecksumAddress(lowerHexWithoutPrefix) {
|
|
8
|
+
if (!/^[0-9a-f]{40}$/.test(lowerHexWithoutPrefix)) throw new MpcProtocolError("INVALID_ETH_ADDRESS", "Expected 40 lowercase hex chars");
|
|
9
|
+
const digestHex = bytesToHex(keccak_256(utf8Bytes(lowerHexWithoutPrefix)));
|
|
10
|
+
let out = "0x";
|
|
11
|
+
for (let i = 0; i < 40; i++) {
|
|
12
|
+
const ch = lowerHexWithoutPrefix[i];
|
|
13
|
+
out += Number.parseInt(digestHex[i], 16) >= 8 ? ch.toUpperCase() : ch;
|
|
14
|
+
}
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Validates an Ethereum `0x` address (rejects non-hex, all-uppercase, bad EIP-55 mixed-case
|
|
19
|
+
* checksums, and the zero address `0x0000...0000`) and returns canonical EIP-55 + lowercase forms.
|
|
20
|
+
*/
|
|
21
|
+
function parseStrictEthAddress(address) {
|
|
22
|
+
if (typeof address !== "string" || !ETH_ADDRESS_RE.test(address)) throw new MpcProtocolError("INVALID_ETH_ADDRESS", `Invalid Ethereum address format: ${String(address)}`);
|
|
23
|
+
const body = address.slice(2);
|
|
24
|
+
const lower = body.toLowerCase();
|
|
25
|
+
if (/^0+$/.test(lower)) throw new MpcProtocolError("INVALID_ETH_ADDRESS", "Zero Ethereum address is forbidden");
|
|
26
|
+
const hasLower = /[a-f]/.test(body);
|
|
27
|
+
const hasUpper = /[A-F]/.test(body);
|
|
28
|
+
if (hasUpper && !hasLower) throw new MpcProtocolError("INVALID_ETH_ADDRESS", "All-uppercase Ethereum address is invalid");
|
|
29
|
+
const checksumAddress = toEip55ChecksumAddress(lower);
|
|
30
|
+
if (hasUpper && hasLower && checksumAddress !== address) throw new MpcProtocolError("INVALID_ETH_ADDRESS", "EIP-55 checksum mismatch");
|
|
31
|
+
return {
|
|
32
|
+
checksumAddress,
|
|
33
|
+
lowercaseAddress: `0x${lower}`,
|
|
34
|
+
addressBytes20: hexToBytes(lower)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function pointToEthAddress(pointOrComp33) {
|
|
38
|
+
const pt = pointOrComp33 instanceof Uint8Array ? decodePointCompressed(pointOrComp33, false) : pointOrComp33;
|
|
39
|
+
if (pt.is0()) throw new MpcProtocolError("INVALID_POINT", "Cannot derive Ethereum address from infinity");
|
|
40
|
+
pt.assertValidity();
|
|
41
|
+
const addrLower = bytesToHex(keccak_256(pt.toBytes(false).subarray(1, 65)).subarray(12, 32));
|
|
42
|
+
if (/^0+$/.test(addrLower)) throw new MpcProtocolError("INVALID_ETH_ADDRESS", "Derived Ethereum address is zero");
|
|
43
|
+
return {
|
|
44
|
+
checksumAddress: toEip55ChecksumAddress(addrLower),
|
|
45
|
+
lowercaseAddress: `0x${addrLower}`
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function assertAllowedOnlineRole(role) {
|
|
49
|
+
if (typeof role !== "string" || role.trim().length === 0) throw new MpcProtocolError("INVALID_PARAMETER", "Role must be a non-empty string");
|
|
50
|
+
if (role === FORBIDDEN_ONLINE_ROLE_ESCAPE_CANARY) throw new MpcProtocolError("FORBIDDEN_ONLINE_ROLE", `Role "${FORBIDDEN_ONLINE_ROLE_ESCAPE_CANARY}" is hard-banned in online MPC derivation and signing`);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Applies a non-hardened additive scalar tweak `P_child = P_root + t_tweak * G`,
|
|
54
|
+
* strictly rejecting `t_tweak == 0`, `t_tweak >= n`, or `P_child == O`.
|
|
55
|
+
*/
|
|
56
|
+
function applyAdditiveTweak(rootPublicKey, tweakScalar, tweakMode, derivationMeta) {
|
|
57
|
+
const pRoot = rootPublicKey instanceof Uint8Array ? decodePointCompressed(rootPublicKey, false) : rootPublicKey;
|
|
58
|
+
if (pRoot.is0()) throw new MpcProtocolError("INVALID_POINT", "Root public key cannot be O");
|
|
59
|
+
if (typeof tweakScalar !== "bigint" || tweakScalar <= 0n || tweakScalar >= SECP256K1_N) throw new MpcProtocolError("DEGENERATE_TWEAK", "Additive tweak scalar must satisfy 1 <= t_tweak < n");
|
|
60
|
+
const pChild = pRoot.add(mulBaseG(tweakScalar));
|
|
61
|
+
if (pChild.is0()) throw new MpcProtocolError("DEGENERATE_TWEAK", "Derived child public key collapsed to point at infinity O");
|
|
62
|
+
const childPublicKeyComp33 = encodePointCompressed(pChild);
|
|
63
|
+
const tweakBytes32 = scalarToBytes32(tweakScalar);
|
|
64
|
+
const { checksumAddress, lowercaseAddress } = pointToEthAddress(pChild);
|
|
65
|
+
const derivationSpec = derivationMeta?.kind === "role-bound" ? {
|
|
66
|
+
tweakMode: "role-bound",
|
|
67
|
+
role: derivationMeta.role,
|
|
68
|
+
ethChainId: derivationMeta.ethChainId,
|
|
69
|
+
tweakLabel: derivationMeta.tweakLabel,
|
|
70
|
+
childPublicKeyComp33
|
|
71
|
+
} : derivationMeta?.kind === "rule-bound" ? {
|
|
72
|
+
tweakMode: "rule-bound",
|
|
73
|
+
controllerDid: derivationMeta.controllerDid,
|
|
74
|
+
ethChainId: derivationMeta.ethChainId,
|
|
75
|
+
ruleHash: derivationMeta.ruleHashBytes32,
|
|
76
|
+
childPublicKeyComp33
|
|
77
|
+
} : {
|
|
78
|
+
tweakMode: "untweaked",
|
|
79
|
+
childPublicKeyComp33
|
|
80
|
+
};
|
|
81
|
+
return {
|
|
82
|
+
tweakMode,
|
|
83
|
+
tweakScalar,
|
|
84
|
+
tweakBytes32,
|
|
85
|
+
tweakHex: `0x${bytesToHex(tweakBytes32)}`,
|
|
86
|
+
childPoint: pChild,
|
|
87
|
+
childPublicKeyComp33,
|
|
88
|
+
ethAddress: checksumAddress,
|
|
89
|
+
ethAddressLower: lowercaseAddress,
|
|
90
|
+
derivationSpec
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function deriveUntweakedChild(rootPublicKey) {
|
|
94
|
+
const pRoot = rootPublicKey instanceof Uint8Array ? decodePointCompressed(rootPublicKey, false) : rootPublicKey;
|
|
95
|
+
if (pRoot.is0()) throw new MpcProtocolError("INVALID_POINT", "Root public key cannot be O");
|
|
96
|
+
const childPublicKeyComp33 = encodePointCompressed(pRoot);
|
|
97
|
+
const tweakBytes32 = new Uint8Array(32);
|
|
98
|
+
const { checksumAddress, lowercaseAddress } = pointToEthAddress(pRoot);
|
|
99
|
+
return {
|
|
100
|
+
tweakMode: "untweaked",
|
|
101
|
+
tweakScalar: 0n,
|
|
102
|
+
tweakBytes32,
|
|
103
|
+
tweakHex: `0x${bytesToHex(tweakBytes32)}`,
|
|
104
|
+
childPoint: pRoot,
|
|
105
|
+
childPublicKeyComp33,
|
|
106
|
+
ethAddress: checksumAddress,
|
|
107
|
+
ethAddressLower: lowercaseAddress,
|
|
108
|
+
derivationSpec: {
|
|
109
|
+
tweakMode: "untweaked",
|
|
110
|
+
childPublicKeyComp33
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* `role-bound` EOA child derivation (`design.md` §4.2):
|
|
116
|
+
* `t_tweak = H_scalar("ARC-MPC-CHILD-TWEAK-V1", P_root^comp33, utf8(rootId), utf8(role), u64be(ethChainId), utf8(tweakLabel))`.
|
|
117
|
+
*/
|
|
118
|
+
function deriveRoleBoundChild(params) {
|
|
119
|
+
const { rootPublicKey, rootId, role, ethChainId, tweakLabel } = params;
|
|
120
|
+
if (typeof rootId !== "string" || rootId.length === 0) throw new MpcProtocolError("INVALID_PARAMETER", "rootId must be non-empty");
|
|
121
|
+
assertAllowedOnlineRole(role);
|
|
122
|
+
if (typeof tweakLabel !== "string" || tweakLabel.length === 0) throw new MpcProtocolError("INVALID_PARAMETER", "tweakLabel must be non-empty");
|
|
123
|
+
const pRoot = rootPublicKey instanceof Uint8Array ? decodePointCompressed(rootPublicKey, false) : rootPublicKey;
|
|
124
|
+
return applyAdditiveTweak(pRoot, H_scalar(DST_CHILD_TWEAK_V1, encodePointCompressed(pRoot), utf8Bytes(rootId), utf8Bytes(role), u64be(ethChainId), utf8Bytes(tweakLabel)), "role-bound", {
|
|
125
|
+
kind: "role-bound",
|
|
126
|
+
role,
|
|
127
|
+
ethChainId,
|
|
128
|
+
tweakLabel
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* `rule-bound` EOA child derivation (`design.md` §4.2):
|
|
133
|
+
* `t_tweak = H_scalar("ARC-MPC-RULE-TWEAK-V1", P_root^comp33, utf8(rootId), utf8(controllerDid), u64be(ethChainId), bytes32(ruleHash))`.
|
|
134
|
+
*/
|
|
135
|
+
function deriveRuleBoundChild(params) {
|
|
136
|
+
const { rootPublicKey, rootId, controllerDid, ethChainId, ruleHash } = params;
|
|
137
|
+
if (typeof rootId !== "string" || rootId.length === 0) throw new MpcProtocolError("INVALID_PARAMETER", "rootId must be non-empty");
|
|
138
|
+
if (typeof controllerDid !== "string" || controllerDid.length === 0) throw new MpcProtocolError("INVALID_PARAMETER", "controllerDid must be non-empty");
|
|
139
|
+
const ruleHashBytes32 = normalizeHexBytes(ruleHash, 32);
|
|
140
|
+
const pRoot = rootPublicKey instanceof Uint8Array ? decodePointCompressed(rootPublicKey, false) : rootPublicKey;
|
|
141
|
+
return applyAdditiveTweak(pRoot, H_scalar(DST_RULE_TWEAK_V1, encodePointCompressed(pRoot), utf8Bytes(rootId), utf8Bytes(controllerDid), u64be(ethChainId), ruleHashBytes32), "rule-bound", {
|
|
142
|
+
kind: "rule-bound",
|
|
143
|
+
controllerDid,
|
|
144
|
+
ethChainId,
|
|
145
|
+
ruleHashBytes32
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Recovers the EIP-55 Ethereum address from a 32-byte digest and EIP-2 low-S `(r, s, yParity)`
|
|
150
|
+
* signature, matching Solidity `ecrecover` and Type-2 EIP-1559 transaction recovery.
|
|
151
|
+
*/
|
|
152
|
+
function ecrecoverEthAddress(params) {
|
|
153
|
+
const { msgDigest32, r, s, yParity } = params;
|
|
154
|
+
if (!(msgDigest32 instanceof Uint8Array) || msgDigest32.length !== 32) throw new MpcProtocolError("INVALID_PARAMETER", "msgDigest32 must be 32 bytes");
|
|
155
|
+
if (yParity !== 0 && yParity !== 1) throw new MpcProtocolError("INVALID_PARAMETER", "yParity must be 0 or 1");
|
|
156
|
+
const sig = new secp256k1.Signature(r, s, yParity);
|
|
157
|
+
if (sig.hasHighS()) throw new MpcProtocolError("SIGN_AGGREGATION_FAILED", "High-S signature rejected by EIP-2");
|
|
158
|
+
const recoveredPoint = sig.recoverPublicKey(msgDigest32);
|
|
159
|
+
const { checksumAddress, lowercaseAddress } = pointToEthAddress(recoveredPoint);
|
|
160
|
+
return {
|
|
161
|
+
recoveredPoint,
|
|
162
|
+
checksumAddress,
|
|
163
|
+
lowercaseAddress
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
//#endregion
|
|
168
|
+
export { applyAdditiveTweak, assertAllowedOnlineRole, deriveRoleBoundChild, deriveRuleBoundChild, deriveUntweakedChild, ecrecoverEthAddress, parseStrictEthAddress, pointToEthAddress, toEip55ChecksumAddress };
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { RandomBytesFn, Secp256k1Point } from "./secp256k1-scalar.mjs";
|
|
2
|
+
import { ColdBackupDealerInput, ColdBackupPlugin, DkgCeremonyConfig } from "./dkg.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/ves-backup.d.ts
|
|
5
|
+
declare const VES_CHUNKS_PER_SHARE: 16;
|
|
6
|
+
declare const VES_BITS_PER_CHUNK: 16;
|
|
7
|
+
declare const VES_BITS_PER_SHARE: 256;
|
|
8
|
+
declare const VES_MAX_LIMB_VALUE: 65535;
|
|
9
|
+
declare const VES_MAX_SUMMED_LIMB: number;
|
|
10
|
+
declare const VES_BIT_RECORD_BYTES: 162;
|
|
11
|
+
declare const VES_LINEAR_DLEQ_BYTES: 98;
|
|
12
|
+
declare const VES_GUARDIAN_BUNDLE_BYTES: number;
|
|
13
|
+
interface ParsedGuardianBundle {
|
|
14
|
+
readonly guardianIndex: number;
|
|
15
|
+
readonly rawBundleBytes: Uint8Array;
|
|
16
|
+
}
|
|
17
|
+
interface ParsedDealerVesContribution {
|
|
18
|
+
readonly dealerSlot: number;
|
|
19
|
+
readonly tCold: number;
|
|
20
|
+
readonly nCold: number;
|
|
21
|
+
readonly coldCommitmentsComp33: ReadonlyArray<Uint8Array>;
|
|
22
|
+
readonly guardianBundles: ReadonlyArray<ParsedGuardianBundle>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Solves `targetPoint == v * G` for `0 <= v <= maxBound` using Baby-Step Giant-Step (`M = 680`).
|
|
26
|
+
*/
|
|
27
|
+
declare function solveDiscreteLogBsgs(targetPoint: Secp256k1Point, maxBound?: number): number;
|
|
28
|
+
/**
|
|
29
|
+
* Creates dealer `i`'s Direct Bit-ElGamal VES contribution across all `k = 1..nCold` guardians.
|
|
30
|
+
*/
|
|
31
|
+
declare function createNodeColdVesContribution(input: ColdBackupDealerInput, options?: {
|
|
32
|
+
rng?: RandomBytesFn;
|
|
33
|
+
}): Uint8Array;
|
|
34
|
+
/**
|
|
35
|
+
* Verifies dealer `i`'s Direct Bit-ElGamal VES contribution (all 256 CDS bit OR-proofs + linear DLEQ
|
|
36
|
+
* per guardian).
|
|
37
|
+
*/
|
|
38
|
+
declare function verifyNodeColdVesContribution(input: {
|
|
39
|
+
readonly ctxDkg32: Uint8Array;
|
|
40
|
+
readonly dealerSlot: number;
|
|
41
|
+
readonly coldCommitmentsComp33: ReadonlyArray<Uint8Array>;
|
|
42
|
+
readonly guardianPublicKeysComp33: ReadonlyArray<Uint8Array>;
|
|
43
|
+
readonly payload: Uint8Array;
|
|
44
|
+
}): boolean;
|
|
45
|
+
interface ParsedVesRecoveryPackage {
|
|
46
|
+
readonly protocolVersion: number;
|
|
47
|
+
readonly nParties: number;
|
|
48
|
+
readonly tCold: number;
|
|
49
|
+
readonly nCold: number;
|
|
50
|
+
readonly ctxDkg32: Uint8Array;
|
|
51
|
+
readonly hDkg32: Uint8Array;
|
|
52
|
+
readonly rootPublicKeyComp33: Uint8Array;
|
|
53
|
+
readonly aggColdCommitmentsComp33: ReadonlyArray<Uint8Array>;
|
|
54
|
+
readonly guardianColdPublicSharesComp33: ReadonlyArray<Uint8Array>;
|
|
55
|
+
readonly guardianPublicKeysComp33: ReadonlyArray<Uint8Array>;
|
|
56
|
+
readonly dealerContributions: ReadonlyArray<{
|
|
57
|
+
readonly dealerSlot: number;
|
|
58
|
+
readonly payload: Uint8Array;
|
|
59
|
+
readonly parsed: ParsedDealerVesContribution;
|
|
60
|
+
}>;
|
|
61
|
+
}
|
|
62
|
+
declare function parseRecoveryPackageBytes(recoveryPackageBytes: Uint8Array): ParsedVesRecoveryPackage;
|
|
63
|
+
/**
|
|
64
|
+
* Aggregates all `nParties` verified dealer VES payloads into a canonical binary recovery package
|
|
65
|
+
* (`< MAX_RECOVERY_PACKAGE_BYTES = 2 MiB`) and returns `(recoveryPackageBytes, sha256(recoveryPackageBytes))`.
|
|
66
|
+
*/
|
|
67
|
+
declare function aggregateRecoveryPackage(input: {
|
|
68
|
+
readonly ctxDkg32: Uint8Array;
|
|
69
|
+
readonly hDkg32: Uint8Array;
|
|
70
|
+
readonly rootPublicKeyComp33: Uint8Array;
|
|
71
|
+
readonly aggColdCommitmentsComp33: ReadonlyArray<Uint8Array>;
|
|
72
|
+
readonly guardianColdPublicSharesComp33: ReadonlyArray<Uint8Array>;
|
|
73
|
+
readonly guardianPublicKeysComp33: ReadonlyArray<Uint8Array>;
|
|
74
|
+
readonly dealerPayloads: ReadonlyArray<{
|
|
75
|
+
readonly dealerSlot: number;
|
|
76
|
+
readonly payload: Uint8Array;
|
|
77
|
+
}>;
|
|
78
|
+
}): {
|
|
79
|
+
readonly recoveryPackageBytes: Uint8Array;
|
|
80
|
+
readonly recoveryPackageHash32: Uint8Array;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Self-contained verification of a serialized Direct Bit-ElGamal recovery package:
|
|
84
|
+
* - Enforces `< MAX_RECOVERY_PACKAGE_BYTES` (`< 2 MiB`) and canonical byte layout.
|
|
85
|
+
* - Verifies `C^{cold}_0 == P_root`, distinct valid `EK_k`, and `Y_k == \sum_l k^l C^{cold}_l`.
|
|
86
|
+
* - Verifies EVERY dealer's 256-bit CDS OR-proofs + linear DLEQ `\pi^{lin}_{i,k}` and confirms
|
|
87
|
+
* `\sum_{i=1}^{nParties} C_{i,l} == C^{cold}_l` across all `l = 0..tCold-1`.
|
|
88
|
+
*/
|
|
89
|
+
declare function verifyRecoveryPackage(recoveryPackageBytes: Uint8Array, expected?: {
|
|
90
|
+
readonly ctxDkg32: Uint8Array;
|
|
91
|
+
readonly rootPublicKeyComp33: Uint8Array;
|
|
92
|
+
readonly aggColdCommitmentsComp33: ReadonlyArray<Uint8Array>;
|
|
93
|
+
readonly guardianPublicKeysComp33: ReadonlyArray<Uint8Array>;
|
|
94
|
+
}): boolean;
|
|
95
|
+
declare class DirectBitElGamalVesPlugin implements ColdBackupPlugin {
|
|
96
|
+
private readonly rng;
|
|
97
|
+
constructor(options?: {
|
|
98
|
+
rng?: RandomBytesFn;
|
|
99
|
+
});
|
|
100
|
+
createDealerContribution(input: ColdBackupDealerInput): Uint8Array;
|
|
101
|
+
verifyDealerContribution(input: {
|
|
102
|
+
readonly ctxDkg32: Uint8Array;
|
|
103
|
+
readonly dealerSlot: number;
|
|
104
|
+
readonly coldCommitmentsComp33: ReadonlyArray<Uint8Array>;
|
|
105
|
+
readonly guardianPublicKeysComp33: ReadonlyArray<Uint8Array>;
|
|
106
|
+
readonly payload: Uint8Array;
|
|
107
|
+
}): boolean;
|
|
108
|
+
aggregateRecoveryPackage(input: {
|
|
109
|
+
readonly ctxDkg32: Uint8Array;
|
|
110
|
+
readonly hDkg32: Uint8Array;
|
|
111
|
+
readonly rootPublicKeyComp33: Uint8Array;
|
|
112
|
+
readonly aggColdCommitmentsComp33: ReadonlyArray<Uint8Array>;
|
|
113
|
+
readonly guardianColdPublicSharesComp33: ReadonlyArray<Uint8Array>;
|
|
114
|
+
readonly guardianPublicKeysComp33: ReadonlyArray<Uint8Array>;
|
|
115
|
+
readonly dealerPayloads: ReadonlyArray<{
|
|
116
|
+
readonly dealerSlot: number;
|
|
117
|
+
readonly payload: Uint8Array;
|
|
118
|
+
}>;
|
|
119
|
+
}): {
|
|
120
|
+
readonly recoveryPackageBytes: Uint8Array;
|
|
121
|
+
readonly recoveryPackageHash32: Uint8Array;
|
|
122
|
+
};
|
|
123
|
+
verifyRecoveryPackage(recoveryPackageBytes: Uint8Array, expected?: {
|
|
124
|
+
readonly ctxDkg32: Uint8Array;
|
|
125
|
+
readonly rootPublicKeyComp33: Uint8Array;
|
|
126
|
+
readonly aggColdCommitmentsComp33: ReadonlyArray<Uint8Array>;
|
|
127
|
+
readonly guardianPublicKeysComp33: ReadonlyArray<Uint8Array>;
|
|
128
|
+
}): boolean;
|
|
129
|
+
}
|
|
130
|
+
interface DecryptedGuardianColdShare {
|
|
131
|
+
readonly guardianIndex: number;
|
|
132
|
+
readonly coldShareBytes32: Uint8Array;
|
|
133
|
+
readonly coldPublicShareComp33: Uint8Array;
|
|
134
|
+
readonly decodedLimbs16: ReadonlyArray<number>;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Verifies the recovery package (unless `skipPackageProofVerification` is never set — always verified!),
|
|
138
|
+
* aggregates `(R^{agg}_{k,m}, S^{agg}_{k,m})` across all `nParties` dealers, solves each of the 16
|
|
139
|
+
* summed limbs in `[0, nParties * 65535]` via `BSGS_M = 680`, reduces `\sum_{m=0}^{15} Y_{k,m} 2^{16m} mod n`,
|
|
140
|
+
* asserts `g(k) * G == Y_k`, and wipes `guardianSecretKeyBytes32` in `finally` (`wipeSecretKeyInput` default `true`).
|
|
141
|
+
*/
|
|
142
|
+
declare function decryptGuardianColdShareBsgs(params: {
|
|
143
|
+
readonly recoveryPackageBytes: Uint8Array;
|
|
144
|
+
readonly guardianIndex: number;
|
|
145
|
+
readonly guardianSecretKeyBytes32: Uint8Array;
|
|
146
|
+
readonly expectedManifest?: {
|
|
147
|
+
readonly ctxDkg32: Uint8Array;
|
|
148
|
+
readonly rootPublicKeyComp33: Uint8Array;
|
|
149
|
+
readonly aggColdCommitmentsComp33: ReadonlyArray<Uint8Array>;
|
|
150
|
+
readonly guardianPublicKeysComp33: ReadonlyArray<Uint8Array>;
|
|
151
|
+
};
|
|
152
|
+
readonly wipeSecretKeyInput?: boolean;
|
|
153
|
+
}): DecryptedGuardianColdShare;
|
|
154
|
+
interface PrintableManifestCard {
|
|
155
|
+
readonly version: 2;
|
|
156
|
+
readonly clusterId: string;
|
|
157
|
+
readonly rootId: string;
|
|
158
|
+
readonly keyEpoch: string;
|
|
159
|
+
readonly t: number;
|
|
160
|
+
readonly nParties: number;
|
|
161
|
+
readonly tCold: number;
|
|
162
|
+
readonly nCold: number;
|
|
163
|
+
readonly ctxDkgHex: string;
|
|
164
|
+
readonly hDkgHex: string;
|
|
165
|
+
readonly rootPublicKeyHex: string;
|
|
166
|
+
readonly rootEthAddress: string;
|
|
167
|
+
readonly escapeColdWallet: string;
|
|
168
|
+
readonly coldFeldmanCommitmentsHex: ReadonlyArray<string>;
|
|
169
|
+
readonly guardianColdPublicSharesHex: ReadonlyArray<string>;
|
|
170
|
+
readonly guardianPublicKeysHex: ReadonlyArray<string>;
|
|
171
|
+
readonly recoveryPackageSha256Hex: string;
|
|
172
|
+
readonly printableText: string;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Exports a deterministic, human-verifiable `PrintableManifestCard` pinning `ctxDkg`, `hDkg`,
|
|
176
|
+
* `rootPublicKey`, `escapeColdWallet`, `C^{cold}_{0..t_c-1}`, `Y_{1..n_c}`, `EK_{1..n_c}`, and
|
|
177
|
+
* `sha256(recoveryPackageBytes)` for air-gapped custodian and disaster-recovery verification.
|
|
178
|
+
*/
|
|
179
|
+
declare function exportPrintableManifestCard(params: {
|
|
180
|
+
readonly clusterId: string;
|
|
181
|
+
readonly rootId: string;
|
|
182
|
+
readonly keyEpoch: bigint;
|
|
183
|
+
readonly t: number;
|
|
184
|
+
readonly nParties: number;
|
|
185
|
+
readonly tCold: number;
|
|
186
|
+
readonly nCold: number;
|
|
187
|
+
readonly ctxDkg32: Uint8Array;
|
|
188
|
+
readonly hDkg32: Uint8Array;
|
|
189
|
+
readonly rootPublicKeyComp33: Uint8Array;
|
|
190
|
+
readonly escapeColdWallet: string;
|
|
191
|
+
readonly coldFeldmanCommitmentsComp33: ReadonlyArray<Uint8Array>;
|
|
192
|
+
readonly guardianColdPublicSharesComp33: ReadonlyArray<Uint8Array>;
|
|
193
|
+
readonly guardianPublicKeysComp33: ReadonlyArray<Uint8Array>;
|
|
194
|
+
readonly recoveryPackageHash32: Uint8Array;
|
|
195
|
+
}): PrintableManifestCard;
|
|
196
|
+
/**
|
|
197
|
+
* Validates full internal & human-readable (`printableText`) self-consistency of a `PrintableManifestCard`:
|
|
198
|
+
* - Enforces version, integer bounds, EIP-55 `escapeColdWallet` & `rootEthAddress`, `C^{cold}_0 == P_root`,
|
|
199
|
+
* distinct `EK_k`, and `Y_k == \sum_l k^l C^{cold}_l`.
|
|
200
|
+
* - Recomputes canonical `printableText` via `exportPrintableManifestCard` and rejects any split-view
|
|
201
|
+
* mismatch between JSON fields (such as `escapeColdWallet`) and `printableText`.
|
|
202
|
+
*/
|
|
203
|
+
declare function validatePrintableManifestCard(manifest: PrintableManifestCard): void;
|
|
204
|
+
declare function verifyManifestAgainstDkgConfig(manifest: PrintableManifestCard, config: DkgCeremonyConfig): boolean;
|
|
205
|
+
declare function verifyManifestAgainstRecoveryPackage(manifest: PrintableManifestCard, recoveryPackageBytes: Uint8Array): boolean;
|
|
206
|
+
interface CanaryChallengePeerApproval {
|
|
207
|
+
readonly slot: number;
|
|
208
|
+
readonly noncePointHex: string;
|
|
209
|
+
readonly responseHex: string;
|
|
210
|
+
}
|
|
211
|
+
interface CanaryChallengeBundle {
|
|
212
|
+
readonly version: 2;
|
|
213
|
+
readonly rootId: string;
|
|
214
|
+
readonly keyEpoch: string;
|
|
215
|
+
readonly ctxDkgHex: string;
|
|
216
|
+
readonly hDkgHex: string;
|
|
217
|
+
readonly challengeId: string;
|
|
218
|
+
readonly challengeNonceHex: string;
|
|
219
|
+
readonly issuedAtSec: number;
|
|
220
|
+
readonly expiresAtSec: number;
|
|
221
|
+
readonly nCold: number;
|
|
222
|
+
readonly guardianColdPublicSharesHex: ReadonlyArray<string>;
|
|
223
|
+
readonly peerApprovals?: ReadonlyArray<CanaryChallengePeerApproval>;
|
|
224
|
+
}
|
|
225
|
+
declare function computeCanaryChallengeDigest32(bundle: Omit<CanaryChallengeBundle, 'peerApprovals'>): Uint8Array;
|
|
226
|
+
declare function assertChallengeBundleMatchesManifest(challengeBundle: CanaryChallengeBundle, manifestCard: PrintableManifestCard): void;
|
|
227
|
+
declare function signCanaryChallengeApproval(params: {
|
|
228
|
+
readonly bundle: Omit<CanaryChallengeBundle, 'peerApprovals'>;
|
|
229
|
+
readonly slot: number;
|
|
230
|
+
readonly rosterSigningSecretBytes32: Uint8Array;
|
|
231
|
+
readonly rng?: RandomBytesFn;
|
|
232
|
+
}): CanaryChallengePeerApproval;
|
|
233
|
+
declare function verifyCanaryChallengeBundle(bundle: CanaryChallengeBundle, options?: {
|
|
234
|
+
readonly rosterVerifyKeysComp33BySlot?: ReadonlyMap<number, Uint8Array>;
|
|
235
|
+
readonly requiredQuorumT?: number;
|
|
236
|
+
readonly trustedNowSec?: number;
|
|
237
|
+
}): boolean;
|
|
238
|
+
interface ColdShardSchnorrPok {
|
|
239
|
+
readonly guardianIndex: number;
|
|
240
|
+
readonly coldPublicShareHex: string;
|
|
241
|
+
readonly noncePointHex: string;
|
|
242
|
+
readonly responseHex: string;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Generates Custodian `k`'s Schnorr PoK `\pi^{cold}_k` over `(ctxDkg32, u16be(guardianIndex), challengeNonce32)`
|
|
246
|
+
* under cold share `g(k)` (`Y_k = g(k) * G`), proving physical steel-plate possession in zero knowledge
|
|
247
|
+
* WITHOUT revealing `g(k)` or reconstructing `x_root`.
|
|
248
|
+
*
|
|
249
|
+
* Strictly verifies `g(k) * G == Y_k` BEFORE generating the proof whenever `expectedColdPublicShare` is supplied.
|
|
250
|
+
*/
|
|
251
|
+
declare function createColdShardSchnorrPok(params: {
|
|
252
|
+
readonly ctxDkg: Uint8Array | string;
|
|
253
|
+
readonly guardianIndex: number;
|
|
254
|
+
readonly challengeNonce: Uint8Array | string;
|
|
255
|
+
readonly coldShareBytes32: Uint8Array;
|
|
256
|
+
readonly expectedColdPublicShare?: Uint8Array | string;
|
|
257
|
+
readonly rng?: RandomBytesFn;
|
|
258
|
+
readonly wipeColdShareInput?: boolean;
|
|
259
|
+
}): ColdShardSchnorrPok;
|
|
260
|
+
declare function verifyColdShardSchnorrPok(params: {
|
|
261
|
+
readonly ctxDkg: Uint8Array | string;
|
|
262
|
+
readonly challengeNonce: Uint8Array | string;
|
|
263
|
+
readonly expectedColdPublicShare: Uint8Array | string;
|
|
264
|
+
readonly shardProof: ColdShardSchnorrPok;
|
|
265
|
+
}): boolean;
|
|
266
|
+
interface CanaryActivationCert {
|
|
267
|
+
readonly version: 2;
|
|
268
|
+
readonly clusterChallengeBundle: CanaryChallengeBundle;
|
|
269
|
+
readonly shardProofs: ReadonlyArray<ColdShardSchnorrPok>;
|
|
270
|
+
}
|
|
271
|
+
declare function assembleCanaryActivationCert(params: {
|
|
272
|
+
readonly clusterChallengeBundle: CanaryChallengeBundle;
|
|
273
|
+
readonly shardProofs: ReadonlyArray<ColdShardSchnorrPok>;
|
|
274
|
+
readonly manifestCard?: PrintableManifestCard;
|
|
275
|
+
}): CanaryActivationCert;
|
|
276
|
+
/**
|
|
277
|
+
* Verifies a self-verifying `CanaryActivationCert` (`design.md` §5.2):
|
|
278
|
+
* - Validates `clusterChallengeBundle` metadata, TTL (`<= 900s`), optional `trustedNowSec`, and
|
|
279
|
+
* optional `>= t` HSM roster approvals.
|
|
280
|
+
* - Requires ALL `nCold` (`3/3` default) distinct guardian Schnorr PoKs `\pi^{cold}_{1..nCold}`
|
|
281
|
+
* verified against `guardianColdPublicSharesComp33` (`Y_{1..nCold}`) and optional `coldFeldmanCommitmentsComp33`.
|
|
282
|
+
*/
|
|
283
|
+
declare function verifyCanaryActivationCert(cert: CanaryActivationCert, expected: {
|
|
284
|
+
readonly ctxDkg: Uint8Array | string;
|
|
285
|
+
readonly hDkg?: Uint8Array | string;
|
|
286
|
+
readonly rootId?: string;
|
|
287
|
+
readonly keyEpoch?: bigint;
|
|
288
|
+
readonly nCold: number;
|
|
289
|
+
readonly guardianColdPublicSharesComp33: ReadonlyArray<Uint8Array | string>;
|
|
290
|
+
readonly coldFeldmanCommitmentsComp33?: ReadonlyArray<Uint8Array | string>;
|
|
291
|
+
readonly rosterVerifyKeysComp33BySlot?: ReadonlyMap<number, Uint8Array>;
|
|
292
|
+
readonly requiredQuorumT?: number;
|
|
293
|
+
readonly trustedNowSec?: number;
|
|
294
|
+
}): boolean;
|
|
295
|
+
//#endregion
|
|
296
|
+
export { CanaryActivationCert, CanaryChallengeBundle, CanaryChallengePeerApproval, ColdShardSchnorrPok, DecryptedGuardianColdShare, DirectBitElGamalVesPlugin, ParsedVesRecoveryPackage, PrintableManifestCard, VES_BITS_PER_CHUNK, VES_BITS_PER_SHARE, VES_BIT_RECORD_BYTES, VES_CHUNKS_PER_SHARE, VES_GUARDIAN_BUNDLE_BYTES, VES_LINEAR_DLEQ_BYTES, VES_MAX_LIMB_VALUE, VES_MAX_SUMMED_LIMB, aggregateRecoveryPackage, assembleCanaryActivationCert, assertChallengeBundleMatchesManifest, computeCanaryChallengeDigest32, createColdShardSchnorrPok, createNodeColdVesContribution, decryptGuardianColdShareBsgs, exportPrintableManifestCard, parseRecoveryPackageBytes, signCanaryChallengeApproval, solveDiscreteLogBsgs, validatePrintableManifestCard, verifyCanaryActivationCert, verifyCanaryChallengeBundle, verifyColdShardSchnorrPok, verifyManifestAgainstDkgConfig, verifyManifestAgainstRecoveryPackage, verifyNodeColdVesContribution, verifyRecoveryPackage };
|