@babylonlabs-io/ts-sdk 0.20.1 → 0.22.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 (51) hide show
  1. package/README.md +14 -6
  2. package/dist/{errors-D_PI__IT.js → errors-CkkL1ztr.js} +338 -328
  3. package/dist/errors-CkkL1ztr.js.map +1 -0
  4. package/dist/errors-D2H46Yut.cjs +2 -0
  5. package/dist/errors-D2H46Yut.cjs.map +1 -0
  6. package/dist/index-BAECy2oz.cjs +2 -0
  7. package/dist/index-BAECy2oz.cjs.map +1 -0
  8. package/dist/{index-CFwoGJNQ.js → index-DLtpqdlu.js} +141 -115
  9. package/dist/index-DLtpqdlu.js.map +1 -0
  10. package/dist/index.cjs +1 -1
  11. package/dist/index.js +124 -117
  12. package/dist/index.js.map +1 -1
  13. package/dist/shared/wallets/index.d.ts +8 -0
  14. package/dist/shared/wallets/index.d.ts.map +1 -1
  15. package/dist/tbv/core/clients/index.cjs +1 -1
  16. package/dist/tbv/core/clients/index.d.ts +3 -2
  17. package/dist/tbv/core/clients/index.d.ts.map +1 -1
  18. package/dist/tbv/core/clients/index.js +16 -15
  19. package/dist/tbv/core/clients/mempool/mempoolApi.d.ts.map +1 -1
  20. package/dist/tbv/core/clients/vault-provider/index.d.ts +1 -1
  21. package/dist/tbv/core/clients/vault-provider/index.d.ts.map +1 -1
  22. package/dist/tbv/core/contracts/errors.d.ts.map +1 -1
  23. package/dist/tbv/core/index.cjs +1 -1
  24. package/dist/tbv/core/index.js +120 -113
  25. package/dist/tbv/core/index.js.map +1 -1
  26. package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
  27. package/dist/tbv/core/managers/index.d.ts +15 -62
  28. package/dist/tbv/core/managers/index.d.ts.map +1 -1
  29. package/dist/tbv/core/services/index.d.ts +2 -4
  30. package/dist/tbv/core/services/index.d.ts.map +1 -1
  31. package/dist/tbv/core/utils/index.cjs +1 -1
  32. package/dist/tbv/core/utils/index.d.ts +2 -7
  33. package/dist/tbv/core/utils/index.d.ts.map +1 -1
  34. package/dist/tbv/core/utils/index.js +37 -31
  35. package/dist/tbv/core/utils/index.js.map +1 -1
  36. package/dist/tbv/core/utils/validation.d.ts +35 -0
  37. package/dist/tbv/core/utils/validation.d.ts.map +1 -0
  38. package/dist/tbv/index.cjs +1 -1
  39. package/dist/tbv/index.js +120 -113
  40. package/dist/tbv/index.js.map +1 -1
  41. package/dist/validation-CxqROCno.js +15 -0
  42. package/dist/validation-CxqROCno.js.map +1 -0
  43. package/dist/validation-u8W7Lp2x.cjs +2 -0
  44. package/dist/validation-u8W7Lp2x.cjs.map +1 -0
  45. package/package.json +1 -1
  46. package/dist/errors-D9EtjJoD.cjs +0 -2
  47. package/dist/errors-D9EtjJoD.cjs.map +0 -1
  48. package/dist/errors-D_PI__IT.js.map +0 -1
  49. package/dist/index-BpXpESWu.cjs +0 -2
  50. package/dist/index-BpXpESWu.cjs.map +0 -1
  51. package/dist/index-CFwoGJNQ.js.map +0 -1
@@ -1,19 +1,20 @@
1
- var qt = Object.defineProperty;
2
- var Gt = (e, t, n) => t in e ? qt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var x = (e, t, n) => Gt(e, typeof t != "symbol" ? t + "" : t, n);
4
- import * as zt from "bitcoinjs-lib";
5
- import { Transaction as Zt, Psbt as mt } from "bitcoinjs-lib";
1
+ var Gt = Object.defineProperty;
2
+ var zt = (e, t, n) => t in e ? Gt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var P = (e, t, n) => zt(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import * as Zt from "bitcoinjs-lib";
5
+ import { Transaction as Jt, Psbt as mt } from "bitcoinjs-lib";
6
6
  import { Buffer as q } from "buffer";
7
- import { createPublicClient as G, http as z, encodeFunctionData as yt, zeroAddress as Jt } from "viem";
8
- import { c as Yt } from "./signing-DeWVBl7m.js";
7
+ import { createPublicClient as G, http as z, encodeFunctionData as yt, zeroAddress as Yt } from "viem";
8
+ import { c as Qt } from "./signing-DeWVBl7m.js";
9
9
  import { deriveVaultId as wt } from "@babylonlabs-io/babylon-tbv-rust-wasm";
10
- import { b as Qt, a as te, d as ee, e as ne, f as se } from "./challengeAssert-D1lpvuMv.js";
11
- import { s as E, g as bt, e as H, i as oe } from "./bitcoin-nOOgeRyl.js";
12
- import { b as re, f as Z, i as ie } from "./psbtInputFields-r1ss6WLU.js";
13
- import { p as ae, f as ce } from "./fundPeginTransaction-BLYXxLBv.js";
14
- import { p as le, f as he } from "./index-CFwoGJNQ.js";
10
+ import { b as te, a as ee, d as ne, e as se, f as oe } from "./challengeAssert-D1lpvuMv.js";
11
+ import { s as E, g as bt, e as H, i as re } from "./bitcoin-nOOgeRyl.js";
12
+ import { M as xt } from "./validation-CxqROCno.js";
13
+ import { b as ie, f as Z, i as ae } from "./psbtInputFields-r1ss6WLU.js";
14
+ import { p as ce, f as le } from "./fundPeginTransaction-BLYXxLBv.js";
15
+ import { p as he, f as ue } from "./index-DLtpqdlu.js";
15
16
  import { B as $ } from "./types-DWjaqVfP.js";
16
- import { n as St, o as K, q as S, r as M, t as Bt, H as ue, u as U, x as fe, y as L, z as de, A as xt, D as ge, E as pe, F as me, G as ye, I as we, J as be, K as xe, L as Pt, M as ut, N as Ct } from "./buildAndBroadcastRefund-DnTQkCgG.js";
17
+ import { n as Bt, o as K, q as S, r as M, t as Ct, H as fe, u as U, x as de, y as L, z as ge, A as Pt, D as pe, E as me, F as ye, G as we, I as be, J as xe, K as Pe, L as kt, M as ut, N as At } from "./buildAndBroadcastRefund-DnTQkCgG.js";
17
18
  const B = {
18
19
  // VaultAlreadyExists()
19
20
  "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.",
@@ -42,7 +43,11 @@ const B = {
42
43
  // VaultProviderNotRegistered()
43
44
  "0x5a3c6b3e": "Vault provider not registered: The selected vault provider is not registered.",
44
45
  // InvalidPeginFee(uint256,uint256)
45
- "0x979f4518": "Invalid pegin fee: The ETH fee sent does not match the required amount. This may indicate a fee rate change during the transaction."
46
+ "0x979f4518": "Invalid pegin fee: The ETH fee sent does not match the required amount. This may indicate a fee rate change during the transaction.",
47
+ // PrePeginOutputAlreadyUsed()
48
+ "0x5fad9694": "This pre-pegin output has already been used to activate another vault.",
49
+ // PeginTransactionAlreadyUsed()
50
+ "0x7ed061c9": "This pegin transaction has already been used to activate another vault."
46
51
  };
47
52
  function ft(e) {
48
53
  if (!e || typeof e != "object") return;
@@ -63,14 +68,14 @@ function ft(e) {
63
68
  if (i)
64
69
  return i[1];
65
70
  }
66
- function wn(e) {
71
+ function xn(e) {
67
72
  const t = ft(e);
68
73
  if (t) {
69
74
  const n = t.substring(0, 10);
70
75
  return B[t] ?? B[n];
71
76
  }
72
77
  }
73
- function bn(e) {
78
+ function Pn(e) {
74
79
  const t = ft(e);
75
80
  if (t === void 0) return !1;
76
81
  const n = t.substring(0, 10);
@@ -98,25 +103,25 @@ function _(e) {
98
103
  }
99
104
  throw e instanceof Error ? (console.error("[Contract Error] Unhandled error:", e.message), e) : new Error(`Contract call failed: ${String(e)}`);
100
105
  }
101
- const Pe = 0;
102
- function ke(e, t, n, s) {
106
+ const ke = 0;
107
+ function Te(e, t, n, s) {
103
108
  const o = n == null ? void 0 : n[`${e}:${t}`];
104
109
  return o ? Promise.resolve({
105
110
  txid: e,
106
111
  vout: t,
107
112
  value: o.value,
108
113
  scriptPubKey: o.scriptPubKey
109
- }) : he(e, t, s);
114
+ }) : ue(e, t, s);
110
115
  }
111
- const kt = 12e4;
112
- class xn {
116
+ const Tt = 12e4;
117
+ class kn {
113
118
  /**
114
119
  * Creates a new PeginManager instance.
115
120
  *
116
121
  * @param config - Manager configuration including wallets and contract addresses
117
122
  */
118
123
  constructor(t) {
119
- x(this, "config");
124
+ P(this, "config");
120
125
  this.config = t;
121
126
  }
122
127
  /**
@@ -160,65 +165,65 @@ class xn {
160
165
  councilQuorum: t.councilQuorum,
161
166
  councilSize: t.councilSize,
162
167
  network: this.config.btcNetwork
163
- }, u = await Qt(d), h = re(
168
+ }, u = await te(d), l = ie(
164
169
  [...t.availableUTXOs],
165
170
  u.totalOutputValue,
166
171
  t.mempoolFeeRate,
167
- ae(u.htlcValues.length)
168
- ), m = bt(this.config.btcNetwork), l = ce({
172
+ ce(u.htlcValues.length)
173
+ ), y = bt(this.config.btcNetwork), c = le({
169
174
  unfundedTxHex: u.psbtHex,
170
- selectedUTXOs: h.selectedUTXOs,
175
+ selectedUTXOs: l.selectedUTXOs,
171
176
  changeAddress: t.changeAddress,
172
- changeAmount: h.changeAmount,
173
- network: m
174
- }), y = E(Z(l)), p = [], w = [], P = [];
175
- for (let g = 0; g < t.hashlocks.length; g++) {
176
- const b = await te({
177
+ changeAmount: l.changeAmount,
178
+ network: y
179
+ }), m = E(Z(c)), g = [], b = [], x = [];
180
+ for (let h = 0; h < t.hashlocks.length; h++) {
181
+ const w = await ee({
177
182
  prePeginParams: d,
178
183
  timelockPegin: t.timelockPegin,
179
- fundedPrePeginTxHex: l,
180
- htlcVout: g
181
- }), T = await ee({
182
- peginTxHex: b.txHex,
183
- fundedPrePeginTxHex: l,
184
+ fundedPrePeginTxHex: c,
185
+ htlcVout: h
186
+ }), T = await ne({
187
+ peginTxHex: w.txHex,
188
+ fundedPrePeginTxHex: c,
184
189
  depositorPubkey: s,
185
190
  vaultProviderPubkey: o,
186
191
  vaultKeeperPubkeys: r,
187
192
  universalChallengerPubkeys: i,
188
- hashlock: t.hashlocks[g],
193
+ hashlock: t.hashlocks[h],
189
194
  timelockRefund: t.timelockRefund,
190
195
  network: this.config.btcNetwork
191
196
  });
192
- p.push(b), w.push(T.psbtHex), P.push(
193
- Yt(n, 1)
197
+ g.push(w), b.push(T.psbtHex), x.push(
198
+ Qt(n, 1)
194
199
  );
195
200
  }
196
201
  const f = await this.signPsbtsWithFallback(
197
- w,
198
- P
199
- ), c = [];
200
- for (let g = 0; g < f.length; g++) {
201
- const b = ne(
202
- f[g],
202
+ b,
203
+ x
204
+ ), p = [];
205
+ for (let h = 0; h < f.length; h++) {
206
+ const w = se(
207
+ f[h],
203
208
  s
204
- ), T = se(f[g]);
205
- c.push({
206
- htlcVout: g,
207
- htlcValue: u.htlcValues[g],
209
+ ), T = oe(f[h]);
210
+ p.push({
211
+ htlcVout: h,
212
+ htlcValue: u.htlcValues[h],
208
213
  peginTxHex: T,
209
- peginTxid: p[g].txid,
210
- peginInputSignature: b,
211
- vaultScriptPubKey: p[g].vaultScriptPubKey
214
+ peginTxid: g[h].txid,
215
+ peginInputSignature: w,
216
+ vaultScriptPubKey: g[h].vaultScriptPubKey
212
217
  });
213
218
  }
214
219
  return {
215
- fundedPrePeginTxHex: l,
216
- prePeginTxid: y,
220
+ fundedPrePeginTxHex: c,
221
+ prePeginTxid: m,
217
222
  unsignedPrePeginTxHex: u.psbtHex,
218
- perVault: c,
219
- selectedUTXOs: h.selectedUTXOs,
220
- fee: h.fee,
221
- changeAmount: h.changeAmount
223
+ perVault: p,
224
+ selectedUTXOs: l.selectedUTXOs,
225
+ fee: l.fee,
226
+ changeAmount: l.changeAmount
222
227
  };
223
228
  }
224
229
  /**
@@ -266,7 +271,7 @@ class xn {
266
271
  * @throws Error if signing or broadcasting fails
267
272
  */
268
273
  async signAndBroadcast(t) {
269
- const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, o = n.startsWith("0x") ? n.slice(2) : n, r = Zt.fromHex(o);
274
+ const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, o = n.startsWith("0x") ? n.slice(2) : n, r = Jt.fromHex(o);
270
275
  if (r.ins.length === 0)
271
276
  throw new Error("Transaction has no inputs");
272
277
  const i = new mt();
@@ -281,55 +286,60 @@ class xn {
281
286
  throw new Error(
282
287
  `Invalid depositorBtcPubkey length: expected 32 bytes, got ${d.length}`
283
288
  );
284
- const u = this.config.mempoolApiUrl, h = r.ins.map((c) => {
285
- const g = q.from(c.hash).reverse().toString("hex"), b = c.index;
286
- return ke(g, b, t.localPrevouts, u).then(
287
- (T) => ({ input: c, utxoData: T, txid: g, vout: b })
289
+ const u = this.config.mempoolApiUrl, l = r.ins.map((h) => {
290
+ const w = q.from(h.hash).reverse().toString("hex"), T = h.index;
291
+ return Te(w, T, t.localPrevouts, u).then(
292
+ (k) => ({ input: h, utxoData: k, txid: w, vout: T })
288
293
  );
289
- }), m = await Promise.all(h), l = m.reduce(
290
- (c, g) => c + BigInt(g.utxoData.value),
294
+ }), y = await Promise.all(l), c = y.reduce(
295
+ (h, w) => h + BigInt(w.utxoData.value),
291
296
  0n
292
- ), y = r.outs.reduce(
293
- (c, g) => c + BigInt(g.value),
297
+ ), m = r.outs.reduce(
298
+ (h, w) => h + BigInt(w.value),
294
299
  0n
295
300
  );
296
- if (l < y)
301
+ if (c < m)
302
+ throw new Error(
303
+ `UTXO value mismatch: total input value (${c} sat) is less than total output value (${m} sat). This may indicate the mempool API returned manipulated UTXO data.`
304
+ );
305
+ const g = c - m;
306
+ if (g > xt)
297
307
  throw new Error(
298
- `UTXO value mismatch: total input value (${l} sat) is less than total output value (${y} sat). This may indicate the mempool API returned manipulated UTXO data.`
308
+ `Implied transaction fee (${g} sat) exceeds maximum reasonable fee (${xt} sat). This may indicate manipulated UTXO data.`
299
309
  );
300
- for (const { input: c, utxoData: g, txid: b, vout: T } of m) {
301
- const k = ie(
310
+ for (const { input: h, utxoData: w, txid: T, vout: k } of y) {
311
+ const v = ae(
302
312
  {
303
- value: g.value,
304
- scriptPubKey: g.scriptPubKey
313
+ value: w.value,
314
+ scriptPubKey: w.scriptPubKey
305
315
  },
306
316
  d
307
317
  );
308
318
  i.addInput({
309
- hash: c.hash,
310
- index: c.index,
311
- sequence: c.sequence,
312
- ...k
319
+ hash: h.hash,
320
+ index: h.index,
321
+ sequence: h.sequence,
322
+ ...v
313
323
  });
314
324
  }
315
- for (const c of r.outs)
325
+ for (const h of r.outs)
316
326
  i.addOutput({
317
- script: c.script,
318
- value: c.value
327
+ script: h.script,
328
+ value: h.value
319
329
  });
320
- const p = await this.config.btcWallet.signPsbt(i.toHex()), w = mt.fromHex(p);
330
+ const b = await this.config.btcWallet.signPsbt(i.toHex()), x = mt.fromHex(b);
321
331
  try {
322
- w.finalizeAllInputs();
323
- } catch (c) {
324
- if (!w.data.inputs.every(
325
- (b) => b.finalScriptWitness || b.finalScriptSig
332
+ x.finalizeAllInputs();
333
+ } catch (h) {
334
+ if (!x.data.inputs.every(
335
+ (T) => T.finalScriptWitness || T.finalScriptSig
326
336
  ))
327
337
  throw new Error(
328
- `PSBT finalization failed and wallet did not auto-finalize: ${c}`
338
+ `PSBT finalization failed and wallet did not auto-finalize: ${h}`
329
339
  );
330
340
  }
331
- const P = w.extractTransaction().toHex();
332
- return await le(P, u);
341
+ const f = x.extractTransaction().toHex();
342
+ return await he(f, u);
333
343
  }
334
344
  /**
335
345
  * Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
@@ -358,25 +368,25 @@ class xn {
358
368
  htlcVout: a,
359
369
  onPopSigned: d,
360
370
  depositorPayoutBtcAddress: u,
361
- depositorWotsPkHash: h,
362
- preSignedBtcPopSignature: m
371
+ depositorWotsPkHash: l,
372
+ preSignedBtcPopSignature: y
363
373
  } = t;
364
374
  if (!this.config.ethWallet.account)
365
375
  throw new Error("Ethereum wallet account not found");
366
- const l = this.config.ethWallet.account.address, y = await this.resolvePopSignature(
367
- l,
368
- m
376
+ const c = this.config.ethWallet.account.address, m = await this.resolvePopSignature(
377
+ c,
378
+ y
369
379
  );
370
380
  d && await d();
371
- const p = H(n), w = H(s), P = H(o), f = await this.resolvePayoutScriptPubKey(
381
+ const g = H(n), b = H(s), x = H(o), f = await this.resolvePayoutScriptPubKey(
372
382
  u
373
- ), c = Z(P), g = await wt(
374
- E(c),
375
- E(l)
376
- ), b = H(g);
377
- if (await this.checkVaultExists(b))
383
+ ), p = Z(x), h = await wt(
384
+ E(p),
385
+ E(c)
386
+ ), w = H(h);
387
+ if (await this.checkVaultExists(w))
378
388
  throw new Error(
379
- `Vault already exists (ID: ${b}, peginTxHash: ${c}). 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.`
389
+ `Vault already exists (ID: ${w}, peginTxHash: ${p}). 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.`
380
390
  );
381
391
  const k = G({
382
392
  chain: this.config.ethChain,
@@ -399,16 +409,16 @@ class xn {
399
409
  abi: $,
400
410
  functionName: "submitPeginRequest",
401
411
  args: [
402
- l,
403
- p,
404
- y,
405
- w,
406
- P,
412
+ c,
413
+ g,
414
+ m,
415
+ b,
416
+ x,
407
417
  r,
408
418
  i,
409
419
  a,
410
420
  f,
411
- h
421
+ l
412
422
  ]
413
423
  });
414
424
  let A;
@@ -437,7 +447,7 @@ class xn {
437
447
  }
438
448
  const pt = await k.waitForTransactionReceipt({
439
449
  hash: X,
440
- timeout: kt
450
+ timeout: Tt
441
451
  });
442
452
  return pt.status === "reverted" && _(
443
453
  new Error(
@@ -445,9 +455,9 @@ class xn {
445
455
  )
446
456
  ), {
447
457
  ethTxHash: pt.transactionHash,
448
- vaultId: b,
449
- peginTxHash: c,
450
- btcPopSignature: y
458
+ vaultId: w,
459
+ peginTxHash: p,
460
+ btcPopSignature: m
451
461
  };
452
462
  }
453
463
  /**
@@ -472,31 +482,31 @@ class xn {
472
482
  );
473
483
  r && await r();
474
484
  const d = [];
475
- for (const c of s)
485
+ for (const p of s)
476
486
  d.push(
477
- await this.resolvePayoutScriptPubKey(c.depositorPayoutBtcAddress)
487
+ await this.resolvePayoutScriptPubKey(p.depositorPayoutBtcAddress)
478
488
  );
479
489
  const u = [];
480
- for (const c of s) {
481
- const g = H(
482
- c.depositorSignedPeginTx
483
- ), b = Z(g), T = await wt(
484
- E(b),
490
+ for (const p of s) {
491
+ const h = H(
492
+ p.depositorSignedPeginTx
493
+ ), w = Z(h), T = await wt(
494
+ E(w),
485
495
  E(i)
486
496
  ), k = H(T);
487
497
  if (await this.checkVaultExists(k))
488
498
  throw new Error(
489
- `Vault already exists (ID: ${k}, peginTxHash: ${b}). To create a new vault, use different UTXOs or a different amount.`
499
+ `Vault already exists (ID: ${k}, peginTxHash: ${w}). To create a new vault, use different UTXOs or a different amount.`
490
500
  );
491
- u.push({ vaultId: k, peginTxHash: b });
501
+ u.push({ vaultId: k, peginTxHash: w });
492
502
  }
493
- const h = G({
503
+ const l = G({
494
504
  chain: this.config.ethChain,
495
505
  transport: z()
496
506
  });
497
- let m;
507
+ let y;
498
508
  try {
499
- m = await h.readContract({
509
+ y = await l.readContract({
500
510
  address: this.config.vaultContracts.btcVaultRegistry,
501
511
  abi: $,
502
512
  functionName: "getPegInFee",
@@ -507,54 +517,54 @@ class xn {
507
517
  "Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
508
518
  );
509
519
  }
510
- const l = m * BigInt(s.length), y = s.map((c, g) => ({
511
- depositorBtcPubKey: H(c.depositorBtcPubkey),
520
+ const c = y * BigInt(s.length), m = s.map((p, h) => ({
521
+ depositorBtcPubKey: H(p.depositorBtcPubkey),
512
522
  btcPopSignature: a,
513
- unsignedPrePeginTx: H(c.unsignedPrePeginTx),
523
+ unsignedPrePeginTx: H(p.unsignedPrePeginTx),
514
524
  depositorSignedPeginTx: H(
515
- c.depositorSignedPeginTx
525
+ p.depositorSignedPeginTx
516
526
  ),
517
- hashlock: c.hashlock,
518
- htlcVout: c.htlcVout,
519
- referralCode: Pe,
520
- depositorPayoutBtcAddress: d[g],
521
- depositorWotsPkHash: c.depositorWotsPkHash
522
- })), p = yt({
527
+ hashlock: p.hashlock,
528
+ htlcVout: p.htlcVout,
529
+ referralCode: ke,
530
+ depositorPayoutBtcAddress: d[h],
531
+ depositorWotsPkHash: p.depositorWotsPkHash
532
+ })), g = yt({
523
533
  abi: $,
524
534
  functionName: "submitPeginRequestBatch",
525
- args: [i, n, y]
535
+ args: [i, n, m]
526
536
  });
527
- let w;
537
+ let b;
528
538
  try {
529
- w = await h.estimateGas({
539
+ b = await l.estimateGas({
530
540
  to: this.config.vaultContracts.btcVaultRegistry,
531
- data: p,
532
- value: l,
541
+ data: g,
542
+ value: c,
533
543
  account: this.config.ethWallet.account.address
534
544
  });
535
- } catch (c) {
536
- _(c);
545
+ } catch (p) {
546
+ _(p);
537
547
  }
538
- let P;
548
+ let x;
539
549
  try {
540
- P = await this.config.ethWallet.sendTransaction({
550
+ x = await this.config.ethWallet.sendTransaction({
541
551
  to: this.config.vaultContracts.btcVaultRegistry,
542
- data: p,
543
- value: l,
552
+ data: g,
553
+ value: c,
544
554
  account: this.config.ethWallet.account,
545
555
  chain: this.config.ethChain,
546
- gas: w
556
+ gas: b
547
557
  });
548
- } catch (c) {
549
- _(c);
558
+ } catch (p) {
559
+ _(p);
550
560
  }
551
- const f = await h.waitForTransactionReceipt({
552
- hash: P,
553
- timeout: kt
561
+ const f = await l.waitForTransactionReceipt({
562
+ hash: x,
563
+ timeout: Tt
554
564
  });
555
565
  return f.status === "reverted" && _(
556
566
  new Error(
557
- `Batch transaction reverted. Hash: ${P}. Check the transaction on block explorer for details.`
567
+ `Batch transaction reverted. Hash: ${x}. Check the transaction on block explorer for details.`
558
568
  )
559
569
  ), {
560
570
  ethTxHash: f.transactionHash,
@@ -578,7 +588,7 @@ class xn {
578
588
  abi: $,
579
589
  functionName: "getBtcVaultBasicInfo",
580
590
  args: [t]
581
- }))[0] !== Jt;
591
+ }))[0] !== Yt;
582
592
  } catch {
583
593
  return !1;
584
594
  }
@@ -597,7 +607,7 @@ class xn {
597
607
  else {
598
608
  n = await this.config.btcWallet.getAddress();
599
609
  const o = await this.config.btcWallet.getPublicKeyHex();
600
- if (!oe(
610
+ if (!re(
601
611
  n,
602
612
  o,
603
613
  this.config.btcNetwork
@@ -608,7 +618,7 @@ class xn {
608
618
  }
609
619
  const s = bt(this.config.btcNetwork);
610
620
  try {
611
- return `0x${zt.address.toOutputScript(n, s).toString("hex")}`;
621
+ return `0x${Zt.address.toOutputScript(n, s).toString("hex")}`;
612
622
  } catch {
613
623
  throw new Error(
614
624
  `Invalid BTC payout address: "${n}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`
@@ -647,15 +657,15 @@ class xn {
647
657
  return this.config.vaultContracts.btcVaultRegistry;
648
658
  }
649
659
  }
650
- class At {
660
+ class $t {
651
661
  constructor(t, n) {
652
- x(this, "oHash");
653
- x(this, "iHash");
654
- x(this, "blockLen");
655
- x(this, "outputLen");
656
- x(this, "finished", !1);
657
- x(this, "destroyed", !1);
658
- if (St(t), K(n, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function")
662
+ P(this, "oHash");
663
+ P(this, "iHash");
664
+ P(this, "blockLen");
665
+ P(this, "outputLen");
666
+ P(this, "finished", !1);
667
+ P(this, "destroyed", !1);
668
+ if (Bt(t), K(n, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function")
659
669
  throw new Error("Expected instance of class which extends utils.Hash");
660
670
  this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
661
671
  const s = this.blockLen, o = new Uint8Array(s);
@@ -689,9 +699,9 @@ class At {
689
699
  this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
690
700
  }
691
701
  }
692
- const N = (e, t, n) => new At(e, t).update(n).digest();
693
- N.create = (e, t) => new At(e, t);
694
- const Te = /* @__PURE__ */ Uint8Array.from([
702
+ const N = (e, t, n) => new $t(e, t).update(n).digest();
703
+ N.create = (e, t) => new $t(e, t);
704
+ const ve = /* @__PURE__ */ Uint8Array.from([
695
705
  7,
696
706
  4,
697
707
  13,
@@ -708,43 +718,43 @@ const Te = /* @__PURE__ */ Uint8Array.from([
708
718
  14,
709
719
  11,
710
720
  8
711
- ]), $t = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)), Ie = $t.map((e) => (9 * e + 5) % 16), Ot = /* @__PURE__ */ (() => {
712
- const n = [[$t], [Ie]];
721
+ ]), Ot = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)), Ie = Ot.map((e) => (9 * e + 5) % 16), Rt = /* @__PURE__ */ (() => {
722
+ const n = [[Ot], [Ie]];
713
723
  for (let s = 0; s < 4; s++)
714
724
  for (let o of n)
715
- o.push(o[s].map((r) => Te[r]));
725
+ o.push(o[s].map((r) => ve[r]));
716
726
  return n;
717
- })(), Rt = Ot[0], Lt = Ot[1], Ut = /* @__PURE__ */ [
727
+ })(), Lt = Rt[0], Ut = Rt[1], Wt = /* @__PURE__ */ [
718
728
  [11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
719
729
  [12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
720
730
  [13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
721
731
  [14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
722
732
  [15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
723
- ].map((e) => Uint8Array.from(e)), ve = /* @__PURE__ */ Rt.map((e, t) => e.map((n) => Ut[t][n])), Ee = /* @__PURE__ */ Lt.map((e, t) => e.map((n) => Ut[t][n])), He = /* @__PURE__ */ Uint32Array.from([
733
+ ].map((e) => Uint8Array.from(e)), Ee = /* @__PURE__ */ Lt.map((e, t) => e.map((n) => Wt[t][n])), He = /* @__PURE__ */ Ut.map((e, t) => e.map((n) => Wt[t][n])), _e = /* @__PURE__ */ Uint32Array.from([
724
734
  0,
725
735
  1518500249,
726
736
  1859775393,
727
737
  2400959708,
728
738
  2840853838
729
- ]), _e = /* @__PURE__ */ Uint32Array.from([
739
+ ]), Se = /* @__PURE__ */ Uint32Array.from([
730
740
  1352829926,
731
741
  1548603684,
732
742
  1836072691,
733
743
  2053994217,
734
744
  0
735
745
  ]);
736
- function Tt(e, t, n, s) {
746
+ function vt(e, t, n, s) {
737
747
  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);
738
748
  }
739
749
  const W = /* @__PURE__ */ new Uint32Array(16);
740
- class Se extends ue {
750
+ class Be extends fe {
741
751
  constructor() {
742
752
  super(64, 20, 8, !0);
743
- x(this, "h0", 1732584193);
744
- x(this, "h1", -271733879);
745
- x(this, "h2", -1732584194);
746
- x(this, "h3", 271733878);
747
- x(this, "h4", -1009589776);
753
+ P(this, "h0", 1732584193);
754
+ P(this, "h1", -271733879);
755
+ P(this, "h2", -1732584194);
756
+ P(this, "h3", 271733878);
757
+ P(this, "h4", -1009589776);
748
758
  }
749
759
  get() {
750
760
  const { h0: n, h1: s, h2: o, h3: r, h4: i } = this;
@@ -754,21 +764,21 @@ class Se extends ue {
754
764
  this.h0 = n | 0, this.h1 = s | 0, this.h2 = o | 0, this.h3 = r | 0, this.h4 = i | 0;
755
765
  }
756
766
  process(n, s) {
757
- for (let p = 0; p < 16; p++, s += 4)
758
- W[p] = n.getUint32(s, !0);
759
- let o = this.h0 | 0, r = o, i = this.h1 | 0, a = i, d = this.h2 | 0, u = d, h = this.h3 | 0, m = h, l = this.h4 | 0, y = l;
760
- for (let p = 0; p < 5; p++) {
761
- const w = 4 - p, P = He[p], f = _e[p], c = Rt[p], g = Lt[p], b = ve[p], T = Ee[p];
767
+ for (let g = 0; g < 16; g++, s += 4)
768
+ W[g] = n.getUint32(s, !0);
769
+ let o = this.h0 | 0, r = o, i = this.h1 | 0, a = i, d = this.h2 | 0, u = d, l = this.h3 | 0, y = l, c = this.h4 | 0, m = c;
770
+ for (let g = 0; g < 5; g++) {
771
+ const b = 4 - g, x = _e[g], f = Se[g], p = Lt[g], h = Ut[g], w = Ee[g], T = He[g];
762
772
  for (let k = 0; k < 16; k++) {
763
- const v = U(o + Tt(p, i, d, h) + W[c[k]] + P, b[k]) + l | 0;
764
- o = l, l = h, h = U(d, 10) | 0, d = i, i = v;
773
+ const v = U(o + vt(g, i, d, l) + W[p[k]] + x, w[k]) + c | 0;
774
+ o = c, c = l, l = U(d, 10) | 0, d = i, i = v;
765
775
  }
766
776
  for (let k = 0; k < 16; k++) {
767
- const v = U(r + Tt(w, a, u, m) + W[g[k]] + f, T[k]) + y | 0;
768
- r = y, y = m, m = U(u, 10) | 0, u = a, a = v;
777
+ const v = U(r + vt(b, a, u, y) + W[h[k]] + f, T[k]) + m | 0;
778
+ r = m, m = y, y = U(u, 10) | 0, u = a, a = v;
769
779
  }
770
780
  }
771
- this.set(this.h1 + d + m | 0, this.h2 + h + y | 0, this.h3 + l + r | 0, this.h4 + o + a | 0, this.h0 + i + u | 0);
781
+ this.set(this.h1 + d + y | 0, this.h2 + l + m | 0, this.h3 + c + r | 0, this.h4 + o + a | 0, this.h0 + i + u | 0);
772
782
  }
773
783
  roundClean() {
774
784
  S(W);
@@ -777,29 +787,29 @@ class Se extends ue {
777
787
  this.destroyed = !0, S(this.buffer), this.set(0, 0, 0, 0, 0);
778
788
  }
779
789
  }
780
- const Wt = /* @__PURE__ */ Bt(() => new Se()), Be = BigInt(0), O = BigInt(1), Ce = BigInt(2), Ae = BigInt(7), $e = BigInt(256), Oe = BigInt(113), Vt = [], Ft = [], Dt = [];
790
+ const Ft = /* @__PURE__ */ Ct(() => new Be()), Ce = BigInt(0), O = BigInt(1), Ae = BigInt(2), $e = BigInt(7), Oe = BigInt(256), Re = BigInt(113), Vt = [], Dt = [], Kt = [];
781
791
  for (let e = 0, t = O, n = 1, s = 0; e < 24; e++) {
782
- [n, s] = [s, (2 * n + 3 * s) % 5], Vt.push(2 * (5 * s + n)), Ft.push((e + 1) * (e + 2) / 2 % 64);
783
- let o = Be;
792
+ [n, s] = [s, (2 * n + 3 * s) % 5], Vt.push(2 * (5 * s + n)), Dt.push((e + 1) * (e + 2) / 2 % 64);
793
+ let o = Ce;
784
794
  for (let r = 0; r < 7; r++)
785
- t = (t << O ^ (t >> Ae) * Oe) % $e, t & Ce && (o ^= O << (O << BigInt(r)) - O);
786
- Dt.push(o);
795
+ t = (t << O ^ (t >> $e) * Re) % Oe, t & Ae && (o ^= O << (O << BigInt(r)) - O);
796
+ Kt.push(o);
787
797
  }
788
- const Kt = fe(Dt, !0), Re = Kt[0], Le = Kt[1], It = (e, t, n) => n > 32 ? ye(e, t, n) : pe(e, t, n), vt = (e, t, n) => n > 32 ? we(e, t, n) : me(e, t, n);
789
- function Ue(e, t = 24) {
798
+ const Mt = de(Kt, !0), Le = Mt[0], Ue = Mt[1], It = (e, t, n) => n > 32 ? we(e, t, n) : me(e, t, n), Et = (e, t, n) => n > 32 ? be(e, t, n) : ye(e, t, n);
799
+ function We(e, t = 24) {
790
800
  const n = new Uint32Array(10);
791
801
  for (let s = 24 - t; s < 24; s++) {
792
802
  for (let i = 0; i < 10; i++)
793
803
  n[i] = e[i] ^ e[i + 10] ^ e[i + 20] ^ e[i + 30] ^ e[i + 40];
794
804
  for (let i = 0; i < 10; i += 2) {
795
- const a = (i + 8) % 10, d = (i + 2) % 10, u = n[d], h = n[d + 1], m = It(u, h, 1) ^ n[a], l = vt(u, h, 1) ^ n[a + 1];
796
- for (let y = 0; y < 50; y += 10)
797
- e[i + y] ^= m, e[i + y + 1] ^= l;
805
+ const a = (i + 8) % 10, d = (i + 2) % 10, u = n[d], l = n[d + 1], y = It(u, l, 1) ^ n[a], c = Et(u, l, 1) ^ n[a + 1];
806
+ for (let m = 0; m < 50; m += 10)
807
+ e[i + m] ^= y, e[i + m + 1] ^= c;
798
808
  }
799
809
  let o = e[2], r = e[3];
800
810
  for (let i = 0; i < 24; i++) {
801
- const a = Ft[i], d = It(o, r, a), u = vt(o, r, a), h = Vt[i];
802
- o = e[h], r = e[h + 1], e[h] = d, e[h + 1] = u;
811
+ const a = Dt[i], d = It(o, r, a), u = Et(o, r, a), l = Vt[i];
812
+ o = e[l], r = e[l + 1], e[l] = d, e[l + 1] = u;
803
813
  }
804
814
  for (let i = 0; i < 50; i += 10) {
805
815
  for (let a = 0; a < 10; a++)
@@ -807,33 +817,33 @@ function Ue(e, t = 24) {
807
817
  for (let a = 0; a < 10; a++)
808
818
  e[i + a] ^= ~n[(a + 2) % 10] & n[(a + 4) % 10];
809
819
  }
810
- e[0] ^= Re[s], e[1] ^= Le[s];
820
+ e[0] ^= Le[s], e[1] ^= Ue[s];
811
821
  }
812
822
  S(n);
813
823
  }
814
824
  class dt {
815
825
  // NOTE: we accept arguments in bytes instead of bits here.
816
826
  constructor(t, n, s, o = !1, r = 24) {
817
- x(this, "state");
818
- x(this, "pos", 0);
819
- x(this, "posOut", 0);
820
- x(this, "finished", !1);
821
- x(this, "state32");
822
- x(this, "destroyed", !1);
823
- x(this, "blockLen");
824
- x(this, "suffix");
825
- x(this, "outputLen");
826
- x(this, "enableXOF", !1);
827
- x(this, "rounds");
827
+ P(this, "state");
828
+ P(this, "pos", 0);
829
+ P(this, "posOut", 0);
830
+ P(this, "finished", !1);
831
+ P(this, "state32");
832
+ P(this, "destroyed", !1);
833
+ P(this, "blockLen");
834
+ P(this, "suffix");
835
+ P(this, "outputLen");
836
+ P(this, "enableXOF", !1);
837
+ P(this, "rounds");
828
838
  if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF = o, this.rounds = r, L(s, "outputLen"), !(0 < t && t < 200))
829
839
  throw new Error("only keccak-f1600 function is supported");
830
- this.state = new Uint8Array(200), this.state32 = de(this.state);
840
+ this.state = new Uint8Array(200), this.state32 = ge(this.state);
831
841
  }
832
842
  clone() {
833
843
  return this._cloneInto();
834
844
  }
835
845
  keccak() {
836
- xt(this.state32), Ue(this.state32, this.rounds), xt(this.state32), this.posOut = 0, this.pos = 0;
846
+ Pt(this.state32), We(this.state32, this.rounds), Pt(this.state32), this.posOut = 0, this.pos = 0;
837
847
  }
838
848
  update(t) {
839
849
  M(this), K(t);
@@ -872,7 +882,7 @@ class dt {
872
882
  return L(t), this.xofInto(new Uint8Array(t));
873
883
  }
874
884
  digestInto(t) {
875
- if (ge(t, this), this.finished)
885
+ if (pe(t, this), this.finished)
876
886
  throw new Error("digest() was already called");
877
887
  return this.writeInto(t), this.destroy(), t;
878
888
  }
@@ -887,49 +897,49 @@ class dt {
887
897
  return t || (t = new dt(n, s, o, i, r)), t.state32.set(this.state32), t.pos = this.pos, t.posOut = this.posOut, t.finished = this.finished, t.rounds = r, t.suffix = s, t.outputLen = o, t.enableXOF = i, t.destroyed = this.destroyed, t;
888
898
  }
889
899
  }
890
- const We = (e, t, n, s = {}) => Bt(() => new dt(t, e, n), s), Mt = /* @__PURE__ */ We(1, 136, 32);
900
+ const Fe = (e, t, n, s = {}) => Ct(() => new dt(t, e, n), s), Nt = /* @__PURE__ */ Fe(1, 136, 32);
891
901
  function Ve(e, t, n, s) {
892
- St(e);
893
- const o = xe({ dkLen: 32, asyncTick: 10 }, s), { c: r, dkLen: i, asyncTick: a } = o;
902
+ Bt(e);
903
+ const o = Pe({ dkLen: 32, asyncTick: 10 }, s), { c: r, dkLen: i, asyncTick: a } = o;
894
904
  if (L(r, "c"), L(i, "dkLen"), L(a, "asyncTick"), r < 1)
895
905
  throw new Error("iterations (c) must be >= 1");
896
- const d = Pt(t, "password"), u = Pt(n, "salt"), h = new Uint8Array(i), m = N.create(e, d), l = m._cloneInto().update(u);
897
- return { c: r, dkLen: i, asyncTick: a, DK: h, PRF: m, PRFSalt: l };
906
+ const d = kt(t, "password"), u = kt(n, "salt"), l = new Uint8Array(i), y = N.create(e, d), c = y._cloneInto().update(u);
907
+ return { c: r, dkLen: i, asyncTick: a, DK: l, PRF: y, PRFSalt: c };
898
908
  }
899
- function Fe(e, t, n, s, o) {
909
+ function De(e, t, n, s, o) {
900
910
  return e.destroy(), t.destroy(), s && s.destroy(), S(o), n;
901
911
  }
902
- function De(e, t, n, s) {
912
+ function Ke(e, t, n, s) {
903
913
  const { c: o, dkLen: r, DK: i, PRF: a, PRFSalt: d } = Ve(e, t, n, s);
904
914
  let u;
905
- const h = new Uint8Array(4), m = be(h), l = new Uint8Array(a.outputLen);
906
- for (let y = 1, p = 0; p < r; y++, p += a.outputLen) {
907
- const w = i.subarray(p, p + a.outputLen);
908
- m.setInt32(0, y, !1), (u = d._cloneInto(u)).update(h).digestInto(l), w.set(l.subarray(0, w.length));
909
- for (let P = 1; P < o; P++) {
910
- a._cloneInto(u).update(l).digestInto(l);
911
- for (let f = 0; f < w.length; f++)
912
- w[f] ^= l[f];
915
+ const l = new Uint8Array(4), y = xe(l), c = new Uint8Array(a.outputLen);
916
+ for (let m = 1, g = 0; g < r; m++, g += a.outputLen) {
917
+ const b = i.subarray(g, g + a.outputLen);
918
+ y.setInt32(0, m, !1), (u = d._cloneInto(u)).update(l).digestInto(c), b.set(c.subarray(0, b.length));
919
+ for (let x = 1; x < o; x++) {
920
+ a._cloneInto(u).update(c).digestInto(c);
921
+ for (let f = 0; f < b.length; f++)
922
+ b[f] ^= c[f];
913
923
  }
914
924
  }
915
- return Fe(a, d, i, u, l);
925
+ return De(a, d, i, u, c);
916
926
  }
917
- function Nt(e) {
927
+ function Xt(e) {
918
928
  if (typeof e != "string")
919
929
  throw new TypeError("invalid mnemonic type: " + typeof e);
920
930
  return e.normalize("NFKD");
921
931
  }
922
- function Ke(e) {
923
- const t = Nt(e), n = t.split(" ");
932
+ function Me(e) {
933
+ const t = Xt(e), n = t.split(" ");
924
934
  if (![12, 15, 18, 21, 24].includes(n.length))
925
935
  throw new Error("Invalid mnemonic");
926
936
  return { nfkd: t, words: n };
927
937
  }
928
- const Me = (e) => Nt("mnemonic" + e);
929
- function Ne(e, t = "") {
930
- return De(ut, Ke(e).nfkd, Me(t), { c: 2048, dkLen: 64 });
938
+ const Ne = (e) => Xt("mnemonic" + e);
939
+ function Xe(e, t = "") {
940
+ return Ke(ut, Me(e).nfkd, Ne(t), { c: 2048, dkLen: 64 });
931
941
  }
932
- const Xe = 508, Et = 16, V = 32, F = 64, Ht = 5, je = 4;
942
+ const je = 508, Ht = 16, F = 32, V = 64, _t = 5, qe = 4;
933
943
  function R(...e) {
934
944
  const t = e.reduce((o, r) => o + r.length, 0), n = new Uint8Array(t);
935
945
  let s = 0;
@@ -941,27 +951,27 @@ function J(e) {
941
951
  return new TextEncoder().encode(e);
942
952
  }
943
953
  function Y(e) {
944
- const t = new Uint8Array(je);
954
+ const t = new Uint8Array(qe);
945
955
  return new DataView(t.buffer).setUint32(0, e.length, !1), R(t, e);
946
956
  }
947
957
  function Q(e, t) {
948
958
  return N(ut, e, t);
949
959
  }
950
- function _t(e) {
951
- return Wt(Ct(e));
960
+ function St(e) {
961
+ return Ft(At(e));
952
962
  }
953
963
  const ct = (e) => Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
954
- function qe(e) {
955
- const t = Ne(e), n = new Uint8Array(t);
964
+ function Ge(e) {
965
+ const t = Xe(e), n = new Uint8Array(t);
956
966
  return t.fill(0), n;
957
967
  }
958
- async function Ge(e, t, n, s) {
959
- if (e.length !== F)
968
+ async function ze(e, t, n, s) {
969
+ if (e.length !== V)
960
970
  throw new Error(
961
- `WOTS seed must be ${F} bytes, got ${e.length}`
971
+ `WOTS seed must be ${V} bytes, got ${e.length}`
962
972
  );
963
973
  t = E(t), n = E(n);
964
- const o = e.slice(V, F), r = e.slice(0, V), i = [o, r];
974
+ const o = e.slice(F, V), r = e.slice(0, F), i = [o, r];
965
975
  try {
966
976
  const a = R(
967
977
  Y(J(t)),
@@ -971,29 +981,29 @@ async function Ge(e, t, n, s) {
971
981
  i.push(d);
972
982
  const u = Q(o, d);
973
983
  i.push(u);
974
- const h = u.slice(0, V), m = u.slice(V, F);
975
- i.push(h, m);
976
- const l = [], y = [], p = [], w = [];
977
- let P = !1;
984
+ const l = u.slice(0, F), y = u.slice(F, V);
985
+ i.push(l, y);
986
+ const c = [], m = [], g = [], b = [];
987
+ let x = !1;
978
988
  try {
979
- for (let f = 0; f < Xe; f++) {
980
- const c = new Uint8Array(Ht);
981
- c[0] = 0, new DataView(c.buffer).setUint32(1, f, !1);
982
- const g = new Uint8Array(Ht);
983
- g[0] = 1, new DataView(g.buffer).setUint32(1, f, !1);
984
- const b = R(h, c), T = R(h, g), k = Q(m, b), v = Q(m, T);
989
+ for (let f = 0; f < je; f++) {
990
+ const p = new Uint8Array(_t);
991
+ p[0] = 0, new DataView(p.buffer).setUint32(1, f, !1);
992
+ const h = new Uint8Array(_t);
993
+ h[0] = 1, new DataView(h.buffer).setUint32(1, f, !1);
994
+ const w = R(l, p), T = R(l, h), k = Q(y, w), v = Q(y, T);
985
995
  try {
986
- const C = k.slice(0, Et), A = v.slice(0, Et);
987
- l.push(C), y.push(A), p.push(_t(C)), w.push(_t(A));
996
+ const C = k.slice(0, Ht), A = v.slice(0, Ht);
997
+ c.push(C), m.push(A), g.push(St(C)), b.push(St(A));
988
998
  } finally {
989
- b.fill(0), T.fill(0), k.fill(0), v.fill(0);
999
+ w.fill(0), T.fill(0), k.fill(0), v.fill(0);
990
1000
  }
991
1001
  }
992
- return P = !0, { falsePreimages: l, truePreimages: y, falseHashes: p, trueHashes: w };
1002
+ return x = !0, { falsePreimages: c, truePreimages: m, falseHashes: g, trueHashes: b };
993
1003
  } finally {
994
- if (!P) {
995
- for (const f of l) f.fill(0);
996
- for (const f of y) f.fill(0);
1004
+ if (!x) {
1005
+ for (const f of c) f.fill(0);
1006
+ for (const f of m) f.fill(0);
997
1007
  }
998
1008
  }
999
1009
  } finally {
@@ -1001,13 +1011,13 @@ async function Ge(e, t, n, s) {
1001
1011
  a.fill(0);
1002
1012
  }
1003
1013
  }
1004
- function Pn(e) {
1014
+ function Tn(e) {
1005
1015
  return {
1006
1016
  false_list: e.falseHashes.map(ct),
1007
1017
  true_list: e.trueHashes.map(ct)
1008
1018
  };
1009
1019
  }
1010
- function ze(e) {
1020
+ function Ze(e) {
1011
1021
  if (e.falseHashes.length === 0 || e.trueHashes.length === 0)
1012
1022
  throw new Error(
1013
1023
  "computeWotsPkHash: keypair hash arrays must not be empty"
@@ -1018,10 +1028,10 @@ function ze(e) {
1018
1028
  s.set(i, o), o += t;
1019
1029
  for (const i of e.trueHashes)
1020
1030
  s.set(i, o), o += t;
1021
- const r = Mt(s);
1031
+ const r = Nt(s);
1022
1032
  return `0x${ct(r)}`;
1023
1033
  }
1024
- const tt = 32, et = 64, Ze = 4, I = 20, lt = 4, Xt = 2, Je = 0, Ye = 1, D = [64, 64];
1034
+ const tt = 32, et = 64, Je = 4, I = 20, lt = 4, jt = 2, Ye = 0, Qe = 1, D = [64, 64];
1025
1035
  function ht(...e) {
1026
1036
  const t = e.reduce((o, r) => o + r.length, 0), n = new Uint8Array(t);
1027
1037
  let s = 0;
@@ -1033,30 +1043,30 @@ function nt(e) {
1033
1043
  return new TextEncoder().encode(e);
1034
1044
  }
1035
1045
  function st(e) {
1036
- const t = new Uint8Array(Ze);
1046
+ const t = new Uint8Array(Je);
1037
1047
  return new DataView(t.buffer).setUint32(0, e.length, !1), ht(t, e);
1038
1048
  }
1039
1049
  function ot(e) {
1040
1050
  return e.startsWith("0x") || e.startsWith("0X") ? e.slice(2) : e;
1041
1051
  }
1042
- const Qe = (e) => Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
1043
- function tn(e, t) {
1052
+ const tn = (e) => Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
1053
+ function en(e, t) {
1044
1054
  return N(ut, e, t);
1045
1055
  }
1046
1056
  function gt(e) {
1047
- return Wt(Ct(e));
1057
+ return Ft(At(e));
1048
1058
  }
1049
- function jt(e) {
1059
+ function qt(e) {
1050
1060
  return (1 << e) - 1;
1051
1061
  }
1052
- function en(e) {
1062
+ function nn(e) {
1053
1063
  let t = 1;
1054
1064
  for (; t * t < e + 1; ) t++;
1055
1065
  return Math.max(t, 2);
1056
1066
  }
1057
- function nn(e) {
1058
- const t = lt, n = jt(t), s = e * n;
1059
- return { d: t, n: e, checksum_radix: en(s) };
1067
+ function sn(e) {
1068
+ const t = lt, n = qt(t), s = e * n;
1069
+ return { d: t, n: e, checksum_radix: nn(s) };
1060
1070
  }
1061
1071
  function rt(e, t) {
1062
1072
  const n = [];
@@ -1075,21 +1085,21 @@ function it(e, t) {
1075
1085
  n = gt(n);
1076
1086
  return n;
1077
1087
  }
1078
- function sn(e, t) {
1079
- const n = jt(t.d), s = t.checksum_radix - 1, o = Math.floor(t.n * n / t.checksum_radix), r = [];
1080
- for (let h = 0; h < t.n; h++) {
1081
- const m = rt(e, h + Xt), l = it(m, n);
1082
- r.push(Array.from(l));
1088
+ function on(e, t) {
1089
+ const n = qt(t.d), s = t.checksum_radix - 1, o = Math.floor(t.n * n / t.checksum_radix), r = [];
1090
+ for (let l = 0; l < t.n; l++) {
1091
+ const y = rt(e, l + jt), c = it(y, n);
1092
+ r.push(Array.from(c));
1083
1093
  }
1084
1094
  const i = rt(
1085
1095
  e,
1086
- Je
1096
+ Ye
1087
1097
  ), a = it(
1088
1098
  i,
1089
1099
  s
1090
1100
  ), d = rt(
1091
1101
  e,
1092
- Ye
1102
+ Qe
1093
1103
  ), u = it(
1094
1104
  d,
1095
1105
  o
@@ -1101,7 +1111,7 @@ function sn(e, t) {
1101
1111
  checksum_minor_terminal: Array.from(a)
1102
1112
  };
1103
1113
  }
1104
- async function kn(e, t, n, s) {
1114
+ async function vn(e, t, n, s) {
1105
1115
  if (e.length !== et)
1106
1116
  throw new Error(
1107
1117
  `WOTS seed must be exactly ${et} bytes, got ${e.length}`
@@ -1113,40 +1123,40 @@ async function kn(e, t, n, s) {
1113
1123
  st(nt(r)),
1114
1124
  st(nt(ot(s)))
1115
1125
  )
1116
- ), u = tn(i, d), h = u.slice(0, tt);
1126
+ ), u = en(i, d), l = u.slice(0, tt);
1117
1127
  try {
1118
- const m = [];
1119
- for (let l = 0; l < D.length; l++) {
1120
- const y = D[l], p = nn(y), w = new Uint8Array(h.length + 1);
1121
- w.set(h), w[h.length] = l;
1122
- const P = gt(w);
1128
+ const y = [];
1129
+ for (let c = 0; c < D.length; c++) {
1130
+ const m = D[c], g = sn(m), b = new Uint8Array(l.length + 1);
1131
+ b.set(l), b[l.length] = c;
1132
+ const x = gt(b);
1123
1133
  try {
1124
- const f = sn(P, p);
1134
+ const f = on(x, g);
1125
1135
  if (f.config.d !== lt)
1126
- throw new Error(`Block ${l}: expected d=${lt}, got d=${f.config.d}`);
1127
- if (f.config.n !== y)
1128
- throw new Error(`Block ${l}: expected n=${y}, got n=${f.config.n}`);
1129
- if (f.message_terminals.length !== y)
1130
- throw new Error(`Block ${l}: expected ${y} message terminals, got ${f.message_terminals.length}`);
1131
- for (let c = 0; c < f.message_terminals.length; c++)
1132
- if (f.message_terminals[c].length !== I)
1133
- throw new Error(`Block ${l} terminal ${c}: expected ${I} bytes, got ${f.message_terminals[c].length}`);
1136
+ throw new Error(`Block ${c}: expected d=${lt}, got d=${f.config.d}`);
1137
+ if (f.config.n !== m)
1138
+ throw new Error(`Block ${c}: expected n=${m}, got n=${f.config.n}`);
1139
+ if (f.message_terminals.length !== m)
1140
+ throw new Error(`Block ${c}: expected ${m} message terminals, got ${f.message_terminals.length}`);
1141
+ for (let p = 0; p < f.message_terminals.length; p++)
1142
+ if (f.message_terminals[p].length !== I)
1143
+ throw new Error(`Block ${c} terminal ${p}: expected ${I} bytes, got ${f.message_terminals[p].length}`);
1134
1144
  if (f.checksum_minor_terminal.length !== I)
1135
- throw new Error(`Block ${l} checksum_minor: expected ${I} bytes`);
1145
+ throw new Error(`Block ${c} checksum_minor: expected ${I} bytes`);
1136
1146
  if (f.checksum_major_terminal.length !== I)
1137
- throw new Error(`Block ${l} checksum_major: expected ${I} bytes`);
1138
- m.push(f);
1147
+ throw new Error(`Block ${c} checksum_major: expected ${I} bytes`);
1148
+ y.push(f);
1139
1149
  } finally {
1140
- w.fill(0), P.fill(0);
1150
+ b.fill(0), x.fill(0);
1141
1151
  }
1142
1152
  }
1143
- if (m.length !== D.length)
1153
+ if (y.length !== D.length)
1144
1154
  throw new Error(
1145
- `Expected ${D.length} blocks, got ${m.length}`
1155
+ `Expected ${D.length} blocks, got ${y.length}`
1146
1156
  );
1147
- return m;
1157
+ return y;
1148
1158
  } finally {
1149
- d.fill(0), i.fill(0), a.fill(0), u.fill(0), h.fill(0), e.fill(0);
1159
+ d.fill(0), i.fill(0), a.fill(0), u.fill(0), l.fill(0), e.fill(0);
1150
1160
  }
1151
1161
  }
1152
1162
  function at(e, t, n) {
@@ -1162,7 +1172,7 @@ function at(e, t, n) {
1162
1172
  );
1163
1173
  }
1164
1174
  }
1165
- function Tn(e) {
1175
+ function In(e) {
1166
1176
  if (e.length === 0)
1167
1177
  throw new Error("Public keys array must not be empty");
1168
1178
  for (let r = 0; r < e.length; r++) {
@@ -1173,7 +1183,7 @@ function Tn(e) {
1173
1183
  }
1174
1184
  let t = 0;
1175
1185
  for (const r of e)
1176
- t += Xt + r.message_terminals.length;
1186
+ t += jt + r.message_terminals.length;
1177
1187
  const n = new Uint8Array(t * I);
1178
1188
  let s = 0;
1179
1189
  for (const r of e) {
@@ -1181,20 +1191,20 @@ function Tn(e) {
1181
1191
  for (const i of r.message_terminals)
1182
1192
  n.set(i, s), s += I;
1183
1193
  }
1184
- const o = Mt(n);
1185
- return `0x${Qe(o)}`;
1194
+ const o = Nt(n);
1195
+ return `0x${tn(o)}`;
1186
1196
  }
1187
- async function In(e, t, n, s) {
1188
- const o = qe(e);
1197
+ async function En(e, t, n, s) {
1198
+ const o = Ge(e);
1189
1199
  try {
1190
- const r = await Ge(
1200
+ const r = await ze(
1191
1201
  o,
1192
1202
  t,
1193
1203
  n,
1194
1204
  s
1195
1205
  );
1196
1206
  try {
1197
- return ze(r);
1207
+ return Ze(r);
1198
1208
  } finally {
1199
1209
  for (const i of r.falsePreimages) i.fill(0);
1200
1210
  for (const i of r.truePreimages) i.fill(0);
@@ -1203,24 +1213,24 @@ async function In(e, t, n, s) {
1203
1213
  o.fill(0);
1204
1214
  }
1205
1215
  }
1206
- function vn(e) {
1216
+ function Hn(e) {
1207
1217
  const t = (e instanceof Error ? e.message : typeof e == "string" ? e : "").toLowerCase();
1208
1218
  return t.includes("wots") && t.includes("hash") && t.includes("does not match");
1209
1219
  }
1210
1220
  export {
1211
1221
  B as C,
1212
- xn as P,
1213
- kn as a,
1214
- Tn as b,
1215
- ze as c,
1216
- Ge as d,
1222
+ kn as P,
1223
+ vn as a,
1224
+ In as b,
1225
+ Ze as c,
1226
+ ze as d,
1217
1227
  ft as e,
1218
- In as f,
1219
- wn as g,
1228
+ En as f,
1229
+ xn as g,
1220
1230
  _ as h,
1221
- bn as i,
1222
- vn as j,
1223
- Pn as k,
1224
- qe as m
1231
+ Pn as i,
1232
+ Hn as j,
1233
+ Tn as k,
1234
+ Ge as m
1225
1235
  };
1226
- //# sourceMappingURL=errors-D_PI__IT.js.map
1236
+ //# sourceMappingURL=errors-CkkL1ztr.js.map