@babylonlabs-io/ts-sdk 0.39.3 → 0.40.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 (69) hide show
  1. package/dist/{PayoutManager-DnKRzWWb.cjs → PayoutManager-B5bovfkD.cjs} +2 -2
  2. package/dist/{PayoutManager-DnKRzWWb.cjs.map → PayoutManager-B5bovfkD.cjs.map} +1 -1
  3. package/dist/{PayoutManager-2XpjdLxE.js → PayoutManager-DChODEOJ.js} +2 -2
  4. package/dist/{PayoutManager-2XpjdLxE.js.map → PayoutManager-DChODEOJ.js.map} +1 -1
  5. package/dist/{PeginManager-CBQnWvX8.js → PeginManager-D9ZZ8wx2.js} +84 -82
  6. package/dist/PeginManager-D9ZZ8wx2.js.map +1 -0
  7. package/dist/{PeginManager-CPw28lAE.cjs → PeginManager-UqbOj2oV.cjs} +2 -2
  8. package/dist/PeginManager-UqbOj2oV.cjs.map +1 -0
  9. package/dist/{assertPsbtUnsignedTxMatches-CsawQGjC.js → assertPsbtUnsignedTxMatches-CzVv57QF.js} +12 -10
  10. package/dist/assertPsbtUnsignedTxMatches-CzVv57QF.js.map +1 -0
  11. package/dist/assertPsbtUnsignedTxMatches-r1svclbd.cjs +2 -0
  12. package/dist/assertPsbtUnsignedTxMatches-r1svclbd.cjs.map +1 -0
  13. package/dist/buildAndBroadcastRefund-Cj8JDI7F.cjs +2 -0
  14. package/dist/{buildAndBroadcastRefund-MoSpjUKJ.cjs.map → buildAndBroadcastRefund-Cj8JDI7F.cjs.map} +1 -1
  15. package/dist/{buildAndBroadcastRefund-BRMB7XyC.js → buildAndBroadcastRefund-fIHDHiFh.js} +345 -301
  16. package/dist/{buildAndBroadcastRefund-BRMB7XyC.js.map → buildAndBroadcastRefund-fIHDHiFh.js.map} +1 -1
  17. package/dist/{challengeAssert-D8-RwiDv.js → challengeAssert-DLEmAhT0.js} +2 -2
  18. package/dist/{challengeAssert-D8-RwiDv.js.map → challengeAssert-DLEmAhT0.js.map} +1 -1
  19. package/dist/{challengeAssert-BobHj1La.cjs → challengeAssert-rpDaS3fH.cjs} +2 -2
  20. package/dist/{challengeAssert-BobHj1La.cjs.map → challengeAssert-rpDaS3fH.cjs.map} +1 -1
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.js +78 -77
  23. package/dist/{mempoolApi-CAIge7Nj.js → mempoolApi-C7hkVkym.js} +31 -22
  24. package/dist/mempoolApi-C7hkVkym.js.map +1 -0
  25. package/dist/mempoolApi-DEAS9wVa.cjs +2 -0
  26. package/dist/mempoolApi-DEAS9wVa.cjs.map +1 -0
  27. package/dist/noPayout-B06Z9RTe.cjs +2 -0
  28. package/dist/noPayout-B06Z9RTe.cjs.map +1 -0
  29. package/dist/noPayout-CS2wnluA.js +154 -0
  30. package/dist/noPayout-CS2wnluA.js.map +1 -0
  31. package/dist/tbv/core/clients/index.cjs +1 -1
  32. package/dist/tbv/core/clients/index.js +33 -32
  33. package/dist/tbv/core/clients/mempool/index.d.ts +1 -1
  34. package/dist/tbv/core/clients/mempool/index.d.ts.map +1 -1
  35. package/dist/tbv/core/clients/mempool/mempoolApi.d.ts +11 -0
  36. package/dist/tbv/core/clients/mempool/mempoolApi.d.ts.map +1 -1
  37. package/dist/tbv/core/index.cjs +1 -1
  38. package/dist/tbv/core/index.js +78 -77
  39. package/dist/tbv/core/managers/PeginManager.d.ts +7 -2
  40. package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
  41. package/dist/tbv/core/managers/index.cjs +1 -1
  42. package/dist/tbv/core/managers/index.js +2 -2
  43. package/dist/tbv/core/primitives/index.cjs +1 -1
  44. package/dist/tbv/core/primitives/index.js +3 -3
  45. package/dist/tbv/core/primitives/psbt/pegin.d.ts +3 -1
  46. package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
  47. package/dist/tbv/core/primitives/psbt/refund.d.ts.map +1 -1
  48. package/dist/tbv/core/services/index.cjs +1 -1
  49. package/dist/tbv/core/services/index.js +2 -2
  50. package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts +27 -0
  51. package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts.map +1 -1
  52. package/dist/tbv/core/services/refund/index.d.ts +1 -1
  53. package/dist/tbv/core/services/refund/index.d.ts.map +1 -1
  54. package/dist/tbv/index.cjs +1 -1
  55. package/dist/tbv/index.js +78 -77
  56. package/package.json +1 -1
  57. package/dist/PeginManager-CBQnWvX8.js.map +0 -1
  58. package/dist/PeginManager-CPw28lAE.cjs.map +0 -1
  59. package/dist/assertPsbtUnsignedTxMatches-CsawQGjC.js.map +0 -1
  60. package/dist/assertPsbtUnsignedTxMatches-u9yeeUFY.cjs +0 -2
  61. package/dist/assertPsbtUnsignedTxMatches-u9yeeUFY.cjs.map +0 -1
  62. package/dist/buildAndBroadcastRefund-MoSpjUKJ.cjs +0 -2
  63. package/dist/mempoolApi-CAIge7Nj.js.map +0 -1
  64. package/dist/mempoolApi-YNkKjQCU.cjs +0 -2
  65. package/dist/mempoolApi-YNkKjQCU.cjs.map +0 -1
  66. package/dist/noPayout-C5b34rs1.js +0 -145
  67. package/dist/noPayout-C5b34rs1.js.map +0 -1
  68. package/dist/noPayout-CtmOEauj.cjs +0 -2
  69. package/dist/noPayout-CtmOEauj.cjs.map +0 -1
@@ -1,33 +1,33 @@
1
1
  var W = Object.defineProperty;
2
2
  var Y = (e, t, r) => t in e ? W(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var C = (e, t, r) => Y(e, typeof t != "symbol" ? t + "" : t, r);
3
+ var A = (e, t, r) => Y(e, typeof t != "symbol" ? t + "" : t, r);
4
4
  import { B as J } from "./BTCVaultRegistry.abi-Cq9-JlqT.js";
5
- import { e as Z, v as ee, s as p, u as M, p as S, f as w } from "./bitcoin-B5aNKtsk.js";
6
- import { v as te, P as re, f as ne } from "./PayoutManager-2XpjdLxE.js";
7
- import { D as y, c as oe, a as se, R as ae, d as L } from "./types-BqGAMOZM.js";
5
+ import { e as Z, v as ee, s as p, u as U, p as C, f as v } from "./bitcoin-B5aNKtsk.js";
6
+ import { v as te, P as re, f as ne } from "./PayoutManager-DChODEOJ.js";
7
+ import { D as y, c as oe, a as ae, R as se, d as L } from "./types-BqGAMOZM.js";
8
8
  import { Transaction as _, Psbt as ie } from "bitcoinjs-lib";
9
- import { c as ue, d as I, e as N } from "./assertPsbtUnsignedTxMatches-CsawQGjC.js";
10
- import { c as le, a as ce, b as de } from "./noPayout-C5b34rs1.js";
11
- import { c as V } from "./signing-DaLvGwQe.js";
12
- const pe = /^0x[0-9a-fA-F]{64}$/, he = /^0x[0-9a-fA-F]{40}$/, fe = /^0x([0-9a-fA-F]{2})*$/;
13
- function B(e, t) {
9
+ import { c as ue, d as V, e as H } from "./assertPsbtUnsignedTxMatches-CzVv57QF.js";
10
+ import { c as le, a as ce, b as he } from "./noPayout-CS2wnluA.js";
11
+ import { c as I } from "./signing-DaLvGwQe.js";
12
+ const de = /^0x[0-9a-fA-F]{64}$/, pe = /^0x[0-9a-fA-F]{40}$/, ge = /^0x([0-9a-fA-F]{2})*$/;
13
+ function $(e, t) {
14
14
  if (e.length !== 66)
15
15
  throw new Error(
16
16
  `${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
17
17
  );
18
- if (!pe.test(e))
18
+ if (!de.test(e))
19
19
  throw new Error(
20
20
  `${t} must contain only hex characters after the 0x prefix`
21
21
  );
22
22
  }
23
- function ge(e, t) {
24
- if (!he.test(e))
23
+ function fe(e, t) {
24
+ if (!pe.test(e))
25
25
  throw new Error(
26
26
  `${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
27
27
  );
28
28
  }
29
- function Pe(e, t) {
30
- if (!fe.test(e))
29
+ function me(e, t) {
30
+ if (!ge.test(e))
31
31
  throw new Error(
32
32
  `${t} must be a 0x-prefixed hex string with an even number of hex chars`
33
33
  );
@@ -37,46 +37,46 @@ async function ot(e) {
37
37
  btcVaultRegistryAddress: t,
38
38
  vaultId: r,
39
39
  hashlock: n,
40
- activationMetadata: s,
40
+ activationMetadata: a,
41
41
  writeContract: u,
42
- signal: a
42
+ signal: s
43
43
  } = e;
44
- a == null || a.throwIfAborted(), ge(t, "btcVaultRegistryAddress"), B(r, "vaultId");
44
+ s == null || s.throwIfAborted(), fe(t, "btcVaultRegistryAddress"), $(r, "vaultId");
45
45
  const i = Z(e.secret);
46
- if (B(i, "secret"), n !== void 0 && (B(n, "hashlock"), !te(i, n)))
46
+ if ($(i, "secret"), n !== void 0 && ($(n, "hashlock"), !te(i, n)))
47
47
  throw new Error(
48
48
  "Invalid secret: SHA256(secret) does not match the provided hashlock"
49
49
  );
50
- return Pe(s, "activationMetadata"), u({
50
+ return me(a, "activationMetadata"), u({
51
51
  address: t,
52
52
  abi: J,
53
53
  functionName: "activateVaultWithSecret",
54
- args: [r, i, s]
54
+ args: [r, i, a]
55
55
  });
56
56
  }
57
- const me = 1e4;
58
- async function F(e) {
57
+ const Pe = 1e4;
58
+ async function X(e) {
59
59
  const {
60
60
  statusReader: t,
61
61
  peginTxid: r,
62
62
  targetStatuses: n,
63
- timeoutMs: s,
64
- pollIntervalMs: u = me,
65
- signal: a
63
+ timeoutMs: a,
64
+ pollIntervalMs: u = Pe,
65
+ signal: s
66
66
  } = e, i = Date.now();
67
67
  for (; ; ) {
68
- if (a != null && a.aborted)
68
+ if (s != null && s.aborted)
69
69
  throw new Error(
70
70
  `Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...n].join(", ")})`
71
71
  );
72
- if (Date.now() - i >= s)
72
+ if (Date.now() - i >= a)
73
73
  throw new Error(
74
- `Polling timeout after ${s}ms for pegin ${r.slice(0, 8)}… (target: ${[...n].join(", ")})`
74
+ `Polling timeout after ${a}ms for pegin ${r.slice(0, 8)}… (target: ${[...n].join(", ")})`
75
75
  );
76
76
  try {
77
77
  const o = await t.getPeginStatus(
78
78
  { pegin_txid: r },
79
- a
79
+ s
80
80
  );
81
81
  if (o.pegin_txid.toLowerCase() !== r.toLowerCase())
82
82
  throw new Error(
@@ -90,112 +90,112 @@ async function F(e) {
90
90
  `Pegin ${r.slice(0, 8)}… reached terminal status "${l}" while waiting for ${[...n].join(", ")}`
91
91
  );
92
92
  } catch (o) {
93
- if (!(o instanceof se && o.code === ae.PEGIN_NOT_FOUND))
93
+ if (!(o instanceof ae && o.code === se.PEGIN_NOT_FOUND))
94
94
  throw o;
95
95
  }
96
96
  await new Promise((o, l) => {
97
- const d = () => {
97
+ const h = () => {
98
98
  clearTimeout(c), l(
99
99
  new Error(
100
100
  `Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...n].join(", ")})`
101
101
  )
102
102
  );
103
103
  }, c = setTimeout(() => {
104
- a == null || a.removeEventListener("abort", d), o();
104
+ s == null || s.removeEventListener("abort", h), o();
105
105
  }, u);
106
- a == null || a.addEventListener("abort", d, { once: !0 });
106
+ s == null || s.addEventListener("abort", h, { once: !0 });
107
107
  });
108
108
  }
109
109
  }
110
- const ye = 300 * 1e3, be = /* @__PURE__ */ new Set([
110
+ const be = 300 * 1e3, ye = /* @__PURE__ */ new Set([
111
111
  y.PENDING_DEPOSITOR_WOTS_PK,
112
112
  ...L
113
113
  ]);
114
- async function st(e) {
114
+ async function at(e) {
115
115
  const {
116
116
  statusReader: t,
117
117
  wotsSubmitter: r,
118
118
  peginTxid: n,
119
- depositorPk: s,
119
+ depositorPk: a,
120
120
  wotsPublicKeys: u,
121
- timeoutMs: a = ye,
121
+ timeoutMs: s = be,
122
122
  signal: i
123
123
  } = e;
124
124
  i == null || i.throwIfAborted();
125
- const o = await F({
125
+ const o = await X({
126
126
  statusReader: t,
127
127
  peginTxid: n,
128
- targetStatuses: be,
129
- timeoutMs: a,
128
+ targetStatuses: ye,
129
+ timeoutMs: s,
130
130
  signal: i
131
131
  });
132
132
  L.has(o) || (i == null || i.throwIfAborted(), await r.submitDepositorWotsKey(
133
133
  {
134
134
  pegin_txid: n,
135
- depositor_pk: s,
135
+ depositor_pk: a,
136
136
  wots_public_keys: u
137
137
  },
138
138
  i
139
139
  ));
140
140
  }
141
- const O = 1, ve = 1;
142
- function we(e, t) {
143
- const r = p(t).toLowerCase(), s = e.map((u) => p(u).toLowerCase()).filter((u) => u !== r);
144
- if (s.length === 0)
141
+ const O = 1, we = 1;
142
+ function xe(e, t) {
143
+ const r = p(t).toLowerCase(), a = e.map((u) => p(u).toLowerCase()).filter((u) => u !== r);
144
+ if (a.length === 0)
145
145
  throw new Error(
146
146
  "Cannot derive localChallengers: vault keeper set is empty (or contains only the depositor)"
147
147
  );
148
- if (new Set(s).size !== s.length)
148
+ if (new Set(a).size !== a.length)
149
149
  throw new Error(
150
150
  "Cannot derive localChallengers: duplicate vaultKeeper key — signing context is misconfigured"
151
151
  );
152
- return s;
152
+ return a;
153
153
  }
154
- function xe(e, t, r) {
154
+ function ve(e, t, r) {
155
155
  const n = r.map(
156
156
  (c) => p(c).toLowerCase()
157
- ), s = t.filter((c) => n.includes(c));
158
- if (s.length > 0)
157
+ ), a = t.filter((c) => n.includes(c));
158
+ if (a.length > 0)
159
159
  throw new Error(
160
- `Cannot validate challenger set: vault keepers and universal challengers overlap (${s.join(", ")})`
160
+ `Cannot validate challenger set: vault keepers and universal challengers overlap (${a.join(", ")})`
161
161
  );
162
- const u = [...t, ...n], a = e.map(
162
+ const u = [...t, ...n], s = e.map(
163
163
  (c) => p(c.challenger_pubkey).toLowerCase()
164
- ), i = new Set(a);
165
- if (i.size !== a.length)
164
+ ), i = new Set(s);
165
+ if (i.size !== s.length)
166
166
  throw new Error(
167
167
  "Depositor graph contains duplicate challenger entries in challenger_presign_data"
168
168
  );
169
- const o = new Set(u), l = u.filter((c) => !i.has(c)), d = a.filter((c) => !o.has(c));
170
- if (l.length > 0 || d.length > 0)
169
+ const o = new Set(u), l = u.filter((c) => !i.has(c)), h = s.filter((c) => !o.has(c));
170
+ if (l.length > 0 || h.length > 0)
171
171
  throw new Error(
172
- "Depositor graph challenger set does not match expected (local ∪ universal)" + (l.length > 0 ? ` (missing: ${l.join(", ")})` : "") + (d.length > 0 ? ` (unexpected: ${d.join(", ")})` : "")
172
+ "Depositor graph challenger set does not match expected (local ∪ universal)" + (l.length > 0 ? ` (missing: ${l.join(", ")})` : "") + (h.length > 0 ? ` (unexpected: ${h.join(", ")})` : "")
173
173
  );
174
174
  }
175
175
  function Ee(e, t) {
176
176
  const r = e.ins[t];
177
- return M(new Uint8Array(r.hash).slice().reverse());
177
+ return U(new Uint8Array(r.hash).slice().reverse());
178
178
  }
179
- function R(e, t, r, n, s) {
179
+ function B(e, t, r, n, a) {
180
180
  const u = e.ins[t];
181
181
  if (u.index !== 0)
182
182
  throw new Error(
183
- `NoPayout (challenger ${s}) input ${t} expected to spend ${n} vout 0, got vout ${u.index}`
183
+ `NoPayout (challenger ${a}) input ${t} expected to spend ${n} vout 0, got vout ${u.index}`
184
184
  );
185
- const a = r.getId(), i = Ee(e, t);
186
- if (i !== a)
185
+ const s = r.getId(), i = Ee(e, t);
186
+ if (i !== s)
187
187
  throw new Error(
188
- `NoPayout (challenger ${s}) input ${t} does not reference ${n} (expected txid ${a}, got ${i})`
188
+ `NoPayout (challenger ${a}) input ${t} does not reference ${n} (expected txid ${s}, got ${i})`
189
189
  );
190
190
  }
191
191
  async function Te(e, t, r) {
192
- const n = [], s = [], u = [], a = we(
192
+ const n = [], a = [], u = [], s = xe(
193
193
  r.vaultKeeperBtcPubkeys,
194
194
  r.depositorBtcPubkey
195
195
  );
196
- xe(
196
+ ve(
197
197
  e.challenger_presign_data,
198
- a,
198
+ s,
199
199
  r.universalChallengerBtcPubkeys
200
200
  );
201
201
  const i = await ue({
@@ -210,10 +210,10 @@ async function Te(e, t, r) {
210
210
  network: r.network,
211
211
  claimerBtcPubkey: r.depositorBtcPubkey,
212
212
  registeredPayoutScriptPubKey: r.registeredPayoutScriptPubKey,
213
- commissionBps: ve
213
+ commissionBps: we
214
214
  });
215
- n.push(i.psbtHex), s.push(
216
- V(
215
+ n.push(i.psbtHex), a.push(
216
+ I(
217
217
  t,
218
218
  O
219
219
  )
@@ -221,40 +221,40 @@ async function Te(e, t, r) {
221
221
  const o = p(r.depositorBtcPubkey), l = _.fromHex(
222
222
  p(e.assert_tx.tx_hex)
223
223
  );
224
- for (const d of e.challenger_presign_data) {
225
- const c = p(d.challenger_pubkey), h = n.length, P = await ke({
226
- challenger: d,
224
+ for (const h of e.challenger_presign_data) {
225
+ const c = p(h.challenger_pubkey), g = n.length, m = await ke({
226
+ challenger: h,
227
227
  challengerPubkey: c,
228
228
  claimerPubkey: o,
229
- localChallengers: a,
229
+ localChallengers: s,
230
230
  assertTxParsed: l,
231
231
  ctx: r
232
232
  });
233
- n.push(P), s.push(
234
- V(
233
+ n.push(m), a.push(
234
+ I(
235
235
  t,
236
236
  O
237
237
  )
238
238
  ), u.push({
239
239
  challengerPubkey: c,
240
- noPayoutIdx: h
240
+ noPayoutIdx: g
241
241
  });
242
242
  }
243
- return { psbtHexes: n, signOptions: s, challengerEntries: u };
243
+ return { psbtHexes: n, signOptions: a, challengerEntries: u };
244
244
  }
245
245
  async function ke(e) {
246
246
  const {
247
247
  challenger: t,
248
248
  challengerPubkey: r,
249
249
  claimerPubkey: n,
250
- localChallengers: s,
250
+ localChallengers: a,
251
251
  assertTxParsed: u,
252
- ctx: a
252
+ ctx: s
253
253
  } = e;
254
254
  le(
255
255
  t.nopayout_tx.tx_hex,
256
256
  r,
257
- a.network
257
+ s.network
258
258
  );
259
259
  const i = _.fromHex(
260
260
  p(t.nopayout_tx.tx_hex)
@@ -267,56 +267,56 @@ async function ke(e) {
267
267
  throw new Error(
268
268
  `NoPayout (challenger ${r}) must have exactly 3 inputs, got ${i.ins.length}`
269
269
  );
270
- R(
270
+ B(
271
271
  i,
272
272
  0,
273
273
  u,
274
274
  "Assert",
275
275
  r
276
- ), R(
276
+ ), B(
277
277
  i,
278
278
  1,
279
279
  o,
280
280
  "ChallengeAssertX",
281
281
  r
282
- ), R(
282
+ ), B(
283
283
  i,
284
284
  2,
285
285
  l,
286
286
  "ChallengeAssertY",
287
287
  r
288
288
  );
289
- const d = [
289
+ const h = [
290
290
  u.outs[0],
291
291
  o.outs[0],
292
292
  l.outs[0]
293
293
  ].map((c) => ({
294
- script_pubkey: M(new Uint8Array(c.script)),
294
+ script_pubkey: U(new Uint8Array(c.script)),
295
295
  value: c.value
296
296
  }));
297
297
  return ce({
298
298
  noPayoutTxHex: t.nopayout_tx.tx_hex,
299
299
  challengerPubkey: r,
300
- prevouts: d,
300
+ prevouts: h,
301
301
  connectorParams: {
302
302
  claimer: n,
303
- localChallengers: s,
304
- universalChallengers: a.universalChallengerBtcPubkeys,
305
- timelockAssert: a.timelockAssert,
306
- councilMembers: a.councilMembers,
307
- councilQuorum: a.councilQuorum
303
+ localChallengers: a,
304
+ universalChallengers: s.universalChallengerBtcPubkeys,
305
+ timelockAssert: s.timelockAssert,
306
+ councilMembers: s.councilMembers,
307
+ councilQuorum: s.councilQuorum
308
308
  }
309
309
  });
310
310
  }
311
311
  function _e(e, t, r) {
312
- I(e[0]);
313
- const n = N(
312
+ V(e[0]);
313
+ const n = H(
314
314
  e[0].returnedPsbtHex,
315
315
  r
316
- ), s = {};
316
+ ), a = {};
317
317
  for (const u of t)
318
- I(e[u.noPayoutIdx]), s[u.challengerPubkey] = {
319
- nopayout_signature: N(
318
+ V(e[u.noPayoutIdx]), a[u.challengerPubkey] = {
319
+ nopayout_signature: H(
320
320
  e[u.noPayoutIdx].returnedPsbtHex,
321
321
  r
322
322
  )
@@ -325,90 +325,90 @@ function _e(e, t, r) {
325
325
  payout_signatures: {
326
326
  payout_signature: n
327
327
  },
328
- per_challenger: s
328
+ per_challenger: a
329
329
  };
330
330
  }
331
- async function Se(e, t, r) {
331
+ async function Ce(e, t, r) {
332
332
  if (typeof e.signPsbts == "function")
333
333
  return e.signPsbts(t, r);
334
334
  const n = [];
335
- for (let s = 0; s < t.length; s++)
336
- n.push(await e.signPsbt(t[s], r == null ? void 0 : r[s]));
335
+ for (let a = 0; a < t.length; a++)
336
+ n.push(await e.signPsbt(t[a], r == null ? void 0 : r[a]));
337
337
  return n;
338
338
  }
339
- async function Ae(e) {
340
- const { depositorGraph: t, btcWallet: r, signingContext: n } = e, s = await r.getPublicKeyHex(), { depositorPubkey: u } = ee(
341
- s,
339
+ async function Se(e) {
340
+ const { depositorGraph: t, btcWallet: r, signingContext: n } = e, a = await r.getPublicKeyHex(), { depositorPubkey: u } = ee(
341
+ a,
342
342
  p(n.depositorBtcPubkey)
343
- ), { psbtHexes: a, signOptions: i, challengerEntries: o } = await Te(
343
+ ), { psbtHexes: s, signOptions: i, challengerEntries: o } = await Te(
344
344
  t,
345
- s,
345
+ a,
346
346
  n
347
- ), l = await Se(
347
+ ), l = await Ce(
348
348
  r,
349
- a,
349
+ s,
350
350
  i
351
351
  );
352
- if (l.length !== a.length)
352
+ if (l.length !== s.length)
353
353
  throw new Error(
354
- `Wallet returned ${l.length} signed PSBTs, expected ${a.length}`
354
+ `Wallet returned ${l.length} signed PSBTs, expected ${s.length}`
355
355
  );
356
- const d = a.map((c, h) => ({
356
+ const h = s.map((c, g) => ({
357
357
  requestedPsbtHex: c,
358
- returnedPsbtHex: l[h]
358
+ returnedPsbtHex: l[g]
359
359
  }));
360
360
  return _e(
361
- d,
361
+ h,
362
362
  o,
363
363
  u
364
364
  );
365
365
  }
366
- const Ce = 1200 * 1e3, X = /* @__PURE__ */ new Set([
366
+ const Ae = 1200 * 1e3, z = /* @__PURE__ */ new Set([
367
367
  y.PENDING_ACKS,
368
368
  y.PENDING_ACTIVATION,
369
369
  y.ACTIVATED_PENDING_BROADCAST,
370
370
  y.ACTIVATED
371
- ]), Be = /* @__PURE__ */ new Set([
371
+ ]), $e = /* @__PURE__ */ new Set([
372
372
  y.PENDING_DEPOSITOR_SIGNATURES,
373
- ...X
373
+ ...z
374
374
  ]);
375
- function Re(e) {
375
+ function Be(e) {
376
376
  return e.map((t) => ({
377
- claimerPubkeyXOnly: S(t.claimer_pubkey),
377
+ claimerPubkeyXOnly: C(t.claimer_pubkey),
378
378
  payoutTxHex: t.payout_tx.tx_hex,
379
379
  assertTxHex: t.assert_tx.tx_hex
380
380
  }));
381
381
  }
382
- function x(e) {
383
- return S(e).toLowerCase();
382
+ function E(e) {
383
+ return C(e).toLowerCase();
384
384
  }
385
- function $e(e, t, r, n) {
386
- const s = x(n), u = [
387
- x(t),
388
- ...r.map(x)
389
- ], a = new Set(u);
390
- if (a.size !== u.length)
385
+ function Re(e, t, r, n) {
386
+ const a = E(n), u = [
387
+ E(t),
388
+ ...r.map(E)
389
+ ], s = new Set(u);
390
+ if (s.size !== u.length)
391
391
  throw new Error(
392
392
  "Cannot validate claimer set: signing context contains duplicate vault provider or vault keeper key"
393
393
  );
394
- if (a.has(s))
394
+ if (s.has(a))
395
395
  throw new Error(
396
396
  "Cannot validate claimer set: depositor key overlaps with vault provider or vault keeper set"
397
397
  );
398
398
  const i = e.map(
399
- (h) => x(h.claimer_pubkey)
399
+ (g) => E(g.claimer_pubkey)
400
400
  );
401
401
  if (new Set(i).size !== i.length)
402
402
  throw new Error(
403
403
  "Presign response contains duplicate claimer entries"
404
404
  );
405
- const o = i.filter((h) => h !== s), l = new Set(o), d = u.filter((h) => !l.has(h)), c = o.filter((h) => !a.has(h));
406
- if (d.length > 0 || c.length > 0)
405
+ const o = i.filter((g) => g !== a), l = new Set(o), h = u.filter((g) => !l.has(g)), c = o.filter((g) => !s.has(g));
406
+ if (h.length > 0 || c.length > 0)
407
407
  throw new Error(
408
- "Presign response claimer set does not match expected (vault provider ∪ vault keepers)" + (d.length > 0 ? ` (missing: ${d.join(", ")})` : "") + (c.length > 0 ? ` (unexpected: ${c.join(", ")})` : "")
408
+ "Presign response claimer set does not match expected (vault provider ∪ vault keepers)" + (h.length > 0 ? ` (missing: ${h.join(", ")})` : "") + (c.length > 0 ? ` (unexpected: ${c.join(", ")})` : "")
409
409
  );
410
410
  }
411
- function H(e, t) {
411
+ function K(e, t) {
412
412
  return {
413
413
  payoutTxHex: e.payoutTxHex,
414
414
  peginTxHex: t.peginTxHex,
@@ -423,109 +423,109 @@ function H(e, t) {
423
423
  commissionBps: t.commissionBps
424
424
  };
425
425
  }
426
- async function Ie(e, t, r, n) {
427
- const s = new re({
426
+ async function Ve(e, t, r, n) {
427
+ const a = new re({
428
428
  network: t.network,
429
429
  btcWallet: e
430
430
  }), u = r.length;
431
431
  n == null || n(0, u);
432
- let a;
433
- if (s.supportsBatchSigning())
434
- a = (await s.signPayoutTransactionsBatch(
435
- r.map((l) => H(l, t))
432
+ let s;
433
+ if (a.supportsBatchSigning())
434
+ s = (await a.signPayoutTransactionsBatch(
435
+ r.map((l) => K(l, t))
436
436
  )).map((l) => l.payoutSignature);
437
437
  else {
438
- a = [];
438
+ s = [];
439
439
  for (let o = 0; o < r.length; o++) {
440
440
  n == null || n(o, u);
441
- const l = await s.signPayoutTransaction(
442
- H(r[o], t)
441
+ const l = await a.signPayoutTransaction(
442
+ K(r[o], t)
443
443
  );
444
- a.push(l.signature);
444
+ s.push(l.signature);
445
445
  }
446
446
  }
447
447
  const i = {};
448
448
  for (let o = 0; o < r.length; o++)
449
449
  i[r[o].claimerPubkeyXOnly] = {
450
- payout_signature: a[o]
450
+ payout_signature: s[o]
451
451
  };
452
452
  return n == null || n(u, u), i;
453
453
  }
454
- async function at(e) {
454
+ async function st(e) {
455
455
  const {
456
456
  statusReader: t,
457
457
  presignClient: r,
458
458
  btcWallet: n,
459
- peginTxid: s,
459
+ peginTxid: a,
460
460
  depositorPk: u,
461
- signingContext: a,
462
- timeoutMs: i = Ce,
461
+ signingContext: s,
462
+ timeoutMs: i = Ae,
463
463
  signal: o,
464
464
  onProgress: l
465
- } = e, d = await F({
465
+ } = e, h = await X({
466
466
  statusReader: t,
467
- peginTxid: s,
468
- targetStatuses: Be,
467
+ peginTxid: a,
468
+ targetStatuses: $e,
469
469
  timeoutMs: i,
470
470
  signal: o
471
471
  });
472
- if (X.has(d))
472
+ if (z.has(h))
473
473
  return;
474
474
  o == null || o.throwIfAborted();
475
475
  const c = await r.requestDepositorPresignTransactions(
476
476
  {
477
- pegin_txid: s,
477
+ pegin_txid: a,
478
478
  depositor_pk: u
479
479
  },
480
480
  o
481
481
  );
482
482
  o == null || o.throwIfAborted();
483
- const h = x(u);
484
- $e(
483
+ const g = E(u);
484
+ Re(
485
485
  c.txs,
486
- a.vaultProviderBtcPubkey,
487
- a.vaultKeeperBtcPubkeys,
486
+ s.vaultProviderBtcPubkey,
487
+ s.vaultKeeperBtcPubkeys,
488
488
  u
489
489
  );
490
- const P = c.txs.filter(
491
- (v) => x(v.claimer_pubkey) !== h
492
- ), b = Re(P), g = await Ie(
490
+ const m = c.txs.filter(
491
+ (x) => E(x.claimer_pubkey) !== g
492
+ ), f = Be(m), P = await Ve(
493
493
  n,
494
- a,
495
- b,
494
+ s,
495
+ f,
496
496
  l
497
497
  );
498
498
  o == null || o.throwIfAborted();
499
- const E = await Ae({
499
+ const w = await Se({
500
500
  depositorGraph: c.depositor_graph,
501
501
  btcWallet: n,
502
502
  signingContext: {
503
- peginTxHex: a.peginTxHex,
503
+ peginTxHex: s.peginTxHex,
504
504
  depositorBtcPubkey: u,
505
- vaultProviderBtcPubkey: a.vaultProviderBtcPubkey,
506
- vaultKeeperBtcPubkeys: a.vaultKeeperBtcPubkeys,
507
- universalChallengerBtcPubkeys: a.universalChallengerBtcPubkeys,
508
- timelockPegin: a.timelockPegin,
509
- timelockAssert: a.timelockAssert,
510
- councilMembers: a.councilMembers,
511
- councilQuorum: a.councilQuorum,
512
- network: a.network,
513
- registeredPayoutScriptPubKey: a.registeredPayoutScriptPubKey
505
+ vaultProviderBtcPubkey: s.vaultProviderBtcPubkey,
506
+ vaultKeeperBtcPubkeys: s.vaultKeeperBtcPubkeys,
507
+ universalChallengerBtcPubkeys: s.universalChallengerBtcPubkeys,
508
+ timelockPegin: s.timelockPegin,
509
+ timelockAssert: s.timelockAssert,
510
+ councilMembers: s.councilMembers,
511
+ councilQuorum: s.councilQuorum,
512
+ network: s.network,
513
+ registeredPayoutScriptPubKey: s.registeredPayoutScriptPubKey
514
514
  }
515
515
  });
516
516
  o == null || o.throwIfAborted();
517
- const m = { ...g };
518
- m[p(u)] = E.payout_signatures, await r.submitDepositorPresignatures(
517
+ const b = { ...P };
518
+ b[p(u)] = w.payout_signatures, await r.submitDepositorPresignatures(
519
519
  {
520
- pegin_txid: s,
520
+ pegin_txid: a,
521
521
  depositor_pk: u,
522
- signatures: m,
523
- depositor_claimer_presignatures: E
522
+ signatures: b,
523
+ depositor_claimer_presignatures: w
524
524
  },
525
525
  o
526
526
  );
527
527
  }
528
- function Ve(e) {
528
+ function Ie(e) {
529
529
  return /^[0-9a-fA-F]{64}$/.test(e);
530
530
  }
531
531
  function it(e) {
@@ -533,11 +533,11 @@ function it(e) {
533
533
  amountSats: t,
534
534
  minDeposit: r,
535
535
  maxDeposit: n,
536
- btcBalance: s,
536
+ btcBalance: a,
537
537
  estimatedFeeSats: u,
538
- depositorClaimValue: a
538
+ depositorClaimValue: s
539
539
  } = e;
540
- return !(t <= 0n || t < r || n && n > 0n && t > n || u == null || a == null || t + u + a > s);
540
+ return !(t <= 0n || t < r || n && n > 0n && t > n || u == null || s == null || t + u + s > a);
541
541
  }
542
542
  function ut(e, t, r) {
543
543
  return e <= 0n ? {
@@ -545,10 +545,10 @@ function ut(e, t, r) {
545
545
  error: "Deposit amount must be greater than zero"
546
546
  } : e < t ? {
547
547
  valid: !1,
548
- error: `Minimum deposit is ${w(t)} BTC`
548
+ error: `Minimum deposit is ${v(t)} BTC`
549
549
  } : r && r > 0n && e > r ? {
550
550
  valid: !1,
551
- error: `Maximum deposit is ${w(r)} BTC`
551
+ error: `Maximum deposit is ${v(r)} BTC`
552
552
  } : { valid: !0 };
553
553
  }
554
554
  function lt(e) {
@@ -558,7 +558,7 @@ function lt(e) {
558
558
  error: "Supply cap reached — deposits temporarily paused"
559
559
  } : t > r ? {
560
560
  valid: !1,
561
- error: `Vault size exceeds remaining capacity (${w(r)} BTC)`
561
+ error: `Vault size exceeds remaining capacity (${v(r)} BTC)`
562
562
  } : { valid: !0 };
563
563
  }
564
564
  function ct(e, t) {
@@ -568,10 +568,10 @@ function ct(e, t) {
568
568
  error: "At least one vault provider must be selected"
569
569
  };
570
570
  const r = t.map(
571
- (s) => s.toLowerCase()
571
+ (a) => a.toLowerCase()
572
572
  );
573
573
  return e.filter(
574
- (s) => !r.includes(s.toLowerCase())
574
+ (a) => !r.includes(a.toLowerCase())
575
575
  ).length > 0 ? {
576
576
  valid: !1,
577
577
  error: "Invalid vault provider selected"
@@ -584,33 +584,33 @@ function Ne(e, t, r) {
584
584
  error: "At least one vault amount required"
585
585
  };
586
586
  for (let n = 0; n < e.length; n++) {
587
- const s = e[n];
588
- if (s <= 0n)
587
+ const a = e[n];
588
+ if (a <= 0n)
589
589
  return {
590
590
  valid: !1,
591
591
  error: `Vault ${n + 1} amount must be positive`
592
592
  };
593
- if (t && s < t)
593
+ if (t && a < t)
594
594
  return {
595
595
  valid: !1,
596
- error: `Vault ${n + 1} amount ${w(s)} BTC is below minimum deposit ${w(t)} BTC`
596
+ error: `Vault ${n + 1} amount ${v(a)} BTC is below minimum deposit ${v(t)} BTC`
597
597
  };
598
- if (r && s > r)
598
+ if (r && a > r)
599
599
  return {
600
600
  valid: !1,
601
- error: `Vault ${n + 1} amount ${w(s)} BTC exceeds maximum deposit ${w(r)} BTC`
601
+ error: `Vault ${n + 1} amount ${v(a)} BTC exceeds maximum deposit ${v(r)} BTC`
602
602
  };
603
603
  }
604
604
  return { valid: !0 };
605
605
  }
606
- function Oe(e) {
606
+ function He(e) {
607
607
  const t = p(e);
608
- return Ve(t) ? { valid: !0 } : {
608
+ return Ie(t) ? { valid: !0 } : {
609
609
  valid: !1,
610
610
  error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
611
611
  };
612
612
  }
613
- function He(e) {
613
+ function Oe(e) {
614
614
  if (!e || e.length === 0)
615
615
  throw new Error(
616
616
  "No vault keepers available. The system requires at least one vault keeper to create a deposit."
@@ -626,170 +626,196 @@ function De(e) {
626
626
  if (e.length === 0)
627
627
  throw new Error("No spendable UTXOs available");
628
628
  }
629
- function dt(e) {
629
+ function ht(e) {
630
630
  const {
631
631
  vaultAmounts: t,
632
632
  confirmedUTXOs: r,
633
633
  vaultProviderBtcPubkey: n,
634
- vaultKeeperBtcPubkeys: s,
634
+ vaultKeeperBtcPubkeys: a,
635
635
  universalChallengerBtcPubkeys: u,
636
- minDeposit: a,
636
+ minDeposit: s,
637
637
  maxDeposit: i
638
638
  } = e, o = Ne(
639
639
  t,
640
- a,
640
+ s,
641
641
  i
642
642
  );
643
643
  if (!o.valid)
644
644
  throw new Error(o.error);
645
- const l = Oe(n);
645
+ const l = He(n);
646
646
  if (!l.valid)
647
647
  throw new Error(l.error);
648
- He(s), Ke(u), De(r);
648
+ Oe(a), Ke(u), De(r);
649
649
  }
650
- async function pt(e) {
650
+ async function dt(e) {
651
651
  const {
652
652
  vaultRegistryReader: t,
653
653
  vaultKeeperReader: r,
654
654
  universalChallengerReader: n,
655
- vaultProviderEthAddress: s,
655
+ vaultProviderEthAddress: a,
656
656
  applicationEntryPoint: u,
657
- expectedVaultProviderBtcPubkey: a,
657
+ expectedVaultProviderBtcPubkey: s,
658
658
  expectedVaultKeeperBtcPubkeys: i,
659
659
  expectedUniversalChallengerBtcPubkeys: o
660
660
  } = e, [
661
661
  l,
662
- d,
662
+ h,
663
663
  c
664
664
  ] = await Promise.all([
665
- t.getVaultProviderBtcPubKey(s),
665
+ t.getVaultProviderBtcPubKey(a),
666
666
  r.getCurrentVaultKeepersVersion(u),
667
667
  n.getLatestUniversalChallengersVersion()
668
- ]), [h, P] = await Promise.all([
668
+ ]), [g, m] = await Promise.all([
669
669
  r.getVaultKeepersByVersion(
670
670
  u,
671
- d
671
+ h
672
672
  ),
673
673
  n.getUniversalChallengersByVersion(
674
674
  c
675
675
  )
676
- ]), b = (f) => S(f).toLowerCase(), g = (f) => f.map(b).sort();
677
- if (b(a) !== l)
676
+ ]), f = (d) => C(d).toLowerCase(), P = (d) => d.map(f).sort();
677
+ if (f(s) !== l)
678
678
  throw new Error(
679
- `Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${s}. Refresh and try again.`
679
+ `Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${a}. Refresh and try again.`
680
680
  );
681
- const m = g(i), v = g(
682
- h.map((f) => f.btcPubKey)
681
+ const b = P(i), x = P(
682
+ g.map((d) => d.btcPubKey)
683
683
  );
684
- if (m.length !== v.length || m.some((f, A) => f !== v[A]))
684
+ if (b.length !== x.length || b.some((d, S) => d !== x[S]))
685
685
  throw new Error(
686
- `Vault keeper BTC pubkeys (v${d}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
686
+ `Vault keeper BTC pubkeys (v${h}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
687
687
  );
688
- const T = g(o), k = g(
689
- P.map((f) => f.btcPubKey)
688
+ const T = P(o), k = P(
689
+ m.map((d) => d.btcPubKey)
690
690
  );
691
- if (T.length !== k.length || T.some((f, A) => f !== k[A]))
691
+ if (T.length !== k.length || T.some((d, S) => d !== k[S]))
692
692
  throw new Error(
693
693
  `Universal challenger BTC pubkeys (v${c}) indexer set does not match ProtocolParams on-chain set. Refresh and try again.`
694
694
  );
695
695
  return {
696
696
  vaultProviderBtcPubkeyXOnly: l,
697
- vaultKeeperBtcPubkeysSorted: v,
697
+ vaultKeeperBtcPubkeysSorted: x,
698
698
  universalChallengerBtcPubkeysSorted: k,
699
- expectedAppVaultKeepersVersion: d,
699
+ expectedAppVaultKeepersVersion: h,
700
700
  expectedUniversalChallengersVersion: c
701
701
  };
702
702
  }
703
- class z extends Error {
703
+ class G extends Error {
704
704
  constructor(t) {
705
705
  super(t), this.name = "RegisteredVaultVersionMismatchError";
706
706
  }
707
707
  }
708
- function ht(e) {
709
- return e instanceof z || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
708
+ function pt(e) {
709
+ return e instanceof G || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
710
710
  }
711
- async function ft(e) {
711
+ async function gt(e) {
712
712
  const {
713
713
  vaultRegistryReader: t,
714
714
  vaultIds: r,
715
715
  expectedOffchainParamsVersion: n,
716
- expectedAppVaultKeepersVersion: s,
716
+ expectedAppVaultKeepersVersion: a,
717
717
  expectedUniversalChallengersVersion: u
718
- } = e, a = await t.getProtocolInfoBatch(r), i = [];
719
- if (a.forEach((o, l) => {
720
- const d = r[l];
718
+ } = e, s = await t.getProtocolInfoBatch(r), i = [];
719
+ if (s.forEach((o, l) => {
720
+ const h = r[l];
721
721
  o.offchainParamsVersion !== n && i.push(
722
- `vault ${d}: offchainParams expected v${n}, got v${o.offchainParamsVersion}`
723
- ), o.appVaultKeepersVersion !== s && i.push(
724
- `vault ${d}: appVaultKeepers expected v${s}, got v${o.appVaultKeepersVersion}`
722
+ `vault ${h}: offchainParams expected v${n}, got v${o.offchainParamsVersion}`
723
+ ), o.appVaultKeepersVersion !== a && i.push(
724
+ `vault ${h}: appVaultKeepers expected v${a}, got v${o.appVaultKeepersVersion}`
725
725
  ), o.universalChallengersVersion !== u && i.push(
726
- `vault ${d}: universalChallengers expected v${u}, got v${o.universalChallengersVersion}`
726
+ `vault ${h}: universalChallengers expected v${u}, got v${o.universalChallengersVersion}`
727
727
  );
728
728
  }), i.length > 0)
729
- throw new z(
729
+ throw new G(
730
730
  `Aborting BTC broadcast: signer-set or offchain-params versions changed during registration (${i.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
731
731
  );
732
732
  }
733
- var G = /* @__PURE__ */ ((e) => (e.CLAIM_EVENT_RECEIVED = "ClaimEventReceived", e.CLAIM_BROADCAST = "ClaimBroadcast", e.ASSERT_BROADCAST = "AssertBroadcast", e.PAYOUT_BROADCAST = "PayoutBroadcast", e.PAYOUT_BLOCKED = "PayoutBlocked", e))(G || {});
734
- const Ue = /* @__PURE__ */ new Set([
733
+ var j = /* @__PURE__ */ ((e) => (e.CLAIM_EVENT_RECEIVED = "ClaimEventReceived", e.CLAIM_BROADCAST = "ClaimBroadcast", e.ASSERT_BROADCAST = "AssertBroadcast", e.PAYOUT_BROADCAST = "PayoutBroadcast", e.PAYOUT_BLOCKED = "PayoutBlocked", e))(j || {});
734
+ const Fe = /* @__PURE__ */ new Set([
735
735
  "PayoutBroadcast",
736
736
  "PayoutBlocked"
737
737
  /* PAYOUT_BLOCKED */
738
738
  ]);
739
- function gt(e) {
740
- return Object.values(G).includes(
739
+ function ft(e) {
740
+ return Object.values(j).includes(
741
741
  e
742
742
  );
743
743
  }
744
- function Pt(e) {
745
- return !!e && Ue.has(e);
744
+ function mt(e) {
745
+ return !!e && Fe.has(e);
746
746
  }
747
747
  class Me extends Error {
748
748
  constructor(r, n) {
749
749
  super(`Refund not yet mature (BIP68 not final): ${n.message}`);
750
- C(this, "vaultId");
751
- C(this, "cause");
750
+ A(this, "vaultId");
751
+ A(this, "cause");
752
752
  this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = n;
753
753
  }
754
754
  }
755
- const Le = /^0x[0-9a-fA-F]{64}$/, Fe = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, j = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, q = 160, K = 2e3, D = 10n, U = 100n;
756
- function mt(e) {
755
+ const Ue = /^0x[0-9a-fA-F]{64}$/, Le = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, q = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, Q = 160, D = 2e3, F = 10n, M = 100n;
756
+ function Pt(e) {
757
757
  if (!Number.isFinite(e) || e <= 0)
758
758
  throw new Error(
759
759
  `feeRateSatsVb must be a positive finite number, got ${e}`
760
760
  );
761
- return BigInt(Math.ceil(e * q));
761
+ return BigInt(Math.ceil(e * Q));
762
762
  }
763
763
  const Xe = 1, ze = /non-BIP68-final/i;
764
- function Q(e, t) {
764
+ function N(e, t) {
765
765
  if (e.length !== 66)
766
766
  throw new Error(
767
767
  `${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
768
768
  );
769
- if (!Le.test(e))
769
+ if (!Ue.test(e))
770
770
  throw new Error(
771
771
  `${t} must contain only hex characters after the 0x prefix`
772
772
  );
773
773
  }
774
- function $(e, t) {
774
+ function R(e, t) {
775
775
  if (!Number.isInteger(e) || e < 0)
776
776
  throw new Error(`${t} must be a non-negative integer, got ${e}`);
777
777
  }
778
778
  function Ge(e) {
779
- if (Q(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout !== 0)
779
+ if (N(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0)
780
+ throw new Error(
781
+ `htlcVout must be a non-negative integer, got ${e.htlcVout}`
782
+ );
783
+ if (!Array.isArray(e.batch) || e.batch.length === 0)
784
+ throw new Error("batch must be a non-empty array of HTLC entries");
785
+ if (e.htlcVout >= e.batch.length)
786
+ throw new Error(
787
+ `htlcVout ${e.htlcVout} is out of range for batch of size ${e.batch.length}`
788
+ );
789
+ for (let r = 0; r < e.batch.length; r++) {
790
+ const n = e.batch[r];
791
+ if (N(n.hashlock, `batch[${r}].hashlock`), !Number.isInteger(n.htlcVout) || n.htlcVout !== r)
792
+ throw new Error(
793
+ `batch[${r}].htlcVout must equal ${r} (contiguous vout-ordered vector), got ${n.htlcVout}`
794
+ );
795
+ if (typeof n.amount != "bigint" || n.amount <= 0n)
796
+ throw new Error(
797
+ `batch[${r}].amount must be a positive bigint, got ${n.amount}`
798
+ );
799
+ }
800
+ const t = e.batch[e.htlcVout];
801
+ if (t.hashlock.toLowerCase() !== e.hashlock.toLowerCase())
780
802
  throw new Error(
781
- `Multi-vault Pre-PegIn refund is not supported by this SDK call (htlcVout=${e.htlcVout}, expected 0). Refund of batched-deposit vaults requires reconstructing all sibling HTLCs.`
803
+ `batch[${e.htlcVout}].hashlock (${t.hashlock}) does not match target hashlock (${e.hashlock})`
782
804
  );
783
- if ($(e.offchainParamsVersion, "offchainParamsVersion"), $(e.appVaultKeepersVersion, "appVaultKeepersVersion"), $(
805
+ if (t.amount !== e.amount)
806
+ throw new Error(
807
+ `batch[${e.htlcVout}].amount (${t.amount}) does not match target amount (${e.amount})`
808
+ );
809
+ if (R(e.offchainParamsVersion, "offchainParamsVersion"), R(e.appVaultKeepersVersion, "appVaultKeepersVersion"), R(
784
810
  e.universalChallengersVersion,
785
811
  "universalChallengersVersion"
786
812
  ), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
787
813
  throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
788
- if (!Fe.test(e.unsignedPrePeginTxHex))
814
+ if (!Le.test(e.unsignedPrePeginTxHex))
789
815
  throw new Error(
790
816
  "unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
791
817
  );
792
- if (!e.depositorBtcPubkey || !j.test(e.depositorBtcPubkey))
818
+ if (!e.depositorBtcPubkey || !q.test(e.depositorBtcPubkey))
793
819
  throw new Error(
794
820
  "depositorBtcPubkey must be 32 or 33 bytes of hex (optional 0x prefix)"
795
821
  );
@@ -797,7 +823,7 @@ function Ge(e) {
797
823
  throw new Error(`amount must be a positive bigint, got ${e.amount}`);
798
824
  }
799
825
  function je(e) {
800
- if (!e.vaultProviderPubkey || !j.test(e.vaultProviderPubkey))
826
+ if (!e.vaultProviderPubkey || !q.test(e.vaultProviderPubkey))
801
827
  throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
802
828
  if (e.vaultKeeperPubkeys.length === 0)
803
829
  throw new Error("vaultKeeperPubkeys must be non-empty");
@@ -811,6 +837,10 @@ function je(e) {
811
837
  throw new Error(
812
838
  `protocol feeRate must be a positive bigint, got ${e.feeRate}`
813
839
  );
840
+ if (typeof e.minPeginFeeRate != "bigint" || e.minPeginFeeRate <= 0n)
841
+ throw new Error(
842
+ `minPeginFeeRate must be a positive bigint, got ${e.minPeginFeeRate}`
843
+ );
814
844
  if (!Number.isInteger(e.numLocalChallengers) || e.numLocalChallengers < 0)
815
845
  throw new Error("numLocalChallengers must be a non-negative integer");
816
846
  if (!Number.isInteger(e.councilQuorum) || !Number.isInteger(e.councilSize) || e.councilQuorum <= 0 || e.councilSize <= 0 || e.councilQuorum > e.councilSize)
@@ -829,58 +859,72 @@ function qe(e) {
829
859
  }
830
860
  return t.extractTransaction().toHex();
831
861
  }
832
- async function yt(e) {
862
+ async function bt(e) {
833
863
  const {
834
864
  vaultId: t,
835
865
  readVault: r,
836
866
  readPrePeginContext: n,
837
- feeRate: s,
867
+ feeRate: a,
838
868
  signPsbt: u,
839
- broadcastTx: a,
869
+ broadcastTx: s,
840
870
  signal: i
841
871
  } = e;
842
- i == null || i.throwIfAborted(), Q(t, "vaultId");
872
+ i == null || i.throwIfAborted(), N(t, "vaultId");
843
873
  const o = await r();
844
874
  Ge(o), i == null || i.throwIfAborted();
845
875
  const l = await n(o);
846
- if (je(l), i == null || i.throwIfAborted(), !Number.isFinite(s) || s <= 0)
847
- throw new Error(`feeRate must be a positive number, got ${s}`);
848
- if (s > K)
876
+ if (je(l), i == null || i.throwIfAborted(), !Number.isFinite(a) || a <= 0)
877
+ throw new Error(`feeRate must be a positive number, got ${a}`);
878
+ if (a > D)
849
879
  throw new Error(
850
- `feeRate ${s} sat/vB exceeds refund safety cap ${K} sat/vB; refusing to sign refund.`
880
+ `feeRate ${a} sat/vB exceeds refund safety cap ${D} sat/vB; refusing to sign refund.`
851
881
  );
852
- const d = BigInt(Math.ceil(s * q)), c = o.amount * D / U;
853
- if (d > c)
882
+ const h = BigInt(Math.ceil(a * Q)), c = o.amount * F / M;
883
+ if (h > c)
854
884
  throw new Error(
855
- `Refund fee ${d} sats exceeds the per-vault safety cap of ${c} sats (${D}/${U} of vault.amount=${o.amount}); refusing to sign refund.`
885
+ `Refund fee ${h} sats exceeds the per-vault safety cap of ${c} sats (${F}/${M} of vault.amount=${o.amount}); refusing to sign refund.`
856
886
  );
857
887
  i == null || i.throwIfAborted();
858
- const h = S(
888
+ const g = C(
859
889
  o.depositorBtcPubkey
860
- ), P = p(o.unsignedPrePeginTxHex), b = 1, g = ne(P);
861
- if (g !== void 0 && g.vout !== b)
890
+ ), m = p(o.unsignedPrePeginTxHex), f = ne(m);
891
+ if (f !== void 0 && f.vout !== o.batch.length)
892
+ throw new Error(
893
+ `Auth-anchor OP_RETURN at vout ${f.vout} does not match batch size (${o.batch.length} HTLC outputs expect the anchor at vout ${o.batch.length}). Refund refused — sibling HTLC vector is incomplete.`
894
+ );
895
+ const P = f == null ? void 0 : f.hash;
896
+ let w;
897
+ try {
898
+ w = _.fromHex(m);
899
+ } catch (d) {
900
+ throw new Error(
901
+ `Failed to parse funded Pre-PegIn transaction hex: ${d instanceof Error ? d.message : String(d)}`
902
+ );
903
+ }
904
+ if (w.outs.length < o.batch.length)
862
905
  throw new Error(
863
- `Multi-vault Pre-PegIn refund is not supported by this SDK call (auth-anchor OP_RETURN at vout ${g.vout}; single-vault refund expects vout ${b}). Refund of batched-deposit vaults requires reconstructing all sibling HTLCs.`
906
+ `Funded Pre-PegIn tx has ${w.outs.length} outputs but batch requires at least ${o.batch.length} HTLC outputs. Refund refused funded tx shape disagrees with sibling vector.`
864
907
  );
865
- const E = g == null ? void 0 : g.hash, { psbtHex: m } = await de({
908
+ const { psbtHex: b } = await he({
866
909
  prePeginParams: {
867
- depositorPubkey: h,
910
+ depositorPubkey: g,
868
911
  vaultProviderPubkey: p(l.vaultProviderPubkey),
869
912
  vaultKeeperPubkeys: l.vaultKeeperPubkeys.map(p),
870
913
  universalChallengerPubkeys: l.universalChallengerPubkeys.map(p),
871
- hashlocks: [p(o.hashlock)],
914
+ hashlocks: o.batch.map((d) => p(d.hashlock)),
872
915
  timelockRefund: l.timelockRefund,
873
- pegInAmounts: [o.amount],
916
+ pegInAmounts: o.batch.map((d) => d.amount),
874
917
  feeRate: l.feeRate,
918
+ minPeginFeeRate: l.minPeginFeeRate,
875
919
  numLocalChallengers: l.numLocalChallengers,
876
920
  councilQuorum: l.councilQuorum,
877
921
  councilSize: l.councilSize,
878
922
  network: l.network,
879
- authAnchorHash: E
923
+ authAnchorHash: P
880
924
  },
881
- fundedPrePeginTxHex: P,
925
+ fundedPrePeginTxHex: m,
882
926
  htlcVout: o.htlcVout,
883
- refundFee: d,
927
+ refundFee: h,
884
928
  // buildRefundPsbt's top-level `hashlock` param is documented as "no 0x
885
929
  // prefix" and flows into the WASM HTLC connector derivation; a prefixed
886
930
  // value would derive the wrong refund script leaf and yield an
@@ -888,48 +932,48 @@ async function yt(e) {
888
932
  hashlock: p(o.hashlock)
889
933
  });
890
934
  i == null || i.throwIfAborted();
891
- const v = V(
935
+ const x = I(
892
936
  o.depositorBtcPubkey,
893
937
  Xe
894
- ), T = await u(m, v);
895
- I({
896
- requestedPsbtHex: m,
938
+ ), T = await u(b, x);
939
+ V({
940
+ requestedPsbtHex: b,
897
941
  returnedPsbtHex: T
898
942
  });
899
943
  const k = qe(T);
900
944
  i == null || i.throwIfAborted();
901
945
  try {
902
- return await a(k);
903
- } catch (f) {
904
- throw f instanceof Error && ze.test(f.message) ? new Me(t, f) : f;
946
+ return await s(k);
947
+ } catch (d) {
948
+ throw d instanceof Error && ze.test(d.message) ? new Me(t, d) : d;
905
949
  }
906
950
  }
907
951
  export {
908
952
  Me as B,
909
- G as C,
910
- z as R,
953
+ j as C,
954
+ G as R,
911
955
  ot as a,
912
- Ae as b,
956
+ Se as b,
913
957
  lt as c,
914
958
  ct as d,
915
959
  Ne as e,
916
- Oe as f,
917
- dt as g,
918
- pt as h,
960
+ He as f,
961
+ ht as g,
962
+ dt as h,
919
963
  it as i,
920
- ht as j,
921
- ft as k,
922
- gt as l,
923
- Pt as m,
924
- yt as n,
925
- mt as o,
926
- U as p,
927
- D as q,
928
- at as r,
929
- st as s,
930
- K as t,
931
- q as u,
964
+ pt as j,
965
+ gt as k,
966
+ ft as l,
967
+ mt as m,
968
+ bt as n,
969
+ Pt as o,
970
+ M as p,
971
+ F as q,
972
+ st as r,
973
+ at as s,
974
+ D as t,
975
+ Q as u,
932
976
  ut as v,
933
- F as w
977
+ X as w
934
978
  };
935
- //# sourceMappingURL=buildAndBroadcastRefund-BRMB7XyC.js.map
979
+ //# sourceMappingURL=buildAndBroadcastRefund-fIHDHiFh.js.map