@babylonlabs-io/ts-sdk 0.30.0 → 0.31.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.
@@ -1,15 +1,15 @@
1
- var z = Object.defineProperty;
2
- var G = (e, t, r) => t in e ? z(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var x = (e, t, r) => G(e, typeof t != "symbol" ? t + "" : t, r);
4
- import { B as Q, c as Y, a as j, R as q, d as O, D as y } from "./types-CnG3JsRs.js";
5
- import { e as J, s as c, u as K, v as H, p as m, f } from "./bitcoin-B-Y0DlqR.js";
6
- import { s as Z } from "./sha2-6wN58S6R.js";
7
- import * as ee from "bitcoinjs-lib";
8
- import { Transaction as w, Psbt as te } from "bitcoinjs-lib";
9
- import { Buffer as re } from "buffer";
1
+ var G = Object.defineProperty;
2
+ var Q = (e, t, r) => t in e ? G(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var x = (e, t, r) => Q(e, typeof t != "symbol" ? t + "" : t, r);
4
+ import { B as Y, c as j, a as q, R as J, d as O, D as y } from "./types-CnG3JsRs.js";
5
+ import { e as Z, s as l, u as K, v as H, p as w, f } from "./bitcoin-B-Y0DlqR.js";
6
+ import { s as ee } from "./sha2-6wN58S6R.js";
7
+ import * as te from "bitcoinjs-lib";
8
+ import { Transaction as m, Psbt as re } from "bitcoinjs-lib";
9
+ import { Buffer as oe } from "buffer";
10
10
  import { c as b } from "./signing-BZigafm0.js";
11
11
  import "@babylonlabs-io/babylon-tbv-rust-wasm";
12
- import { a as V, c as S, e as v, g as oe, d as ne, b as se } from "./noPayout-B8JiTaYt.js";
12
+ import { a as V, c as S, e as v, g as ne, d as se, b as ie } from "./noPayout-B8JiTaYt.js";
13
13
  const $ = 66;
14
14
  function L(e) {
15
15
  if (!e.startsWith("0x") && !e.startsWith("0X"))
@@ -24,7 +24,7 @@ function L(e) {
24
24
  r[o] = parseInt(t.slice(o * 2, o * 2 + 2), 16);
25
25
  return r;
26
26
  }
27
- function ie(e) {
27
+ function ae(e) {
28
28
  return `0x${Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("")}`;
29
29
  }
30
30
  function A(e, t) {
@@ -33,15 +33,15 @@ function A(e, t) {
33
33
  `${t} must be exactly 32 bytes (${$} hex chars with 0x prefix), got ${e.length}`
34
34
  );
35
35
  }
36
- function ae(e) {
36
+ function ue(e) {
37
37
  A(e, "Secret");
38
- const t = L(e), r = Z(t);
39
- return ie(r);
38
+ const t = L(e), r = ee(t);
39
+ return ae(r);
40
40
  }
41
- function ue(e, t) {
42
- return A(e, "Secret"), A(t, "Hashlock"), L(t), ae(e).toLowerCase() === t.toLowerCase();
41
+ function ce(e, t) {
42
+ return A(e, "Secret"), A(t, "Hashlock"), L(t), ue(e).toLowerCase() === t.toLowerCase();
43
43
  }
44
- const le = /^0x[0-9a-fA-F]{64}$/, ce = /^0x[0-9a-fA-F]{40}$/, de = /^0x([0-9a-fA-F]{2})*$/;
44
+ const le = /^0x[0-9a-fA-F]{64}$/, de = /^0x[0-9a-fA-F]{40}$/, he = /^0x([0-9a-fA-F]{2})*$/;
45
45
  function E(e, t) {
46
46
  if (e.length !== 66)
47
47
  throw new Error(
@@ -52,14 +52,14 @@ function E(e, t) {
52
52
  `${t} must contain only hex characters after the 0x prefix`
53
53
  );
54
54
  }
55
- function he(e, t) {
56
- if (!ce.test(e))
55
+ function pe(e, t) {
56
+ if (!de.test(e))
57
57
  throw new Error(
58
58
  `${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
59
59
  );
60
60
  }
61
- function pe(e, t) {
62
- if (!de.test(e))
61
+ function fe(e, t) {
62
+ if (!he.test(e))
63
63
  throw new Error(
64
64
  `${t} must be a 0x-prefixed hex string with an even number of hex chars`
65
65
  );
@@ -73,27 +73,27 @@ async function rt(e) {
73
73
  writeContract: u,
74
74
  signal: s
75
75
  } = e;
76
- s == null || s.throwIfAborted(), he(t, "btcVaultRegistryAddress"), E(r, "vaultId");
77
- const a = J(e.secret);
78
- if (E(a, "secret"), o !== void 0 && (E(o, "hashlock"), !ue(a, o)))
76
+ s == null || s.throwIfAborted(), pe(t, "btcVaultRegistryAddress"), E(r, "vaultId");
77
+ const a = Z(e.secret);
78
+ if (E(a, "secret"), o !== void 0 && (E(o, "hashlock"), !ce(a, o)))
79
79
  throw new Error(
80
80
  "Invalid secret: SHA256(secret) does not match the provided hashlock"
81
81
  );
82
- return pe(i, "activationMetadata"), u({
82
+ return fe(i, "activationMetadata"), u({
83
83
  address: t,
84
- abi: Q,
84
+ abi: Y,
85
85
  functionName: "activateVaultWithSecret",
86
86
  args: [r, a, i]
87
87
  });
88
88
  }
89
- const fe = 1e4;
89
+ const ge = 1e4;
90
90
  async function D(e) {
91
91
  const {
92
92
  statusReader: t,
93
93
  peginTxid: r,
94
94
  targetStatuses: o,
95
95
  timeoutMs: i,
96
- pollIntervalMs: u = fe,
96
+ pollIntervalMs: u = ge,
97
97
  signal: s
98
98
  } = e, a = Date.now();
99
99
  for (; ; ) {
@@ -106,23 +106,23 @@ async function D(e) {
106
106
  `Polling timeout after ${i}ms for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
107
107
  );
108
108
  try {
109
- const l = (await t.getPeginStatus(
109
+ const c = (await t.getPeginStatus(
110
110
  { pegin_txid: r },
111
111
  s
112
112
  )).status;
113
- if (o.has(l))
114
- return l;
115
- if (Y.has(l) && !o.has(l))
113
+ if (o.has(c))
114
+ return c;
115
+ if (j.has(c) && !o.has(c))
116
116
  throw new Error(
117
- `Pegin ${r.slice(0, 8)}… reached terminal status "${l}" while waiting for ${[...o].join(", ")}`
117
+ `Pegin ${r.slice(0, 8)}… reached terminal status "${c}" while waiting for ${[...o].join(", ")}`
118
118
  );
119
119
  } catch (n) {
120
- if (!(n instanceof j && n.code === q.NOT_FOUND || n instanceof Error && n.message.includes("PegIn not found")))
120
+ if (!(n instanceof q && n.code === J.NOT_FOUND || n instanceof Error && n.message.includes("PegIn not found")))
121
121
  throw n;
122
122
  }
123
- await new Promise((n, l) => {
123
+ await new Promise((n, c) => {
124
124
  const d = () => {
125
- clearTimeout(h), l(
125
+ clearTimeout(h), c(
126
126
  new Error(
127
127
  `Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
128
128
  )
@@ -134,7 +134,7 @@ async function D(e) {
134
134
  });
135
135
  }
136
136
  }
137
- const ge = 300 * 1e3, Pe = /* @__PURE__ */ new Set([
137
+ const Pe = 300 * 1e3, ye = /* @__PURE__ */ new Set([
138
138
  y.PENDING_DEPOSITOR_WOTS_PK,
139
139
  ...O
140
140
  ]);
@@ -145,14 +145,14 @@ async function ot(e) {
145
145
  peginTxid: o,
146
146
  depositorPk: i,
147
147
  wotsPublicKeys: u,
148
- timeoutMs: s = ge,
148
+ timeoutMs: s = Pe,
149
149
  signal: a
150
150
  } = e;
151
151
  a == null || a.throwIfAborted();
152
152
  const n = await D({
153
153
  statusReader: t,
154
154
  peginTxid: o,
155
- targetStatuses: Pe,
155
+ targetStatuses: ye,
156
156
  timeoutMs: s,
157
157
  signal: a
158
158
  });
@@ -166,9 +166,9 @@ async function ot(e) {
166
166
  ));
167
167
  }
168
168
  const I = 1;
169
- function ye(e, t, r) {
170
- const o = c(r).toLowerCase(), u = [e, ...t].map(
171
- (s) => c(s).toLowerCase()
169
+ function be(e, t, r) {
170
+ const o = l(r).toLowerCase(), u = [e, ...t].map(
171
+ (s) => l(s).toLowerCase()
172
172
  ).filter((s) => s !== o);
173
173
  if (u.length === 0)
174
174
  throw new Error(
@@ -176,23 +176,23 @@ function ye(e, t, r) {
176
176
  );
177
177
  return u;
178
178
  }
179
- function be(e, t) {
179
+ function xe(e, t) {
180
180
  const r = e.ins[t];
181
181
  return K(new Uint8Array(r.hash).slice().reverse());
182
182
  }
183
- function _(e, t, r, o, i) {
183
+ function B(e, t, r, o, i) {
184
184
  const u = e.ins[t];
185
185
  if (u.index !== 0)
186
186
  throw new Error(
187
187
  `NoPayout (challenger ${i}) input ${t} expected to spend ${o} vout 0, got vout ${u.index}`
188
188
  );
189
- const s = r.getId(), a = be(e, t);
189
+ const s = r.getId(), a = xe(e, t);
190
190
  if (a !== s)
191
191
  throw new Error(
192
192
  `NoPayout (challenger ${i}) input ${t} does not reference ${o} (expected txid ${s}, got ${a})`
193
193
  );
194
194
  }
195
- async function xe(e, t, r) {
195
+ async function me(e, t, r) {
196
196
  const o = [], i = [], u = [];
197
197
  V(
198
198
  e.payout_tx.tx_hex,
@@ -215,20 +215,20 @@ async function xe(e, t, r) {
215
215
  I
216
216
  )
217
217
  );
218
- const a = ye(
218
+ const a = be(
219
219
  r.vaultProviderBtcPubkey,
220
220
  r.vaultKeeperBtcPubkeys,
221
221
  r.depositorBtcPubkey
222
- ), n = c(r.depositorBtcPubkey), l = w.fromHex(
223
- c(e.assert_tx.tx_hex)
222
+ ), n = l(r.depositorBtcPubkey), c = m.fromHex(
223
+ l(e.assert_tx.tx_hex)
224
224
  );
225
225
  for (const d of e.challenger_presign_data) {
226
- const h = c(d.challenger_pubkey), g = o.length, P = await we({
226
+ const h = l(d.challenger_pubkey), g = o.length, P = await we({
227
227
  challenger: d,
228
228
  challengerPubkey: h,
229
229
  claimerPubkey: n,
230
230
  localChallengers: a,
231
- assertTxParsed: l,
231
+ assertTxParsed: c,
232
232
  ctx: r
233
233
  });
234
234
  o.push(P), i.push(
@@ -252,50 +252,50 @@ async function we(e) {
252
252
  assertTxParsed: u,
253
253
  ctx: s
254
254
  } = e;
255
- oe(
255
+ ne(
256
256
  t.nopayout_tx.tx_hex,
257
257
  r,
258
258
  s.network
259
259
  );
260
- const a = w.fromHex(
261
- c(t.nopayout_tx.tx_hex)
262
- ), n = w.fromHex(
263
- c(t.challenge_assert_x_tx.tx_hex)
264
- ), l = w.fromHex(
265
- c(t.challenge_assert_y_tx.tx_hex)
260
+ const a = m.fromHex(
261
+ l(t.nopayout_tx.tx_hex)
262
+ ), n = m.fromHex(
263
+ l(t.challenge_assert_x_tx.tx_hex)
264
+ ), c = m.fromHex(
265
+ l(t.challenge_assert_y_tx.tx_hex)
266
266
  );
267
267
  if (a.ins.length !== 3)
268
268
  throw new Error(
269
269
  `NoPayout (challenger ${r}) must have exactly 3 inputs, got ${a.ins.length}`
270
270
  );
271
- _(
271
+ B(
272
272
  a,
273
273
  0,
274
274
  u,
275
275
  "Assert",
276
276
  r
277
- ), _(
277
+ ), B(
278
278
  a,
279
279
  1,
280
280
  n,
281
281
  "ChallengeAssertX",
282
282
  r
283
- ), _(
283
+ ), B(
284
284
  a,
285
285
  2,
286
- l,
286
+ c,
287
287
  "ChallengeAssertY",
288
288
  r
289
289
  );
290
290
  const d = [
291
291
  u.outs[0],
292
292
  n.outs[0],
293
- l.outs[0]
293
+ c.outs[0]
294
294
  ].map((h) => ({
295
295
  script_pubkey: K(new Uint8Array(h.script)),
296
296
  value: h.value
297
297
  }));
298
- return ne({
298
+ return se({
299
299
  noPayoutTxHex: t.nopayout_tx.tx_hex,
300
300
  challengerPubkey: r,
301
301
  prevouts: d,
@@ -309,7 +309,7 @@ async function we(e) {
309
309
  }
310
310
  });
311
311
  }
312
- function me(e, t, r) {
312
+ function ve(e, t, r) {
313
313
  const o = v(
314
314
  e[0],
315
315
  r
@@ -328,7 +328,7 @@ function me(e, t, r) {
328
328
  per_challenger: i
329
329
  };
330
330
  }
331
- async function ve(e, t, r) {
331
+ async function ke(e, t, r) {
332
332
  if (typeof e.signPsbts == "function")
333
333
  return e.signPsbts(t, r);
334
334
  const o = [];
@@ -336,27 +336,27 @@ async function ve(e, t, r) {
336
336
  o.push(await e.signPsbt(t[i], r == null ? void 0 : r[i]));
337
337
  return o;
338
338
  }
339
- async function ke(e) {
340
- const { depositorGraph: t, btcWallet: r, signingContext: o } = e, i = c(o.depositorBtcPubkey), u = await r.getPublicKeyHex(), { psbtHexes: s, signOptions: a, challengerEntries: n } = await xe(
339
+ async function Te(e) {
340
+ const { depositorGraph: t, btcWallet: r, signingContext: o } = e, i = l(o.depositorBtcPubkey), u = await r.getPublicKeyHex(), { psbtHexes: s, signOptions: a, challengerEntries: n } = await me(
341
341
  t,
342
342
  u,
343
343
  o
344
- ), l = await ve(
344
+ ), c = await ke(
345
345
  r,
346
346
  s,
347
347
  a
348
348
  );
349
- if (l.length !== s.length)
349
+ if (c.length !== s.length)
350
350
  throw new Error(
351
- `Wallet returned ${l.length} signed PSBTs, expected ${s.length}`
351
+ `Wallet returned ${c.length} signed PSBTs, expected ${s.length}`
352
352
  );
353
- return me(
354
- l,
353
+ return ve(
354
+ c,
355
355
  n,
356
356
  i
357
357
  );
358
358
  }
359
- class Te {
359
+ class Ee {
360
360
  /**
361
361
  * Creates a new PayoutManager instance.
362
362
  *
@@ -451,16 +451,16 @@ class Te {
451
451
  n.payoutTxHex,
452
452
  n.registeredPayoutScriptPubKey
453
453
  );
454
- const { depositorPubkey: l } = H(
454
+ const { depositorPubkey: c } = H(
455
455
  r,
456
456
  n.depositorBtcPubkey
457
457
  );
458
- u.push(l);
458
+ u.push(c);
459
459
  const d = await S({
460
460
  payoutTxHex: n.payoutTxHex,
461
461
  peginTxHex: n.peginTxHex,
462
462
  assertTxHex: n.assertTxHex,
463
- depositorBtcPubkey: l,
463
+ depositorBtcPubkey: c,
464
464
  vaultProviderBtcPubkey: n.vaultProviderBtcPubkey,
465
465
  vaultKeeperBtcPubkeys: n.vaultKeeperBtcPubkeys,
466
466
  universalChallengerBtcPubkeys: n.universalChallengerBtcPubkeys,
@@ -479,13 +479,13 @@ class Te {
479
479
  );
480
480
  const a = [];
481
481
  for (let n = 0; n < t.length; n++) {
482
- const l = u[n], d = v(
482
+ const c = u[n], d = v(
483
483
  s[n],
484
- l
484
+ c
485
485
  );
486
486
  a.push({
487
487
  payoutSignature: d,
488
- depositorBtcPubkey: l
488
+ depositorBtcPubkey: c
489
489
  });
490
490
  }
491
491
  return a;
@@ -511,7 +511,7 @@ class Te {
511
511
  );
512
512
  }
513
513
  }
514
- const Ee = 1200 * 1e3, M = /* @__PURE__ */ new Set([
514
+ const Be = 1200 * 1e3, M = /* @__PURE__ */ new Set([
515
515
  y.PENDING_ACKS,
516
516
  y.PENDING_ACTIVATION,
517
517
  y.ACTIVATED
@@ -519,36 +519,36 @@ const Ee = 1200 * 1e3, M = /* @__PURE__ */ new Set([
519
519
  y.PENDING_DEPOSITOR_SIGNATURES,
520
520
  ...M
521
521
  ]);
522
- function Be(e) {
522
+ function Se(e) {
523
523
  return e.map((t) => ({
524
- claimerPubkeyXOnly: m(t.claimer_pubkey),
524
+ claimerPubkeyXOnly: w(t.claimer_pubkey),
525
525
  payoutTxHex: t.payout_tx.tx_hex,
526
526
  assertTxHex: t.assert_tx.tx_hex
527
527
  }));
528
528
  }
529
- function Se(e) {
530
- const { output: t } = ee.payments.p2tr({
531
- internalPubkey: re.from(e, "hex")
529
+ function Ae(e) {
530
+ const { output: t } = te.payments.p2tr({
531
+ internalPubkey: oe.from(e, "hex")
532
532
  });
533
533
  if (!t)
534
534
  throw new Error("Failed to derive BIP-86 P2TR scriptPubKey");
535
535
  return t.toString("hex");
536
536
  }
537
- function Ae(e, t) {
538
- const r = c(e).toLowerCase(), o = c(
537
+ function Ce(e, t) {
538
+ const r = l(e).toLowerCase(), o = l(
539
539
  t.vaultProviderBtcPubkey
540
- ).toLowerCase(), i = c(
540
+ ).toLowerCase(), i = l(
541
541
  t.depositorBtcPubkey
542
542
  ).toLowerCase();
543
543
  if (r === o || r === i)
544
544
  return t.registeredPayoutScriptPubKey;
545
545
  if (!t.vaultKeeperBtcPubkeys.some(
546
- (a) => c(a).toLowerCase() === r
546
+ (a) => l(a).toLowerCase() === r
547
547
  ))
548
548
  throw new Error(
549
549
  `Unknown claimer pubkey ${r}: not VP, depositor, or a registered vault keeper`
550
550
  );
551
- return `0x${Se(r)}`;
551
+ return `0x${Ae(r)}`;
552
552
  }
553
553
  function R(e, t) {
554
554
  return {
@@ -560,14 +560,14 @@ function R(e, t) {
560
560
  universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys,
561
561
  depositorBtcPubkey: t.depositorBtcPubkey,
562
562
  timelockPegin: t.timelockPegin,
563
- registeredPayoutScriptPubKey: Ae(
563
+ registeredPayoutScriptPubKey: Ce(
564
564
  e.claimerPubkeyXOnly,
565
565
  t
566
566
  )
567
567
  };
568
568
  }
569
- async function Ce(e, t, r, o) {
570
- const i = new Te({
569
+ async function He(e, t, r, o) {
570
+ const i = new Ee({
571
571
  network: t.network,
572
572
  btcWallet: e
573
573
  }), u = r.length;
@@ -575,16 +575,16 @@ async function Ce(e, t, r, o) {
575
575
  let s;
576
576
  if (i.supportsBatchSigning())
577
577
  s = (await i.signPayoutTransactionsBatch(
578
- r.map((l) => R(l, t))
579
- )).map((l) => l.payoutSignature);
578
+ r.map((c) => R(c, t))
579
+ )).map((c) => c.payoutSignature);
580
580
  else {
581
581
  s = [];
582
582
  for (let n = 0; n < r.length; n++) {
583
583
  o == null || o(n, u);
584
- const l = await i.signPayoutTransaction(
584
+ const c = await i.signPayoutTransaction(
585
585
  R(r[n], t)
586
586
  );
587
- s.push(l.signature);
587
+ s.push(c.signature);
588
588
  }
589
589
  }
590
590
  const a = {};
@@ -602,9 +602,9 @@ async function nt(e) {
602
602
  peginTxid: i,
603
603
  depositorPk: u,
604
604
  signingContext: s,
605
- timeoutMs: a = Ee,
605
+ timeoutMs: a = Be,
606
606
  signal: n,
607
- onProgress: l
607
+ onProgress: c
608
608
  } = e, d = await D({
609
609
  statusReader: t,
610
610
  peginTxid: i,
@@ -623,16 +623,16 @@ async function nt(e) {
623
623
  n
624
624
  );
625
625
  n == null || n.throwIfAborted();
626
- const g = m(u), P = h.txs.filter(
627
- (X) => m(X.claimer_pubkey) !== g
628
- ), k = Be(P), T = await Ce(
626
+ const g = w(u), P = h.txs.filter(
627
+ (z) => w(z.claimer_pubkey) !== g
628
+ ), k = Se(P), T = await He(
629
629
  o,
630
630
  s,
631
631
  k,
632
- l
632
+ c
633
633
  );
634
634
  n == null || n.throwIfAborted();
635
- const p = await ke({
635
+ const p = await Te({
636
636
  depositorGraph: h.depositor_graph,
637
637
  btcWallet: o,
638
638
  signingContext: {
@@ -651,7 +651,7 @@ async function nt(e) {
651
651
  });
652
652
  n == null || n.throwIfAborted();
653
653
  const C = { ...T };
654
- C[c(u)] = p.payout_signatures, await r.submitDepositorPresignatures(
654
+ C[l(u)] = p.payout_signatures, await r.submitDepositorPresignatures(
655
655
  {
656
656
  pegin_txid: i,
657
657
  depositor_pk: u,
@@ -661,7 +661,7 @@ async function nt(e) {
661
661
  n
662
662
  );
663
663
  }
664
- function He(e) {
664
+ function $e(e) {
665
665
  return /^[0-9a-fA-F]{64}$/.test(e);
666
666
  }
667
667
  function st(e) {
@@ -713,7 +713,7 @@ function ut(e, t) {
713
713
  error: "Invalid vault provider selected"
714
714
  } : { valid: !0 };
715
715
  }
716
- function $e(e, t, r) {
716
+ function Ie(e, t, r) {
717
717
  if (!e || e.length === 0)
718
718
  return {
719
719
  valid: !1,
@@ -739,30 +739,30 @@ function $e(e, t, r) {
739
739
  }
740
740
  return { valid: !0 };
741
741
  }
742
- function Ie(e) {
743
- const t = c(e);
744
- return He(t) ? { valid: !0 } : {
742
+ function Re(e) {
743
+ const t = l(e);
744
+ return $e(t) ? { valid: !0 } : {
745
745
  valid: !1,
746
746
  error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
747
747
  };
748
748
  }
749
- function Re(e) {
749
+ function Ne(e) {
750
750
  if (!e || e.length === 0)
751
751
  throw new Error(
752
752
  "No vault keepers available. The system requires at least one vault keeper to create a deposit."
753
753
  );
754
754
  }
755
- function Ne(e) {
755
+ function Oe(e) {
756
756
  if (!e || e.length === 0)
757
757
  throw new Error(
758
758
  "No universal challengers available. The system requires at least one universal challenger to create a deposit."
759
759
  );
760
760
  }
761
- function Oe(e) {
761
+ function Ke(e) {
762
762
  if (e.length === 0)
763
763
  throw new Error("No spendable UTXOs available");
764
764
  }
765
- function lt(e) {
765
+ function ct(e) {
766
766
  const {
767
767
  vaultAmounts: t,
768
768
  confirmedUTXOs: r,
@@ -771,33 +771,33 @@ function lt(e) {
771
771
  universalChallengerBtcPubkeys: u,
772
772
  minDeposit: s,
773
773
  maxDeposit: a
774
- } = e, n = $e(
774
+ } = e, n = Ie(
775
775
  t,
776
776
  s,
777
777
  a
778
778
  );
779
779
  if (!n.valid)
780
780
  throw new Error(n.error);
781
- const l = Ie(o);
782
- if (!l.valid)
783
- throw new Error(l.error);
784
- Re(i), Ne(u), Oe(r);
781
+ const c = Re(o);
782
+ if (!c.valid)
783
+ throw new Error(c.error);
784
+ Ne(i), Oe(u), Ke(r);
785
785
  }
786
786
  var U = /* @__PURE__ */ ((e) => (e.CLAIM_EVENT_RECEIVED = "ClaimEventReceived", e.CLAIM_BROADCAST = "ClaimBroadcast", e.ASSERT_BROADCAST = "AssertBroadcast", e.CHALLENGE_ASSERT_OBSERVED = "ChallengeAssertObserved", e.WRONGLY_CHALLENGED_BROADCAST = "WronglyChallengedBroadcast", e.PAYOUT_BROADCAST = "PayoutBroadcast", e.FAILED = "Failed", e))(U || {});
787
- const Ke = /* @__PURE__ */ new Set([
787
+ const Ve = /* @__PURE__ */ new Set([
788
788
  "PayoutBroadcast",
789
789
  "Failed"
790
790
  /* FAILED */
791
791
  ]);
792
- function ct(e) {
792
+ function lt(e) {
793
793
  return Object.values(U).includes(
794
794
  e
795
795
  );
796
796
  }
797
797
  function dt(e) {
798
- return !!e && Ke.has(e);
798
+ return !!e && Ve.has(e);
799
799
  }
800
- class Ve extends Error {
800
+ class Le extends Error {
801
801
  constructor(r, o) {
802
802
  super(`Refund not yet mature (BIP68 not final): ${o.message}`);
803
803
  x(this, "vaultId");
@@ -805,32 +805,40 @@ class Ve extends Error {
805
805
  this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = o;
806
806
  }
807
807
  }
808
- const Le = /^0x[0-9a-fA-F]{64}$/, De = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, F = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, Me = 160, Ue = 1, N = 65535, Fe = /non-BIP68-final/i;
809
- function W(e, t) {
808
+ const De = /^0x[0-9a-fA-F]{64}$/, Me = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, F = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, W = 160;
809
+ function ht(e) {
810
+ if (!Number.isFinite(e) || e <= 0)
811
+ throw new Error(
812
+ `feeRateSatsVb must be a positive finite number, got ${e}`
813
+ );
814
+ return BigInt(Math.ceil(e * W));
815
+ }
816
+ const Ue = 1, N = 65535, Fe = /non-BIP68-final/i;
817
+ function X(e, t) {
810
818
  if (e.length !== 66)
811
819
  throw new Error(
812
820
  `${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
813
821
  );
814
- if (!Le.test(e))
822
+ if (!De.test(e))
815
823
  throw new Error(
816
824
  `${t} must contain only hex characters after the 0x prefix`
817
825
  );
818
826
  }
819
- function B(e, t) {
827
+ function _(e, t) {
820
828
  if (!Number.isInteger(e) || e < 0)
821
829
  throw new Error(`${t} must be a non-negative integer, got ${e}`);
822
830
  }
823
831
  function We(e) {
824
- if (W(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0 || e.htlcVout > N)
832
+ if (X(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0 || e.htlcVout > N)
825
833
  throw new Error(
826
834
  `htlcVout must be an integer 0-${N}, got ${e.htlcVout}`
827
835
  );
828
- if (B(e.offchainParamsVersion, "offchainParamsVersion"), B(e.appVaultKeepersVersion, "appVaultKeepersVersion"), B(
836
+ if (_(e.offchainParamsVersion, "offchainParamsVersion"), _(e.appVaultKeepersVersion, "appVaultKeepersVersion"), _(
829
837
  e.universalChallengersVersion,
830
838
  "universalChallengersVersion"
831
839
  ), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
832
840
  throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
833
- if (!De.test(e.unsignedPrePeginTxHex))
841
+ if (!Me.test(e.unsignedPrePeginTxHex))
834
842
  throw new Error(
835
843
  "unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
836
844
  );
@@ -864,7 +872,7 @@ function Xe(e) {
864
872
  );
865
873
  }
866
874
  function ze(e) {
867
- const t = te.fromHex(e);
875
+ const t = re.fromHex(e);
868
876
  try {
869
877
  t.finalizeAllInputs();
870
878
  } catch (r) {
@@ -874,7 +882,7 @@ function ze(e) {
874
882
  }
875
883
  return t.extractTransaction().toHex();
876
884
  }
877
- async function ht(e) {
885
+ async function pt(e) {
878
886
  const {
879
887
  vaultId: t,
880
888
  readVault: r,
@@ -884,39 +892,39 @@ async function ht(e) {
884
892
  broadcastTx: s,
885
893
  signal: a
886
894
  } = e;
887
- a == null || a.throwIfAborted(), W(t, "vaultId");
895
+ a == null || a.throwIfAborted(), X(t, "vaultId");
888
896
  const n = await r();
889
897
  We(n), a == null || a.throwIfAborted();
890
- const l = await o(n);
891
- if (Xe(l), a == null || a.throwIfAborted(), !Number.isFinite(i) || i <= 0)
898
+ const c = await o(n);
899
+ if (Xe(c), a == null || a.throwIfAborted(), !Number.isFinite(i) || i <= 0)
892
900
  throw new Error(`feeRate must be a positive number, got ${i}`);
893
- const d = BigInt(Math.ceil(i * Me));
901
+ const d = BigInt(Math.ceil(i * W));
894
902
  a == null || a.throwIfAborted();
895
- const h = m(
903
+ const h = w(
896
904
  n.depositorBtcPubkey
897
- ), { psbtHex: g } = await se({
905
+ ), { psbtHex: g } = await ie({
898
906
  prePeginParams: {
899
907
  depositorPubkey: h,
900
- vaultProviderPubkey: c(l.vaultProviderPubkey),
901
- vaultKeeperPubkeys: l.vaultKeeperPubkeys.map(c),
902
- universalChallengerPubkeys: l.universalChallengerPubkeys.map(c),
903
- hashlocks: [c(n.hashlock)],
904
- timelockRefund: l.timelockRefund,
908
+ vaultProviderPubkey: l(c.vaultProviderPubkey),
909
+ vaultKeeperPubkeys: c.vaultKeeperPubkeys.map(l),
910
+ universalChallengerPubkeys: c.universalChallengerPubkeys.map(l),
911
+ hashlocks: [l(n.hashlock)],
912
+ timelockRefund: c.timelockRefund,
905
913
  pegInAmounts: [n.amount],
906
- feeRate: l.feeRate,
907
- numLocalChallengers: l.numLocalChallengers,
908
- councilQuorum: l.councilQuorum,
909
- councilSize: l.councilSize,
910
- network: l.network
914
+ feeRate: c.feeRate,
915
+ numLocalChallengers: c.numLocalChallengers,
916
+ councilQuorum: c.councilQuorum,
917
+ councilSize: c.councilSize,
918
+ network: c.network
911
919
  },
912
- fundedPrePeginTxHex: c(n.unsignedPrePeginTxHex),
920
+ fundedPrePeginTxHex: l(n.unsignedPrePeginTxHex),
913
921
  htlcVout: n.htlcVout,
914
922
  refundFee: d,
915
923
  // buildRefundPsbt's top-level `hashlock` param is documented as "no 0x
916
924
  // prefix" and flows into the WASM HTLC connector derivation; a prefixed
917
925
  // value would derive the wrong refund script leaf and yield an
918
926
  // unspendable PSBT. Match the `hashlocks` array handling above.
919
- hashlock: c(n.hashlock)
927
+ hashlock: l(n.hashlock)
920
928
  });
921
929
  a == null || a.throwIfAborted();
922
930
  const P = b(
@@ -927,29 +935,31 @@ async function ht(e) {
927
935
  try {
928
936
  return await s(T);
929
937
  } catch (p) {
930
- throw p instanceof Error && Fe.test(p.message) ? new Ve(t, p) : p;
938
+ throw p instanceof Error && Fe.test(p.message) ? new Le(t, p) : p;
931
939
  }
932
940
  }
933
941
  export {
934
- Ve as B,
942
+ Le as B,
935
943
  U as C,
936
- Te as P,
944
+ Ee as P,
945
+ W as R,
937
946
  rt as a,
938
- ke as b,
947
+ Te as b,
939
948
  at as c,
940
949
  ut as d,
941
- $e as e,
942
- Ie as f,
943
- lt as g,
944
- ae as h,
950
+ Ie as e,
951
+ Re as f,
952
+ ct as g,
953
+ ue as h,
945
954
  st as i,
946
- ue as j,
947
- ct as k,
955
+ ce as j,
956
+ lt as k,
948
957
  dt as l,
949
- ht as m,
958
+ pt as m,
959
+ ht as n,
950
960
  nt as p,
951
961
  ot as s,
952
962
  it as v,
953
963
  D as w
954
964
  };
955
- //# sourceMappingURL=buildAndBroadcastRefund-BY6mYmFl.js.map
965
+ //# sourceMappingURL=buildAndBroadcastRefund-BRQaCQrJ.js.map