@babylonlabs-io/ts-sdk 0.33.6 → 0.33.8

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.
@@ -2,100 +2,100 @@ var M = Object.defineProperty;
2
2
  var U = (e, t, r) => t in e ? M(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
3
  var v = (e, t, r) => U(e, typeof t != "symbol" ? t + "" : t, r);
4
4
  import { B as F } from "./BTCVaultRegistry.abi-DbJ5lsFJ.js";
5
- import { e as X, s as c, u as R, p as m, f as h } from "./bitcoin-B0S8SHCX.js";
6
- import { v as z, P as G } from "./PayoutManager-C9XHKZ5j.js";
7
- import { c as Q, a as W, R as Y, d as $, D as b } from "./types-TiIjyo2b.js";
8
- import * as q from "bitcoinjs-lib";
9
- import { Transaction as y, Psbt as j } from "bitcoinjs-lib";
10
- import { Buffer as J } from "buffer";
11
- import { c as Z, a as ee, b as te } from "./noPayout-DBX6G96_.js";
12
- import { a as re, b as oe, e as A } from "./payout-BNFMBXS6.js";
5
+ import { e as X, v as z, s as c, u as R, p as m, f as h } from "./bitcoin-B0S8SHCX.js";
6
+ import { v as G, P as W } from "./PayoutManager-C9XHKZ5j.js";
7
+ import { c as Q, a as Y, R as q, d as $, D as b } from "./types-TiIjyo2b.js";
8
+ import * as j from "bitcoinjs-lib";
9
+ import { Transaction as y, Psbt as J } from "bitcoinjs-lib";
10
+ import { Buffer as Z } from "buffer";
11
+ import { c as ee, a as te, b as re } from "./noPayout-DBX6G96_.js";
12
+ import { a as oe, b as ne, e as A } from "./payout-BNFMBXS6.js";
13
13
  import { c as _ } from "./signing-DaLvGwQe.js";
14
- const ne = /^0x[0-9a-fA-F]{64}$/, ie = /^0x[0-9a-fA-F]{40}$/, se = /^0x([0-9a-fA-F]{2})*$/;
14
+ const ae = /^0x[0-9a-fA-F]{64}$/, ie = /^0x[0-9a-fA-F]{40}$/, se = /^0x([0-9a-fA-F]{2})*$/;
15
15
  function T(e, t) {
16
16
  if (e.length !== 66)
17
17
  throw new Error(
18
18
  `${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
19
19
  );
20
- if (!ne.test(e))
20
+ if (!ae.test(e))
21
21
  throw new Error(
22
22
  `${t} must contain only hex characters after the 0x prefix`
23
23
  );
24
24
  }
25
- function ae(e, t) {
25
+ function ue(e, t) {
26
26
  if (!ie.test(e))
27
27
  throw new Error(
28
28
  `${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
29
29
  );
30
30
  }
31
- function ue(e, t) {
31
+ function le(e, t) {
32
32
  if (!se.test(e))
33
33
  throw new Error(
34
34
  `${t} must be a 0x-prefixed hex string with an even number of hex chars`
35
35
  );
36
36
  }
37
- async function qe(e) {
37
+ async function je(e) {
38
38
  const {
39
39
  btcVaultRegistryAddress: t,
40
40
  vaultId: r,
41
41
  hashlock: o,
42
- activationMetadata: s,
42
+ activationMetadata: i,
43
43
  writeContract: u,
44
44
  signal: n
45
45
  } = e;
46
- n == null || n.throwIfAborted(), ae(t, "btcVaultRegistryAddress"), T(r, "vaultId");
47
- const a = X(e.secret);
48
- if (T(a, "secret"), o !== void 0 && (T(o, "hashlock"), !z(a, o)))
46
+ n == null || n.throwIfAborted(), ue(t, "btcVaultRegistryAddress"), T(r, "vaultId");
47
+ const s = X(e.secret);
48
+ if (T(s, "secret"), o !== void 0 && (T(o, "hashlock"), !G(s, o)))
49
49
  throw new Error(
50
50
  "Invalid secret: SHA256(secret) does not match the provided hashlock"
51
51
  );
52
- return ue(s, "activationMetadata"), u({
52
+ return le(i, "activationMetadata"), u({
53
53
  address: t,
54
54
  abi: F,
55
55
  functionName: "activateVaultWithSecret",
56
- args: [r, a, s]
56
+ args: [r, s, i]
57
57
  });
58
58
  }
59
- const le = 1e4;
59
+ const ce = 1e4;
60
60
  async function N(e) {
61
61
  const {
62
62
  statusReader: t,
63
63
  peginTxid: r,
64
64
  targetStatuses: o,
65
- timeoutMs: s,
66
- pollIntervalMs: u = le,
65
+ timeoutMs: i,
66
+ pollIntervalMs: u = ce,
67
67
  signal: n
68
- } = e, a = Date.now();
68
+ } = e, s = Date.now();
69
69
  for (; ; ) {
70
70
  if (n != null && n.aborted)
71
71
  throw new Error(
72
72
  `Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
73
73
  );
74
- if (Date.now() - a >= s)
74
+ if (Date.now() - s >= i)
75
75
  throw new Error(
76
- `Polling timeout after ${s}ms for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
76
+ `Polling timeout after ${i}ms for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
77
77
  );
78
78
  try {
79
- const i = await t.getPeginStatus(
79
+ const a = await t.getPeginStatus(
80
80
  { pegin_txid: r },
81
81
  n
82
82
  );
83
- if (i.pegin_txid.toLowerCase() !== r.toLowerCase())
83
+ if (a.pegin_txid.toLowerCase() !== r.toLowerCase())
84
84
  throw new Error(
85
- `getPeginStatus returned status for pegin ${i.pegin_txid.slice(0, 8)}…, requested ${r.slice(0, 8)}…`
85
+ `getPeginStatus returned status for pegin ${a.pegin_txid.slice(0, 8)}…, requested ${r.slice(0, 8)}…`
86
86
  );
87
- const l = i.status;
87
+ const l = a.status;
88
88
  if (o.has(l))
89
89
  return l;
90
90
  if (Q.has(l) && !o.has(l))
91
91
  throw new Error(
92
92
  `Pegin ${r.slice(0, 8)}… reached terminal status "${l}" while waiting for ${[...o].join(", ")}`
93
93
  );
94
- } catch (i) {
95
- if (!(i instanceof W && i.code === Y.NOT_FOUND || i instanceof Error && i.message.includes("PegIn not found")))
96
- throw i;
94
+ } catch (a) {
95
+ if (!(a instanceof Y && a.code === q.NOT_FOUND || a instanceof Error && a.message.includes("PegIn not found")))
96
+ throw a;
97
97
  }
98
- await new Promise((i, l) => {
98
+ await new Promise((a, l) => {
99
99
  const f = () => {
100
100
  clearTimeout(d), l(
101
101
  new Error(
@@ -103,45 +103,45 @@ async function N(e) {
103
103
  )
104
104
  );
105
105
  }, d = setTimeout(() => {
106
- n == null || n.removeEventListener("abort", f), i();
106
+ n == null || n.removeEventListener("abort", f), a();
107
107
  }, u);
108
108
  n == null || n.addEventListener("abort", f, { once: !0 });
109
109
  });
110
110
  }
111
111
  }
112
- const ce = 300 * 1e3, de = /* @__PURE__ */ new Set([
112
+ const de = 300 * 1e3, fe = /* @__PURE__ */ new Set([
113
113
  b.PENDING_DEPOSITOR_WOTS_PK,
114
114
  ...$
115
115
  ]);
116
- async function je(e) {
116
+ async function Je(e) {
117
117
  const {
118
118
  statusReader: t,
119
119
  wotsSubmitter: r,
120
120
  peginTxid: o,
121
- depositorPk: s,
121
+ depositorPk: i,
122
122
  wotsPublicKeys: u,
123
- timeoutMs: n = ce,
124
- signal: a
123
+ timeoutMs: n = de,
124
+ signal: s
125
125
  } = e;
126
- a == null || a.throwIfAborted();
127
- const i = await N({
126
+ s == null || s.throwIfAborted();
127
+ const a = await N({
128
128
  statusReader: t,
129
129
  peginTxid: o,
130
- targetStatuses: de,
130
+ targetStatuses: fe,
131
131
  timeoutMs: n,
132
- signal: a
132
+ signal: s
133
133
  });
134
- $.has(i) || (a == null || a.throwIfAborted(), await r.submitDepositorWotsKey(
134
+ $.has(a) || (s == null || s.throwIfAborted(), await r.submitDepositorWotsKey(
135
135
  {
136
136
  pegin_txid: o,
137
- depositor_pk: s,
137
+ depositor_pk: i,
138
138
  wots_public_keys: u
139
139
  },
140
- a
140
+ s
141
141
  ));
142
142
  }
143
143
  const B = 1;
144
- function fe(e, t, r) {
144
+ function pe(e, t, r) {
145
145
  const o = c(r).toLowerCase(), u = [e, ...t].map(
146
146
  (n) => c(n).toLowerCase()
147
147
  ).filter((n) => n !== o);
@@ -151,29 +151,29 @@ function fe(e, t, r) {
151
151
  );
152
152
  return u;
153
153
  }
154
- function pe(e, t) {
154
+ function he(e, t) {
155
155
  const r = e.ins[t];
156
156
  return R(new Uint8Array(r.hash).slice().reverse());
157
157
  }
158
- function k(e, t, r, o, s) {
158
+ function k(e, t, r, o, i) {
159
159
  const u = e.ins[t];
160
160
  if (u.index !== 0)
161
161
  throw new Error(
162
- `NoPayout (challenger ${s}) input ${t} expected to spend ${o} vout 0, got vout ${u.index}`
162
+ `NoPayout (challenger ${i}) input ${t} expected to spend ${o} vout 0, got vout ${u.index}`
163
163
  );
164
- const n = r.getId(), a = pe(e, t);
165
- if (a !== n)
164
+ const n = r.getId(), s = he(e, t);
165
+ if (s !== n)
166
166
  throw new Error(
167
- `NoPayout (challenger ${s}) input ${t} does not reference ${o} (expected txid ${n}, got ${a})`
167
+ `NoPayout (challenger ${i}) input ${t} does not reference ${o} (expected txid ${n}, got ${s})`
168
168
  );
169
169
  }
170
- async function he(e, t, r) {
171
- const o = [], s = [], u = [];
172
- re(
170
+ async function ge(e, t, r) {
171
+ const o = [], i = [], u = [];
172
+ oe(
173
173
  e.payout_tx.tx_hex,
174
174
  r.registeredPayoutScriptPubKey
175
175
  );
176
- const n = await oe({
176
+ const n = await ne({
177
177
  payoutTxHex: e.payout_tx.tx_hex,
178
178
  peginTxHex: r.peginTxHex,
179
179
  assertTxHex: e.assert_tx.tx_hex,
@@ -184,29 +184,29 @@ async function he(e, t, r) {
184
184
  timelockPegin: r.timelockPegin,
185
185
  network: r.network
186
186
  });
187
- o.push(n.psbtHex), s.push(
187
+ o.push(n.psbtHex), i.push(
188
188
  _(
189
189
  t,
190
190
  B
191
191
  )
192
192
  );
193
- const a = fe(
193
+ const s = pe(
194
194
  r.vaultProviderBtcPubkey,
195
195
  r.vaultKeeperBtcPubkeys,
196
196
  r.depositorBtcPubkey
197
- ), i = c(r.depositorBtcPubkey), l = y.fromHex(
197
+ ), a = c(r.depositorBtcPubkey), l = y.fromHex(
198
198
  c(e.assert_tx.tx_hex)
199
199
  );
200
200
  for (const f of e.challenger_presign_data) {
201
- const d = c(f.challenger_pubkey), g = o.length, P = await ge({
201
+ const d = c(f.challenger_pubkey), g = o.length, P = await Pe({
202
202
  challenger: f,
203
203
  challengerPubkey: d,
204
- claimerPubkey: i,
205
- localChallengers: a,
204
+ claimerPubkey: a,
205
+ localChallengers: s,
206
206
  assertTxParsed: l,
207
207
  ctx: r
208
208
  });
209
- o.push(P), s.push(
209
+ o.push(P), i.push(
210
210
  _(
211
211
  t,
212
212
  B
@@ -216,47 +216,47 @@ async function he(e, t, r) {
216
216
  noPayoutIdx: g
217
217
  });
218
218
  }
219
- return { psbtHexes: o, signOptions: s, challengerEntries: u };
219
+ return { psbtHexes: o, signOptions: i, challengerEntries: u };
220
220
  }
221
- async function ge(e) {
221
+ async function Pe(e) {
222
222
  const {
223
223
  challenger: t,
224
224
  challengerPubkey: r,
225
225
  claimerPubkey: o,
226
- localChallengers: s,
226
+ localChallengers: i,
227
227
  assertTxParsed: u,
228
228
  ctx: n
229
229
  } = e;
230
- Z(
230
+ ee(
231
231
  t.nopayout_tx.tx_hex,
232
232
  r,
233
233
  n.network
234
234
  );
235
- const a = y.fromHex(
235
+ const s = y.fromHex(
236
236
  c(t.nopayout_tx.tx_hex)
237
- ), i = y.fromHex(
237
+ ), a = y.fromHex(
238
238
  c(t.challenge_assert_x_tx.tx_hex)
239
239
  ), l = y.fromHex(
240
240
  c(t.challenge_assert_y_tx.tx_hex)
241
241
  );
242
- if (a.ins.length !== 3)
242
+ if (s.ins.length !== 3)
243
243
  throw new Error(
244
- `NoPayout (challenger ${r}) must have exactly 3 inputs, got ${a.ins.length}`
244
+ `NoPayout (challenger ${r}) must have exactly 3 inputs, got ${s.ins.length}`
245
245
  );
246
246
  k(
247
- a,
247
+ s,
248
248
  0,
249
249
  u,
250
250
  "Assert",
251
251
  r
252
252
  ), k(
253
- a,
253
+ s,
254
254
  1,
255
- i,
255
+ a,
256
256
  "ChallengeAssertX",
257
257
  r
258
258
  ), k(
259
- a,
259
+ s,
260
260
  2,
261
261
  l,
262
262
  "ChallengeAssertY",
@@ -264,19 +264,19 @@ async function ge(e) {
264
264
  );
265
265
  const f = [
266
266
  u.outs[0],
267
- i.outs[0],
267
+ a.outs[0],
268
268
  l.outs[0]
269
269
  ].map((d) => ({
270
270
  script_pubkey: R(new Uint8Array(d.script)),
271
271
  value: d.value
272
272
  }));
273
- return ee({
273
+ return te({
274
274
  noPayoutTxHex: t.nopayout_tx.tx_hex,
275
275
  challengerPubkey: r,
276
276
  prevouts: f,
277
277
  connectorParams: {
278
278
  claimer: o,
279
- localChallengers: s,
279
+ localChallengers: i,
280
280
  universalChallengers: n.universalChallengerBtcPubkeys,
281
281
  timelockAssert: n.timelockAssert,
282
282
  councilMembers: n.councilMembers,
@@ -284,13 +284,13 @@ async function ge(e) {
284
284
  }
285
285
  });
286
286
  }
287
- function Pe(e, t, r) {
287
+ function be(e, t, r) {
288
288
  const o = A(
289
289
  e[0],
290
290
  r
291
- ), s = {};
291
+ ), i = {};
292
292
  for (const u of t)
293
- s[u.challengerPubkey] = {
293
+ i[u.challengerPubkey] = {
294
294
  nopayout_signature: A(
295
295
  e[u.noPayoutIdx],
296
296
  r
@@ -300,75 +300,78 @@ function Pe(e, t, r) {
300
300
  payout_signatures: {
301
301
  payout_signature: o
302
302
  },
303
- per_challenger: s
303
+ per_challenger: i
304
304
  };
305
305
  }
306
- async function be(e, t, r) {
306
+ async function ye(e, t, r) {
307
307
  if (typeof e.signPsbts == "function")
308
308
  return e.signPsbts(t, r);
309
309
  const o = [];
310
- for (let s = 0; s < t.length; s++)
311
- o.push(await e.signPsbt(t[s], r == null ? void 0 : r[s]));
310
+ for (let i = 0; i < t.length; i++)
311
+ o.push(await e.signPsbt(t[i], r == null ? void 0 : r[i]));
312
312
  return o;
313
313
  }
314
- async function ye(e) {
315
- const { depositorGraph: t, btcWallet: r, signingContext: o } = e, s = c(o.depositorBtcPubkey), u = await r.getPublicKeyHex(), { psbtHexes: n, signOptions: a, challengerEntries: i } = await he(
314
+ async function me(e) {
315
+ const { depositorGraph: t, btcWallet: r, signingContext: o } = e, i = await r.getPublicKeyHex(), { depositorPubkey: u } = z(
316
+ i,
317
+ c(o.depositorBtcPubkey)
318
+ ), { psbtHexes: n, signOptions: s, challengerEntries: a } = await ge(
316
319
  t,
317
- u,
320
+ i,
318
321
  o
319
- ), l = await be(
322
+ ), l = await ye(
320
323
  r,
321
324
  n,
322
- a
325
+ s
323
326
  );
324
327
  if (l.length !== n.length)
325
328
  throw new Error(
326
329
  `Wallet returned ${l.length} signed PSBTs, expected ${n.length}`
327
330
  );
328
- return Pe(
331
+ return be(
329
332
  l,
330
- i,
331
- s
333
+ a,
334
+ u
332
335
  );
333
336
  }
334
- const me = 1200 * 1e3, H = /* @__PURE__ */ new Set([
337
+ const we = 1200 * 1e3, H = /* @__PURE__ */ new Set([
335
338
  b.PENDING_ACKS,
336
339
  b.PENDING_ACTIVATION,
337
340
  b.ACTIVATED
338
- ]), we = /* @__PURE__ */ new Set([
341
+ ]), xe = /* @__PURE__ */ new Set([
339
342
  b.PENDING_DEPOSITOR_SIGNATURES,
340
343
  ...H
341
344
  ]);
342
- function xe(e) {
345
+ function ve(e) {
343
346
  return e.map((t) => ({
344
347
  claimerPubkeyXOnly: m(t.claimer_pubkey),
345
348
  payoutTxHex: t.payout_tx.tx_hex,
346
349
  assertTxHex: t.assert_tx.tx_hex
347
350
  }));
348
351
  }
349
- function ve(e) {
350
- const { output: t } = q.payments.p2tr({
351
- internalPubkey: J.from(e, "hex")
352
+ function Te(e) {
353
+ const { output: t } = j.payments.p2tr({
354
+ internalPubkey: Z.from(e, "hex")
352
355
  });
353
356
  if (!t)
354
357
  throw new Error("Failed to derive BIP-86 P2TR scriptPubKey");
355
358
  return t.toString("hex");
356
359
  }
357
- function Te(e, t) {
360
+ function ke(e, t) {
358
361
  const r = c(e).toLowerCase(), o = c(
359
362
  t.vaultProviderBtcPubkey
360
- ).toLowerCase(), s = c(
363
+ ).toLowerCase(), i = c(
361
364
  t.depositorBtcPubkey
362
365
  ).toLowerCase();
363
- if (r === o || r === s)
366
+ if (r === o || r === i)
364
367
  return t.registeredPayoutScriptPubKey;
365
368
  if (!t.vaultKeeperBtcPubkeys.some(
366
- (a) => c(a).toLowerCase() === r
369
+ (s) => c(s).toLowerCase() === r
367
370
  ))
368
371
  throw new Error(
369
372
  `Unknown claimer pubkey ${r}: not VP, depositor, or a registered vault keeper`
370
373
  );
371
- return `0x${ve(r)}`;
374
+ return `0x${Te(r)}`;
372
375
  }
373
376
  function C(e, t) {
374
377
  return {
@@ -380,79 +383,79 @@ function C(e, t) {
380
383
  universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys,
381
384
  depositorBtcPubkey: t.depositorBtcPubkey,
382
385
  timelockPegin: t.timelockPegin,
383
- registeredPayoutScriptPubKey: Te(
386
+ registeredPayoutScriptPubKey: ke(
384
387
  e.claimerPubkeyXOnly,
385
388
  t
386
389
  )
387
390
  };
388
391
  }
389
- async function ke(e, t, r, o) {
390
- const s = new G({
392
+ async function Ee(e, t, r, o) {
393
+ const i = new W({
391
394
  network: t.network,
392
395
  btcWallet: e
393
396
  }), u = r.length;
394
397
  o == null || o(0, u);
395
398
  let n;
396
- if (s.supportsBatchSigning())
397
- n = (await s.signPayoutTransactionsBatch(
399
+ if (i.supportsBatchSigning())
400
+ n = (await i.signPayoutTransactionsBatch(
398
401
  r.map((l) => C(l, t))
399
402
  )).map((l) => l.payoutSignature);
400
403
  else {
401
404
  n = [];
402
- for (let i = 0; i < r.length; i++) {
403
- o == null || o(i, u);
404
- const l = await s.signPayoutTransaction(
405
- C(r[i], t)
405
+ for (let a = 0; a < r.length; a++) {
406
+ o == null || o(a, u);
407
+ const l = await i.signPayoutTransaction(
408
+ C(r[a], t)
406
409
  );
407
410
  n.push(l.signature);
408
411
  }
409
412
  }
410
- const a = {};
411
- for (let i = 0; i < r.length; i++)
412
- a[r[i].claimerPubkeyXOnly] = {
413
- payout_signature: n[i]
413
+ const s = {};
414
+ for (let a = 0; a < r.length; a++)
415
+ s[r[a].claimerPubkeyXOnly] = {
416
+ payout_signature: n[a]
414
417
  };
415
- return o == null || o(u, u), a;
418
+ return o == null || o(u, u), s;
416
419
  }
417
- async function Je(e) {
420
+ async function Ze(e) {
418
421
  const {
419
422
  statusReader: t,
420
423
  presignClient: r,
421
424
  btcWallet: o,
422
- peginTxid: s,
425
+ peginTxid: i,
423
426
  depositorPk: u,
424
427
  signingContext: n,
425
- timeoutMs: a = me,
426
- signal: i,
428
+ timeoutMs: s = we,
429
+ signal: a,
427
430
  onProgress: l
428
431
  } = e, f = await N({
429
432
  statusReader: t,
430
- peginTxid: s,
431
- targetStatuses: we,
432
- timeoutMs: a,
433
- signal: i
433
+ peginTxid: i,
434
+ targetStatuses: xe,
435
+ timeoutMs: s,
436
+ signal: a
434
437
  });
435
438
  if (H.has(f))
436
439
  return;
437
- i == null || i.throwIfAborted();
440
+ a == null || a.throwIfAborted();
438
441
  const d = await r.requestDepositorPresignTransactions(
439
442
  {
440
- pegin_txid: s,
443
+ pegin_txid: i,
441
444
  depositor_pk: u
442
445
  },
443
- i
446
+ a
444
447
  );
445
- i == null || i.throwIfAborted();
448
+ a == null || a.throwIfAborted();
446
449
  const g = m(u), P = d.txs.filter(
447
450
  (K) => m(K.claimer_pubkey) !== g
448
- ), w = xe(P), x = await ke(
451
+ ), w = ve(P), x = await Ee(
449
452
  o,
450
453
  n,
451
454
  w,
452
455
  l
453
456
  );
454
- i == null || i.throwIfAborted();
455
- const p = await ye({
457
+ a == null || a.throwIfAborted();
458
+ const p = await me({
456
459
  depositorGraph: d.depositor_graph,
457
460
  btcWallet: o,
458
461
  signingContext: {
@@ -469,33 +472,33 @@ async function Je(e) {
469
472
  registeredPayoutScriptPubKey: n.registeredPayoutScriptPubKey
470
473
  }
471
474
  });
472
- i == null || i.throwIfAborted();
475
+ a == null || a.throwIfAborted();
473
476
  const S = { ...x };
474
477
  S[c(u)] = p.payout_signatures, await r.submitDepositorPresignatures(
475
478
  {
476
- pegin_txid: s,
479
+ pegin_txid: i,
477
480
  depositor_pk: u,
478
481
  signatures: S,
479
482
  depositor_claimer_presignatures: p
480
483
  },
481
- i
484
+ a
482
485
  );
483
486
  }
484
- function Ee(e) {
487
+ function _e(e) {
485
488
  return /^[0-9a-fA-F]{64}$/.test(e);
486
489
  }
487
- function Ze(e) {
490
+ function et(e) {
488
491
  const {
489
492
  amountSats: t,
490
493
  minDeposit: r,
491
494
  maxDeposit: o,
492
- btcBalance: s,
495
+ btcBalance: i,
493
496
  estimatedFeeSats: u,
494
497
  depositorClaimValue: n
495
498
  } = e;
496
- return !(t <= 0n || t < r || o && o > 0n && t > o || u == null || n == null || t + u + n > s);
499
+ return !(t <= 0n || t < r || o && o > 0n && t > o || u == null || n == null || t + u + n > i);
497
500
  }
498
- function et(e, t, r) {
501
+ function tt(e, t, r) {
499
502
  return e <= 0n ? {
500
503
  valid: !1,
501
504
  error: "Deposit amount must be greater than zero"
@@ -507,7 +510,7 @@ function et(e, t, r) {
507
510
  error: `Maximum deposit is ${h(r)} BTC`
508
511
  } : { valid: !0 };
509
512
  }
510
- function tt(e) {
513
+ function rt(e) {
511
514
  const { amount: t, effectiveRemaining: r } = e;
512
515
  return r === null ? { valid: !0 } : r === 0n ? {
513
516
  valid: !1,
@@ -517,107 +520,107 @@ function tt(e) {
517
520
  error: `Vault size exceeds remaining capacity (${h(r)} BTC)`
518
521
  } : { valid: !0 };
519
522
  }
520
- function rt(e, t) {
523
+ function ot(e, t) {
521
524
  if (!e || e.length === 0)
522
525
  return {
523
526
  valid: !1,
524
527
  error: "At least one vault provider must be selected"
525
528
  };
526
529
  const r = t.map(
527
- (s) => s.toLowerCase()
530
+ (i) => i.toLowerCase()
528
531
  );
529
532
  return e.filter(
530
- (s) => !r.includes(s.toLowerCase())
533
+ (i) => !r.includes(i.toLowerCase())
531
534
  ).length > 0 ? {
532
535
  valid: !1,
533
536
  error: "Invalid vault provider selected"
534
537
  } : { valid: !0 };
535
538
  }
536
- function _e(e, t, r) {
539
+ function Se(e, t, r) {
537
540
  if (!e || e.length === 0)
538
541
  return {
539
542
  valid: !1,
540
543
  error: "At least one vault amount required"
541
544
  };
542
545
  for (let o = 0; o < e.length; o++) {
543
- const s = e[o];
544
- if (s <= 0n)
546
+ const i = e[o];
547
+ if (i <= 0n)
545
548
  return {
546
549
  valid: !1,
547
550
  error: `Vault ${o + 1} amount must be positive`
548
551
  };
549
- if (t && s < t)
552
+ if (t && i < t)
550
553
  return {
551
554
  valid: !1,
552
- error: `Vault ${o + 1} amount ${h(s)} BTC is below minimum deposit ${h(t)} BTC`
555
+ error: `Vault ${o + 1} amount ${h(i)} BTC is below minimum deposit ${h(t)} BTC`
553
556
  };
554
- if (r && s > r)
557
+ if (r && i > r)
555
558
  return {
556
559
  valid: !1,
557
- error: `Vault ${o + 1} amount ${h(s)} BTC exceeds maximum deposit ${h(r)} BTC`
560
+ error: `Vault ${o + 1} amount ${h(i)} BTC exceeds maximum deposit ${h(r)} BTC`
558
561
  };
559
562
  }
560
563
  return { valid: !0 };
561
564
  }
562
- function Se(e) {
565
+ function Ae(e) {
563
566
  const t = c(e);
564
- return Ee(t) ? { valid: !0 } : {
567
+ return _e(t) ? { valid: !0 } : {
565
568
  valid: !1,
566
569
  error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
567
570
  };
568
571
  }
569
- function Ae(e) {
572
+ function Be(e) {
570
573
  if (!e || e.length === 0)
571
574
  throw new Error(
572
575
  "No vault keepers available. The system requires at least one vault keeper to create a deposit."
573
576
  );
574
577
  }
575
- function Be(e) {
578
+ function Ce(e) {
576
579
  if (!e || e.length === 0)
577
580
  throw new Error(
578
581
  "No universal challengers available. The system requires at least one universal challenger to create a deposit."
579
582
  );
580
583
  }
581
- function Ce(e) {
584
+ function Ie(e) {
582
585
  if (e.length === 0)
583
586
  throw new Error("No spendable UTXOs available");
584
587
  }
585
- function ot(e) {
588
+ function nt(e) {
586
589
  const {
587
590
  vaultAmounts: t,
588
591
  confirmedUTXOs: r,
589
592
  vaultProviderBtcPubkey: o,
590
- vaultKeeperBtcPubkeys: s,
593
+ vaultKeeperBtcPubkeys: i,
591
594
  universalChallengerBtcPubkeys: u,
592
595
  minDeposit: n,
593
- maxDeposit: a
594
- } = e, i = _e(
596
+ maxDeposit: s
597
+ } = e, a = Se(
595
598
  t,
596
599
  n,
597
- a
600
+ s
598
601
  );
599
- if (!i.valid)
600
- throw new Error(i.error);
601
- const l = Se(o);
602
+ if (!a.valid)
603
+ throw new Error(a.error);
604
+ const l = Ae(o);
602
605
  if (!l.valid)
603
606
  throw new Error(l.error);
604
- Ae(s), Be(u), Ce(r);
607
+ Be(i), Ce(u), Ie(r);
605
608
  }
606
609
  var O = /* @__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))(O || {});
607
- const Ie = /* @__PURE__ */ new Set([
610
+ const Re = /* @__PURE__ */ new Set([
608
611
  "PayoutBroadcast",
609
612
  "Failed"
610
613
  /* FAILED */
611
614
  ]);
612
- function nt(e) {
615
+ function at(e) {
613
616
  return Object.values(O).includes(
614
617
  e
615
618
  );
616
619
  }
617
620
  function it(e) {
618
- return !!e && Ie.has(e);
621
+ return !!e && Re.has(e);
619
622
  }
620
- class Re extends Error {
623
+ class $e extends Error {
621
624
  constructor(r, o) {
622
625
  super(`Refund not yet mature (BIP68 not final): ${o.message}`);
623
626
  v(this, "vaultId");
@@ -625,7 +628,7 @@ class Re extends Error {
625
628
  this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = o;
626
629
  }
627
630
  }
628
- const $e = /^0x[0-9a-fA-F]{64}$/, Ne = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, V = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, D = 160;
631
+ const Ne = /^0x[0-9a-fA-F]{64}$/, He = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, V = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, D = 160;
629
632
  function st(e) {
630
633
  if (!Number.isFinite(e) || e <= 0)
631
634
  throw new Error(
@@ -633,13 +636,13 @@ function st(e) {
633
636
  );
634
637
  return BigInt(Math.ceil(e * D));
635
638
  }
636
- const He = 1, I = 65535, Oe = /non-BIP68-final/i;
639
+ const Oe = 1, I = 65535, Ve = /non-BIP68-final/i;
637
640
  function L(e, t) {
638
641
  if (e.length !== 66)
639
642
  throw new Error(
640
643
  `${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
641
644
  );
642
- if (!$e.test(e))
645
+ if (!Ne.test(e))
643
646
  throw new Error(
644
647
  `${t} must contain only hex characters after the 0x prefix`
645
648
  );
@@ -648,7 +651,7 @@ function E(e, t) {
648
651
  if (!Number.isInteger(e) || e < 0)
649
652
  throw new Error(`${t} must be a non-negative integer, got ${e}`);
650
653
  }
651
- function Ve(e) {
654
+ function De(e) {
652
655
  if (L(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0 || e.htlcVout > I)
653
656
  throw new Error(
654
657
  `htlcVout must be an integer 0-${I}, got ${e.htlcVout}`
@@ -658,7 +661,7 @@ function Ve(e) {
658
661
  "universalChallengersVersion"
659
662
  ), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
660
663
  throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
661
- if (!Ne.test(e.unsignedPrePeginTxHex))
664
+ if (!He.test(e.unsignedPrePeginTxHex))
662
665
  throw new Error(
663
666
  "unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
664
667
  );
@@ -669,7 +672,7 @@ function Ve(e) {
669
672
  if (typeof e.amount != "bigint" || e.amount <= 0n)
670
673
  throw new Error(`amount must be a positive bigint, got ${e.amount}`);
671
674
  }
672
- function De(e) {
675
+ function Le(e) {
673
676
  if (!e.vaultProviderPubkey || !V.test(e.vaultProviderPubkey))
674
677
  throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
675
678
  if (e.vaultKeeperPubkeys.length === 0)
@@ -691,8 +694,8 @@ function De(e) {
691
694
  `councilQuorum (${e.councilQuorum}) must be in [1, councilSize=${e.councilSize}]`
692
695
  );
693
696
  }
694
- function Le(e) {
695
- const t = j.fromHex(e);
697
+ function Ke(e) {
698
+ const t = J.fromHex(e);
696
699
  try {
697
700
  t.finalizeAllInputs();
698
701
  } catch (r) {
@@ -702,81 +705,81 @@ function Le(e) {
702
705
  }
703
706
  return t.extractTransaction().toHex();
704
707
  }
705
- async function at(e) {
708
+ async function ut(e) {
706
709
  const {
707
710
  vaultId: t,
708
711
  readVault: r,
709
712
  readPrePeginContext: o,
710
- feeRate: s,
713
+ feeRate: i,
711
714
  signPsbt: u,
712
715
  broadcastTx: n,
713
- signal: a
716
+ signal: s
714
717
  } = e;
715
- a == null || a.throwIfAborted(), L(t, "vaultId");
716
- const i = await r();
717
- Ve(i), a == null || a.throwIfAborted();
718
- const l = await o(i);
719
- if (De(l), a == null || a.throwIfAborted(), !Number.isFinite(s) || s <= 0)
720
- throw new Error(`feeRate must be a positive number, got ${s}`);
721
- const f = BigInt(Math.ceil(s * D));
722
- a == null || a.throwIfAborted();
718
+ s == null || s.throwIfAborted(), L(t, "vaultId");
719
+ const a = await r();
720
+ De(a), s == null || s.throwIfAborted();
721
+ const l = await o(a);
722
+ if (Le(l), s == null || s.throwIfAborted(), !Number.isFinite(i) || i <= 0)
723
+ throw new Error(`feeRate must be a positive number, got ${i}`);
724
+ const f = BigInt(Math.ceil(i * D));
725
+ s == null || s.throwIfAborted();
723
726
  const d = m(
724
- i.depositorBtcPubkey
725
- ), { psbtHex: g } = await te({
727
+ a.depositorBtcPubkey
728
+ ), { psbtHex: g } = await re({
726
729
  prePeginParams: {
727
730
  depositorPubkey: d,
728
731
  vaultProviderPubkey: c(l.vaultProviderPubkey),
729
732
  vaultKeeperPubkeys: l.vaultKeeperPubkeys.map(c),
730
733
  universalChallengerPubkeys: l.universalChallengerPubkeys.map(c),
731
- hashlocks: [c(i.hashlock)],
734
+ hashlocks: [c(a.hashlock)],
732
735
  timelockRefund: l.timelockRefund,
733
- pegInAmounts: [i.amount],
736
+ pegInAmounts: [a.amount],
734
737
  feeRate: l.feeRate,
735
738
  numLocalChallengers: l.numLocalChallengers,
736
739
  councilQuorum: l.councilQuorum,
737
740
  councilSize: l.councilSize,
738
741
  network: l.network
739
742
  },
740
- fundedPrePeginTxHex: c(i.unsignedPrePeginTxHex),
741
- htlcVout: i.htlcVout,
743
+ fundedPrePeginTxHex: c(a.unsignedPrePeginTxHex),
744
+ htlcVout: a.htlcVout,
742
745
  refundFee: f,
743
746
  // buildRefundPsbt's top-level `hashlock` param is documented as "no 0x
744
747
  // prefix" and flows into the WASM HTLC connector derivation; a prefixed
745
748
  // value would derive the wrong refund script leaf and yield an
746
749
  // unspendable PSBT. Match the `hashlocks` array handling above.
747
- hashlock: c(i.hashlock)
750
+ hashlock: c(a.hashlock)
748
751
  });
749
- a == null || a.throwIfAborted();
752
+ s == null || s.throwIfAborted();
750
753
  const P = _(
751
- i.depositorBtcPubkey,
752
- He
753
- ), w = await u(g, P), x = Le(w);
754
- a == null || a.throwIfAborted();
754
+ a.depositorBtcPubkey,
755
+ Oe
756
+ ), w = await u(g, P), x = Ke(w);
757
+ s == null || s.throwIfAborted();
755
758
  try {
756
759
  return await n(x);
757
760
  } catch (p) {
758
- throw p instanceof Error && Oe.test(p.message) ? new Re(t, p) : p;
761
+ throw p instanceof Error && Ve.test(p.message) ? new $e(t, p) : p;
759
762
  }
760
763
  }
761
764
  export {
762
- Re as B,
765
+ $e as B,
763
766
  O as C,
764
767
  D as R,
765
- qe as a,
766
- ye as b,
767
- tt as c,
768
- rt as d,
769
- _e as e,
770
- Se as f,
771
- ot as g,
772
- nt as h,
773
- Ze as i,
768
+ je as a,
769
+ me as b,
770
+ rt as c,
771
+ ot as d,
772
+ Se as e,
773
+ Ae as f,
774
+ nt as g,
775
+ at as h,
776
+ et as i,
774
777
  it as j,
775
- at as k,
778
+ ut as k,
776
779
  st as l,
777
- Je as r,
778
- je as s,
779
- et as v,
780
+ Ze as r,
781
+ Je as s,
782
+ tt as v,
780
783
  N as w
781
784
  };
782
- //# sourceMappingURL=buildAndBroadcastRefund-CPjXNaMi.js.map
785
+ //# sourceMappingURL=buildAndBroadcastRefund-B6fGRmvo.js.map