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