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