@babylonlabs-io/ts-sdk 0.9.0 → 0.11.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 (77) hide show
  1. package/dist/challengeAssert-DW0sEUgn.cjs +2 -0
  2. package/dist/challengeAssert-DW0sEUgn.cjs.map +1 -0
  3. package/dist/{challengeAssert-D50t_Qyo.js → challengeAssert-DnnliaRt.js} +66 -60
  4. package/dist/challengeAssert-DnnliaRt.js.map +1 -0
  5. package/dist/{errors-D_DWT0CT.js → errors-DOJdtNTD.js} +465 -391
  6. package/dist/errors-DOJdtNTD.js.map +1 -0
  7. package/dist/errors-DbATYfYA.cjs +2 -0
  8. package/dist/errors-DbATYfYA.cjs.map +1 -0
  9. package/dist/index.cjs +1 -1
  10. package/dist/index.js +71 -72
  11. package/dist/index.js.map +1 -1
  12. package/dist/shared/index.cjs +1 -1
  13. package/dist/shared/index.cjs.map +1 -1
  14. package/dist/shared/index.d.ts +2 -4
  15. package/dist/shared/index.d.ts.map +1 -1
  16. package/dist/shared/index.js +6 -5
  17. package/dist/shared/index.js.map +1 -1
  18. package/dist/shared/wallets/index.d.ts +2 -4
  19. package/dist/shared/wallets/index.d.ts.map +1 -1
  20. package/dist/shared/wallets/interfaces/index.d.ts +1 -1
  21. package/dist/shared/wallets/interfaces/index.d.ts.map +1 -1
  22. package/dist/tbv/core/index.cjs +1 -1
  23. package/dist/tbv/core/index.js +64 -62
  24. package/dist/tbv/core/managers/PeginManager.d.ts +41 -75
  25. package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
  26. package/dist/tbv/core/primitives/index.cjs +1 -1
  27. package/dist/tbv/core/primitives/index.d.ts +1 -1
  28. package/dist/tbv/core/primitives/index.d.ts.map +1 -1
  29. package/dist/tbv/core/primitives/index.js +9 -10
  30. package/dist/tbv/core/primitives/psbt/pegin.d.ts +10 -11
  31. package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
  32. package/dist/tbv/core/utils/__tests__/signing.test.d.ts +2 -0
  33. package/dist/tbv/core/utils/__tests__/signing.test.d.ts.map +1 -0
  34. package/dist/tbv/core/utils/fee/constants.d.ts +16 -0
  35. package/dist/tbv/core/utils/fee/constants.d.ts.map +1 -1
  36. package/dist/tbv/core/utils/index.d.ts +1 -0
  37. package/dist/tbv/core/utils/index.d.ts.map +1 -1
  38. package/dist/{shared/wallets/signOptions.d.ts → tbv/core/utils/signing.d.ts} +2 -2
  39. package/dist/tbv/core/utils/signing.d.ts.map +1 -0
  40. package/dist/tbv/core/utils/utxo/selectUtxos.d.ts +2 -1
  41. package/dist/tbv/core/utils/utxo/selectUtxos.d.ts.map +1 -1
  42. package/dist/tbv/index.cjs +1 -1
  43. package/dist/tbv/index.js +64 -62
  44. package/dist/{shared/wallets/mocks → testing}/MockBitcoinWallet.d.ts +2 -2
  45. package/dist/testing/MockBitcoinWallet.d.ts.map +1 -0
  46. package/dist/testing/MockEthereumWallet.d.ts.map +1 -0
  47. package/dist/testing/__tests__/MockEthereumWallet.test.d.ts +2 -0
  48. package/dist/testing/__tests__/MockEthereumWallet.test.d.ts.map +1 -0
  49. package/dist/testing/index.cjs +2 -0
  50. package/dist/testing/index.cjs.map +1 -0
  51. package/dist/testing/index.d.ts.map +1 -0
  52. package/dist/{MockEthereumWallet-ibdry7pZ.js → testing/index.js} +6 -8
  53. package/dist/testing/index.js.map +1 -0
  54. package/package.json +8 -3
  55. package/dist/MockEthereumWallet-CKQlH2AM.cjs +0 -2
  56. package/dist/MockEthereumWallet-CKQlH2AM.cjs.map +0 -1
  57. package/dist/MockEthereumWallet-ibdry7pZ.js.map +0 -1
  58. package/dist/challengeAssert-D50t_Qyo.js.map +0 -1
  59. package/dist/challengeAssert-DDceAi0r.cjs +0 -2
  60. package/dist/challengeAssert-DDceAi0r.cjs.map +0 -1
  61. package/dist/errors-D_DWT0CT.js.map +0 -1
  62. package/dist/errors-tDgLyp-N.cjs +0 -2
  63. package/dist/errors-tDgLyp-N.cjs.map +0 -1
  64. package/dist/shared/wallets/__tests__/EthereumWallet.test.d.ts +0 -2
  65. package/dist/shared/wallets/__tests__/EthereumWallet.test.d.ts.map +0 -1
  66. package/dist/shared/wallets/__tests__/signOptions.test.d.ts +0 -2
  67. package/dist/shared/wallets/__tests__/signOptions.test.d.ts.map +0 -1
  68. package/dist/shared/wallets/mocks/MockBitcoinWallet.d.ts.map +0 -1
  69. package/dist/shared/wallets/mocks/MockEthereumWallet.d.ts.map +0 -1
  70. package/dist/shared/wallets/mocks/index.d.ts.map +0 -1
  71. package/dist/shared/wallets/signOptions.d.ts.map +0 -1
  72. package/dist/signOptions-Deg5lCoC.cjs +0 -2
  73. package/dist/signOptions-Deg5lCoC.cjs.map +0 -1
  74. package/dist/signOptions-Drwr3bXB.js +0 -16
  75. package/dist/signOptions-Drwr3bXB.js.map +0 -1
  76. /package/dist/{shared/wallets/mocks → testing}/MockEthereumWallet.d.ts +0 -0
  77. /package/dist/{shared/wallets/mocks → testing}/index.d.ts +0 -0
@@ -1,54 +1,57 @@
1
- var ue = Object.defineProperty;
2
- var le = (e, t, n) => t in e ? ue(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var f = (e, t, n) => le(e, typeof t != "symbol" ? t + "" : t, n);
4
- import * as he from "bitcoinjs-lib";
5
- import { script as fe, Transaction as st, address as de, Psbt as ft } from "bitcoinjs-lib";
1
+ var ce = Object.defineProperty;
2
+ var ue = (e, t, n) => t in e ? ce(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var f = (e, t, n) => ue(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import * as le from "bitcoinjs-lib";
5
+ import { script as he, Transaction as st, address as fe, Psbt as dt } from "bitcoinjs-lib";
6
6
  import { Buffer as S } from "buffer";
7
- import { P as pe, x as be, D as Dt, M as Pt, B as xe, T as ye, A as dt, t as W, b as ge, z as me, a as we, d as Pe, e as Te, f as ve, r as at, p as He, w as Tt, g as vt, h as Ht } from "./challengeAssert-D50t_Qyo.js";
8
- import { createPublicClient as kt, http as It, encodeFunctionData as ke, zeroAddress as Ie } from "viem";
9
- import { c as pt } from "./signOptions-Drwr3bXB.js";
10
- import { SINGLE_DEPOSIT_HTLC_VOUT as Et } from "@babylonlabs-io/babylon-tbv-rust-wasm";
11
- function Ee(e, t, n) {
7
+ import { P as de, x as pe, D as Wt, M as Tt, B as be, T as ge, E as pt, t as D, b as xe, z as ye, C as me, a as we, d as Pe, e as Te, f as ve, r as at, p as ke, w as vt, g as kt, h as Ht } from "./challengeAssert-DnnliaRt.js";
8
+ import { createPublicClient as It, http as Et, encodeFunctionData as He, zeroAddress as Ie } from "viem";
9
+ import "@babylonlabs-io/babylon-tbv-rust-wasm";
10
+ function Ee(e, t, n, s) {
11
+ if (!Number.isInteger(s) || s < 1)
12
+ throw new Error(
13
+ `Invalid numOutputs: expected a positive integer, got ${s}`
14
+ );
12
15
  if (e.length === 0)
13
16
  throw new Error("Insufficient funds: no UTXOs available");
14
- const s = e.filter((c) => {
15
- const l = S.from(c.scriptPubKey, "hex");
16
- return !!fe.decompile(l);
17
+ const r = e.filter((u) => {
18
+ const h = S.from(u.scriptPubKey, "hex");
19
+ return !!he.decompile(h);
17
20
  });
18
- if (s.length === 0)
21
+ if (r.length === 0)
19
22
  throw new Error(
20
23
  "Insufficient funds: no valid UTXOs available (all have invalid scripts)"
21
24
  );
22
- const r = [...s].sort((c, l) => l.value - c.value), o = [];
23
- let i = 0n, a = 0n;
24
- for (const c of r) {
25
- o.push(c), i += BigInt(c.value);
26
- const l = o.length * pe, h = 2 * Pt, u = l + h + ye;
27
- if (a = BigInt(Math.ceil(u * n)) + BigInt(be(n)), i - t - a > Dt) {
25
+ const o = [...r].sort((u, h) => h.value - u.value), i = [];
26
+ let a = 0n, c = 0n;
27
+ for (const u of o) {
28
+ i.push(u), a += BigInt(u.value);
29
+ const h = i.length * de, l = s * Tt, d = h + l + ge;
30
+ if (c = BigInt(Math.ceil(d * n)) + BigInt(pe(n)), a - t - c > Wt) {
28
31
  const p = BigInt(
29
- Math.ceil(Pt * n)
32
+ Math.ceil(Tt * n)
30
33
  );
31
- a += p;
34
+ c += p;
32
35
  }
33
- if (i >= t + a) {
34
- const p = i - t - a;
36
+ if (a >= t + c) {
37
+ const p = a - t - c;
35
38
  return {
36
- selectedUTXOs: o,
37
- totalValue: i,
38
- fee: a,
39
+ selectedUTXOs: i,
40
+ totalValue: a,
41
+ fee: c,
39
42
  changeAmount: p
40
43
  };
41
44
  }
42
45
  }
43
46
  throw new Error(
44
- `Insufficient funds: need ${t + a} sats (${t} pegin + ${a} fee), have ${i} sats`
47
+ `Insufficient funds: need ${t + c} sats (${t} pegin + ${c} fee), have ${a} sats`
45
48
  );
46
49
  }
47
50
  function zn(e) {
48
- return e > Dt;
51
+ return e > Wt;
49
52
  }
50
53
  function qn() {
51
- return xe;
54
+ return be;
52
55
  }
53
56
  function St(e) {
54
57
  const t = e.startsWith("0x") ? e.slice(2) : e;
@@ -64,28 +67,28 @@ function Zn(e, t, n) {
64
67
  throw new Error(
65
68
  `Invalid output amount for ${c.address}: ${c.amount} satoshis. Amount must be greater than zero.`
66
69
  );
67
- const s = dt(n), r = new st();
70
+ const s = pt(n), r = new st();
68
71
  r.version = 2;
69
72
  for (const c of e) {
70
- const l = S.from(c.txid, "hex").reverse();
71
- r.addInput(l, c.vout);
73
+ const u = S.from(c.txid, "hex").reverse();
74
+ r.addInput(u, c.vout);
72
75
  }
73
76
  const o = [];
74
77
  for (let c = 0; c < t.length; c++) {
75
- const l = t[c];
78
+ const u = t[c];
76
79
  let h;
77
80
  try {
78
- h = de.toOutputScript(l.address, s);
79
- } catch (u) {
81
+ h = fe.toOutputScript(u.address, s);
82
+ } catch (l) {
80
83
  throw new Error(
81
- `Failed to decode address "${l.address}": ${u instanceof Error ? u.message : String(u)}`
84
+ `Failed to decode address "${u.address}": ${l instanceof Error ? l.message : String(l)}`
82
85
  );
83
86
  }
84
- r.addOutput(h, Number(l.amount)), o.push({
87
+ r.addOutput(h, Number(u.amount)), o.push({
85
88
  txid: "",
86
89
  // Will be set after txid calculation
87
90
  vout: c,
88
- value: Number(l.amount),
91
+ value: Number(u.amount),
89
92
  scriptPubKey: h.toString("hex")
90
93
  });
91
94
  }
@@ -99,7 +102,7 @@ function Zn(e, t, n) {
99
102
  };
100
103
  }
101
104
  function Jn(e, t, n) {
102
- const s = st.fromHex(e), r = new ft();
105
+ const s = st.fromHex(e), r = new dt();
103
106
  if (r.setVersion(s.version), r.setLocktime(s.locktime), !S.isBuffer(n) || n.length !== 32)
104
107
  throw new Error(
105
108
  `Invalid publicKeyNoCoord: expected 32-byte Buffer (x-only pubkey), got ${S.isBuffer(n) ? `${n.length}-byte Buffer` : typeof n}`
@@ -112,10 +115,10 @@ function Jn(e, t, n) {
112
115
  const i = s.ins[o], a = t[o];
113
116
  if (!a)
114
117
  throw new Error(`Missing UTXO data for input ${o}`);
115
- const c = S.from(i.hash).reverse().toString("hex"), l = i.index;
116
- if (a.txid !== c || a.vout !== l)
118
+ const c = S.from(i.hash).reverse().toString("hex"), u = i.index;
119
+ if (a.txid !== c || a.vout !== u)
117
120
  throw new Error(
118
- `Input ${o} outpoint mismatch: transaction expects ${c}:${l}, but UTXO ${a.txid}:${a.vout} was provided. Ensure inputs array matches the order used in createSplitTransaction().`
121
+ `Input ${o} outpoint mismatch: transaction expects ${c}:${u}, but UTXO ${a.txid}:${a.vout} was provided. Ensure inputs array matches the order used in createSplitTransaction().`
119
122
  );
120
123
  const h = S.from(a.scriptPubKey, "hex");
121
124
  if (!(h.length === 34 && h[0] === 81 && // OP_1 (witness version 1)
@@ -195,17 +198,29 @@ function Ae(e, t) {
195
198
  throw new Error(`Unsupported script type: ${s}`);
196
199
  }
197
200
  }
198
- const Be = 21e6 * 1e8, Kt = 1e4;
199
- function Mt(e) {
201
+ function bt(e, t) {
202
+ if (!Number.isInteger(t) || t < 1)
203
+ throw new Error(`inputCount must be a positive integer, got ${t}`);
204
+ return {
205
+ autoFinalized: !1,
206
+ signInputs: Array.from({ length: t }, (n, s) => ({
207
+ index: s,
208
+ publicKey: e,
209
+ disableTweakSigner: !0
210
+ }))
211
+ };
212
+ }
213
+ const Be = 21e6 * 1e8, Dt = 1e4;
214
+ function Kt(e) {
200
215
  return Number.isInteger(e) && e > 0 && e <= Be;
201
216
  }
202
- function Ue(e) {
203
- return Number.isInteger(e) && e > 0 && e <= Kt;
217
+ function $e(e) {
218
+ return Number.isInteger(e) && e > 0 && e <= Dt;
204
219
  }
205
- function Nt(e, t) {
220
+ function Mt(e, t) {
206
221
  return !Number.isInteger(e) || e < 0 ? !1 : t === void 0 || e < t;
207
222
  }
208
- const Le = {
223
+ const Ue = {
209
224
  mainnet: "https://mempool.space/api",
210
225
  testnet: "https://mempool.space/testnet/api",
211
226
  signet: "https://mempool.space/signet/api"
@@ -225,7 +240,7 @@ async function nt(e, t) {
225
240
  throw n instanceof Error ? new Error(`Failed to fetch from mempool API: ${n.message}`) : new Error("Failed to fetch from mempool API: Unknown error");
226
241
  }
227
242
  }
228
- async function $e(e, t) {
243
+ async function Le(e, t) {
229
244
  try {
230
245
  const n = await fetch(`${t}/tx`, {
231
246
  method: "POST",
@@ -268,14 +283,14 @@ async function Yn(e, t) {
268
283
  throw n instanceof Error ? new Error(`Failed to get transaction hex for ${e}: ${n.message}`) : new Error(`Failed to get transaction hex for ${e}: Unknown error`);
269
284
  }
270
285
  }
271
- async function Oe(e, t, n) {
286
+ async function Ce(e, t, n) {
272
287
  const s = await Fe(e, n);
273
- if (!Nt(t, s.vout.length))
288
+ if (!Mt(t, s.vout.length))
274
289
  throw new Error(
275
290
  `Invalid vout ${t} for transaction ${e} (has ${s.vout.length} outputs)`
276
291
  );
277
292
  const r = s.vout[t];
278
- if (!Mt(r.value))
293
+ if (!Kt(r.value))
279
294
  throw new Error(`Invalid UTXO value ${r.value} for ${e}:${t}`);
280
295
  return {
281
296
  txid: e,
@@ -292,9 +307,9 @@ async function Qn(e, t) {
292
307
  `Invalid Bitcoin address: ${e}. Mempool API validation failed.`
293
308
  );
294
309
  for (const o of n) {
295
- if (!Nt(o.vout))
310
+ if (!Mt(o.vout))
296
311
  throw new Error(`Invalid vout ${o.vout} for ${o.txid}`);
297
- if (!Mt(o.value))
312
+ if (!Kt(o.value))
298
313
  throw new Error(
299
314
  `Invalid UTXO value ${o.value} for ${o.txid}:${o.vout}`
300
315
  );
@@ -315,7 +330,7 @@ async function Qn(e, t) {
315
330
  }
316
331
  }
317
332
  function ts(e) {
318
- return Le[e];
333
+ return Ue[e];
319
334
  }
320
335
  async function es(e, t) {
321
336
  return nt(`${t}/address/${e}/txs`);
@@ -334,9 +349,9 @@ async function ns(e) {
334
349
  "minimumFee"
335
350
  ];
336
351
  for (const r of s)
337
- if (!Ue(n[r]))
352
+ if (!$e(n[r]))
338
353
  throw new Error(
339
- `Invalid fee rate ${r}=${n[r]} from mempool API: expected a positive number ≤ ${Kt}`
354
+ `Invalid fee rate ${r}=${n[r]} from mempool API: expected a positive number ≤ ${Dt}`
340
355
  );
341
356
  if (n.minimumFee > n.economyFee || n.economyFee > n.hourFee || n.hourFee > n.halfHourFee || n.halfHourFee > n.fastestFee)
342
357
  throw new Error(
@@ -603,7 +618,7 @@ const ct = [
603
618
  name: "PeginSignaturesIncomplete",
604
619
  inputs: []
605
620
  }
606
- ], D = {
621
+ ], K = {
607
622
  // VaultAlreadyExists()
608
623
  "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.",
609
624
  // ScriptPubKeyMismatch() - taproot output doesn't match expected script
@@ -656,20 +671,20 @@ function ss(e) {
656
671
  const t = xt(e);
657
672
  if (t) {
658
673
  const n = t.substring(0, 10);
659
- return D[t] ?? D[n];
674
+ return K[t] ?? K[n];
660
675
  }
661
676
  }
662
677
  function rs(e) {
663
678
  const t = xt(e);
664
679
  if (t === void 0) return !1;
665
680
  const n = t.substring(0, 10);
666
- return t in D || n in D;
681
+ return t in K || n in K;
667
682
  }
668
- function At(e) {
683
+ function ut(e) {
669
684
  console.error("[Contract Error] Raw error:", e);
670
685
  const t = xt(e);
671
686
  if (console.error("[Contract Error] Extracted error data:", t), t) {
672
- const s = t.substring(0, 10), r = D[t] ?? D[s];
687
+ const s = t.substring(0, 10), r = K[t] ?? K[s];
673
688
  if (r)
674
689
  throw console.error("[Contract Error] Known error:", r), new Error(r);
675
690
  }
@@ -687,15 +702,16 @@ function At(e) {
687
702
  }
688
703
  throw e instanceof Error ? (console.error("[Contract Error] Unhandled error:", e.message), e) : new Error(`Contract call failed: ${String(e)}`);
689
704
  }
690
- function Ce(e, t, n, s) {
705
+ function Oe(e, t, n, s) {
691
706
  const r = n == null ? void 0 : n[`${e}:${t}`];
692
707
  return r ? Promise.resolve({
693
708
  txid: e,
694
709
  vout: t,
695
710
  value: r.value,
696
711
  scriptPubKey: r.scriptPubKey
697
- }) : Oe(e, t, s);
712
+ }) : Ce(e, t, s);
698
713
  }
714
+ const _e = 12e4;
699
715
  class os {
700
716
  /**
701
717
  * Creates a new PeginManager instance.
@@ -727,11 +743,13 @@ class os {
727
743
  * @throws Error if wallet operations fail or insufficient funds
728
744
  */
729
745
  async preparePegin(t) {
730
- const n = await this.config.btcWallet.getPublicKeyHex(), s = n.length === 66 ? n.slice(2) : n, r = W(t.vaultProviderBtcPubkey), o = t.vaultKeeperBtcPubkeys.map(W), i = t.universalChallengerBtcPubkeys.map(W);
731
- if (t.hashlocks.length !== 1)
746
+ const n = await this.config.btcWallet.getPublicKeyHex(), s = n.length === 66 ? n.slice(2) : n, r = D(t.vaultProviderBtcPubkey), o = t.vaultKeeperBtcPubkeys.map(D), i = t.universalChallengerBtcPubkeys.map(D);
747
+ if (t.hashlocks.length !== t.amounts.length)
732
748
  throw new Error(
733
- "hashlocks must contain exactly one entry (batched deposits not yet supported)"
749
+ `hashlocks.length (${t.hashlocks.length}) must equal amounts.length (${t.amounts.length})`
734
750
  );
751
+ if (t.hashlocks.length === 0)
752
+ throw new Error("hashlocks must contain at least one entry");
735
753
  const a = o.length, c = {
736
754
  depositorPubkey: s,
737
755
  vaultProviderPubkey: r,
@@ -739,58 +757,102 @@ class os {
739
757
  universalChallengerPubkeys: i,
740
758
  hashlocks: t.hashlocks,
741
759
  timelockRefund: t.timelockRefund,
742
- pegInAmount: t.amount,
760
+ pegInAmounts: t.amounts,
743
761
  feeRate: t.protocolFeeRate,
744
762
  numLocalChallengers: a,
745
763
  councilQuorum: t.councilQuorum,
746
764
  councilSize: t.councilSize,
747
765
  network: this.config.btcNetwork
748
- }, l = await ge(c), h = Ee(
766
+ }, u = await xe(c), h = Ee(
749
767
  [...t.availableUTXOs],
750
- l.totalOutputValue,
751
- t.mempoolFeeRate
752
- ), u = dt(this.config.btcNetwork), d = me({
753
- unfundedTxHex: l.psbtHex,
768
+ u.totalOutputValue,
769
+ t.mempoolFeeRate,
770
+ ye(u.htlcValues.length)
771
+ ), l = pt(this.config.btcNetwork), d = me({
772
+ unfundedTxHex: u.psbtHex,
754
773
  selectedUTXOs: h.selectedUTXOs,
755
774
  changeAddress: t.changeAddress,
756
775
  changeAmount: h.changeAmount,
757
- network: u
758
- }), p = W(St(d)), b = await we({
759
- prePeginParams: c,
760
- timelockPegin: t.timelockPegin,
761
- fundedPrePeginTxHex: d,
762
- htlcVout: Et
763
- }), m = await Pe({
764
- peginTxHex: b.txHex,
765
- fundedPrePeginTxHex: d,
766
- depositorPubkey: s,
767
- vaultProviderPubkey: r,
768
- vaultKeeperPubkeys: o,
769
- universalChallengerPubkeys: i,
770
- hashlock: t.hashlocks[0],
771
- timelockRefund: t.timelockRefund,
772
- network: this.config.btcNetwork
773
- }), x = await this.config.btcWallet.signPsbt(
774
- m.psbtHex,
775
- pt(n, 1)
776
- ), g = Te(
777
- x,
778
- s
779
- ), w = ve(x);
776
+ network: l
777
+ }), g = D(St(d)), p = [], m = [], x = [];
778
+ for (let b = 0; b < t.hashlocks.length; b++) {
779
+ const P = await we({
780
+ prePeginParams: c,
781
+ timelockPegin: t.timelockPegin,
782
+ fundedPrePeginTxHex: d,
783
+ htlcVout: b
784
+ }), T = await Pe({
785
+ peginTxHex: P.txHex,
786
+ fundedPrePeginTxHex: d,
787
+ depositorPubkey: s,
788
+ vaultProviderPubkey: r,
789
+ vaultKeeperPubkeys: o,
790
+ universalChallengerPubkeys: i,
791
+ hashlock: t.hashlocks[b],
792
+ timelockRefund: t.timelockRefund,
793
+ network: this.config.btcNetwork
794
+ });
795
+ p.push(P), m.push(T.psbtHex), x.push(
796
+ bt(n, 1)
797
+ );
798
+ }
799
+ const y = await this.signPsbtsWithFallback(
800
+ m,
801
+ x
802
+ ), w = [];
803
+ for (let b = 0; b < y.length; b++) {
804
+ const P = Te(
805
+ y[b],
806
+ s
807
+ ), T = ve(y[b]);
808
+ w.push({
809
+ htlcVout: b,
810
+ htlcValue: u.htlcValues[b],
811
+ peginTxHex: T,
812
+ peginTxid: p[b].txid,
813
+ peginInputSignature: P,
814
+ vaultScriptPubKey: p[b].vaultScriptPubKey
815
+ });
816
+ }
780
817
  return {
781
818
  fundedPrePeginTxHex: d,
782
- htlcValue: l.htlcValue,
783
- signedPeginInputPsbtHex: x,
784
- peginInputSignature: g,
785
- vaultScriptPubKey: b.vaultScriptPubKey,
786
- peginTxHex: w,
787
- prePeginTxid: p,
788
- peginTxid: b.txid,
819
+ prePeginTxid: g,
820
+ unsignedPrePeginTxHex: u.psbtHex,
821
+ perVault: w,
789
822
  selectedUTXOs: h.selectedUTXOs,
790
823
  fee: h.fee,
791
824
  changeAmount: h.changeAmount
792
825
  };
793
826
  }
827
+ /**
828
+ * Signs multiple PSBTs using batch signing if available, falling back to sequential signing.
829
+ *
830
+ * Wallets that support native batch signing (e.g. UniSat) will sign all PSBTs
831
+ * in a single interaction. Others (e.g. Ledger, AppKit) implement signPsbts
832
+ * by looping signPsbt internally, so the UX depends on the wallet adapter.
833
+ */
834
+ async signPsbtsWithFallback(t, n) {
835
+ if (typeof this.config.btcWallet.signPsbts == "function") {
836
+ const r = await this.config.btcWallet.signPsbts(
837
+ t,
838
+ n
839
+ );
840
+ if (r.length !== t.length)
841
+ throw new Error(
842
+ `Expected ${t.length} signed PSBTs but received ${r.length}`
843
+ );
844
+ return r;
845
+ }
846
+ const s = [];
847
+ for (let r = 0; r < t.length; r++) {
848
+ const o = await this.config.btcWallet.signPsbt(
849
+ t[r],
850
+ n[r]
851
+ );
852
+ s.push(o);
853
+ }
854
+ return s;
855
+ }
794
856
  /**
795
857
  * Signs and broadcasts a funded peg-in transaction to the Bitcoin network.
796
858
  *
@@ -810,7 +872,7 @@ class os {
810
872
  const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, r = n.startsWith("0x") ? n.slice(2) : n, o = st.fromHex(r);
811
873
  if (o.ins.length === 0)
812
874
  throw new Error("Transaction has no inputs");
813
- const i = new ft();
875
+ const i = new dt();
814
876
  i.setVersion(o.version), i.setLocktime(o.locktime);
815
877
  const a = s.startsWith("0x") ? s.slice(2) : s;
816
878
  if (a.length !== 64 || !/^[0-9a-fA-F]+$/.test(a))
@@ -822,17 +884,17 @@ class os {
822
884
  throw new Error(
823
885
  `Invalid depositorBtcPubkey length: expected 32 bytes, got ${c.length}`
824
886
  );
825
- const l = this.config.mempoolApiUrl, h = o.ins.map((x) => {
826
- const g = S.from(x.hash).reverse().toString("hex"), w = x.index;
827
- return Ce(g, w, t.localPrevouts, l).then(
828
- (y) => ({ input: x, utxoData: y, txid: g, vout: w })
887
+ const u = this.config.mempoolApiUrl, h = o.ins.map((x) => {
888
+ const y = S.from(x.hash).reverse().toString("hex"), w = x.index;
889
+ return Oe(y, w, t.localPrevouts, u).then(
890
+ (b) => ({ input: x, utxoData: b, txid: y, vout: w })
829
891
  );
830
- }), u = await Promise.all(h);
831
- for (const { input: x, utxoData: g, txid: w, vout: y } of u) {
892
+ }), l = await Promise.all(h);
893
+ for (const { input: x, utxoData: y, txid: w, vout: b } of l) {
832
894
  const P = Ae(
833
895
  {
834
- value: g.value,
835
- scriptPubKey: g.scriptPubKey
896
+ value: y.value,
897
+ scriptPubKey: y.scriptPubKey
836
898
  },
837
899
  c
838
900
  );
@@ -848,19 +910,19 @@ class os {
848
910
  script: x.script,
849
911
  value: x.value
850
912
  });
851
- const d = await this.config.btcWallet.signPsbt(i.toHex()), p = ft.fromHex(d);
913
+ const d = await this.config.btcWallet.signPsbt(i.toHex()), g = dt.fromHex(d);
852
914
  try {
853
- p.finalizeAllInputs();
915
+ g.finalizeAllInputs();
854
916
  } catch (x) {
855
- if (!p.data.inputs.every(
917
+ if (!g.data.inputs.every(
856
918
  (w) => w.finalScriptWitness || w.finalScriptSig
857
919
  ))
858
920
  throw new Error(
859
921
  `PSBT finalization failed and wallet did not auto-finalize: ${x}`
860
922
  );
861
923
  }
862
- const b = p.extractTransaction().toHex();
863
- return await $e(b, l);
924
+ const p = g.extractTransaction().toHex();
925
+ return await Le(p, u);
864
926
  }
865
927
  /**
866
928
  * Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
@@ -886,32 +948,33 @@ class os {
886
948
  depositorSignedPeginTx: r,
887
949
  vaultProvider: o,
888
950
  hashlock: i,
889
- onPopSigned: a,
890
- depositorPayoutBtcAddress: c,
891
- depositorLamportPkHash: l,
892
- preSignedBtcPopSignature: h
951
+ htlcVout: a,
952
+ onPopSigned: c,
953
+ depositorPayoutBtcAddress: u,
954
+ depositorLamportPkHash: h,
955
+ preSignedBtcPopSignature: l
893
956
  } = t;
894
957
  if (!this.config.ethWallet.account)
895
958
  throw new Error("Ethereum wallet account not found");
896
- const u = this.config.ethWallet.account.address, d = await this.resolvePopSignature(
897
- u,
898
- h
959
+ const d = this.config.ethWallet.account.address, g = await this.resolvePopSignature(
960
+ d,
961
+ l
899
962
  );
900
- a && await a();
901
- const p = at(n), b = at(s), m = at(r), x = await this.resolvePayoutScriptPubKey(
902
- c
903
- ), g = St(m);
904
- if (await this.checkVaultExists(g))
963
+ c && await c();
964
+ const p = at(n), m = at(s), x = at(r), y = await this.resolvePayoutScriptPubKey(
965
+ u
966
+ ), w = St(x);
967
+ if (await this.checkVaultExists(w))
905
968
  throw new Error(
906
- `Vault already exists for this transaction (ID: ${g}). Vault IDs are deterministically derived from the unsigned Bitcoin transaction, so using the same UTXOs and amount will always produce the same vault. To create a new vault, please use different UTXOs or a different amount to generate a unique transaction.`
969
+ `Vault already exists for this transaction (ID: ${w}). Vault IDs are deterministically derived from the unsigned Bitcoin transaction, so using the same UTXOs and amount will always produce the same vault. To create a new vault, please use different UTXOs or a different amount to generate a unique transaction.`
907
970
  );
908
- const y = kt({
971
+ const P = It({
909
972
  chain: this.config.ethChain,
910
- transport: It()
973
+ transport: Et()
911
974
  });
912
- let P;
975
+ let T;
913
976
  try {
914
- P = await y.readContract({
977
+ T = await P.readContract({
915
978
  address: this.config.vaultContracts.btcVaultRegistry,
916
979
  abi: ct,
917
980
  functionName: "getPegInFee",
@@ -922,49 +985,59 @@ class os {
922
985
  "Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
923
986
  );
924
987
  }
925
- const v = ke({
988
+ const v = He({
926
989
  abi: ct,
927
990
  functionName: "submitPeginRequest",
928
991
  args: [
929
- u,
930
- p,
931
992
  d,
932
- b,
993
+ p,
994
+ g,
933
995
  m,
996
+ x,
934
997
  o,
935
998
  i,
936
- Et,
937
- x,
938
- l
999
+ a,
1000
+ y,
1001
+ h
939
1002
  ]
940
1003
  });
941
- let T;
1004
+ let E;
942
1005
  try {
943
- T = await y.estimateGas({
1006
+ E = await P.estimateGas({
944
1007
  to: this.config.vaultContracts.btcVaultRegistry,
945
1008
  data: v,
946
- value: P,
1009
+ value: T,
947
1010
  account: this.config.ethWallet.account.address
948
1011
  });
949
- } catch (k) {
950
- At(k);
1012
+ } catch (U) {
1013
+ ut(U);
951
1014
  }
1015
+ let k;
952
1016
  try {
953
- return {
954
- ethTxHash: await this.config.ethWallet.sendTransaction({
955
- to: this.config.vaultContracts.btcVaultRegistry,
956
- data: v,
957
- value: P,
958
- account: this.config.ethWallet.account,
959
- chain: this.config.ethChain,
960
- gas: T
961
- }),
962
- vaultId: g,
963
- btcPopSignature: d
964
- };
965
- } catch (k) {
966
- At(k);
1017
+ k = await this.config.ethWallet.sendTransaction({
1018
+ to: this.config.vaultContracts.btcVaultRegistry,
1019
+ data: v,
1020
+ value: T,
1021
+ account: this.config.ethWallet.account,
1022
+ chain: this.config.ethChain,
1023
+ gas: E
1024
+ });
1025
+ } catch (U) {
1026
+ ut(U);
967
1027
  }
1028
+ const I = await P.waitForTransactionReceipt({
1029
+ hash: k,
1030
+ timeout: _e
1031
+ });
1032
+ return I.status === "reverted" && ut(
1033
+ new Error(
1034
+ `Transaction reverted. Hash: ${k}. Check the transaction on block explorer for details.`
1035
+ )
1036
+ ), {
1037
+ ethTxHash: I.transactionHash,
1038
+ vaultId: w,
1039
+ btcPopSignature: g
1040
+ };
968
1041
  }
969
1042
  /**
970
1043
  * Check if a vault already exists for a given vault ID.
@@ -974,9 +1047,9 @@ class os {
974
1047
  */
975
1048
  async checkVaultExists(t) {
976
1049
  try {
977
- return (await kt({
1050
+ return (await It({
978
1051
  chain: this.config.ethChain,
979
- transport: It()
1052
+ transport: Et()
980
1053
  }).readContract({
981
1054
  address: this.config.vaultContracts.btcVaultRegistry,
982
1055
  abi: ct,
@@ -1001,7 +1074,7 @@ class os {
1001
1074
  else {
1002
1075
  n = await this.config.btcWallet.getAddress();
1003
1076
  const r = await this.config.btcWallet.getPublicKeyHex();
1004
- if (!He(
1077
+ if (!ke(
1005
1078
  n,
1006
1079
  r,
1007
1080
  this.config.btcNetwork
@@ -1010,9 +1083,9 @@ class os {
1010
1083
  "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)."
1011
1084
  );
1012
1085
  }
1013
- const s = dt(this.config.btcNetwork);
1086
+ const s = pt(this.config.btcNetwork);
1014
1087
  try {
1015
- return `0x${he.address.toOutputScript(n, s).toString("hex")}`;
1088
+ return `0x${le.address.toOutputScript(n, s).toString("hex")}`;
1016
1089
  } catch {
1017
1090
  throw new Error(
1018
1091
  `Invalid BTC payout address: "${n}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`
@@ -1084,10 +1157,10 @@ class is {
1084
1157
  * @throws Error if wallet operations fail or signature extraction fails
1085
1158
  */
1086
1159
  async signPayoutTransaction(t) {
1087
- const n = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: s } = Tt(
1160
+ const n = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: s } = vt(
1088
1161
  n,
1089
1162
  t.depositorBtcPubkey
1090
- ), r = await vt({
1163
+ ), r = await kt({
1091
1164
  payoutTxHex: t.payoutTxHex,
1092
1165
  peginTxHex: t.peginTxHex,
1093
1166
  assertTxHex: t.assertTxHex,
@@ -1099,7 +1172,7 @@ class is {
1099
1172
  network: this.config.network
1100
1173
  }), o = await this.config.btcWallet.signPsbt(
1101
1174
  r.psbtHex,
1102
- pt(n, 1)
1175
+ bt(n, 1)
1103
1176
  );
1104
1177
  return {
1105
1178
  signature: Ht(o, s),
@@ -1138,23 +1211,23 @@ class is {
1138
1211
  );
1139
1212
  const n = await this.config.btcWallet.getPublicKeyHex(), s = [], r = [], o = [];
1140
1213
  for (const c of t) {
1141
- const { depositorPubkey: l } = Tt(
1214
+ const { depositorPubkey: u } = vt(
1142
1215
  n,
1143
1216
  c.depositorBtcPubkey
1144
1217
  );
1145
- o.push(l);
1146
- const h = await vt({
1218
+ o.push(u);
1219
+ const h = await kt({
1147
1220
  payoutTxHex: c.payoutTxHex,
1148
1221
  peginTxHex: c.peginTxHex,
1149
1222
  assertTxHex: c.assertTxHex,
1150
- depositorBtcPubkey: l,
1223
+ depositorBtcPubkey: u,
1151
1224
  vaultProviderBtcPubkey: c.vaultProviderBtcPubkey,
1152
1225
  vaultKeeperBtcPubkeys: c.vaultKeeperBtcPubkeys,
1153
1226
  universalChallengerBtcPubkeys: c.universalChallengerBtcPubkeys,
1154
1227
  timelockPegin: c.timelockPegin,
1155
1228
  network: this.config.network
1156
1229
  });
1157
- s.push(h.psbtHex), r.push(pt(n, 1));
1230
+ s.push(h.psbtHex), r.push(bt(n, 1));
1158
1231
  }
1159
1232
  const i = await this.config.btcWallet.signPsbts(
1160
1233
  s,
@@ -1166,53 +1239,53 @@ class is {
1166
1239
  );
1167
1240
  const a = [];
1168
1241
  for (let c = 0; c < t.length; c++) {
1169
- const l = o[c], h = Ht(
1242
+ const u = o[c], h = Ht(
1170
1243
  i[c],
1171
- l
1244
+ u
1172
1245
  );
1173
1246
  a.push({
1174
1247
  payoutSignature: h,
1175
- depositorBtcPubkey: l
1248
+ depositorBtcPubkey: u
1176
1249
  });
1177
1250
  }
1178
1251
  return a;
1179
1252
  }
1180
1253
  }
1181
- function _e(e) {
1254
+ function Re(e) {
1182
1255
  return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
1183
1256
  }
1184
- function C(e, t = "") {
1257
+ function _(e, t = "") {
1185
1258
  if (!Number.isSafeInteger(e) || e < 0) {
1186
1259
  const n = t && `"${t}" `;
1187
1260
  throw new Error(`${n}expected integer >= 0, got ${e}`);
1188
1261
  }
1189
1262
  }
1190
- function _(e, t, n = "") {
1191
- const s = _e(e), r = e == null ? void 0 : e.length, o = t !== void 0;
1263
+ function R(e, t, n = "") {
1264
+ const s = Re(e), r = e == null ? void 0 : e.length, o = t !== void 0;
1192
1265
  if (!s || o && r !== t) {
1193
1266
  const i = n && `"${n}" `, a = o ? ` of length ${t}` : "", c = s ? `length=${r}` : `type=${typeof e}`;
1194
1267
  throw new Error(i + "expected Uint8Array" + a + ", got " + c);
1195
1268
  }
1196
1269
  return e;
1197
1270
  }
1198
- function Xt(e) {
1271
+ function Nt(e) {
1199
1272
  if (typeof e != "function" || typeof e.create != "function")
1200
1273
  throw new Error("Hash must wrapped by utils.createHasher");
1201
- C(e.outputLen), C(e.blockLen);
1274
+ _(e.outputLen), _(e.blockLen);
1202
1275
  }
1203
- function K(e, t = !0) {
1276
+ function M(e, t = !0) {
1204
1277
  if (e.destroyed)
1205
1278
  throw new Error("Hash instance has been destroyed");
1206
1279
  if (t && e.finished)
1207
1280
  throw new Error("Hash#digest() has already been called");
1208
1281
  }
1209
- function Gt(e, t) {
1210
- _(e, void 0, "digestInto() output");
1282
+ function Xt(e, t) {
1283
+ R(e, void 0, "digestInto() output");
1211
1284
  const n = t.outputLen;
1212
1285
  if (e.length < n)
1213
1286
  throw new Error('"digestInto() output" expected to be of length >=' + n);
1214
1287
  }
1215
- function Re(e) {
1288
+ function Ve(e) {
1216
1289
  return new Uint32Array(e.buffer, e.byteOffset, Math.floor(e.byteLength / 4));
1217
1290
  }
1218
1291
  function A(...e) {
@@ -1225,28 +1298,28 @@ function et(e) {
1225
1298
  function B(e, t) {
1226
1299
  return e << 32 - t | e >>> t;
1227
1300
  }
1228
- function j(e, t) {
1301
+ function G(e, t) {
1229
1302
  return e << t | e >>> 32 - t >>> 0;
1230
1303
  }
1231
- const Ve = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
1232
- function We(e) {
1304
+ const We = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
1305
+ function De(e) {
1233
1306
  return e << 24 & 4278190080 | e << 8 & 16711680 | e >>> 8 & 65280 | e >>> 24 & 255;
1234
1307
  }
1235
- function De(e) {
1308
+ function Ke(e) {
1236
1309
  for (let t = 0; t < e.length; t++)
1237
- e[t] = We(e[t]);
1310
+ e[t] = De(e[t]);
1238
1311
  return e;
1239
1312
  }
1240
- const Bt = Ve ? (e) => e : De;
1241
- function Ke(e) {
1313
+ const At = We ? (e) => e : Ke;
1314
+ function Me(e) {
1242
1315
  if (typeof e != "string")
1243
1316
  throw new Error("string expected");
1244
1317
  return new Uint8Array(new TextEncoder().encode(e));
1245
1318
  }
1246
- function Ut(e, t = "") {
1247
- return typeof e == "string" ? Ke(e) : _(e, void 0, t);
1319
+ function Bt(e, t = "") {
1320
+ return typeof e == "string" ? Me(e) : R(e, void 0, t);
1248
1321
  }
1249
- function Me(e, t) {
1322
+ function Ne(e, t) {
1250
1323
  if (t !== void 0 && {}.toString.call(t) !== "[object Object]")
1251
1324
  throw new Error("options must be object or undefined");
1252
1325
  return Object.assign(e, t);
@@ -1258,7 +1331,7 @@ function rt(e, t = {}) {
1258
1331
  const jt = (e) => ({
1259
1332
  oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, e])
1260
1333
  });
1261
- class zt {
1334
+ class Gt {
1262
1335
  constructor(t, n) {
1263
1336
  f(this, "oHash");
1264
1337
  f(this, "iHash");
@@ -1266,7 +1339,7 @@ class zt {
1266
1339
  f(this, "outputLen");
1267
1340
  f(this, "finished", !1);
1268
1341
  f(this, "destroyed", !1);
1269
- if (Xt(t), _(n, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function")
1342
+ if (Nt(t), R(n, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function")
1270
1343
  throw new Error("Expected instance of class which extends utils.Hash");
1271
1344
  this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
1272
1345
  const s = this.blockLen, r = new Uint8Array(s);
@@ -1279,10 +1352,10 @@ class zt {
1279
1352
  this.oHash.update(r), A(r);
1280
1353
  }
1281
1354
  update(t) {
1282
- return K(this), this.iHash.update(t), this;
1355
+ return M(this), this.iHash.update(t), this;
1283
1356
  }
1284
1357
  digestInto(t) {
1285
- K(this), _(t, this.outputLen, "output"), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
1358
+ M(this), R(t, this.outputLen, "output"), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
1286
1359
  }
1287
1360
  digest() {
1288
1361
  const t = new Uint8Array(this.oHash.outputLen);
@@ -1300,15 +1373,15 @@ class zt {
1300
1373
  this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
1301
1374
  }
1302
1375
  }
1303
- const yt = (e, t, n) => new zt(e, t).update(n).digest();
1304
- yt.create = (e, t) => new zt(e, t);
1305
- function Ne(e, t, n) {
1376
+ const yt = (e, t, n) => new Gt(e, t).update(n).digest();
1377
+ yt.create = (e, t) => new Gt(e, t);
1378
+ function Xe(e, t, n) {
1306
1379
  return e & t ^ ~e & n;
1307
1380
  }
1308
- function Xe(e, t, n) {
1381
+ function je(e, t, n) {
1309
1382
  return e & t ^ e & n ^ t & n;
1310
1383
  }
1311
- class gt {
1384
+ class mt {
1312
1385
  constructor(t, n, s, r) {
1313
1386
  f(this, "blockLen");
1314
1387
  f(this, "outputLen");
@@ -1324,7 +1397,7 @@ class gt {
1324
1397
  this.blockLen = t, this.outputLen = n, this.padOffset = s, this.isLE = r, this.buffer = new Uint8Array(t), this.view = et(this.buffer);
1325
1398
  }
1326
1399
  update(t) {
1327
- K(this), _(t);
1400
+ M(this), R(t);
1328
1401
  const { view: n, buffer: s, blockLen: r } = this, o = t.length;
1329
1402
  for (let i = 0; i < o; ) {
1330
1403
  const a = Math.min(r - this.pos, o - i);
@@ -1339,21 +1412,21 @@ class gt {
1339
1412
  return this.length += t.length, this.roundClean(), this;
1340
1413
  }
1341
1414
  digestInto(t) {
1342
- K(this), Gt(t, this), this.finished = !0;
1415
+ M(this), Xt(t, this), this.finished = !0;
1343
1416
  const { buffer: n, view: s, blockLen: r, isLE: o } = this;
1344
1417
  let { pos: i } = this;
1345
1418
  n[i++] = 128, A(this.buffer.subarray(i)), this.padOffset > r - i && (this.process(s, 0), i = 0);
1346
- for (let u = i; u < r; u++)
1347
- n[u] = 0;
1419
+ for (let l = i; l < r; l++)
1420
+ n[l] = 0;
1348
1421
  s.setBigUint64(r - 8, BigInt(this.length * 8), o), this.process(s, 0);
1349
1422
  const a = et(t), c = this.outputLen;
1350
1423
  if (c % 4)
1351
1424
  throw new Error("_sha2: outputLen must be aligned to 32bit");
1352
- const l = c / 4, h = this.get();
1353
- if (l > h.length)
1425
+ const u = c / 4, h = this.get();
1426
+ if (u > h.length)
1354
1427
  throw new Error("_sha2: outputLen bigger than state");
1355
- for (let u = 0; u < l; u++)
1356
- a.setUint32(4 * u, h[u], o);
1428
+ for (let l = 0; l < u; l++)
1429
+ a.setUint32(4 * l, h[l], o);
1357
1430
  }
1358
1431
  digest() {
1359
1432
  const { buffer: t, outputLen: n } = this;
@@ -1413,36 +1486,36 @@ const L = /* @__PURE__ */ Uint32Array.from([
1413
1486
  14,
1414
1487
  11,
1415
1488
  8
1416
- ]), qt = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)), je = qt.map((e) => (9 * e + 5) % 16), Zt = /* @__PURE__ */ (() => {
1417
- const n = [[qt], [je]];
1489
+ ]), zt = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)), ze = zt.map((e) => (9 * e + 5) % 16), qt = /* @__PURE__ */ (() => {
1490
+ const n = [[zt], [ze]];
1418
1491
  for (let s = 0; s < 4; s++)
1419
1492
  for (let r of n)
1420
1493
  r.push(r[s].map((o) => Ge[o]));
1421
1494
  return n;
1422
- })(), Jt = Zt[0], Yt = Zt[1], Qt = /* @__PURE__ */ [
1495
+ })(), Zt = qt[0], Jt = qt[1], Yt = /* @__PURE__ */ [
1423
1496
  [11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
1424
1497
  [12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
1425
1498
  [13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
1426
1499
  [14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
1427
1500
  [15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
1428
- ].map((e) => Uint8Array.from(e)), ze = /* @__PURE__ */ Jt.map((e, t) => e.map((n) => Qt[t][n])), qe = /* @__PURE__ */ Yt.map((e, t) => e.map((n) => Qt[t][n])), Ze = /* @__PURE__ */ Uint32Array.from([
1501
+ ].map((e) => Uint8Array.from(e)), qe = /* @__PURE__ */ Zt.map((e, t) => e.map((n) => Yt[t][n])), Ze = /* @__PURE__ */ Jt.map((e, t) => e.map((n) => Yt[t][n])), Je = /* @__PURE__ */ Uint32Array.from([
1429
1502
  0,
1430
1503
  1518500249,
1431
1504
  1859775393,
1432
1505
  2400959708,
1433
1506
  2840853838
1434
- ]), Je = /* @__PURE__ */ Uint32Array.from([
1507
+ ]), Ye = /* @__PURE__ */ Uint32Array.from([
1435
1508
  1352829926,
1436
1509
  1548603684,
1437
1510
  1836072691,
1438
1511
  2053994217,
1439
1512
  0
1440
1513
  ]);
1441
- function Lt(e, t, n, s) {
1514
+ function $t(e, t, n, s) {
1442
1515
  return e === 0 ? t ^ n ^ s : e === 1 ? t & n | ~t & s : e === 2 ? (t | ~n) ^ s : e === 3 ? t & s | n & ~s : t ^ (n | ~s);
1443
1516
  }
1444
1517
  const z = /* @__PURE__ */ new Uint32Array(16);
1445
- class Ye extends gt {
1518
+ class Qe extends mt {
1446
1519
  constructor() {
1447
1520
  super(64, 20, 8, !0);
1448
1521
  f(this, "h0", 1732584193);
@@ -1459,21 +1532,21 @@ class Ye extends gt {
1459
1532
  this.h0 = n | 0, this.h1 = s | 0, this.h2 = r | 0, this.h3 = o | 0, this.h4 = i | 0;
1460
1533
  }
1461
1534
  process(n, s) {
1462
- for (let b = 0; b < 16; b++, s += 4)
1463
- z[b] = n.getUint32(s, !0);
1464
- let r = this.h0 | 0, o = r, i = this.h1 | 0, a = i, c = this.h2 | 0, l = c, h = this.h3 | 0, u = h, d = this.h4 | 0, p = d;
1465
- for (let b = 0; b < 5; b++) {
1466
- const m = 4 - b, x = Ze[b], g = Je[b], w = Jt[b], y = Yt[b], P = ze[b], v = qe[b];
1467
- for (let T = 0; T < 16; T++) {
1468
- const k = j(r + Lt(b, i, c, h) + z[w[T]] + x, P[T]) + d | 0;
1469
- r = d, d = h, h = j(c, 10) | 0, c = i, i = k;
1535
+ for (let p = 0; p < 16; p++, s += 4)
1536
+ z[p] = n.getUint32(s, !0);
1537
+ let r = this.h0 | 0, o = r, i = this.h1 | 0, a = i, c = this.h2 | 0, u = c, h = this.h3 | 0, l = h, d = this.h4 | 0, g = d;
1538
+ for (let p = 0; p < 5; p++) {
1539
+ const m = 4 - p, x = Je[p], y = Ye[p], w = Zt[p], b = Jt[p], P = qe[p], T = Ze[p];
1540
+ for (let v = 0; v < 16; v++) {
1541
+ const E = G(r + $t(p, i, c, h) + z[w[v]] + x, P[v]) + d | 0;
1542
+ r = d, d = h, h = G(c, 10) | 0, c = i, i = E;
1470
1543
  }
1471
- for (let T = 0; T < 16; T++) {
1472
- const k = j(o + Lt(m, a, l, u) + z[y[T]] + g, v[T]) + p | 0;
1473
- o = p, p = u, u = j(l, 10) | 0, l = a, a = k;
1544
+ for (let v = 0; v < 16; v++) {
1545
+ const E = G(o + $t(m, a, u, l) + z[b[v]] + y, T[v]) + g | 0;
1546
+ o = g, g = l, l = G(u, 10) | 0, u = a, a = E;
1474
1547
  }
1475
1548
  }
1476
- this.set(this.h1 + c + u | 0, this.h2 + h + p | 0, this.h3 + d + o | 0, this.h4 + r + a | 0, this.h0 + i + l | 0);
1549
+ this.set(this.h1 + c + l | 0, this.h2 + h + g | 0, this.h3 + d + o | 0, this.h4 + r + a | 0, this.h0 + i + u | 0);
1477
1550
  }
1478
1551
  roundClean() {
1479
1552
  A(z);
@@ -1482,25 +1555,25 @@ class Ye extends gt {
1482
1555
  this.destroyed = !0, A(this.buffer), this.set(0, 0, 0, 0, 0);
1483
1556
  }
1484
1557
  }
1485
- const Qe = /* @__PURE__ */ rt(() => new Ye()), q = /* @__PURE__ */ BigInt(2 ** 32 - 1), $t = /* @__PURE__ */ BigInt(32);
1486
- function tn(e, t = !1) {
1487
- return t ? { h: Number(e & q), l: Number(e >> $t & q) } : { h: Number(e >> $t & q) | 0, l: Number(e & q) | 0 };
1558
+ const tn = /* @__PURE__ */ rt(() => new Qe()), q = /* @__PURE__ */ BigInt(2 ** 32 - 1), Ut = /* @__PURE__ */ BigInt(32);
1559
+ function en(e, t = !1) {
1560
+ return t ? { h: Number(e & q), l: Number(e >> Ut & q) } : { h: Number(e >> Ut & q) | 0, l: Number(e & q) | 0 };
1488
1561
  }
1489
- function te(e, t = !1) {
1562
+ function Qt(e, t = !1) {
1490
1563
  const n = e.length;
1491
1564
  let s = new Uint32Array(n), r = new Uint32Array(n);
1492
1565
  for (let o = 0; o < n; o++) {
1493
- const { h: i, l: a } = tn(e[o], t);
1566
+ const { h: i, l: a } = en(e[o], t);
1494
1567
  [s[o], r[o]] = [i, a];
1495
1568
  }
1496
1569
  return [s, r];
1497
1570
  }
1498
- const Ft = (e, t, n) => e >>> n, Ot = (e, t, n) => e << 32 - n | t >>> n, R = (e, t, n) => e >>> n | t << 32 - n, V = (e, t, n) => e << 32 - n | t >>> n, Z = (e, t, n) => e << 64 - n | t >>> n - 32, J = (e, t, n) => e >>> n - 32 | t << 64 - n, en = (e, t, n) => e << n | t >>> 32 - n, nn = (e, t, n) => t << n | e >>> 32 - n, sn = (e, t, n) => t << n - 32 | e >>> 64 - n, rn = (e, t, n) => e << n - 32 | t >>> 64 - n;
1499
- function U(e, t, n, s) {
1571
+ const Lt = (e, t, n) => e >>> n, Ft = (e, t, n) => e << 32 - n | t >>> n, V = (e, t, n) => e >>> n | t << 32 - n, W = (e, t, n) => e << 32 - n | t >>> n, Z = (e, t, n) => e << 64 - n | t >>> n - 32, J = (e, t, n) => e >>> n - 32 | t << 64 - n, nn = (e, t, n) => e << n | t >>> 32 - n, sn = (e, t, n) => t << n | e >>> 32 - n, rn = (e, t, n) => t << n - 32 | e >>> 64 - n, on = (e, t, n) => e << n - 32 | t >>> 64 - n;
1572
+ function $(e, t, n, s) {
1500
1573
  const r = (t >>> 0) + (s >>> 0);
1501
1574
  return { h: e + n + (r / 2 ** 32 | 0) | 0, l: r | 0 };
1502
1575
  }
1503
- const on = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), an = (e, t, n, s) => t + n + s + (e / 2 ** 32 | 0) | 0, cn = (e, t, n, s) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0), un = (e, t, n, s, r) => t + n + s + r + (e / 2 ** 32 | 0) | 0, ln = (e, t, n, s, r) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0) + (r >>> 0), hn = (e, t, n, s, r, o) => t + n + s + r + o + (e / 2 ** 32 | 0) | 0, fn = /* @__PURE__ */ Uint32Array.from([
1576
+ const an = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), cn = (e, t, n, s) => t + n + s + (e / 2 ** 32 | 0) | 0, un = (e, t, n, s) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0), ln = (e, t, n, s, r) => t + n + s + r + (e / 2 ** 32 | 0) | 0, hn = (e, t, n, s, r) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0) + (r >>> 0), fn = (e, t, n, s, r, o) => t + n + s + r + o + (e / 2 ** 32 | 0) | 0, dn = /* @__PURE__ */ Uint32Array.from([
1504
1577
  1116352408,
1505
1578
  1899447441,
1506
1579
  3049323471,
@@ -1565,8 +1638,8 @@ const on = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), an = (e, t, n, s) =>
1565
1638
  2756734187,
1566
1639
  3204031479,
1567
1640
  3329325298
1568
- ]), $ = /* @__PURE__ */ new Uint32Array(64);
1569
- class dn extends gt {
1641
+ ]), F = /* @__PURE__ */ new Uint32Array(64);
1642
+ class pn extends mt {
1570
1643
  constructor(t) {
1571
1644
  super(64, t, 8, !1);
1572
1645
  }
@@ -1579,27 +1652,27 @@ class dn extends gt {
1579
1652
  this.A = t | 0, this.B = n | 0, this.C = s | 0, this.D = r | 0, this.E = o | 0, this.F = i | 0, this.G = a | 0, this.H = c | 0;
1580
1653
  }
1581
1654
  process(t, n) {
1582
- for (let u = 0; u < 16; u++, n += 4)
1583
- $[u] = t.getUint32(n, !1);
1584
- for (let u = 16; u < 64; u++) {
1585
- const d = $[u - 15], p = $[u - 2], b = B(d, 7) ^ B(d, 18) ^ d >>> 3, m = B(p, 17) ^ B(p, 19) ^ p >>> 10;
1586
- $[u] = m + $[u - 7] + b + $[u - 16] | 0;
1655
+ for (let l = 0; l < 16; l++, n += 4)
1656
+ F[l] = t.getUint32(n, !1);
1657
+ for (let l = 16; l < 64; l++) {
1658
+ const d = F[l - 15], g = F[l - 2], p = B(d, 7) ^ B(d, 18) ^ d >>> 3, m = B(g, 17) ^ B(g, 19) ^ g >>> 10;
1659
+ F[l] = m + F[l - 7] + p + F[l - 16] | 0;
1587
1660
  }
1588
- let { A: s, B: r, C: o, D: i, E: a, F: c, G: l, H: h } = this;
1589
- for (let u = 0; u < 64; u++) {
1590
- const d = B(a, 6) ^ B(a, 11) ^ B(a, 25), p = h + d + Ne(a, c, l) + fn[u] + $[u] | 0, m = (B(s, 2) ^ B(s, 13) ^ B(s, 22)) + Xe(s, r, o) | 0;
1591
- h = l, l = c, c = a, a = i + p | 0, i = o, o = r, r = s, s = p + m | 0;
1661
+ let { A: s, B: r, C: o, D: i, E: a, F: c, G: u, H: h } = this;
1662
+ for (let l = 0; l < 64; l++) {
1663
+ const d = B(a, 6) ^ B(a, 11) ^ B(a, 25), g = h + d + Xe(a, c, u) + dn[l] + F[l] | 0, m = (B(s, 2) ^ B(s, 13) ^ B(s, 22)) + je(s, r, o) | 0;
1664
+ h = u, u = c, c = a, a = i + g | 0, i = o, o = r, r = s, s = g + m | 0;
1592
1665
  }
1593
- s = s + this.A | 0, r = r + this.B | 0, o = o + this.C | 0, i = i + this.D | 0, a = a + this.E | 0, c = c + this.F | 0, l = l + this.G | 0, h = h + this.H | 0, this.set(s, r, o, i, a, c, l, h);
1666
+ s = s + this.A | 0, r = r + this.B | 0, o = o + this.C | 0, i = i + this.D | 0, a = a + this.E | 0, c = c + this.F | 0, u = u + this.G | 0, h = h + this.H | 0, this.set(s, r, o, i, a, c, u, h);
1594
1667
  }
1595
1668
  roundClean() {
1596
- A($);
1669
+ A(F);
1597
1670
  }
1598
1671
  destroy() {
1599
1672
  this.set(0, 0, 0, 0, 0, 0, 0, 0), A(this.buffer);
1600
1673
  }
1601
1674
  }
1602
- class pn extends dn {
1675
+ class bn extends pn {
1603
1676
  constructor() {
1604
1677
  super(32);
1605
1678
  // We cannot use array here since array allows indexing by variable
@@ -1614,7 +1687,7 @@ class pn extends dn {
1614
1687
  f(this, "H", L[7] | 0);
1615
1688
  }
1616
1689
  }
1617
- const ee = te([
1690
+ const te = Qt([
1618
1691
  "0x428a2f98d728ae22",
1619
1692
  "0x7137449123ef65cd",
1620
1693
  "0xb5c0fbcfec4d3b2f",
@@ -1695,44 +1768,44 @@ const ee = te([
1695
1768
  "0x597f299cfc657e2a",
1696
1769
  "0x5fcb6fab3ad6faec",
1697
1770
  "0x6c44198c4a475817"
1698
- ].map((e) => BigInt(e))), bn = ee[0], xn = ee[1], F = /* @__PURE__ */ new Uint32Array(80), O = /* @__PURE__ */ new Uint32Array(80);
1699
- class yn extends gt {
1771
+ ].map((e) => BigInt(e))), gn = te[0], xn = te[1], C = /* @__PURE__ */ new Uint32Array(80), O = /* @__PURE__ */ new Uint32Array(80);
1772
+ class yn extends mt {
1700
1773
  constructor(t) {
1701
1774
  super(128, t, 16, !1);
1702
1775
  }
1703
1776
  // prettier-ignore
1704
1777
  get() {
1705
- const { Ah: t, Al: n, Bh: s, Bl: r, Ch: o, Cl: i, Dh: a, Dl: c, Eh: l, El: h, Fh: u, Fl: d, Gh: p, Gl: b, Hh: m, Hl: x } = this;
1706
- return [t, n, s, r, o, i, a, c, l, h, u, d, p, b, m, x];
1778
+ const { Ah: t, Al: n, Bh: s, Bl: r, Ch: o, Cl: i, Dh: a, Dl: c, Eh: u, El: h, Fh: l, Fl: d, Gh: g, Gl: p, Hh: m, Hl: x } = this;
1779
+ return [t, n, s, r, o, i, a, c, u, h, l, d, g, p, m, x];
1707
1780
  }
1708
1781
  // prettier-ignore
1709
- set(t, n, s, r, o, i, a, c, l, h, u, d, p, b, m, x) {
1710
- this.Ah = t | 0, this.Al = n | 0, this.Bh = s | 0, this.Bl = r | 0, this.Ch = o | 0, this.Cl = i | 0, this.Dh = a | 0, this.Dl = c | 0, this.Eh = l | 0, this.El = h | 0, this.Fh = u | 0, this.Fl = d | 0, this.Gh = p | 0, this.Gl = b | 0, this.Hh = m | 0, this.Hl = x | 0;
1782
+ set(t, n, s, r, o, i, a, c, u, h, l, d, g, p, m, x) {
1783
+ this.Ah = t | 0, this.Al = n | 0, this.Bh = s | 0, this.Bl = r | 0, this.Ch = o | 0, this.Cl = i | 0, this.Dh = a | 0, this.Dl = c | 0, this.Eh = u | 0, this.El = h | 0, this.Fh = l | 0, this.Fl = d | 0, this.Gh = g | 0, this.Gl = p | 0, this.Hh = m | 0, this.Hl = x | 0;
1711
1784
  }
1712
1785
  process(t, n) {
1713
- for (let y = 0; y < 16; y++, n += 4)
1714
- F[y] = t.getUint32(n), O[y] = t.getUint32(n += 4);
1715
- for (let y = 16; y < 80; y++) {
1716
- const P = F[y - 15] | 0, v = O[y - 15] | 0, T = R(P, v, 1) ^ R(P, v, 8) ^ Ft(P, v, 7), k = V(P, v, 1) ^ V(P, v, 8) ^ Ot(P, v, 7), I = F[y - 2] | 0, E = O[y - 2] | 0, X = R(I, E, 19) ^ Z(I, E, 61) ^ Ft(I, E, 6), ot = V(I, E, 19) ^ J(I, E, 61) ^ Ot(I, E, 6), G = cn(k, ot, O[y - 7], O[y - 16]), it = un(G, T, X, F[y - 7], F[y - 16]);
1717
- F[y] = it | 0, O[y] = G | 0;
1786
+ for (let b = 0; b < 16; b++, n += 4)
1787
+ C[b] = t.getUint32(n), O[b] = t.getUint32(n += 4);
1788
+ for (let b = 16; b < 80; b++) {
1789
+ const P = C[b - 15] | 0, T = O[b - 15] | 0, v = V(P, T, 1) ^ V(P, T, 8) ^ Lt(P, T, 7), E = W(P, T, 1) ^ W(P, T, 8) ^ Ft(P, T, 7), k = C[b - 2] | 0, I = O[b - 2] | 0, U = V(k, I, 19) ^ Z(k, I, 61) ^ Lt(k, I, 6), ot = W(k, I, 19) ^ J(k, I, 61) ^ Ft(k, I, 6), j = un(E, ot, O[b - 7], O[b - 16]), it = ln(j, v, U, C[b - 7], C[b - 16]);
1790
+ C[b] = it | 0, O[b] = j | 0;
1718
1791
  }
1719
- let { Ah: s, Al: r, Bh: o, Bl: i, Ch: a, Cl: c, Dh: l, Dl: h, Eh: u, El: d, Fh: p, Fl: b, Gh: m, Gl: x, Hh: g, Hl: w } = this;
1720
- for (let y = 0; y < 80; y++) {
1721
- const P = R(u, d, 14) ^ R(u, d, 18) ^ Z(u, d, 41), v = V(u, d, 14) ^ V(u, d, 18) ^ J(u, d, 41), T = u & p ^ ~u & m, k = d & b ^ ~d & x, I = ln(w, v, k, xn[y], O[y]), E = hn(I, g, P, T, bn[y], F[y]), X = I | 0, ot = R(s, r, 28) ^ Z(s, r, 34) ^ Z(s, r, 39), G = V(s, r, 28) ^ J(s, r, 34) ^ J(s, r, 39), it = s & o ^ s & a ^ o & a, ce = r & i ^ r & c ^ i & c;
1722
- g = m | 0, w = x | 0, m = p | 0, x = b | 0, p = u | 0, b = d | 0, { h: u, l: d } = U(l | 0, h | 0, E | 0, X | 0), l = a | 0, h = c | 0, a = o | 0, c = i | 0, o = s | 0, i = r | 0;
1723
- const wt = on(X, G, ce);
1724
- s = an(wt, E, ot, it), r = wt | 0;
1792
+ let { Ah: s, Al: r, Bh: o, Bl: i, Ch: a, Cl: c, Dh: u, Dl: h, Eh: l, El: d, Fh: g, Fl: p, Gh: m, Gl: x, Hh: y, Hl: w } = this;
1793
+ for (let b = 0; b < 80; b++) {
1794
+ const P = V(l, d, 14) ^ V(l, d, 18) ^ Z(l, d, 41), T = W(l, d, 14) ^ W(l, d, 18) ^ J(l, d, 41), v = l & g ^ ~l & m, E = d & p ^ ~d & x, k = hn(w, T, E, xn[b], O[b]), I = fn(k, y, P, v, gn[b], C[b]), U = k | 0, ot = V(s, r, 28) ^ Z(s, r, 34) ^ Z(s, r, 39), j = W(s, r, 28) ^ J(s, r, 34) ^ J(s, r, 39), it = s & o ^ s & a ^ o & a, ae = r & i ^ r & c ^ i & c;
1795
+ y = m | 0, w = x | 0, m = g | 0, x = p | 0, g = l | 0, p = d | 0, { h: l, l: d } = $(u | 0, h | 0, I | 0, U | 0), u = a | 0, h = c | 0, a = o | 0, c = i | 0, o = s | 0, i = r | 0;
1796
+ const Pt = an(U, j, ae);
1797
+ s = cn(Pt, I, ot, it), r = Pt | 0;
1725
1798
  }
1726
- ({ h: s, l: r } = U(this.Ah | 0, this.Al | 0, s | 0, r | 0)), { h: o, l: i } = U(this.Bh | 0, this.Bl | 0, o | 0, i | 0), { h: a, l: c } = U(this.Ch | 0, this.Cl | 0, a | 0, c | 0), { h: l, l: h } = U(this.Dh | 0, this.Dl | 0, l | 0, h | 0), { h: u, l: d } = U(this.Eh | 0, this.El | 0, u | 0, d | 0), { h: p, l: b } = U(this.Fh | 0, this.Fl | 0, p | 0, b | 0), { h: m, l: x } = U(this.Gh | 0, this.Gl | 0, m | 0, x | 0), { h: g, l: w } = U(this.Hh | 0, this.Hl | 0, g | 0, w | 0), this.set(s, r, o, i, a, c, l, h, u, d, p, b, m, x, g, w);
1799
+ ({ h: s, l: r } = $(this.Ah | 0, this.Al | 0, s | 0, r | 0)), { h: o, l: i } = $(this.Bh | 0, this.Bl | 0, o | 0, i | 0), { h: a, l: c } = $(this.Ch | 0, this.Cl | 0, a | 0, c | 0), { h: u, l: h } = $(this.Dh | 0, this.Dl | 0, u | 0, h | 0), { h: l, l: d } = $(this.Eh | 0, this.El | 0, l | 0, d | 0), { h: g, l: p } = $(this.Fh | 0, this.Fl | 0, g | 0, p | 0), { h: m, l: x } = $(this.Gh | 0, this.Gl | 0, m | 0, x | 0), { h: y, l: w } = $(this.Hh | 0, this.Hl | 0, y | 0, w | 0), this.set(s, r, o, i, a, c, u, h, l, d, g, p, m, x, y, w);
1727
1800
  }
1728
1801
  roundClean() {
1729
- A(F, O);
1802
+ A(C, O);
1730
1803
  }
1731
1804
  destroy() {
1732
1805
  A(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1733
1806
  }
1734
1807
  }
1735
- class gn extends yn {
1808
+ class mn extends yn {
1736
1809
  constructor() {
1737
1810
  super(64);
1738
1811
  f(this, "Ah", H[0] | 0);
@@ -1753,35 +1826,35 @@ class gn extends yn {
1753
1826
  f(this, "Hl", H[15] | 0);
1754
1827
  }
1755
1828
  }
1756
- const mn = /* @__PURE__ */ rt(
1757
- () => new pn(),
1829
+ const wn = /* @__PURE__ */ rt(
1830
+ () => new bn(),
1758
1831
  /* @__PURE__ */ jt(1)
1759
- ), ne = /* @__PURE__ */ rt(
1760
- () => new gn(),
1832
+ ), ee = /* @__PURE__ */ rt(
1833
+ () => new mn(),
1761
1834
  /* @__PURE__ */ jt(3)
1762
- ), wn = BigInt(0), M = BigInt(1), Pn = BigInt(2), Tn = BigInt(7), vn = BigInt(256), Hn = BigInt(113), se = [], re = [], oe = [];
1763
- for (let e = 0, t = M, n = 1, s = 0; e < 24; e++) {
1764
- [n, s] = [s, (2 * n + 3 * s) % 5], se.push(2 * (5 * s + n)), re.push((e + 1) * (e + 2) / 2 % 64);
1765
- let r = wn;
1835
+ ), Pn = BigInt(0), N = BigInt(1), Tn = BigInt(2), vn = BigInt(7), kn = BigInt(256), Hn = BigInt(113), ne = [], se = [], re = [];
1836
+ for (let e = 0, t = N, n = 1, s = 0; e < 24; e++) {
1837
+ [n, s] = [s, (2 * n + 3 * s) % 5], ne.push(2 * (5 * s + n)), se.push((e + 1) * (e + 2) / 2 % 64);
1838
+ let r = Pn;
1766
1839
  for (let o = 0; o < 7; o++)
1767
- t = (t << M ^ (t >> Tn) * Hn) % vn, t & Pn && (r ^= M << (M << BigInt(o)) - M);
1768
- oe.push(r);
1840
+ t = (t << N ^ (t >> vn) * Hn) % kn, t & Tn && (r ^= N << (N << BigInt(o)) - N);
1841
+ re.push(r);
1769
1842
  }
1770
- const ie = te(oe, !0), kn = ie[0], In = ie[1], Ct = (e, t, n) => n > 32 ? sn(e, t, n) : en(e, t, n), _t = (e, t, n) => n > 32 ? rn(e, t, n) : nn(e, t, n);
1771
- function En(e, t = 24) {
1843
+ const oe = Qt(re, !0), In = oe[0], En = oe[1], Ct = (e, t, n) => n > 32 ? rn(e, t, n) : nn(e, t, n), Ot = (e, t, n) => n > 32 ? on(e, t, n) : sn(e, t, n);
1844
+ function Sn(e, t = 24) {
1772
1845
  const n = new Uint32Array(10);
1773
1846
  for (let s = 24 - t; s < 24; s++) {
1774
1847
  for (let i = 0; i < 10; i++)
1775
1848
  n[i] = e[i] ^ e[i + 10] ^ e[i + 20] ^ e[i + 30] ^ e[i + 40];
1776
1849
  for (let i = 0; i < 10; i += 2) {
1777
- const a = (i + 8) % 10, c = (i + 2) % 10, l = n[c], h = n[c + 1], u = Ct(l, h, 1) ^ n[a], d = _t(l, h, 1) ^ n[a + 1];
1778
- for (let p = 0; p < 50; p += 10)
1779
- e[i + p] ^= u, e[i + p + 1] ^= d;
1850
+ const a = (i + 8) % 10, c = (i + 2) % 10, u = n[c], h = n[c + 1], l = Ct(u, h, 1) ^ n[a], d = Ot(u, h, 1) ^ n[a + 1];
1851
+ for (let g = 0; g < 50; g += 10)
1852
+ e[i + g] ^= l, e[i + g + 1] ^= d;
1780
1853
  }
1781
1854
  let r = e[2], o = e[3];
1782
1855
  for (let i = 0; i < 24; i++) {
1783
- const a = re[i], c = Ct(r, o, a), l = _t(r, o, a), h = se[i];
1784
- r = e[h], o = e[h + 1], e[h] = c, e[h + 1] = l;
1856
+ const a = se[i], c = Ct(r, o, a), u = Ot(r, o, a), h = ne[i];
1857
+ r = e[h], o = e[h + 1], e[h] = c, e[h + 1] = u;
1785
1858
  }
1786
1859
  for (let i = 0; i < 50; i += 10) {
1787
1860
  for (let a = 0; a < 10; a++)
@@ -1789,11 +1862,11 @@ function En(e, t = 24) {
1789
1862
  for (let a = 0; a < 10; a++)
1790
1863
  e[i + a] ^= ~n[(a + 2) % 10] & n[(a + 4) % 10];
1791
1864
  }
1792
- e[0] ^= kn[s], e[1] ^= In[s];
1865
+ e[0] ^= In[s], e[1] ^= En[s];
1793
1866
  }
1794
1867
  A(n);
1795
1868
  }
1796
- class mt {
1869
+ class wt {
1797
1870
  // NOTE: we accept arguments in bytes instead of bits here.
1798
1871
  constructor(t, n, s, r = !1, o = 24) {
1799
1872
  f(this, "state");
@@ -1807,18 +1880,18 @@ class mt {
1807
1880
  f(this, "outputLen");
1808
1881
  f(this, "enableXOF", !1);
1809
1882
  f(this, "rounds");
1810
- if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF = r, this.rounds = o, C(s, "outputLen"), !(0 < t && t < 200))
1883
+ if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF = r, this.rounds = o, _(s, "outputLen"), !(0 < t && t < 200))
1811
1884
  throw new Error("only keccak-f1600 function is supported");
1812
- this.state = new Uint8Array(200), this.state32 = Re(this.state);
1885
+ this.state = new Uint8Array(200), this.state32 = Ve(this.state);
1813
1886
  }
1814
1887
  clone() {
1815
1888
  return this._cloneInto();
1816
1889
  }
1817
1890
  keccak() {
1818
- Bt(this.state32), En(this.state32, this.rounds), Bt(this.state32), this.posOut = 0, this.pos = 0;
1891
+ At(this.state32), Sn(this.state32, this.rounds), At(this.state32), this.posOut = 0, this.pos = 0;
1819
1892
  }
1820
1893
  update(t) {
1821
- K(this), _(t);
1894
+ M(this), R(t);
1822
1895
  const { blockLen: n, state: s } = this, r = t.length;
1823
1896
  for (let o = 0; o < r; ) {
1824
1897
  const i = Math.min(n - this.pos, r - o);
@@ -1836,7 +1909,7 @@ class mt {
1836
1909
  t[s] ^= n, (n & 128) !== 0 && s === r - 1 && this.keccak(), t[r - 1] ^= 128, this.keccak();
1837
1910
  }
1838
1911
  writeInto(t) {
1839
- K(this, !1), _(t), this.finish();
1912
+ M(this, !1), R(t), this.finish();
1840
1913
  const n = this.state, { blockLen: s } = this;
1841
1914
  for (let r = 0, o = t.length; r < o; ) {
1842
1915
  this.posOut >= s && this.keccak();
@@ -1851,10 +1924,10 @@ class mt {
1851
1924
  return this.writeInto(t);
1852
1925
  }
1853
1926
  xof(t) {
1854
- return C(t), this.xofInto(new Uint8Array(t));
1927
+ return _(t), this.xofInto(new Uint8Array(t));
1855
1928
  }
1856
1929
  digestInto(t) {
1857
- if (Gt(t, this), this.finished)
1930
+ if (Xt(t, this), this.finished)
1858
1931
  throw new Error("digest() was already called");
1859
1932
  return this.writeInto(t), this.destroy(), t;
1860
1933
  }
@@ -1866,116 +1939,116 @@ class mt {
1866
1939
  }
1867
1940
  _cloneInto(t) {
1868
1941
  const { blockLen: n, suffix: s, outputLen: r, rounds: o, enableXOF: i } = this;
1869
- return t || (t = new mt(n, s, r, i, o)), t.state32.set(this.state32), t.pos = this.pos, t.posOut = this.posOut, t.finished = this.finished, t.rounds = o, t.suffix = s, t.outputLen = r, t.enableXOF = i, t.destroyed = this.destroyed, t;
1942
+ return t || (t = new wt(n, s, r, i, o)), t.state32.set(this.state32), t.pos = this.pos, t.posOut = this.posOut, t.finished = this.finished, t.rounds = o, t.suffix = s, t.outputLen = r, t.enableXOF = i, t.destroyed = this.destroyed, t;
1870
1943
  }
1871
1944
  }
1872
- const Sn = (e, t, n, s = {}) => rt(() => new mt(t, e, n), s), An = /* @__PURE__ */ Sn(1, 136, 32);
1873
- function Bn(e, t, n, s) {
1874
- Xt(e);
1875
- const r = Me({ dkLen: 32, asyncTick: 10 }, s), { c: o, dkLen: i, asyncTick: a } = r;
1876
- if (C(o, "c"), C(i, "dkLen"), C(a, "asyncTick"), o < 1)
1945
+ const An = (e, t, n, s = {}) => rt(() => new wt(t, e, n), s), Bn = /* @__PURE__ */ An(1, 136, 32);
1946
+ function $n(e, t, n, s) {
1947
+ Nt(e);
1948
+ const r = Ne({ dkLen: 32, asyncTick: 10 }, s), { c: o, dkLen: i, asyncTick: a } = r;
1949
+ if (_(o, "c"), _(i, "dkLen"), _(a, "asyncTick"), o < 1)
1877
1950
  throw new Error("iterations (c) must be >= 1");
1878
- const c = Ut(t, "password"), l = Ut(n, "salt"), h = new Uint8Array(i), u = yt.create(e, c), d = u._cloneInto().update(l);
1879
- return { c: o, dkLen: i, asyncTick: a, DK: h, PRF: u, PRFSalt: d };
1951
+ const c = Bt(t, "password"), u = Bt(n, "salt"), h = new Uint8Array(i), l = yt.create(e, c), d = l._cloneInto().update(u);
1952
+ return { c: o, dkLen: i, asyncTick: a, DK: h, PRF: l, PRFSalt: d };
1880
1953
  }
1881
1954
  function Un(e, t, n, s, r) {
1882
1955
  return e.destroy(), t.destroy(), s && s.destroy(), A(r), n;
1883
1956
  }
1884
1957
  function Ln(e, t, n, s) {
1885
- const { c: r, dkLen: o, DK: i, PRF: a, PRFSalt: c } = Bn(e, t, n, s);
1886
- let l;
1887
- const h = new Uint8Array(4), u = et(h), d = new Uint8Array(a.outputLen);
1888
- for (let p = 1, b = 0; b < o; p++, b += a.outputLen) {
1889
- const m = i.subarray(b, b + a.outputLen);
1890
- u.setInt32(0, p, !1), (l = c._cloneInto(l)).update(h).digestInto(d), m.set(d.subarray(0, m.length));
1958
+ const { c: r, dkLen: o, DK: i, PRF: a, PRFSalt: c } = $n(e, t, n, s);
1959
+ let u;
1960
+ const h = new Uint8Array(4), l = et(h), d = new Uint8Array(a.outputLen);
1961
+ for (let g = 1, p = 0; p < o; g++, p += a.outputLen) {
1962
+ const m = i.subarray(p, p + a.outputLen);
1963
+ l.setInt32(0, g, !1), (u = c._cloneInto(u)).update(h).digestInto(d), m.set(d.subarray(0, m.length));
1891
1964
  for (let x = 1; x < r; x++) {
1892
- a._cloneInto(l).update(d).digestInto(d);
1893
- for (let g = 0; g < m.length; g++)
1894
- m[g] ^= d[g];
1965
+ a._cloneInto(u).update(d).digestInto(d);
1966
+ for (let y = 0; y < m.length; y++)
1967
+ m[y] ^= d[y];
1895
1968
  }
1896
1969
  }
1897
- return Un(a, c, i, l, d);
1970
+ return Un(a, c, i, u, d);
1898
1971
  }
1899
- function ae(e) {
1972
+ function ie(e) {
1900
1973
  if (typeof e != "string")
1901
1974
  throw new TypeError("invalid mnemonic type: " + typeof e);
1902
1975
  return e.normalize("NFKD");
1903
1976
  }
1904
- function $n(e) {
1905
- const t = ae(e), n = t.split(" ");
1977
+ function Fn(e) {
1978
+ const t = ie(e), n = t.split(" ");
1906
1979
  if (![12, 15, 18, 21, 24].includes(n.length))
1907
1980
  throw new Error("Invalid mnemonic");
1908
1981
  return { nfkd: t, words: n };
1909
1982
  }
1910
- const Fn = (e) => ae("mnemonic" + e);
1983
+ const Cn = (e) => ie("mnemonic" + e);
1911
1984
  function On(e, t = "") {
1912
- return Ln(ne, $n(e).nfkd, Fn(t), { c: 2048, dkLen: 64 });
1985
+ return Ln(ee, Fn(e).nfkd, Cn(t), { c: 2048, dkLen: 64 });
1913
1986
  }
1914
- const Cn = 508, Rt = 16, Y = 32, Q = 64, Vt = 5, _n = 4;
1915
- function N(...e) {
1987
+ const _n = 508, _t = 16, Y = 32, Q = 64, Rt = 5, Rn = 4;
1988
+ function X(...e) {
1916
1989
  const t = e.reduce((r, o) => r + o.length, 0), n = new Uint8Array(t);
1917
1990
  let s = 0;
1918
1991
  for (const r of e)
1919
1992
  n.set(r, s), s += r.length;
1920
1993
  return n;
1921
1994
  }
1922
- function ut(e) {
1995
+ function lt(e) {
1923
1996
  return new TextEncoder().encode(e);
1924
1997
  }
1925
- function lt(e) {
1926
- const t = new Uint8Array(_n);
1927
- return new DataView(t.buffer).setUint32(0, e.length, !1), N(t, e);
1998
+ function ht(e) {
1999
+ const t = new Uint8Array(Rn);
2000
+ return new DataView(t.buffer).setUint32(0, e.length, !1), X(t, e);
1928
2001
  }
1929
- function ht(e, t) {
1930
- return yt(ne, e, t);
2002
+ function ft(e, t) {
2003
+ return yt(ee, e, t);
1931
2004
  }
1932
- function Wt(e) {
1933
- return Qe(mn(e));
2005
+ function Vt(e) {
2006
+ return tn(wn(e));
1934
2007
  }
1935
- const bt = (e) => Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
1936
- function Rn(e) {
2008
+ const gt = (e) => Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
2009
+ function Vn(e) {
1937
2010
  const t = On(e);
1938
2011
  return new Uint8Array(t);
1939
2012
  }
1940
- async function Vn(e, t, n, s) {
2013
+ async function Wn(e, t, n, s) {
1941
2014
  if (e.length !== Q)
1942
2015
  throw new Error(
1943
2016
  `Lamport seed must be ${Q} bytes, got ${e.length}`
1944
2017
  );
1945
- t = W(t), n = W(n);
2018
+ t = D(t), n = D(n);
1946
2019
  const r = e.slice(Y, Q), o = e.slice(0, Y), i = [r, o];
1947
2020
  try {
1948
- const a = N(
1949
- lt(ut(t)),
1950
- lt(ut(n)),
1951
- lt(ut(s))
1952
- ), c = N(o, a);
2021
+ const a = X(
2022
+ ht(lt(t)),
2023
+ ht(lt(n)),
2024
+ ht(lt(s))
2025
+ ), c = X(o, a);
1953
2026
  i.push(c);
1954
- const l = ht(r, c);
1955
- i.push(l);
1956
- const h = l.slice(0, Y), u = l.slice(Y, Q);
1957
- i.push(h, u);
1958
- const d = [], p = [], b = [], m = [];
2027
+ const u = ft(r, c);
2028
+ i.push(u);
2029
+ const h = u.slice(0, Y), l = u.slice(Y, Q);
2030
+ i.push(h, l);
2031
+ const d = [], g = [], p = [], m = [];
1959
2032
  let x = !1;
1960
2033
  try {
1961
- for (let g = 0; g < Cn; g++) {
1962
- const w = new Uint8Array(Vt);
1963
- w[0] = 0, new DataView(w.buffer).setUint32(1, g, !1);
1964
- const y = new Uint8Array(Vt);
1965
- y[0] = 1, new DataView(y.buffer).setUint32(1, g, !1);
1966
- const P = N(h, w), v = N(h, y), T = ht(u, P), k = ht(u, v);
2034
+ for (let y = 0; y < _n; y++) {
2035
+ const w = new Uint8Array(Rt);
2036
+ w[0] = 0, new DataView(w.buffer).setUint32(1, y, !1);
2037
+ const b = new Uint8Array(Rt);
2038
+ b[0] = 1, new DataView(b.buffer).setUint32(1, y, !1);
2039
+ const P = X(h, w), T = X(h, b), v = ft(l, P), E = ft(l, T);
1967
2040
  try {
1968
- const I = T.slice(0, Rt), E = k.slice(0, Rt);
1969
- d.push(I), p.push(E), b.push(Wt(I)), m.push(Wt(E));
2041
+ const k = v.slice(0, _t), I = E.slice(0, _t);
2042
+ d.push(k), g.push(I), p.push(Vt(k)), m.push(Vt(I));
1970
2043
  } finally {
1971
- P.fill(0), v.fill(0), T.fill(0), k.fill(0);
2044
+ P.fill(0), T.fill(0), v.fill(0), E.fill(0);
1972
2045
  }
1973
2046
  }
1974
- return x = !0, { falsePreimages: d, truePreimages: p, falseHashes: b, trueHashes: m };
2047
+ return x = !0, { falsePreimages: d, truePreimages: g, falseHashes: p, trueHashes: m };
1975
2048
  } finally {
1976
2049
  if (!x) {
1977
- for (const g of d) g.fill(0);
1978
- for (const g of p) g.fill(0);
2050
+ for (const y of d) y.fill(0);
2051
+ for (const y of g) y.fill(0);
1979
2052
  }
1980
2053
  }
1981
2054
  } finally {
@@ -1985,11 +2058,11 @@ async function Vn(e, t, n, s) {
1985
2058
  }
1986
2059
  function as(e) {
1987
2060
  return {
1988
- false_list: e.falseHashes.map(bt),
1989
- true_list: e.trueHashes.map(bt)
2061
+ false_list: e.falseHashes.map(gt),
2062
+ true_list: e.trueHashes.map(gt)
1990
2063
  };
1991
2064
  }
1992
- function Wn(e) {
2065
+ function Dn(e) {
1993
2066
  if (e.falseHashes.length === 0 || e.trueHashes.length === 0)
1994
2067
  throw new Error(
1995
2068
  "computeLamportPkHash: keypair hash arrays must not be empty"
@@ -2000,20 +2073,20 @@ function Wn(e) {
2000
2073
  s.set(i, r), r += t;
2001
2074
  for (const i of e.trueHashes)
2002
2075
  s.set(i, r), r += t;
2003
- const o = An(s);
2004
- return `0x${bt(o)}`;
2076
+ const o = Bn(s);
2077
+ return `0x${gt(o)}`;
2005
2078
  }
2006
2079
  async function cs(e, t, n, s) {
2007
- const r = Rn(e);
2080
+ const r = Vn(e);
2008
2081
  try {
2009
- const o = await Vn(
2082
+ const o = await Wn(
2010
2083
  r,
2011
2084
  t,
2012
2085
  n,
2013
2086
  s
2014
2087
  );
2015
2088
  try {
2016
- return Wn(o);
2089
+ return Dn(o);
2017
2090
  } finally {
2018
2091
  for (const i of o.falsePreimages) i.fill(0);
2019
2092
  for (const i of o.truePreimages) i.fill(0);
@@ -2027,11 +2100,12 @@ function us(e) {
2027
2100
  return t.includes("lamport") && t.includes("hash") && t.includes("does not match");
2028
2101
  }
2029
2102
  export {
2030
- cs as A,
2103
+ Dn as A,
2031
2104
  tt as B,
2032
- D as C,
2033
- us as D,
2034
- Le as M,
2105
+ K as C,
2106
+ cs as D,
2107
+ us as E,
2108
+ Ue as M,
2035
2109
  os as P,
2036
2110
  zn as a,
2037
2111
  Zn as b,
@@ -2040,24 +2114,24 @@ export {
2040
2114
  Se as e,
2041
2115
  Ae as f,
2042
2116
  qn as g,
2043
- is as h,
2044
- es as i,
2045
- Qn as j,
2046
- ts as k,
2047
- ns as l,
2048
- Yn as m,
2049
- Fe as n,
2050
- Oe as o,
2051
- $e as p,
2052
- ct as q,
2053
- xt as r,
2117
+ bt as h,
2118
+ is as i,
2119
+ es as j,
2120
+ Qn as k,
2121
+ ts as l,
2122
+ ns as m,
2123
+ Yn as n,
2124
+ Fe as o,
2125
+ Ce as p,
2126
+ Le as q,
2127
+ ct as r,
2054
2128
  Ee as s,
2055
- ss as t,
2056
- rs as u,
2057
- At as v,
2058
- Rn as w,
2129
+ xt as t,
2130
+ ss as u,
2131
+ rs as v,
2132
+ ut as w,
2059
2133
  Vn as x,
2060
- as as y,
2061
- Wn as z
2134
+ Wn as y,
2135
+ as as z
2062
2136
  };
2063
- //# sourceMappingURL=errors-D_DWT0CT.js.map
2137
+ //# sourceMappingURL=errors-DOJdtNTD.js.map