@babylonlabs-io/ts-sdk 0.13.0 → 0.13.2

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.
@@ -1,13 +1,13 @@
1
1
  var ce = Object.defineProperty;
2
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);
3
+ var d = (e, t, n) => ue(e, typeof t != "symbol" ? t + "" : t, n);
4
4
  import * as le from "bitcoinjs-lib";
5
- import { script as he, Transaction as st, address as fe, Psbt as dt } from "bitcoinjs-lib";
5
+ import { script as he, Transaction as q, address as fe, Psbt as dt } from "bitcoinjs-lib";
6
6
  import { Buffer as S } from "buffer";
7
- import { P as de, y as pe, D as Vt, M as Tt, B as be, T as ge, G as pt, u as D, b as xe, A as ye, E as we, a as me, d as Pe, e as Te, f as ve, s as at, q as ke, x as vt, h as kt, i as Ht } from "./challengeAssert-CenzzhZU.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) {
7
+ import { P as de, y as pe, D as Vt, M as Tt, B as be, T as ge, G as pt, u as $, b as xe, A as ye, E as we, a as me, d as Pe, e as Te, f as ve, s as z, q as ke, x as vt, h as kt, i as Ht, r as He } from "./challengeAssert-CenzzhZU.js";
8
+ import { createPublicClient as It, http as Et, encodeFunctionData as Ie, zeroAddress as Ee } from "viem";
9
+ import { deriveVaultId as Se } from "@babylonlabs-io/babylon-tbv-rust-wasm";
10
+ function Ae(e, t, n, s) {
11
11
  if (!Number.isInteger(s) || s < 1)
12
12
  throw new Error(
13
13
  `Invalid numOutputs: expected a positive integer, got ${s}`
@@ -26,20 +26,20 @@ function Ee(e, t, n, s) {
26
26
  let a = 0n, c = 0n;
27
27
  for (const u of o) {
28
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 > Vt) {
31
- const p = BigInt(
29
+ const h = i.length * de, l = s * Tt, f = h + l + ge;
30
+ if (c = BigInt(Math.ceil(f * n)) + BigInt(pe(n)), a - t - c > Vt) {
31
+ const b = BigInt(
32
32
  Math.ceil(Tt * n)
33
33
  );
34
- c += p;
34
+ c += b;
35
35
  }
36
36
  if (a >= t + c) {
37
- const p = a - t - c;
37
+ const b = a - t - c;
38
38
  return {
39
39
  selectedUTXOs: i,
40
40
  totalValue: a,
41
41
  fee: c,
42
- changeAmount: p
42
+ changeAmount: b
43
43
  };
44
44
  }
45
45
  }
@@ -47,17 +47,17 @@ function Ee(e, t, n, s) {
47
47
  `Insufficient funds: need ${t + c} sats (${t} pegin + ${c} fee), have ${a} sats`
48
48
  );
49
49
  }
50
- function qn(e) {
50
+ function Zn(e) {
51
51
  return e > Vt;
52
52
  }
53
- function zn() {
53
+ function Jn() {
54
54
  return be;
55
55
  }
56
56
  function St(e) {
57
57
  const t = e.startsWith("0x") ? e.slice(2) : e;
58
- return `0x${st.fromHex(t).getId()}`;
58
+ return `0x${q.fromHex(t).getId()}`;
59
59
  }
60
- function Zn(e, t, n) {
60
+ function Yn(e, t, n) {
61
61
  if (e.length === 0)
62
62
  throw new Error("No input UTXOs provided for split transaction");
63
63
  if (t.length === 0)
@@ -67,7 +67,7 @@ function Zn(e, t, n) {
67
67
  throw new Error(
68
68
  `Invalid output amount for ${c.address}: ${c.amount} satoshis. Amount must be greater than zero.`
69
69
  );
70
- const s = pt(n), r = new st();
70
+ const s = pt(n), r = new q();
71
71
  r.version = 2;
72
72
  for (const c of e) {
73
73
  const u = S.from(c.txid, "hex").reverse();
@@ -101,8 +101,8 @@ function Zn(e, t, n) {
101
101
  outputs: o
102
102
  };
103
103
  }
104
- function Jn(e, t, n) {
105
- const s = st.fromHex(e), r = new dt();
104
+ function Qn(e, t, n) {
105
+ const s = q.fromHex(e), r = new dt();
106
106
  if (r.setVersion(s.version), r.setLocktime(s.locktime), !S.isBuffer(n) || n.length !== 32)
107
107
  throw new Error(
108
108
  `Invalid publicKeyNoCoord: expected 32-byte Buffer (x-only pubkey), got ${S.isBuffer(n) ? `${n.length}-byte Buffer` : typeof n}`
@@ -126,7 +126,7 @@ function Jn(e, t, n) {
126
126
  throw new Error(
127
127
  `Input ${o} must be P2TR (Taproot). createSplitTransactionPsbt() requires P2TR inputs because it uses tapInternalKey for Taproot signing. ScriptPubKey: ${a.scriptPubKey.substring(0, 20)}...`
128
128
  );
129
- const d = {
129
+ const f = {
130
130
  script: S.from(a.scriptPubKey, "hex"),
131
131
  value: a.value
132
132
  };
@@ -134,7 +134,7 @@ function Jn(e, t, n) {
134
134
  hash: i.hash,
135
135
  index: i.index,
136
136
  sequence: i.sequence,
137
- witnessUtxo: d,
137
+ witnessUtxo: f,
138
138
  tapInternalKey: n
139
139
  });
140
140
  }
@@ -145,8 +145,8 @@ function Jn(e, t, n) {
145
145
  });
146
146
  return r.toHex();
147
147
  }
148
- var tt = /* @__PURE__ */ ((e) => (e.P2PKH = "P2PKH", e.P2SH = "P2SH", e.P2WPKH = "P2WPKH", e.P2WSH = "P2WSH", e.P2TR = "P2TR", e.UNKNOWN = "UNKNOWN", e))(tt || {});
149
- function Se(e) {
148
+ var st = /* @__PURE__ */ ((e) => (e.P2PKH = "P2PKH", e.P2SH = "P2SH", e.P2WPKH = "P2WPKH", e.P2WSH = "P2WSH", e.P2TR = "P2TR", e.UNKNOWN = "UNKNOWN", e))(st || {});
149
+ function Be(e) {
150
150
  const t = e.length;
151
151
  return t === 25 && e[0] === 118 && // OP_DUP
152
152
  e[1] === 169 && // OP_HASH160
@@ -159,17 +159,17 @@ function Se(e) {
159
159
  e[1] === 32 ? "P2WSH" : t === 34 && e[0] === 81 && // OP_1
160
160
  e[1] === 32 ? "P2TR" : "UNKNOWN";
161
161
  }
162
- function Ae(e, t) {
163
- const n = S.from(e.scriptPubKey, "hex"), s = Se(n);
162
+ function $e(e, t) {
163
+ const n = S.from(e.scriptPubKey, "hex"), s = Be(n);
164
164
  switch (s) {
165
- case tt.P2WPKH:
165
+ case st.P2WPKH:
166
166
  return {
167
167
  witnessUtxo: {
168
168
  script: n,
169
169
  value: e.value
170
170
  }
171
171
  };
172
- case tt.P2WSH: {
172
+ case st.P2WSH: {
173
173
  if (!e.witnessScript)
174
174
  throw new Error("Missing witnessScript for P2WSH input");
175
175
  return {
@@ -180,7 +180,7 @@ function Ae(e, t) {
180
180
  witnessScript: S.from(e.witnessScript, "hex")
181
181
  };
182
182
  }
183
- case tt.P2TR: {
183
+ case st.P2TR: {
184
184
  if (t && t.length !== 32)
185
185
  throw new Error(
186
186
  `Invalid tapInternalKey length: expected 32 bytes, got ${t.length}`
@@ -210,22 +210,22 @@ function bt(e, t) {
210
210
  }))
211
211
  };
212
212
  }
213
- const Be = 21e6 * 1e8, Dt = 1e4;
214
- function Kt(e) {
215
- return Number.isInteger(e) && e > 0 && e <= Be;
213
+ const Ue = 21e6 * 1e8, Kt = 1e4;
214
+ function Dt(e) {
215
+ return Number.isInteger(e) && e > 0 && e <= Ue;
216
216
  }
217
- function $e(e) {
218
- return Number.isInteger(e) && e > 0 && e <= Dt;
217
+ function Fe(e) {
218
+ return Number.isInteger(e) && e > 0 && e <= Kt;
219
219
  }
220
220
  function Mt(e, t) {
221
221
  return !Number.isInteger(e) || e < 0 ? !1 : t === void 0 || e < t;
222
222
  }
223
- const Ue = {
223
+ const Oe = {
224
224
  mainnet: "https://mempool.space/api",
225
225
  testnet: "https://mempool.space/testnet/api",
226
226
  signet: "https://mempool.space/signet/api"
227
227
  };
228
- async function nt(e, t) {
228
+ async function ot(e, t) {
229
229
  try {
230
230
  const n = await fetch(e, t);
231
231
  if (!n.ok) {
@@ -240,7 +240,7 @@ async function nt(e, t) {
240
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");
241
241
  }
242
242
  }
243
- async function Fe(e, t) {
243
+ async function Le(e, t) {
244
244
  try {
245
245
  const n = await fetch(`${t}/tx`, {
246
246
  method: "POST",
@@ -266,10 +266,10 @@ async function Fe(e, t) {
266
266
  throw n instanceof Error ? new Error(`Failed to broadcast BTC transaction: ${n.message}`) : new Error("Failed to broadcast BTC transaction: Unknown error");
267
267
  }
268
268
  }
269
- async function Le(e, t) {
270
- return nt(`${t}/tx/${e}`);
269
+ async function Ce(e, t) {
270
+ return ot(`${t}/tx/${e}`);
271
271
  }
272
- async function Yn(e, t) {
272
+ async function ts(e, t) {
273
273
  try {
274
274
  const n = await fetch(`${t}/tx/${e}/hex`);
275
275
  if (!n.ok) {
@@ -283,14 +283,14 @@ async function Yn(e, t) {
283
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`);
284
284
  }
285
285
  }
286
- async function Oe(e, t, n) {
287
- const s = await Le(e, n);
286
+ async function _e(e, t, n) {
287
+ const s = await Ce(e, n);
288
288
  if (!Mt(t, s.vout.length))
289
289
  throw new Error(
290
290
  `Invalid vout ${t} for transaction ${e} (has ${s.vout.length} outputs)`
291
291
  );
292
292
  const r = s.vout[t];
293
- if (!Kt(r.value))
293
+ if (!Dt(r.value))
294
294
  throw new Error(`Invalid UTXO value ${r.value} for ${e}:${t}`);
295
295
  return {
296
296
  txid: e,
@@ -299,9 +299,9 @@ async function Oe(e, t, n) {
299
299
  scriptPubKey: r.scriptpubkey
300
300
  };
301
301
  }
302
- async function Qn(e, t) {
302
+ async function es(e, t) {
303
303
  try {
304
- const n = await nt(`${t}/address/${e}/utxo`), s = await nt(`${t}/v1/validate-address/${e}`);
304
+ const n = await ot(`${t}/address/${e}/utxo`), s = await ot(`${t}/v1/validate-address/${e}`);
305
305
  if (!s.isvalid)
306
306
  throw new Error(
307
307
  `Invalid Bitcoin address: ${e}. Mempool API validation failed.`
@@ -309,7 +309,7 @@ async function Qn(e, t) {
309
309
  for (const o of n) {
310
310
  if (!Mt(o.vout))
311
311
  throw new Error(`Invalid vout ${o.vout} for ${o.txid}`);
312
- if (!Kt(o.value))
312
+ if (!Dt(o.value))
313
313
  throw new Error(
314
314
  `Invalid UTXO value ${o.value} for ${o.txid}:${o.vout}`
315
315
  );
@@ -329,13 +329,13 @@ async function Qn(e, t) {
329
329
  );
330
330
  }
331
331
  }
332
- function ts(e) {
333
- return Ue[e];
332
+ function ns(e) {
333
+ return Oe[e];
334
334
  }
335
- async function es(e, t) {
336
- return nt(`${t}/address/${e}/txs`);
335
+ async function ss(e, t) {
336
+ return ot(`${t}/address/${e}/txs`);
337
337
  }
338
- async function ns(e) {
338
+ async function rs(e) {
339
339
  const t = await fetch(`${e}/v1/fees/recommended`);
340
340
  if (!t.ok)
341
341
  throw new Error(
@@ -349,9 +349,9 @@ async function ns(e) {
349
349
  "minimumFee"
350
350
  ];
351
351
  for (const r of s)
352
- if (!$e(n[r]))
352
+ if (!Fe(n[r]))
353
353
  throw new Error(
354
- `Invalid fee rate ${r}=${n[r]} from mempool API: expected a positive number ≤ ${Dt}`
354
+ `Invalid fee rate ${r}=${n[r]} from mempool API: expected a positive number ≤ ${Kt}`
355
355
  );
356
356
  if (n.minimumFee > n.economyFee || n.economyFee > n.hourFee || n.hourFee > n.halfHourFee || n.halfHourFee > n.fastestFee)
357
357
  throw new Error(
@@ -624,7 +624,7 @@ const ct = [
624
624
  name: "PeginSignaturesIncomplete",
625
625
  inputs: []
626
626
  }
627
- ], K = {
627
+ ], N = {
628
628
  // VaultAlreadyExists()
629
629
  "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.",
630
630
  // ScriptPubKeyMismatch() - taproot output doesn't match expected script
@@ -673,24 +673,24 @@ function xt(e) {
673
673
  if (i)
674
674
  return i[1];
675
675
  }
676
- function ss(e) {
676
+ function os(e) {
677
677
  const t = xt(e);
678
678
  if (t) {
679
679
  const n = t.substring(0, 10);
680
- return K[t] ?? K[n];
680
+ return N[t] ?? N[n];
681
681
  }
682
682
  }
683
- function rs(e) {
683
+ function is(e) {
684
684
  const t = xt(e);
685
685
  if (t === void 0) return !1;
686
686
  const n = t.substring(0, 10);
687
- return t in K || n in K;
687
+ return t in N || n in N;
688
688
  }
689
689
  function ut(e) {
690
690
  console.error("[Contract Error] Raw error:", e);
691
691
  const t = xt(e);
692
692
  if (console.error("[Contract Error] Extracted error data:", t), t) {
693
- const s = t.substring(0, 10), r = K[t] ?? K[s];
693
+ const s = t.substring(0, 10), r = N[t] ?? N[s];
694
694
  if (r)
695
695
  throw console.error("[Contract Error] Known error:", r), new Error(r);
696
696
  }
@@ -708,24 +708,24 @@ function ut(e) {
708
708
  }
709
709
  throw e instanceof Error ? (console.error("[Contract Error] Unhandled error:", e.message), e) : new Error(`Contract call failed: ${String(e)}`);
710
710
  }
711
- function Ce(e, t, n, s) {
711
+ function We(e, t, n, s) {
712
712
  const r = n == null ? void 0 : n[`${e}:${t}`];
713
713
  return r ? Promise.resolve({
714
714
  txid: e,
715
715
  vout: t,
716
716
  value: r.value,
717
717
  scriptPubKey: r.scriptPubKey
718
- }) : Oe(e, t, s);
718
+ }) : _e(e, t, s);
719
719
  }
720
- const _e = 12e4;
721
- class os {
720
+ const Re = 12e4;
721
+ class as {
722
722
  /**
723
723
  * Creates a new PeginManager instance.
724
724
  *
725
725
  * @param config - Manager configuration including wallets and contract addresses
726
726
  */
727
727
  constructor(t) {
728
- f(this, "config");
728
+ d(this, "config");
729
729
  this.config = t;
730
730
  }
731
731
  /**
@@ -749,7 +749,7 @@ class os {
749
749
  * @throws Error if wallet operations fail or insufficient funds
750
750
  */
751
751
  async preparePegin(t) {
752
- 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);
752
+ const n = await this.config.btcWallet.getPublicKeyHex(), s = n.length === 66 ? n.slice(2) : n, r = $(t.vaultProviderBtcPubkey), o = t.vaultKeeperBtcPubkeys.map($), i = t.universalChallengerBtcPubkeys.map($);
753
753
  if (t.hashlocks.length !== t.amounts.length)
754
754
  throw new Error(
755
755
  `hashlocks.length (${t.hashlocks.length}) must equal amounts.length (${t.amounts.length})`
@@ -769,36 +769,36 @@ class os {
769
769
  councilQuorum: t.councilQuorum,
770
770
  councilSize: t.councilSize,
771
771
  network: this.config.btcNetwork
772
- }, u = await xe(c), h = Ee(
772
+ }, u = await xe(c), h = Ae(
773
773
  [...t.availableUTXOs],
774
774
  u.totalOutputValue,
775
775
  t.mempoolFeeRate,
776
776
  ye(u.htlcValues.length)
777
- ), l = pt(this.config.btcNetwork), d = we({
777
+ ), l = pt(this.config.btcNetwork), f = we({
778
778
  unfundedTxHex: u.psbtHex,
779
779
  selectedUTXOs: h.selectedUTXOs,
780
780
  changeAddress: t.changeAddress,
781
781
  changeAmount: h.changeAmount,
782
782
  network: l
783
- }), g = D(St(d)), p = [], w = [], x = [];
784
- for (let b = 0; b < t.hashlocks.length; b++) {
783
+ }), g = $(St(f)), b = [], w = [], x = [];
784
+ for (let p = 0; p < t.hashlocks.length; p++) {
785
785
  const P = await me({
786
786
  prePeginParams: c,
787
787
  timelockPegin: t.timelockPegin,
788
- fundedPrePeginTxHex: d,
789
- htlcVout: b
790
- }), T = await Pe({
788
+ fundedPrePeginTxHex: f,
789
+ htlcVout: p
790
+ }), v = await Pe({
791
791
  peginTxHex: P.txHex,
792
- fundedPrePeginTxHex: d,
792
+ fundedPrePeginTxHex: f,
793
793
  depositorPubkey: s,
794
794
  vaultProviderPubkey: r,
795
795
  vaultKeeperPubkeys: o,
796
796
  universalChallengerPubkeys: i,
797
- hashlock: t.hashlocks[b],
797
+ hashlock: t.hashlocks[p],
798
798
  timelockRefund: t.timelockRefund,
799
799
  network: this.config.btcNetwork
800
800
  });
801
- p.push(P), w.push(T.psbtHex), x.push(
801
+ b.push(P), w.push(v.psbtHex), x.push(
802
802
  bt(n, 1)
803
803
  );
804
804
  }
@@ -806,22 +806,22 @@ class os {
806
806
  w,
807
807
  x
808
808
  ), m = [];
809
- for (let b = 0; b < y.length; b++) {
809
+ for (let p = 0; p < y.length; p++) {
810
810
  const P = Te(
811
- y[b],
811
+ y[p],
812
812
  s
813
- ), T = ve(y[b]);
813
+ ), v = ve(y[p]);
814
814
  m.push({
815
- htlcVout: b,
816
- htlcValue: u.htlcValues[b],
817
- peginTxHex: T,
818
- peginTxid: p[b].txid,
815
+ htlcVout: p,
816
+ htlcValue: u.htlcValues[p],
817
+ peginTxHex: v,
818
+ peginTxid: b[p].txid,
819
819
  peginInputSignature: P,
820
- vaultScriptPubKey: p[b].vaultScriptPubKey
820
+ vaultScriptPubKey: b[p].vaultScriptPubKey
821
821
  });
822
822
  }
823
823
  return {
824
- fundedPrePeginTxHex: d,
824
+ fundedPrePeginTxHex: f,
825
825
  prePeginTxid: g,
826
826
  unsignedPrePeginTxHex: u.psbtHex,
827
827
  perVault: m,
@@ -875,7 +875,7 @@ class os {
875
875
  * @throws Error if signing or broadcasting fails
876
876
  */
877
877
  async signAndBroadcast(t) {
878
- const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, r = n.startsWith("0x") ? n.slice(2) : n, o = st.fromHex(r);
878
+ const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, r = n.startsWith("0x") ? n.slice(2) : n, o = q.fromHex(r);
879
879
  if (o.ins.length === 0)
880
880
  throw new Error("Transaction has no inputs");
881
881
  const i = new dt();
@@ -892,12 +892,12 @@ class os {
892
892
  );
893
893
  const u = this.config.mempoolApiUrl, h = o.ins.map((x) => {
894
894
  const y = S.from(x.hash).reverse().toString("hex"), m = x.index;
895
- return Ce(y, m, t.localPrevouts, u).then(
896
- (b) => ({ input: x, utxoData: b, txid: y, vout: m })
895
+ return We(y, m, t.localPrevouts, u).then(
896
+ (p) => ({ input: x, utxoData: p, txid: y, vout: m })
897
897
  );
898
898
  }), l = await Promise.all(h);
899
- for (const { input: x, utxoData: y, txid: m, vout: b } of l) {
900
- const P = Ae(
899
+ for (const { input: x, utxoData: y, txid: m, vout: p } of l) {
900
+ const P = $e(
901
901
  {
902
902
  value: y.value,
903
903
  scriptPubKey: y.scriptPubKey
@@ -916,7 +916,7 @@ class os {
916
916
  script: x.script,
917
917
  value: x.value
918
918
  });
919
- const d = await this.config.btcWallet.signPsbt(i.toHex()), g = dt.fromHex(d);
919
+ const f = await this.config.btcWallet.signPsbt(i.toHex()), g = dt.fromHex(f);
920
920
  try {
921
921
  g.finalizeAllInputs();
922
922
  } catch (x) {
@@ -927,8 +927,8 @@ class os {
927
927
  `PSBT finalization failed and wallet did not auto-finalize: ${x}`
928
928
  );
929
929
  }
930
- const p = g.extractTransaction().toHex();
931
- return await Fe(p, u);
930
+ const b = g.extractTransaction().toHex();
931
+ return await Le(b, u);
932
932
  }
933
933
  /**
934
934
  * Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
@@ -962,25 +962,28 @@ class os {
962
962
  } = t;
963
963
  if (!this.config.ethWallet.account)
964
964
  throw new Error("Ethereum wallet account not found");
965
- const d = this.config.ethWallet.account.address, g = await this.resolvePopSignature(
966
- d,
965
+ const f = this.config.ethWallet.account.address, g = await this.resolvePopSignature(
966
+ f,
967
967
  l
968
968
  );
969
969
  c && await c();
970
- const p = at(n), w = at(s), x = at(r), y = await this.resolvePayoutScriptPubKey(
970
+ const b = z(n), w = z(s), x = z(r), y = await this.resolvePayoutScriptPubKey(
971
971
  u
972
- ), m = St(x);
973
- if (await this.checkVaultExists(m))
972
+ ), m = St(x), p = await Se(
973
+ $(m),
974
+ $(f)
975
+ ), P = z(p);
976
+ if (await this.checkVaultExists(P))
974
977
  throw new Error(
975
- `Vault already exists for this transaction (ID: ${m}). 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.`
978
+ `Vault already exists (ID: ${P}, peginTxHash: ${m}). 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.`
976
979
  );
977
- const P = It({
980
+ const T = It({
978
981
  chain: this.config.ethChain,
979
982
  transport: Et()
980
983
  });
981
- let T;
984
+ let E;
982
985
  try {
983
- T = await P.readContract({
986
+ E = await T.readContract({
984
987
  address: this.config.vaultContracts.btcVaultRegistry,
985
988
  abi: ct,
986
989
  functionName: "getPegInFee",
@@ -991,12 +994,12 @@ class os {
991
994
  "Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
992
995
  );
993
996
  }
994
- const v = He({
997
+ const H = Ie({
995
998
  abi: ct,
996
999
  functionName: "submitPeginRequest",
997
1000
  args: [
998
- d,
999
- p,
1001
+ f,
1002
+ b,
1000
1003
  g,
1001
1004
  w,
1002
1005
  x,
@@ -1007,41 +1010,42 @@ class os {
1007
1010
  h
1008
1011
  ]
1009
1012
  });
1010
- let E;
1013
+ let I;
1011
1014
  try {
1012
- E = await P.estimateGas({
1015
+ I = await T.estimateGas({
1013
1016
  to: this.config.vaultContracts.btcVaultRegistry,
1014
- data: v,
1015
- value: T,
1017
+ data: H,
1018
+ value: E,
1016
1019
  account: this.config.ethWallet.account.address
1017
1020
  });
1018
- } catch (U) {
1019
- ut(U);
1021
+ } catch (O) {
1022
+ ut(O);
1020
1023
  }
1021
- let k;
1024
+ let F;
1022
1025
  try {
1023
- k = await this.config.ethWallet.sendTransaction({
1026
+ F = await this.config.ethWallet.sendTransaction({
1024
1027
  to: this.config.vaultContracts.btcVaultRegistry,
1025
- data: v,
1026
- value: T,
1028
+ data: H,
1029
+ value: E,
1027
1030
  account: this.config.ethWallet.account,
1028
1031
  chain: this.config.ethChain,
1029
- gas: E
1032
+ gas: I
1030
1033
  });
1031
- } catch (U) {
1032
- ut(U);
1034
+ } catch (O) {
1035
+ ut(O);
1033
1036
  }
1034
- const I = await P.waitForTransactionReceipt({
1035
- hash: k,
1036
- timeout: _e
1037
+ const K = await T.waitForTransactionReceipt({
1038
+ hash: F,
1039
+ timeout: Re
1037
1040
  });
1038
- return I.status === "reverted" && ut(
1041
+ return K.status === "reverted" && ut(
1039
1042
  new Error(
1040
- `Transaction reverted. Hash: ${k}. Check the transaction on block explorer for details.`
1043
+ `Transaction reverted. Hash: ${F}. Check the transaction on block explorer for details.`
1041
1044
  )
1042
1045
  ), {
1043
- ethTxHash: I.transactionHash,
1044
- vaultId: m,
1046
+ ethTxHash: K.transactionHash,
1047
+ vaultId: P,
1048
+ peginTxHash: m,
1045
1049
  btcPopSignature: g
1046
1050
  };
1047
1051
  }
@@ -1061,7 +1065,7 @@ class os {
1061
1065
  abi: ct,
1062
1066
  functionName: "getBTCVault",
1063
1067
  args: [t]
1064
- })).depositor !== Ie;
1068
+ })).depositor !== Ee;
1065
1069
  } catch {
1066
1070
  return !1;
1067
1071
  }
@@ -1130,14 +1134,14 @@ class os {
1130
1134
  return this.config.vaultContracts.btcVaultRegistry;
1131
1135
  }
1132
1136
  }
1133
- class is {
1137
+ class cs {
1134
1138
  /**
1135
1139
  * Creates a new PayoutManager instance.
1136
1140
  *
1137
1141
  * @param config - Manager configuration including wallet
1138
1142
  */
1139
1143
  constructor(t) {
1140
- f(this, "config");
1144
+ d(this, "config");
1141
1145
  this.config = t;
1142
1146
  }
1143
1147
  /**
@@ -1163,6 +1167,10 @@ class is {
1163
1167
  * @throws Error if wallet operations fail or signature extraction fails
1164
1168
  */
1165
1169
  async signPayoutTransaction(t) {
1170
+ this.validatePayoutOutputs(
1171
+ t.payoutTxHex,
1172
+ t.registeredPayoutScriptPubKey
1173
+ );
1166
1174
  const n = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: s } = vt(
1167
1175
  n,
1168
1176
  t.depositorBtcPubkey
@@ -1217,6 +1225,10 @@ class is {
1217
1225
  );
1218
1226
  const n = await this.config.btcWallet.getPublicKeyHex(), s = [], r = [], o = [];
1219
1227
  for (const c of t) {
1228
+ this.validatePayoutOutputs(
1229
+ c.payoutTxHex,
1230
+ c.registeredPayoutScriptPubKey
1231
+ );
1220
1232
  const { depositorPubkey: u } = vt(
1221
1233
  n,
1222
1234
  c.depositorBtcPubkey
@@ -1256,18 +1268,50 @@ class is {
1256
1268
  }
1257
1269
  return a;
1258
1270
  }
1271
+ /**
1272
+ * Validates that the payout transaction's largest output pays to the
1273
+ * registered depositor payout address (scriptPubKey).
1274
+ *
1275
+ * This prevents two attack vectors from a malicious vault provider:
1276
+ * 1. Substituting a completely different payout address
1277
+ * 2. Including a dust output to the correct address while routing
1278
+ * the actual funds to an attacker-controlled address
1279
+ *
1280
+ * @param payoutTxHex - Raw payout transaction hex
1281
+ * @param registeredPayoutScriptPubKey - On-chain registered scriptPubKey (hex, with or without 0x prefix)
1282
+ * @throws Error if scriptPubKey is invalid hex
1283
+ * @throws Error if the largest output does not pay to the registered address
1284
+ */
1285
+ validatePayoutOutputs(t, n) {
1286
+ if (!He(n))
1287
+ throw new Error(
1288
+ "Invalid registeredPayoutScriptPubKey: not valid hex"
1289
+ );
1290
+ const s = S.from(
1291
+ $(n),
1292
+ "hex"
1293
+ ), r = q.fromHex($(t));
1294
+ if (r.outs.length === 0)
1295
+ throw new Error("Payout transaction has no outputs");
1296
+ if (!r.outs.reduce(
1297
+ (i, a) => a.value > i.value ? a : i
1298
+ ).script.equals(s))
1299
+ throw new Error(
1300
+ "Payout transaction does not pay to the registered depositor payout address"
1301
+ );
1302
+ }
1259
1303
  }
1260
- function We(e) {
1304
+ function Ve(e) {
1261
1305
  return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
1262
1306
  }
1263
- function _(e, t = "") {
1307
+ function R(e, t = "") {
1264
1308
  if (!Number.isSafeInteger(e) || e < 0) {
1265
1309
  const n = t && `"${t}" `;
1266
1310
  throw new Error(`${n}expected integer >= 0, got ${e}`);
1267
1311
  }
1268
1312
  }
1269
- function W(e, t, n = "") {
1270
- const s = We(e), r = e == null ? void 0 : e.length, o = t !== void 0;
1313
+ function V(e, t, n = "") {
1314
+ const s = Ve(e), r = e == null ? void 0 : e.length, o = t !== void 0;
1271
1315
  if (!s || o && r !== t) {
1272
1316
  const i = n && `"${n}" `, a = o ? ` of length ${t}` : "", c = s ? `length=${r}` : `type=${typeof e}`;
1273
1317
  throw new Error(i + "expected Uint8Array" + a + ", got " + c);
@@ -1277,60 +1321,60 @@ function W(e, t, n = "") {
1277
1321
  function Nt(e) {
1278
1322
  if (typeof e != "function" || typeof e.create != "function")
1279
1323
  throw new Error("Hash must wrapped by utils.createHasher");
1280
- _(e.outputLen), _(e.blockLen);
1324
+ R(e.outputLen), R(e.blockLen);
1281
1325
  }
1282
- function M(e, t = !0) {
1326
+ function X(e, t = !0) {
1283
1327
  if (e.destroyed)
1284
1328
  throw new Error("Hash instance has been destroyed");
1285
1329
  if (t && e.finished)
1286
1330
  throw new Error("Hash#digest() has already been called");
1287
1331
  }
1288
1332
  function Xt(e, t) {
1289
- W(e, void 0, "digestInto() output");
1333
+ V(e, void 0, "digestInto() output");
1290
1334
  const n = t.outputLen;
1291
1335
  if (e.length < n)
1292
1336
  throw new Error('"digestInto() output" expected to be of length >=' + n);
1293
1337
  }
1294
- function Re(e) {
1338
+ function Ke(e) {
1295
1339
  return new Uint32Array(e.buffer, e.byteOffset, Math.floor(e.byteLength / 4));
1296
1340
  }
1297
1341
  function A(...e) {
1298
1342
  for (let t = 0; t < e.length; t++)
1299
1343
  e[t].fill(0);
1300
1344
  }
1301
- function et(e) {
1345
+ function rt(e) {
1302
1346
  return new DataView(e.buffer, e.byteOffset, e.byteLength);
1303
1347
  }
1304
1348
  function B(e, t) {
1305
1349
  return e << 32 - t | e >>> t;
1306
1350
  }
1307
- function j(e, t) {
1351
+ function Z(e, t) {
1308
1352
  return e << t | e >>> 32 - t >>> 0;
1309
1353
  }
1310
- const Ve = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
1311
- function De(e) {
1354
+ const De = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
1355
+ function Me(e) {
1312
1356
  return e << 24 & 4278190080 | e << 8 & 16711680 | e >>> 8 & 65280 | e >>> 24 & 255;
1313
1357
  }
1314
- function Ke(e) {
1358
+ function Ne(e) {
1315
1359
  for (let t = 0; t < e.length; t++)
1316
- e[t] = De(e[t]);
1360
+ e[t] = Me(e[t]);
1317
1361
  return e;
1318
1362
  }
1319
- const At = Ve ? (e) => e : Ke;
1320
- function Me(e) {
1363
+ const At = De ? (e) => e : Ne;
1364
+ function Xe(e) {
1321
1365
  if (typeof e != "string")
1322
1366
  throw new Error("string expected");
1323
1367
  return new Uint8Array(new TextEncoder().encode(e));
1324
1368
  }
1325
1369
  function Bt(e, t = "") {
1326
- return typeof e == "string" ? Me(e) : W(e, void 0, t);
1370
+ return typeof e == "string" ? Xe(e) : V(e, void 0, t);
1327
1371
  }
1328
- function Ne(e, t) {
1372
+ function Ge(e, t) {
1329
1373
  if (t !== void 0 && {}.toString.call(t) !== "[object Object]")
1330
1374
  throw new Error("options must be object or undefined");
1331
1375
  return Object.assign(e, t);
1332
1376
  }
1333
- function rt(e, t = {}) {
1377
+ function it(e, t = {}) {
1334
1378
  const n = (r, o) => e(o).update(r).digest(), s = e(void 0);
1335
1379
  return n.outputLen = s.outputLen, n.blockLen = s.blockLen, n.create = (r) => e(r), Object.assign(n, t), Object.freeze(n);
1336
1380
  }
@@ -1339,13 +1383,13 @@ const Gt = (e) => ({
1339
1383
  });
1340
1384
  class jt {
1341
1385
  constructor(t, n) {
1342
- f(this, "oHash");
1343
- f(this, "iHash");
1344
- f(this, "blockLen");
1345
- f(this, "outputLen");
1346
- f(this, "finished", !1);
1347
- f(this, "destroyed", !1);
1348
- if (Nt(t), W(n, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function")
1386
+ d(this, "oHash");
1387
+ d(this, "iHash");
1388
+ d(this, "blockLen");
1389
+ d(this, "outputLen");
1390
+ d(this, "finished", !1);
1391
+ d(this, "destroyed", !1);
1392
+ if (Nt(t), V(n, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function")
1349
1393
  throw new Error("Expected instance of class which extends utils.Hash");
1350
1394
  this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
1351
1395
  const s = this.blockLen, r = new Uint8Array(s);
@@ -1358,10 +1402,10 @@ class jt {
1358
1402
  this.oHash.update(r), A(r);
1359
1403
  }
1360
1404
  update(t) {
1361
- return M(this), this.iHash.update(t), this;
1405
+ return X(this), this.iHash.update(t), this;
1362
1406
  }
1363
1407
  digestInto(t) {
1364
- M(this), W(t, this.outputLen, "output"), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
1408
+ X(this), V(t, this.outputLen, "output"), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
1365
1409
  }
1366
1410
  digest() {
1367
1411
  const t = new Uint8Array(this.oHash.outputLen);
@@ -1381,34 +1425,34 @@ class jt {
1381
1425
  }
1382
1426
  const yt = (e, t, n) => new jt(e, t).update(n).digest();
1383
1427
  yt.create = (e, t) => new jt(e, t);
1384
- function Xe(e, t, n) {
1428
+ function je(e, t, n) {
1385
1429
  return e & t ^ ~e & n;
1386
1430
  }
1387
- function Ge(e, t, n) {
1431
+ function qe(e, t, n) {
1388
1432
  return e & t ^ e & n ^ t & n;
1389
1433
  }
1390
1434
  class wt {
1391
1435
  constructor(t, n, s, r) {
1392
- f(this, "blockLen");
1393
- f(this, "outputLen");
1394
- f(this, "padOffset");
1395
- f(this, "isLE");
1436
+ d(this, "blockLen");
1437
+ d(this, "outputLen");
1438
+ d(this, "padOffset");
1439
+ d(this, "isLE");
1396
1440
  // For partial updates less than block size
1397
- f(this, "buffer");
1398
- f(this, "view");
1399
- f(this, "finished", !1);
1400
- f(this, "length", 0);
1401
- f(this, "pos", 0);
1402
- f(this, "destroyed", !1);
1403
- this.blockLen = t, this.outputLen = n, this.padOffset = s, this.isLE = r, this.buffer = new Uint8Array(t), this.view = et(this.buffer);
1441
+ d(this, "buffer");
1442
+ d(this, "view");
1443
+ d(this, "finished", !1);
1444
+ d(this, "length", 0);
1445
+ d(this, "pos", 0);
1446
+ d(this, "destroyed", !1);
1447
+ this.blockLen = t, this.outputLen = n, this.padOffset = s, this.isLE = r, this.buffer = new Uint8Array(t), this.view = rt(this.buffer);
1404
1448
  }
1405
1449
  update(t) {
1406
- M(this), W(t);
1450
+ X(this), V(t);
1407
1451
  const { view: n, buffer: s, blockLen: r } = this, o = t.length;
1408
1452
  for (let i = 0; i < o; ) {
1409
1453
  const a = Math.min(r - this.pos, o - i);
1410
1454
  if (a === r) {
1411
- const c = et(t);
1455
+ const c = rt(t);
1412
1456
  for (; r <= o - i; i += r)
1413
1457
  this.process(c, i);
1414
1458
  continue;
@@ -1418,14 +1462,14 @@ class wt {
1418
1462
  return this.length += t.length, this.roundClean(), this;
1419
1463
  }
1420
1464
  digestInto(t) {
1421
- M(this), Xt(t, this), this.finished = !0;
1465
+ X(this), Xt(t, this), this.finished = !0;
1422
1466
  const { buffer: n, view: s, blockLen: r, isLE: o } = this;
1423
1467
  let { pos: i } = this;
1424
1468
  n[i++] = 128, A(this.buffer.subarray(i)), this.padOffset > r - i && (this.process(s, 0), i = 0);
1425
1469
  for (let l = i; l < r; l++)
1426
1470
  n[l] = 0;
1427
1471
  s.setBigUint64(r - 8, BigInt(this.length * 8), o), this.process(s, 0);
1428
- const a = et(t), c = this.outputLen;
1472
+ const a = rt(t), c = this.outputLen;
1429
1473
  if (c % 4)
1430
1474
  throw new Error("_sha2: outputLen must be aligned to 32bit");
1431
1475
  const u = c / 4, h = this.get();
@@ -1449,7 +1493,7 @@ class wt {
1449
1493
  return this._cloneInto();
1450
1494
  }
1451
1495
  }
1452
- const F = /* @__PURE__ */ Uint32Array.from([
1496
+ const L = /* @__PURE__ */ Uint32Array.from([
1453
1497
  1779033703,
1454
1498
  3144134277,
1455
1499
  1013904242,
@@ -1458,7 +1502,7 @@ const F = /* @__PURE__ */ Uint32Array.from([
1458
1502
  2600822924,
1459
1503
  528734635,
1460
1504
  1541459225
1461
- ]), H = /* @__PURE__ */ Uint32Array.from([
1505
+ ]), k = /* @__PURE__ */ Uint32Array.from([
1462
1506
  1779033703,
1463
1507
  4089235720,
1464
1508
  3144134277,
@@ -1475,7 +1519,7 @@ const F = /* @__PURE__ */ Uint32Array.from([
1475
1519
  4215389547,
1476
1520
  1541459225,
1477
1521
  327033209
1478
- ]), je = /* @__PURE__ */ Uint8Array.from([
1522
+ ]), ze = /* @__PURE__ */ Uint8Array.from([
1479
1523
  7,
1480
1524
  4,
1481
1525
  13,
@@ -1492,11 +1536,11 @@ const F = /* @__PURE__ */ Uint32Array.from([
1492
1536
  14,
1493
1537
  11,
1494
1538
  8
1495
- ]), qt = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)), qe = qt.map((e) => (9 * e + 5) % 16), zt = /* @__PURE__ */ (() => {
1496
- const n = [[qt], [qe]];
1539
+ ]), qt = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)), Ze = qt.map((e) => (9 * e + 5) % 16), zt = /* @__PURE__ */ (() => {
1540
+ const n = [[qt], [Ze]];
1497
1541
  for (let s = 0; s < 4; s++)
1498
1542
  for (let r of n)
1499
- r.push(r[s].map((o) => je[o]));
1543
+ r.push(r[s].map((o) => ze[o]));
1500
1544
  return n;
1501
1545
  })(), Zt = zt[0], Jt = zt[1], Yt = /* @__PURE__ */ [
1502
1546
  [11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
@@ -1504,13 +1548,13 @@ const F = /* @__PURE__ */ Uint32Array.from([
1504
1548
  [13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
1505
1549
  [14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
1506
1550
  [15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
1507
- ].map((e) => Uint8Array.from(e)), ze = /* @__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([
1551
+ ].map((e) => Uint8Array.from(e)), Je = /* @__PURE__ */ Zt.map((e, t) => e.map((n) => Yt[t][n])), Ye = /* @__PURE__ */ Jt.map((e, t) => e.map((n) => Yt[t][n])), Qe = /* @__PURE__ */ Uint32Array.from([
1508
1552
  0,
1509
1553
  1518500249,
1510
1554
  1859775393,
1511
1555
  2400959708,
1512
1556
  2840853838
1513
- ]), Ye = /* @__PURE__ */ Uint32Array.from([
1557
+ ]), tn = /* @__PURE__ */ Uint32Array.from([
1514
1558
  1352829926,
1515
1559
  1548603684,
1516
1560
  1836072691,
@@ -1520,15 +1564,15 @@ const F = /* @__PURE__ */ Uint32Array.from([
1520
1564
  function $t(e, t, n, s) {
1521
1565
  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);
1522
1566
  }
1523
- const q = /* @__PURE__ */ new Uint32Array(16);
1524
- class Qe extends wt {
1567
+ const J = /* @__PURE__ */ new Uint32Array(16);
1568
+ class en extends wt {
1525
1569
  constructor() {
1526
1570
  super(64, 20, 8, !0);
1527
- f(this, "h0", 1732584193);
1528
- f(this, "h1", -271733879);
1529
- f(this, "h2", -1732584194);
1530
- f(this, "h3", 271733878);
1531
- f(this, "h4", -1009589776);
1571
+ d(this, "h0", 1732584193);
1572
+ d(this, "h1", -271733879);
1573
+ d(this, "h2", -1732584194);
1574
+ d(this, "h3", 271733878);
1575
+ d(this, "h4", -1009589776);
1532
1576
  }
1533
1577
  get() {
1534
1578
  const { h0: n, h1: s, h2: r, h3: o, h4: i } = this;
@@ -1538,48 +1582,48 @@ class Qe extends wt {
1538
1582
  this.h0 = n | 0, this.h1 = s | 0, this.h2 = r | 0, this.h3 = o | 0, this.h4 = i | 0;
1539
1583
  }
1540
1584
  process(n, s) {
1541
- for (let p = 0; p < 16; p++, s += 4)
1542
- q[p] = n.getUint32(s, !0);
1543
- 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;
1544
- for (let p = 0; p < 5; p++) {
1545
- const w = 4 - p, x = Je[p], y = Ye[p], m = Zt[p], b = Jt[p], P = ze[p], T = Ze[p];
1546
- for (let v = 0; v < 16; v++) {
1547
- const E = j(r + $t(p, i, c, h) + q[m[v]] + x, P[v]) + d | 0;
1548
- r = d, d = h, h = j(c, 10) | 0, c = i, i = E;
1585
+ for (let b = 0; b < 16; b++, s += 4)
1586
+ J[b] = n.getUint32(s, !0);
1587
+ 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, f = this.h4 | 0, g = f;
1588
+ for (let b = 0; b < 5; b++) {
1589
+ const w = 4 - b, x = Qe[b], y = tn[b], m = Zt[b], p = Jt[b], P = Je[b], v = Ye[b];
1590
+ for (let T = 0; T < 16; T++) {
1591
+ const E = Z(r + $t(b, i, c, h) + J[m[T]] + x, P[T]) + f | 0;
1592
+ r = f, f = h, h = Z(c, 10) | 0, c = i, i = E;
1549
1593
  }
1550
- for (let v = 0; v < 16; v++) {
1551
- const E = j(o + $t(w, a, u, l) + q[b[v]] + y, T[v]) + g | 0;
1552
- o = g, g = l, l = j(u, 10) | 0, u = a, a = E;
1594
+ for (let T = 0; T < 16; T++) {
1595
+ const E = Z(o + $t(w, a, u, l) + J[p[T]] + y, v[T]) + g | 0;
1596
+ o = g, g = l, l = Z(u, 10) | 0, u = a, a = E;
1553
1597
  }
1554
1598
  }
1555
- 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);
1599
+ this.set(this.h1 + c + l | 0, this.h2 + h + g | 0, this.h3 + f + o | 0, this.h4 + r + a | 0, this.h0 + i + u | 0);
1556
1600
  }
1557
1601
  roundClean() {
1558
- A(q);
1602
+ A(J);
1559
1603
  }
1560
1604
  destroy() {
1561
1605
  this.destroyed = !0, A(this.buffer), this.set(0, 0, 0, 0, 0);
1562
1606
  }
1563
1607
  }
1564
- const tn = /* @__PURE__ */ rt(() => new Qe()), z = /* @__PURE__ */ BigInt(2 ** 32 - 1), Ut = /* @__PURE__ */ BigInt(32);
1565
- function en(e, t = !1) {
1566
- return t ? { h: Number(e & z), l: Number(e >> Ut & z) } : { h: Number(e >> Ut & z) | 0, l: Number(e & z) | 0 };
1608
+ const nn = /* @__PURE__ */ it(() => new en()), Y = /* @__PURE__ */ BigInt(2 ** 32 - 1), Ut = /* @__PURE__ */ BigInt(32);
1609
+ function sn(e, t = !1) {
1610
+ return t ? { h: Number(e & Y), l: Number(e >> Ut & Y) } : { h: Number(e >> Ut & Y) | 0, l: Number(e & Y) | 0 };
1567
1611
  }
1568
1612
  function Qt(e, t = !1) {
1569
1613
  const n = e.length;
1570
1614
  let s = new Uint32Array(n), r = new Uint32Array(n);
1571
1615
  for (let o = 0; o < n; o++) {
1572
- const { h: i, l: a } = en(e[o], t);
1616
+ const { h: i, l: a } = sn(e[o], t);
1573
1617
  [s[o], r[o]] = [i, a];
1574
1618
  }
1575
1619
  return [s, r];
1576
1620
  }
1577
- const Ft = (e, t, n) => e >>> n, Lt = (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, 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;
1578
- function $(e, t, n, s) {
1621
+ const Ft = (e, t, n) => e >>> n, Ot = (e, t, n) => e << 32 - n | t >>> n, D = (e, t, n) => e >>> n | t << 32 - n, M = (e, t, n) => e << 32 - n | t >>> n, Q = (e, t, n) => e << 64 - n | t >>> n - 32, tt = (e, t, n) => e >>> n - 32 | t << 64 - n, rn = (e, t, n) => e << n | t >>> 32 - n, on = (e, t, n) => t << n | e >>> 32 - n, an = (e, t, n) => t << n - 32 | e >>> 64 - n, cn = (e, t, n) => e << n - 32 | t >>> 64 - n;
1622
+ function U(e, t, n, s) {
1579
1623
  const r = (t >>> 0) + (s >>> 0);
1580
1624
  return { h: e + n + (r / 2 ** 32 | 0) | 0, l: r | 0 };
1581
1625
  }
1582
- 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([
1626
+ const un = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), ln = (e, t, n, s) => t + n + s + (e / 2 ** 32 | 0) | 0, hn = (e, t, n, s) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0), fn = (e, t, n, s, r) => t + n + s + r + (e / 2 ** 32 | 0) | 0, dn = (e, t, n, s, r) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0) + (r >>> 0), pn = (e, t, n, s, r, o) => t + n + s + r + o + (e / 2 ** 32 | 0) | 0, bn = /* @__PURE__ */ Uint32Array.from([
1583
1627
  1116352408,
1584
1628
  1899447441,
1585
1629
  3049323471,
@@ -1644,8 +1688,8 @@ const an = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), cn = (e, t, n, s) =>
1644
1688
  2756734187,
1645
1689
  3204031479,
1646
1690
  3329325298
1647
- ]), L = /* @__PURE__ */ new Uint32Array(64);
1648
- class pn extends wt {
1691
+ ]), C = /* @__PURE__ */ new Uint32Array(64);
1692
+ class gn extends wt {
1649
1693
  constructor(t) {
1650
1694
  super(64, t, 8, !1);
1651
1695
  }
@@ -1659,38 +1703,38 @@ class pn extends wt {
1659
1703
  }
1660
1704
  process(t, n) {
1661
1705
  for (let l = 0; l < 16; l++, n += 4)
1662
- L[l] = t.getUint32(n, !1);
1706
+ C[l] = t.getUint32(n, !1);
1663
1707
  for (let l = 16; l < 64; l++) {
1664
- const d = L[l - 15], g = L[l - 2], p = B(d, 7) ^ B(d, 18) ^ d >>> 3, w = B(g, 17) ^ B(g, 19) ^ g >>> 10;
1665
- L[l] = w + L[l - 7] + p + L[l - 16] | 0;
1708
+ const f = C[l - 15], g = C[l - 2], b = B(f, 7) ^ B(f, 18) ^ f >>> 3, w = B(g, 17) ^ B(g, 19) ^ g >>> 10;
1709
+ C[l] = w + C[l - 7] + b + C[l - 16] | 0;
1666
1710
  }
1667
1711
  let { A: s, B: r, C: o, D: i, E: a, F: c, G: u, H: h } = this;
1668
1712
  for (let l = 0; l < 64; l++) {
1669
- const d = B(a, 6) ^ B(a, 11) ^ B(a, 25), g = h + d + Xe(a, c, u) + dn[l] + L[l] | 0, w = (B(s, 2) ^ B(s, 13) ^ B(s, 22)) + Ge(s, r, o) | 0;
1713
+ const f = B(a, 6) ^ B(a, 11) ^ B(a, 25), g = h + f + je(a, c, u) + bn[l] + C[l] | 0, w = (B(s, 2) ^ B(s, 13) ^ B(s, 22)) + qe(s, r, o) | 0;
1670
1714
  h = u, u = c, c = a, a = i + g | 0, i = o, o = r, r = s, s = g + w | 0;
1671
1715
  }
1672
1716
  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);
1673
1717
  }
1674
1718
  roundClean() {
1675
- A(L);
1719
+ A(C);
1676
1720
  }
1677
1721
  destroy() {
1678
1722
  this.set(0, 0, 0, 0, 0, 0, 0, 0), A(this.buffer);
1679
1723
  }
1680
1724
  }
1681
- class bn extends pn {
1725
+ class xn extends gn {
1682
1726
  constructor() {
1683
1727
  super(32);
1684
1728
  // We cannot use array here since array allows indexing by variable
1685
1729
  // which means optimizer/compiler cannot use registers.
1686
- f(this, "A", F[0] | 0);
1687
- f(this, "B", F[1] | 0);
1688
- f(this, "C", F[2] | 0);
1689
- f(this, "D", F[3] | 0);
1690
- f(this, "E", F[4] | 0);
1691
- f(this, "F", F[5] | 0);
1692
- f(this, "G", F[6] | 0);
1693
- f(this, "H", F[7] | 0);
1730
+ d(this, "A", L[0] | 0);
1731
+ d(this, "B", L[1] | 0);
1732
+ d(this, "C", L[2] | 0);
1733
+ d(this, "D", L[3] | 0);
1734
+ d(this, "E", L[4] | 0);
1735
+ d(this, "F", L[5] | 0);
1736
+ d(this, "G", L[6] | 0);
1737
+ d(this, "H", L[7] | 0);
1694
1738
  }
1695
1739
  }
1696
1740
  const te = Qt([
@@ -1774,92 +1818,92 @@ const te = Qt([
1774
1818
  "0x597f299cfc657e2a",
1775
1819
  "0x5fcb6fab3ad6faec",
1776
1820
  "0x6c44198c4a475817"
1777
- ].map((e) => BigInt(e))), gn = te[0], xn = te[1], O = /* @__PURE__ */ new Uint32Array(80), C = /* @__PURE__ */ new Uint32Array(80);
1778
- class yn extends wt {
1821
+ ].map((e) => BigInt(e))), yn = te[0], wn = te[1], _ = /* @__PURE__ */ new Uint32Array(80), W = /* @__PURE__ */ new Uint32Array(80);
1822
+ class mn extends wt {
1779
1823
  constructor(t) {
1780
1824
  super(128, t, 16, !1);
1781
1825
  }
1782
1826
  // prettier-ignore
1783
1827
  get() {
1784
- 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: w, Hl: x } = this;
1785
- return [t, n, s, r, o, i, a, c, u, h, l, d, g, p, w, x];
1828
+ const { Ah: t, Al: n, Bh: s, Bl: r, Ch: o, Cl: i, Dh: a, Dl: c, Eh: u, El: h, Fh: l, Fl: f, Gh: g, Gl: b, Hh: w, Hl: x } = this;
1829
+ return [t, n, s, r, o, i, a, c, u, h, l, f, g, b, w, x];
1786
1830
  }
1787
1831
  // prettier-ignore
1788
- set(t, n, s, r, o, i, a, c, u, h, l, d, g, p, w, x) {
1789
- 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 = w | 0, this.Hl = x | 0;
1832
+ set(t, n, s, r, o, i, a, c, u, h, l, f, g, b, w, x) {
1833
+ 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 = f | 0, this.Gh = g | 0, this.Gl = b | 0, this.Hh = w | 0, this.Hl = x | 0;
1790
1834
  }
1791
1835
  process(t, n) {
1792
- for (let b = 0; b < 16; b++, n += 4)
1793
- O[b] = t.getUint32(n), C[b] = t.getUint32(n += 4);
1794
- for (let b = 16; b < 80; b++) {
1795
- const P = O[b - 15] | 0, T = C[b - 15] | 0, v = R(P, T, 1) ^ R(P, T, 8) ^ Ft(P, T, 7), E = V(P, T, 1) ^ V(P, T, 8) ^ Lt(P, T, 7), k = O[b - 2] | 0, I = C[b - 2] | 0, U = R(k, I, 19) ^ Z(k, I, 61) ^ Ft(k, I, 6), ot = V(k, I, 19) ^ J(k, I, 61) ^ Lt(k, I, 6), G = un(E, ot, C[b - 7], C[b - 16]), it = ln(G, v, U, O[b - 7], O[b - 16]);
1796
- O[b] = it | 0, C[b] = G | 0;
1836
+ for (let p = 0; p < 16; p++, n += 4)
1837
+ _[p] = t.getUint32(n), W[p] = t.getUint32(n += 4);
1838
+ for (let p = 16; p < 80; p++) {
1839
+ const P = _[p - 15] | 0, v = W[p - 15] | 0, T = D(P, v, 1) ^ D(P, v, 8) ^ Ft(P, v, 7), E = M(P, v, 1) ^ M(P, v, 8) ^ Ot(P, v, 7), H = _[p - 2] | 0, I = W[p - 2] | 0, F = D(H, I, 19) ^ Q(H, I, 61) ^ Ft(H, I, 6), K = M(H, I, 19) ^ tt(H, I, 61) ^ Ot(H, I, 6), O = hn(E, K, W[p - 7], W[p - 16]), at = fn(O, T, F, _[p - 7], _[p - 16]);
1840
+ _[p] = at | 0, W[p] = O | 0;
1797
1841
  }
1798
- 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: w, Gl: x, Hh: y, Hl: m } = this;
1799
- for (let b = 0; b < 80; b++) {
1800
- const P = R(l, d, 14) ^ R(l, d, 18) ^ Z(l, d, 41), T = V(l, d, 14) ^ V(l, d, 18) ^ J(l, d, 41), v = l & g ^ ~l & w, E = d & p ^ ~d & x, k = hn(m, T, E, xn[b], C[b]), I = fn(k, y, P, v, gn[b], O[b]), U = k | 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, ae = r & i ^ r & c ^ i & c;
1801
- y = w | 0, m = x | 0, w = 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;
1802
- const Pt = an(U, G, ae);
1803
- s = cn(Pt, I, ot, it), r = Pt | 0;
1842
+ let { Ah: s, Al: r, Bh: o, Bl: i, Ch: a, Cl: c, Dh: u, Dl: h, Eh: l, El: f, Fh: g, Fl: b, Gh: w, Gl: x, Hh: y, Hl: m } = this;
1843
+ for (let p = 0; p < 80; p++) {
1844
+ const P = D(l, f, 14) ^ D(l, f, 18) ^ Q(l, f, 41), v = M(l, f, 14) ^ M(l, f, 18) ^ tt(l, f, 41), T = l & g ^ ~l & w, E = f & b ^ ~f & x, H = dn(m, v, E, wn[p], W[p]), I = pn(H, y, P, T, yn[p], _[p]), F = H | 0, K = D(s, r, 28) ^ Q(s, r, 34) ^ Q(s, r, 39), O = M(s, r, 28) ^ tt(s, r, 34) ^ tt(s, r, 39), at = s & o ^ s & a ^ o & a, ae = r & i ^ r & c ^ i & c;
1845
+ y = w | 0, m = x | 0, w = g | 0, x = b | 0, g = l | 0, b = f | 0, { h: l, l: f } = U(u | 0, h | 0, I | 0, F | 0), u = a | 0, h = c | 0, a = o | 0, c = i | 0, o = s | 0, i = r | 0;
1846
+ const Pt = un(F, O, ae);
1847
+ s = ln(Pt, I, K, at), r = Pt | 0;
1804
1848
  }
1805
- ({ 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: w, l: x } = $(this.Gh | 0, this.Gl | 0, w | 0, x | 0), { h: y, l: m } = $(this.Hh | 0, this.Hl | 0, y | 0, m | 0), this.set(s, r, o, i, a, c, u, h, l, d, g, p, w, x, y, m);
1849
+ ({ 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: u, l: h } = U(this.Dh | 0, this.Dl | 0, u | 0, h | 0), { h: l, l: f } = U(this.Eh | 0, this.El | 0, l | 0, f | 0), { h: g, l: b } = U(this.Fh | 0, this.Fl | 0, g | 0, b | 0), { h: w, l: x } = U(this.Gh | 0, this.Gl | 0, w | 0, x | 0), { h: y, l: m } = U(this.Hh | 0, this.Hl | 0, y | 0, m | 0), this.set(s, r, o, i, a, c, u, h, l, f, g, b, w, x, y, m);
1806
1850
  }
1807
1851
  roundClean() {
1808
- A(O, C);
1852
+ A(_, W);
1809
1853
  }
1810
1854
  destroy() {
1811
1855
  A(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1812
1856
  }
1813
1857
  }
1814
- class wn extends yn {
1858
+ class Pn extends mn {
1815
1859
  constructor() {
1816
1860
  super(64);
1817
- f(this, "Ah", H[0] | 0);
1818
- f(this, "Al", H[1] | 0);
1819
- f(this, "Bh", H[2] | 0);
1820
- f(this, "Bl", H[3] | 0);
1821
- f(this, "Ch", H[4] | 0);
1822
- f(this, "Cl", H[5] | 0);
1823
- f(this, "Dh", H[6] | 0);
1824
- f(this, "Dl", H[7] | 0);
1825
- f(this, "Eh", H[8] | 0);
1826
- f(this, "El", H[9] | 0);
1827
- f(this, "Fh", H[10] | 0);
1828
- f(this, "Fl", H[11] | 0);
1829
- f(this, "Gh", H[12] | 0);
1830
- f(this, "Gl", H[13] | 0);
1831
- f(this, "Hh", H[14] | 0);
1832
- f(this, "Hl", H[15] | 0);
1833
- }
1834
- }
1835
- const mn = /* @__PURE__ */ rt(
1836
- () => new bn(),
1861
+ d(this, "Ah", k[0] | 0);
1862
+ d(this, "Al", k[1] | 0);
1863
+ d(this, "Bh", k[2] | 0);
1864
+ d(this, "Bl", k[3] | 0);
1865
+ d(this, "Ch", k[4] | 0);
1866
+ d(this, "Cl", k[5] | 0);
1867
+ d(this, "Dh", k[6] | 0);
1868
+ d(this, "Dl", k[7] | 0);
1869
+ d(this, "Eh", k[8] | 0);
1870
+ d(this, "El", k[9] | 0);
1871
+ d(this, "Fh", k[10] | 0);
1872
+ d(this, "Fl", k[11] | 0);
1873
+ d(this, "Gh", k[12] | 0);
1874
+ d(this, "Gl", k[13] | 0);
1875
+ d(this, "Hh", k[14] | 0);
1876
+ d(this, "Hl", k[15] | 0);
1877
+ }
1878
+ }
1879
+ const Tn = /* @__PURE__ */ it(
1880
+ () => new xn(),
1837
1881
  /* @__PURE__ */ Gt(1)
1838
- ), ee = /* @__PURE__ */ rt(
1839
- () => new wn(),
1882
+ ), ee = /* @__PURE__ */ it(
1883
+ () => new Pn(),
1840
1884
  /* @__PURE__ */ Gt(3)
1841
- ), Pn = BigInt(0), N = BigInt(1), Tn = BigInt(2), vn = BigInt(7), kn = BigInt(256), Hn = BigInt(113), ne = [], se = [], re = [];
1842
- for (let e = 0, t = N, n = 1, s = 0; e < 24; e++) {
1885
+ ), vn = BigInt(0), G = BigInt(1), kn = BigInt(2), Hn = BigInt(7), In = BigInt(256), En = BigInt(113), ne = [], se = [], re = [];
1886
+ for (let e = 0, t = G, n = 1, s = 0; e < 24; e++) {
1843
1887
  [n, s] = [s, (2 * n + 3 * s) % 5], ne.push(2 * (5 * s + n)), se.push((e + 1) * (e + 2) / 2 % 64);
1844
- let r = Pn;
1888
+ let r = vn;
1845
1889
  for (let o = 0; o < 7; o++)
1846
- t = (t << N ^ (t >> vn) * Hn) % kn, t & Tn && (r ^= N << (N << BigInt(o)) - N);
1890
+ t = (t << G ^ (t >> Hn) * En) % In, t & kn && (r ^= G << (G << BigInt(o)) - G);
1847
1891
  re.push(r);
1848
1892
  }
1849
- const oe = Qt(re, !0), In = oe[0], En = oe[1], Ot = (e, t, n) => n > 32 ? rn(e, t, n) : nn(e, t, n), Ct = (e, t, n) => n > 32 ? on(e, t, n) : sn(e, t, n);
1850
- function Sn(e, t = 24) {
1893
+ const oe = Qt(re, !0), Sn = oe[0], An = oe[1], Lt = (e, t, n) => n > 32 ? an(e, t, n) : rn(e, t, n), Ct = (e, t, n) => n > 32 ? cn(e, t, n) : on(e, t, n);
1894
+ function Bn(e, t = 24) {
1851
1895
  const n = new Uint32Array(10);
1852
1896
  for (let s = 24 - t; s < 24; s++) {
1853
1897
  for (let i = 0; i < 10; i++)
1854
1898
  n[i] = e[i] ^ e[i + 10] ^ e[i + 20] ^ e[i + 30] ^ e[i + 40];
1855
1899
  for (let i = 0; i < 10; i += 2) {
1856
- const a = (i + 8) % 10, c = (i + 2) % 10, u = n[c], h = n[c + 1], l = Ot(u, h, 1) ^ n[a], d = Ct(u, h, 1) ^ n[a + 1];
1900
+ const a = (i + 8) % 10, c = (i + 2) % 10, u = n[c], h = n[c + 1], l = Lt(u, h, 1) ^ n[a], f = Ct(u, h, 1) ^ n[a + 1];
1857
1901
  for (let g = 0; g < 50; g += 10)
1858
- e[i + g] ^= l, e[i + g + 1] ^= d;
1902
+ e[i + g] ^= l, e[i + g + 1] ^= f;
1859
1903
  }
1860
1904
  let r = e[2], o = e[3];
1861
1905
  for (let i = 0; i < 24; i++) {
1862
- const a = se[i], c = Ot(r, o, a), u = Ct(r, o, a), h = ne[i];
1906
+ const a = se[i], c = Lt(r, o, a), u = Ct(r, o, a), h = ne[i];
1863
1907
  r = e[h], o = e[h + 1], e[h] = c, e[h + 1] = u;
1864
1908
  }
1865
1909
  for (let i = 0; i < 50; i += 10) {
@@ -1868,36 +1912,36 @@ function Sn(e, t = 24) {
1868
1912
  for (let a = 0; a < 10; a++)
1869
1913
  e[i + a] ^= ~n[(a + 2) % 10] & n[(a + 4) % 10];
1870
1914
  }
1871
- e[0] ^= In[s], e[1] ^= En[s];
1915
+ e[0] ^= Sn[s], e[1] ^= An[s];
1872
1916
  }
1873
1917
  A(n);
1874
1918
  }
1875
1919
  class mt {
1876
1920
  // NOTE: we accept arguments in bytes instead of bits here.
1877
1921
  constructor(t, n, s, r = !1, o = 24) {
1878
- f(this, "state");
1879
- f(this, "pos", 0);
1880
- f(this, "posOut", 0);
1881
- f(this, "finished", !1);
1882
- f(this, "state32");
1883
- f(this, "destroyed", !1);
1884
- f(this, "blockLen");
1885
- f(this, "suffix");
1886
- f(this, "outputLen");
1887
- f(this, "enableXOF", !1);
1888
- f(this, "rounds");
1889
- if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF = r, this.rounds = o, _(s, "outputLen"), !(0 < t && t < 200))
1922
+ d(this, "state");
1923
+ d(this, "pos", 0);
1924
+ d(this, "posOut", 0);
1925
+ d(this, "finished", !1);
1926
+ d(this, "state32");
1927
+ d(this, "destroyed", !1);
1928
+ d(this, "blockLen");
1929
+ d(this, "suffix");
1930
+ d(this, "outputLen");
1931
+ d(this, "enableXOF", !1);
1932
+ d(this, "rounds");
1933
+ if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF = r, this.rounds = o, R(s, "outputLen"), !(0 < t && t < 200))
1890
1934
  throw new Error("only keccak-f1600 function is supported");
1891
- this.state = new Uint8Array(200), this.state32 = Re(this.state);
1935
+ this.state = new Uint8Array(200), this.state32 = Ke(this.state);
1892
1936
  }
1893
1937
  clone() {
1894
1938
  return this._cloneInto();
1895
1939
  }
1896
1940
  keccak() {
1897
- At(this.state32), Sn(this.state32, this.rounds), At(this.state32), this.posOut = 0, this.pos = 0;
1941
+ At(this.state32), Bn(this.state32, this.rounds), At(this.state32), this.posOut = 0, this.pos = 0;
1898
1942
  }
1899
1943
  update(t) {
1900
- M(this), W(t);
1944
+ X(this), V(t);
1901
1945
  const { blockLen: n, state: s } = this, r = t.length;
1902
1946
  for (let o = 0; o < r; ) {
1903
1947
  const i = Math.min(n - this.pos, r - o);
@@ -1915,7 +1959,7 @@ class mt {
1915
1959
  t[s] ^= n, (n & 128) !== 0 && s === r - 1 && this.keccak(), t[r - 1] ^= 128, this.keccak();
1916
1960
  }
1917
1961
  writeInto(t) {
1918
- M(this, !1), W(t), this.finish();
1962
+ X(this, !1), V(t), this.finish();
1919
1963
  const n = this.state, { blockLen: s } = this;
1920
1964
  for (let r = 0, o = t.length; r < o; ) {
1921
1965
  this.posOut >= s && this.keccak();
@@ -1930,7 +1974,7 @@ class mt {
1930
1974
  return this.writeInto(t);
1931
1975
  }
1932
1976
  xof(t) {
1933
- return _(t), this.xofInto(new Uint8Array(t));
1977
+ return R(t), this.xofInto(new Uint8Array(t));
1934
1978
  }
1935
1979
  digestInto(t) {
1936
1980
  if (Xt(t, this), this.finished)
@@ -1948,50 +1992,50 @@ class mt {
1948
1992
  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;
1949
1993
  }
1950
1994
  }
1951
- const An = (e, t, n, s = {}) => rt(() => new mt(t, e, n), s), Bn = /* @__PURE__ */ An(1, 136, 32);
1952
- function $n(e, t, n, s) {
1995
+ const $n = (e, t, n, s = {}) => it(() => new mt(t, e, n), s), Un = /* @__PURE__ */ $n(1, 136, 32);
1996
+ function Fn(e, t, n, s) {
1953
1997
  Nt(e);
1954
- const r = Ne({ dkLen: 32, asyncTick: 10 }, s), { c: o, dkLen: i, asyncTick: a } = r;
1955
- if (_(o, "c"), _(i, "dkLen"), _(a, "asyncTick"), o < 1)
1998
+ const r = Ge({ dkLen: 32, asyncTick: 10 }, s), { c: o, dkLen: i, asyncTick: a } = r;
1999
+ if (R(o, "c"), R(i, "dkLen"), R(a, "asyncTick"), o < 1)
1956
2000
  throw new Error("iterations (c) must be >= 1");
1957
- const c = Bt(t, "password"), u = Bt(n, "salt"), h = new Uint8Array(i), l = yt.create(e, c), d = l._cloneInto().update(u);
1958
- return { c: o, dkLen: i, asyncTick: a, DK: h, PRF: l, PRFSalt: d };
2001
+ const c = Bt(t, "password"), u = Bt(n, "salt"), h = new Uint8Array(i), l = yt.create(e, c), f = l._cloneInto().update(u);
2002
+ return { c: o, dkLen: i, asyncTick: a, DK: h, PRF: l, PRFSalt: f };
1959
2003
  }
1960
- function Un(e, t, n, s, r) {
2004
+ function On(e, t, n, s, r) {
1961
2005
  return e.destroy(), t.destroy(), s && s.destroy(), A(r), n;
1962
2006
  }
1963
- function Fn(e, t, n, s) {
1964
- const { c: r, dkLen: o, DK: i, PRF: a, PRFSalt: c } = $n(e, t, n, s);
2007
+ function Ln(e, t, n, s) {
2008
+ const { c: r, dkLen: o, DK: i, PRF: a, PRFSalt: c } = Fn(e, t, n, s);
1965
2009
  let u;
1966
- const h = new Uint8Array(4), l = et(h), d = new Uint8Array(a.outputLen);
1967
- for (let g = 1, p = 0; p < o; g++, p += a.outputLen) {
1968
- const w = i.subarray(p, p + a.outputLen);
1969
- l.setInt32(0, g, !1), (u = c._cloneInto(u)).update(h).digestInto(d), w.set(d.subarray(0, w.length));
2010
+ const h = new Uint8Array(4), l = rt(h), f = new Uint8Array(a.outputLen);
2011
+ for (let g = 1, b = 0; b < o; g++, b += a.outputLen) {
2012
+ const w = i.subarray(b, b + a.outputLen);
2013
+ l.setInt32(0, g, !1), (u = c._cloneInto(u)).update(h).digestInto(f), w.set(f.subarray(0, w.length));
1970
2014
  for (let x = 1; x < r; x++) {
1971
- a._cloneInto(u).update(d).digestInto(d);
2015
+ a._cloneInto(u).update(f).digestInto(f);
1972
2016
  for (let y = 0; y < w.length; y++)
1973
- w[y] ^= d[y];
2017
+ w[y] ^= f[y];
1974
2018
  }
1975
2019
  }
1976
- return Un(a, c, i, u, d);
2020
+ return On(a, c, i, u, f);
1977
2021
  }
1978
2022
  function ie(e) {
1979
2023
  if (typeof e != "string")
1980
2024
  throw new TypeError("invalid mnemonic type: " + typeof e);
1981
2025
  return e.normalize("NFKD");
1982
2026
  }
1983
- function Ln(e) {
2027
+ function Cn(e) {
1984
2028
  const t = ie(e), n = t.split(" ");
1985
2029
  if (![12, 15, 18, 21, 24].includes(n.length))
1986
2030
  throw new Error("Invalid mnemonic");
1987
2031
  return { nfkd: t, words: n };
1988
2032
  }
1989
- const On = (e) => ie("mnemonic" + e);
1990
- function Cn(e, t = "") {
1991
- return Fn(ee, Ln(e).nfkd, On(t), { c: 2048, dkLen: 64 });
2033
+ const _n = (e) => ie("mnemonic" + e);
2034
+ function Wn(e, t = "") {
2035
+ return Ln(ee, Cn(e).nfkd, _n(t), { c: 2048, dkLen: 64 });
1992
2036
  }
1993
- const _n = 508, _t = 16, Y = 32, Q = 64, Wt = 5, Wn = 4;
1994
- function X(...e) {
2037
+ const Rn = 508, _t = 16, et = 32, nt = 64, Wt = 5, Vn = 4;
2038
+ function j(...e) {
1995
2039
  const t = e.reduce((r, o) => r + o.length, 0), n = new Uint8Array(t);
1996
2040
  let s = 0;
1997
2041
  for (const r of e)
@@ -2002,58 +2046,58 @@ function lt(e) {
2002
2046
  return new TextEncoder().encode(e);
2003
2047
  }
2004
2048
  function ht(e) {
2005
- const t = new Uint8Array(Wn);
2006
- return new DataView(t.buffer).setUint32(0, e.length, !1), X(t, e);
2049
+ const t = new Uint8Array(Vn);
2050
+ return new DataView(t.buffer).setUint32(0, e.length, !1), j(t, e);
2007
2051
  }
2008
2052
  function ft(e, t) {
2009
2053
  return yt(ee, e, t);
2010
2054
  }
2011
2055
  function Rt(e) {
2012
- return tn(mn(e));
2056
+ return nn(Tn(e));
2013
2057
  }
2014
2058
  const gt = (e) => Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
2015
- function Rn(e) {
2016
- const t = Cn(e), n = new Uint8Array(t);
2059
+ function Kn(e) {
2060
+ const t = Wn(e), n = new Uint8Array(t);
2017
2061
  return t.fill(0), n;
2018
2062
  }
2019
- async function Vn(e, t, n, s) {
2020
- if (e.length !== Q)
2063
+ async function Dn(e, t, n, s) {
2064
+ if (e.length !== nt)
2021
2065
  throw new Error(
2022
- `WOTS seed must be ${Q} bytes, got ${e.length}`
2066
+ `WOTS seed must be ${nt} bytes, got ${e.length}`
2023
2067
  );
2024
- t = D(t), n = D(n);
2025
- const r = e.slice(Y, Q), o = e.slice(0, Y), i = [r, o];
2068
+ t = $(t), n = $(n);
2069
+ const r = e.slice(et, nt), o = e.slice(0, et), i = [r, o];
2026
2070
  try {
2027
- const a = X(
2071
+ const a = j(
2028
2072
  ht(lt(t)),
2029
2073
  ht(lt(n)),
2030
2074
  ht(lt(s))
2031
- ), c = X(o, a);
2075
+ ), c = j(o, a);
2032
2076
  i.push(c);
2033
2077
  const u = ft(r, c);
2034
2078
  i.push(u);
2035
- const h = u.slice(0, Y), l = u.slice(Y, Q);
2079
+ const h = u.slice(0, et), l = u.slice(et, nt);
2036
2080
  i.push(h, l);
2037
- const d = [], g = [], p = [], w = [];
2081
+ const f = [], g = [], b = [], w = [];
2038
2082
  let x = !1;
2039
2083
  try {
2040
- for (let y = 0; y < _n; y++) {
2084
+ for (let y = 0; y < Rn; y++) {
2041
2085
  const m = new Uint8Array(Wt);
2042
2086
  m[0] = 0, new DataView(m.buffer).setUint32(1, y, !1);
2043
- const b = new Uint8Array(Wt);
2044
- b[0] = 1, new DataView(b.buffer).setUint32(1, y, !1);
2045
- const P = X(h, m), T = X(h, b), v = ft(l, P), E = ft(l, T);
2087
+ const p = new Uint8Array(Wt);
2088
+ p[0] = 1, new DataView(p.buffer).setUint32(1, y, !1);
2089
+ const P = j(h, m), v = j(h, p), T = ft(l, P), E = ft(l, v);
2046
2090
  try {
2047
- const k = v.slice(0, _t), I = E.slice(0, _t);
2048
- d.push(k), g.push(I), p.push(Rt(k)), w.push(Rt(I));
2091
+ const H = T.slice(0, _t), I = E.slice(0, _t);
2092
+ f.push(H), g.push(I), b.push(Rt(H)), w.push(Rt(I));
2049
2093
  } finally {
2050
- P.fill(0), T.fill(0), v.fill(0), E.fill(0);
2094
+ P.fill(0), v.fill(0), T.fill(0), E.fill(0);
2051
2095
  }
2052
2096
  }
2053
- return x = !0, { falsePreimages: d, truePreimages: g, falseHashes: p, trueHashes: w };
2097
+ return x = !0, { falsePreimages: f, truePreimages: g, falseHashes: b, trueHashes: w };
2054
2098
  } finally {
2055
2099
  if (!x) {
2056
- for (const y of d) y.fill(0);
2100
+ for (const y of f) y.fill(0);
2057
2101
  for (const y of g) y.fill(0);
2058
2102
  }
2059
2103
  }
@@ -2062,13 +2106,13 @@ async function Vn(e, t, n, s) {
2062
2106
  a.fill(0);
2063
2107
  }
2064
2108
  }
2065
- function as(e) {
2109
+ function us(e) {
2066
2110
  return {
2067
2111
  false_list: e.falseHashes.map(gt),
2068
2112
  true_list: e.trueHashes.map(gt)
2069
2113
  };
2070
2114
  }
2071
- function Dn(e) {
2115
+ function Mn(e) {
2072
2116
  if (e.falseHashes.length === 0 || e.trueHashes.length === 0)
2073
2117
  throw new Error(
2074
2118
  "computeWotsPkHash: keypair hash arrays must not be empty"
@@ -2079,20 +2123,20 @@ function Dn(e) {
2079
2123
  s.set(i, r), r += t;
2080
2124
  for (const i of e.trueHashes)
2081
2125
  s.set(i, r), r += t;
2082
- const o = Bn(s);
2126
+ const o = Un(s);
2083
2127
  return `0x${gt(o)}`;
2084
2128
  }
2085
- async function cs(e, t, n, s) {
2086
- const r = Rn(e);
2129
+ async function ls(e, t, n, s) {
2130
+ const r = Kn(e);
2087
2131
  try {
2088
- const o = await Vn(
2132
+ const o = await Dn(
2089
2133
  r,
2090
2134
  t,
2091
2135
  n,
2092
2136
  s
2093
2137
  );
2094
2138
  try {
2095
- return Dn(o);
2139
+ return Mn(o);
2096
2140
  } finally {
2097
2141
  for (const i of o.falsePreimages) i.fill(0);
2098
2142
  for (const i of o.truePreimages) i.fill(0);
@@ -2101,43 +2145,43 @@ async function cs(e, t, n, s) {
2101
2145
  r.fill(0);
2102
2146
  }
2103
2147
  }
2104
- function us(e) {
2148
+ function hs(e) {
2105
2149
  const t = (e instanceof Error ? e.message : typeof e == "string" ? e : "").toLowerCase();
2106
2150
  return t.includes("wots") && t.includes("hash") && t.includes("does not match");
2107
2151
  }
2108
2152
  export {
2109
- Dn as A,
2110
- tt as B,
2111
- K as C,
2112
- cs as D,
2113
- us as E,
2114
- Ue as M,
2115
- os as P,
2116
- qn as a,
2117
- Zn as b,
2153
+ Mn as A,
2154
+ st as B,
2155
+ N as C,
2156
+ ls as D,
2157
+ hs as E,
2158
+ Oe as M,
2159
+ as as P,
2160
+ Zn as a,
2161
+ Yn as b,
2118
2162
  St as c,
2119
- Jn as d,
2120
- Se as e,
2121
- Ae as f,
2122
- zn as g,
2163
+ Qn as d,
2164
+ Be as e,
2165
+ $e as f,
2166
+ Jn as g,
2123
2167
  bt as h,
2124
- is as i,
2125
- es as j,
2126
- Qn as k,
2127
- ts as l,
2128
- ns as m,
2129
- Yn as n,
2130
- Le as o,
2131
- Oe as p,
2132
- Fe as q,
2168
+ cs as i,
2169
+ ss as j,
2170
+ es as k,
2171
+ ns as l,
2172
+ rs as m,
2173
+ ts as n,
2174
+ Ce as o,
2175
+ _e as p,
2176
+ Le as q,
2133
2177
  ct as r,
2134
- Ee as s,
2178
+ Ae as s,
2135
2179
  xt as t,
2136
- ss as u,
2137
- rs as v,
2180
+ os as u,
2181
+ is as v,
2138
2182
  ut as w,
2139
- Rn as x,
2140
- Vn as y,
2141
- as as z
2183
+ Kn as x,
2184
+ Dn as y,
2185
+ us as z
2142
2186
  };
2143
- //# sourceMappingURL=errors-ZoUEvcDE.js.map
2187
+ //# sourceMappingURL=errors-D19BQSaj.js.map