@babylonlabs-io/ts-sdk 3.0.1 → 3.0.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.
@@ -1,55 +1,55 @@
1
- var ut = Object.defineProperty;
2
- var ct = (e, t, r) => t in e ? ut(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var N = (e, t, r) => ct(e, typeof t != "symbol" ? t + "" : t, r);
4
- import { B as Ke } from "./BTCVaultRegistry.abi-B0x9_Bza.js";
5
- import { e as De, s as f, i as lt, c as C, v as ht, u as Me, p as j, f as V } from "./bitcoin-C-TuHb-v.js";
6
- import { v as pt, d as Fe, s as dt, P as gt, a as ft } from "./PayoutManager-BSwbUQeF.js";
7
- import { Buffer as I } from "buffer";
8
- import { b as yt, a as F, c as bt } from "./signing-Dhr2t0Z6.js";
9
- import { buildClaimPsbt as mt, buildAssertClaimerPsbt as vt, buildPayoutClaimerPsbt as Pt, buildWronglyChallengedPsbts as wt, buildPayoutDepositorPsbt as xt, finalizeClaimTx as Et, buildWatchtowerArtifacts as kt, extractTapScriptSig as _t, expandWotsSeed as Tt, wotsKeypairFromSeed as $t, validateWotsKeypairAgainstGraph as Ct, verifyWatchtowerArtifacts as At, deriveVaultId as St } from "./tbv/core/wasm/index.js";
10
- import { p as Le, P as he, f as It, i as L, g as U, j as G } from "./verifyScriptPathSchnorrSignature-CpjSTfMj.js";
11
- import { Psbt as Ue, Transaction as B } from "bitcoinjs-lib";
12
- import { m as pe, n as de, N as z, o as ge, D as fe } from "./constants-D5vORbQE.js";
13
- import { d as Rt } from "./deriveVaultRoot-BcvmER1E.js";
14
- import { d as Bt, a as ye } from "./onChainBtcPubkey-CCTdl53s.js";
15
- import { zeroAddress as Vt, isAddress as Ot, isAddressEqual as Nt } from "viem";
16
- import { v as be, D as R, c as Ht, b as Kt, R as Dt, d as Ge } from "./state-CFn1rT74.js";
17
- import { h as me, b as Mt, s as Ft, j as Lt } from "./sha2-YqVHJiFj.js";
18
- import { d as Ut, c as Gt, b as Xt, f as Xe, e as qt, a as jt } from "./noPayout-qBXWKwav.js";
19
- import { a as zt } from "./secp256k1-D-H9jmd7.js";
20
- const Wt = /^0x[0-9a-fA-F]{64}$/, Yt = /^0x[0-9a-fA-F]{40}$/, Qt = /^0x([0-9a-fA-F]{2})*$/;
21
- function W(e, t) {
1
+ var dt = Object.defineProperty;
2
+ var gt = (e, t, r) => t in e ? dt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var K = (e, t, r) => gt(e, typeof t != "symbol" ? t + "" : t, r);
4
+ import { B as Me } from "./BTCVaultRegistry.abi-B0x9_Bza.js";
5
+ import { e as Fe, s as b, i as ft, c as C, v as yt, u as Le, p as Q, f as H } from "./bitcoin-C-TuHb-v.js";
6
+ import { v as bt, d as Ue, s as mt, P as vt, a as Pt } from "./PayoutManager-BSwbUQeF.js";
7
+ import { Buffer as A } from "buffer";
8
+ import { b as xt, a as U, c as wt } from "./signing-Dhr2t0Z6.js";
9
+ import { buildClaimPsbt as Et, buildAssertClaimerPsbt as _t, buildPayoutClaimerPsbt as kt, buildWronglyChallengedPsbts as Tt, buildPayoutDepositorPsbt as $t, finalizeClaimTx as Ct, buildWatchtowerArtifacts as At, extractTapScriptSig as St, expandWotsSeed as It, wotsKeypairFromSeed as Rt, validateWotsKeypairAgainstGraph as Bt, verifyWatchtowerArtifacts as Vt, deriveVaultId as Ht } from "./tbv/core/wasm/index.js";
10
+ import { p as Ge, P as G, f as Ot, i as X, g as q, j } from "./verifyScriptPathSchnorrSignature-CpjSTfMj.js";
11
+ import { Psbt as Xe, Transaction as B } from "bitcoinjs-lib";
12
+ import { m as ge, n as fe, N as J, o as ye, D as be } from "./constants-D5vORbQE.js";
13
+ import { d as Nt } from "./deriveVaultRoot-BcvmER1E.js";
14
+ import { d as Kt, a as me } from "./onChainBtcPubkey-CCTdl53s.js";
15
+ import { zeroAddress as Dt, isAddress as Mt, isAddressEqual as Ft } from "viem";
16
+ import { v as ve, D as R, c as Lt, b as Ut, R as Gt, d as qe } from "./state-CFn1rT74.js";
17
+ import { h as Pe, b as Xt, s as qt, j as jt } from "./sha2-YqVHJiFj.js";
18
+ import { d as zt, c as Wt, b as Yt, f as je, e as Qt, a as Jt } from "./noPayout-qBXWKwav.js";
19
+ import { a as Zt } from "./secp256k1-D-H9jmd7.js";
20
+ const er = /^0x[0-9a-fA-F]{64}$/, tr = /^0x[0-9a-fA-F]{40}$/, rr = /^0x([0-9a-fA-F]{2})*$/;
21
+ function Z(e, t) {
22
22
  if (e.length !== 66)
23
23
  throw new Error(
24
24
  `${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
25
25
  );
26
- if (!Wt.test(e))
26
+ if (!er.test(e))
27
27
  throw new Error(
28
28
  `${t} must contain only hex characters after the 0x prefix`
29
29
  );
30
30
  }
31
- function Jt(e, t) {
32
- if (!Yt.test(e))
31
+ function or(e, t) {
32
+ if (!tr.test(e))
33
33
  throw new Error(
34
34
  `${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
35
35
  );
36
36
  }
37
- function Zt(e, t) {
38
- if (!Qt.test(e))
37
+ function nr(e, t) {
38
+ if (!rr.test(e))
39
39
  throw new Error(
40
40
  `${t} must be a 0x-prefixed hex string with an even number of hex chars`
41
41
  );
42
42
  }
43
- function qe(e) {
44
- Jt(e.btcVaultRegistryAddress, "btcVaultRegistryAddress"), W(e.vaultId, "vaultId");
45
- const t = De(e.secret);
46
- if (W(t, "secret"), e.hashlock !== void 0 && (W(e.hashlock, "hashlock"), !pt(t, e.hashlock)))
43
+ function ze(e) {
44
+ or(e.btcVaultRegistryAddress, "btcVaultRegistryAddress"), Z(e.vaultId, "vaultId");
45
+ const t = Fe(e.secret);
46
+ if (Z(t, "secret"), e.hashlock !== void 0 && (Z(e.hashlock, "hashlock"), !bt(t, e.hashlock)))
47
47
  throw new Error(
48
48
  "Invalid secret: SHA256(secret) does not match the provided hashlock"
49
49
  );
50
50
  return t;
51
51
  }
52
- async function Oo(e) {
52
+ async function Uo(e) {
53
53
  const {
54
54
  btcVaultRegistryAddress: t,
55
55
  vaultId: r,
@@ -59,23 +59,23 @@ async function Oo(e) {
59
59
  signal: a
60
60
  } = e;
61
61
  a == null || a.throwIfAborted();
62
- const s = qe({
62
+ const s = ze({
63
63
  btcVaultRegistryAddress: t,
64
64
  vaultId: r,
65
65
  secret: e.secret,
66
66
  hashlock: o
67
67
  });
68
- return Zt(n, "activationMetadata"), i({
68
+ return nr(n, "activationMetadata"), i({
69
69
  address: t,
70
- abi: Ke,
70
+ abi: Me,
71
71
  functionName: "activateVaultWithSecret",
72
72
  args: [r, s, n]
73
73
  });
74
74
  }
75
- async function No(e) {
75
+ async function Go(e) {
76
76
  const { btcVaultRegistryAddress: t, vaultId: r, hashlock: o, writeContract: n, signal: i } = e;
77
77
  i == null || i.throwIfAborted();
78
- const a = qe({
78
+ const a = ze({
79
79
  btcVaultRegistryAddress: t,
80
80
  vaultId: r,
81
81
  secret: e.secret,
@@ -83,155 +83,155 @@ async function No(e) {
83
83
  });
84
84
  return n({
85
85
  address: t,
86
- abi: Ke,
86
+ abi: Me,
87
87
  functionName: "activateVaultWithSecretAndRedeem",
88
88
  args: [r, a]
89
89
  });
90
90
  }
91
- class er extends Error {
91
+ class sr extends Error {
92
92
  constructor(t, r) {
93
93
  super(
94
94
  "Transaction graph's challenger set does not match the vault's (local ∪ universal)" + (t.length > 0 ? ` (missing: ${t.join(", ")})` : "") + (r.length > 0 ? ` (unexpected: ${r.join(", ")})` : "") + ". Refusing to sign an incomplete or padded challenger set."
95
95
  ), this.missing = t, this.unexpected = r, this.name = "ChallengerSetMismatchError";
96
96
  }
97
97
  }
98
- function tr(e) {
99
- const t = Le({
98
+ function ar(e) {
99
+ const t = Ge({
100
100
  claimerBtcPubkey: e.depositorBtcPubkey,
101
101
  depositorBtcPubkey: e.depositorBtcPubkey,
102
102
  vaultProviderBtcPubkey: e.vaultProviderBtcPubkey,
103
103
  vaultKeeperBtcPubkeys: e.vaultKeeperBtcPubkeys
104
- }), r = e.universalChallengerBtcPubkeys.map(ve), o = t.filter((l) => r.includes(l));
104
+ }), r = e.universalChallengerBtcPubkeys.map(xe), o = t.filter((c) => r.includes(c));
105
105
  if (o.length > 0)
106
106
  throw new Error(
107
107
  `Cannot check the challenger set: vault keepers and universal challengers overlap (${o.join(", ")}).`
108
108
  );
109
- const n = e.graphChallengerPubkeys.map(ve), i = new Set(n);
109
+ const n = e.graphChallengerPubkeys.map(xe), i = new Set(n);
110
110
  if (i.size !== n.length)
111
111
  throw new Error(
112
112
  "Transaction graph lists the same challenger more than once."
113
113
  );
114
- const a = [...t, ...r], s = new Set(a), u = a.filter((l) => !i.has(l)), c = n.filter((l) => !s.has(l));
115
- if (u.length > 0 || c.length > 0)
116
- throw new er(u, c);
114
+ const a = [...t, ...r], s = new Set(a), u = a.filter((c) => !i.has(c)), l = n.filter((c) => !s.has(c));
115
+ if (u.length > 0 || l.length > 0)
116
+ throw new sr(u, l);
117
117
  }
118
- function ve(e) {
119
- return f(e).toLowerCase();
118
+ function xe(e) {
119
+ return b(e).toLowerCase();
120
120
  }
121
- const je = 0;
122
- class rr extends Error {
121
+ const We = 0;
122
+ class ir extends Error {
123
123
  constructor(t, r) {
124
124
  super(
125
- `Payout transaction output ${je} pays ${r}, not the vault's registered payout script ${t}. Refusing to sign a payout to another destination.`
125
+ `Payout transaction output ${We} pays ${r}, not the vault's registered payout script ${t}. Refusing to sign a payout to another destination.`
126
126
  ), this.expectedScriptHex = t, this.actualScriptHex = r, this.name = "PayoutDestinationError";
127
127
  }
128
128
  }
129
- function or(e) {
129
+ function ur(e) {
130
130
  let t;
131
131
  try {
132
- t = Ue.fromBase64(e.payoutPsbtBase64);
132
+ t = Xe.fromBase64(e.payoutPsbtBase64);
133
133
  } catch (u) {
134
134
  throw new Error("Payout PSBT cannot be parsed.", { cause: u });
135
135
  }
136
- const { version: r, locktime: o, outs: n } = nr(t);
137
- if (r !== pe || o !== de)
136
+ const { version: r, locktime: o, outs: n } = cr(t);
137
+ if (r !== ge || o !== fe)
138
138
  throw new Error(
139
- `Payout transaction has version ${r} and locktime ${o}, expected ${pe} and ${de}.`
139
+ `Payout transaction has version ${r} and locktime ${o}, expected ${ge} and ${fe}.`
140
140
  );
141
- if (n.length !== z)
141
+ if (n.length !== J)
142
142
  throw new Error(
143
- `Payout transaction has ${n.length} output(s), expected exactly ${z} for a depositor-as-claimer payout.`
143
+ `Payout transaction has ${n.length} output(s), expected exactly ${J} for a depositor-as-claimer payout.`
144
144
  );
145
- const i = f(
145
+ const i = b(
146
146
  e.registeredPayoutScriptPubKey
147
147
  ).toLowerCase();
148
148
  if (i.length === 0)
149
149
  throw new Error(
150
150
  "registeredPayoutScriptPubKey is empty; the vault's on-chain payout script is required to check the Payout destination."
151
151
  );
152
- const a = n[je].script.toString("hex").toLowerCase();
153
- if (!I.from(a, "hex").equals(I.from(i, "hex")))
154
- throw new rr(i, a);
155
- const s = n[z - 1];
156
- if (s.value !== ge)
152
+ const a = n[We].script.toString("hex").toLowerCase();
153
+ if (!A.from(a, "hex").equals(A.from(i, "hex")))
154
+ throw new ir(i, a);
155
+ const s = n[J - 1];
156
+ if (s.value !== ye)
157
157
  throw new Error(
158
- `Payout CPFP anchor value ${s.value} sats must equal ${ge} sats.`
158
+ `Payout CPFP anchor value ${s.value} sats must equal ${ye} sats.`
159
159
  );
160
160
  }
161
- function nr(e) {
161
+ function cr(e) {
162
162
  return {
163
163
  version: e.version,
164
164
  locktime: e.locktime,
165
165
  outs: e.txOutputs.map((t) => ({
166
- script: I.from(t.script),
166
+ script: A.from(t.script),
167
167
  value: t.value
168
168
  }))
169
169
  };
170
170
  }
171
- const ze = 0;
172
- class sr extends Error {
171
+ const Ye = 0;
172
+ class lr extends Error {
173
173
  constructor(t, r, o) {
174
174
  super(
175
175
  `Transaction graph does not belong to vault ${t}: its Claim spends PegIn ${o}, which derives vault ${r}. Refusing to sign for a graph served for another vault.`
176
176
  ), this.expectedVaultId = t, this.derivedVaultId = r, this.peginTxid = o, this.name = "VaultIdBindingError";
177
177
  }
178
178
  }
179
- function ar(e) {
179
+ function hr(e) {
180
180
  let t;
181
181
  try {
182
- t = Ue.fromBase64(e);
182
+ t = Xe.fromBase64(e);
183
183
  } catch (o) {
184
184
  throw new Error("Claim PSBT cannot be parsed.", { cause: o });
185
185
  }
186
- const r = t.txInputs[ze];
186
+ const r = t.txInputs[Ye];
187
187
  if (!r)
188
188
  throw new Error("Claim PSBT carries no PegIn input to bind the vault to.");
189
- return Ye(r.hash);
189
+ return Je(r.hash);
190
190
  }
191
- function ir(e) {
192
- const t = e.ins[ze];
191
+ function pr(e) {
192
+ const t = e.ins[Ye];
193
193
  if (!t)
194
194
  throw new Error(
195
195
  "Artifacts file's claim_tx carries no PegIn input to bind the vault to."
196
196
  );
197
- return Ye(t.hash);
197
+ return Je(t.hash);
198
198
  }
199
- function We(e) {
200
- const t = X(
201
- Bt(e.peginTxid, e.depositorEthAddress)
202
- ), r = X(e.expectedVaultId);
199
+ function Qe(e) {
200
+ const t = z(
201
+ Kt(e.peginTxid, e.depositorEthAddress)
202
+ ), r = z(e.expectedVaultId);
203
203
  if (t !== r)
204
- throw new sr(r, t, e.peginTxid);
204
+ throw new lr(r, t, e.peginTxid);
205
205
  }
206
- function X(e) {
206
+ function z(e) {
207
207
  return `0x${(e.startsWith("0x") ? e.slice(2) : e).toLowerCase()}`;
208
208
  }
209
- function Ye(e) {
210
- return I.from(e).reverse().toString("hex");
209
+ function Je(e) {
210
+ return A.from(e).reverse().toString("hex");
211
211
  }
212
- const ur = 0, cr = 0, lr = 1, hr = 0, pr = 0;
213
- async function Ho(e) {
212
+ const dr = 0, gr = 0, fr = 1, yr = 0, br = 0;
213
+ async function Xo(e) {
214
214
  const { txGraphVersion: t } = e.vault, r = e.source.txGraphJson, [o, n, i, a] = await Promise.all([
215
- mt(t, r),
216
- vt(t, r),
217
- Pt(t, r),
218
- wt(t, r)
215
+ Et(t, r),
216
+ _t(t, r),
217
+ kt(t, r),
218
+ Tt(t, r)
219
219
  ]);
220
- We({
221
- peginTxid: ar(o),
220
+ Qe({
221
+ peginTxid: hr(o),
222
222
  depositorEthAddress: e.vault.depositorEthAddress,
223
223
  expectedVaultId: e.vault.vaultId
224
224
  });
225
- const s = await xt(
225
+ const s = await $t(
226
226
  t,
227
227
  r
228
228
  );
229
- for (const w of [i, s])
230
- or({
231
- payoutPsbtBase64: w,
229
+ for (const x of [i, s])
230
+ ur({
231
+ payoutPsbtBase64: x,
232
232
  registeredPayoutScriptPubKey: e.vault.registeredPayoutScriptPubKey
233
233
  });
234
- tr({
234
+ ar({
235
235
  graphChallengerPubkeys: Object.keys(a),
236
236
  depositorBtcPubkey: e.depositorPublicKey,
237
237
  vaultProviderBtcPubkey: e.vault.vaultProviderBtcPubkey,
@@ -239,45 +239,45 @@ async function Ho(e) {
239
239
  universalChallengerBtcPubkeys: e.vault.universalChallengerBtcPubkeys
240
240
  });
241
241
  const u = [
242
- { psbtBase64: o, inputIndex: ur },
243
- { psbtBase64: n, inputIndex: cr },
244
- { psbtBase64: i, inputIndex: lr },
242
+ { psbtBase64: o, inputIndex: dr },
243
+ { psbtBase64: n, inputIndex: gr },
244
+ { psbtBase64: i, inputIndex: fr },
245
245
  {
246
246
  psbtBase64: s,
247
- inputIndex: hr
247
+ inputIndex: yr
248
248
  }
249
- ], c = Object.keys(a);
250
- for (const w of c)
251
- for (const x of a[w])
252
- u.push({ psbtBase64: x, inputIndex: pr });
253
- const l = await gr(
249
+ ], l = Object.keys(a);
250
+ for (const x of l)
251
+ for (const w of a[x])
252
+ u.push({ psbtBase64: w, inputIndex: br });
253
+ const c = await vr(
254
254
  e.btcWallet,
255
255
  e.depositorPublicKey,
256
256
  e.btcNetwork,
257
257
  u
258
258
  );
259
259
  let h = 0;
260
- const p = l[h++], d = l[h++], g = l[h++], b = l[h++], y = {};
261
- for (const w of c) {
262
- const x = a[w].length;
263
- y[w] = l.slice(
260
+ const p = c[h++], d = c[h++], g = c[h++], y = c[h++], f = {};
261
+ for (const x of l) {
262
+ const w = a[x].length;
263
+ f[x] = c.slice(
264
264
  h,
265
- h + x
266
- ), h += x;
265
+ h + w
266
+ ), h += w;
267
267
  }
268
- const m = await Et(
268
+ const P = await Ct(
269
269
  t,
270
270
  r,
271
271
  p
272
272
  );
273
- return kt({
273
+ return At({
274
274
  txGraphVersion: t,
275
275
  graphJson: r,
276
- signedClaimTxHex: m,
276
+ signedClaimTxHex: P,
277
277
  assertClaimerSigHex: d,
278
278
  payoutClaimerSigHex: g,
279
- wronglyChallengedSigs: y,
280
- depositorPayoutSigHex: b,
279
+ wronglyChallengedSigs: f,
280
+ depositorPayoutSigHex: y,
281
281
  verifyingKeyHex: e.source.verifyingKeyHex,
282
282
  claimableEventBlockNumber: e.vault.claimableEventBlockNumber,
283
283
  proverCircuitVersion: e.vault.proverCircuitVersion,
@@ -286,7 +286,7 @@ async function Ho(e) {
286
286
  expectedVaultCoreVersion: e.vault.vaultCoreVersion
287
287
  });
288
288
  }
289
- function Pe(e) {
289
+ function we(e) {
290
290
  const t = e.replace(/^0x/, "").toLowerCase();
291
291
  if (t.length === 66) return t.slice(2);
292
292
  if (t.length === 64) return t;
@@ -294,29 +294,29 @@ function Pe(e) {
294
294
  `Public key must be 33-byte compressed or 32-byte x-only hex, got ${t.length / 2} bytes.`
295
295
  );
296
296
  }
297
- async function dr(e, t, r) {
297
+ async function mr(e, t, r) {
298
298
  const o = await e.getPublicKeyHex();
299
- if (Pe(o) !== Pe(t))
299
+ if (we(o) !== we(t))
300
300
  throw new Error(
301
301
  "Connected wallet does not hold the vault's depositor key. Select the account that made the deposit, then try again."
302
302
  );
303
303
  const n = await e.getAddress();
304
- if (!lt(n, t, r))
304
+ if (!ft(n, t, r))
305
305
  throw new Error(
306
306
  `Connected wallet reports address "${n}", which is not derived from the vault's depositor key. Select the account that made the deposit, then try again.`
307
307
  );
308
308
  return n;
309
309
  }
310
- async function gr(e, t, r, o) {
311
- const n = await dr(
310
+ async function vr(e, t, r, o) {
311
+ const n = await mr(
312
312
  e,
313
313
  t,
314
314
  r
315
- ), i = await Fe(
315
+ ), i = await Ue(
316
316
  e,
317
- o.map((a) => fr(a.psbtBase64)),
317
+ o.map((a) => Pr(a.psbtBase64)),
318
318
  o.map(
319
- (a) => yt(
319
+ (a) => xt(
320
320
  t,
321
321
  a.inputIndex,
322
322
  n
@@ -325,31 +325,31 @@ async function gr(e, t, r, o) {
325
325
  );
326
326
  return Promise.all(
327
327
  i.map(
328
- (a, s) => _t(yr(a), o[s].inputIndex)
328
+ (a, s) => St(xr(a), o[s].inputIndex)
329
329
  )
330
330
  );
331
331
  }
332
- function fr(e) {
333
- return I.from(e, "base64").toString("hex");
332
+ function Pr(e) {
333
+ return A.from(e, "base64").toString("hex");
334
334
  }
335
- function yr(e) {
336
- return I.from(e, "hex").toString("base64");
335
+ function xr(e) {
336
+ return A.from(e, "hex").toString("base64");
337
337
  }
338
- async function Ko(e) {
339
- const t = await Rt(e.btcWallet, e.vaultContext);
338
+ async function qo(e) {
339
+ const t = await Nt(e.btcWallet, e.vaultContext);
340
340
  let r;
341
341
  try {
342
- r = await Tt(t, e.htlcVout);
342
+ r = await It(t, e.htlcVout);
343
343
  } finally {
344
344
  t.fill(0);
345
345
  }
346
346
  let o;
347
347
  try {
348
- o = await $t(r);
348
+ o = await Rt(r);
349
349
  } finally {
350
350
  r.fill(0);
351
351
  }
352
- return br(o.pk_hash, e.expectedWotsPkHash), await Ct(
352
+ return wr(o.pk_hash, e.expectedWotsPkHash), await Bt(
353
353
  e.txGraphVersion,
354
354
  o.keypair,
355
355
  e.txGraphJson
@@ -358,61 +358,61 @@ async function Ko(e) {
358
358
  pkHash: o.pk_hash
359
359
  };
360
360
  }
361
- function br(e, t) {
362
- if (M(e) !== M(t))
361
+ function wr(e, t) {
362
+ if (L(e) !== L(t))
363
363
  throw new Error(
364
- `Derived WOTS public-key hash ${M(e)} does not match the vault's on-chain depositorWotsPkHash ${M(t)}. The wallet, the HTLC output index, or the derivation itself is not the one this vault was created with.`
364
+ `Derived WOTS public-key hash ${L(e)} does not match the vault's on-chain depositorWotsPkHash ${L(t)}. The wallet, the HTLC output index, or the derivation itself is not the one this vault was created with.`
365
365
  );
366
366
  }
367
- function M(e) {
367
+ function L(e) {
368
368
  return `0x${(e.startsWith("0x") ? e.slice(2) : e).toLowerCase()}`;
369
369
  }
370
- const mr = 3;
371
- class vr extends Error {
370
+ const Er = 3;
371
+ class _r extends Error {
372
372
  constructor(t, r) {
373
373
  super(
374
374
  `Artifacts belong to vault ${r}, not ${t}. Select the artifacts file saved for this vault.`
375
375
  ), this.expectedVaultId = t, this.actualVaultId = r, this.name = "ArtifactsVaultMismatchError";
376
376
  }
377
377
  }
378
- function Pr(e) {
378
+ function kr(e) {
379
379
  let t;
380
380
  try {
381
381
  t = JSON.parse(e);
382
382
  } catch (a) {
383
383
  throw new Error("Artifacts file is not valid JSON.", { cause: a });
384
384
  }
385
- const r = we(t.vault_id, "vault_id"), o = wr(we(t.claim_tx, "claim_tx")), n = Y(
385
+ const r = Ee(t.vault_id, "vault_id"), o = Tr(Ee(t.claim_tx, "claim_tx")), n = ee(
386
386
  t.prover_circuit_version,
387
387
  "prover_circuit_version"
388
388
  ), i = t.claimable_event_block_number === void 0 ? 0n : BigInt(
389
- Y(
389
+ ee(
390
390
  t.claimable_event_block_number,
391
391
  "claimable_event_block_number"
392
392
  )
393
393
  );
394
394
  return {
395
- vaultCoreVersion: t.vault_core_version === void 0 ? void 0 : Y(t.vault_core_version, "vault_core_version"),
395
+ vaultCoreVersion: t.vault_core_version === void 0 ? void 0 : ee(t.vault_core_version, "vault_core_version"),
396
396
  vaultId: r,
397
397
  claimTxid: o.getId(),
398
- peginTxid: ir(o),
398
+ peginTxid: pr(o),
399
399
  proverCircuitVersion: n,
400
400
  claimableEventBlockNumber: i,
401
401
  babeSessionChallengerPubkeys: Object.keys(
402
- xr(t.babe_sessions, "babe_sessions")
402
+ $r(t.babe_sessions, "babe_sessions")
403
403
  )
404
404
  };
405
405
  }
406
- async function Do(e) {
407
- const t = Pr(e.artifactsJson), r = X(e.expectedVaultId), o = X(t.vaultId);
406
+ async function jo(e) {
407
+ const t = kr(e.artifactsJson), r = z(e.expectedVaultId), o = z(t.vaultId);
408
408
  if (r !== o)
409
- throw new vr(r, o);
410
- We({
409
+ throw new _r(r, o);
410
+ Qe({
411
411
  peginTxid: t.peginTxid,
412
412
  depositorEthAddress: e.depositorEthAddress,
413
413
  expectedVaultId: r
414
414
  });
415
- const n = e.txGraphVersion ?? mr;
415
+ const n = e.txGraphVersion ?? Er;
416
416
  if (t.vaultCoreVersion !== void 0 && t.vaultCoreVersion !== n)
417
417
  throw new Error(
418
418
  `Artifacts record vault core version ${t.vaultCoreVersion}, but verification was asked for version ${n}.`
@@ -421,9 +421,9 @@ async function Do(e) {
421
421
  throw new Error(
422
422
  "Artifacts carry no claimable event block number. They were assembled before the Ethereum withdrawal was initiated; assemble them again."
423
423
  );
424
- return await At(n, e.artifactsJson), t;
424
+ return await Vt(n, e.artifactsJson), t;
425
425
  }
426
- function wr(e) {
426
+ function Tr(e) {
427
427
  try {
428
428
  return B.fromHex(e);
429
429
  } catch (t) {
@@ -432,51 +432,51 @@ function wr(e) {
432
432
  });
433
433
  }
434
434
  }
435
- function we(e, t) {
435
+ function Ee(e, t) {
436
436
  if (typeof e != "string" || e.length === 0)
437
437
  throw new Error(`Artifacts file is missing a usable "${t}".`);
438
438
  return e;
439
439
  }
440
- function Y(e, t) {
440
+ function ee(e, t) {
441
441
  if (typeof e != "number" || !Number.isSafeInteger(e) || e < 0)
442
442
  throw new Error(`Artifacts file is missing a usable "${t}".`);
443
443
  return e;
444
444
  }
445
- function xr(e, t) {
445
+ function $r(e, t) {
446
446
  if (e === void 0) return {};
447
447
  if (typeof e != "object" || e === null || Array.isArray(e))
448
448
  throw new Error(`Artifacts file is missing a usable "${t}".`);
449
449
  return e;
450
450
  }
451
- const Er = 8, kr = 6e3, _r = 10 * 6e4, Tr = 10;
452
- class Qe extends Error {
451
+ const Cr = 8, Ar = 6e3, Sr = 10 * 6e4, Ir = 10;
452
+ class Ze extends Error {
453
453
  constructor(t) {
454
454
  super(t), this.name = "PeginRegistrationMissingError";
455
455
  }
456
456
  }
457
- class Je extends Error {
457
+ class et extends Error {
458
458
  constructor(t) {
459
459
  super(t), this.name = "PeginRegistrationNotFinalError";
460
460
  }
461
461
  }
462
- function $r(e) {
463
- return e instanceof Qe || e instanceof Error && e.name === "PeginRegistrationMissingError";
462
+ function Rr(e) {
463
+ return e instanceof Ze || e instanceof Error && e.name === "PeginRegistrationMissingError";
464
464
  }
465
- function Mo(e) {
466
- return e instanceof Je || e instanceof Error && e.name === "PeginRegistrationNotFinalError";
465
+ function zo(e) {
466
+ return e instanceof et || e instanceof Error && e.name === "PeginRegistrationNotFinalError";
467
467
  }
468
- function xe(e) {
468
+ function _e(e) {
469
469
  const { currentBlock: t, createdAtBlock: r } = e, o = t - r + 1n;
470
470
  return o < 0n ? 0 : Number(o);
471
471
  }
472
- async function Fo(e) {
472
+ async function Wo(e) {
473
473
  const {
474
474
  vaultRegistryReader: t,
475
475
  getBlockNumber: r,
476
476
  vaultIds: o,
477
- required: n = Er,
478
- pollIntervalMs: i = kr,
479
- timeoutMs: a = _r,
477
+ required: n = Cr,
478
+ pollIntervalMs: i = Ar,
479
+ timeoutMs: a = Sr,
480
480
  signal: s,
481
481
  onProgress: u
482
482
  } = e;
@@ -484,70 +484,70 @@ async function Fo(e) {
484
484
  throw new Error(
485
485
  "waitForPeginRegistrationDepth requires at least one vault ID"
486
486
  );
487
- const c = Date.now();
488
- let l = !1, h = 0, p;
487
+ const l = Date.now();
488
+ let c = !1, h = 0, p;
489
489
  for (; ; ) {
490
490
  if (s != null && s.aborted)
491
491
  throw new Error(
492
492
  `Aborted while waiting for peg-in registration depth (${o.length} vault(s))`
493
493
  );
494
- if (Date.now() - c >= a)
495
- throw new Je(
494
+ if (Date.now() - l >= a)
495
+ throw new et(
496
496
  `Peg-in registration did not reach ${n} Ethereum confirmations within ${a}ms. The registration transaction was submitted but is not yet final, so the Pre-PegIn Bitcoin transaction was never sent and no funds are at risk. Resume this deposit from the dashboard once the network settles.` + (p instanceof Error ? ` Last read error: ${p.message}` : "")
497
497
  );
498
498
  try {
499
499
  const d = await r(), g = await Promise.all(
500
- o.map((y) => t.getVaultBasicInfo(y))
501
- ), b = g.findIndex(
502
- (y) => y.depositor === Vt || y.createdAt === 0n
500
+ o.map((f) => t.getVaultBasicInfo(f))
501
+ ), y = g.findIndex(
502
+ (f) => f.depositor === Dt || f.createdAt === 0n
503
503
  );
504
- if (b !== -1) {
505
- if (h += 1, !l && h > Tr)
506
- throw new Qe(
507
- `Vault ${o[b]} is still not visible on-chain after ${h} reads — the registration does not exist.`
504
+ if (y !== -1) {
505
+ if (h += 1, !c && h > Ir)
506
+ throw new Ze(
507
+ `Vault ${o[y]} is still not visible on-chain after ${h} reads — the registration does not exist.`
508
508
  );
509
509
  console.warn(
510
- `Peg-in registration for vault ${o[b]} is not visible in chain state at block ${d} — a lagging RPC backend or an Ethereum reorg. Still polling.`
510
+ `Peg-in registration for vault ${o[y]} is not visible in chain state at block ${d} — a lagging RPC backend or an Ethereum reorg. Still polling.`
511
511
  ), u == null || u({ confirmations: 0, required: n });
512
512
  } else {
513
- l = !0, h = 0, p = void 0;
514
- let y = g[0], m = xe({
513
+ c = !0, h = 0, p = void 0;
514
+ let f = g[0], P = _e({
515
515
  currentBlock: d,
516
516
  createdAtBlock: g[0].createdAt
517
517
  });
518
- for (const w of g.slice(1)) {
519
- const x = xe({
518
+ for (const x of g.slice(1)) {
519
+ const w = _e({
520
520
  currentBlock: d,
521
- createdAtBlock: w.createdAt
521
+ createdAtBlock: x.createdAt
522
522
  });
523
- x < m && (m = x, y = w);
523
+ w < P && (P = w, f = x);
524
524
  }
525
- if (u == null || u({ confirmations: m, required: n }), m >= n)
526
- return { confirmations: m, basicInfo: y };
525
+ if (u == null || u({ confirmations: P, required: n }), P >= n)
526
+ return { confirmations: P, basicInfo: f };
527
527
  }
528
528
  } catch (d) {
529
- if ($r(d))
529
+ if (Rr(d))
530
530
  throw d;
531
531
  console.warn(
532
532
  `Registration-depth read failed (retrying in ${i}ms): ` + (d instanceof Error ? d.message : String(d))
533
533
  ), p = d;
534
534
  }
535
535
  await new Promise((d, g) => {
536
- const b = () => {
537
- clearTimeout(y), g(
536
+ const y = () => {
537
+ clearTimeout(f), g(
538
538
  new Error(
539
539
  `Aborted while waiting for peg-in registration depth (${o.length} vault(s))`
540
540
  )
541
541
  );
542
- }, y = setTimeout(() => {
543
- s == null || s.removeEventListener("abort", b), d();
542
+ }, f = setTimeout(() => {
543
+ s == null || s.removeEventListener("abort", y), d();
544
544
  }, i);
545
- s == null || s.addEventListener("abort", b, { once: !0 });
545
+ s == null || s.addEventListener("abort", y, { once: !0 });
546
546
  });
547
547
  }
548
548
  }
549
- const Cr = /^(?:[0-9a-f]{2})*$/, Ar = /^[0-9a-f]{64}$/, Sr = /^([0-9a-f]{64}):(0|[1-9][0-9]*)$/, Ir = -2147483648, Rr = 2147483647, Q = 4294967295, Ee = 2, ke = 2;
550
- class P extends Error {
549
+ const Br = /^(?:[0-9a-f]{2})*$/, Vr = /^[0-9a-f]{64}$/, Hr = /^([0-9a-f]{64}):(0|[1-9][0-9]*)$/, Or = -2147483648, Nr = 2147483647, te = 4294967295, ke = 2, Te = 2, W = 0;
550
+ class m extends Error {
551
551
  constructor(t) {
552
552
  super(t), this.name = "GraphFingerprintError";
553
553
  }
@@ -555,264 +555,317 @@ class P extends Error {
555
555
  function E(e, t, r) {
556
556
  const o = e[t];
557
557
  if (o === void 0)
558
- throw new P(`Graph tx ${r} is missing "${t}"`);
558
+ throw new m(`Graph tx ${r} is missing "${t}"`);
559
559
  return o;
560
560
  }
561
- function D(e, t) {
561
+ function M(e, t) {
562
562
  if (!Array.isArray(e))
563
- throw new P(`Graph tx ${t} is not an array`);
563
+ throw new m(`Graph tx ${t} is not an array`);
564
564
  return e;
565
565
  }
566
- function A(e, t) {
566
+ function S(e, t) {
567
567
  if (e === null || typeof e != "object" || Array.isArray(e))
568
- throw new P(`Graph tx ${t} is not an object`);
568
+ throw new m(`Graph tx ${t} is not an object`);
569
569
  return e;
570
570
  }
571
- function H(e, t, r, o) {
571
+ function D(e, t, r, o) {
572
572
  if (typeof e != "number" || !Number.isSafeInteger(e) || e < r || e > o)
573
- throw new P(
573
+ throw new m(
574
574
  `Graph tx ${t} is not an integer in [${r}, ${o}]`
575
575
  );
576
576
  return e;
577
577
  }
578
- function J(e, t) {
579
- if (typeof e != "string" || !Cr.test(e))
580
- throw new P(
578
+ function re(e, t) {
579
+ if (typeof e != "string" || !Br.test(e))
580
+ throw new m(
581
581
  `Graph tx ${t} is not lowercase hex without a prefix`
582
582
  );
583
- return I.from(e, "hex");
583
+ return A.from(e, "hex");
584
584
  }
585
- function q(e, t) {
586
- if (typeof e != "string" || !Ar.test(e))
587
- throw new P(
585
+ function Y(e, t) {
586
+ if (typeof e != "string" || !Vr.test(e))
587
+ throw new m(
588
588
  `Graph ${t} is not 32 bytes of lowercase hex`
589
589
  );
590
590
  return e;
591
591
  }
592
- function _e(e, t) {
593
- const r = A(e, t), o = new B();
594
- return o.version = H(
592
+ function $e(e, t) {
593
+ const r = S(e, t), o = new B();
594
+ return o.version = D(
595
595
  E(r, "version", t),
596
596
  `${t}.version`,
597
- Ir,
598
- Rr
599
- ), o.locktime = H(
597
+ Or,
598
+ Nr
599
+ ), o.locktime = D(
600
600
  E(r, "lock_time", t),
601
601
  `${t}.lock_time`,
602
602
  0,
603
- Q
604
- ), D(E(r, "input", t), `${t}.input`).forEach((n, i) => {
605
- const a = `${t}.input[${i}]`, s = A(n, a), u = E(s, "previous_output", a), c = typeof u == "string" && Sr.exec(u);
606
- if (!c)
607
- throw new P(
603
+ te
604
+ ), M(E(r, "input", t), `${t}.input`).forEach((n, i) => {
605
+ const a = `${t}.input[${i}]`, s = S(n, a), u = E(s, "previous_output", a), l = typeof u == "string" && Hr.exec(u);
606
+ if (!l)
607
+ throw new m(
608
608
  `Graph tx ${a}.previous_output is not "<txid>:<vout>"`
609
609
  );
610
- const l = H(Number(c[2]), `${a}.previous_output vout`, 0, Q);
610
+ const c = D(Number(l[2]), `${a}.previous_output vout`, 0, te);
611
611
  o.addInput(
612
- I.from(c[1], "hex").reverse(),
613
- l,
614
- H(E(s, "sequence", a), `${a}.sequence`, 0, Q),
615
- J(E(s, "script_sig", a), `${a}.script_sig`)
616
- ), o.ins[i].witness = D(
612
+ A.from(l[1], "hex").reverse(),
613
+ c,
614
+ D(E(s, "sequence", a), `${a}.sequence`, 0, te),
615
+ re(E(s, "script_sig", a), `${a}.script_sig`)
616
+ ), o.ins[i].witness = M(
617
617
  E(s, "witness", a),
618
618
  `${a}.witness`
619
- ).map((h, p) => J(h, `${a}.witness[${p}]`));
620
- }), D(E(r, "output", t), `${t}.output`).forEach((n, i) => {
621
- const a = `${t}.output[${i}]`, s = A(n, a);
619
+ ).map((h, p) => re(h, `${a}.witness[${p}]`));
620
+ }), M(E(r, "output", t), `${t}.output`).forEach((n, i) => {
621
+ const a = `${t}.output[${i}]`, s = S(n, a);
622
622
  o.addOutput(
623
- J(E(s, "script_pubkey", a), `${a}.script_pubkey`),
624
- H(E(s, "value", a), `${a}.value`, 0, Number.MAX_SAFE_INTEGER)
623
+ re(E(s, "script_pubkey", a), `${a}.script_pubkey`),
624
+ D(E(s, "value", a), `${a}.value`, 0, Number.MAX_SAFE_INTEGER)
625
625
  );
626
626
  }), new Uint8Array(o.toBuffer());
627
627
  }
628
- function K(e, t) {
629
- const r = f(e).toLowerCase();
628
+ function O(e, t) {
629
+ const r = b(e).toLowerCase();
630
630
  let o;
631
631
  try {
632
632
  o = B.fromHex(r);
633
633
  } catch (n) {
634
- throw new P(
634
+ throw new m(
635
635
  `Presign ${t} is not one transaction: ${n instanceof Error ? n.message : String(n)}`
636
636
  );
637
637
  }
638
638
  if (o.toHex() !== r)
639
- throw new P(
639
+ throw new m(
640
640
  `Presign ${t} is not a canonical transaction encoding`
641
641
  );
642
642
  return o;
643
643
  }
644
- function Br(e, t) {
644
+ function tt(e, t) {
645
+ const r = e.ins[t];
646
+ if (r)
647
+ return {
648
+ txid: A.from(r.hash).reverse().toString("hex"),
649
+ vout: r.index
650
+ };
651
+ }
652
+ function rt(e, t) {
653
+ if (!e.outs[W])
654
+ throw new m(
655
+ `Presign ${t}.claim_tx must have output ${W}`
656
+ );
657
+ }
658
+ function Kr(e, t, r) {
659
+ if (e.ins.length !== 1)
660
+ throw new m(
661
+ `Presign ${r}.claim_tx must have exactly one input, got ${e.ins.length}`
662
+ );
663
+ rt(e, r);
664
+ const o = tt(e, 0);
665
+ if ((o == null ? void 0 : o.txid) !== t || o.vout !== G) {
666
+ const n = o ? `${o.txid}:${o.vout}` : "no input";
667
+ throw new m(
668
+ `Presign ${r}.claim_tx must spend ${t}:${G}, got ${n}`
669
+ );
670
+ }
671
+ }
672
+ function le(e, t, r) {
673
+ const o = tt(e, 0);
674
+ if ((o == null ? void 0 : o.txid) !== t || o.vout !== W) {
675
+ const n = o ? `${o.txid}:${o.vout}` : "no input";
676
+ throw new m(
677
+ `Presign ${r}.assert_tx input 0 must spend ${t}:${W}, got ${n}`
678
+ );
679
+ }
680
+ }
681
+ function ot(e) {
682
+ const t = O(e.peginTxHex, `${e.path}.pegin_tx`), r = O(e.claimTxHex, `${e.path}.claim_tx`), o = O(e.assertTxHex, `${e.path}.assert_tx`);
683
+ return { peginTx: t, claimTx: r, assertTx: o };
684
+ }
685
+ function Dr(e) {
686
+ const t = O(e.claimTxHex, `${e.path}.claim_tx`), r = O(e.assertTxHex, `${e.path}.assert_tx`);
687
+ rt(t, e.path), le(r, t.getId(), e.path);
688
+ }
689
+ function Mr(e) {
690
+ const { peginTx: t, claimTx: r, assertTx: o } = ot(e);
691
+ Kr(r, t.getId(), e.path), le(o, r.getId(), e.path);
692
+ }
693
+ function Fr(e, t) {
645
694
  const [r, ...o] = e.ins;
646
695
  if (!r || o.length > 0)
647
- throw new P(
696
+ throw new m(
648
697
  `Presign claim_tx must have exactly one input, got ${e.ins.length}`
649
698
  );
650
- const n = I.from(r.hash).reverse().toString("hex");
651
- if (n !== t || r.index !== he)
652
- throw new P(
653
- `Presign claim_tx must spend ${t}:${he}, got ${n}:${r.index}`
699
+ const n = A.from(r.hash).reverse().toString("hex");
700
+ if (n !== t || r.index !== G)
701
+ throw new m(
702
+ `Presign claim_tx must spend ${t}:${G}, got ${n}:${r.index}`
654
703
  );
655
- if (e.version !== Ee)
656
- throw new P(
657
- `Presign claim_tx version must be ${Ee}, got ${e.version}`
704
+ if (e.version !== ke)
705
+ throw new m(
706
+ `Presign claim_tx version must be ${ke}, got ${e.version}`
658
707
  );
659
708
  if (r.witness.length > 0)
660
- throw new P(
709
+ throw new m(
661
710
  `Presign claim_tx input must have an empty witness, got ${r.witness.length} item(s)`
662
711
  );
663
- if (e.outs.length !== ke)
664
- throw new P(
665
- `Presign claim_tx must have exactly ${ke} outputs, got ${e.outs.length}`
712
+ if (e.outs.length !== Te)
713
+ throw new m(
714
+ `Presign claim_tx must have exactly ${Te} outputs, got ${e.outs.length}`
666
715
  );
667
716
  }
668
- function Ze(e) {
717
+ function nt(e) {
669
718
  const t = [...e.challengers].sort(
670
719
  (o, n) => o.pubkey < n.pubkey ? -1 : o.pubkey > n.pubkey ? 1 : 0
671
720
  ), r = [e.peginTx, e.claimTx, e.assertTx, e.payoutTx];
672
721
  return t.forEach((o, n) => {
673
- const i = q(o.pubkey, "challenger pubkey");
722
+ const i = Y(o.pubkey, "challenger pubkey");
674
723
  if (n > 0 && t[n - 1].pubkey === i)
675
- throw new P(`Graph lists challenger ${i} twice`);
676
- r.push(me(i), o.nopayoutTx);
724
+ throw new m(`Graph lists challenger ${i} twice`);
725
+ r.push(Pe(i), o.nopayoutTx);
677
726
  for (const a of o.outputLabelHashes)
678
- r.push(me(q(a, "output_label_hashes entry")));
679
- }), Mt(Ft(Lt(...r)));
727
+ r.push(Pe(Y(a, "output_label_hashes entry")));
728
+ }), Xt(qt(jt(...r)));
680
729
  }
681
- function Vr(e) {
682
- const t = f(e.peginTxid).toLowerCase(), r = K(e.peginTxHex, "pegin_tx");
730
+ function Lr(e) {
731
+ const t = b(e.peginTxid).toLowerCase(), { peginTx: r, claimTx: o, assertTx: n } = ot({
732
+ peginTxHex: e.peginTxHex,
733
+ claimTxHex: e.claimTxHex,
734
+ assertTxHex: e.assertTxHex,
735
+ path: "depositor_graph"
736
+ });
683
737
  if (r.getId() !== t)
684
- throw new P(
738
+ throw new m(
685
739
  `Presign pegin_tx hashes to ${r.getId()}, expected ${t}`
686
740
  );
687
- const o = K(e.claimTxHex, "claim_tx");
688
- Br(o, t);
689
- const n = (i) => new Uint8Array(i.toBuffer());
690
- return Ze({
691
- peginTx: n(r),
692
- claimTx: n(o),
693
- assertTx: n(K(e.assertTxHex, "assert_tx")),
694
- payoutTx: n(K(e.payoutTxHex, "payout_tx")),
695
- challengers: e.challengers.map((i) => ({
696
- pubkey: C(i.challenger_pubkey),
697
- nopayoutTx: n(K(i.nopayout_tx.tx_hex, "nopayout_tx")),
698
- outputLabelHashes: i.output_label_hashes.map(
699
- (a) => f(a).toLowerCase()
741
+ Fr(o, t), le(n, o.getId(), "depositor_graph");
742
+ const i = (a) => new Uint8Array(a.toBuffer());
743
+ return nt({
744
+ peginTx: i(r),
745
+ claimTx: i(o),
746
+ assertTx: i(n),
747
+ payoutTx: i(O(e.payoutTxHex, "payout_tx")),
748
+ challengers: e.challengers.map((a) => ({
749
+ pubkey: C(a.challenger_pubkey),
750
+ nopayoutTx: i(O(a.nopayout_tx.tx_hex, "nopayout_tx")),
751
+ outputLabelHashes: a.output_label_hashes.map(
752
+ (s) => b(s).toLowerCase()
700
753
  )
701
754
  }))
702
755
  });
703
756
  }
704
- function Or(e) {
705
- const t = (o) => _e(A(E(e, o, "graph"), o).tx, o), r = A(
757
+ function Ur(e) {
758
+ const t = (o) => $e(S(E(e, o, "graph"), o).tx, o), r = S(
706
759
  E(e, "challenger_subgraphs", "graph"),
707
760
  "challenger_subgraphs"
708
761
  );
709
- return Ze({
762
+ return nt({
710
763
  peginTx: t("pegin_tx"),
711
764
  claimTx: t("claim_tx"),
712
765
  assertTx: t("assert_tx"),
713
766
  payoutTx: t("payout_tx"),
714
767
  challengers: Object.entries(r).map(([o, n]) => {
715
- const i = `challenger_subgraphs[${o}]`, a = A(n, i);
768
+ const i = `challenger_subgraphs[${o}]`, a = S(n, i);
716
769
  return {
717
770
  pubkey: o,
718
- nopayoutTx: _e(
719
- A(E(a, "nopayout_tx", i), `${i}.nopayout_tx`).tx,
771
+ nopayoutTx: $e(
772
+ S(E(a, "nopayout_tx", i), `${i}.nopayout_tx`).tx,
720
773
  `${i}.nopayout_tx`
721
774
  ),
722
- outputLabelHashes: D(
775
+ outputLabelHashes: M(
723
776
  E(a, "output_label_hashes", i),
724
777
  `${i}.output_label_hashes`
725
778
  ).map(
726
- (s, u) => q(s, `${i}.output_label_hashes[${u}]`)
779
+ (s, u) => Y(s, `${i}.output_label_hashes[${u}]`)
727
780
  )
728
781
  };
729
782
  })
730
783
  });
731
784
  }
732
- function Nr(e) {
733
- const t = A(
785
+ function Gr(e) {
786
+ const t = S(
734
787
  E(e, "challenger_pubkeys", "graph"),
735
788
  "challenger_pubkeys"
736
789
  ), r = /* @__PURE__ */ new Set();
737
790
  for (const o of ["local", "universal"])
738
- D(
791
+ M(
739
792
  E(t, o, "challenger_pubkeys"),
740
793
  `challenger_pubkeys.${o}`
741
794
  ).forEach((n, i) => {
742
- const a = q(n, `challenger_pubkeys.${o}[${i}]`);
795
+ const a = Y(n, `challenger_pubkeys.${o}[${i}]`);
743
796
  if (r.has(a))
744
- throw new P(
797
+ throw new m(
745
798
  `Graph declares challenger ${a} more than once`
746
799
  );
747
800
  r.add(a);
748
801
  });
749
802
  return r;
750
803
  }
751
- function Lo(e, t) {
752
- const r = Or(e);
804
+ function Yo(e, t) {
805
+ const r = Ur(e);
753
806
  if (r !== t)
754
- throw new P(
807
+ throw new m(
755
808
  `Graph fingerprint ${r} does not match the presign fingerprint ${t}`
756
809
  );
757
810
  const o = Object.keys(
758
- A(e.challenger_subgraphs, "challenger_subgraphs")
759
- ), n = Nr(e);
811
+ S(e.challenger_subgraphs, "challenger_subgraphs")
812
+ ), n = Gr(e);
760
813
  if (o.length !== n.size || o.some((i) => !n.has(i)))
761
- throw new P(
814
+ throw new m(
762
815
  `Graph challenger_subgraphs keys ${o.join(", ")} do not match challenger_pubkeys ${[...n].join(", ")}`
763
816
  );
764
817
  }
765
- const Hr = 1;
766
- function Kr(e, t, r) {
818
+ const Xr = 1;
819
+ function qr(e, t, r) {
767
820
  const o = r.map(
768
- (h) => f(h).toLowerCase()
821
+ (h) => b(h).toLowerCase()
769
822
  ), n = t.filter((h) => o.includes(h));
770
823
  if (n.length > 0)
771
824
  throw new Error(
772
825
  `Cannot validate challenger set: vault keepers and universal challengers overlap (${n.join(", ")})`
773
826
  );
774
827
  const i = [...t, ...o], a = e.map(
775
- (h) => f(h.challenger_pubkey).toLowerCase()
828
+ (h) => b(h.challenger_pubkey).toLowerCase()
776
829
  ), s = new Set(a);
777
830
  if (s.size !== a.length)
778
831
  throw new Error(
779
832
  "Depositor graph contains duplicate challenger entries in challenger_presign_data"
780
833
  );
781
- const u = new Set(i), c = i.filter((h) => !s.has(h)), l = a.filter((h) => !u.has(h));
782
- if (c.length > 0 || l.length > 0)
834
+ const u = new Set(i), l = i.filter((h) => !s.has(h)), c = a.filter((h) => !u.has(h));
835
+ if (l.length > 0 || c.length > 0)
783
836
  throw new Error(
784
- "Depositor graph challenger set does not match expected (local ∪ universal)" + (c.length > 0 ? ` (missing: ${c.join(", ")})` : "") + (l.length > 0 ? ` (unexpected: ${l.join(", ")})` : "")
837
+ "Depositor graph challenger set does not match expected (local ∪ universal)" + (l.length > 0 ? ` (missing: ${l.join(", ")})` : "") + (c.length > 0 ? ` (unexpected: ${c.join(", ")})` : "")
785
838
  );
786
839
  }
787
- function Dr(e, t) {
840
+ function jr(e, t) {
788
841
  const r = e.ins[t];
789
- return Me(new Uint8Array(r.hash).slice().reverse());
842
+ return Le(new Uint8Array(r.hash).slice().reverse());
790
843
  }
791
- function Z(e, t, r, o, n) {
844
+ function oe(e, t, r, o, n) {
792
845
  const i = e.ins[t];
793
846
  if (i.index !== 0)
794
847
  throw new Error(
795
848
  `NoPayout (challenger ${n}) input ${t} expected to spend ${o} vout 0, got vout ${i.index}`
796
849
  );
797
- const a = r.getId(), s = Dr(e, t);
850
+ const a = r.getId(), s = jr(e, t);
798
851
  if (s !== a)
799
852
  throw new Error(
800
853
  `NoPayout (challenger ${n}) input ${t} does not reference ${o} (expected txid ${a}, got ${s})`
801
854
  );
802
855
  }
803
- async function Mr(e, t, r) {
804
- const o = [], n = [], i = [], a = Le({
856
+ async function zr(e, t, r) {
857
+ const o = [], n = [], i = [], a = Ge({
805
858
  claimerBtcPubkey: r.depositorBtcPubkey,
806
859
  depositorBtcPubkey: r.depositorBtcPubkey,
807
860
  vaultProviderBtcPubkey: r.vaultProviderBtcPubkey,
808
861
  vaultKeeperBtcPubkeys: r.vaultKeeperBtcPubkeys
809
862
  });
810
- Kr(
863
+ qr(
811
864
  e.challenger_presign_data,
812
865
  a,
813
866
  r.universalChallengerBtcPubkeys
814
867
  );
815
- const s = await It({
868
+ const s = await Ot({
816
869
  vaultCoreVersion: r.vaultCoreVersion,
817
870
  vkClaimerPayoutScriptPubKeys: r.vkClaimerPayoutScriptPubKeys,
818
871
  vpCommissionScriptPubKey: r.vpCommissionScriptPubKey,
@@ -828,33 +881,33 @@ async function Mr(e, t, r) {
828
881
  network: r.network,
829
882
  claimerBtcPubkey: r.depositorBtcPubkey,
830
883
  registeredPayoutScriptPubKey: r.registeredPayoutScriptPubKey,
831
- commissionBps: Hr,
884
+ commissionBps: Xr,
832
885
  protocolFeeRate: r.protocolFeeRate,
833
886
  councilMembers: r.councilMembers,
834
887
  councilQuorum: r.councilQuorum
835
888
  });
836
889
  o.push(s.psbtHex), n.push(
837
- F(
890
+ U(
838
891
  t,
839
- fe
892
+ be
840
893
  )
841
894
  );
842
- const u = f(r.depositorBtcPubkey), c = B.fromHex(
843
- f(e.assert_tx.tx_hex)
895
+ const u = b(r.depositorBtcPubkey), l = B.fromHex(
896
+ b(e.assert_tx.tx_hex)
844
897
  );
845
- for (const l of e.challenger_presign_data) {
846
- const h = f(l.challenger_pubkey), p = o.length, d = await Fr({
847
- challenger: l,
898
+ for (const c of e.challenger_presign_data) {
899
+ const h = b(c.challenger_pubkey), p = o.length, d = await Wr({
900
+ challenger: c,
848
901
  challengerPubkey: h,
849
902
  claimerPubkey: u,
850
903
  localChallengers: a,
851
- assertTxParsed: c,
904
+ assertTxParsed: l,
852
905
  ctx: r
853
906
  });
854
907
  o.push(d), n.push(
855
- F(
908
+ U(
856
909
  t,
857
- fe
910
+ be
858
911
  )
859
912
  ), i.push({
860
913
  challengerPubkey: h,
@@ -863,7 +916,7 @@ async function Mr(e, t, r) {
863
916
  }
864
917
  return { psbtHexes: o, signOptions: n, challengerEntries: i };
865
918
  }
866
- async function Fr(e) {
919
+ async function Wr(e) {
867
920
  const {
868
921
  challenger: t,
869
922
  challengerPubkey: r,
@@ -872,53 +925,53 @@ async function Fr(e) {
872
925
  assertTxParsed: i,
873
926
  ctx: a
874
927
  } = e;
875
- Ut(
928
+ zt(
876
929
  t.nopayout_tx.tx_hex,
877
930
  r,
878
931
  a.network
879
932
  );
880
933
  const s = B.fromHex(
881
- f(t.nopayout_tx.tx_hex)
934
+ b(t.nopayout_tx.tx_hex)
882
935
  ), u = B.fromHex(
883
- f(t.challenge_assert_x_tx.tx_hex)
884
- ), c = B.fromHex(
885
- f(t.challenge_assert_y_tx.tx_hex)
936
+ b(t.challenge_assert_x_tx.tx_hex)
937
+ ), l = B.fromHex(
938
+ b(t.challenge_assert_y_tx.tx_hex)
886
939
  );
887
940
  if (s.ins.length !== 3)
888
941
  throw new Error(
889
942
  `NoPayout (challenger ${r}) must have exactly 3 inputs, got ${s.ins.length}`
890
943
  );
891
- Z(
944
+ oe(
892
945
  s,
893
946
  0,
894
947
  i,
895
948
  "Assert",
896
949
  r
897
- ), Z(
950
+ ), oe(
898
951
  s,
899
952
  1,
900
953
  u,
901
954
  "ChallengeAssertX",
902
955
  r
903
- ), Z(
956
+ ), oe(
904
957
  s,
905
958
  2,
906
- c,
959
+ l,
907
960
  "ChallengeAssertY",
908
961
  r
909
962
  );
910
- const l = [
963
+ const c = [
911
964
  i.outs[0],
912
965
  u.outs[0],
913
- c.outs[0]
966
+ l.outs[0]
914
967
  ].map((h) => ({
915
- script_pubkey: Me(new Uint8Array(h.script)),
968
+ script_pubkey: Le(new Uint8Array(h.script)),
916
969
  value: h.value
917
970
  }));
918
- return Gt({
971
+ return Wt({
919
972
  noPayoutTxHex: t.nopayout_tx.tx_hex,
920
973
  challengerPubkey: r,
921
- prevouts: l,
974
+ prevouts: c,
922
975
  connectorParams: {
923
976
  txGraphVersion: a.vaultCoreVersion,
924
977
  claimer: o,
@@ -930,13 +983,13 @@ async function Fr(e) {
930
983
  }
931
984
  });
932
985
  }
933
- function Lr(e, t, r) {
934
- L(e[0]);
935
- const n = U(
986
+ function Yr(e, t, r) {
987
+ X(e[0]);
988
+ const n = q(
936
989
  e[0].returnedPsbtHex,
937
990
  r
938
991
  );
939
- G({
992
+ j({
940
993
  requestedPsbtHex: e[0].requestedPsbtHex,
941
994
  signatureHex: n,
942
995
  signerXOnlyPubkeyHex: r,
@@ -944,12 +997,12 @@ function Lr(e, t, r) {
944
997
  });
945
998
  const i = {};
946
999
  for (const a of t) {
947
- L(e[a.noPayoutIdx]);
948
- const s = U(
1000
+ X(e[a.noPayoutIdx]);
1001
+ const s = q(
949
1002
  e[a.noPayoutIdx].returnedPsbtHex,
950
1003
  r
951
1004
  );
952
- G({
1005
+ j({
953
1006
  requestedPsbtHex: e[a.noPayoutIdx].requestedPsbtHex,
954
1007
  signatureHex: s,
955
1008
  signerXOnlyPubkeyHex: r,
@@ -965,109 +1018,116 @@ function Lr(e, t, r) {
965
1018
  per_challenger: i
966
1019
  };
967
1020
  }
968
- async function Ur(e) {
969
- const { depositorGraph: t, btcWallet: r, signingContext: o } = e, n = await r.getPublicKeyHex(), { depositorPubkey: i } = ht(
1021
+ async function Qr(e) {
1022
+ const { depositorGraph: t, btcWallet: r, signingContext: o } = e;
1023
+ Mr({
1024
+ peginTxHex: o.peginTxHex,
1025
+ claimTxHex: t.claim_tx.tx_hex,
1026
+ assertTxHex: t.assert_tx.tx_hex,
1027
+ path: "depositor_graph"
1028
+ });
1029
+ const n = await r.getPublicKeyHex(), { depositorPubkey: i } = yt(
970
1030
  n,
971
- f(o.depositorBtcPubkey)
972
- ), { psbtHexes: a, signOptions: s, challengerEntries: u } = await Mr(
1031
+ b(o.depositorBtcPubkey)
1032
+ ), { psbtHexes: a, signOptions: s, challengerEntries: u } = await zr(
973
1033
  t,
974
1034
  n,
975
1035
  o
976
- ), c = await Fe(
1036
+ ), l = await Ue(
977
1037
  r,
978
1038
  a,
979
1039
  s
980
- ), l = a.map((h, p) => ({
1040
+ ), c = a.map((h, p) => ({
981
1041
  requestedPsbtHex: h,
982
- returnedPsbtHex: c[p]
1042
+ returnedPsbtHex: l[p]
983
1043
  }));
984
- return Lr(
985
- l,
1044
+ return Yr(
1045
+ c,
986
1046
  u,
987
1047
  i
988
1048
  );
989
1049
  }
990
- const Gr = 1e4, O = 10;
991
- async function et(e) {
1050
+ const Jr = 1e4, N = 10;
1051
+ async function st(e) {
992
1052
  const {
993
1053
  statusReader: t,
994
1054
  vaultId: r,
995
1055
  peginTxid: o,
996
1056
  targetStatuses: n,
997
1057
  timeoutMs: i,
998
- pollIntervalMs: a = Gr,
1058
+ pollIntervalMs: a = Jr,
999
1059
  signal: s
1000
1060
  } = e, u = Date.now();
1001
1061
  for (; ; ) {
1002
1062
  if (s != null && s.aborted)
1003
1063
  throw new Error(
1004
- `Polling aborted for vault ${r.slice(0, O)}… (target: ${[...n].join(", ")})`
1064
+ `Polling aborted for vault ${r.slice(0, N)}… (target: ${[...n].join(", ")})`
1005
1065
  );
1006
1066
  if (Date.now() - u >= i)
1007
1067
  throw new Error(
1008
- `Polling timeout after ${i}ms for vault ${r.slice(0, O)}… (target: ${[...n].join(", ")})`
1068
+ `Polling timeout after ${i}ms for vault ${r.slice(0, N)}… (target: ${[...n].join(", ")})`
1009
1069
  );
1010
1070
  try {
1011
- const c = await t.getPeginStatusByVaultId(
1071
+ const l = await t.getPeginStatusByVaultId(
1012
1072
  { vault_id: r },
1013
1073
  s
1014
1074
  );
1015
- if (be(c.vault_id) !== be(r))
1075
+ if (ve(l.vault_id) !== ve(r))
1016
1076
  throw new Error(
1017
- `getPeginStatusByVaultId returned status for vault ${c.vault_id.slice(0, O)}…, requested ${r.slice(0, O)}…`
1077
+ `getPeginStatusByVaultId returned status for vault ${l.vault_id.slice(0, N)}…, requested ${r.slice(0, N)}…`
1018
1078
  );
1019
- if (c.pegin_txid.toLowerCase() !== o.toLowerCase())
1079
+ if (l.pegin_txid.toLowerCase() !== o.toLowerCase())
1020
1080
  throw new Error(
1021
- `getPeginStatusByVaultId returned status for pegin ${c.pegin_txid.slice(0, 8)}…, requested ${o.slice(0, 8)}…`
1081
+ `getPeginStatusByVaultId returned status for pegin ${l.pegin_txid.slice(0, 8)}…, requested ${o.slice(0, 8)}…`
1022
1082
  );
1023
- const l = c.status;
1024
- if (n.has(l) || l === R.ACTIVATED)
1025
- return l;
1026
- if (l === R.EXPIRED || Ht.has(l))
1083
+ const c = l.status;
1084
+ if (n.has(c) || c === R.ACTIVATED)
1085
+ return c;
1086
+ if (c === R.EXPIRED || Lt.has(c))
1027
1087
  throw new Error(
1028
- `Vault ${r.slice(0, O)}… reached terminal status "${l}" while waiting for ${[...n].join(", ")}`
1088
+ `Vault ${r.slice(0, N)}… reached terminal status "${c}" while waiting for ${[...n].join(", ")}`
1029
1089
  );
1030
- } catch (c) {
1031
- if (!(c instanceof Kt && c.code === Dt.PEGIN_NOT_FOUND))
1032
- throw c;
1090
+ } catch (l) {
1091
+ if (!(l instanceof Ut && l.code === Gt.PEGIN_NOT_FOUND))
1092
+ throw l;
1033
1093
  }
1034
- await new Promise((c, l) => {
1094
+ await new Promise((l, c) => {
1035
1095
  const h = () => {
1036
- clearTimeout(p), l(
1096
+ clearTimeout(p), c(
1037
1097
  new Error(
1038
- `Polling aborted for vault ${r.slice(0, O)}… (target: ${[...n].join(", ")})`
1098
+ `Polling aborted for vault ${r.slice(0, N)}… (target: ${[...n].join(", ")})`
1039
1099
  )
1040
1100
  );
1041
1101
  }, p = setTimeout(() => {
1042
- s == null || s.removeEventListener("abort", h), c();
1102
+ s == null || s.removeEventListener("abort", h), l();
1043
1103
  }, a);
1044
1104
  s == null || s.addEventListener("abort", h, { once: !0 });
1045
1105
  });
1046
1106
  }
1047
1107
  }
1048
- const Xr = 1200 * 1e3, tt = /* @__PURE__ */ new Set([
1108
+ const Zr = 1200 * 1e3, at = /* @__PURE__ */ new Set([
1049
1109
  R.PENDING_ACKS,
1050
1110
  R.PENDING_ACTIVATION,
1051
1111
  R.ACTIVATED_PENDING_BROADCAST,
1052
1112
  R.ACTIVATED
1053
- ]), qr = /* @__PURE__ */ new Set([
1113
+ ]), eo = /* @__PURE__ */ new Set([
1054
1114
  R.PENDING_DEPOSITOR_SIGNATURES,
1055
- ...tt
1115
+ ...at
1056
1116
  ]);
1057
- function jr(e) {
1117
+ function to(e) {
1058
1118
  return e.map((t) => ({
1059
- claimerPubkeyXOnly: j(t.claimer_pubkey),
1119
+ claimerPubkeyXOnly: Q(t.claimer_pubkey),
1060
1120
  payoutTxHex: t.payout_tx.tx_hex,
1061
1121
  assertTxHex: t.assert_tx.tx_hex
1062
1122
  }));
1063
1123
  }
1064
- function S(e) {
1065
- return j(e).toLowerCase();
1124
+ function I(e) {
1125
+ return Q(e).toLowerCase();
1066
1126
  }
1067
- function zr(e, t) {
1068
- const r = (u, c, l) => {
1127
+ function ro(e, t) {
1128
+ const r = (u, l, c) => {
1069
1129
  throw new Error(
1070
- `Deposit terms ${u} (${String(c)}) does not match the vault's version-locked signing context (${String(l)}); refusing to sign payouts against terms that describe a different graph.`
1130
+ `Deposit terms ${u} (${String(l)}) does not match the vault's version-locked signing context (${String(c)}); refusing to sign payouts against terms that describe a different graph.`
1071
1131
  );
1072
1132
  }, o = [
1073
1133
  ["protocolFeeRate", e.protocolFeeRate, t.protocolFeeRate],
@@ -1075,11 +1135,11 @@ function zr(e, t) {
1075
1135
  ["timelockPegin", e.timelockPegin, t.timelockPegin],
1076
1136
  ["timelockAssert", e.timelockAssert, t.timelockAssert]
1077
1137
  ];
1078
- for (const [u, c, l] of o)
1079
- c !== l && r(u, c, l);
1080
- const n = (u) => u.map(S).sort(), i = (u, c) => {
1081
- const l = n(u), h = n(c);
1082
- return l.length === h.length && l.every((p, d) => p === h[d]);
1138
+ for (const [u, l, c] of o)
1139
+ l !== c && r(u, l, c);
1140
+ const n = (u) => u.map(I).sort(), i = (u, l) => {
1141
+ const c = n(u), h = n(l);
1142
+ return c.length === h.length && c.every((p, d) => p === h[d]);
1083
1143
  };
1084
1144
  i(e.vaultKeeperBtcPubkeys, t.vaultKeeperBtcPubkeys) || r(
1085
1145
  "vaultKeeperBtcPubkeys",
@@ -1093,8 +1153,8 @@ function zr(e, t) {
1093
1153
  e.universalChallengerBtcPubkeys.join(","),
1094
1154
  t.universalChallengerBtcPubkeys.join(",")
1095
1155
  );
1096
- const a = S(t.vaultProviderBtcPubkey), s = e.vaults.map(
1097
- (u) => S(u.vaultProviderBtcPubkey)
1156
+ const a = I(t.vaultProviderBtcPubkey), s = e.vaults.map(
1157
+ (u) => I(u.vaultProviderBtcPubkey)
1098
1158
  );
1099
1159
  s.includes(a) || r(
1100
1160
  "vaults[].vaultProviderBtcPubkey",
@@ -1102,10 +1162,10 @@ function zr(e, t) {
1102
1162
  t.vaultProviderBtcPubkey
1103
1163
  );
1104
1164
  }
1105
- function Wr(e, t, r, o) {
1106
- const n = S(o), i = [
1107
- S(t),
1108
- ...r.map(S)
1165
+ function oo(e, t, r, o) {
1166
+ const n = I(o), i = [
1167
+ I(t),
1168
+ ...r.map(I)
1109
1169
  ], a = new Set(i);
1110
1170
  if (a.size !== i.length)
1111
1171
  throw new Error(
@@ -1116,17 +1176,17 @@ function Wr(e, t, r, o) {
1116
1176
  "Cannot validate claimer set: depositor key overlaps with vault provider or vault keeper set"
1117
1177
  );
1118
1178
  const s = e.map(
1119
- (p) => S(p.claimer_pubkey)
1179
+ (p) => I(p.claimer_pubkey)
1120
1180
  );
1121
1181
  if (new Set(s).size !== s.length)
1122
1182
  throw new Error("Presign response contains duplicate claimer entries");
1123
- const u = s.filter((p) => p !== n), c = new Set(u), l = i.filter((p) => !c.has(p)), h = u.filter((p) => !a.has(p));
1124
- if (l.length > 0 || h.length > 0)
1183
+ const u = s.filter((p) => p !== n), l = new Set(u), c = i.filter((p) => !l.has(p)), h = u.filter((p) => !a.has(p));
1184
+ if (c.length > 0 || h.length > 0)
1125
1185
  throw new Error(
1126
- "Presign response claimer set does not match expected (vault provider ∪ vault keepers)" + (l.length > 0 ? ` (missing: ${l.join(", ")})` : "") + (h.length > 0 ? ` (unexpected: ${h.join(", ")})` : "")
1186
+ "Presign response claimer set does not match expected (vault provider ∪ vault keepers)" + (c.length > 0 ? ` (missing: ${c.join(", ")})` : "") + (h.length > 0 ? ` (unexpected: ${h.join(", ")})` : "")
1127
1187
  );
1128
1188
  }
1129
- function Te(e, t) {
1189
+ function Ce(e, t) {
1130
1190
  return {
1131
1191
  vaultCoreVersion: t.vaultCoreVersion,
1132
1192
  payoutTxHex: e.payoutTxHex,
@@ -1148,8 +1208,8 @@ function Te(e, t) {
1148
1208
  vpCommissionScriptPubKey: t.vpCommissionScriptPubKey
1149
1209
  };
1150
1210
  }
1151
- async function Yr(e, t, r, o) {
1152
- const n = new gt({
1211
+ async function no(e, t, r, o) {
1212
+ const n = new vt({
1153
1213
  network: t.network,
1154
1214
  btcWallet: e
1155
1215
  }), i = r.length;
@@ -1157,16 +1217,16 @@ async function Yr(e, t, r, o) {
1157
1217
  let a;
1158
1218
  if (n.supportsBatchSigning())
1159
1219
  a = (await n.signPayoutTransactionsBatch(
1160
- r.map((c) => Te(c, t))
1161
- )).map((c) => c.payoutSignature);
1220
+ r.map((l) => Ce(l, t))
1221
+ )).map((l) => l.payoutSignature);
1162
1222
  else {
1163
1223
  a = [];
1164
1224
  for (let u = 0; u < r.length; u++) {
1165
1225
  o == null || o(u, i);
1166
- const c = await n.signPayoutTransaction(
1167
- Te(r[u], t)
1226
+ const l = await n.signPayoutTransaction(
1227
+ Ce(r[u], t)
1168
1228
  );
1169
- a.push(c.signature);
1229
+ a.push(l.signature);
1170
1230
  }
1171
1231
  }
1172
1232
  const s = {};
@@ -1176,7 +1236,7 @@ async function Yr(e, t, r, o) {
1176
1236
  };
1177
1237
  return o == null || o(i, i), s;
1178
1238
  }
1179
- async function Uo(e) {
1239
+ async function Qo(e) {
1180
1240
  const {
1181
1241
  statusReader: t,
1182
1242
  presignClient: r,
@@ -1186,60 +1246,71 @@ async function Uo(e) {
1186
1246
  depositorPk: a,
1187
1247
  signingContext: s,
1188
1248
  depositTerms: u,
1189
- timeoutMs: c = Xr,
1190
- signal: l,
1249
+ timeoutMs: l = Zr,
1250
+ signal: c,
1191
1251
  onProgress: h,
1192
1252
  recordGraphFingerprint: p
1193
- } = e, d = await et({
1253
+ } = e, d = await st({
1194
1254
  statusReader: t,
1195
1255
  vaultId: n,
1196
1256
  peginTxid: i,
1197
- targetStatuses: qr,
1198
- timeoutMs: c,
1199
- signal: l
1257
+ targetStatuses: eo,
1258
+ timeoutMs: l,
1259
+ signal: c
1200
1260
  });
1201
- if (tt.has(d))
1261
+ if (at.has(d))
1202
1262
  return;
1203
- if (l == null || l.throwIfAborted(), u !== void 0 && zr(u, s), dt(o)) {
1263
+ c == null || c.throwIfAborted(), u !== void 0 && ro(u, s);
1264
+ const g = mt(o) ? o : void 0;
1265
+ let y;
1266
+ if (g) {
1204
1267
  if (!u)
1205
1268
  throw new Error(
1206
1269
  "runDepositorPresignFlow: this wallet requires approved deposit terms but none were provided. Fresh deposits must pass PreparePeginResult.depositTerms; resume flows must rebuild them from on-chain state (the vault app's rebuildDepositTerms)."
1207
1270
  );
1208
- typeof o.validateDepositTerms == "function" && await o.validateDepositTerms(u), await o.approveDepositTerms(u);
1271
+ y = u;
1209
1272
  }
1210
- const g = await r.requestDepositorPresignTransactions(
1273
+ const f = await r.requestDepositorPresignTransactions(
1211
1274
  {
1212
1275
  pegin_txid: i,
1213
1276
  depositor_pk: a
1214
1277
  },
1215
- l
1278
+ c
1216
1279
  );
1217
- l == null || l.throwIfAborted();
1218
- const b = Vr({
1280
+ c == null || c.throwIfAborted(), f.txs.forEach((V, F) => {
1281
+ Dr({
1282
+ claimTxHex: V.claim_tx.tx_hex,
1283
+ assertTxHex: V.assert_tx.tx_hex,
1284
+ path: `txs[${F}]`
1285
+ });
1286
+ });
1287
+ const P = Lr({
1219
1288
  peginTxid: i,
1220
1289
  peginTxHex: s.peginTxHex,
1221
- claimTxHex: g.depositor_graph.claim_tx.tx_hex,
1222
- assertTxHex: g.depositor_graph.assert_tx.tx_hex,
1223
- payoutTxHex: g.depositor_graph.payout_tx.tx_hex,
1224
- challengers: g.depositor_graph.challenger_presign_data
1225
- }), y = S(a);
1226
- Wr(
1227
- g.txs,
1290
+ claimTxHex: f.depositor_graph.claim_tx.tx_hex,
1291
+ assertTxHex: f.depositor_graph.assert_tx.tx_hex,
1292
+ payoutTxHex: f.depositor_graph.payout_tx.tx_hex,
1293
+ challengers: f.depositor_graph.challenger_presign_data
1294
+ }), x = I(a);
1295
+ oo(
1296
+ f.txs,
1228
1297
  s.vaultProviderBtcPubkey,
1229
1298
  s.vaultKeeperBtcPubkeys,
1230
1299
  a
1231
1300
  );
1232
- const m = g.txs.filter(
1233
- ($) => S($.claimer_pubkey) !== y
1234
- ), w = jr(m), x = await Yr(
1301
+ const w = f.txs.filter(
1302
+ (V) => I(V.claimer_pubkey) !== x
1303
+ ), _ = to(w);
1304
+ g && y && (typeof g.validateDepositTerms == "function" && await g.validateDepositTerms(y), await g.approveDepositTerms(y)), c == null || c.throwIfAborted();
1305
+ const k = await no(
1235
1306
  o,
1236
1307
  s,
1237
- w,
1308
+ _,
1238
1309
  h
1239
1310
  );
1240
- l == null || l.throwIfAborted();
1241
- const k = await Ur({
1242
- depositorGraph: g.depositor_graph,
1311
+ c == null || c.throwIfAborted();
1312
+ const T = await Qr({
1313
+ depositorGraph: f.depositor_graph,
1243
1314
  btcWallet: o,
1244
1315
  signingContext: {
1245
1316
  vaultCoreVersion: s.vaultCoreVersion,
@@ -1259,23 +1330,23 @@ async function Uo(e) {
1259
1330
  vpCommissionScriptPubKey: s.vpCommissionScriptPubKey
1260
1331
  }
1261
1332
  });
1262
- l == null || l.throwIfAborted(), await p(b), l == null || l.throwIfAborted();
1263
- const _ = { ...x };
1264
- _[f(a)] = k.payout_signatures, await r.submitDepositorPresignatures(
1333
+ c == null || c.throwIfAborted(), await p(P), c == null || c.throwIfAborted();
1334
+ const v = { ...k };
1335
+ v[b(a)] = T.payout_signatures, await r.submitDepositorPresignatures(
1265
1336
  {
1266
1337
  pegin_txid: i,
1267
1338
  depositor_pk: a,
1268
- signatures: _,
1269
- depositor_claimer_presignatures: k
1339
+ signatures: v,
1340
+ depositor_claimer_presignatures: T
1270
1341
  },
1271
- l
1342
+ c
1272
1343
  );
1273
1344
  }
1274
- const Qr = 300 * 1e3, Jr = /* @__PURE__ */ new Set([
1345
+ const so = 300 * 1e3, ao = /* @__PURE__ */ new Set([
1275
1346
  R.PENDING_DEPOSITOR_WOTS_PK,
1276
- ...Ge
1347
+ ...qe
1277
1348
  ]);
1278
- async function Go(e) {
1349
+ async function Jo(e) {
1279
1350
  const {
1280
1351
  statusReader: t,
1281
1352
  wotsSubmitter: r,
@@ -1283,19 +1354,19 @@ async function Go(e) {
1283
1354
  peginTxid: n,
1284
1355
  depositorPk: i,
1285
1356
  wotsPublicKeys: a,
1286
- timeoutMs: s = Qr,
1357
+ timeoutMs: s = so,
1287
1358
  signal: u
1288
1359
  } = e;
1289
1360
  u == null || u.throwIfAborted();
1290
- const c = await et({
1361
+ const l = await st({
1291
1362
  statusReader: t,
1292
1363
  vaultId: o,
1293
1364
  peginTxid: n,
1294
- targetStatuses: Jr,
1365
+ targetStatuses: ao,
1295
1366
  timeoutMs: s,
1296
1367
  signal: u
1297
1368
  });
1298
- Ge.has(c) || (u == null || u.throwIfAborted(), await r.submitDepositorWotsKey(
1369
+ qe.has(l) || (u == null || u.throwIfAborted(), await r.submitDepositorWotsKey(
1299
1370
  {
1300
1371
  pegin_txid: n,
1301
1372
  depositor_pk: i,
@@ -1304,30 +1375,30 @@ async function Go(e) {
1304
1375
  u
1305
1376
  ));
1306
1377
  }
1307
- function ee(e) {
1378
+ function ne(e) {
1308
1379
  return e.registration || e.operation;
1309
1380
  }
1310
- function Zr(e, t, r) {
1381
+ function io(e, t, r) {
1311
1382
  const o = C(e);
1312
1383
  return {
1313
1384
  registration: o === C(t),
1314
1385
  operation: o === C(r)
1315
1386
  };
1316
1387
  }
1317
- function $e(e, t, r) {
1318
- const o = te(e);
1388
+ function Ae(e, t, r) {
1389
+ const o = se(e);
1319
1390
  return {
1320
- registration: Ce(o, te(t)),
1321
- operation: Ce(o, te(r))
1391
+ registration: Se(o, se(t)),
1392
+ operation: Se(o, se(r))
1322
1393
  };
1323
1394
  }
1324
- function te(e) {
1395
+ function se(e) {
1325
1396
  return e.map(C).sort();
1326
1397
  }
1327
- function Ce(e, t) {
1398
+ function Se(e, t) {
1328
1399
  return e.length === t.length && e.every((r, o) => r === t[o]);
1329
1400
  }
1330
- async function Xo(e) {
1401
+ async function Zo(e) {
1331
1402
  const {
1332
1403
  vaultProviderEthAddress: t,
1333
1404
  hintBtcPubkey: r,
@@ -1346,11 +1417,11 @@ async function Xo(e) {
1346
1417
  `Vault provider BTC pubkey mismatch for ${t}: indexer hint matches neither the registration key nor the current operation key on-chain.${i ? ` ${i}` : ""}`
1347
1418
  );
1348
1419
  }
1349
- function re(e, t, r) {
1350
- const o = `${e} operation key (admin=${t.ethAddress})`, n = ye(
1420
+ function ae(e, t, r) {
1421
+ const o = `${e} operation key (admin=${t.ethAddress})`, n = me(
1351
1422
  t.btcPubKey,
1352
1423
  `${e} roster key (admin=${t.ethAddress})`
1353
- ), i = ye(r, o);
1424
+ ), i = me(r, o);
1354
1425
  return {
1355
1426
  adminAddress: t.ethAddress,
1356
1427
  genesisBtcPubkey: n,
@@ -1358,7 +1429,7 @@ function re(e, t, r) {
1358
1429
  rotated: i !== n
1359
1430
  };
1360
1431
  }
1361
- function eo(e) {
1432
+ function uo(e) {
1362
1433
  const t = /* @__PURE__ */ new Map();
1363
1434
  for (const r of e) {
1364
1435
  const o = t.get(r.operationBtcPubkey);
@@ -1369,12 +1440,12 @@ function eo(e) {
1369
1440
  t.set(r.operationBtcPubkey, r.adminAddress);
1370
1441
  }
1371
1442
  }
1372
- function rt(e, t, r) {
1443
+ function it(e, t, r) {
1373
1444
  if (t.vaultKeepers.length !== e.vaultKeepers.length || t.universalChallengers.length !== e.universalChallengers.length)
1374
1445
  throw new Error(
1375
1446
  `Operation-key resolution returned ${t.vaultKeepers.length} keeper and ${t.universalChallengers.length} challenger keys for a roster of ${e.vaultKeepers.length} keepers and ${e.universalChallengers.length} challengers`
1376
1447
  );
1377
- const o = re(
1448
+ const o = ae(
1378
1449
  "vault provider",
1379
1450
  {
1380
1451
  ethAddress: e.vaultProviderEthAddress,
@@ -1382,11 +1453,11 @@ function rt(e, t, r) {
1382
1453
  },
1383
1454
  t.vaultProvider
1384
1455
  ), n = e.vaultKeepers.map(
1385
- (a, s) => re("vault keeper", a, t.vaultKeepers[s])
1456
+ (a, s) => ae("vault keeper", a, t.vaultKeepers[s])
1386
1457
  ), i = e.universalChallengers.map(
1387
- (a, s) => re("universal challenger", a, t.universalChallengers[s])
1458
+ (a, s) => ae("universal challenger", a, t.universalChallengers[s])
1388
1459
  );
1389
- return eo([
1460
+ return uo([
1390
1461
  o,
1391
1462
  ...n,
1392
1463
  ...i
@@ -1401,33 +1472,33 @@ function rt(e, t, r) {
1401
1472
  query: e
1402
1473
  };
1403
1474
  }
1404
- async function to(e) {
1475
+ async function co(e) {
1405
1476
  const t = await e.operationKeyReader.getCurrentOperationKeys(
1406
1477
  e.query,
1407
1478
  e.blockNumber
1408
1479
  );
1409
- return rt(e.query, t, { mode: "current" });
1480
+ return it(e.query, t, { mode: "current" });
1410
1481
  }
1411
- async function ro(e) {
1482
+ async function lo(e) {
1412
1483
  const t = await e.operationKeyReader.getOperationKeysAtEpochs(
1413
1484
  e.query,
1414
1485
  e.epochs
1415
1486
  );
1416
- return rt(e.query, t, {
1487
+ return it(e.query, t, {
1417
1488
  mode: "epochs",
1418
1489
  epochs: e.epochs
1419
1490
  });
1420
1491
  }
1421
- class ne extends Error {
1492
+ class ue extends Error {
1422
1493
  constructor(t) {
1423
1494
  super(t), this.name = "ApplicationEntryPointMismatchError";
1424
1495
  }
1425
1496
  }
1426
- function qo(e) {
1427
- return e instanceof ne || e instanceof Error && e.name === "ApplicationEntryPointMismatchError";
1497
+ function en(e) {
1498
+ return e instanceof ue || e instanceof Error && e.name === "ApplicationEntryPointMismatchError";
1428
1499
  }
1429
- const Ae = (e) => e.map(C).sort();
1430
- async function jo(e) {
1500
+ const Ie = (e) => e.map(C).sort();
1501
+ async function tn(e) {
1431
1502
  const {
1432
1503
  vaultRegistryReader: t,
1433
1504
  vaultKeeperReader: r,
@@ -1437,15 +1508,15 @@ async function jo(e) {
1437
1508
  expectedVaultProviderBtcPubkey: a,
1438
1509
  expectedVaultKeeperBtcPubkeys: s,
1439
1510
  expectedUniversalChallengerBtcPubkeys: u,
1440
- operationKeyReader: c,
1441
- onIndexerServingOperationKeys: l,
1511
+ operationKeyReader: l,
1512
+ onIndexerServingOperationKeys: c,
1442
1513
  onIndexerHintsInconsistent: h,
1443
1514
  blockNumber: p
1444
1515
  } = e, [
1445
1516
  d,
1446
1517
  g,
1447
- b,
1448
- y
1518
+ y,
1519
+ f
1449
1520
  ] = await Promise.all([
1450
1521
  t.getVaultProviderApplication(
1451
1522
  n,
@@ -1458,15 +1529,15 @@ async function jo(e) {
1458
1529
  o.getLatestUniversalChallengersVersion(p),
1459
1530
  o.getCurrentUcKeyEpoch(p)
1460
1531
  ]);
1461
- if (!Ot(i, { strict: !1 }))
1462
- throw new ne(
1532
+ if (!Mt(i, { strict: !1 }))
1533
+ throw new ue(
1463
1534
  `The application entry point this deposit was prepared for is not a valid address: ${i}`
1464
1535
  );
1465
- if (!Nt(d, i))
1466
- throw new ne(
1536
+ if (!Ft(d, i))
1537
+ throw new ue(
1467
1538
  `Vault provider ${n} is registered to application ${d}, but this deposit was prepared for ${i}. Refusing to build: the vault keeper roster, its version, and the keeper key epoch would all resolve against a different application than the one selected.`
1468
1539
  );
1469
- const [m, w] = await Promise.all(
1540
+ const [P, x] = await Promise.all(
1470
1541
  [
1471
1542
  r.getCurrentVaultKeepersVersion(
1472
1543
  d,
@@ -1477,84 +1548,84 @@ async function jo(e) {
1477
1548
  p
1478
1549
  )
1479
1550
  ]
1480
- ), [x, k] = await Promise.all([
1551
+ ), [w, _] = await Promise.all([
1481
1552
  r.getVaultKeepersByVersion(
1482
1553
  d,
1483
- m,
1554
+ P,
1484
1555
  p
1485
1556
  ),
1486
1557
  o.getUniversalChallengersByVersion(
1487
- b,
1558
+ y,
1488
1559
  p
1489
1560
  )
1490
- ]), _ = {
1561
+ ]), k = {
1491
1562
  vaultProvider: C(g),
1492
- vaultKeepers: Ae(x.map((T) => T.btcPubKey)),
1493
- universalChallengers: Ae(k.map((T) => T.btcPubKey))
1494
- }, $ = await to({
1495
- operationKeyReader: c,
1563
+ vaultKeepers: Ie(w.map(($) => $.btcPubKey)),
1564
+ universalChallengers: Ie(_.map(($) => $.btcPubKey))
1565
+ }, T = await co({
1566
+ operationKeyReader: l,
1496
1567
  query: {
1497
1568
  vaultProviderEthAddress: n,
1498
1569
  vaultProviderGenesisBtcPubkey: `0x${g}`,
1499
1570
  applicationEntryPoint: d,
1500
- vaultKeepers: x,
1501
- universalChallengers: k
1571
+ vaultKeepers: w,
1572
+ universalChallengers: _
1502
1573
  },
1503
1574
  blockNumber: p
1504
1575
  }), v = {
1505
- vaultProvider: $.vaultProvider.operationBtcPubkey,
1506
- vaultKeepers: [...$.vaultKeeperOperationKeysSorted],
1576
+ vaultProvider: T.vaultProvider.operationBtcPubkey,
1577
+ vaultKeepers: [...T.vaultKeeperOperationKeysSorted],
1507
1578
  universalChallengers: [
1508
- ...$.universalChallengerOperationKeysSorted
1579
+ ...T.universalChallengerOperationKeysSorted
1509
1580
  ]
1510
- }, ae = Zr(
1581
+ }, V = io(
1511
1582
  a,
1512
- _.vaultProvider,
1583
+ k.vaultProvider,
1513
1584
  v.vaultProvider
1514
- ), ie = $e(
1585
+ ), F = Ae(
1515
1586
  s,
1516
- _.vaultKeepers,
1587
+ k.vaultKeepers,
1517
1588
  v.vaultKeepers
1518
- ), ue = $e(
1589
+ ), he = Ae(
1519
1590
  u,
1520
- _.universalChallengers,
1591
+ k.universalChallengers,
1521
1592
  v.universalChallengers
1522
1593
  );
1523
- if (!ee(ae))
1594
+ if (!ne(V))
1524
1595
  throw new Error(
1525
1596
  `Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${n}. Refresh and try again.`
1526
1597
  );
1527
- if (!ee(ie))
1598
+ if (!ne(F))
1528
1599
  throw new Error(
1529
- `Vault keeper BTC pubkeys (v${m}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
1600
+ `Vault keeper BTC pubkeys (v${P}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
1530
1601
  );
1531
- if (!ee(ue))
1602
+ if (!ne(he))
1532
1603
  throw new Error(
1533
- `Universal challenger BTC pubkeys (v${b}) indexer set does not match ProtocolParams on-chain set. Refresh and try again.`
1604
+ `Universal challenger BTC pubkeys (v${y}) indexer set does not match ProtocolParams on-chain set. Refresh and try again.`
1534
1605
  );
1535
- const ce = [ae, ie, ue], it = ce.some((T) => T.registration && !T.operation), le = ce.some((T) => T.operation && !T.registration);
1536
- if (it && le) {
1537
- const T = `Indexer participant hints are internally inconsistent for vault provider ${n}: some roles match the registration keys while others match the rotated operation keys.`;
1538
- throw h == null || h(T), new Error(`${T} Refresh and try again.`);
1606
+ const pe = [V, F, he], pt = pe.some(($) => $.registration && !$.operation), de = pe.some(($) => $.operation && !$.registration);
1607
+ if (pt && de) {
1608
+ const $ = `Indexer participant hints are internally inconsistent for vault provider ${n}: some roles match the registration keys while others match the rotated operation keys.`;
1609
+ throw h == null || h($), new Error(`${$} Refresh and try again.`);
1539
1610
  }
1540
- return le && (l == null || l(
1611
+ return de && (c == null || c(
1541
1612
  `Indexer is serving rotated operation keys for vault provider ${n}`
1542
1613
  )), {
1543
1614
  vaultProviderBtcPubkeyXOnly: v.vaultProvider,
1544
1615
  vaultKeeperBtcPubkeysSorted: v.vaultKeepers,
1545
1616
  universalChallengerBtcPubkeysSorted: v.universalChallengers,
1546
- expectedAppVaultKeepersVersion: m,
1547
- expectedUniversalChallengersVersion: b,
1548
- appKeeperKeyEpoch: w,
1549
- ucKeyEpoch: y,
1550
- registrationKeys: _,
1551
- participantKeys: $
1617
+ expectedAppVaultKeepersVersion: P,
1618
+ expectedUniversalChallengersVersion: y,
1619
+ appKeeperKeyEpoch: x,
1620
+ ucKeyEpoch: f,
1621
+ registrationKeys: k,
1622
+ participantKeys: T
1552
1623
  };
1553
1624
  }
1554
- function oo(e) {
1625
+ function ho(e) {
1555
1626
  return /^[0-9a-fA-F]{64}$/.test(e);
1556
1627
  }
1557
- function zo(e) {
1628
+ function rn(e) {
1558
1629
  const {
1559
1630
  amountSats: t,
1560
1631
  minDeposit: r,
@@ -1565,29 +1636,29 @@ function zo(e) {
1565
1636
  } = e;
1566
1637
  return !(t <= 0n || t < r || o && o > 0n && t > o || i == null || a == null || t + i + a > n);
1567
1638
  }
1568
- function Wo(e, t, r) {
1639
+ function on(e, t, r) {
1569
1640
  return e <= 0n ? {
1570
1641
  valid: !1,
1571
1642
  error: "Deposit amount must be greater than zero"
1572
1643
  } : e < t ? {
1573
1644
  valid: !1,
1574
- error: `Minimum deposit is ${V(t)} BTC`
1645
+ error: `Minimum deposit is ${H(t)} BTC`
1575
1646
  } : r && r > 0n && e > r ? {
1576
1647
  valid: !1,
1577
- error: `Maximum deposit is ${V(r)} BTC`
1648
+ error: `Maximum deposit is ${H(r)} BTC`
1578
1649
  } : { valid: !0 };
1579
1650
  }
1580
- function Yo(e) {
1651
+ function nn(e) {
1581
1652
  const { amount: t, effectiveRemaining: r } = e;
1582
1653
  return r === null ? { valid: !0 } : r === 0n ? {
1583
1654
  valid: !1,
1584
1655
  error: "Supply cap reached — deposits temporarily paused"
1585
1656
  } : t > r ? {
1586
1657
  valid: !1,
1587
- error: `Vault size exceeds remaining capacity (${V(r)} BTC)`
1658
+ error: `Vault size exceeds remaining capacity (${H(r)} BTC)`
1588
1659
  } : { valid: !0 };
1589
1660
  }
1590
- function Qo(e, t) {
1661
+ function sn(e, t) {
1591
1662
  if (!e || e.length === 0)
1592
1663
  return {
1593
1664
  valid: !1,
@@ -1603,7 +1674,7 @@ function Qo(e, t) {
1603
1674
  error: "Invalid vault provider selected"
1604
1675
  } : { valid: !0 };
1605
1676
  }
1606
- function no(e, t, r) {
1677
+ function po(e, t, r) {
1607
1678
  if (!e || e.length === 0)
1608
1679
  return {
1609
1680
  valid: !1,
@@ -1619,40 +1690,40 @@ function no(e, t, r) {
1619
1690
  if (t && n < t)
1620
1691
  return {
1621
1692
  valid: !1,
1622
- error: `Vault ${o + 1} amount ${V(n)} BTC is below minimum deposit ${V(t)} BTC`
1693
+ error: `Vault ${o + 1} amount ${H(n)} BTC is below minimum deposit ${H(t)} BTC`
1623
1694
  };
1624
1695
  if (r && n > r)
1625
1696
  return {
1626
1697
  valid: !1,
1627
- error: `Vault ${o + 1} amount ${V(n)} BTC exceeds maximum deposit ${V(r)} BTC`
1698
+ error: `Vault ${o + 1} amount ${H(n)} BTC exceeds maximum deposit ${H(r)} BTC`
1628
1699
  };
1629
1700
  }
1630
1701
  return { valid: !0 };
1631
1702
  }
1632
- function so(e) {
1633
- const t = f(e);
1634
- return oo(t) ? { valid: !0 } : {
1703
+ function go(e) {
1704
+ const t = b(e);
1705
+ return ho(t) ? { valid: !0 } : {
1635
1706
  valid: !1,
1636
1707
  error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
1637
1708
  };
1638
1709
  }
1639
- function ao(e) {
1710
+ function fo(e) {
1640
1711
  if (!e || e.length === 0)
1641
1712
  throw new Error(
1642
1713
  "No vault keepers available. The system requires at least one vault keeper to create a deposit."
1643
1714
  );
1644
1715
  }
1645
- function io(e) {
1716
+ function yo(e) {
1646
1717
  if (!e || e.length === 0)
1647
1718
  throw new Error(
1648
1719
  "No universal challengers available. The system requires at least one universal challenger to create a deposit."
1649
1720
  );
1650
1721
  }
1651
- function uo(e) {
1722
+ function bo(e) {
1652
1723
  if (e.length === 0)
1653
1724
  throw new Error("No spendable UTXOs available");
1654
1725
  }
1655
- function Jo(e) {
1726
+ function an(e) {
1656
1727
  const {
1657
1728
  vaultAmounts: t,
1658
1729
  confirmedUTXOs: r,
@@ -1661,78 +1732,78 @@ function Jo(e) {
1661
1732
  universalChallengerBtcPubkeys: i,
1662
1733
  minDeposit: a,
1663
1734
  maxDeposit: s
1664
- } = e, u = no(
1735
+ } = e, u = po(
1665
1736
  t,
1666
1737
  a,
1667
1738
  s
1668
1739
  );
1669
1740
  if (!u.valid)
1670
1741
  throw new Error(u.error);
1671
- const c = so(o);
1672
- if (!c.valid)
1673
- throw new Error(c.error);
1674
- ao(n), io(i), uo(r);
1742
+ const l = go(o);
1743
+ if (!l.valid)
1744
+ throw new Error(l.error);
1745
+ fo(n), yo(i), bo(r);
1675
1746
  }
1676
- class ot extends Error {
1747
+ class ut extends Error {
1677
1748
  constructor(t) {
1678
1749
  super(t), this.name = "ParticipantKeyDriftError";
1679
1750
  }
1680
1751
  }
1681
- function Zo(e) {
1682
- return e instanceof ot || e instanceof Error && e.name === "ParticipantKeyDriftError";
1752
+ function un(e) {
1753
+ return e instanceof ut || e instanceof Error && e.name === "ParticipantKeyDriftError";
1683
1754
  }
1684
- function Se(e, t, r) {
1755
+ function Re(e, t, r) {
1685
1756
  return t.length === r.length && t.every((o, n) => o === r[n]) ? null : `${e} expected [${t.join(", ")}], got [${r.join(", ")}]`;
1686
1757
  }
1687
- async function en(e) {
1758
+ async function cn(e) {
1688
1759
  const { vaultRegistryReader: t, operationKeyReader: r, vaultIds: o, expected: n } = e, i = n.query;
1689
1760
  if (o.length === 0) return;
1690
1761
  const a = await t.getVaultKeyEpochsBatch(o), s = [];
1691
- for (const [u, c] of a.entries()) {
1692
- const l = o[u];
1762
+ for (const [u, l] of a.entries()) {
1763
+ const c = o[u];
1693
1764
  let h;
1694
1765
  try {
1695
- h = await ro({
1766
+ h = await lo({
1696
1767
  operationKeyReader: r,
1697
1768
  query: i,
1698
- epochs: c
1769
+ epochs: l
1699
1770
  });
1700
1771
  } catch (g) {
1701
1772
  s.push(
1702
- `vault ${l}: could not resolve participants at frozen epochs (vp=${c.vpKeyEpoch}, keeper=${c.appKeeperKeyEpoch}, uc=${c.ucKeyEpoch}): ${g.message}`
1773
+ `vault ${c}: could not resolve participants at frozen epochs (vp=${l.vpKeyEpoch}, keeper=${l.appKeeperKeyEpoch}, uc=${l.ucKeyEpoch}): ${g.message}`
1703
1774
  );
1704
1775
  continue;
1705
1776
  }
1706
1777
  h.vaultProvider.operationBtcPubkey !== n.vaultProvider.operationBtcPubkey && s.push(
1707
- `vault ${l}: vault provider key expected ${n.vaultProvider.operationBtcPubkey}, got ${h.vaultProvider.operationBtcPubkey}`
1778
+ `vault ${c}: vault provider key expected ${n.vaultProvider.operationBtcPubkey}, got ${h.vaultProvider.operationBtcPubkey}`
1708
1779
  );
1709
- const p = Se(
1710
- `vault ${l}: vault keeper keys`,
1780
+ const p = Re(
1781
+ `vault ${c}: vault keeper keys`,
1711
1782
  n.vaultKeeperOperationKeysSorted,
1712
1783
  h.vaultKeeperOperationKeysSorted
1713
1784
  );
1714
1785
  p && s.push(p);
1715
- const d = Se(
1716
- `vault ${l}: universal challenger keys`,
1786
+ const d = Re(
1787
+ `vault ${c}: universal challenger keys`,
1717
1788
  n.universalChallengerOperationKeysSorted,
1718
1789
  h.universalChallengerOperationKeysSorted
1719
1790
  );
1720
1791
  d && s.push(d);
1721
1792
  }
1722
1793
  if (s.length > 0)
1723
- throw new ot(
1794
+ throw new ut(
1724
1795
  `Aborting BTC broadcast: participant operation keys changed during registration (${s.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
1725
1796
  );
1726
1797
  }
1727
- class nt extends Error {
1798
+ class ct extends Error {
1728
1799
  constructor(t) {
1729
1800
  super(t), this.name = "RegisteredVaultVersionMismatchError";
1730
1801
  }
1731
1802
  }
1732
- function tn(e) {
1733
- return e instanceof nt || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
1803
+ function ln(e) {
1804
+ return e instanceof ct || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
1734
1805
  }
1735
- async function rn(e) {
1806
+ async function hn(e) {
1736
1807
  const {
1737
1808
  vaultRegistryReader: t,
1738
1809
  vaultIds: r,
@@ -1741,55 +1812,55 @@ async function rn(e) {
1741
1812
  expectedUniversalChallengersVersion: i,
1742
1813
  expectedVaultCoreVersion: a
1743
1814
  } = e, s = await t.getProtocolInfoBatch(r), u = [];
1744
- if (s.forEach((c, l) => {
1745
- const h = r[l];
1746
- c.offchainParamsVersion !== o && u.push(
1747
- `vault ${h}: offchainParams expected v${o}, got v${c.offchainParamsVersion}`
1748
- ), c.appVaultKeepersVersion !== n && u.push(
1749
- `vault ${h}: appVaultKeepers expected v${n}, got v${c.appVaultKeepersVersion}`
1750
- ), c.universalChallengersVersion !== i && u.push(
1751
- `vault ${h}: universalChallengers expected v${i}, got v${c.universalChallengersVersion}`
1752
- ), c.vaultCoreVersion !== a && u.push(
1753
- `vault ${h}: vaultCoreVersion expected v${a} (build-time active), got v${c.vaultCoreVersion}`
1815
+ if (s.forEach((l, c) => {
1816
+ const h = r[c];
1817
+ l.offchainParamsVersion !== o && u.push(
1818
+ `vault ${h}: offchainParams expected v${o}, got v${l.offchainParamsVersion}`
1819
+ ), l.appVaultKeepersVersion !== n && u.push(
1820
+ `vault ${h}: appVaultKeepers expected v${n}, got v${l.appVaultKeepersVersion}`
1821
+ ), l.universalChallengersVersion !== i && u.push(
1822
+ `vault ${h}: universalChallengers expected v${i}, got v${l.universalChallengersVersion}`
1823
+ ), l.vaultCoreVersion !== a && u.push(
1824
+ `vault ${h}: vaultCoreVersion expected v${a} (build-time active), got v${l.vaultCoreVersion}`
1754
1825
  );
1755
1826
  }), u.length > 0)
1756
- throw new nt(
1827
+ throw new ct(
1757
1828
  `Aborting BTC broadcast: signer-set or offchain-params versions changed during registration (${u.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
1758
1829
  );
1759
1830
  }
1760
- class co extends Error {
1831
+ class mo extends Error {
1761
1832
  constructor(r, o) {
1762
1833
  super(`Refund not yet mature (BIP68 not final): ${o.message}`);
1763
- N(this, "vaultId");
1764
- N(this, "cause");
1834
+ K(this, "vaultId");
1835
+ K(this, "cause");
1765
1836
  this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = o;
1766
1837
  }
1767
1838
  }
1768
- const lo = /^0x[0-9a-fA-F]{64}$/, ho = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, st = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, at = 160, Ie = 2e3, Re = 10n, Be = 100n;
1769
- function on(e) {
1839
+ const vo = /^0x[0-9a-fA-F]{64}$/, Po = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, lt = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, ht = 160, Be = 2e3, Ve = 10n, He = 100n;
1840
+ function pn(e) {
1770
1841
  if (!Number.isFinite(e) || e <= 0)
1771
1842
  throw new Error(
1772
1843
  `feeRateSatsVb must be a positive finite number, got ${e}`
1773
1844
  );
1774
- return BigInt(Math.ceil(e * at));
1845
+ return BigInt(Math.ceil(e * ht));
1775
1846
  }
1776
- const po = 1, go = /non-BIP68-final/i;
1777
- function se(e, t) {
1847
+ const xo = 1, wo = /non-BIP68-final/i;
1848
+ function ce(e, t) {
1778
1849
  if (e.length !== 66)
1779
1850
  throw new Error(
1780
1851
  `${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
1781
1852
  );
1782
- if (!lo.test(e))
1853
+ if (!vo.test(e))
1783
1854
  throw new Error(
1784
1855
  `${t} must contain only hex characters after the 0x prefix`
1785
1856
  );
1786
1857
  }
1787
- function oe(e, t) {
1858
+ function ie(e, t) {
1788
1859
  if (!Number.isInteger(e) || e < 0)
1789
1860
  throw new Error(`${t} must be a non-negative integer, got ${e}`);
1790
1861
  }
1791
- function fo(e) {
1792
- if (se(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0)
1862
+ function Eo(e) {
1863
+ if (ce(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0)
1793
1864
  throw new Error(
1794
1865
  `htlcVout must be a non-negative integer, got ${e.htlcVout}`
1795
1866
  );
@@ -1801,7 +1872,7 @@ function fo(e) {
1801
1872
  );
1802
1873
  for (let r = 0; r < e.batch.length; r++) {
1803
1874
  const o = e.batch[r];
1804
- if (se(o.hashlock, `batch[${r}].hashlock`), !Number.isInteger(o.htlcVout) || o.htlcVout !== r)
1875
+ if (ce(o.hashlock, `batch[${r}].hashlock`), !Number.isInteger(o.htlcVout) || o.htlcVout !== r)
1805
1876
  throw new Error(
1806
1877
  `batch[${r}].htlcVout must equal ${r} (contiguous vout-ordered vector), got ${o.htlcVout}`
1807
1878
  );
@@ -1819,27 +1890,27 @@ function fo(e) {
1819
1890
  throw new Error(
1820
1891
  `batch[${e.htlcVout}].amount (${t.amount}) does not match target amount (${e.amount})`
1821
1892
  );
1822
- if (oe(e.offchainParamsVersion, "offchainParamsVersion"), oe(e.appVaultKeepersVersion, "appVaultKeepersVersion"), oe(
1893
+ if (ie(e.offchainParamsVersion, "offchainParamsVersion"), ie(e.appVaultKeepersVersion, "appVaultKeepersVersion"), ie(
1823
1894
  e.universalChallengersVersion,
1824
1895
  "universalChallengersVersion"
1825
- ), zt(
1896
+ ), Zt(
1826
1897
  e.vaultCoreVersion,
1827
1898
  "VaultRefundData.vaultCoreVersion"
1828
1899
  ), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
1829
1900
  throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
1830
- if (!ho.test(e.unsignedPrePeginTxHex))
1901
+ if (!Po.test(e.unsignedPrePeginTxHex))
1831
1902
  throw new Error(
1832
1903
  "unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
1833
1904
  );
1834
- if (!e.depositorBtcPubkey || !st.test(e.depositorBtcPubkey))
1905
+ if (!e.depositorBtcPubkey || !lt.test(e.depositorBtcPubkey))
1835
1906
  throw new Error(
1836
1907
  "depositorBtcPubkey must be 32 or 33 bytes of hex (optional 0x prefix)"
1837
1908
  );
1838
1909
  if (typeof e.amount != "bigint" || e.amount <= 0n)
1839
1910
  throw new Error(`amount must be a positive bigint, got ${e.amount}`);
1840
1911
  }
1841
- function yo(e) {
1842
- if (!e.vaultProviderPubkey || !st.test(e.vaultProviderPubkey))
1912
+ function _o(e) {
1913
+ if (!e.vaultProviderPubkey || !lt.test(e.vaultProviderPubkey))
1843
1914
  throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
1844
1915
  if (e.vaultKeeperPubkeys.length === 0)
1845
1916
  throw new Error("vaultKeeperPubkeys must be non-empty");
@@ -1864,7 +1935,7 @@ function yo(e) {
1864
1935
  `councilQuorum (${e.councilQuorum}) must be in [1, councilSize=${e.councilSize}]`
1865
1936
  );
1866
1937
  }
1867
- async function nn(e) {
1938
+ async function dn(e) {
1868
1939
  const {
1869
1940
  vaultId: t,
1870
1941
  readVault: r,
@@ -1874,51 +1945,51 @@ async function nn(e) {
1874
1945
  broadcastTx: a,
1875
1946
  signal: s
1876
1947
  } = e;
1877
- s == null || s.throwIfAborted(), se(t, "vaultId");
1948
+ s == null || s.throwIfAborted(), ce(t, "vaultId");
1878
1949
  const u = await r();
1879
- fo(u), s == null || s.throwIfAborted();
1880
- const c = await o(u);
1881
- if (yo(c), s == null || s.throwIfAborted(), !Number.isFinite(n) || n <= 0)
1950
+ Eo(u), s == null || s.throwIfAborted();
1951
+ const l = await o(u);
1952
+ if (_o(l), s == null || s.throwIfAborted(), !Number.isFinite(n) || n <= 0)
1882
1953
  throw new Error(`feeRate must be a positive number, got ${n}`);
1883
- if (n > Ie)
1954
+ if (n > Be)
1884
1955
  throw new Error(
1885
- `feeRate ${n} sat/vB exceeds refund safety cap ${Ie} sat/vB; refusing to sign refund.`
1956
+ `feeRate ${n} sat/vB exceeds refund safety cap ${Be} sat/vB; refusing to sign refund.`
1886
1957
  );
1887
- const l = BigInt(Math.ceil(n * at)), h = u.amount * Re / Be;
1888
- if (l > h)
1958
+ const c = BigInt(Math.ceil(n * ht)), h = u.amount * Ve / He;
1959
+ if (c > h)
1889
1960
  throw new Error(
1890
- `Refund fee ${l} sats exceeds the per-vault safety cap of ${h} sats (${Re}/${Be} of vault.amount=${u.amount}); refusing to sign refund.`
1961
+ `Refund fee ${c} sats exceeds the per-vault safety cap of ${h} sats (${Ve}/${He} of vault.amount=${u.amount}); refusing to sign refund.`
1891
1962
  );
1892
1963
  s == null || s.throwIfAborted();
1893
- const p = j(
1964
+ const p = Q(
1894
1965
  u.depositorBtcPubkey
1895
- ), d = f(u.unsignedPrePeginTxHex), g = ft(d);
1966
+ ), d = b(u.unsignedPrePeginTxHex), g = Pt(d);
1896
1967
  if (g !== void 0 && g.vout !== u.batch.length)
1897
1968
  throw new Error(
1898
1969
  `Auth-anchor OP_RETURN at vout ${g.vout} does not match batch size (${u.batch.length} HTLC outputs expect the anchor at vout ${u.batch.length}). Refund refused — sibling HTLC vector is incomplete.`
1899
1970
  );
1900
- const b = g == null ? void 0 : g.hash;
1901
- let y;
1971
+ const y = g == null ? void 0 : g.hash;
1972
+ let f;
1902
1973
  try {
1903
- y = B.fromHex(d);
1974
+ f = B.fromHex(d);
1904
1975
  } catch (v) {
1905
1976
  throw new Error(
1906
1977
  `Failed to parse funded Pre-PegIn transaction hex: ${v instanceof Error ? v.message : String(v)}`
1907
1978
  );
1908
1979
  }
1909
- if (y.outs.length < u.batch.length)
1980
+ if (f.outs.length < u.batch.length)
1910
1981
  throw new Error(
1911
- `Funded Pre-PegIn tx has ${y.outs.length} outputs but batch requires at least ${u.batch.length} HTLC outputs. Refund refused — funded tx shape disagrees with sibling vector.`
1982
+ `Funded Pre-PegIn tx has ${f.outs.length} outputs but batch requires at least ${u.batch.length} HTLC outputs. Refund refused — funded tx shape disagrees with sibling vector.`
1912
1983
  );
1913
- const { psbtHex: m } = await Xt({
1984
+ const { psbtHex: P } = await Yt({
1914
1985
  prePeginParams: {
1915
1986
  vaultCoreVersion: u.vaultCoreVersion,
1916
1987
  depositorPubkey: p,
1917
- vaultProviderPubkey: f(c.vaultProviderPubkey),
1918
- vaultKeeperPubkeys: c.vaultKeeperPubkeys.map(f),
1919
- universalChallengerPubkeys: c.universalChallengerPubkeys.map(f),
1920
- hashlocks: u.batch.map((v) => f(v.hashlock)),
1921
- timelockRefund: c.timelockRefund,
1988
+ vaultProviderPubkey: b(l.vaultProviderPubkey),
1989
+ vaultKeeperPubkeys: l.vaultKeeperPubkeys.map(b),
1990
+ universalChallengerPubkeys: l.universalChallengerPubkeys.map(b),
1991
+ hashlocks: u.batch.map((v) => b(v.hashlock)),
1992
+ timelockRefund: l.timelockRefund,
1922
1993
  // `batch[i].amount` is the on-chain vault deposit (peg-in) amount, which
1923
1994
  // is exactly what WASM's `pegInAmounts` expects — it re-adds the protocol
1924
1995
  // reserve (`depositorClaimValue + minPeginFee`) internally when sizing the
@@ -1926,72 +1997,72 @@ async function nn(e) {
1926
1997
  // to the funded tx bytes, refusing the refund if the template's HTLC value
1927
1998
  // disagrees with the on-chain commitment.
1928
1999
  pegInAmounts: u.batch.map((v) => v.amount),
1929
- feeRate: c.feeRate,
1930
- minPeginFeeRate: c.minPeginFeeRate,
1931
- numLocalChallengers: c.numLocalChallengers,
1932
- councilQuorum: c.councilQuorum,
1933
- councilSize: c.councilSize,
1934
- network: c.network,
1935
- authAnchorHash: b
2000
+ feeRate: l.feeRate,
2001
+ minPeginFeeRate: l.minPeginFeeRate,
2002
+ numLocalChallengers: l.numLocalChallengers,
2003
+ councilQuorum: l.councilQuorum,
2004
+ councilSize: l.councilSize,
2005
+ network: l.network,
2006
+ authAnchorHash: y
1936
2007
  },
1937
2008
  fundedPrePeginTxHex: d,
1938
2009
  htlcVout: u.htlcVout,
1939
- refundFee: l,
2010
+ refundFee: c,
1940
2011
  // buildRefundPsbt's top-level `hashlock` param is documented as "no 0x
1941
2012
  // prefix" and flows into the WASM HTLC connector derivation; a prefixed
1942
2013
  // value would derive the wrong refund script leaf and yield an
1943
2014
  // unspendable PSBT. Match the `hashlocks` array handling above.
1944
- hashlock: f(u.hashlock)
2015
+ hashlock: b(u.hashlock)
1945
2016
  });
1946
2017
  s == null || s.throwIfAborted();
1947
- const w = F(
2018
+ const x = U(
1948
2019
  u.depositorBtcPubkey,
1949
- po
1950
- ), x = await i(m, w);
1951
- L({
1952
- requestedPsbtHex: m,
1953
- returnedPsbtHex: x
2020
+ xo
2021
+ ), w = await i(P, x);
2022
+ X({
2023
+ requestedPsbtHex: P,
2024
+ returnedPsbtHex: w
1954
2025
  });
1955
- const k = 0, _ = U(
1956
- x,
2026
+ const _ = 0, k = q(
2027
+ w,
1957
2028
  p,
1958
- k
2029
+ _
1959
2030
  );
1960
- G({
1961
- requestedPsbtHex: m,
1962
- signatureHex: _,
2031
+ j({
2032
+ requestedPsbtHex: P,
2033
+ signatureHex: k,
1963
2034
  signerXOnlyPubkeyHex: p,
1964
- inputIndex: k
2035
+ inputIndex: _
1965
2036
  });
1966
- const $ = Xe({
1967
- requestedPsbtHex: m,
1968
- signaturesHex: [_],
2037
+ const T = je({
2038
+ requestedPsbtHex: P,
2039
+ signaturesHex: [k],
1969
2040
  signerXOnlyPubkeyHex: p
1970
2041
  });
1971
2042
  s == null || s.throwIfAborted();
1972
2043
  try {
1973
- return await a($);
2044
+ return await a(T);
1974
2045
  } catch (v) {
1975
- throw v instanceof Error && go.test(v.message) ? new co(t, v) : v;
2046
+ throw v instanceof Error && wo.test(v.message) ? new mo(t, v) : v;
1976
2047
  }
1977
2048
  }
1978
- class Ve extends Error {
2049
+ class Oe extends Error {
1979
2050
  constructor(r, o, n) {
1980
2051
  super(r);
1981
2052
  /** Fee the reclaim would have paid, in satoshis. */
1982
- N(this, "feeSats");
2053
+ K(this, "feeSats");
1983
2054
  /** Sum of the reserves the reclaim would have swept, in satoshis. */
1984
- N(this, "sweptTotalSats");
2055
+ K(this, "sweptTotalSats");
1985
2056
  this.name = "ReclaimUneconomicalError", this.feeSats = o, this.sweptTotalSats = n;
1986
2057
  }
1987
2058
  }
1988
- const Oe = 2e3, Ne = 25n, He = 100n, sn = 10n;
1989
- async function bo(e, t, r) {
2059
+ const Ne = 2e3, Ke = 25n, De = 100n, gn = 10n;
2060
+ async function ko(e, t, r) {
1990
2061
  for (let o = 0; o < e.length; o++) {
1991
- const n = bt(e[o].depositorSignedPeginTxHex), i = De(
1992
- await St(
1993
- f(n),
1994
- f(r)
2062
+ const n = wt(e[o].depositorSignedPeginTxHex), i = Fe(
2063
+ await Ht(
2064
+ b(n),
2065
+ b(r)
1995
2066
  )
1996
2067
  ).toLowerCase();
1997
2068
  if (i !== t[o].toLowerCase())
@@ -2000,7 +2071,7 @@ async function bo(e, t, r) {
2000
2071
  );
2001
2072
  }
2002
2073
  }
2003
- async function an(e) {
2074
+ async function fn(e) {
2004
2075
  const {
2005
2076
  vaultIds: t,
2006
2077
  depositorEthAddress: r,
@@ -2015,125 +2086,125 @@ async function an(e) {
2015
2086
  throw new Error("Reclaim requires at least one vault id; got none.");
2016
2087
  if (!Number.isFinite(i) || i <= 0)
2017
2088
  throw new Error(`feeRate must be a positive number, got ${i}`);
2018
- if (i > Oe)
2019
- throw new Ve(
2020
- `Fee rate ${i} sat/vB exceeds the reclaim safety cap of ${Oe} sat/vB; refusing to sign.`,
2089
+ if (i > Ne)
2090
+ throw new Oe(
2091
+ `Fee rate ${i} sat/vB exceeds the reclaim safety cap of ${Ne} sat/vB; refusing to sign.`,
2021
2092
  0n,
2022
2093
  0n
2023
2094
  );
2024
- const c = await n();
2025
- if (u == null || u.throwIfAborted(), c.length !== t.length)
2095
+ const l = await n();
2096
+ if (u == null || u.throwIfAborted(), l.length !== t.length)
2026
2097
  throw new Error(
2027
- `readVaults returned ${c.length} reserves for ${t.length} vault id(s); refusing to sweep a set that does not match the request.`
2028
- );
2029
- await bo(c, t, r), u == null || u.throwIfAborted();
2030
- const l = j(o), h = c.map((k) => ({
2031
- depositorSignedPeginTxHex: k.depositorSignedPeginTxHex,
2032
- observed: k.observed,
2033
- expectedValue: k.expectedClaimValue
2034
- })), p = qt(i, h.length), d = h.reduce((k, _) => k + _.expectedValue, 0n), g = d * Ne / He;
2098
+ `readVaults returned ${l.length} reserves for ${t.length} vault id(s); refusing to sweep a set that does not match the request.`
2099
+ );
2100
+ await ko(l, t, r), u == null || u.throwIfAborted();
2101
+ const c = Q(o), h = l.map((_) => ({
2102
+ depositorSignedPeginTxHex: _.depositorSignedPeginTxHex,
2103
+ observed: _.observed,
2104
+ expectedValue: _.expectedClaimValue
2105
+ })), p = Qt(i, h.length), d = h.reduce((_, k) => _ + k.expectedValue, 0n), g = d * Ke / De;
2035
2106
  if (p > g)
2036
- throw new Ve(
2037
- `Reclaim fee ${p} sats exceeds ${Ne}/${He} of the swept total (${d} sats, cap ${g} sats). The reserve is not at risk — it stays where it is until fee rates fall.`,
2107
+ throw new Oe(
2108
+ `Reclaim fee ${p} sats exceeds ${Ke}/${De} of the swept total (${d} sats, cap ${g} sats). The reserve is not at risk — it stays where it is until fee rates fall.`,
2038
2109
  p,
2039
2110
  d
2040
2111
  );
2041
2112
  u == null || u.throwIfAborted();
2042
- const { psbtHex: b } = jt({
2043
- depositorPubkey: l,
2113
+ const { psbtHex: y } = Jt({
2114
+ depositorPubkey: c,
2044
2115
  inputs: h,
2045
2116
  feeSats: p
2046
2117
  });
2047
2118
  u == null || u.throwIfAborted();
2048
- const y = F(
2119
+ const f = U(
2049
2120
  o,
2050
2121
  h.length
2051
- ), m = await a(b, y);
2052
- L({
2053
- requestedPsbtHex: b,
2054
- returnedPsbtHex: m
2122
+ ), P = await a(y, f);
2123
+ X({
2124
+ requestedPsbtHex: y,
2125
+ returnedPsbtHex: P
2055
2126
  });
2056
- const w = h.map((k, _) => {
2057
- const $ = U(
2058
- m,
2059
- l,
2060
- _
2061
- );
2062
- return G({
2063
- requestedPsbtHex: b,
2064
- signatureHex: $,
2065
- signerXOnlyPubkeyHex: l,
2066
- inputIndex: _
2067
- }), $;
2068
- }), x = Xe({
2069
- requestedPsbtHex: b,
2070
- signaturesHex: w,
2071
- signerXOnlyPubkeyHex: l
2127
+ const x = h.map((_, k) => {
2128
+ const T = q(
2129
+ P,
2130
+ c,
2131
+ k
2132
+ );
2133
+ return j({
2134
+ requestedPsbtHex: y,
2135
+ signatureHex: T,
2136
+ signerXOnlyPubkeyHex: c,
2137
+ inputIndex: k
2138
+ }), T;
2139
+ }), w = je({
2140
+ requestedPsbtHex: y,
2141
+ signaturesHex: x,
2142
+ signerXOnlyPubkeyHex: c
2072
2143
  });
2073
- return u == null || u.throwIfAborted(), s(x);
2144
+ return u == null || u.throwIfAborted(), s(w);
2074
2145
  }
2075
2146
  export {
2076
- Re as $,
2077
- vr as A,
2078
- Qo as B,
2079
- er as C,
2080
- mr as D,
2081
- Yo as E,
2082
- no as F,
2083
- P as G,
2084
- so as H,
2085
- ot as I,
2086
- Zo as J,
2087
- en as K,
2088
- tn as L,
2089
- rn as M,
2090
- et as N,
2091
- Xo as O,
2092
- rr as P,
2093
- ee as Q,
2094
- nt as R,
2095
- Zr as S,
2096
- $e as T,
2097
- to as U,
2098
- sr as V,
2099
- ro as W,
2100
- co as X,
2101
- nn as Y,
2102
- on as Z,
2103
- Be as _,
2104
- Oo as a,
2105
- Ie as a0,
2106
- at as a1,
2107
- Ve as a2,
2108
- an as a3,
2109
- He as a4,
2110
- Ne as a5,
2111
- Oe as a6,
2112
- sn as a7,
2113
- No as b,
2114
- Ho as c,
2115
- Ko as d,
2116
- Do as e,
2117
- tr as f,
2118
- or as g,
2119
- We as h,
2120
- Er as i,
2121
- Qe as j,
2122
- Je as k,
2123
- $r as l,
2124
- Mo as m,
2125
- Lo as n,
2126
- Or as o,
2127
- Ur as p,
2128
- Go as q,
2129
- Uo as r,
2130
- Pr as s,
2131
- ne as t,
2132
- qo as u,
2133
- jo as v,
2134
- Fo as w,
2135
- zo as x,
2136
- Wo as y,
2137
- Jo as z
2147
+ Ve as $,
2148
+ _r as A,
2149
+ sn as B,
2150
+ sr as C,
2151
+ Er as D,
2152
+ nn as E,
2153
+ po as F,
2154
+ m as G,
2155
+ go as H,
2156
+ ut as I,
2157
+ un as J,
2158
+ cn as K,
2159
+ ln as L,
2160
+ hn as M,
2161
+ st as N,
2162
+ Zo as O,
2163
+ ir as P,
2164
+ ne as Q,
2165
+ ct as R,
2166
+ io as S,
2167
+ Ae as T,
2168
+ co as U,
2169
+ lr as V,
2170
+ lo as W,
2171
+ mo as X,
2172
+ dn as Y,
2173
+ pn as Z,
2174
+ He as _,
2175
+ Uo as a,
2176
+ Be as a0,
2177
+ ht as a1,
2178
+ Oe as a2,
2179
+ fn as a3,
2180
+ De as a4,
2181
+ Ke as a5,
2182
+ Ne as a6,
2183
+ gn as a7,
2184
+ Go as b,
2185
+ Xo as c,
2186
+ qo as d,
2187
+ jo as e,
2188
+ ar as f,
2189
+ ur as g,
2190
+ Qe as h,
2191
+ Cr as i,
2192
+ Ze as j,
2193
+ et as k,
2194
+ Rr as l,
2195
+ zo as m,
2196
+ Yo as n,
2197
+ Ur as o,
2198
+ Qr as p,
2199
+ Jo as q,
2200
+ Qo as r,
2201
+ kr as s,
2202
+ ue as t,
2203
+ en as u,
2204
+ tn as v,
2205
+ Wo as w,
2206
+ rn as x,
2207
+ on as y,
2208
+ an as z
2138
2209
  };
2139
- //# sourceMappingURL=buildAndBroadcastReclaim-C55KaRJF.js.map
2210
+ //# sourceMappingURL=buildAndBroadcastReclaim-D5520lbL.js.map