@babylonlabs-io/ts-sdk 0.47.1 → 0.48.1

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