@babylonlabs-io/ts-sdk 0.17.1 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/dist/errors-DVNYib5y.cjs +2 -0
  2. package/dist/errors-DVNYib5y.cjs.map +1 -0
  3. package/dist/errors-aMocmFr-.js +1225 -0
  4. package/dist/errors-aMocmFr-.js.map +1 -0
  5. package/dist/index-BX-V3C9t.js +995 -0
  6. package/dist/index-BX-V3C9t.js.map +1 -0
  7. package/dist/index-BgnxXV5G.cjs +2 -0
  8. package/dist/index-BgnxXV5G.cjs.map +1 -0
  9. package/dist/index-BvFLf3vm.js +1513 -0
  10. package/dist/index-BvFLf3vm.js.map +1 -0
  11. package/dist/index-DpKhuCta.cjs +2 -0
  12. package/dist/index-DpKhuCta.cjs.map +1 -0
  13. package/dist/index.cjs +1 -1
  14. package/dist/index.js +84 -74
  15. package/dist/tbv/core/clients/eth/__tests__/protocol-params-reader.test.d.ts +2 -0
  16. package/dist/tbv/core/clients/eth/__tests__/protocol-params-reader.test.d.ts.map +1 -0
  17. package/dist/tbv/core/clients/eth/__tests__/signer-set-reader.test.d.ts +2 -0
  18. package/dist/tbv/core/clients/eth/__tests__/signer-set-reader.test.d.ts.map +1 -0
  19. package/dist/tbv/core/clients/eth/contract-address-resolver.d.ts +18 -0
  20. package/dist/tbv/core/clients/eth/contract-address-resolver.d.ts.map +1 -0
  21. package/dist/tbv/core/clients/eth/index.d.ts +4 -1
  22. package/dist/tbv/core/clients/eth/index.d.ts.map +1 -1
  23. package/dist/tbv/core/clients/eth/protocol-params-reader.d.ts +27 -0
  24. package/dist/tbv/core/clients/eth/protocol-params-reader.d.ts.map +1 -0
  25. package/dist/tbv/core/clients/eth/signer-set-reader.d.ts +37 -0
  26. package/dist/tbv/core/clients/eth/signer-set-reader.d.ts.map +1 -0
  27. package/dist/tbv/core/clients/eth/types.d.ts +80 -0
  28. package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
  29. package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts.map +1 -1
  30. package/dist/tbv/core/clients/index.cjs +1 -1
  31. package/dist/tbv/core/clients/index.js +25 -21
  32. package/dist/tbv/core/contracts/abis/ApplicationRegistry.abi.d.ts +74 -0
  33. package/dist/tbv/core/contracts/abis/ApplicationRegistry.abi.d.ts.map +1 -0
  34. package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts +74 -0
  35. package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts.map +1 -1
  36. package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts +233 -0
  37. package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts.map +1 -0
  38. package/dist/tbv/core/contracts/index.d.ts +2 -0
  39. package/dist/tbv/core/contracts/index.d.ts.map +1 -1
  40. package/dist/tbv/core/index.cjs +1 -1
  41. package/dist/tbv/core/index.js +86 -76
  42. package/dist/tbv/core/services/htlc/__tests__/htlc.test.d.ts +2 -0
  43. package/dist/tbv/core/services/htlc/__tests__/htlc.test.d.ts.map +1 -0
  44. package/dist/tbv/core/services/htlc/index.d.ts +25 -0
  45. package/dist/tbv/core/services/htlc/index.d.ts.map +1 -0
  46. package/dist/tbv/core/services/index.cjs +1 -1
  47. package/dist/tbv/core/services/index.d.ts +1 -0
  48. package/dist/tbv/core/services/index.d.ts.map +1 -1
  49. package/dist/tbv/core/services/index.js +6 -4
  50. package/dist/tbv/core/wots/__tests__/blockDerivation.test.d.ts +2 -0
  51. package/dist/tbv/core/wots/__tests__/blockDerivation.test.d.ts.map +1 -0
  52. package/dist/tbv/core/wots/blockDerivation.d.ts +36 -0
  53. package/dist/tbv/core/wots/blockDerivation.d.ts.map +1 -0
  54. package/dist/tbv/core/wots/index.d.ts +1 -0
  55. package/dist/tbv/core/wots/index.d.ts.map +1 -1
  56. package/dist/tbv/index.cjs +1 -1
  57. package/dist/tbv/index.js +86 -76
  58. package/dist/tbv/integrations/aave/clients/abis/AaveSpoke.abi.json.d.ts +140 -0
  59. package/dist/tbv/integrations/aave/clients/index.d.ts +1 -1
  60. package/dist/tbv/integrations/aave/clients/index.d.ts.map +1 -1
  61. package/dist/tbv/integrations/aave/clients/query.d.ts +12 -1
  62. package/dist/tbv/integrations/aave/clients/query.d.ts.map +1 -1
  63. package/dist/tbv/integrations/aave/index.cjs +1 -1
  64. package/dist/tbv/integrations/aave/index.cjs.map +1 -1
  65. package/dist/tbv/integrations/aave/index.d.ts +2 -2
  66. package/dist/tbv/integrations/aave/index.d.ts.map +1 -1
  67. package/dist/tbv/integrations/aave/index.js +141 -129
  68. package/dist/tbv/integrations/aave/index.js.map +1 -1
  69. package/dist/tbv/integrations/aave/types.d.ts +10 -0
  70. package/dist/tbv/integrations/aave/types.d.ts.map +1 -1
  71. package/package.json +1 -1
  72. package/dist/errors-DKLboMnq.cjs +0 -2
  73. package/dist/errors-DKLboMnq.cjs.map +0 -1
  74. package/dist/errors-KY63mgWT.js +0 -1510
  75. package/dist/errors-KY63mgWT.js.map +0 -1
  76. package/dist/index-D3z3SZAj.cjs +0 -2
  77. package/dist/index-D3z3SZAj.cjs.map +0 -1
  78. package/dist/index-Dw7FAwne.js +0 -913
  79. package/dist/index-Dw7FAwne.js.map +0 -1
  80. package/dist/signAndSubmitPayouts-CAOEAQp9.js +0 -490
  81. package/dist/signAndSubmitPayouts-CAOEAQp9.js.map +0 -1
  82. package/dist/signAndSubmitPayouts-CSJmcPQN.cjs +0 -2
  83. package/dist/signAndSubmitPayouts-CSJmcPQN.cjs.map +0 -1
@@ -1,1510 +0,0 @@
1
- var Yt = Object.defineProperty;
2
- var te = (e, t, s) => t in e ? Yt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
- var f = (e, t, s) => te(e, typeof t != "symbol" ? t + "" : t, s);
4
- import * as ee from "bitcoinjs-lib";
5
- import { Transaction as se, Psbt as wt } from "bitcoinjs-lib";
6
- import { Buffer as rt } from "buffer";
7
- import { createPublicClient as ct, http as at, encodeFunctionData as mt, zeroAddress as ne } from "viem";
8
- import { c as oe } from "./signing-Drwr3bXB.js";
9
- import { p as ie, B as j, f as re } from "./index-Dw7FAwne.js";
10
- import { s as S, f as ce, g as Pt, e as C, i as ae } from "./constants-Q7v2O7Ps.js";
11
- import { deriveVaultId as Ht } from "@babylonlabs-io/babylon-tbv-rust-wasm";
12
- import { b as he, a as le, d as ue, e as fe, f as de } from "./challengeAssert-k5_LWUtO.js";
13
- import { s as be, c as ht, d as ge } from "./psbtInputFields-DO0ELwiv.js";
14
- import { f as xe } from "./fundPeginTransaction-DpwnDslW.js";
15
- const G = {
16
- // VaultAlreadyExists()
17
- "0x04aabf33": "Vault already exists: This Bitcoin transaction has already been registered. Please select different UTXOs or use a different amount to create a unique transaction.",
18
- // ScriptPubKeyMismatch() - taproot output doesn't match expected script
19
- "0x4fec082d": "Script mismatch: The Bitcoin transaction's taproot output does not match the expected vault script. This may be caused by incorrect vault participants or key configuration.",
20
- // InvalidBTCProofOfPossession()
21
- "0x6cc363a5": "Invalid BTC proof of possession: The signature could not be verified. Please ensure you're signing with the correct Bitcoin wallet.",
22
- // InvalidBTCPublicKey()
23
- "0x6c3f2bf6": "Invalid BTC public key: The Bitcoin public key format is invalid.",
24
- // InvalidAmount()
25
- "0x2c5211c6": "Invalid amount: The deposit amount is invalid or below the minimum required.",
26
- // ApplicationNotRegistered()
27
- "0x0405f772": "Application not registered: The application controller is not registered in the system.",
28
- // InvalidProviderStatus()
29
- "0x24e165cc": "Invalid provider status: The vault provider is not in a valid state to accept deposits.",
30
- // ZeroAddress()
31
- "0xd92e233d": "Zero address: One of the required addresses is the zero address.",
32
- // BtcKeyMismatch()
33
- "0x65aa7007": "BTC key mismatch: The Bitcoin public key does not match the expected key.",
34
- // Unauthorized()
35
- "0x82b42900": "Unauthorized: You must be the depositor or vault provider to submit this transaction.",
36
- // InvalidSignature() - common signature verification error
37
- "0x8baa579f": "Invalid signature: The BTC proof of possession signature could not be verified.",
38
- // InvalidBtcTransaction()
39
- "0x2f9d01e9": "Invalid BTC transaction: The Bitcoin transaction format is invalid.",
40
- // VaultProviderNotRegistered()
41
- "0x5a3c6b3e": "Vault provider not registered: The selected vault provider is not registered.",
42
- // InvalidPeginFee(uint256,uint256)
43
- "0x979f4518": "Invalid pegin fee: The ETH fee sent does not match the required amount. This may indicate a fee rate change during the transaction."
44
- };
45
- function bt(e) {
46
- if (!e || typeof e != "object") return;
47
- const t = e;
48
- if (typeof t.data == "string" && t.data.startsWith("0x"))
49
- return t.data;
50
- if (typeof t.details == "string" && t.details.startsWith("0x"))
51
- return t.details;
52
- let s = t.cause, n = 0;
53
- const o = 5;
54
- for (; s && typeof s == "object" && n < o; ) {
55
- const c = s;
56
- if (typeof c.data == "string" && c.data.startsWith("0x"))
57
- return c.data;
58
- s = c.cause, n++;
59
- }
60
- const i = (typeof t.message == "string" ? t.message : "").match(/\b(0x[a-fA-F0-9]{8})\b/);
61
- if (i)
62
- return i[1];
63
- }
64
- function Us(e) {
65
- const t = bt(e);
66
- if (t) {
67
- const s = t.substring(0, 10);
68
- return G[t] ?? G[s];
69
- }
70
- }
71
- function _s(e) {
72
- const t = bt(e);
73
- if (t === void 0) return !1;
74
- const s = t.substring(0, 10);
75
- return t in G || s in G;
76
- }
77
- function $(e) {
78
- console.error("[Contract Error] Raw error:", e);
79
- const t = bt(e);
80
- if (console.error("[Contract Error] Extracted error data:", t), t) {
81
- const n = t.substring(0, 10), o = G[t] ?? G[n];
82
- if (o)
83
- throw console.error("[Contract Error] Known error:", o), new Error(o);
84
- }
85
- const s = (e == null ? void 0 : e.message) || "";
86
- if (s.includes("gas limit too high") || s.includes("21000000") || s.includes("Internal JSON-RPC error")) {
87
- const n = t ? ` (error code: ${t})` : "";
88
- throw console.error(
89
- "[Contract Error] Transaction rejected. Error code:",
90
- t,
91
- "Message:",
92
- s
93
- ), new Error(
94
- `Transaction failed: The contract rejected this transaction${n}. Possible causes: (1) Vault already exists for this transaction, (2) Invalid signature, (3) Unauthorized caller. Please check your transaction parameters and try again.`
95
- );
96
- }
97
- throw e instanceof Error ? (console.error("[Contract Error] Unhandled error:", e.message), e) : new Error(`Contract call failed: ${String(e)}`);
98
- }
99
- const pe = 0;
100
- function ye(e, t, s, n) {
101
- const o = s == null ? void 0 : s[`${e}:${t}`];
102
- return o ? Promise.resolve({
103
- txid: e,
104
- vout: t,
105
- value: o.value,
106
- scriptPubKey: o.scriptPubKey
107
- }) : re(e, t, n);
108
- }
109
- const kt = 12e4;
110
- class Os {
111
- /**
112
- * Creates a new PeginManager instance.
113
- *
114
- * @param config - Manager configuration including wallets and contract addresses
115
- */
116
- constructor(t) {
117
- f(this, "config");
118
- this.config = t;
119
- }
120
- /**
121
- * Prepares a peg-in by building the Pre-PegIn HTLC transaction,
122
- * funding it, constructing the PegIn transaction, and signing the PegIn input.
123
- *
124
- * This method orchestrates the following steps:
125
- * 1. Get depositor BTC public key from wallet
126
- * 2. Build unfunded Pre-PegIn transaction (HTLC output) using primitives
127
- * 3. Select UTXOs to cover the HTLC value
128
- * 4. Fund the Pre-PegIn transaction
129
- * 5. Derive the PegIn transaction from the funded Pre-PegIn txid
130
- * 6. Build PSBT for signing the PegIn input (HTLC leaf 0)
131
- * 7. Sign via BTC wallet and extract depositor signature
132
- *
133
- * The returned `fundedPrePeginTxHex` is funded but unsigned (inputs unsigned).
134
- * Use `signAndBroadcast()` AFTER registering on Ethereum to broadcast it.
135
- *
136
- * @param params - Pegin parameters including amount, HTLC params, UTXOs
137
- * @returns Pegin result with funded Pre-PegIn tx, signed PegIn input, and signatures
138
- * @throws Error if wallet operations fail or insufficient funds
139
- */
140
- async preparePegin(t) {
141
- const s = await this.config.btcWallet.getPublicKeyHex(), n = s.length === 66 ? s.slice(2) : s, o = S(t.vaultProviderBtcPubkey), r = t.vaultKeeperBtcPubkeys.map(S), i = t.universalChallengerBtcPubkeys.map(S);
142
- if (t.hashlocks.length !== t.amounts.length)
143
- throw new Error(
144
- `hashlocks.length (${t.hashlocks.length}) must equal amounts.length (${t.amounts.length})`
145
- );
146
- if (t.hashlocks.length === 0)
147
- throw new Error("hashlocks must contain at least one entry");
148
- const c = r.length, h = {
149
- depositorPubkey: n,
150
- vaultProviderPubkey: o,
151
- vaultKeeperPubkeys: r,
152
- universalChallengerPubkeys: i,
153
- hashlocks: t.hashlocks,
154
- timelockRefund: t.timelockRefund,
155
- pegInAmounts: t.amounts,
156
- feeRate: t.protocolFeeRate,
157
- numLocalChallengers: c,
158
- councilQuorum: t.councilQuorum,
159
- councilSize: t.councilSize,
160
- network: this.config.btcNetwork
161
- }, b = await he(h), d = be(
162
- [...t.availableUTXOs],
163
- b.totalOutputValue,
164
- t.mempoolFeeRate,
165
- ce(b.htlcValues.length)
166
- ), a = Pt(this.config.btcNetwork), u = xe({
167
- unfundedTxHex: b.psbtHex,
168
- selectedUTXOs: d.selectedUTXOs,
169
- changeAddress: t.changeAddress,
170
- changeAmount: d.changeAmount,
171
- network: a
172
- }), p = S(ht(u)), x = [], y = [], P = [];
173
- for (let l = 0; l < t.hashlocks.length; l++) {
174
- const w = await le({
175
- prePeginParams: h,
176
- timelockPegin: t.timelockPegin,
177
- fundedPrePeginTxHex: u,
178
- htlcVout: l
179
- }), k = await ue({
180
- peginTxHex: w.txHex,
181
- fundedPrePeginTxHex: u,
182
- depositorPubkey: n,
183
- vaultProviderPubkey: o,
184
- vaultKeeperPubkeys: r,
185
- universalChallengerPubkeys: i,
186
- hashlock: t.hashlocks[l],
187
- timelockRefund: t.timelockRefund,
188
- network: this.config.btcNetwork
189
- });
190
- x.push(w), y.push(k.psbtHex), P.push(
191
- oe(s, 1)
192
- );
193
- }
194
- const m = await this.signPsbtsWithFallback(
195
- y,
196
- P
197
- ), g = [];
198
- for (let l = 0; l < m.length; l++) {
199
- const w = fe(
200
- m[l],
201
- n
202
- ), k = de(m[l]);
203
- g.push({
204
- htlcVout: l,
205
- htlcValue: b.htlcValues[l],
206
- peginTxHex: k,
207
- peginTxid: x[l].txid,
208
- peginInputSignature: w,
209
- vaultScriptPubKey: x[l].vaultScriptPubKey
210
- });
211
- }
212
- return {
213
- fundedPrePeginTxHex: u,
214
- prePeginTxid: p,
215
- unsignedPrePeginTxHex: b.psbtHex,
216
- perVault: g,
217
- selectedUTXOs: d.selectedUTXOs,
218
- fee: d.fee,
219
- changeAmount: d.changeAmount
220
- };
221
- }
222
- /**
223
- * Signs multiple PSBTs using batch signing if available, falling back to sequential signing.
224
- *
225
- * Wallets that support native batch signing (e.g. UniSat) will sign all PSBTs
226
- * in a single interaction. Others (e.g. Ledger, AppKit) implement signPsbts
227
- * by looping signPsbt internally, so the UX depends on the wallet adapter.
228
- */
229
- async signPsbtsWithFallback(t, s) {
230
- if (typeof this.config.btcWallet.signPsbts == "function") {
231
- const o = await this.config.btcWallet.signPsbts(
232
- t,
233
- s
234
- );
235
- if (o.length !== t.length)
236
- throw new Error(
237
- `Expected ${t.length} signed PSBTs but received ${o.length}`
238
- );
239
- return o;
240
- }
241
- const n = [];
242
- for (let o = 0; o < t.length; o++) {
243
- const r = await this.config.btcWallet.signPsbt(
244
- t[o],
245
- s[o]
246
- );
247
- n.push(r);
248
- }
249
- return n;
250
- }
251
- /**
252
- * Signs and broadcasts a funded peg-in transaction to the Bitcoin network.
253
- *
254
- * This method:
255
- * 1. Parses the funded transaction hex
256
- * 2. Fetches UTXO data from mempool for each input
257
- * 3. Creates a PSBT with proper witnessUtxo/tapInternalKey
258
- * 4. Signs via btcWallet.signPsbt()
259
- * 5. Finalizes and extracts the transaction
260
- * 6. Broadcasts via mempool API
261
- *
262
- * @param params - Transaction hex and depositor public key
263
- * @returns The broadcasted Bitcoin transaction ID
264
- * @throws Error if signing or broadcasting fails
265
- */
266
- async signAndBroadcast(t) {
267
- const { fundedPrePeginTxHex: s, depositorBtcPubkey: n } = t, o = s.startsWith("0x") ? s.slice(2) : s, r = se.fromHex(o);
268
- if (r.ins.length === 0)
269
- throw new Error("Transaction has no inputs");
270
- const i = new wt();
271
- i.setVersion(r.version), i.setLocktime(r.locktime);
272
- const c = n.startsWith("0x") ? n.slice(2) : n;
273
- if (c.length !== 64 || !/^[0-9a-fA-F]+$/.test(c))
274
- throw new Error(
275
- "Invalid depositorBtcPubkey: expected 64 hex characters (x-only pubkey)"
276
- );
277
- const h = rt.from(c, "hex");
278
- if (h.length !== 32)
279
- throw new Error(
280
- `Invalid depositorBtcPubkey length: expected 32 bytes, got ${h.length}`
281
- );
282
- const b = this.config.mempoolApiUrl, d = r.ins.map((g) => {
283
- const l = rt.from(g.hash).reverse().toString("hex"), w = g.index;
284
- return ye(l, w, t.localPrevouts, b).then(
285
- (k) => ({ input: g, utxoData: k, txid: l, vout: w })
286
- );
287
- }), a = await Promise.all(d), u = a.reduce(
288
- (g, l) => g + BigInt(l.utxoData.value),
289
- 0n
290
- ), p = r.outs.reduce(
291
- (g, l) => g + BigInt(l.value),
292
- 0n
293
- );
294
- if (u < p)
295
- throw new Error(
296
- `UTXO value mismatch: total input value (${u} sat) is less than total output value (${p} sat). This may indicate the mempool API returned manipulated UTXO data.`
297
- );
298
- for (const { input: g, utxoData: l, txid: w, vout: k } of a) {
299
- const H = ge(
300
- {
301
- value: l.value,
302
- scriptPubKey: l.scriptPubKey
303
- },
304
- h
305
- );
306
- i.addInput({
307
- hash: g.hash,
308
- index: g.index,
309
- sequence: g.sequence,
310
- ...H
311
- });
312
- }
313
- for (const g of r.outs)
314
- i.addOutput({
315
- script: g.script,
316
- value: g.value
317
- });
318
- const x = await this.config.btcWallet.signPsbt(i.toHex()), y = wt.fromHex(x);
319
- try {
320
- y.finalizeAllInputs();
321
- } catch (g) {
322
- if (!y.data.inputs.every(
323
- (w) => w.finalScriptWitness || w.finalScriptSig
324
- ))
325
- throw new Error(
326
- `PSBT finalization failed and wallet did not auto-finalize: ${g}`
327
- );
328
- }
329
- const P = y.extractTransaction().toHex();
330
- return await ie(P, b);
331
- }
332
- /**
333
- * Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
334
- *
335
- * This method:
336
- * 1. Gets depositor ETH address from wallet
337
- * 2. Creates proof of possession (BTC signature of ETH address)
338
- * 3. Checks if vault already exists (pre-flight check)
339
- * 4. Encodes the contract call using viem
340
- * 5. Estimates gas (catches contract errors early with proper revert reasons)
341
- * 6. Sends transaction with pre-estimated gas via ethWallet.sendTransaction()
342
- *
343
- * @param params - Registration parameters including BTC pubkey and unsigned tx
344
- * @returns Result containing Ethereum transaction hash and vault ID
345
- * @throws Error if signing or transaction fails
346
- * @throws Error if vault already exists
347
- * @throws Error if contract simulation fails (e.g., invalid signature, unauthorized)
348
- */
349
- async registerPeginOnChain(t) {
350
- const {
351
- depositorBtcPubkey: s,
352
- unsignedPrePeginTx: n,
353
- depositorSignedPeginTx: o,
354
- vaultProvider: r,
355
- hashlock: i,
356
- htlcVout: c,
357
- onPopSigned: h,
358
- depositorPayoutBtcAddress: b,
359
- depositorWotsPkHash: d,
360
- preSignedBtcPopSignature: a
361
- } = t;
362
- if (!this.config.ethWallet.account)
363
- throw new Error("Ethereum wallet account not found");
364
- const u = this.config.ethWallet.account.address, p = await this.resolvePopSignature(
365
- u,
366
- a
367
- );
368
- h && await h();
369
- const x = C(s), y = C(n), P = C(o), m = await this.resolvePayoutScriptPubKey(
370
- b
371
- ), g = ht(P), l = await Ht(
372
- S(g),
373
- S(u)
374
- ), w = C(l);
375
- if (await this.checkVaultExists(w))
376
- throw new Error(
377
- `Vault already exists (ID: ${w}, peginTxHash: ${g}). Vault IDs are derived from the pegin transaction hash and depositor address. To create a new vault, use different UTXOs or a different amount to generate a unique transaction.`
378
- );
379
- const H = ct({
380
- chain: this.config.ethChain,
381
- transport: at()
382
- });
383
- let I;
384
- try {
385
- I = await H.readContract({
386
- address: this.config.vaultContracts.btcVaultRegistry,
387
- abi: j,
388
- functionName: "getPegInFee",
389
- args: [r]
390
- });
391
- } catch {
392
- throw new Error(
393
- "Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
394
- );
395
- }
396
- const E = mt({
397
- abi: j,
398
- functionName: "submitPeginRequest",
399
- args: [
400
- u,
401
- x,
402
- p,
403
- y,
404
- P,
405
- r,
406
- i,
407
- c,
408
- m,
409
- d
410
- ]
411
- });
412
- let v;
413
- try {
414
- v = await H.estimateGas({
415
- to: this.config.vaultContracts.btcVaultRegistry,
416
- data: E,
417
- value: I,
418
- account: this.config.ethWallet.account.address
419
- });
420
- } catch (_) {
421
- $(_);
422
- }
423
- let U;
424
- try {
425
- U = await this.config.ethWallet.sendTransaction({
426
- to: this.config.vaultContracts.btcVaultRegistry,
427
- data: E,
428
- value: I,
429
- account: this.config.ethWallet.account,
430
- chain: this.config.ethChain,
431
- gas: v
432
- });
433
- } catch (_) {
434
- $(_);
435
- }
436
- const K = await H.waitForTransactionReceipt({
437
- hash: U,
438
- timeout: kt
439
- });
440
- return K.status === "reverted" && $(
441
- new Error(
442
- `Transaction reverted. Hash: ${U}. Check the transaction on block explorer for details.`
443
- )
444
- ), {
445
- ethTxHash: K.transactionHash,
446
- vaultId: w,
447
- peginTxHash: g,
448
- btcPopSignature: p
449
- };
450
- }
451
- /**
452
- * Register multiple pegins on Ethereum in a single transaction.
453
- *
454
- * Uses the contract's submitPeginRequestBatch() to submit all vault
455
- * registrations atomically. All vaults must share the same vault provider.
456
- * The PoP signature is signed once and included in each request.
457
- *
458
- * @param params - Batch registration parameters
459
- * @returns Batch result with per-vault IDs and single ETH tx hash
460
- */
461
- async registerPeginBatchOnChain(t) {
462
- const { vaultProvider: s, requests: n, preSignedBtcPopSignature: o, onPopSigned: r } = t;
463
- if (n.length === 0)
464
- throw new Error("Batch pegin requires at least one request");
465
- if (!this.config.ethWallet.account)
466
- throw new Error("Ethereum wallet account not found");
467
- const i = this.config.ethWallet.account.address, c = await this.resolvePopSignature(
468
- i,
469
- o
470
- );
471
- r && await r();
472
- const h = [];
473
- for (const g of n)
474
- h.push(
475
- await this.resolvePayoutScriptPubKey(g.depositorPayoutBtcAddress)
476
- );
477
- const b = [];
478
- for (const g of n) {
479
- const l = C(
480
- g.depositorSignedPeginTx
481
- ), w = ht(l), k = await Ht(
482
- S(w),
483
- S(i)
484
- ), H = C(k);
485
- if (await this.checkVaultExists(H))
486
- throw new Error(
487
- `Vault already exists (ID: ${H}, peginTxHash: ${w}). To create a new vault, use different UTXOs or a different amount.`
488
- );
489
- b.push({ vaultId: H, peginTxHash: w });
490
- }
491
- const d = ct({
492
- chain: this.config.ethChain,
493
- transport: at()
494
- });
495
- let a;
496
- try {
497
- a = await d.readContract({
498
- address: this.config.vaultContracts.btcVaultRegistry,
499
- abi: j,
500
- functionName: "getPegInFee",
501
- args: [s]
502
- });
503
- } catch {
504
- throw new Error(
505
- "Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
506
- );
507
- }
508
- const u = a * BigInt(n.length), p = n.map((g, l) => ({
509
- depositorBtcPubKey: C(g.depositorBtcPubkey),
510
- btcPopSignature: c,
511
- unsignedPrePeginTx: C(g.unsignedPrePeginTx),
512
- depositorSignedPeginTx: C(
513
- g.depositorSignedPeginTx
514
- ),
515
- hashlock: g.hashlock,
516
- htlcVout: g.htlcVout,
517
- referralCode: pe,
518
- depositorPayoutBtcAddress: h[l],
519
- depositorWotsPkHash: g.depositorWotsPkHash
520
- })), x = mt({
521
- abi: j,
522
- functionName: "submitPeginRequestBatch",
523
- args: [i, s, p]
524
- });
525
- let y;
526
- try {
527
- y = await d.estimateGas({
528
- to: this.config.vaultContracts.btcVaultRegistry,
529
- data: x,
530
- value: u,
531
- account: this.config.ethWallet.account.address
532
- });
533
- } catch (g) {
534
- $(g);
535
- }
536
- let P;
537
- try {
538
- P = await this.config.ethWallet.sendTransaction({
539
- to: this.config.vaultContracts.btcVaultRegistry,
540
- data: x,
541
- value: u,
542
- account: this.config.ethWallet.account,
543
- chain: this.config.ethChain,
544
- gas: y
545
- });
546
- } catch (g) {
547
- $(g);
548
- }
549
- const m = await d.waitForTransactionReceipt({
550
- hash: P,
551
- timeout: kt
552
- });
553
- return m.status === "reverted" && $(
554
- new Error(
555
- `Batch transaction reverted. Hash: ${P}. Check the transaction on block explorer for details.`
556
- )
557
- ), {
558
- ethTxHash: m.transactionHash,
559
- vaults: b,
560
- btcPopSignature: c
561
- };
562
- }
563
- /**
564
- * Check if a vault already exists for a given vault ID.
565
- *
566
- * @param vaultId - The Bitcoin transaction hash (vault ID)
567
- * @returns True if vault exists, false otherwise
568
- */
569
- async checkVaultExists(t) {
570
- try {
571
- return (await ct({
572
- chain: this.config.ethChain,
573
- transport: at()
574
- }).readContract({
575
- address: this.config.vaultContracts.btcVaultRegistry,
576
- abi: j,
577
- functionName: "getBtcVaultBasicInfo",
578
- args: [t]
579
- }))[0] !== ne;
580
- } catch {
581
- return !1;
582
- }
583
- }
584
- /**
585
- * Resolve the BTC payout address to a scriptPubKey hex for the contract.
586
- *
587
- * If a payout address is provided, converts it directly.
588
- * If omitted, uses the wallet's address and validates it against the
589
- * wallet's public key to guard against a compromised wallet provider.
590
- */
591
- async resolvePayoutScriptPubKey(t) {
592
- let s;
593
- if (t)
594
- s = t;
595
- else {
596
- s = await this.config.btcWallet.getAddress();
597
- const o = await this.config.btcWallet.getPublicKeyHex();
598
- if (!ae(
599
- s,
600
- o,
601
- this.config.btcNetwork
602
- ))
603
- throw new Error(
604
- "The BTC address from your wallet does not match the wallet's public key. Please ensure your wallet is using a supported address type (Taproot or Native SegWit)."
605
- );
606
- }
607
- const n = Pt(this.config.btcNetwork);
608
- try {
609
- return `0x${ee.address.toOutputScript(s, n).toString("hex")}`;
610
- } catch {
611
- throw new Error(
612
- `Invalid BTC payout address: "${s}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`
613
- );
614
- }
615
- }
616
- /**
617
- * Resolve or create a BTC Proof-of-Possession signature.
618
- *
619
- * Reuses a pre-signed signature when provided (e.g. multi-vault deposits),
620
- * otherwise signs a BIP-322 message with the BTC wallet.
621
- */
622
- async resolvePopSignature(t, s) {
623
- if (s)
624
- return s;
625
- const n = this.config.vaultContracts.btcVaultRegistry, o = `${t.toLowerCase()}:${this.config.ethChain.id}:pegin:${n.toLowerCase()}`, r = await this.config.btcWallet.signMessage(
626
- o,
627
- "bip322-simple"
628
- );
629
- return r.startsWith("0x") ? r : `0x${rt.from(r, "base64").toString("hex")}`;
630
- }
631
- /**
632
- * Gets the configured Bitcoin network.
633
- *
634
- * @returns The Bitcoin network (mainnet, testnet, signet, regtest)
635
- */
636
- getNetwork() {
637
- return this.config.btcNetwork;
638
- }
639
- /**
640
- * Gets the configured BTCVaultRegistry contract address.
641
- *
642
- * @returns The Ethereum address of the BTCVaultRegistry contract
643
- */
644
- getVaultContractAddress() {
645
- return this.config.vaultContracts.btcVaultRegistry;
646
- }
647
- }
648
- function we(e) {
649
- return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
650
- }
651
- function V(e, t = "") {
652
- if (!Number.isSafeInteger(e) || e < 0) {
653
- const s = t && `"${t}" `;
654
- throw new Error(`${s}expected integer >= 0, got ${e}`);
655
- }
656
- }
657
- function D(e, t, s = "") {
658
- const n = we(e), o = e == null ? void 0 : e.length, r = t !== void 0;
659
- if (!n || r && o !== t) {
660
- const i = s && `"${s}" `, c = r ? ` of length ${t}` : "", h = n ? `length=${o}` : `type=${typeof e}`;
661
- throw new Error(i + "expected Uint8Array" + c + ", got " + h);
662
- }
663
- return e;
664
- }
665
- function Ot(e) {
666
- if (typeof e != "function" || typeof e.create != "function")
667
- throw new Error("Hash must wrapped by utils.createHasher");
668
- V(e.outputLen), V(e.blockLen);
669
- }
670
- function X(e, t = !0) {
671
- if (e.destroyed)
672
- throw new Error("Hash instance has been destroyed");
673
- if (t && e.finished)
674
- throw new Error("Hash#digest() has already been called");
675
- }
676
- function Ft(e, t) {
677
- D(e, void 0, "digestInto() output");
678
- const s = t.outputLen;
679
- if (e.length < s)
680
- throw new Error('"digestInto() output" expected to be of length >=' + s);
681
- }
682
- function me(e) {
683
- return new Uint32Array(e.buffer, e.byteOffset, Math.floor(e.byteLength / 4));
684
- }
685
- function A(...e) {
686
- for (let t = 0; t < e.length; t++)
687
- e[t].fill(0);
688
- }
689
- function nt(e) {
690
- return new DataView(e.buffer, e.byteOffset, e.byteLength);
691
- }
692
- function B(e, t) {
693
- return e << 32 - t | e >>> t;
694
- }
695
- function Z(e, t) {
696
- return e << t | e >>> 32 - t >>> 0;
697
- }
698
- const Pe = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
699
- function He(e) {
700
- return e << 24 & 4278190080 | e << 8 & 16711680 | e >>> 8 & 65280 | e >>> 24 & 255;
701
- }
702
- function ke(e) {
703
- for (let t = 0; t < e.length; t++)
704
- e[t] = He(e[t]);
705
- return e;
706
- }
707
- const Tt = Pe ? (e) => e : ke;
708
- function Te(e) {
709
- if (typeof e != "string")
710
- throw new Error("string expected");
711
- return new Uint8Array(new TextEncoder().encode(e));
712
- }
713
- function It(e, t = "") {
714
- return typeof e == "string" ? Te(e) : D(e, void 0, t);
715
- }
716
- function Ie(e, t) {
717
- if (t !== void 0 && {}.toString.call(t) !== "[object Object]")
718
- throw new Error("options must be object or undefined");
719
- return Object.assign(e, t);
720
- }
721
- function ot(e, t = {}) {
722
- const s = (o, r) => e(r).update(o).digest(), n = e(void 0);
723
- return s.outputLen = n.outputLen, s.blockLen = n.blockLen, s.create = (o) => e(o), Object.assign(s, t), Object.freeze(s);
724
- }
725
- const Rt = (e) => ({
726
- oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, e])
727
- });
728
- class Wt {
729
- constructor(t, s) {
730
- f(this, "oHash");
731
- f(this, "iHash");
732
- f(this, "blockLen");
733
- f(this, "outputLen");
734
- f(this, "finished", !1);
735
- f(this, "destroyed", !1);
736
- if (Ot(t), D(s, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function")
737
- throw new Error("Expected instance of class which extends utils.Hash");
738
- this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
739
- const n = this.blockLen, o = new Uint8Array(n);
740
- o.set(s.length > n ? t.create().update(s).digest() : s);
741
- for (let r = 0; r < o.length; r++)
742
- o[r] ^= 54;
743
- this.iHash.update(o), this.oHash = t.create();
744
- for (let r = 0; r < o.length; r++)
745
- o[r] ^= 106;
746
- this.oHash.update(o), A(o);
747
- }
748
- update(t) {
749
- return X(this), this.iHash.update(t), this;
750
- }
751
- digestInto(t) {
752
- X(this), D(t, this.outputLen, "output"), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
753
- }
754
- digest() {
755
- const t = new Uint8Array(this.oHash.outputLen);
756
- return this.digestInto(t), t;
757
- }
758
- _cloneInto(t) {
759
- t || (t = Object.create(Object.getPrototypeOf(this), {}));
760
- const { oHash: s, iHash: n, finished: o, destroyed: r, blockLen: i, outputLen: c } = this;
761
- return t = t, t.finished = o, t.destroyed = r, t.blockLen = i, t.outputLen = c, t.oHash = s._cloneInto(t.oHash), t.iHash = n._cloneInto(t.iHash), t;
762
- }
763
- clone() {
764
- return this._cloneInto();
765
- }
766
- destroy() {
767
- this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
768
- }
769
- }
770
- const gt = (e, t, s) => new Wt(e, t).update(s).digest();
771
- gt.create = (e, t) => new Wt(e, t);
772
- function Ee(e, t, s) {
773
- return e & t ^ ~e & s;
774
- }
775
- function ve(e, t, s) {
776
- return e & t ^ e & s ^ t & s;
777
- }
778
- class xt {
779
- constructor(t, s, n, o) {
780
- f(this, "blockLen");
781
- f(this, "outputLen");
782
- f(this, "padOffset");
783
- f(this, "isLE");
784
- // For partial updates less than block size
785
- f(this, "buffer");
786
- f(this, "view");
787
- f(this, "finished", !1);
788
- f(this, "length", 0);
789
- f(this, "pos", 0);
790
- f(this, "destroyed", !1);
791
- this.blockLen = t, this.outputLen = s, this.padOffset = n, this.isLE = o, this.buffer = new Uint8Array(t), this.view = nt(this.buffer);
792
- }
793
- update(t) {
794
- X(this), D(t);
795
- const { view: s, buffer: n, blockLen: o } = this, r = t.length;
796
- for (let i = 0; i < r; ) {
797
- const c = Math.min(o - this.pos, r - i);
798
- if (c === o) {
799
- const h = nt(t);
800
- for (; o <= r - i; i += o)
801
- this.process(h, i);
802
- continue;
803
- }
804
- n.set(t.subarray(i, i + c), this.pos), this.pos += c, i += c, this.pos === o && (this.process(s, 0), this.pos = 0);
805
- }
806
- return this.length += t.length, this.roundClean(), this;
807
- }
808
- digestInto(t) {
809
- X(this), Ft(t, this), this.finished = !0;
810
- const { buffer: s, view: n, blockLen: o, isLE: r } = this;
811
- let { pos: i } = this;
812
- s[i++] = 128, A(this.buffer.subarray(i)), this.padOffset > o - i && (this.process(n, 0), i = 0);
813
- for (let a = i; a < o; a++)
814
- s[a] = 0;
815
- n.setBigUint64(o - 8, BigInt(this.length * 8), r), this.process(n, 0);
816
- const c = nt(t), h = this.outputLen;
817
- if (h % 4)
818
- throw new Error("_sha2: outputLen must be aligned to 32bit");
819
- const b = h / 4, d = this.get();
820
- if (b > d.length)
821
- throw new Error("_sha2: outputLen bigger than state");
822
- for (let a = 0; a < b; a++)
823
- c.setUint32(4 * a, d[a], r);
824
- }
825
- digest() {
826
- const { buffer: t, outputLen: s } = this;
827
- this.digestInto(t);
828
- const n = t.slice(0, s);
829
- return this.destroy(), n;
830
- }
831
- _cloneInto(t) {
832
- t || (t = new this.constructor()), t.set(...this.get());
833
- const { blockLen: s, buffer: n, length: o, finished: r, destroyed: i, pos: c } = this;
834
- return t.destroyed = i, t.finished = r, t.length = o, t.pos = c, o % s && t.buffer.set(n), t;
835
- }
836
- clone() {
837
- return this._cloneInto();
838
- }
839
- }
840
- const O = /* @__PURE__ */ Uint32Array.from([
841
- 1779033703,
842
- 3144134277,
843
- 1013904242,
844
- 2773480762,
845
- 1359893119,
846
- 2600822924,
847
- 528734635,
848
- 1541459225
849
- ]), T = /* @__PURE__ */ Uint32Array.from([
850
- 1779033703,
851
- 4089235720,
852
- 3144134277,
853
- 2227873595,
854
- 1013904242,
855
- 4271175723,
856
- 2773480762,
857
- 1595750129,
858
- 1359893119,
859
- 2917565137,
860
- 2600822924,
861
- 725511199,
862
- 528734635,
863
- 4215389547,
864
- 1541459225,
865
- 327033209
866
- ]), Ae = /* @__PURE__ */ Uint8Array.from([
867
- 7,
868
- 4,
869
- 13,
870
- 1,
871
- 10,
872
- 6,
873
- 15,
874
- 3,
875
- 12,
876
- 0,
877
- 9,
878
- 5,
879
- 2,
880
- 14,
881
- 11,
882
- 8
883
- ]), Vt = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)), Be = Vt.map((e) => (9 * e + 5) % 16), Dt = /* @__PURE__ */ (() => {
884
- const s = [[Vt], [Be]];
885
- for (let n = 0; n < 4; n++)
886
- for (let o of s)
887
- o.push(o[n].map((r) => Ae[r]));
888
- return s;
889
- })(), Kt = Dt[0], $t = Dt[1], Nt = /* @__PURE__ */ [
890
- [11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
891
- [12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
892
- [13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
893
- [14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
894
- [15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
895
- ].map((e) => Uint8Array.from(e)), Se = /* @__PURE__ */ Kt.map((e, t) => e.map((s) => Nt[t][s])), Ce = /* @__PURE__ */ $t.map((e, t) => e.map((s) => Nt[t][s])), Le = /* @__PURE__ */ Uint32Array.from([
896
- 0,
897
- 1518500249,
898
- 1859775393,
899
- 2400959708,
900
- 2840853838
901
- ]), Ue = /* @__PURE__ */ Uint32Array.from([
902
- 1352829926,
903
- 1548603684,
904
- 1836072691,
905
- 2053994217,
906
- 0
907
- ]);
908
- function Et(e, t, s, n) {
909
- return e === 0 ? t ^ s ^ n : e === 1 ? t & s | ~t & n : e === 2 ? (t | ~s) ^ n : e === 3 ? t & n | s & ~n : t ^ (s | ~n);
910
- }
911
- const J = /* @__PURE__ */ new Uint32Array(16);
912
- class _e extends xt {
913
- constructor() {
914
- super(64, 20, 8, !0);
915
- f(this, "h0", 1732584193);
916
- f(this, "h1", -271733879);
917
- f(this, "h2", -1732584194);
918
- f(this, "h3", 271733878);
919
- f(this, "h4", -1009589776);
920
- }
921
- get() {
922
- const { h0: s, h1: n, h2: o, h3: r, h4: i } = this;
923
- return [s, n, o, r, i];
924
- }
925
- set(s, n, o, r, i) {
926
- this.h0 = s | 0, this.h1 = n | 0, this.h2 = o | 0, this.h3 = r | 0, this.h4 = i | 0;
927
- }
928
- process(s, n) {
929
- for (let x = 0; x < 16; x++, n += 4)
930
- J[x] = s.getUint32(n, !0);
931
- let o = this.h0 | 0, r = o, i = this.h1 | 0, c = i, h = this.h2 | 0, b = h, d = this.h3 | 0, a = d, u = this.h4 | 0, p = u;
932
- for (let x = 0; x < 5; x++) {
933
- const y = 4 - x, P = Le[x], m = Ue[x], g = Kt[x], l = $t[x], w = Se[x], k = Ce[x];
934
- for (let H = 0; H < 16; H++) {
935
- const I = Z(o + Et(x, i, h, d) + J[g[H]] + P, w[H]) + u | 0;
936
- o = u, u = d, d = Z(h, 10) | 0, h = i, i = I;
937
- }
938
- for (let H = 0; H < 16; H++) {
939
- const I = Z(r + Et(y, c, b, a) + J[l[H]] + m, k[H]) + p | 0;
940
- r = p, p = a, a = Z(b, 10) | 0, b = c, c = I;
941
- }
942
- }
943
- this.set(this.h1 + h + a | 0, this.h2 + d + p | 0, this.h3 + u + r | 0, this.h4 + o + c | 0, this.h0 + i + b | 0);
944
- }
945
- roundClean() {
946
- A(J);
947
- }
948
- destroy() {
949
- this.destroyed = !0, A(this.buffer), this.set(0, 0, 0, 0, 0);
950
- }
951
- }
952
- const Oe = /* @__PURE__ */ ot(() => new _e()), Q = /* @__PURE__ */ BigInt(2 ** 32 - 1), vt = /* @__PURE__ */ BigInt(32);
953
- function Fe(e, t = !1) {
954
- return t ? { h: Number(e & Q), l: Number(e >> vt & Q) } : { h: Number(e >> vt & Q) | 0, l: Number(e & Q) | 0 };
955
- }
956
- function Mt(e, t = !1) {
957
- const s = e.length;
958
- let n = new Uint32Array(s), o = new Uint32Array(s);
959
- for (let r = 0; r < s; r++) {
960
- const { h: i, l: c } = Fe(e[r], t);
961
- [n[r], o[r]] = [i, c];
962
- }
963
- return [n, o];
964
- }
965
- const At = (e, t, s) => e >>> s, Bt = (e, t, s) => e << 32 - s | t >>> s, N = (e, t, s) => e >>> s | t << 32 - s, M = (e, t, s) => e << 32 - s | t >>> s, Y = (e, t, s) => e << 64 - s | t >>> s - 32, tt = (e, t, s) => e >>> s - 32 | t << 64 - s, Re = (e, t, s) => e << s | t >>> 32 - s, We = (e, t, s) => t << s | e >>> 32 - s, Ve = (e, t, s) => t << s - 32 | e >>> 64 - s, De = (e, t, s) => e << s - 32 | t >>> 64 - s;
966
- function L(e, t, s, n) {
967
- const o = (t >>> 0) + (n >>> 0);
968
- return { h: e + s + (o / 2 ** 32 | 0) | 0, l: o | 0 };
969
- }
970
- const Ke = (e, t, s) => (e >>> 0) + (t >>> 0) + (s >>> 0), $e = (e, t, s, n) => t + s + n + (e / 2 ** 32 | 0) | 0, Ne = (e, t, s, n) => (e >>> 0) + (t >>> 0) + (s >>> 0) + (n >>> 0), Me = (e, t, s, n, o) => t + s + n + o + (e / 2 ** 32 | 0) | 0, Ge = (e, t, s, n, o) => (e >>> 0) + (t >>> 0) + (s >>> 0) + (n >>> 0) + (o >>> 0), Xe = (e, t, s, n, o, r) => t + s + n + o + r + (e / 2 ** 32 | 0) | 0, je = /* @__PURE__ */ Uint32Array.from([
971
- 1116352408,
972
- 1899447441,
973
- 3049323471,
974
- 3921009573,
975
- 961987163,
976
- 1508970993,
977
- 2453635748,
978
- 2870763221,
979
- 3624381080,
980
- 310598401,
981
- 607225278,
982
- 1426881987,
983
- 1925078388,
984
- 2162078206,
985
- 2614888103,
986
- 3248222580,
987
- 3835390401,
988
- 4022224774,
989
- 264347078,
990
- 604807628,
991
- 770255983,
992
- 1249150122,
993
- 1555081692,
994
- 1996064986,
995
- 2554220882,
996
- 2821834349,
997
- 2952996808,
998
- 3210313671,
999
- 3336571891,
1000
- 3584528711,
1001
- 113926993,
1002
- 338241895,
1003
- 666307205,
1004
- 773529912,
1005
- 1294757372,
1006
- 1396182291,
1007
- 1695183700,
1008
- 1986661051,
1009
- 2177026350,
1010
- 2456956037,
1011
- 2730485921,
1012
- 2820302411,
1013
- 3259730800,
1014
- 3345764771,
1015
- 3516065817,
1016
- 3600352804,
1017
- 4094571909,
1018
- 275423344,
1019
- 430227734,
1020
- 506948616,
1021
- 659060556,
1022
- 883997877,
1023
- 958139571,
1024
- 1322822218,
1025
- 1537002063,
1026
- 1747873779,
1027
- 1955562222,
1028
- 2024104815,
1029
- 2227730452,
1030
- 2361852424,
1031
- 2428436474,
1032
- 2756734187,
1033
- 3204031479,
1034
- 3329325298
1035
- ]), F = /* @__PURE__ */ new Uint32Array(64);
1036
- class qe extends xt {
1037
- constructor(t) {
1038
- super(64, t, 8, !1);
1039
- }
1040
- get() {
1041
- const { A: t, B: s, C: n, D: o, E: r, F: i, G: c, H: h } = this;
1042
- return [t, s, n, o, r, i, c, h];
1043
- }
1044
- // prettier-ignore
1045
- set(t, s, n, o, r, i, c, h) {
1046
- this.A = t | 0, this.B = s | 0, this.C = n | 0, this.D = o | 0, this.E = r | 0, this.F = i | 0, this.G = c | 0, this.H = h | 0;
1047
- }
1048
- process(t, s) {
1049
- for (let a = 0; a < 16; a++, s += 4)
1050
- F[a] = t.getUint32(s, !1);
1051
- for (let a = 16; a < 64; a++) {
1052
- const u = F[a - 15], p = F[a - 2], x = B(u, 7) ^ B(u, 18) ^ u >>> 3, y = B(p, 17) ^ B(p, 19) ^ p >>> 10;
1053
- F[a] = y + F[a - 7] + x + F[a - 16] | 0;
1054
- }
1055
- let { A: n, B: o, C: r, D: i, E: c, F: h, G: b, H: d } = this;
1056
- for (let a = 0; a < 64; a++) {
1057
- const u = B(c, 6) ^ B(c, 11) ^ B(c, 25), p = d + u + Ee(c, h, b) + je[a] + F[a] | 0, y = (B(n, 2) ^ B(n, 13) ^ B(n, 22)) + ve(n, o, r) | 0;
1058
- d = b, b = h, h = c, c = i + p | 0, i = r, r = o, o = n, n = p + y | 0;
1059
- }
1060
- n = n + this.A | 0, o = o + this.B | 0, r = r + this.C | 0, i = i + this.D | 0, c = c + this.E | 0, h = h + this.F | 0, b = b + this.G | 0, d = d + this.H | 0, this.set(n, o, r, i, c, h, b, d);
1061
- }
1062
- roundClean() {
1063
- A(F);
1064
- }
1065
- destroy() {
1066
- this.set(0, 0, 0, 0, 0, 0, 0, 0), A(this.buffer);
1067
- }
1068
- }
1069
- class ze extends qe {
1070
- constructor() {
1071
- super(32);
1072
- // We cannot use array here since array allows indexing by variable
1073
- // which means optimizer/compiler cannot use registers.
1074
- f(this, "A", O[0] | 0);
1075
- f(this, "B", O[1] | 0);
1076
- f(this, "C", O[2] | 0);
1077
- f(this, "D", O[3] | 0);
1078
- f(this, "E", O[4] | 0);
1079
- f(this, "F", O[5] | 0);
1080
- f(this, "G", O[6] | 0);
1081
- f(this, "H", O[7] | 0);
1082
- }
1083
- }
1084
- const Gt = Mt([
1085
- "0x428a2f98d728ae22",
1086
- "0x7137449123ef65cd",
1087
- "0xb5c0fbcfec4d3b2f",
1088
- "0xe9b5dba58189dbbc",
1089
- "0x3956c25bf348b538",
1090
- "0x59f111f1b605d019",
1091
- "0x923f82a4af194f9b",
1092
- "0xab1c5ed5da6d8118",
1093
- "0xd807aa98a3030242",
1094
- "0x12835b0145706fbe",
1095
- "0x243185be4ee4b28c",
1096
- "0x550c7dc3d5ffb4e2",
1097
- "0x72be5d74f27b896f",
1098
- "0x80deb1fe3b1696b1",
1099
- "0x9bdc06a725c71235",
1100
- "0xc19bf174cf692694",
1101
- "0xe49b69c19ef14ad2",
1102
- "0xefbe4786384f25e3",
1103
- "0x0fc19dc68b8cd5b5",
1104
- "0x240ca1cc77ac9c65",
1105
- "0x2de92c6f592b0275",
1106
- "0x4a7484aa6ea6e483",
1107
- "0x5cb0a9dcbd41fbd4",
1108
- "0x76f988da831153b5",
1109
- "0x983e5152ee66dfab",
1110
- "0xa831c66d2db43210",
1111
- "0xb00327c898fb213f",
1112
- "0xbf597fc7beef0ee4",
1113
- "0xc6e00bf33da88fc2",
1114
- "0xd5a79147930aa725",
1115
- "0x06ca6351e003826f",
1116
- "0x142929670a0e6e70",
1117
- "0x27b70a8546d22ffc",
1118
- "0x2e1b21385c26c926",
1119
- "0x4d2c6dfc5ac42aed",
1120
- "0x53380d139d95b3df",
1121
- "0x650a73548baf63de",
1122
- "0x766a0abb3c77b2a8",
1123
- "0x81c2c92e47edaee6",
1124
- "0x92722c851482353b",
1125
- "0xa2bfe8a14cf10364",
1126
- "0xa81a664bbc423001",
1127
- "0xc24b8b70d0f89791",
1128
- "0xc76c51a30654be30",
1129
- "0xd192e819d6ef5218",
1130
- "0xd69906245565a910",
1131
- "0xf40e35855771202a",
1132
- "0x106aa07032bbd1b8",
1133
- "0x19a4c116b8d2d0c8",
1134
- "0x1e376c085141ab53",
1135
- "0x2748774cdf8eeb99",
1136
- "0x34b0bcb5e19b48a8",
1137
- "0x391c0cb3c5c95a63",
1138
- "0x4ed8aa4ae3418acb",
1139
- "0x5b9cca4f7763e373",
1140
- "0x682e6ff3d6b2b8a3",
1141
- "0x748f82ee5defb2fc",
1142
- "0x78a5636f43172f60",
1143
- "0x84c87814a1f0ab72",
1144
- "0x8cc702081a6439ec",
1145
- "0x90befffa23631e28",
1146
- "0xa4506cebde82bde9",
1147
- "0xbef9a3f7b2c67915",
1148
- "0xc67178f2e372532b",
1149
- "0xca273eceea26619c",
1150
- "0xd186b8c721c0c207",
1151
- "0xeada7dd6cde0eb1e",
1152
- "0xf57d4f7fee6ed178",
1153
- "0x06f067aa72176fba",
1154
- "0x0a637dc5a2c898a6",
1155
- "0x113f9804bef90dae",
1156
- "0x1b710b35131c471b",
1157
- "0x28db77f523047d84",
1158
- "0x32caab7b40c72493",
1159
- "0x3c9ebe0a15c9bebc",
1160
- "0x431d67c49c100d4c",
1161
- "0x4cc5d4becb3e42b6",
1162
- "0x597f299cfc657e2a",
1163
- "0x5fcb6fab3ad6faec",
1164
- "0x6c44198c4a475817"
1165
- ].map((e) => BigInt(e))), Ze = Gt[0], Je = Gt[1], R = /* @__PURE__ */ new Uint32Array(80), W = /* @__PURE__ */ new Uint32Array(80);
1166
- class Qe extends xt {
1167
- constructor(t) {
1168
- super(128, t, 16, !1);
1169
- }
1170
- // prettier-ignore
1171
- get() {
1172
- const { Ah: t, Al: s, Bh: n, Bl: o, Ch: r, Cl: i, Dh: c, Dl: h, Eh: b, El: d, Fh: a, Fl: u, Gh: p, Gl: x, Hh: y, Hl: P } = this;
1173
- return [t, s, n, o, r, i, c, h, b, d, a, u, p, x, y, P];
1174
- }
1175
- // prettier-ignore
1176
- set(t, s, n, o, r, i, c, h, b, d, a, u, p, x, y, P) {
1177
- this.Ah = t | 0, this.Al = s | 0, this.Bh = n | 0, this.Bl = o | 0, this.Ch = r | 0, this.Cl = i | 0, this.Dh = c | 0, this.Dl = h | 0, this.Eh = b | 0, this.El = d | 0, this.Fh = a | 0, this.Fl = u | 0, this.Gh = p | 0, this.Gl = x | 0, this.Hh = y | 0, this.Hl = P | 0;
1178
- }
1179
- process(t, s) {
1180
- for (let l = 0; l < 16; l++, s += 4)
1181
- R[l] = t.getUint32(s), W[l] = t.getUint32(s += 4);
1182
- for (let l = 16; l < 80; l++) {
1183
- const w = R[l - 15] | 0, k = W[l - 15] | 0, H = N(w, k, 1) ^ N(w, k, 8) ^ At(w, k, 7), I = M(w, k, 1) ^ M(w, k, 8) ^ Bt(w, k, 7), E = R[l - 2] | 0, v = W[l - 2] | 0, U = N(E, v, 19) ^ Y(E, v, 61) ^ At(E, v, 6), K = M(E, v, 19) ^ tt(E, v, 61) ^ Bt(E, v, 6), _ = Ne(I, K, W[l - 7], W[l - 16]), it = Me(_, H, U, R[l - 7], R[l - 16]);
1184
- R[l] = it | 0, W[l] = _ | 0;
1185
- }
1186
- let { Ah: n, Al: o, Bh: r, Bl: i, Ch: c, Cl: h, Dh: b, Dl: d, Eh: a, El: u, Fh: p, Fl: x, Gh: y, Gl: P, Hh: m, Hl: g } = this;
1187
- for (let l = 0; l < 80; l++) {
1188
- const w = N(a, u, 14) ^ N(a, u, 18) ^ Y(a, u, 41), k = M(a, u, 14) ^ M(a, u, 18) ^ tt(a, u, 41), H = a & p ^ ~a & y, I = u & x ^ ~u & P, E = Ge(g, k, I, Je[l], W[l]), v = Xe(E, m, w, H, Ze[l], R[l]), U = E | 0, K = N(n, o, 28) ^ Y(n, o, 34) ^ Y(n, o, 39), _ = M(n, o, 28) ^ tt(n, o, 34) ^ tt(n, o, 39), it = n & r ^ n & c ^ r & c, Qt = o & i ^ o & h ^ i & h;
1189
- m = y | 0, g = P | 0, y = p | 0, P = x | 0, p = a | 0, x = u | 0, { h: a, l: u } = L(b | 0, d | 0, v | 0, U | 0), b = c | 0, d = h | 0, c = r | 0, h = i | 0, r = n | 0, i = o | 0;
1190
- const yt = Ke(U, _, Qt);
1191
- n = $e(yt, v, K, it), o = yt | 0;
1192
- }
1193
- ({ h: n, l: o } = L(this.Ah | 0, this.Al | 0, n | 0, o | 0)), { h: r, l: i } = L(this.Bh | 0, this.Bl | 0, r | 0, i | 0), { h: c, l: h } = L(this.Ch | 0, this.Cl | 0, c | 0, h | 0), { h: b, l: d } = L(this.Dh | 0, this.Dl | 0, b | 0, d | 0), { h: a, l: u } = L(this.Eh | 0, this.El | 0, a | 0, u | 0), { h: p, l: x } = L(this.Fh | 0, this.Fl | 0, p | 0, x | 0), { h: y, l: P } = L(this.Gh | 0, this.Gl | 0, y | 0, P | 0), { h: m, l: g } = L(this.Hh | 0, this.Hl | 0, m | 0, g | 0), this.set(n, o, r, i, c, h, b, d, a, u, p, x, y, P, m, g);
1194
- }
1195
- roundClean() {
1196
- A(R, W);
1197
- }
1198
- destroy() {
1199
- A(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1200
- }
1201
- }
1202
- class Ye extends Qe {
1203
- constructor() {
1204
- super(64);
1205
- f(this, "Ah", T[0] | 0);
1206
- f(this, "Al", T[1] | 0);
1207
- f(this, "Bh", T[2] | 0);
1208
- f(this, "Bl", T[3] | 0);
1209
- f(this, "Ch", T[4] | 0);
1210
- f(this, "Cl", T[5] | 0);
1211
- f(this, "Dh", T[6] | 0);
1212
- f(this, "Dl", T[7] | 0);
1213
- f(this, "Eh", T[8] | 0);
1214
- f(this, "El", T[9] | 0);
1215
- f(this, "Fh", T[10] | 0);
1216
- f(this, "Fl", T[11] | 0);
1217
- f(this, "Gh", T[12] | 0);
1218
- f(this, "Gl", T[13] | 0);
1219
- f(this, "Hh", T[14] | 0);
1220
- f(this, "Hl", T[15] | 0);
1221
- }
1222
- }
1223
- const ts = /* @__PURE__ */ ot(
1224
- () => new ze(),
1225
- /* @__PURE__ */ Rt(1)
1226
- ), Xt = /* @__PURE__ */ ot(
1227
- () => new Ye(),
1228
- /* @__PURE__ */ Rt(3)
1229
- ), es = BigInt(0), q = BigInt(1), ss = BigInt(2), ns = BigInt(7), os = BigInt(256), is = BigInt(113), jt = [], qt = [], zt = [];
1230
- for (let e = 0, t = q, s = 1, n = 0; e < 24; e++) {
1231
- [s, n] = [n, (2 * s + 3 * n) % 5], jt.push(2 * (5 * n + s)), qt.push((e + 1) * (e + 2) / 2 % 64);
1232
- let o = es;
1233
- for (let r = 0; r < 7; r++)
1234
- t = (t << q ^ (t >> ns) * is) % os, t & ss && (o ^= q << (q << BigInt(r)) - q);
1235
- zt.push(o);
1236
- }
1237
- const Zt = Mt(zt, !0), rs = Zt[0], cs = Zt[1], St = (e, t, s) => s > 32 ? Ve(e, t, s) : Re(e, t, s), Ct = (e, t, s) => s > 32 ? De(e, t, s) : We(e, t, s);
1238
- function as(e, t = 24) {
1239
- const s = new Uint32Array(10);
1240
- for (let n = 24 - t; n < 24; n++) {
1241
- for (let i = 0; i < 10; i++)
1242
- s[i] = e[i] ^ e[i + 10] ^ e[i + 20] ^ e[i + 30] ^ e[i + 40];
1243
- for (let i = 0; i < 10; i += 2) {
1244
- const c = (i + 8) % 10, h = (i + 2) % 10, b = s[h], d = s[h + 1], a = St(b, d, 1) ^ s[c], u = Ct(b, d, 1) ^ s[c + 1];
1245
- for (let p = 0; p < 50; p += 10)
1246
- e[i + p] ^= a, e[i + p + 1] ^= u;
1247
- }
1248
- let o = e[2], r = e[3];
1249
- for (let i = 0; i < 24; i++) {
1250
- const c = qt[i], h = St(o, r, c), b = Ct(o, r, c), d = jt[i];
1251
- o = e[d], r = e[d + 1], e[d] = h, e[d + 1] = b;
1252
- }
1253
- for (let i = 0; i < 50; i += 10) {
1254
- for (let c = 0; c < 10; c++)
1255
- s[c] = e[i + c];
1256
- for (let c = 0; c < 10; c++)
1257
- e[i + c] ^= ~s[(c + 2) % 10] & s[(c + 4) % 10];
1258
- }
1259
- e[0] ^= rs[n], e[1] ^= cs[n];
1260
- }
1261
- A(s);
1262
- }
1263
- class pt {
1264
- // NOTE: we accept arguments in bytes instead of bits here.
1265
- constructor(t, s, n, o = !1, r = 24) {
1266
- f(this, "state");
1267
- f(this, "pos", 0);
1268
- f(this, "posOut", 0);
1269
- f(this, "finished", !1);
1270
- f(this, "state32");
1271
- f(this, "destroyed", !1);
1272
- f(this, "blockLen");
1273
- f(this, "suffix");
1274
- f(this, "outputLen");
1275
- f(this, "enableXOF", !1);
1276
- f(this, "rounds");
1277
- if (this.blockLen = t, this.suffix = s, this.outputLen = n, this.enableXOF = o, this.rounds = r, V(n, "outputLen"), !(0 < t && t < 200))
1278
- throw new Error("only keccak-f1600 function is supported");
1279
- this.state = new Uint8Array(200), this.state32 = me(this.state);
1280
- }
1281
- clone() {
1282
- return this._cloneInto();
1283
- }
1284
- keccak() {
1285
- Tt(this.state32), as(this.state32, this.rounds), Tt(this.state32), this.posOut = 0, this.pos = 0;
1286
- }
1287
- update(t) {
1288
- X(this), D(t);
1289
- const { blockLen: s, state: n } = this, o = t.length;
1290
- for (let r = 0; r < o; ) {
1291
- const i = Math.min(s - this.pos, o - r);
1292
- for (let c = 0; c < i; c++)
1293
- n[this.pos++] ^= t[r++];
1294
- this.pos === s && this.keccak();
1295
- }
1296
- return this;
1297
- }
1298
- finish() {
1299
- if (this.finished)
1300
- return;
1301
- this.finished = !0;
1302
- const { state: t, suffix: s, pos: n, blockLen: o } = this;
1303
- t[n] ^= s, (s & 128) !== 0 && n === o - 1 && this.keccak(), t[o - 1] ^= 128, this.keccak();
1304
- }
1305
- writeInto(t) {
1306
- X(this, !1), D(t), this.finish();
1307
- const s = this.state, { blockLen: n } = this;
1308
- for (let o = 0, r = t.length; o < r; ) {
1309
- this.posOut >= n && this.keccak();
1310
- const i = Math.min(n - this.posOut, r - o);
1311
- t.set(s.subarray(this.posOut, this.posOut + i), o), this.posOut += i, o += i;
1312
- }
1313
- return t;
1314
- }
1315
- xofInto(t) {
1316
- if (!this.enableXOF)
1317
- throw new Error("XOF is not possible for this instance");
1318
- return this.writeInto(t);
1319
- }
1320
- xof(t) {
1321
- return V(t), this.xofInto(new Uint8Array(t));
1322
- }
1323
- digestInto(t) {
1324
- if (Ft(t, this), this.finished)
1325
- throw new Error("digest() was already called");
1326
- return this.writeInto(t), this.destroy(), t;
1327
- }
1328
- digest() {
1329
- return this.digestInto(new Uint8Array(this.outputLen));
1330
- }
1331
- destroy() {
1332
- this.destroyed = !0, A(this.state);
1333
- }
1334
- _cloneInto(t) {
1335
- const { blockLen: s, suffix: n, outputLen: o, rounds: r, enableXOF: i } = this;
1336
- return t || (t = new pt(s, n, o, i, r)), t.state32.set(this.state32), t.pos = this.pos, t.posOut = this.posOut, t.finished = this.finished, t.rounds = r, t.suffix = n, t.outputLen = o, t.enableXOF = i, t.destroyed = this.destroyed, t;
1337
- }
1338
- }
1339
- const hs = (e, t, s, n = {}) => ot(() => new pt(t, e, s), n), ls = /* @__PURE__ */ hs(1, 136, 32);
1340
- function us(e, t, s, n) {
1341
- Ot(e);
1342
- const o = Ie({ dkLen: 32, asyncTick: 10 }, n), { c: r, dkLen: i, asyncTick: c } = o;
1343
- if (V(r, "c"), V(i, "dkLen"), V(c, "asyncTick"), r < 1)
1344
- throw new Error("iterations (c) must be >= 1");
1345
- const h = It(t, "password"), b = It(s, "salt"), d = new Uint8Array(i), a = gt.create(e, h), u = a._cloneInto().update(b);
1346
- return { c: r, dkLen: i, asyncTick: c, DK: d, PRF: a, PRFSalt: u };
1347
- }
1348
- function fs(e, t, s, n, o) {
1349
- return e.destroy(), t.destroy(), n && n.destroy(), A(o), s;
1350
- }
1351
- function ds(e, t, s, n) {
1352
- const { c: o, dkLen: r, DK: i, PRF: c, PRFSalt: h } = us(e, t, s, n);
1353
- let b;
1354
- const d = new Uint8Array(4), a = nt(d), u = new Uint8Array(c.outputLen);
1355
- for (let p = 1, x = 0; x < r; p++, x += c.outputLen) {
1356
- const y = i.subarray(x, x + c.outputLen);
1357
- a.setInt32(0, p, !1), (b = h._cloneInto(b)).update(d).digestInto(u), y.set(u.subarray(0, y.length));
1358
- for (let P = 1; P < o; P++) {
1359
- c._cloneInto(b).update(u).digestInto(u);
1360
- for (let m = 0; m < y.length; m++)
1361
- y[m] ^= u[m];
1362
- }
1363
- }
1364
- return fs(c, h, i, b, u);
1365
- }
1366
- function Jt(e) {
1367
- if (typeof e != "string")
1368
- throw new TypeError("invalid mnemonic type: " + typeof e);
1369
- return e.normalize("NFKD");
1370
- }
1371
- function bs(e) {
1372
- const t = Jt(e), s = t.split(" ");
1373
- if (![12, 15, 18, 21, 24].includes(s.length))
1374
- throw new Error("Invalid mnemonic");
1375
- return { nfkd: t, words: s };
1376
- }
1377
- const gs = (e) => Jt("mnemonic" + e);
1378
- function xs(e, t = "") {
1379
- return ds(Xt, bs(e).nfkd, gs(t), { c: 2048, dkLen: 64 });
1380
- }
1381
- const ps = 508, Lt = 16, et = 32, st = 64, Ut = 5, ys = 4;
1382
- function z(...e) {
1383
- const t = e.reduce((o, r) => o + r.length, 0), s = new Uint8Array(t);
1384
- let n = 0;
1385
- for (const o of e)
1386
- s.set(o, n), n += o.length;
1387
- return s;
1388
- }
1389
- function lt(e) {
1390
- return new TextEncoder().encode(e);
1391
- }
1392
- function ut(e) {
1393
- const t = new Uint8Array(ys);
1394
- return new DataView(t.buffer).setUint32(0, e.length, !1), z(t, e);
1395
- }
1396
- function ft(e, t) {
1397
- return gt(Xt, e, t);
1398
- }
1399
- function _t(e) {
1400
- return Oe(ts(e));
1401
- }
1402
- const dt = (e) => Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
1403
- function ws(e) {
1404
- const t = xs(e), s = new Uint8Array(t);
1405
- return t.fill(0), s;
1406
- }
1407
- async function ms(e, t, s, n) {
1408
- if (e.length !== st)
1409
- throw new Error(
1410
- `WOTS seed must be ${st} bytes, got ${e.length}`
1411
- );
1412
- t = S(t), s = S(s);
1413
- const o = e.slice(et, st), r = e.slice(0, et), i = [o, r];
1414
- try {
1415
- const c = z(
1416
- ut(lt(t)),
1417
- ut(lt(s)),
1418
- ut(lt(n))
1419
- ), h = z(r, c);
1420
- i.push(h);
1421
- const b = ft(o, h);
1422
- i.push(b);
1423
- const d = b.slice(0, et), a = b.slice(et, st);
1424
- i.push(d, a);
1425
- const u = [], p = [], x = [], y = [];
1426
- let P = !1;
1427
- try {
1428
- for (let m = 0; m < ps; m++) {
1429
- const g = new Uint8Array(Ut);
1430
- g[0] = 0, new DataView(g.buffer).setUint32(1, m, !1);
1431
- const l = new Uint8Array(Ut);
1432
- l[0] = 1, new DataView(l.buffer).setUint32(1, m, !1);
1433
- const w = z(d, g), k = z(d, l), H = ft(a, w), I = ft(a, k);
1434
- try {
1435
- const E = H.slice(0, Lt), v = I.slice(0, Lt);
1436
- u.push(E), p.push(v), x.push(_t(E)), y.push(_t(v));
1437
- } finally {
1438
- w.fill(0), k.fill(0), H.fill(0), I.fill(0);
1439
- }
1440
- }
1441
- return P = !0, { falsePreimages: u, truePreimages: p, falseHashes: x, trueHashes: y };
1442
- } finally {
1443
- if (!P) {
1444
- for (const m of u) m.fill(0);
1445
- for (const m of p) m.fill(0);
1446
- }
1447
- }
1448
- } finally {
1449
- for (const c of i)
1450
- c.fill(0);
1451
- }
1452
- }
1453
- function Fs(e) {
1454
- return {
1455
- false_list: e.falseHashes.map(dt),
1456
- true_list: e.trueHashes.map(dt)
1457
- };
1458
- }
1459
- function Ps(e) {
1460
- if (e.falseHashes.length === 0 || e.trueHashes.length === 0)
1461
- throw new Error(
1462
- "computeWotsPkHash: keypair hash arrays must not be empty"
1463
- );
1464
- const t = e.falseHashes[0].length, s = (e.falseHashes.length + e.trueHashes.length) * t, n = new Uint8Array(s);
1465
- let o = 0;
1466
- for (const i of e.falseHashes)
1467
- n.set(i, o), o += t;
1468
- for (const i of e.trueHashes)
1469
- n.set(i, o), o += t;
1470
- const r = ls(n);
1471
- return `0x${dt(r)}`;
1472
- }
1473
- async function Rs(e, t, s, n) {
1474
- const o = ws(e);
1475
- try {
1476
- const r = await ms(
1477
- o,
1478
- t,
1479
- s,
1480
- n
1481
- );
1482
- try {
1483
- return Ps(r);
1484
- } finally {
1485
- for (const i of r.falsePreimages) i.fill(0);
1486
- for (const i of r.truePreimages) i.fill(0);
1487
- }
1488
- } finally {
1489
- o.fill(0);
1490
- }
1491
- }
1492
- function Ws(e) {
1493
- const t = (e instanceof Error ? e.message : typeof e == "string" ? e : "").toLowerCase();
1494
- return t.includes("wots") && t.includes("hash") && t.includes("does not match");
1495
- }
1496
- export {
1497
- G as C,
1498
- Os as P,
1499
- Rs as a,
1500
- Ws as b,
1501
- Ps as c,
1502
- ms as d,
1503
- bt as e,
1504
- Us as g,
1505
- $ as h,
1506
- _s as i,
1507
- Fs as k,
1508
- ws as m
1509
- };
1510
- //# sourceMappingURL=errors-KY63mgWT.js.map