@ocap/mpc-hsm 1.33.6 → 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.
Files changed (56) hide show
  1. package/esm/bip39-english-wordlist.d.mts +11 -0
  2. package/esm/bip39-english-wordlist.mjs +31 -0
  3. package/esm/constants.d.mts +66 -2
  4. package/esm/constants.mjs +65 -1
  5. package/esm/dkg.mjs +2 -2
  6. package/esm/index.d.mts +11 -3
  7. package/esm/index.mjs +11 -3
  8. package/esm/ocap-clear-signing.d.mts +125 -0
  9. package/esm/ocap-clear-signing.mjs +1170 -0
  10. package/esm/offline-ceremony.d.mts +127 -0
  11. package/esm/offline-ceremony.mjs +481 -0
  12. package/esm/ot.d.mts +7 -1
  13. package/esm/ot.mjs +149 -16
  14. package/esm/personal-vault.d.mts +1292 -0
  15. package/esm/personal-vault.mjs +3615 -0
  16. package/esm/personal.d.mts +10 -0
  17. package/esm/personal.mjs +11 -0
  18. package/esm/presign.mjs +1 -1
  19. package/esm/rlp-eip1559.d.mts +75 -0
  20. package/esm/rlp-eip1559.mjs +293 -0
  21. package/esm/secp256k1-scalar.d.mts +1 -1
  22. package/esm/secp256k1-scalar.mjs +14 -5
  23. package/esm/steel-mnemonic.d.mts +55 -0
  24. package/esm/steel-mnemonic.mjs +247 -0
  25. package/esm/ves-backup.d.mts +296 -0
  26. package/esm/ves-backup.mjs +1025 -0
  27. package/esm/x402-agent-guard.d.mts +111 -0
  28. package/esm/x402-agent-guard.mjs +780 -0
  29. package/lib/bip39-english-wordlist.cjs +33 -0
  30. package/lib/bip39-english-wordlist.d.cts +11 -0
  31. package/lib/constants.cjs +128 -0
  32. package/lib/constants.d.cts +66 -2
  33. package/lib/dkg.cjs +2 -2
  34. package/lib/index.cjs +249 -0
  35. package/lib/index.d.cts +11 -3
  36. package/lib/ocap-clear-signing.cjs +1176 -0
  37. package/lib/ocap-clear-signing.d.cts +125 -0
  38. package/lib/offline-ceremony.cjs +487 -0
  39. package/lib/offline-ceremony.d.cts +127 -0
  40. package/lib/ot.cjs +150 -15
  41. package/lib/ot.d.cts +7 -1
  42. package/lib/personal-vault.cjs +3725 -0
  43. package/lib/personal-vault.d.cts +1292 -0
  44. package/lib/personal.cjs +338 -0
  45. package/lib/personal.d.cts +10 -0
  46. package/lib/presign.cjs +1 -1
  47. package/lib/rlp-eip1559.cjs +303 -0
  48. package/lib/rlp-eip1559.d.cts +75 -0
  49. package/lib/secp256k1-scalar.cjs +14 -5
  50. package/lib/steel-mnemonic.cjs +253 -0
  51. package/lib/steel-mnemonic.d.cts +55 -0
  52. package/lib/ves-backup.cjs +1053 -0
  53. package/lib/ves-backup.d.cts +296 -0
  54. package/lib/x402-agent-guard.cjs +788 -0
  55. package/lib/x402-agent-guard.d.cts +111 -0
  56. package/package.json +6 -1
@@ -0,0 +1,247 @@
1
+ import { MAX_MPC_CLUSTER_NODES, MpcProtocolError, SECP256K1_N } from "./constants.mjs";
2
+ import { addModN, bytes32ToScalarNonZero, bytesToBigIntBE, concatBytes, decodePointCompressed, encodePointCompressed, evaluateFeldmanCommitments, mulBaseG, normalizeHexBytes, scalarToBytes32, u32be, u8, utf8Bytes, zeroizeBytes } from "./secp256k1-scalar.mjs";
3
+ import { BIP39_ENGLISH_WORDLIST, BIP39_ENGLISH_WORD_TO_INDEX } from "./bip39-english-wordlist.mjs";
4
+ import { pointToEthAddress } from "./tweak.mjs";
5
+ import { sha256, sha512 } from "@noble/hashes/sha2.js";
6
+ import { hmac } from "@noble/hashes/hmac.js";
7
+ import { pbkdf2 } from "@noble/hashes/pbkdf2.js";
8
+
9
+ //#region src/steel-mnemonic.ts
10
+ /**
11
+ * Pure 3-Plate 24-Word Standard `BIP-39` Stainless-Steel Cold Backup (`design.md` §5.2):
12
+ * - ZERO human-memorized passphrases (`25th word`) anywhere in cold-backup encoding, decoding, or derivation.
13
+ * - Standard 256-bit entropy (`coldShareBytes32` in `[1, secp256k1.n - 1]`) + 8-bit `SHA-256` BIP-39 checksum
14
+ * -> 24 lowercase English BIP-39 words (`Plate A`, `Plate B`, `Plate C`).
15
+ * - Feldman index identification (`g(k) * G == Y_k`) and 24th-word 8-sibling `m/44'/60'/0'/0/0` decoy address
16
+ * enumeration for outgoing-nonce physical-burglar tripwires.
17
+ */
18
+ const BIP44_ETH_STANDARD_PATH = "m/44'/60'/0'/0/0";
19
+ const BIP44_ETH_INDICES = [
20
+ 2147483692,
21
+ 2147483708,
22
+ 2147483648,
23
+ 0,
24
+ 0
25
+ ];
26
+ const BIP39_WORD_RE = /^[a-z]+$/;
27
+ function guardianIndexToPlateLabel(guardianIndex) {
28
+ if (!Number.isInteger(guardianIndex) || guardianIndex < 1) throw new MpcProtocolError("INVALID_PARAMETER", `Invalid guardianIndex: ${guardianIndex}`);
29
+ if (guardianIndex <= 26) return `Plate ${String.fromCharCode(64 + guardianIndex)}`;
30
+ return `Plate #${guardianIndex}`;
31
+ }
32
+ function normalizeMnemonicWordList(wordsInput, expectedCount) {
33
+ let rawTokens;
34
+ if (typeof wordsInput === "string") {
35
+ const trimmed = wordsInput.trim();
36
+ if (trimmed.length === 0) throw new MpcProtocolError("BIP39_INVALID_MNEMONIC", "Mnemonic input is empty");
37
+ rawTokens = trimmed.split(/\s+/);
38
+ } else if (Array.isArray(wordsInput)) rawTokens = wordsInput.map((w) => {
39
+ if (typeof w !== "string") throw new MpcProtocolError("BIP39_INVALID_MNEMONIC", "Mnemonic words must be strings");
40
+ return w.trim();
41
+ });
42
+ else throw new MpcProtocolError("BIP39_INVALID_MNEMONIC", "Expected 24-word string or string array");
43
+ if (rawTokens.length !== expectedCount) throw new MpcProtocolError("BIP39_INVALID_MNEMONIC", `Expected exactly ${expectedCount} standard BIP-39 words (zero passphrases), got ${rawTokens.length}`);
44
+ return rawTokens.map((token, idx) => {
45
+ const lower = token.toLowerCase();
46
+ if (!BIP39_WORD_RE.test(lower) || !BIP39_ENGLISH_WORD_TO_INDEX.has(lower)) throw new MpcProtocolError("BIP39_INVALID_MNEMONIC", `Invalid BIP-39 English word at position ${idx + 1}: "${token}"`);
47
+ return lower;
48
+ });
49
+ }
50
+ /**
51
+ * Encodes a 32-byte cold Shamir share (`1 <= scalar < secp256k1.n`) into 24 standard English BIP-39 words
52
+ * (`256` entropy bits + `8` SHA-256 checksum bits = `264` bits = `24 x 11` bits).
53
+ */
54
+ function encodeColdShareToBip39Words24(coldShareBytes32) {
55
+ bytes32ToScalarNonZero(coldShareBytes32);
56
+ const digest32 = sha256(coldShareBytes32);
57
+ const words = new Array(24);
58
+ try {
59
+ const checksumByte = digest32[0];
60
+ for (let w = 0; w < 24; w++) {
61
+ let wordIndex = 0;
62
+ for (let bit = 0; bit < 11; bit++) {
63
+ const bitPos = w * 11 + bit;
64
+ let bitVal;
65
+ if (bitPos < 256) {
66
+ const byteIdx = bitPos >>> 3;
67
+ const shift = 7 - (bitPos & 7);
68
+ bitVal = coldShareBytes32[byteIdx] >>> shift & 1;
69
+ } else bitVal = checksumByte >>> 7 - (bitPos - 256) & 1;
70
+ wordIndex = wordIndex << 1 | bitVal;
71
+ }
72
+ words[w] = BIP39_ENGLISH_WORDLIST[wordIndex];
73
+ }
74
+ return words;
75
+ } finally {
76
+ zeroizeBytes(digest32);
77
+ }
78
+ }
79
+ /**
80
+ * Decodes 24 standard English BIP-39 words into a validated 32-byte `secp256k1` scalar (`1 <= scalar < n`),
81
+ * verifying exact 24-word count (zero passphrases) and the 8-bit SHA-256 BIP-39 checksum.
82
+ */
83
+ function decodeBip39Words24ToColdShare(wordsInput) {
84
+ const words = normalizeMnemonicWordList(wordsInput, 24);
85
+ const entropy32 = new Uint8Array(32);
86
+ let givenChecksum = 0;
87
+ for (let w = 0; w < 24; w++) {
88
+ const wordIndex = BIP39_ENGLISH_WORD_TO_INDEX.get(words[w]);
89
+ for (let bit = 0; bit < 11; bit++) {
90
+ const bitVal = wordIndex >>> 10 - bit & 1;
91
+ const bitPos = w * 11 + bit;
92
+ if (bitPos < 256) {
93
+ const byteIdx = bitPos >>> 3;
94
+ const shift = 7 - (bitPos & 7);
95
+ entropy32[byteIdx] |= bitVal << shift;
96
+ } else {
97
+ const chkShift = 7 - (bitPos - 256);
98
+ givenChecksum |= bitVal << chkShift;
99
+ }
100
+ }
101
+ }
102
+ const digest32 = sha256(entropy32);
103
+ const expectedChecksum = digest32[0];
104
+ zeroizeBytes(digest32);
105
+ if (givenChecksum !== expectedChecksum) {
106
+ zeroizeBytes(entropy32);
107
+ throw new MpcProtocolError("BIP39_CHECKSUM_MISMATCH", "24-word BIP-39 mnemonic failed 8-bit SHA-256 checksum verification");
108
+ }
109
+ const scalar = bytesToBigIntBE(entropy32);
110
+ if (scalar < 1n || scalar >= SECP256K1_N) {
111
+ zeroizeBytes(entropy32);
112
+ throw new MpcProtocolError("INVALID_SCALAR", "Decoded 24-word entropy is outside [1, secp256k1.n - 1]");
113
+ }
114
+ return entropy32;
115
+ }
116
+ /**
117
+ * Identifies which guardian index `k in 1..nCold` a physical 24-word cold share belongs to by
118
+ * evaluating the aggregated cold Feldman commitments `Y_k = \sum_{l=0}^{t_c-1} k^l C^{cold}_l`
119
+ * and checking `scalar * G == Y_k`. Fails closed if zero indices match (e.g. wrong 24th sibling word).
120
+ */
121
+ function identifyColdShareIndexViaFeldman(coldShareBytes32, coldFeldmanCommitmentsComp33, nCold) {
122
+ if (!Number.isInteger(nCold) || nCold < 1 || nCold > MAX_MPC_CLUSTER_NODES) throw new MpcProtocolError("INVALID_PARAMETER", `Invalid nCold: ${nCold}`);
123
+ if (!Array.isArray(coldFeldmanCommitmentsComp33) || coldFeldmanCommitmentsComp33.length === 0) throw new MpcProtocolError("INVALID_PARAMETER", "coldFeldmanCommitmentsComp33 must be non-empty");
124
+ const scalar = bytes32ToScalarNonZero(coldShareBytes32);
125
+ const coldPoints = coldFeldmanCommitmentsComp33.map((c) => decodePointCompressed(normalizeHexBytes(c, 33), false));
126
+ const candidatePub = mulBaseG(scalar);
127
+ let matchedIndex = null;
128
+ for (let k = 1; k <= nCold; k++) {
129
+ const yk = evaluateFeldmanCommitments(coldPoints, k);
130
+ if (!yk.is0() && candidatePub.equals(yk)) {
131
+ if (matchedIndex !== null) throw new MpcProtocolError("COLD_SHARE_UNKNOWN_INDEX", "Ambiguous Feldman cold share index match");
132
+ matchedIndex = k;
133
+ }
134
+ }
135
+ if (matchedIndex === null) throw new MpcProtocolError("COLD_SHARE_UNKNOWN_INDEX", `Cold share scalar * G does not match any guardian Feldman commitment Y_1..Y_${nCold}`);
136
+ return {
137
+ guardianIndex: matchedIndex,
138
+ plateLabel: guardianIndexToPlateLabel(matchedIndex),
139
+ coldPublicShareComp33: encodePointCompressed(candidatePub)
140
+ };
141
+ }
142
+ /**
143
+ * Derives the standard `m/44'/60'/0'/0/0` Ethereum EOA address (zero passphrase: salt = `"mnemonic"`)
144
+ * for a 24-word BIP-39 mnemonic so honeypot monitoring matches standard hardware/software wallets
145
+ * (`design.md` §5.2(2)).
146
+ */
147
+ function deriveBip44EthAddressFromWords24(wordsInput) {
148
+ const words = normalizeMnemonicWordList(wordsInput, 24);
149
+ const entropy32 = new Uint8Array(32);
150
+ let givenChecksum = 0;
151
+ for (let w = 0; w < 24; w++) {
152
+ const wordIndex = BIP39_ENGLISH_WORD_TO_INDEX.get(words[w]);
153
+ for (let bit = 0; bit < 11; bit++) {
154
+ const bitVal = wordIndex >>> 10 - bit & 1;
155
+ const bitPos = w * 11 + bit;
156
+ if (bitPos < 256) entropy32[bitPos >>> 3] |= bitVal << 7 - (bitPos & 7);
157
+ else givenChecksum |= bitVal << 7 - (bitPos - 256);
158
+ }
159
+ }
160
+ const chkDigest = sha256(entropy32);
161
+ const expectedChecksum = chkDigest[0];
162
+ zeroizeBytes(entropy32, chkDigest);
163
+ if (givenChecksum !== expectedChecksum) throw new MpcProtocolError("BIP39_CHECKSUM_MISMATCH", "Invalid 24-word BIP-39 checksum");
164
+ const sentenceBytes = utf8Bytes(words.join(" "));
165
+ const seed64 = pbkdf2(sha512, sentenceBytes, utf8Bytes("mnemonic"), {
166
+ c: 2048,
167
+ dkLen: 64
168
+ });
169
+ const masterI = hmac(sha512, utf8Bytes("Bitcoin seed"), seed64);
170
+ const chainCode32 = new Uint8Array(masterI.subarray(32, 64));
171
+ let keyScalar = bytesToBigIntBE(masterI.subarray(0, 32));
172
+ try {
173
+ if (keyScalar === 0n || keyScalar >= SECP256K1_N) throw new MpcProtocolError("INVALID_SCALAR", "Degenerate BIP-32 master key derived from mnemonic");
174
+ for (const childIndex of BIP44_ETH_INDICES) {
175
+ let data;
176
+ if (childIndex >= 2147483648) {
177
+ const keyBytes = scalarToBytes32(keyScalar);
178
+ data = concatBytes(u8(0), keyBytes, u32be(childIndex));
179
+ zeroizeBytes(keyBytes);
180
+ } else data = concatBytes(encodePointCompressed(mulBaseG(keyScalar)), u32be(childIndex));
181
+ const childI = hmac(sha512, chainCode32, data);
182
+ zeroizeBytes(data);
183
+ try {
184
+ const il = bytesToBigIntBE(childI.subarray(0, 32));
185
+ const nextKey = addModN(il, keyScalar);
186
+ if (il >= SECP256K1_N || nextKey === 0n) throw new MpcProtocolError("INVALID_SCALAR", "Degenerate BIP-32 child key derived along m/44h/60h/0h/0/0");
187
+ keyScalar = nextKey;
188
+ chainCode32.set(childI.subarray(32, 64));
189
+ } finally {
190
+ zeroizeBytes(childI);
191
+ }
192
+ }
193
+ return pointToEthAddress(mulBaseG(keyScalar)).checksumAddress;
194
+ } finally {
195
+ keyScalar = 0n;
196
+ zeroizeBytes(sentenceBytes, seed64, masterI, chainCode32);
197
+ }
198
+ }
199
+ /**
200
+ * Given the first 23 standard BIP-39 words (`253` bits), enumerates all `2^3 = 8` checksum-valid
201
+ * 24th words (`3` entropy bits + `8` SHA-256 checksum bits) and derives each candidate's standard
202
+ * `m/44'/60'/0'/0/0` `0x...` Ethereum canary/honeypot address (`design.md` §5.2(2)).
203
+ */
204
+ function enumerateValid24thBip39Siblings(first23WordsInput) {
205
+ const first23Words = normalizeMnemonicWordList(first23WordsInput, 23);
206
+ const baseEntropy32 = new Uint8Array(32);
207
+ for (let w = 0; w < 23; w++) {
208
+ const wordIndex = BIP39_ENGLISH_WORD_TO_INDEX.get(first23Words[w]);
209
+ for (let bit = 0; bit < 11; bit++) {
210
+ const bitVal = wordIndex >>> 10 - bit & 1;
211
+ const bitPos = w * 11 + bit;
212
+ baseEntropy32[bitPos >>> 3] |= bitVal << 7 - (bitPos & 7);
213
+ }
214
+ }
215
+ const results = [];
216
+ const candidateEntropy32 = new Uint8Array(32);
217
+ try {
218
+ for (let tail3 = 0; tail3 < 8; tail3++) {
219
+ candidateEntropy32.set(baseEntropy32);
220
+ candidateEntropy32[31] = baseEntropy32[31] & 248 | tail3;
221
+ const digest32 = sha256(candidateEntropy32);
222
+ const checksumByte = digest32[0];
223
+ zeroizeBytes(digest32);
224
+ const wordIndex = tail3 << 8 | checksumByte;
225
+ const word24 = BIP39_ENGLISH_WORDLIST[wordIndex];
226
+ const words24 = [...first23Words, word24];
227
+ const scalarVal = bytesToBigIntBE(candidateEntropy32);
228
+ const isValidColdScalar = scalarVal >= 1n && scalarVal < SECP256K1_N;
229
+ const ethAddress = deriveBip44EthAddressFromWords24(words24);
230
+ results.push({
231
+ tail3Bits: tail3,
232
+ wordIndex,
233
+ word24,
234
+ words24,
235
+ derivationPath: BIP44_ETH_STANDARD_PATH,
236
+ ethAddress,
237
+ isValidColdScalar
238
+ });
239
+ }
240
+ return results;
241
+ } finally {
242
+ zeroizeBytes(baseEntropy32, candidateEntropy32);
243
+ }
244
+ }
245
+
246
+ //#endregion
247
+ export { BIP44_ETH_STANDARD_PATH, decodeBip39Words24ToColdShare, deriveBip44EthAddressFromWords24, encodeColdShareToBip39Words24, enumerateValid24thBip39Siblings, guardianIndexToPlateLabel, identifyColdShareIndexViaFeldman };
@@ -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 };