@ocap/mpc-hsm 1.33.6 → 1.33.8

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,303 @@
1
+ const require_constants = require('./constants.cjs');
2
+ const require_secp256k1_scalar = require('./secp256k1-scalar.cjs');
3
+ const require_tweak = require('./tweak.cjs');
4
+ let _noble_hashes_sha3_js = require("@noble/hashes/sha3.js");
5
+ let _noble_hashes_utils_js = require("@noble/hashes/utils.js");
6
+
7
+ //#region src/rlp-eip1559.ts
8
+ const EIP1559_TX_TYPE_BYTE = 2;
9
+ const ERC20_TRANSFER_SELECTOR_HEX = "a9059cbb";
10
+ const MAX_UINT64 = (1n << 64n) - 1n;
11
+ const MAX_UINT256 = (1n << 256n) - 1n;
12
+ function bigintToMinimalBytesBE(value, label = "uint") {
13
+ if (typeof value !== "bigint" || value < 0n || value > MAX_UINT256) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", `${label} must satisfy 0 <= v <= 2^256 - 1`);
14
+ if (value === 0n) return new Uint8Array(0);
15
+ const bytes = [];
16
+ let rem = value;
17
+ while (rem > 0n) {
18
+ bytes.push(Number(rem & 255n));
19
+ rem >>= 8n;
20
+ }
21
+ bytes.reverse();
22
+ return Uint8Array.from(bytes);
23
+ }
24
+ function encodeLengthPrefix(length, offsetBase) {
25
+ if (length < 56) return Uint8Array.of(offsetBase + length);
26
+ const lenBytes = bigintToMinimalBytesBE(BigInt(length), "rlpLength");
27
+ return require_secp256k1_scalar.concatBytes(Uint8Array.of(offsetBase + 55 + lenBytes.length), lenBytes);
28
+ }
29
+ function rlpEncode(item) {
30
+ if (item instanceof Uint8Array) {
31
+ if (item.length === 1 && item[0] <= 127) return new Uint8Array(item);
32
+ return require_secp256k1_scalar.concatBytes(encodeLengthPrefix(item.length, 128), item);
33
+ }
34
+ if (Array.isArray(item)) {
35
+ const payload = require_secp256k1_scalar.concatBytes(...item.map((child) => rlpEncode(child)));
36
+ return require_secp256k1_scalar.concatBytes(encodeLengthPrefix(payload.length, 192), payload);
37
+ }
38
+ throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Unsupported RLP item type");
39
+ }
40
+ const MAX_RLP_DECODE_DEPTH = 4;
41
+ function rlpDecodeItem(buf, offset, depth = 0) {
42
+ if (depth > MAX_RLP_DECODE_DEPTH) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", `RLP nesting depth exceeds maximum (${MAX_RLP_DECODE_DEPTH})`);
43
+ if (offset >= buf.length) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Unexpected EOF during RLP decode");
44
+ const prefix = buf[offset];
45
+ if (prefix <= 127) return {
46
+ item: buf.subarray(offset, offset + 1),
47
+ nextOffset: offset + 1
48
+ };
49
+ if (prefix <= 183) {
50
+ const strLen = prefix - 128;
51
+ const start = offset + 1;
52
+ const end$1 = start + strLen;
53
+ if (end$1 > buf.length) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Truncated short RLP byte string");
54
+ if (strLen === 1 && buf[start] <= 127) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Non-canonical single-byte RLP string");
55
+ return {
56
+ item: buf.subarray(start, end$1),
57
+ nextOffset: end$1
58
+ };
59
+ }
60
+ if (prefix <= 191) {
61
+ const lenOfLen$1 = prefix - 183;
62
+ const lenStart$1 = offset + 1;
63
+ const lenEnd$1 = lenStart$1 + lenOfLen$1;
64
+ if (lenEnd$1 > buf.length || buf[lenStart$1] === 0) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Malformed long RLP string length");
65
+ const strLen = Number(require_secp256k1_scalar.bytesToBigIntBE(buf.subarray(lenStart$1, lenEnd$1)));
66
+ if (!Number.isSafeInteger(strLen) || strLen < 56 || lenEnd$1 + strLen > buf.length) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Invalid or truncated long RLP string");
67
+ return {
68
+ item: buf.subarray(lenEnd$1, lenEnd$1 + strLen),
69
+ nextOffset: lenEnd$1 + strLen
70
+ };
71
+ }
72
+ if (prefix <= 247) {
73
+ const listLen$1 = prefix - 192;
74
+ let cur$1 = offset + 1;
75
+ const end$1 = cur$1 + listLen$1;
76
+ if (end$1 > buf.length) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Truncated short RLP list");
77
+ const list$1 = [];
78
+ while (cur$1 < end$1) {
79
+ const child = rlpDecodeItem(buf, cur$1, depth + 1);
80
+ list$1.push(child.item);
81
+ cur$1 = child.nextOffset;
82
+ }
83
+ if (cur$1 !== end$1) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Misaligned short RLP list boundary");
84
+ return {
85
+ item: list$1,
86
+ nextOffset: end$1
87
+ };
88
+ }
89
+ const lenOfLen = prefix - 247;
90
+ const lenStart = offset + 1;
91
+ const lenEnd = lenStart + lenOfLen;
92
+ if (lenEnd > buf.length || buf[lenStart] === 0) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Malformed long RLP list length");
93
+ const listLen = Number(require_secp256k1_scalar.bytesToBigIntBE(buf.subarray(lenStart, lenEnd)));
94
+ if (!Number.isSafeInteger(listLen) || listLen < 56 || lenEnd + listLen > buf.length) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Invalid or truncated long RLP list");
95
+ let cur = lenEnd;
96
+ const end = lenEnd + listLen;
97
+ const list = [];
98
+ while (cur < end) {
99
+ const child = rlpDecodeItem(buf, cur, depth + 1);
100
+ list.push(child.item);
101
+ cur = child.nextOffset;
102
+ }
103
+ if (cur !== end) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Misaligned long RLP list boundary");
104
+ return {
105
+ item: list,
106
+ nextOffset: end
107
+ };
108
+ }
109
+ function rlpDecode(bytes) {
110
+ const { item, nextOffset } = rlpDecodeItem(bytes, 0);
111
+ if (nextOffset !== bytes.length) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Trailing bytes after RLP item");
112
+ return item;
113
+ }
114
+ function canonicalRlpBytesToBigInt(bytes, label) {
115
+ if (bytes.length > 32) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", `${label} exceeds 32 bytes`);
116
+ if (bytes.length > 0 && bytes[0] === 0) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", `Non-canonical leading zero in ${label}`);
117
+ return require_secp256k1_scalar.bytesToBigIntBE(bytes);
118
+ }
119
+ function validateAndBuildCoreRlpFields(tx) {
120
+ if (typeof tx.chainId !== "bigint" || tx.chainId < 1n || tx.chainId > MAX_UINT64) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", `Invalid chainId: ${String(tx.chainId)}`);
121
+ if (typeof tx.nonce !== "bigint" || tx.nonce < 0n || tx.nonce >= MAX_UINT64) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", `Invalid nonce: ${String(tx.nonce)}`);
122
+ if (typeof tx.maxPriorityFeePerGasWei !== "bigint" || typeof tx.maxFeePerGasWei !== "bigint" || tx.maxPriorityFeePerGasWei < 0n || tx.maxFeePerGasWei < 0n || tx.maxFeePerGasWei > MAX_UINT256 || tx.maxFeePerGasWei < tx.maxPriorityFeePerGasWei) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Invalid EIP-1559 fee parameters (require 0 <= maxPriorityFeePerGasWei <= maxFeePerGasWei)");
123
+ if (typeof tx.gasLimit !== "bigint" || tx.gasLimit < 21000n || tx.gasLimit > MAX_UINT64) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", `Invalid gasLimit: ${String(tx.gasLimit)}`);
124
+ if (typeof tx.valueWei !== "bigint" || tx.valueWei < 0n || tx.valueWei > MAX_UINT256) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", `Invalid valueWei: ${String(tx.valueWei)}`);
125
+ const parsedTo = require_tweak.parseStrictEthAddress(tx.to);
126
+ const dataBytes = tx.data === void 0 || tx.data === "0x" || tx.data === "" ? new Uint8Array(0) : require_secp256k1_scalar.normalizeHexBytes(tx.data);
127
+ const encodedAccessList = (tx.accessList ?? []).map((entry) => {
128
+ const addr = require_tweak.parseStrictEthAddress(entry.address);
129
+ const keys = entry.storageKeys.map((k) => require_secp256k1_scalar.normalizeHexBytes(k, 32));
130
+ return [addr.addressBytes20, keys];
131
+ });
132
+ return {
133
+ coreFields: [
134
+ bigintToMinimalBytesBE(tx.chainId, "chainId"),
135
+ bigintToMinimalBytesBE(tx.nonce, "nonce"),
136
+ bigintToMinimalBytesBE(tx.maxPriorityFeePerGasWei, "maxPriorityFeePerGasWei"),
137
+ bigintToMinimalBytesBE(tx.maxFeePerGasWei, "maxFeePerGasWei"),
138
+ bigintToMinimalBytesBE(tx.gasLimit, "gasLimit"),
139
+ parsedTo.addressBytes20,
140
+ bigintToMinimalBytesBE(tx.valueWei, "valueWei"),
141
+ dataBytes,
142
+ encodedAccessList
143
+ ],
144
+ normalizedToChecksum: parsedTo.checksumAddress,
145
+ dataBytes
146
+ };
147
+ }
148
+ function encodeUnsignedEip1559Tx(tx) {
149
+ const { coreFields, normalizedToChecksum } = validateAndBuildCoreRlpFields(tx);
150
+ const unsignedPayloadBytes = require_secp256k1_scalar.concatBytes(require_secp256k1_scalar.u8(EIP1559_TX_TYPE_BYTE), rlpEncode(coreFields));
151
+ const signingDigest32 = (0, _noble_hashes_sha3_js.keccak_256)(unsignedPayloadBytes);
152
+ return {
153
+ unsignedPayloadBytes,
154
+ signingDigest32,
155
+ signingDigestHex: `0x${(0, _noble_hashes_utils_js.bytesToHex)(signingDigest32)}`,
156
+ toChecksumAddress: normalizedToChecksum
157
+ };
158
+ }
159
+ function encodeSignedEip1559Tx(params) {
160
+ const { tx, yParity, r, s } = params;
161
+ if (yParity !== 0 && yParity !== 1) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "yParity must be 0 or 1");
162
+ if (typeof r !== "bigint" || r < 1n || r >= require_constants.SECP256K1_N) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Invalid ECDSA r scalar");
163
+ if (typeof s !== "bigint" || s < 1n || s > require_constants.SECP256K1_HALF_N) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Invalid or high-S ECDSA s scalar");
164
+ const { coreFields } = validateAndBuildCoreRlpFields(tx);
165
+ const signingDigest32 = (0, _noble_hashes_sha3_js.keccak_256)(require_secp256k1_scalar.concatBytes(require_secp256k1_scalar.u8(EIP1559_TX_TYPE_BYTE), rlpEncode(coreFields)));
166
+ const signedFields = [
167
+ ...coreFields,
168
+ bigintToMinimalBytesBE(BigInt(yParity), "yParity"),
169
+ bigintToMinimalBytesBE(r, "r"),
170
+ bigintToMinimalBytesBE(s, "s")
171
+ ];
172
+ const rawSignedTxBytes = require_secp256k1_scalar.concatBytes(require_secp256k1_scalar.u8(EIP1559_TX_TYPE_BYTE), rlpEncode(signedFields));
173
+ const txHash32 = (0, _noble_hashes_sha3_js.keccak_256)(rawSignedTxBytes);
174
+ return {
175
+ rawSignedTxBytes,
176
+ rawSignedTxHex: `0x${(0, _noble_hashes_utils_js.bytesToHex)(rawSignedTxBytes)}`,
177
+ txHash32,
178
+ txHashHex: `0x${(0, _noble_hashes_utils_js.bytesToHex)(txHash32)}`,
179
+ signingDigest32
180
+ };
181
+ }
182
+ function decodeAndRecoverSignedEip1559Tx(rawTx) {
183
+ const rawBytes = require_secp256k1_scalar.normalizeHexBytes(rawTx);
184
+ if (rawBytes.length < 4 || rawBytes[0] !== EIP1559_TX_TYPE_BYTE) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Expected EIP-1559 Type 0x02 transaction envelope");
185
+ const decoded = rlpDecode(rawBytes.subarray(1));
186
+ if (!Array.isArray(decoded) || decoded.length !== 12) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Signed EIP-1559 RLP list must have 12 elements");
187
+ for (let i = 0; i < 12; i++) if (i === 8) {
188
+ if (!Array.isArray(decoded[8])) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "accessList must be an RLP list");
189
+ } else if (!(decoded[i] instanceof Uint8Array)) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", `Field ${i} must be an RLP byte string`);
190
+ const chainId = canonicalRlpBytesToBigInt(decoded[0], "chainId");
191
+ const nonce = canonicalRlpBytesToBigInt(decoded[1], "nonce");
192
+ const maxPriorityFeePerGasWei = canonicalRlpBytesToBigInt(decoded[2], "maxPriorityFeePerGasWei");
193
+ const maxFeePerGasWei = canonicalRlpBytesToBigInt(decoded[3], "maxFeePerGasWei");
194
+ const gasLimit = canonicalRlpBytesToBigInt(decoded[4], "gasLimit");
195
+ const toBytes = decoded[5];
196
+ if (toBytes.length !== 20) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Destination address must be 20 bytes");
197
+ const toLowerHex = (0, _noble_hashes_utils_js.bytesToHex)(toBytes);
198
+ if (/^0+$/.test(toLowerHex)) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Zero destination address rejected");
199
+ const toChecksumAddress = require_tweak.toEip55ChecksumAddress(toLowerHex);
200
+ const valueWei = canonicalRlpBytesToBigInt(decoded[6], "valueWei");
201
+ const dataBytes = new Uint8Array(decoded[7]);
202
+ const parsedAccessList = decoded[8].map((entry) => {
203
+ if (!Array.isArray(entry) || entry.length !== 2 || !(entry[0] instanceof Uint8Array) || !Array.isArray(entry[1])) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Malformed EIP-2930 accessList tuple");
204
+ if (entry[0].length !== 20) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "accessList address must be 20 bytes");
205
+ const addrHex = (0, _noble_hashes_utils_js.bytesToHex)(entry[0]);
206
+ if (/^0+$/.test(addrHex)) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Zero address in accessList rejected");
207
+ const storageKeys = entry[1].map((sk) => {
208
+ if (!(sk instanceof Uint8Array) || sk.length !== 32) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "accessList storageKey must be 32 bytes");
209
+ return sk;
210
+ });
211
+ return {
212
+ address: require_tweak.toEip55ChecksumAddress(addrHex),
213
+ storageKeys
214
+ };
215
+ });
216
+ const yParityBig = canonicalRlpBytesToBigInt(decoded[9], "yParity");
217
+ if (yParityBig !== 0n && yParityBig !== 1n) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "yParity must be 0 or 1");
218
+ const yParity = Number(yParityBig);
219
+ const r = canonicalRlpBytesToBigInt(decoded[10], "r");
220
+ const s = canonicalRlpBytesToBigInt(decoded[11], "s");
221
+ if (r < 1n || r >= require_constants.SECP256K1_N || s < 1n || s > require_constants.SECP256K1_HALF_N) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Invalid or high-S signature in signed EIP-1559 tx");
222
+ const reencoded = encodeSignedEip1559Tx({
223
+ tx: {
224
+ chainId,
225
+ nonce,
226
+ maxPriorityFeePerGasWei,
227
+ maxFeePerGasWei,
228
+ gasLimit,
229
+ to: toChecksumAddress,
230
+ valueWei,
231
+ data: dataBytes,
232
+ accessList: parsedAccessList
233
+ },
234
+ yParity,
235
+ r,
236
+ s
237
+ });
238
+ if (!require_secp256k1_scalar.constantTimeEqual(rawBytes, reencoded.rawSignedTxBytes)) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Non-canonical EIP-1559 RLP encoding");
239
+ const signingDigest32 = reencoded.signingDigest32;
240
+ return {
241
+ chainId,
242
+ nonce,
243
+ maxPriorityFeePerGasWei,
244
+ maxFeePerGasWei,
245
+ gasLimit,
246
+ toChecksumAddress,
247
+ valueWei,
248
+ dataBytes,
249
+ accessList: parsedAccessList,
250
+ yParity,
251
+ r,
252
+ s,
253
+ senderChecksumAddress: require_tweak.ecrecoverEthAddress({
254
+ msgDigest32: signingDigest32,
255
+ r,
256
+ s,
257
+ yParity
258
+ }).checksumAddress,
259
+ signingDigest32,
260
+ txHashHex: `0x${(0, _noble_hashes_utils_js.bytesToHex)((0, _noble_hashes_sha3_js.keccak_256)(rawBytes))}`
261
+ };
262
+ }
263
+ /**
264
+ * Encodes canonical 68-byte ERC-20 `transfer(address,uint256)` calldata (`0xa9059cbb` + 32B recipient + 32B amount).
265
+ */
266
+ function encodeErc20TransferCalldata(recipientAddress, tokenAmount) {
267
+ const parsedRecipient = require_tweak.parseStrictEthAddress(recipientAddress);
268
+ if (typeof tokenAmount !== "bigint" || tokenAmount <= 0n || tokenAmount > MAX_UINT256) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "ERC-20 transfer amount must satisfy 1 <= amount <= 2^256-1");
269
+ const out = new Uint8Array(68);
270
+ out.set(require_secp256k1_scalar.normalizeHexBytes(ERC20_TRANSFER_SELECTOR_HEX, 4), 0);
271
+ out.set(parsedRecipient.addressBytes20, 16);
272
+ let rem = tokenAmount;
273
+ for (let i = 67; i >= 36; i--) {
274
+ out[i] = Number(rem & 255n);
275
+ rem >>= 8n;
276
+ }
277
+ return out;
278
+ }
279
+ function decodeErc20TransferCalldata(calldata) {
280
+ const bytes = require_secp256k1_scalar.normalizeHexBytes(calldata);
281
+ if (bytes.length !== 68 || (0, _noble_hashes_utils_js.bytesToHex)(bytes.subarray(0, 4)) !== ERC20_TRANSFER_SELECTOR_HEX) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Expected 68-byte ERC-20 transfer(address,uint256) calldata");
282
+ for (let i = 4; i < 16; i++) if (bytes[i] !== 0) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Non-zero padding in ABI-encoded ERC-20 recipient word");
283
+ const addrLower = (0, _noble_hashes_utils_js.bytesToHex)(bytes.subarray(16, 36));
284
+ if (/^0+$/.test(addrLower)) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "Zero recipient in ERC-20 transfer calldata");
285
+ const tokenAmount = require_secp256k1_scalar.bytesToBigIntBE(bytes.subarray(36, 68));
286
+ if (tokenAmount <= 0n) throw new require_constants.MpcProtocolError("RLP_INVALID_TRANSACTION", "ERC-20 transfer amount must be > 0");
287
+ return {
288
+ recipientChecksumAddress: require_tweak.toEip55ChecksumAddress(addrLower),
289
+ tokenAmount
290
+ };
291
+ }
292
+
293
+ //#endregion
294
+ exports.EIP1559_TX_TYPE_BYTE = EIP1559_TX_TYPE_BYTE;
295
+ exports.ERC20_TRANSFER_SELECTOR_HEX = ERC20_TRANSFER_SELECTOR_HEX;
296
+ exports.bigintToMinimalBytesBE = bigintToMinimalBytesBE;
297
+ exports.decodeAndRecoverSignedEip1559Tx = decodeAndRecoverSignedEip1559Tx;
298
+ exports.decodeErc20TransferCalldata = decodeErc20TransferCalldata;
299
+ exports.encodeErc20TransferCalldata = encodeErc20TransferCalldata;
300
+ exports.encodeSignedEip1559Tx = encodeSignedEip1559Tx;
301
+ exports.encodeUnsignedEip1559Tx = encodeUnsignedEip1559Tx;
302
+ exports.rlpDecode = rlpDecode;
303
+ exports.rlpEncode = rlpEncode;
@@ -0,0 +1,75 @@
1
+ //#region src/rlp-eip1559.d.ts
2
+ /**
3
+ * Minimal, zero-dependency canonical RLP encoder/decoder and EIP-1559 (EIP-2718 Type `0x02`)
4
+ * transaction serializer for air-gapped disaster recovery and clear-signing (`design.md` §5 & §7).
5
+ *
6
+ * Enforces Yellow Paper Appendix B canonical integer encoding (`0n -> 0x80` empty byte string,
7
+ * zero leading `0x00` bytes on positive integers) and EIP-2 low-S (`s <= SECP256K1_HALF_N`).
8
+ */
9
+ type RlpInput = Uint8Array | ReadonlyArray<RlpInput>;
10
+ declare const EIP1559_TX_TYPE_BYTE: 2;
11
+ declare const ERC20_TRANSFER_SELECTOR_HEX: "a9059cbb";
12
+ declare function bigintToMinimalBytesBE(value: bigint, label?: string): Uint8Array;
13
+ declare function rlpEncode(item: RlpInput): Uint8Array;
14
+ declare function rlpDecode(bytes: Uint8Array): RlpInput;
15
+ interface Eip1559AccessListItem {
16
+ readonly address: string;
17
+ readonly storageKeys: ReadonlyArray<Uint8Array | string>;
18
+ }
19
+ interface Eip1559UnsignedTxFields {
20
+ readonly chainId: bigint;
21
+ readonly nonce: bigint;
22
+ readonly maxPriorityFeePerGasWei: bigint;
23
+ readonly maxFeePerGasWei: bigint;
24
+ readonly gasLimit: bigint;
25
+ readonly to: string;
26
+ readonly valueWei: bigint;
27
+ readonly data?: Uint8Array | string;
28
+ readonly accessList?: ReadonlyArray<Eip1559AccessListItem>;
29
+ }
30
+ declare function encodeUnsignedEip1559Tx(tx: Eip1559UnsignedTxFields): {
31
+ readonly unsignedPayloadBytes: Uint8Array;
32
+ readonly signingDigest32: Uint8Array;
33
+ readonly signingDigestHex: string;
34
+ readonly toChecksumAddress: string;
35
+ };
36
+ declare function encodeSignedEip1559Tx(params: {
37
+ readonly tx: Eip1559UnsignedTxFields;
38
+ readonly yParity: 0 | 1;
39
+ readonly r: bigint;
40
+ readonly s: bigint;
41
+ }): {
42
+ readonly rawSignedTxBytes: Uint8Array;
43
+ readonly rawSignedTxHex: string;
44
+ readonly txHash32: Uint8Array;
45
+ readonly txHashHex: string;
46
+ readonly signingDigest32: Uint8Array;
47
+ };
48
+ interface DecodedSignedEip1559Tx {
49
+ readonly chainId: bigint;
50
+ readonly nonce: bigint;
51
+ readonly maxPriorityFeePerGasWei: bigint;
52
+ readonly maxFeePerGasWei: bigint;
53
+ readonly gasLimit: bigint;
54
+ readonly toChecksumAddress: string;
55
+ readonly valueWei: bigint;
56
+ readonly dataBytes: Uint8Array;
57
+ readonly accessList: ReadonlyArray<Eip1559AccessListItem>;
58
+ readonly yParity: 0 | 1;
59
+ readonly r: bigint;
60
+ readonly s: bigint;
61
+ readonly senderChecksumAddress: string;
62
+ readonly signingDigest32: Uint8Array;
63
+ readonly txHashHex: string;
64
+ }
65
+ declare function decodeAndRecoverSignedEip1559Tx(rawTx: Uint8Array | string): DecodedSignedEip1559Tx;
66
+ /**
67
+ * Encodes canonical 68-byte ERC-20 `transfer(address,uint256)` calldata (`0xa9059cbb` + 32B recipient + 32B amount).
68
+ */
69
+ declare function encodeErc20TransferCalldata(recipientAddress: string, tokenAmount: bigint): Uint8Array;
70
+ declare function decodeErc20TransferCalldata(calldata: Uint8Array | string): {
71
+ readonly recipientChecksumAddress: string;
72
+ readonly tokenAmount: bigint;
73
+ };
74
+ //#endregion
75
+ export { DecodedSignedEip1559Tx, EIP1559_TX_TYPE_BYTE, ERC20_TRANSFER_SELECTOR_HEX, Eip1559AccessListItem, Eip1559UnsignedTxFields, RlpInput, bigintToMinimalBytesBE, decodeAndRecoverSignedEip1559Tx, decodeErc20TransferCalldata, encodeErc20TransferCalldata, encodeSignedEip1559Tx, encodeUnsignedEip1559Tx, rlpDecode, rlpEncode };
@@ -1,10 +1,9 @@
1
1
  const require_constants = require('./constants.cjs');
2
- let node_crypto = require("node:crypto");
3
- let _noble_curves_ed25519_js = require("@noble/curves/ed25519.js");
4
2
  let _noble_hashes_sha2_js = require("@noble/hashes/sha2.js");
3
+ let _noble_hashes_utils_js = require("@noble/hashes/utils.js");
4
+ let _noble_curves_ed25519_js = require("@noble/curves/ed25519.js");
5
5
  let _noble_curves_secp256k1_js = require("@noble/curves/secp256k1.js");
6
6
  let _noble_hashes_sha3_js = require("@noble/hashes/sha3.js");
7
- let _noble_hashes_utils_js = require("@noble/hashes/utils.js");
8
7
 
9
8
  //#region src/secp256k1-scalar.ts
10
9
  const Fn = _noble_curves_secp256k1_js.secp256k1.Point.Fn;
@@ -18,13 +17,23 @@ function utf8Bytes(text) {
18
17
  function zeroizeBytes(...buffers) {
19
18
  for (const buf of buffers) if (buf) buf.fill(0);
20
19
  }
20
+ const MAX_GET_RANDOM_VALUES_CHUNK = 65536;
21
21
  function constantTimeEqual(a, b) {
22
22
  if (a.length !== b.length) return false;
23
- return (0, node_crypto.timingSafeEqual)(a, b);
23
+ let diff = 0;
24
+ for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i];
25
+ return diff === 0;
24
26
  }
25
27
  function defaultRandomBytes(length) {
26
28
  if (!Number.isInteger(length) || length < 0) throw new require_constants.MpcProtocolError("INVALID_PARAMETER", `Invalid random byte length: ${length}`);
27
- return new Uint8Array((0, node_crypto.randomBytes)(length));
29
+ const cryptoObj = globalThis.crypto;
30
+ if (!cryptoObj || typeof cryptoObj.getRandomValues !== "function") throw new require_constants.MpcProtocolError("INVALID_PARAMETER", "WebCrypto getRandomValues is unavailable");
31
+ const out = new Uint8Array(length);
32
+ for (let offset = 0; offset < length; offset += MAX_GET_RANDOM_VALUES_CHUNK) {
33
+ const end = Math.min(offset + MAX_GET_RANDOM_VALUES_CHUNK, length);
34
+ cryptoObj.getRandomValues(out.subarray(offset, end));
35
+ }
36
+ return out;
28
37
  }
29
38
  /**
30
39
  * RFC 9380 `secp256k1_XMD:SHA-256_SSWU_RO_` NUMS generator `H` for Pedersen commitments.
@@ -0,0 +1,253 @@
1
+ const require_constants = require('./constants.cjs');
2
+ const require_secp256k1_scalar = require('./secp256k1-scalar.cjs');
3
+ const require_bip39_english_wordlist = require('./bip39-english-wordlist.cjs');
4
+ const require_tweak = require('./tweak.cjs');
5
+ let _noble_hashes_sha2_js = require("@noble/hashes/sha2.js");
6
+ let _noble_hashes_hmac_js = require("@noble/hashes/hmac.js");
7
+ let _noble_hashes_pbkdf2_js = require("@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 require_constants.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 require_constants.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 require_constants.MpcProtocolError("BIP39_INVALID_MNEMONIC", "Mnemonic words must be strings");
40
+ return w.trim();
41
+ });
42
+ else throw new require_constants.MpcProtocolError("BIP39_INVALID_MNEMONIC", "Expected 24-word string or string array");
43
+ if (rawTokens.length !== expectedCount) throw new require_constants.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) || !require_bip39_english_wordlist.BIP39_ENGLISH_WORD_TO_INDEX.has(lower)) throw new require_constants.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
+ require_secp256k1_scalar.bytes32ToScalarNonZero(coldShareBytes32);
56
+ const digest32 = (0, _noble_hashes_sha2_js.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] = require_bip39_english_wordlist.BIP39_ENGLISH_WORDLIST[wordIndex];
73
+ }
74
+ return words;
75
+ } finally {
76
+ require_secp256k1_scalar.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 = require_bip39_english_wordlist.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 = (0, _noble_hashes_sha2_js.sha256)(entropy32);
103
+ const expectedChecksum = digest32[0];
104
+ require_secp256k1_scalar.zeroizeBytes(digest32);
105
+ if (givenChecksum !== expectedChecksum) {
106
+ require_secp256k1_scalar.zeroizeBytes(entropy32);
107
+ throw new require_constants.MpcProtocolError("BIP39_CHECKSUM_MISMATCH", "24-word BIP-39 mnemonic failed 8-bit SHA-256 checksum verification");
108
+ }
109
+ const scalar = require_secp256k1_scalar.bytesToBigIntBE(entropy32);
110
+ if (scalar < 1n || scalar >= require_constants.SECP256K1_N) {
111
+ require_secp256k1_scalar.zeroizeBytes(entropy32);
112
+ throw new require_constants.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 > require_constants.MAX_MPC_CLUSTER_NODES) throw new require_constants.MpcProtocolError("INVALID_PARAMETER", `Invalid nCold: ${nCold}`);
123
+ if (!Array.isArray(coldFeldmanCommitmentsComp33) || coldFeldmanCommitmentsComp33.length === 0) throw new require_constants.MpcProtocolError("INVALID_PARAMETER", "coldFeldmanCommitmentsComp33 must be non-empty");
124
+ const scalar = require_secp256k1_scalar.bytes32ToScalarNonZero(coldShareBytes32);
125
+ const coldPoints = coldFeldmanCommitmentsComp33.map((c) => require_secp256k1_scalar.decodePointCompressed(require_secp256k1_scalar.normalizeHexBytes(c, 33), false));
126
+ const candidatePub = require_secp256k1_scalar.mulBaseG(scalar);
127
+ let matchedIndex = null;
128
+ for (let k = 1; k <= nCold; k++) {
129
+ const yk = require_secp256k1_scalar.evaluateFeldmanCommitments(coldPoints, k);
130
+ if (!yk.is0() && candidatePub.equals(yk)) {
131
+ if (matchedIndex !== null) throw new require_constants.MpcProtocolError("COLD_SHARE_UNKNOWN_INDEX", "Ambiguous Feldman cold share index match");
132
+ matchedIndex = k;
133
+ }
134
+ }
135
+ if (matchedIndex === null) throw new require_constants.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: require_secp256k1_scalar.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 = require_bip39_english_wordlist.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 = (0, _noble_hashes_sha2_js.sha256)(entropy32);
161
+ const expectedChecksum = chkDigest[0];
162
+ require_secp256k1_scalar.zeroizeBytes(entropy32, chkDigest);
163
+ if (givenChecksum !== expectedChecksum) throw new require_constants.MpcProtocolError("BIP39_CHECKSUM_MISMATCH", "Invalid 24-word BIP-39 checksum");
164
+ const sentenceBytes = require_secp256k1_scalar.utf8Bytes(words.join(" "));
165
+ const seed64 = (0, _noble_hashes_pbkdf2_js.pbkdf2)(_noble_hashes_sha2_js.sha512, sentenceBytes, require_secp256k1_scalar.utf8Bytes("mnemonic"), {
166
+ c: 2048,
167
+ dkLen: 64
168
+ });
169
+ const masterI = (0, _noble_hashes_hmac_js.hmac)(_noble_hashes_sha2_js.sha512, require_secp256k1_scalar.utf8Bytes("Bitcoin seed"), seed64);
170
+ const chainCode32 = new Uint8Array(masterI.subarray(32, 64));
171
+ let keyScalar = require_secp256k1_scalar.bytesToBigIntBE(masterI.subarray(0, 32));
172
+ try {
173
+ if (keyScalar === 0n || keyScalar >= require_constants.SECP256K1_N) throw new require_constants.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 = require_secp256k1_scalar.scalarToBytes32(keyScalar);
178
+ data = require_secp256k1_scalar.concatBytes(require_secp256k1_scalar.u8(0), keyBytes, require_secp256k1_scalar.u32be(childIndex));
179
+ require_secp256k1_scalar.zeroizeBytes(keyBytes);
180
+ } else data = require_secp256k1_scalar.concatBytes(require_secp256k1_scalar.encodePointCompressed(require_secp256k1_scalar.mulBaseG(keyScalar)), require_secp256k1_scalar.u32be(childIndex));
181
+ const childI = (0, _noble_hashes_hmac_js.hmac)(_noble_hashes_sha2_js.sha512, chainCode32, data);
182
+ require_secp256k1_scalar.zeroizeBytes(data);
183
+ try {
184
+ const il = require_secp256k1_scalar.bytesToBigIntBE(childI.subarray(0, 32));
185
+ const nextKey = require_secp256k1_scalar.addModN(il, keyScalar);
186
+ if (il >= require_constants.SECP256K1_N || nextKey === 0n) throw new require_constants.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
+ require_secp256k1_scalar.zeroizeBytes(childI);
191
+ }
192
+ }
193
+ return require_tweak.pointToEthAddress(require_secp256k1_scalar.mulBaseG(keyScalar)).checksumAddress;
194
+ } finally {
195
+ keyScalar = 0n;
196
+ require_secp256k1_scalar.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 = require_bip39_english_wordlist.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 = (0, _noble_hashes_sha2_js.sha256)(candidateEntropy32);
222
+ const checksumByte = digest32[0];
223
+ require_secp256k1_scalar.zeroizeBytes(digest32);
224
+ const wordIndex = tail3 << 8 | checksumByte;
225
+ const word24 = require_bip39_english_wordlist.BIP39_ENGLISH_WORDLIST[wordIndex];
226
+ const words24 = [...first23Words, word24];
227
+ const scalarVal = require_secp256k1_scalar.bytesToBigIntBE(candidateEntropy32);
228
+ const isValidColdScalar = scalarVal >= 1n && scalarVal < require_constants.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
+ require_secp256k1_scalar.zeroizeBytes(baseEntropy32, candidateEntropy32);
243
+ }
244
+ }
245
+
246
+ //#endregion
247
+ exports.BIP44_ETH_STANDARD_PATH = BIP44_ETH_STANDARD_PATH;
248
+ exports.decodeBip39Words24ToColdShare = decodeBip39Words24ToColdShare;
249
+ exports.deriveBip44EthAddressFromWords24 = deriveBip44EthAddressFromWords24;
250
+ exports.encodeColdShareToBip39Words24 = encodeColdShareToBip39Words24;
251
+ exports.enumerateValid24thBip39Siblings = enumerateValid24thBip39Siblings;
252
+ exports.guardianIndexToPlateLabel = guardianIndexToPlateLabel;
253
+ exports.identifyColdShareIndexViaFeldman = identifyColdShareIndexViaFeldman;