@babylonlabs-io/ts-sdk 0.48.1 → 0.48.2

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