@babylonlabs-io/ts-sdk 5.1.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/dist/{buildAndBroadcastReclaim-Acz637Vf.js → buildAndBroadcastReclaim-Bs_zdDGN.js} +793 -772
  2. package/dist/{buildAndBroadcastReclaim-Acz637Vf.js.map → buildAndBroadcastReclaim-Bs_zdDGN.js.map} +1 -1
  3. package/dist/{buildAndBroadcastReclaim-Cf05JFP-.cjs → buildAndBroadcastReclaim-CXOMHHgK.cjs} +2 -2
  4. package/dist/{buildAndBroadcastReclaim-Cf05JFP-.cjs.map → buildAndBroadcastReclaim-CXOMHHgK.cjs.map} +1 -1
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.js +95 -94
  7. package/dist/tbv/core/index.cjs +1 -1
  8. package/dist/tbv/core/index.js +77 -76
  9. package/dist/tbv/core/recovery/reconstructPeginParams.d.ts +6 -0
  10. package/dist/tbv/core/recovery/reconstructPeginParams.d.ts.map +1 -1
  11. package/dist/tbv/core/recovery/toRefundInputs.d.ts +0 -2
  12. package/dist/tbv/core/recovery/toRefundInputs.d.ts.map +1 -1
  13. package/dist/tbv/core/services/index.cjs +1 -1
  14. package/dist/tbv/core/services/index.js +73 -72
  15. package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts +6 -2
  16. package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts.map +1 -1
  17. package/dist/tbv/core/services/refund/errors.d.ts +15 -0
  18. package/dist/tbv/core/services/refund/errors.d.ts.map +1 -1
  19. package/dist/tbv/core/services/refund/index.d.ts +1 -1
  20. package/dist/tbv/core/services/refund/index.d.ts.map +1 -1
  21. package/dist/tbv/index.cjs +1 -1
  22. package/dist/tbv/index.js +77 -76
  23. package/dist/{toRefundInputs-DwXpKQxN.js → toRefundInputs-Cl4KgzIc.js} +149 -149
  24. package/dist/{toRefundInputs-DwXpKQxN.js.map → toRefundInputs-Cl4KgzIc.js.map} +1 -1
  25. package/dist/{toRefundInputs-BzyN0zvj.cjs → toRefundInputs-DyIgmGJq.cjs} +2 -2
  26. package/dist/{toRefundInputs-BzyN0zvj.cjs.map → toRefundInputs-DyIgmGJq.cjs.map} +1 -1
  27. package/package.json +1 -1
@@ -1,58 +1,58 @@
1
- var tr = Object.defineProperty;
2
- var rr = (e, t, r) => t in e ? tr(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var W = (e, t, r) => rr(e, typeof t != "symbol" ? t + "" : t, r);
1
+ var rr = Object.defineProperty;
2
+ var or = (e, t, r) => t in e ? rr(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var B = (e, t, r) => or(e, typeof t != "symbol" ? t + "" : t, r);
4
4
  import { B as Be } from "./BTCVaultRegistry.abi-DnP4UkB5.js";
5
- import { e as Ie, s as P, i as or, u as yt, c as _, v as sr, g as nr, p as he, f as N } from "./bitcoin-C-TuHb-v.js";
6
- import { v as ir, s as vt, b as Pt, P as ar, d as ur } from "./PayoutManager-BHeiLQ1j.js";
7
- import { verifyWatchtowerArtifacts as cr, buildClaimPsbt as lr, buildAssertClaimerPsbt as pr, buildPayoutClaimerPsbt as dr, buildWronglyChallengedPsbts as hr, buildPayoutDepositorPsbt as gr, finalizeClaimTx as fr, buildWatchtowerArtifacts as yr, extractTapScriptSig as mt, expandWotsSeed as vr, wotsKeypairFromSeed as Pr, validateWotsKeypairAgainstGraph as mr, getChallengeAssertOutputScriptPubKey as br, deriveVaultId as wr } from "./tbv/core/wasm/index.js";
8
- import { m as xr, d as bt, k as Er, a as _e, V as Le, i as kr, g as $r, f as Cr, r as Tr, h as _r } from "./registration-records-D39ApuHS.js";
9
- import { Psbt as q, Transaction as S } from "bitcoinjs-lib";
10
- import { F as U, G as A, H as re, I as J, A as G, z as Z, J as ge, v as Me, E as ee, K as Ve, w as Ue, x as Fe, y as qe, W as Sr, D as Ge, C as Xe, L as Ar, O as Br, Q as Ir } from "./constants-CmDDuM3L.js";
11
- import { p as Vr, q as Rr, r as wt, P as X, j as oe, f as Kr, i as ae, g as ue, s as Hr } from "./verifyScriptPathSchnorrSignature-DLNGgm4j.js";
12
- import { Buffer as H } from "buffer";
13
- import { C as xt, X as Et } from "./validation-OSC0xTHB.js";
5
+ import { e as Ie, s as P, i as sr, u as vt, c as _, v as nr, g as ir, p as he, f as D } from "./bitcoin-C-TuHb-v.js";
6
+ import { v as ar, s as Pt, b as mt, P as ur, d as cr } from "./PayoutManager-BHeiLQ1j.js";
7
+ import { verifyWatchtowerArtifacts as lr, buildClaimPsbt as dr, buildAssertClaimerPsbt as pr, buildPayoutClaimerPsbt as hr, buildWronglyChallengedPsbts as gr, buildPayoutDepositorPsbt as fr, finalizeClaimTx as yr, buildWatchtowerArtifacts as vr, extractTapScriptSig as bt, expandWotsSeed as Pr, wotsKeypairFromSeed as mr, validateWotsKeypairAgainstGraph as br, getChallengeAssertOutputScriptPubKey as wr, deriveVaultId as xr } from "./tbv/core/wasm/index.js";
8
+ import { m as Er, d as wt, k as $r, a as _e, V as Le, i as kr, g as Cr, f as Tr, r as _r, h as Sr } from "./registration-records-D39ApuHS.js";
9
+ import { Psbt as G, Transaction as S } from "bitcoinjs-lib";
10
+ import { F, G as A, H as re, I as J, A as X, z as Z, J as ge, v as Me, E as ee, K as Ve, w as Ue, x as Fe, y as qe, W as Ar, D as Ge, C as Xe, L as Br, O as Ir, Q as Vr } from "./constants-CmDDuM3L.js";
11
+ import { p as Rr, q as Kr, r as xt, P as z, j as oe, f as Hr, i as ae, g as ue, s as Or } from "./verifyScriptPathSchnorrSignature-DLNGgm4j.js";
12
+ import { Buffer as O } from "buffer";
13
+ import { C as Et, X as $t } from "./validation-OSC0xTHB.js";
14
14
  import { a as kt, c as ce } from "./signing-C1rR4tqs.js";
15
- import { d as $t } from "./deriveVaultRoot-BcvmER1E.js";
16
- import { O as ze, d as Or } from "./types-K_aM5GZO.js";
17
- import { zeroAddress as Nr, isAddress as Dr, isAddressEqual as Lr } from "viem";
18
- import { v as je, D as R, c as Mr, b as Ur, R as Fr, d as Ct } from "./state-CFn1rT74.js";
19
- import { h as We, b as qr, s as Gr, j as Xr } from "./sha2-YqVHJiFj.js";
20
- import { c as zr, g as jr, h as Wr, i as Yr, b as Qr, f as Tt, e as Jr, a as Zr } from "./challengeAssert-D_lRvsO0.js";
21
- import { a as eo } from "./secp256k1-BuxBFUHm.js";
22
- import { c as to } from "./btcTxHash-BRZ8_EZq.js";
23
- const ro = /^0x[0-9a-fA-F]{64}$/, oo = /^0x[0-9a-fA-F]{40}$/, so = /^0x([0-9a-fA-F]{2})*$/;
15
+ import { d as Ct } from "./deriveVaultRoot-BcvmER1E.js";
16
+ import { O as ze, d as Nr } from "./types-K_aM5GZO.js";
17
+ import { zeroAddress as Dr, isAddress as Lr, isAddressEqual as Mr } from "viem";
18
+ import { v as je, D as K, c as Ur, b as Fr, R as qr, d as Tt } from "./state-CFn1rT74.js";
19
+ import { h as We, b as Gr, s as Xr, j as zr } from "./sha2-YqVHJiFj.js";
20
+ import { c as jr, g as Wr, h as Yr, i as Qr, b as Jr, f as _t, e as Zr, a as eo } from "./challengeAssert-D_lRvsO0.js";
21
+ import { a as to } from "./secp256k1-BuxBFUHm.js";
22
+ import { c as ro } from "./btcTxHash-BRZ8_EZq.js";
23
+ const oo = /^0x[0-9a-fA-F]{64}$/, so = /^0x[0-9a-fA-F]{40}$/, no = /^0x([0-9a-fA-F]{2})*$/;
24
24
  function ye(e, t) {
25
25
  if (e.length !== 66)
26
26
  throw new Error(
27
27
  `${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
28
28
  );
29
- if (!ro.test(e))
29
+ if (!oo.test(e))
30
30
  throw new Error(
31
31
  `${t} must contain only hex characters after the 0x prefix`
32
32
  );
33
33
  }
34
- function no(e, t) {
35
- if (!oo.test(e))
34
+ function io(e, t) {
35
+ if (!so.test(e))
36
36
  throw new Error(
37
37
  `${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
38
38
  );
39
39
  }
40
- function io(e, t) {
41
- if (!so.test(e))
40
+ function ao(e, t) {
41
+ if (!no.test(e))
42
42
  throw new Error(
43
43
  `${t} must be a 0x-prefixed hex string with an even number of hex chars`
44
44
  );
45
45
  }
46
46
  function Re(e) {
47
- no(e.btcVaultRegistryAddress, "btcVaultRegistryAddress"), ye(e.vaultId, "vaultId");
47
+ io(e.btcVaultRegistryAddress, "btcVaultRegistryAddress"), ye(e.vaultId, "vaultId");
48
48
  const t = Ie(e.secret);
49
- if (ye(t, "secret"), e.hashlock !== void 0 && (ye(e.hashlock, "hashlock"), !ir(t, e.hashlock)))
49
+ if (ye(t, "secret"), e.hashlock !== void 0 && (ye(e.hashlock, "hashlock"), !ar(t, e.hashlock)))
50
50
  throw new Error(
51
51
  "Invalid secret: SHA256(secret) does not match the provided hashlock"
52
52
  );
53
53
  return t;
54
54
  }
55
- async function cn(e) {
55
+ async function pn(e) {
56
56
  const {
57
57
  btcVaultRegistryAddress: t,
58
58
  vaultId: r,
@@ -68,14 +68,14 @@ async function cn(e) {
68
68
  secret: e.secret,
69
69
  hashlock: o
70
70
  });
71
- return io(s, "activationMetadata"), n({
71
+ return ao(s, "activationMetadata"), n({
72
72
  address: t,
73
73
  abi: Be,
74
74
  functionName: "activateVaultWithSecret",
75
75
  args: [r, i, s]
76
76
  });
77
77
  }
78
- async function ln(e) {
78
+ async function hn(e) {
79
79
  const { btcVaultRegistryAddress: t, vaultId: r, hashlock: o, writeContract: s, signal: n } = e;
80
80
  n == null || n.throwIfAborted();
81
81
  const a = Re({
@@ -91,7 +91,7 @@ async function ln(e) {
91
91
  args: [r, a]
92
92
  });
93
93
  }
94
- async function pn(e) {
94
+ async function gn(e) {
95
95
  const { btcVaultRegistryAddress: t, vaultId: r, hashlock: o, writeContract: s, signal: n } = e;
96
96
  if (n == null || n.throwIfAborted(), typeof o != "string")
97
97
  throw new Error("hashlock is required to claim an expired vault");
@@ -108,22 +108,22 @@ async function pn(e) {
108
108
  args: [r, a]
109
109
  });
110
110
  }
111
- class K extends Error {
111
+ class H extends Error {
112
112
  constructor(t, r) {
113
113
  super(t, r), this.name = "AssertBindingError";
114
114
  }
115
115
  }
116
116
  function ve(e, t) {
117
117
  try {
118
- return q.fromBase64(t);
118
+ return G.fromBase64(t);
119
119
  } catch (r) {
120
- throw new K(`${e} PSBT cannot be parsed.`, { cause: r });
120
+ throw new H(`${e} PSBT cannot be parsed.`, { cause: r });
121
121
  }
122
122
  }
123
- function ao(e, t, r) {
123
+ function uo(e, t, r) {
124
124
  const o = t.txInputs[r];
125
125
  if (!o)
126
- throw new K(`${e} PSBT has no input ${r}.`);
126
+ throw new H(`${e} PSBT has no input ${r}.`);
127
127
  return o.hash;
128
128
  }
129
129
  function Ye(e) {
@@ -134,61 +134,61 @@ function Ye(e) {
134
134
  function Pe(e, t, r, o, s, n) {
135
135
  const a = t.txInputs[r];
136
136
  if (!a)
137
- throw new K(`${e} PSBT has no input ${r}.`);
137
+ throw new H(`${e} PSBT has no input ${r}.`);
138
138
  if (!a.hash.equals(o) || a.index !== s)
139
- throw new K(
139
+ throw new H(
140
140
  `${e} input ${r} does not spend ${n}: the graph pairs this ${e} with a different transaction.`
141
141
  );
142
142
  }
143
- function uo(e, t) {
143
+ function co(e, t) {
144
144
  var s;
145
- const r = (s = e.data.inputs[U]) == null ? void 0 : s.witnessUtxo;
145
+ const r = (s = e.data.inputs[F]) == null ? void 0 : s.witnessUtxo;
146
146
  if (r === void 0)
147
- throw new K(
148
- `Assert input ${U} carries no witnessUtxo, so the amount and script its signature commits to cannot be checked; refusing to sign assert.`
147
+ throw new H(
148
+ `Assert input ${F} carries no witnessUtxo, so the amount and script its signature commits to cannot be checked; refusing to sign assert.`
149
149
  );
150
150
  const o = t.txOutputs[J];
151
151
  if (!o)
152
- throw new K(
152
+ throw new H(
153
153
  `Claim PSBT has no output ${J} for the Assert to spend; refusing to sign assert.`
154
154
  );
155
155
  if (r.value !== o.value)
156
- throw new K(
157
- `Assert input ${U} declares a prevout of ${r.value} sats but the Claim's output ${J} is worth ${o.value}; refusing to sign assert.`
156
+ throw new H(
157
+ `Assert input ${F} declares a prevout of ${r.value} sats but the Claim's output ${J} is worth ${o.value}; refusing to sign assert.`
158
158
  );
159
159
  if (!r.script.equals(o.script))
160
- throw new K(
161
- `Assert input ${U} declares a prevout script that is not the Claim's output ${J} script; refusing to sign assert.`
160
+ throw new H(
161
+ `Assert input ${F} declares a prevout script that is not the Claim's output ${J} script; refusing to sign assert.`
162
162
  );
163
163
  }
164
- function co(e) {
164
+ function lo(e) {
165
165
  const t = ve("Claim", e.claimPsbtBase64), r = ve("Assert", e.assertPsbtBase64), o = ve("Payout", e.payoutClaimerPsbtBase64);
166
166
  Pe(
167
167
  "Assert",
168
168
  r,
169
- U,
169
+ F,
170
170
  Ye(t),
171
171
  J,
172
172
  "Claim:0"
173
- ), uo(r, t), Pe(
173
+ ), co(r, t), Pe(
174
174
  "Payout",
175
175
  o,
176
176
  A,
177
177
  Ye(r),
178
- G,
178
+ X,
179
179
  "Assert:0"
180
180
  ), Pe(
181
181
  "Payout",
182
182
  o,
183
183
  re,
184
- ao("Claim", t, ge),
184
+ uo("Claim", t, ge),
185
185
  Z,
186
186
  "this vault's PegIn:0"
187
187
  );
188
188
  }
189
189
  function me(e, t) {
190
190
  try {
191
- return q.fromBase64(t);
191
+ return G.fromBase64(t);
192
192
  } catch (r) {
193
193
  throw new Error(`${e} PSBT cannot be parsed.`, { cause: r });
194
194
  }
@@ -204,7 +204,7 @@ function Qe(e, t, r, o) {
204
204
  {
205
205
  inputIndex: A,
206
206
  expectedSats: o.value,
207
- source: `the Assert's output ${G}`
207
+ source: `the Assert's output ${X}`
208
208
  }
209
209
  ];
210
210
  for (const { inputIndex: i, expectedSats: u, source: l } of s) {
@@ -221,10 +221,10 @@ function Qe(e, t, r, o) {
221
221
  const n = t.data.inputs[A].witnessUtxo;
222
222
  if (!(n != null && n.script.equals(o.script)))
223
223
  throw new Error(
224
- `${e} Payout input ${A} declares a prevout script that is not the Assert's output ${G} script; refusing to sign payout.`
224
+ `${e} Payout input ${A} declares a prevout script that is not the Assert's output ${X} script; refusing to sign payout.`
225
225
  );
226
226
  }
227
- async function lo(e) {
227
+ async function po(e) {
228
228
  const { vault: t } = e, r = {
229
229
  vaultCoreVersion: t.vaultCoreVersion,
230
230
  numVaultKeepers: t.vaultKeeperBtcPubkeys.length,
@@ -232,7 +232,7 @@ async function lo(e) {
232
232
  councilSize: t.councilSize,
233
233
  protocolFeeRate: t.protocolFeeRate
234
234
  };
235
- Vr(r);
235
+ Rr(r);
236
236
  const o = me("Claimer Payout", e.payoutClaimerPsbtBase64), s = me(
237
237
  "Depositor Payout",
238
238
  e.payoutDepositorPsbtBase64
@@ -241,10 +241,10 @@ async function lo(e) {
241
241
  throw new Error(
242
242
  "Depositor and claimer Payout PSBTs describe different transactions; refusing to sign payout."
243
243
  );
244
- const a = n.txOutputs[G];
244
+ const a = n.txOutputs[X];
245
245
  if (a === void 0)
246
246
  throw new Error(
247
- `Assert transaction has no output ${G}; the Payout's implicit fee cannot be measured.`
247
+ `Assert transaction has no output ${X}; the Payout's implicit fee cannot be measured.`
248
248
  );
249
249
  if (o.txInputs.length !== Me)
250
250
  throw new Error(
@@ -276,27 +276,27 @@ async function lo(e) {
276
276
  throw new Error(
277
277
  `Payout transaction has ${c.length} output(s), expected exactly ${ee} for a depositor-as-claimer payout.`
278
278
  );
279
- let d = 0;
280
- for (const p of c) d += p.value;
281
- if (d > l)
279
+ let p = 0;
280
+ for (const d of c) p += d.value;
281
+ if (p > l)
282
282
  throw new Error(
283
- `Payout outputs (${d} sats) exceed inputs (${l} sats); invalid transaction.`
283
+ `Payout outputs (${p} sats) exceed inputs (${l} sats); invalid transaction.`
284
284
  );
285
- await Rr(r, {
286
- implicitFeeSats: l - d,
285
+ await Kr(r, {
286
+ implicitFeeSats: l - p,
287
287
  out0Len: c[Ve].script.length,
288
288
  out1Len: void 0
289
289
  });
290
290
  }
291
- class po extends Error {
291
+ class ho extends Error {
292
292
  constructor(t, r) {
293
293
  super(
294
294
  "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."
295
295
  ), this.missing = t, this.unexpected = r, this.name = "ChallengerSetMismatchError";
296
296
  }
297
297
  }
298
- function ho(e) {
299
- const t = wt({
298
+ function go(e) {
299
+ const t = xt({
300
300
  claimerBtcPubkey: e.depositorBtcPubkey,
301
301
  depositorBtcPubkey: e.depositorBtcPubkey,
302
302
  vaultProviderBtcPubkey: e.vaultProviderBtcPubkey,
@@ -313,26 +313,26 @@ function ho(e) {
313
313
  );
314
314
  const a = [...t, ...r], i = new Set(a), u = a.filter((c) => !n.has(c)), l = s.filter((c) => !i.has(c));
315
315
  if (u.length > 0 || l.length > 0)
316
- throw new po(u, l);
316
+ throw new ho(u, l);
317
317
  }
318
318
  function Je(e) {
319
319
  return P(e).toLowerCase();
320
320
  }
321
- class go extends Error {
321
+ class fo extends Error {
322
322
  constructor(t, r) {
323
323
  super(
324
324
  `Payout transaction output ${Ve} pays ${r}, not the vault's registered payout script ${t}. Refusing to sign a payout to another destination.`
325
325
  ), this.expectedScriptHex = t, this.actualScriptHex = r, this.name = "PayoutDestinationError";
326
326
  }
327
327
  }
328
- function fo(e) {
328
+ function yo(e) {
329
329
  let t;
330
330
  try {
331
- t = q.fromBase64(e.payoutPsbtBase64);
331
+ t = G.fromBase64(e.payoutPsbtBase64);
332
332
  } catch (c) {
333
333
  throw new Error("Payout PSBT cannot be parsed.", { cause: c });
334
334
  }
335
- const { version: r, locktime: o, outs: s } = yo(t);
335
+ const { version: r, locktime: o, outs: s } = vo(t);
336
336
  if (r !== Ue || o !== Fe)
337
337
  throw new Error(
338
338
  `Payout transaction has version ${r} and locktime ${o}, expected ${Ue} and ${Fe}.`
@@ -350,26 +350,26 @@ function fo(e) {
350
350
  );
351
351
  const a = s[Ve].script.toString("hex").toLowerCase();
352
352
  if (a !== n)
353
- throw new go(n, a);
353
+ throw new fo(n, a);
354
354
  const i = s[ee - 1];
355
355
  if (i.value !== qe)
356
356
  throw new Error(
357
357
  `Payout CPFP anchor value ${i.value} sats must equal ${qe} sats.`
358
358
  );
359
359
  const u = P(
360
- xr(P(e.depositorBtcPubkey).toLowerCase())
360
+ Er(P(e.depositorBtcPubkey).toLowerCase())
361
361
  ), l = i.script.toString("hex").toLowerCase();
362
362
  if (l !== u)
363
363
  throw new Error(
364
364
  `Payout CPFP anchor pays ${l}, not the depositor's BIP-86 P2TR ${u}. Refusing to sign a payout whose fee-bump output is spendable by somebody else.`
365
365
  );
366
366
  }
367
- function yo(e) {
367
+ function vo(e) {
368
368
  return {
369
369
  version: e.version,
370
370
  locktime: e.locktime,
371
371
  outs: e.txOutputs.map((t) => ({
372
- script: H.from(t.script),
372
+ script: O.from(t.script),
373
373
  value: t.value
374
374
  }))
375
375
  };
@@ -379,8 +379,8 @@ class ne extends Error {
379
379
  super(t), this.name = "PayoutInputLeafError";
380
380
  }
381
381
  }
382
- function vo(e) {
383
- const t = q.fromBase64(e.payoutDepositorPsbtBase64), r = q.fromBase64(e.payoutClaimerPsbtBase64), o = t.data.globalMap.unsignedTx.toBuffer(), s = r.data.globalMap.unsignedTx.toBuffer();
382
+ function Po(e) {
383
+ const t = G.fromBase64(e.payoutDepositorPsbtBase64), r = G.fromBase64(e.payoutClaimerPsbtBase64), o = t.data.globalMap.unsignedTx.toBuffer(), s = r.data.globalMap.unsignedTx.toBuffer();
384
384
  if (!o.equals(s))
385
385
  throw new ne(
386
386
  "Depositor and claimer Payout PSBTs describe different transactions; the graph is inconsistent."
@@ -404,59 +404,59 @@ function vo(e) {
404
404
  ...n.tapMerkleRoot ? { tapMerkleRoot: n.tapMerkleRoot } : {}
405
405
  }), t.toBase64();
406
406
  }
407
- class Po extends Error {
407
+ class mo extends Error {
408
408
  constructor(t, r, o) {
409
409
  super(
410
410
  `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.`
411
411
  ), this.expectedVaultId = t, this.derivedVaultId = r, this.peginTxid = o, this.name = "VaultIdBindingError";
412
412
  }
413
413
  }
414
- function mo(e) {
414
+ function bo(e) {
415
415
  let t;
416
416
  try {
417
- t = q.fromBase64(e);
417
+ t = G.fromBase64(e);
418
418
  } catch (o) {
419
419
  throw new Error("Claim PSBT cannot be parsed.", { cause: o });
420
420
  }
421
421
  const r = t.txInputs[ge];
422
422
  if (!r)
423
423
  throw new Error("Claim PSBT carries no PegIn input to bind the vault to.");
424
- return _t(
424
+ return St(
425
425
  "Claim PSBT",
426
426
  t.txInputs.length,
427
427
  r.index
428
428
  ), Ke(r.hash);
429
429
  }
430
- function bo(e) {
430
+ function wo(e) {
431
431
  const t = e.ins[ge];
432
432
  if (!t)
433
433
  throw new Error(
434
434
  "Artifacts file's claim_tx carries no PegIn input to bind the vault to."
435
435
  );
436
- return _t(
436
+ return St(
437
437
  "Artifacts file's claim_tx",
438
438
  e.ins.length,
439
439
  t.index
440
440
  ), Ke(t.hash);
441
441
  }
442
- function _t(e, t, r) {
443
- if (t !== 1 || r !== X)
442
+ function St(e, t, r) {
443
+ if (t !== 1 || r !== z)
444
444
  throw new Error(
445
- `${e} must have exactly one input spending PegIn output ${X}; it has ${t} input(s) and the first spends output ${r}.`
445
+ `${e} must have exactly one input spending PegIn output ${z}; it has ${t} input(s) and the first spends output ${r}.`
446
446
  );
447
447
  }
448
- function St(e) {
449
- const t = z(
450
- bt(e.peginTxid, e.depositorEthAddress)
451
- ), r = z(e.expectedVaultId);
448
+ function At(e) {
449
+ const t = j(
450
+ wt(e.peginTxid, e.depositorEthAddress)
451
+ ), r = j(e.expectedVaultId);
452
452
  if (t !== r)
453
- throw new Po(r, t, e.peginTxid);
453
+ throw new mo(r, t, e.peginTxid);
454
454
  }
455
- function z(e) {
455
+ function j(e) {
456
456
  return `0x${(e.startsWith("0x") ? e.slice(2) : e).toLowerCase()}`;
457
457
  }
458
458
  function Ke(e) {
459
- return H.from(e).reverse().toString("hex");
459
+ return O.from(e).reverse().toString("hex");
460
460
  }
461
461
  function le(e, t) {
462
462
  const r = P(e);
@@ -464,7 +464,7 @@ function le(e, t) {
464
464
  throw new Error(`${t} must be non-empty, even-length hex.`);
465
465
  return r.toLowerCase();
466
466
  }
467
- function At(e) {
467
+ function Bt(e) {
468
468
  const t = le(
469
469
  e.servedVerifyingKeyHex,
470
470
  "source.verifyingKeyHex"
@@ -477,22 +477,22 @@ function At(e) {
477
477
  `Vault provider served Groth16 verifying key ${t} but the trusted key for prover circuit version ${e.proverCircuitVersion} is ${r}; refusing to sign a claim whose proof would verify under a substituted key.`
478
478
  );
479
479
  }
480
- const F = 1;
481
- class wo extends Error {
480
+ const q = 1;
481
+ class xo extends Error {
482
482
  constructor(t, r) {
483
483
  super(
484
484
  `Artifacts belong to vault ${r}, not ${t}. Select the artifacts file saved for this vault.`
485
485
  ), this.expectedVaultId = t, this.actualVaultId = r, this.name = "ArtifactsVaultMismatchError";
486
486
  }
487
487
  }
488
- const xo = /^(?:[0-9a-fA-F]{2})+$/;
489
- function Eo(e) {
490
- const t = Co(e, "babe_sessions"), r = Object.keys(t);
488
+ const Eo = /^(?:[0-9a-fA-F]{2})+$/;
489
+ function $o(e) {
490
+ const t = To(e, "babe_sessions"), r = Object.keys(t);
491
491
  if (r.length === 0)
492
492
  return { joined: !1 };
493
493
  for (const [o, s] of Object.entries(t)) {
494
494
  const n = typeof s == "object" && s !== null ? s.decryptor_artifacts_hex : void 0;
495
- if (typeof n != "string" || !xo.test(n))
495
+ if (typeof n != "string" || !Eo.test(n))
496
496
  throw new Error(
497
497
  `Artifacts file is missing a usable "babe_sessions": the entry for ${o} carries no non-empty hex "decryptor_artifacts_hex".`
498
498
  );
@@ -506,7 +506,7 @@ function ko(e) {
506
506
  } catch (a) {
507
507
  throw new Error("Artifacts file is not valid JSON.", { cause: a });
508
508
  }
509
- const r = be(t.vault_id, "vault_id"), o = $o(be(t.claim_tx, "claim_tx")), s = we(
509
+ const r = be(t.vault_id, "vault_id"), o = Co(be(t.claim_tx, "claim_tx")), s = we(
510
510
  t.prover_circuit_version,
511
511
  "prover_circuit_version"
512
512
  ), n = BigInt(
@@ -522,26 +522,26 @@ function ko(e) {
522
522
  ),
523
523
  vaultId: r,
524
524
  claimTxid: o.getId(),
525
- peginTxid: bo(o),
525
+ peginTxid: wo(o),
526
526
  proverCircuitVersion: s,
527
527
  claimableEventBlockNumber: n,
528
528
  // Required: btc-vault's builder always writes it
529
529
  // (`delegated_claim.rs:874` @ b534ff9e), so an absent one is not a file
530
530
  // this SDK or the CLI produced.
531
531
  verifyingKeyHex: be(t.verifying_key, "verifying_key"),
532
- babeSessions: Eo(t.babe_sessions)
532
+ babeSessions: $o(t.babe_sessions)
533
533
  };
534
534
  }
535
- async function dn(e) {
536
- const t = ko(e.artifactsJson), r = z(e.expectedVaultId), o = z(t.vaultId);
535
+ async function fn(e) {
536
+ const t = ko(e.artifactsJson), r = j(e.expectedVaultId), o = j(t.vaultId);
537
537
  if (r !== o)
538
- throw new wo(r, o);
539
- St({
538
+ throw new xo(r, o);
539
+ At({
540
540
  peginTxid: t.peginTxid,
541
541
  depositorEthAddress: e.depositorEthAddress,
542
542
  expectedVaultId: r
543
543
  });
544
- const s = e.txGraphVersion ?? F;
544
+ const s = e.txGraphVersion ?? q;
545
545
  if (t.vaultCoreVersion !== s)
546
546
  throw new Error(
547
547
  `Artifacts record vault core version ${t.vaultCoreVersion}, but verification was asked for version ${s}.`
@@ -569,9 +569,9 @@ async function dn(e) {
569
569
  throw new Error(
570
570
  `Artifacts carry Groth16 verifying key ${n} but the trusted key for prover circuit version ${e.expectedProverCircuitVersion} is ${a}; refusing a file whose proof would verify under a substituted key.`
571
571
  );
572
- return await cr(s, e.artifactsJson), t;
572
+ return await lr(s, e.artifactsJson), t;
573
573
  }
574
- function $o(e) {
574
+ function Co(e) {
575
575
  try {
576
576
  return S.fromHex(e);
577
577
  } catch (t) {
@@ -590,15 +590,15 @@ function we(e, t) {
590
590
  throw new Error(`Artifacts file is missing a usable "${t}".`);
591
591
  return e;
592
592
  }
593
- function Co(e, t) {
593
+ function To(e, t) {
594
594
  if (typeof e != "object" || e === null || Array.isArray(e))
595
595
  throw new Error(`Artifacts file is missing a usable "${t}".`);
596
596
  return e;
597
597
  }
598
- function Bt(e, t) {
598
+ function It(e, t) {
599
599
  return `wronglyChallenged:${e}:${t}`;
600
600
  }
601
- function It(e) {
601
+ function Vt(e) {
602
602
  const t = [
603
603
  {
604
604
  id: "claim",
@@ -610,7 +610,7 @@ function It(e) {
610
610
  id: "assert",
611
611
  kind: "assert",
612
612
  psbtBase64: e.assert,
613
- inputIndex: U
613
+ inputIndex: F
614
614
  },
615
615
  {
616
616
  id: "payoutClaimer",
@@ -628,95 +628,95 @@ function It(e) {
628
628
  for (const r of Object.keys(e.wronglyChallenged))
629
629
  e.wronglyChallenged[r].forEach((o, s) => {
630
630
  t.push({
631
- id: Bt(r, s),
631
+ id: It(r, s),
632
632
  kind: "wronglyChallenged",
633
633
  psbtBase64: o,
634
- inputIndex: Sr
634
+ inputIndex: Ar
635
635
  });
636
636
  });
637
637
  return t;
638
638
  }
639
- const To = "{}", _o = xt - Et;
640
- function V(e) {
639
+ const _o = "{}", So = Et - $t;
640
+ function R(e) {
641
641
  const t = e.replace(/^0x/, "").toLowerCase();
642
- if (t.length === xt)
643
- return t.slice(_o);
644
- if (t.length === Et) return t;
642
+ if (t.length === Et)
643
+ return t.slice(So);
644
+ if (t.length === $t) return t;
645
645
  throw new Error(
646
646
  `Public key must be 33-byte compressed or 32-byte x-only hex, got ${t.length / 2} bytes.`
647
647
  );
648
648
  }
649
649
  async function Ze(e, t, r) {
650
650
  const o = await e.getPublicKeyHex();
651
- if (V(o) !== V(t))
651
+ if (R(o) !== R(t))
652
652
  throw new Error(
653
653
  "Connected wallet does not hold the vault's depositor key. Select the account that made the deposit, then try again."
654
654
  );
655
655
  const s = await e.getAddress();
656
- if (!or(s, o, r))
656
+ if (!sr(s, o, r))
657
657
  throw new Error(
658
658
  `Connected wallet reports address "${s}", which is not derived from the vault's depositor key. Select the account that made the deposit, then try again.`
659
659
  );
660
660
  return s;
661
661
  }
662
- async function Vt(e, t, r, o) {
663
- const s = V(o);
662
+ async function Rt(e, t, r, o) {
663
+ const s = R(o);
664
664
  if (s !== r.depositorBtcPubkey)
665
665
  throw new Error(
666
666
  `Depositor key ${s} is not the vault's registered depositor key ${r.depositorBtcPubkey}; refusing to plan a claim for another key.`
667
667
  );
668
668
  try {
669
- Er(
669
+ $r(
670
670
  Ie(r.registeredPayoutScriptPubKey),
671
671
  r.depositorBtcPubkey,
672
672
  o
673
673
  );
674
- } catch (d) {
674
+ } catch (p) {
675
675
  throw new Error(
676
- `Registered payout script ${r.registeredPayoutScriptPubKey} failed the depositor-key derivation check: ${d instanceof Error ? d.message : String(d)}. This SDK registers only P2TR of the depositor's x-only key or P2WPKH of the compressed key (the contract bounds the script's length alone, PeginLogic.sol:237-240 @ c559f5c2); refusing to sign a claim that pays it.`,
677
- { cause: d }
676
+ `Registered payout script ${r.registeredPayoutScriptPubKey} failed the depositor-key derivation check: ${p instanceof Error ? p.message : String(p)}. This SDK registers only P2TR of the depositor's x-only key or P2WPKH of the compressed key (the contract bounds the script's length alone, PeginLogic.sol:237-240 @ c559f5c2); refusing to sign a claim that pays it.`,
677
+ { cause: p }
678
678
  );
679
679
  }
680
- if (e !== F)
680
+ if (e !== q)
681
681
  throw new Error(
682
- `Graph version ${e} is not the delegated-claim graph version ${F}; vaults on other graphs have no delegated-claim path.`
682
+ `Graph version ${e} is not the delegated-claim graph version ${q}; vaults on other graphs have no delegated-claim path.`
683
683
  );
684
684
  if (e !== r.vaultCoreVersion)
685
685
  throw new Error(
686
686
  `Graph version ${e} does not match the vault context's vault core version ${r.vaultCoreVersion}; they are one axis and must agree.`
687
687
  );
688
688
  const [n, a, i, u, l] = await Promise.all([
689
- lr(e, t),
690
- pr(e, t),
691
689
  dr(e, t),
690
+ pr(e, t),
692
691
  hr(e, t),
693
- gr(e, t)
692
+ gr(e, t),
693
+ fr(e, t)
694
694
  ]);
695
- St({
696
- peginTxid: mo(n),
695
+ At({
696
+ peginTxid: bo(n),
697
697
  depositorEthAddress: r.depositorEthAddress,
698
698
  expectedVaultId: r.vaultId
699
- }), co({
699
+ }), lo({
700
700
  claimPsbtBase64: n,
701
701
  assertPsbtBase64: a,
702
702
  payoutClaimerPsbtBase64: i
703
703
  });
704
- for (const d of [i, l])
705
- fo({
706
- payoutPsbtBase64: d,
704
+ for (const p of [i, l])
705
+ yo({
706
+ payoutPsbtBase64: p,
707
707
  registeredPayoutScriptPubKey: r.registeredPayoutScriptPubKey,
708
708
  depositorBtcPubkey: r.depositorBtcPubkey
709
709
  });
710
- const c = vo({
710
+ const c = Po({
711
711
  payoutDepositorPsbtBase64: l,
712
712
  payoutClaimerPsbtBase64: i
713
713
  });
714
- return await lo({
714
+ return await po({
715
715
  payoutClaimerPsbtBase64: i,
716
716
  payoutDepositorPsbtBase64: c,
717
717
  assertPsbtBase64: a,
718
718
  vault: r
719
- }), ho({
719
+ }), go({
720
720
  graphChallengerPubkeys: Object.keys(u),
721
721
  depositorBtcPubkey: o,
722
722
  vaultProviderBtcPubkey: r.vaultProviderBtcPubkey,
@@ -724,13 +724,13 @@ async function Vt(e, t, r, o) {
724
724
  universalChallengerBtcPubkeys: r.universalChallengerBtcPubkeys
725
725
  }), { claim: n, assert: a, payoutClaimer: i, payoutDepositor: c, wronglyChallenged: u };
726
726
  }
727
- async function So(e) {
728
- At({
727
+ async function Ao(e) {
728
+ Bt({
729
729
  servedVerifyingKeyHex: e.source.verifyingKeyHex,
730
730
  trustedVerifyingKeyHex: e.trustedVerifyingKeyHex,
731
731
  proverCircuitVersion: e.vault.proverCircuitVersion
732
732
  });
733
- const t = await Vt(
733
+ const t = await Rt(
734
734
  e.vault.txGraphVersion,
735
735
  e.source.txGraphJson,
736
736
  e.vault,
@@ -743,30 +743,30 @@ async function So(e) {
743
743
  source: e.source,
744
744
  vault: e.vault,
745
745
  // Omitted means unjoined: the browser cannot hold the real sessions.
746
- babeSessionsJson: e.babeSessionsJson === void 0 ? To : e.babeSessionsJson,
747
- requests: It(t)
746
+ babeSessionsJson: e.babeSessionsJson === void 0 ? _o : e.babeSessionsJson,
747
+ requests: Vt(t)
748
748
  };
749
749
  }
750
750
  function fe(e, t, r) {
751
751
  oe({
752
752
  requestedPsbtHex: He(t.psbtBase64),
753
753
  signatureHex: r,
754
- signerXOnlyPubkeyHex: V(e.depositorPublicKey),
754
+ signerXOnlyPubkeyHex: R(e.depositorPublicKey),
755
755
  inputIndex: t.inputIndex
756
756
  });
757
757
  }
758
758
  function He(e) {
759
- return H.from(e, "base64").toString("hex");
759
+ return O.from(e, "base64").toString("hex");
760
760
  }
761
- function Rt(e) {
762
- return H.from(e, "hex").toString("base64");
761
+ function Kt(e) {
762
+ return O.from(e, "hex").toString("base64");
763
763
  }
764
764
  class Y extends Error {
765
765
  constructor(t) {
766
766
  super(t), this.name = "SigningPlanMismatchError";
767
767
  }
768
768
  }
769
- function Ao(e, t) {
769
+ function Bo(e, t) {
770
770
  if (e.length !== t.length)
771
771
  throw new Y(
772
772
  `Plan has ${e.length} requests but the graph builds ${t.length}; the plan was altered after planning.`
@@ -791,7 +791,7 @@ function Ao(e, t) {
791
791
  );
792
792
  }
793
793
  }
794
- function Bo(e, t) {
794
+ function Io(e, t) {
795
795
  const r = new Set(e.map((a) => a.id)), o = [...r].filter((a) => !t.has(a)), s = [...t.keys()].filter((a) => !r.has(a));
796
796
  if (o.length === 0 && s.length === 0) return;
797
797
  const n = (a) => a.map((i) => `"${i}"`).join(", ");
@@ -799,7 +799,7 @@ function Bo(e, t) {
799
799
  `Signatures do not cover the plan: ${t.size} signatures for ${e.length} requests` + (o.length > 0 ? `; missing ${n(o)}` : "") + (s.length > 0 ? `; extra ${n(s)}` : "") + "."
800
800
  );
801
801
  }
802
- function L(e, t) {
802
+ function M(e, t) {
803
803
  const r = e.get(t);
804
804
  if (r === void 0)
805
805
  throw new Error(
@@ -807,45 +807,45 @@ function L(e, t) {
807
807
  );
808
808
  return r;
809
809
  }
810
- async function Io(e) {
811
- const { plan: t, signatures: r } = e, { txGraphVersion: o } = t.vault, s = t.source.txGraphJson, n = At({
810
+ async function Vo(e) {
811
+ const { plan: t, signatures: r } = e, { txGraphVersion: o } = t.vault, s = t.source.txGraphJson, n = Bt({
812
812
  servedVerifyingKeyHex: t.source.verifyingKeyHex,
813
813
  trustedVerifyingKeyHex: t.trustedVerifyingKeyHex,
814
814
  proverCircuitVersion: t.vault.proverCircuitVersion
815
- }), a = await Vt(
815
+ }), a = await Rt(
816
816
  o,
817
817
  s,
818
818
  t.vault,
819
819
  t.depositorPublicKey
820
- ), i = It(a);
821
- Ao(t.requests, i), Bo(i, r);
820
+ ), i = Vt(a);
821
+ Bo(t.requests, i), Io(i, r);
822
822
  for (const c of i)
823
823
  fe(
824
824
  t,
825
825
  c,
826
- L(r, c.id)
826
+ M(r, c.id)
827
827
  );
828
828
  const u = {};
829
829
  for (const c of Object.keys(a.wronglyChallenged))
830
830
  u[c] = a.wronglyChallenged[c].map(
831
- (d, p) => L(
831
+ (p, d) => M(
832
832
  r,
833
- Bt(c, p)
833
+ It(c, d)
834
834
  )
835
835
  );
836
- const l = await fr(
836
+ const l = await yr(
837
837
  o,
838
838
  s,
839
- L(r, "claim")
839
+ M(r, "claim")
840
840
  );
841
- return yr({
841
+ return vr({
842
842
  txGraphVersion: o,
843
843
  graphJson: s,
844
844
  signedClaimTxHex: l,
845
- assertClaimerSigHex: L(r, "assert"),
846
- payoutClaimerSigHex: L(r, "payoutClaimer"),
845
+ assertClaimerSigHex: M(r, "assert"),
846
+ payoutClaimerSigHex: M(r, "payoutClaimer"),
847
847
  wronglyChallengedSigs: u,
848
- depositorPayoutSigHex: L(r, "payoutDepositor"),
848
+ depositorPayoutSigHex: M(r, "payoutDepositor"),
849
849
  verifyingKeyHex: n,
850
850
  claimableEventBlockNumber: t.vault.claimableEventBlockNumber,
851
851
  proverCircuitVersion: t.vault.proverCircuitVersion,
@@ -854,44 +854,44 @@ async function Io(e) {
854
854
  expectedVaultCoreVersion: t.vault.vaultCoreVersion
855
855
  });
856
856
  }
857
- function Vo(e) {
857
+ function Ro(e) {
858
858
  return typeof e.signDelegatedClaimPsbt == "function";
859
859
  }
860
- class Ro extends Error {
860
+ class Ko extends Error {
861
861
  constructor(t, r, o, s) {
862
862
  super(t, s), this.signatures = r, this.failedRequestId = o, this.name = "DelegatedClaimSigningIncompleteError";
863
863
  }
864
864
  }
865
- const Kt = {
865
+ const Ht = {
866
866
  assert: "intentBound",
867
867
  payoutDepositor: "intentBound",
868
868
  payoutClaimer: "standalone",
869
869
  claim: "standalone",
870
870
  wronglyChallenged: "standalone"
871
- }, Ko = [
871
+ }, Ho = [
872
872
  "payoutClaimer",
873
873
  "claim",
874
874
  "wronglyChallenged"
875
875
  ];
876
- async function Ho(e, t, r = {}) {
876
+ async function Oo(e, t, r = {}) {
877
877
  var s;
878
- if ((s = r.signal) == null || s.throwIfAborted(), Oo(e), V(e.depositorPublicKey) !== e.vault.depositorBtcPubkey)
878
+ if ((s = r.signal) == null || s.throwIfAborted(), No(e), R(e.depositorPublicKey) !== e.vault.depositorBtcPubkey)
879
879
  throw new Error(
880
- `Plan depositor key ${V(e.depositorPublicKey)} is not the vault's registered depositor key ${e.vault.depositorBtcPubkey}; the plan was not built for this vault.`
880
+ `Plan depositor key ${R(e.depositorPublicKey)} is not the vault's registered depositor key ${e.vault.depositorBtcPubkey}; the plan was not built for this vault.`
881
881
  );
882
- if (vt(t)) {
883
- if (!Vo(t))
882
+ if (Pt(t)) {
883
+ if (!Ro(t))
884
884
  throw new Error(
885
885
  "Approval wallet does not implement signDelegatedClaimPsbt; the claim ceremony needs it because the device signs some claim PSBTs with no loaded intent and needs its own derivation fields on them."
886
886
  );
887
- const n = Do(r, e);
888
- Lo(n.depositTerms, e.vault);
889
- const a = No(e), i = await Ze(
887
+ const n = Lo(r, e);
888
+ Mo(n.depositTerms, e.vault);
889
+ const a = Do(e), i = await Ze(
890
890
  t,
891
891
  e.depositorPublicKey,
892
892
  e.btcNetwork
893
893
  );
894
- return Mo(
894
+ return Uo(
895
895
  e,
896
896
  t,
897
897
  i,
@@ -905,9 +905,9 @@ async function Ho(e, t, r = {}) {
905
905
  e.depositorPublicKey,
906
906
  e.btcNetwork
907
907
  );
908
- return Fo(e, t, o, r.signal);
908
+ return qo(e, t, o, r.signal);
909
909
  }
910
- function Oo(e) {
910
+ function No(e) {
911
911
  const t = /* @__PURE__ */ new Set();
912
912
  for (const r of e.requests) {
913
913
  if (t.has(r.id))
@@ -917,10 +917,10 @@ function Oo(e) {
917
917
  t.add(r.id);
918
918
  }
919
919
  }
920
- function No(e) {
920
+ function Do(e) {
921
921
  const t = e.requests.filter(
922
- (s) => Kt[s.kind] === "intentBound"
923
- ), r = Ko.flatMap(
922
+ (s) => Ht[s.kind] === "intentBound"
923
+ ), r = Ho.flatMap(
924
924
  (s) => e.requests.filter((n) => n.kind === s)
925
925
  ), o = t.length + r.length;
926
926
  if (o !== e.requests.length)
@@ -929,13 +929,13 @@ function No(e) {
929
929
  );
930
930
  return { intentBound: t, standalone: r };
931
931
  }
932
- function Ht(e, t) {
932
+ function Ot(e, t) {
933
933
  if (t.size !== e.requests.length)
934
934
  throw new Error(
935
935
  `Delegated-claim signing ended with ${t.size} signatures for ${e.requests.length} requests; the set is incomplete and must not be treated as signed.`
936
936
  );
937
937
  }
938
- function Do(e, t) {
938
+ function Lo(e, t) {
939
939
  if (e.depositTerms === void 0)
940
940
  throw new Error(
941
941
  "An approval wallet signs Assert and the depositor Payout only under this vault's loaded intent; pass depositTerms (rebuilt from on-chain state) so it can be approved."
@@ -944,15 +944,15 @@ function Do(e, t) {
944
944
  throw new Error(
945
945
  "An approval wallet releases a loaded intent only through the vault-root derivation; pass vaultContext so that derivation can run before and after the intent-bound signatures."
946
946
  );
947
- const r = yt(e.vaultContext.depositorBtcPubkey);
947
+ const r = vt(e.vaultContext.depositorBtcPubkey);
948
948
  if (r !== t.vault.depositorBtcPubkey)
949
949
  throw new Error(
950
950
  `vaultContext derives from depositor key ${r} but this plan's vault is registered to ${t.vault.depositorBtcPubkey}; the device would derive for another depositor.`
951
951
  );
952
952
  return { depositTerms: e.depositTerms, vaultContext: e.vaultContext };
953
953
  }
954
- function Lo(e, t) {
955
- const r = (s) => s.map((n) => V(n)).sort().join(",");
954
+ function Mo(e, t) {
955
+ const r = (s) => s.map((n) => R(n)).sort().join(",");
956
956
  if (r(e.vaultKeeperBtcPubkeys) !== r(t.vaultKeeperBtcPubkeys) || r(e.universalChallengerBtcPubkeys) !== r(t.universalChallengerBtcPubkeys))
957
957
  throw new Error(
958
958
  "Deposit terms carry different keeper or challenger rosters than the vault context this claim signs for; the device would bind the Assert to the wrong intent."
@@ -977,22 +977,22 @@ function Lo(e, t) {
977
977
  throw new Error(
978
978
  "Deposit terms describe no vault group, so they cannot name the vault context's vault provider; the device would bind the Assert to the wrong intent."
979
979
  );
980
- const o = V(t.vaultProviderBtcPubkey);
980
+ const o = R(t.vaultProviderBtcPubkey);
981
981
  for (const s of e.vaults)
982
- if (V(s.vaultProviderBtcPubkey) !== o)
982
+ if (R(s.vaultProviderBtcPubkey) !== o)
983
983
  throw new Error(
984
984
  `Deposit terms group at htlcVout ${s.htlcVout} names a different vault provider than the vault context this claim signs for; the device would bind the Assert to the wrong intent.`
985
985
  );
986
986
  }
987
- async function Mo(e, t, r, o, { intentBound: s, standalone: n }, a) {
987
+ async function Uo(e, t, r, o, { intentBound: s, standalone: n }, a) {
988
988
  var g;
989
- const i = Uo(e, a.resume), u = [...s, ...n];
989
+ const i = Fo(e, a.resume), u = [...s, ...n];
990
990
  let l = 0;
991
991
  const c = {
992
992
  phase: "clearing any loaded intent"
993
- }, d = async (h) => {
994
- var m;
995
- c.phase = "signing", (m = a.signal) == null || m.throwIfAborted();
993
+ }, p = async (h) => {
994
+ var b;
995
+ c.phase = "signing", (b = a.signal) == null || b.throwIfAborted();
996
996
  const y = await t.signDelegatedClaimPsbt(
997
997
  He(h.psbtBase64),
998
998
  kt(
@@ -1000,42 +1000,42 @@ async function Mo(e, t, r, o, { intentBound: s, standalone: n }, a) {
1000
1000
  h.inputIndex,
1001
1001
  r
1002
1002
  )
1003
- ), f = await mt(
1004
- Rt(y),
1003
+ ), f = await bt(
1004
+ Kt(y),
1005
1005
  h.inputIndex
1006
1006
  );
1007
1007
  fe(e, h, f), i.set(h.id, f);
1008
- }, p = async (h) => {
1008
+ }, d = async (h) => {
1009
1009
  var f;
1010
- c.phase = h, (f = a.signal) == null || f.throwIfAborted(), (await $t(t, o.vaultContext)).fill(0);
1010
+ c.phase = h, (f = a.signal) == null || f.throwIfAborted(), (await Ct(t, o.vaultContext)).fill(0);
1011
1011
  };
1012
1012
  typeof t.validateDepositTerms == "function" && await t.validateDepositTerms(o.depositTerms);
1013
1013
  try {
1014
- await p("clearing any loaded intent"), c.phase = "approving the deposit terms", (g = a.signal) == null || g.throwIfAborted(), await t.approveDepositTerms(o.depositTerms);
1014
+ await d("clearing any loaded intent"), c.phase = "approving the deposit terms", (g = a.signal) == null || g.throwIfAborted(), await t.approveDepositTerms(o.depositTerms);
1015
1015
  for (const h of s)
1016
- await d(h), l++;
1017
- await p("releasing the loaded intent");
1016
+ await p(h), l++;
1017
+ await d("releasing the loaded intent");
1018
1018
  for (const h of n)
1019
- i.has(h.id) || await d(h), l++;
1019
+ i.has(h.id) || await p(h), l++;
1020
1020
  } catch (h) {
1021
1021
  const y = u[l];
1022
1022
  if (i.size === 0 || y === void 0) throw h;
1023
1023
  const f = c.phase === "signing" ? `stopped at "${y.id}"` : `stopped before "${y.id}" while ${c.phase}`;
1024
- throw new Ro(
1024
+ throw new Ko(
1025
1025
  `Delegated-claim signing ${f}; ${i.size} of ${e.requests.length} signatures were collected.`,
1026
1026
  i,
1027
1027
  y.id,
1028
1028
  { cause: h }
1029
1029
  );
1030
1030
  }
1031
- return Ht(e, i), i;
1031
+ return Ot(e, i), i;
1032
1032
  }
1033
- function Uo(e, t) {
1033
+ function Fo(e, t) {
1034
1034
  const r = /* @__PURE__ */ new Map();
1035
1035
  if (!t) return r;
1036
1036
  for (const o of e.requests) {
1037
1037
  const s = t.get(o.id);
1038
- if (!(s === void 0 || Kt[o.kind] === "intentBound")) {
1038
+ if (!(s === void 0 || Ht[o.kind] === "intentBound")) {
1039
1039
  try {
1040
1040
  fe(e, o, s);
1041
1041
  } catch {
@@ -1046,8 +1046,8 @@ function Uo(e, t) {
1046
1046
  }
1047
1047
  return r;
1048
1048
  }
1049
- async function Fo(e, t, r, o) {
1050
- const s = e.requests, n = await Pt(
1049
+ async function qo(e, t, r, o) {
1050
+ const s = e.requests, n = await mt(
1051
1051
  t,
1052
1052
  s.map((i) => He(i.psbtBase64)),
1053
1053
  s.map(
@@ -1060,43 +1060,43 @@ async function Fo(e, t, r, o) {
1060
1060
  o
1061
1061
  ), a = /* @__PURE__ */ new Map();
1062
1062
  for (let i = 0; i < s.length; i++) {
1063
- const u = await mt(
1064
- Rt(n[i]),
1063
+ const u = await bt(
1064
+ Kt(n[i]),
1065
1065
  s[i].inputIndex
1066
1066
  );
1067
1067
  fe(e, s[i], u), a.set(s[i].id, u);
1068
1068
  }
1069
- return Ht(e, a), a;
1069
+ return Ot(e, a), a;
1070
1070
  }
1071
- async function hn(e) {
1072
- const t = await So({
1071
+ async function yn(e) {
1072
+ const t = await Ao({
1073
1073
  depositorPublicKey: e.depositorPublicKey,
1074
1074
  btcNetwork: e.btcNetwork,
1075
1075
  source: e.source,
1076
1076
  trustedVerifyingKeyHex: e.trustedVerifyingKeyHex,
1077
1077
  vault: e.vault,
1078
1078
  babeSessionsJson: e.babeSessionsJson
1079
- }), r = await Ho(t, e.btcWallet, {
1079
+ }), r = await Oo(t, e.btcWallet, {
1080
1080
  depositTerms: e.depositTerms,
1081
1081
  vaultContext: e.vaultContext
1082
1082
  });
1083
- return Io({ plan: t, signatures: r });
1083
+ return Vo({ plan: t, signatures: r });
1084
1084
  }
1085
- async function gn(e) {
1086
- const t = await $t(e.btcWallet, e.vaultContext);
1085
+ async function vn(e) {
1086
+ const t = await Ct(e.btcWallet, e.vaultContext);
1087
1087
  let r;
1088
1088
  try {
1089
- r = await vr(t, e.htlcVout);
1089
+ r = await Pr(t, e.htlcVout);
1090
1090
  } finally {
1091
1091
  t.fill(0);
1092
1092
  }
1093
1093
  let o;
1094
1094
  try {
1095
- o = await Pr(r);
1095
+ o = await mr(r);
1096
1096
  } finally {
1097
1097
  r.fill(0);
1098
1098
  }
1099
- return qo(o.pk_hash, e.expectedWotsPkHash), await mr(
1099
+ return Go(o.pk_hash, e.expectedWotsPkHash), await br(
1100
1100
  e.txGraphVersion,
1101
1101
  o.keypair,
1102
1102
  e.txGraphJson
@@ -1105,7 +1105,7 @@ async function gn(e) {
1105
1105
  pkHash: o.pk_hash
1106
1106
  };
1107
1107
  }
1108
- function qo(e, t) {
1108
+ function Go(e, t) {
1109
1109
  if (ie(e) !== ie(t))
1110
1110
  throw new Error(
1111
1111
  `Derived WOTS public-key hash ${ie(e)} does not match the vault's on-chain depositorWotsPkHash ${ie(t)}. The wallet, the HTLC output index, or the derivation itself is not the one this vault was created with.`
@@ -1126,7 +1126,7 @@ function xe(e, t, r) {
1126
1126
  rotated: n !== s
1127
1127
  };
1128
1128
  }
1129
- function Go(e) {
1129
+ function Xo(e) {
1130
1130
  const t = /* @__PURE__ */ new Map();
1131
1131
  for (const r of e) {
1132
1132
  const o = t.get(r.operationBtcPubkey);
@@ -1137,7 +1137,7 @@ function Go(e) {
1137
1137
  t.set(r.operationBtcPubkey, r.adminAddress);
1138
1138
  }
1139
1139
  }
1140
- function Ot(e, t, r) {
1140
+ function Nt(e, t, r) {
1141
1141
  if (t.vaultKeepers.length !== e.vaultKeepers.length || t.universalChallengers.length !== e.universalChallengers.length)
1142
1142
  throw new Error(
1143
1143
  `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`
@@ -1154,7 +1154,7 @@ function Ot(e, t, r) {
1154
1154
  ), n = e.universalChallengers.map(
1155
1155
  (a, i) => xe("universal challenger", a, t.universalChallengers[i])
1156
1156
  );
1157
- return Go([
1157
+ return Xo([
1158
1158
  o,
1159
1159
  ...s,
1160
1160
  ...n
@@ -1169,24 +1169,24 @@ function Ot(e, t, r) {
1169
1169
  query: e
1170
1170
  };
1171
1171
  }
1172
- async function Xo(e) {
1172
+ async function zo(e) {
1173
1173
  const t = await e.operationKeyReader.getCurrentOperationKeys(
1174
1174
  e.query,
1175
1175
  e.blockNumber
1176
1176
  );
1177
- return Ot(e.query, t, { mode: "current" });
1177
+ return Nt(e.query, t, { mode: "current" });
1178
1178
  }
1179
- async function Nt(e) {
1179
+ async function Dt(e) {
1180
1180
  const t = await e.operationKeyReader.getOperationKeysAtEpochs(
1181
1181
  e.query,
1182
1182
  e.epochs
1183
1183
  );
1184
- return Ot(e.query, t, {
1184
+ return Nt(e.query, t, {
1185
1185
  mode: "epochs",
1186
1186
  epochs: e.epochs
1187
1187
  });
1188
1188
  }
1189
- async function Dt(e) {
1189
+ async function Lt(e) {
1190
1190
  const { basic: t, protocol: r } = e.vault, {
1191
1191
  registryReader: o,
1192
1192
  vaultKeeperReader: s,
@@ -1216,7 +1216,7 @@ async function Dt(e) {
1216
1216
  throw new Error(
1217
1217
  `No universal challengers for version ${r.universalChallengersVersion}`
1218
1218
  );
1219
- return Nt({
1219
+ return Dt({
1220
1220
  operationKeyReader: a,
1221
1221
  query: {
1222
1222
  vaultProviderEthAddress: t.vaultProvider,
@@ -1228,11 +1228,11 @@ async function Dt(e) {
1228
1228
  epochs: c
1229
1229
  });
1230
1230
  }
1231
- async function fn(e) {
1231
+ async function Pn(e) {
1232
1232
  const { vaultId: t, readers: r } = e, o = await r.registryReader.getVaultData(t), { basic: s, protocol: n } = o;
1233
- if (n.vaultCoreVersion !== F)
1233
+ if (n.vaultCoreVersion !== q)
1234
1234
  throw new Error(
1235
- `Vault ${t} is stamped vault core version ${n.vaultCoreVersion}; delegated claim requires ${F}.`
1235
+ `Vault ${t} is stamped vault core version ${n.vaultCoreVersion}; delegated claim requires ${q}.`
1236
1236
  );
1237
1237
  const a = _e(
1238
1238
  s.depositorBtcPubKey,
@@ -1247,7 +1247,7 @@ async function fn(e) {
1247
1247
  `the vault's status is ${s.status}, not Redeemed (${ze.REDEEMED}); no scan was made`
1248
1248
  );
1249
1249
  const [i, u, l, c] = await Promise.all([
1250
- Dt({ vaultId: t, vault: o, readers: r }),
1250
+ Lt({ vaultId: t, vault: o, readers: r }),
1251
1251
  r.registryReader.getRegistrationRecordsAtBlock(s.createdAt),
1252
1252
  r.registryReader.getVaultClaimableBy(t, s.depositorBtcPubKey, s.createdAt).catch((v) => {
1253
1253
  throw kr(v) ? new Le(
@@ -1262,54 +1262,54 @@ async function fn(e) {
1262
1262
  r.protocolParamsReader.getOffchainParamsByVersion(
1263
1263
  n.offchainParamsVersion
1264
1264
  )
1265
- ]), d = Or(c.timelockAssert), p = $r(u, t, s.createdAt);
1266
- Cr(p);
1267
- const g = Tr(p);
1265
+ ]), p = Nr(c.timelockAssert), d = Cr(u, t, s.createdAt);
1266
+ Tr(d);
1267
+ const g = _r(d);
1268
1268
  if (g.toLowerCase() !== n.prePeginTxHash.toLowerCase())
1269
1269
  throw new Error(
1270
1270
  `Registration log of vault ${t} records prePeginTxHash ${g} but the vault record says ${n.prePeginTxHash}; refusing an inconsistent node.`
1271
1271
  );
1272
- if (p.vaultCoreVersion !== n.vaultCoreVersion)
1272
+ if (d.vaultCoreVersion !== n.vaultCoreVersion)
1273
1273
  throw new Error(
1274
- `Registration log of vault ${t} records vault core version ${p.vaultCoreVersion} but the vault record says ${n.vaultCoreVersion}; refusing an inconsistent node.`
1274
+ `Registration log of vault ${t} records vault core version ${d.vaultCoreVersion} but the vault record says ${n.vaultCoreVersion}; refusing an inconsistent node.`
1275
1275
  );
1276
- if (p.amount !== s.amount)
1276
+ if (d.amount !== s.amount)
1277
1277
  throw new Error(
1278
- `Registration log of vault ${t} records amount ${p.amount} sats but the vault record says ${s.amount}; refusing an inconsistent node.`
1278
+ `Registration log of vault ${t} records amount ${d.amount} sats but the vault record says ${s.amount}; refusing an inconsistent node.`
1279
1279
  );
1280
- if (p.depositor.toLowerCase() !== s.depositor.toLowerCase())
1280
+ if (d.depositor.toLowerCase() !== s.depositor.toLowerCase())
1281
1281
  throw new Error(
1282
- `Registration log of vault ${t} records depositor ${p.depositor} but the vault record says ${s.depositor}; refusing an inconsistent node.`
1282
+ `Registration log of vault ${t} records depositor ${d.depositor} but the vault record says ${s.depositor}; refusing an inconsistent node.`
1283
1283
  );
1284
- if (p.vaultProvider.toLowerCase() !== s.vaultProvider.toLowerCase())
1284
+ if (d.vaultProvider.toLowerCase() !== s.vaultProvider.toLowerCase())
1285
1285
  throw new Error(
1286
- `Registration log of vault ${t} records vaultProvider ${p.vaultProvider} but the vault record says ${s.vaultProvider}; refusing an inconsistent node.`
1286
+ `Registration log of vault ${t} records vaultProvider ${d.vaultProvider} but the vault record says ${s.vaultProvider}; refusing an inconsistent node.`
1287
1287
  );
1288
1288
  if (l.vaultCoreVersion !== n.vaultCoreVersion)
1289
1289
  throw new Error(
1290
1290
  `Redemption log of vault ${t} records vault core version ${l.vaultCoreVersion} but the vault record says ${n.vaultCoreVersion}; refusing an inconsistent node.`
1291
1291
  );
1292
- if (l.proverCircuitVersion !== p.proverCircuitVersion)
1292
+ if (l.proverCircuitVersion !== d.proverCircuitVersion)
1293
1293
  throw new Error(
1294
- `Redemption log of vault ${t} records proverCircuitVersion ${l.proverCircuitVersion} but the registration log says ${p.proverCircuitVersion}; refusing an inconsistent node.`
1294
+ `Redemption log of vault ${t} records proverCircuitVersion ${l.proverCircuitVersion} but the registration log says ${d.proverCircuitVersion}; refusing an inconsistent node.`
1295
1295
  );
1296
- if (p.proverCircuitVersion !== c.proverCircuitVersion)
1296
+ if (d.proverCircuitVersion !== c.proverCircuitVersion)
1297
1297
  throw new Error(
1298
- `Registration log of vault ${t} records proverCircuitVersion ${p.proverCircuitVersion} but the stamped offchain params say ${c.proverCircuitVersion}; refusing an inconsistent node.`
1298
+ `Registration log of vault ${t} records proverCircuitVersion ${d.proverCircuitVersion} but the stamped offchain params say ${c.proverCircuitVersion}; refusing an inconsistent node.`
1299
1299
  );
1300
- const h = _r(n.depositorSignedPeginTx);
1300
+ const h = Sr(n.depositorSignedPeginTx);
1301
1301
  for (const [v, E] of [
1302
- ["Registration", p.peginTxHash],
1302
+ ["Registration", d.peginTxHash],
1303
1303
  ["Redemption", l.peginTxHash]
1304
1304
  ])
1305
1305
  if (E.toLowerCase() !== h.toLowerCase())
1306
1306
  throw new Error(
1307
1307
  `${v} log of vault ${t} records peginTxHash ${E} but the vault's depositor-signed PegIn hashes to ${h}; refusing an inconsistent node.`
1308
1308
  );
1309
- const y = z(
1310
- bt(h, s.depositor)
1309
+ const y = j(
1310
+ wt(h, s.depositor)
1311
1311
  );
1312
- if (y !== z(t))
1312
+ if (y !== j(t))
1313
1313
  throw new Error(
1314
1314
  `Depositor-signed PegIn of vault ${t} derives vault id ${y} with depositor ${s.depositor}; refusing an inconsistent node.`
1315
1315
  );
@@ -1318,9 +1318,9 @@ async function fn(e) {
1318
1318
  "universalChallengersVersion",
1319
1319
  "appVaultKeepersVersion"
1320
1320
  ]) {
1321
- if (p[v] !== n[v])
1321
+ if (d[v] !== n[v])
1322
1322
  throw new Error(
1323
- `Registration log of vault ${t} records ${v} ${p[v]} but the vault record says ${n[v]}; refusing an inconsistent node.`
1323
+ `Registration log of vault ${t} records ${v} ${d[v]} but the vault record says ${n[v]}; refusing an inconsistent node.`
1324
1324
  );
1325
1325
  if (l[v] !== n[v])
1326
1326
  throw new Error(
@@ -1334,10 +1334,10 @@ async function fn(e) {
1334
1334
  throw new Error(
1335
1335
  `Depositor-signed PegIn of vault ${t} has ${f.ins.length} inputs; it spends Pre-PegIn ${n.prePeginTxHash} output ${n.htlcVout} with exactly one; refusing an inconsistent node.`
1336
1336
  );
1337
- const m = Ke(f.ins[0].hash), $ = f.ins[0].index;
1338
- if (m !== P(n.prePeginTxHash).toLowerCase() || $ !== n.htlcVout)
1337
+ const b = Ke(f.ins[0].hash), k = f.ins[0].index;
1338
+ if (b !== P(n.prePeginTxHash).toLowerCase() || k !== n.htlcVout)
1339
1339
  throw new Error(
1340
- `Depositor-signed PegIn of vault ${t} spends ${m}:${$} but the vault record says Pre-PegIn ${n.prePeginTxHash} output ${n.htlcVout}; refusing an inconsistent node.`
1340
+ `Depositor-signed PegIn of vault ${t} spends ${b}:${k} but the vault record says Pre-PegIn ${n.prePeginTxHash} output ${n.htlcVout}; refusing an inconsistent node.`
1341
1341
  );
1342
1342
  const x = f.outs[Z];
1343
1343
  if (x === void 0)
@@ -1354,7 +1354,7 @@ async function fn(e) {
1354
1354
  depositorEthAddress: s.depositor,
1355
1355
  depositorBtcPubkey: a,
1356
1356
  registeredPayoutScriptPubKey: P(
1357
- p.depositorPayoutScriptPubKey
1357
+ d.depositorPayoutScriptPubKey
1358
1358
  ),
1359
1359
  vaultProviderBtcPubkey: i.vaultProvider.operationBtcPubkey,
1360
1360
  vaultKeeperBtcPubkeys: [
@@ -1363,18 +1363,18 @@ async function fn(e) {
1363
1363
  universalChallengerBtcPubkeys: [
1364
1364
  ...i.universalChallengerOperationKeysSorted
1365
1365
  ],
1366
- txGraphVersion: F,
1366
+ txGraphVersion: q,
1367
1367
  proverCircuitVersion: c.proverCircuitVersion,
1368
1368
  vaultCoreVersion: n.vaultCoreVersion,
1369
1369
  claimableEventBlockNumber: l.blockNumber,
1370
1370
  peginVaultOutputValueSats: x.value,
1371
1371
  protocolFeeRate: c.feeRate,
1372
1372
  councilSize: c.securityCouncilKeys.length,
1373
- timelockPegin: d,
1373
+ timelockPegin: p,
1374
1374
  timelockAssert: Number(c.timelockAssert)
1375
1375
  },
1376
1376
  vault: o,
1377
- registrationRecord: p,
1377
+ registrationRecord: d,
1378
1378
  registrationRecords: u,
1379
1379
  participantKeys: i,
1380
1380
  offchainParams: c,
@@ -1386,35 +1386,35 @@ async function fn(e) {
1386
1386
  htlcVout: n.htlcVout
1387
1387
  };
1388
1388
  }
1389
- const zo = 8, jo = 6e3, Wo = 10 * 6e4, Yo = 10;
1390
- class Lt extends Error {
1389
+ const jo = 8, Wo = 6e3, Yo = 10 * 6e4, Qo = 10;
1390
+ class Mt extends Error {
1391
1391
  constructor(t) {
1392
1392
  super(t), this.name = "PeginRegistrationMissingError";
1393
1393
  }
1394
1394
  }
1395
- class Mt extends Error {
1395
+ class Ut extends Error {
1396
1396
  constructor(t) {
1397
1397
  super(t), this.name = "PeginRegistrationNotFinalError";
1398
1398
  }
1399
1399
  }
1400
- function Qo(e) {
1401
- return e instanceof Lt || e instanceof Error && e.name === "PeginRegistrationMissingError";
1400
+ function Jo(e) {
1401
+ return e instanceof Mt || e instanceof Error && e.name === "PeginRegistrationMissingError";
1402
1402
  }
1403
- function yn(e) {
1404
- return e instanceof Mt || e instanceof Error && e.name === "PeginRegistrationNotFinalError";
1403
+ function mn(e) {
1404
+ return e instanceof Ut || e instanceof Error && e.name === "PeginRegistrationNotFinalError";
1405
1405
  }
1406
1406
  function et(e) {
1407
1407
  const { currentBlock: t, createdAtBlock: r } = e, o = t - r + 1n;
1408
1408
  return o < 0n ? 0 : Number(o);
1409
1409
  }
1410
- async function vn(e) {
1410
+ async function bn(e) {
1411
1411
  const {
1412
1412
  vaultRegistryReader: t,
1413
1413
  getBlockNumber: r,
1414
1414
  vaultIds: o,
1415
- required: s = zo,
1416
- pollIntervalMs: n = jo,
1417
- timeoutMs: a = Wo,
1415
+ required: s = jo,
1416
+ pollIntervalMs: n = Wo,
1417
+ timeoutMs: a = Yo,
1418
1418
  signal: i,
1419
1419
  onProgress: u
1420
1420
  } = e;
@@ -1423,52 +1423,52 @@ async function vn(e) {
1423
1423
  "waitForPeginRegistrationDepth requires at least one vault ID"
1424
1424
  );
1425
1425
  const l = Date.now();
1426
- let c = !1, d = 0, p;
1426
+ let c = !1, p = 0, d;
1427
1427
  for (; ; ) {
1428
1428
  if (i != null && i.aborted)
1429
1429
  throw new Error(
1430
1430
  `Aborted while waiting for peg-in registration depth (${o.length} vault(s))`
1431
1431
  );
1432
1432
  if (Date.now() - l >= a)
1433
- throw new Mt(
1434
- `Peg-in registration did not reach ${s} 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}` : "")
1433
+ throw new Ut(
1434
+ `Peg-in registration did not reach ${s} 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.` + (d instanceof Error ? ` Last read error: ${d.message}` : "")
1435
1435
  );
1436
1436
  try {
1437
1437
  const g = await r(), h = await Promise.all(
1438
1438
  o.map((f) => t.getVaultBasicInfo(f))
1439
1439
  ), y = h.findIndex(
1440
- (f) => f.depositor === Nr || f.createdAt === 0n
1440
+ (f) => f.depositor === Dr || f.createdAt === 0n
1441
1441
  );
1442
1442
  if (y !== -1) {
1443
- if (d += 1, !c && d > Yo)
1444
- throw new Lt(
1445
- `Vault ${o[y]} is still not visible on-chain after ${d} reads — the registration does not exist.`
1443
+ if (p += 1, !c && p > Qo)
1444
+ throw new Mt(
1445
+ `Vault ${o[y]} is still not visible on-chain after ${p} reads — the registration does not exist.`
1446
1446
  );
1447
1447
  console.warn(
1448
1448
  `Peg-in registration for vault ${o[y]} is not visible in chain state at block ${g} — a lagging RPC backend or an Ethereum reorg. Still polling.`
1449
1449
  ), u == null || u({ confirmations: 0, required: s });
1450
1450
  } else {
1451
- c = !0, d = 0, p = void 0;
1452
- let f = h[0], m = et({
1451
+ c = !0, p = 0, d = void 0;
1452
+ let f = h[0], b = et({
1453
1453
  currentBlock: g,
1454
1454
  createdAtBlock: h[0].createdAt
1455
1455
  });
1456
- for (const $ of h.slice(1)) {
1456
+ for (const k of h.slice(1)) {
1457
1457
  const x = et({
1458
1458
  currentBlock: g,
1459
- createdAtBlock: $.createdAt
1459
+ createdAtBlock: k.createdAt
1460
1460
  });
1461
- x < m && (m = x, f = $);
1461
+ x < b && (b = x, f = k);
1462
1462
  }
1463
- if (u == null || u({ confirmations: m, required: s }), m >= s)
1464
- return { confirmations: m, basicInfo: f };
1463
+ if (u == null || u({ confirmations: b, required: s }), b >= s)
1464
+ return { confirmations: b, basicInfo: f };
1465
1465
  }
1466
1466
  } catch (g) {
1467
- if (Qo(g))
1467
+ if (Jo(g))
1468
1468
  throw g;
1469
1469
  console.warn(
1470
1470
  `Registration-depth read failed (retrying in ${n}ms): ` + (g instanceof Error ? g.message : String(g))
1471
- ), p = g;
1471
+ ), d = g;
1472
1472
  }
1473
1473
  await new Promise((g, h) => {
1474
1474
  const y = () => {
@@ -1484,307 +1484,307 @@ async function vn(e) {
1484
1484
  });
1485
1485
  }
1486
1486
  }
1487
- const Jo = /^(?:[0-9a-f]{2})*$/, Zo = /^[0-9a-f]{64}$/, es = /^([0-9a-f]{64}):(0|[1-9][0-9]*)$/, ts = -2147483648, rs = 2147483647, Ee = 4294967295, tt = 2, rt = 2, pe = 0;
1488
- class b extends Error {
1487
+ const Zo = /^(?:[0-9a-f]{2})*$/, es = /^[0-9a-f]{64}$/, ts = /^([0-9a-f]{64}):(0|[1-9][0-9]*)$/, rs = -2147483648, os = 2147483647, Ee = 4294967295, tt = 2, rt = 2, de = 0;
1488
+ class w extends Error {
1489
1489
  constructor(t) {
1490
1490
  super(t), this.name = "GraphFingerprintError";
1491
1491
  }
1492
1492
  }
1493
- function k(e, t, r) {
1493
+ function $(e, t, r) {
1494
1494
  const o = e[t];
1495
1495
  if (o === void 0)
1496
- throw new b(`Graph tx ${r} is missing "${t}"`);
1496
+ throw new w(`Graph tx ${r} is missing "${t}"`);
1497
1497
  return o;
1498
1498
  }
1499
1499
  function te(e, t) {
1500
1500
  if (!Array.isArray(e))
1501
- throw new b(`Graph tx ${t} is not an array`);
1501
+ throw new w(`Graph tx ${t} is not an array`);
1502
1502
  return e;
1503
1503
  }
1504
- function B(e, t) {
1504
+ function I(e, t) {
1505
1505
  if (e === null || typeof e != "object" || Array.isArray(e))
1506
- throw new b(`Graph tx ${t} is not an object`);
1506
+ throw new w(`Graph tx ${t} is not an object`);
1507
1507
  return e;
1508
1508
  }
1509
1509
  function Q(e, t, r, o) {
1510
1510
  if (typeof e != "number" || !Number.isSafeInteger(e) || e < r || e > o)
1511
- throw new b(
1511
+ throw new w(
1512
1512
  `Graph tx ${t} is not an integer in [${r}, ${o}]`
1513
1513
  );
1514
1514
  return e;
1515
1515
  }
1516
- function ke(e, t) {
1517
- if (typeof e != "string" || !Jo.test(e))
1518
- throw new b(
1516
+ function $e(e, t) {
1517
+ if (typeof e != "string" || !Zo.test(e))
1518
+ throw new w(
1519
1519
  `Graph tx ${t} is not lowercase hex without a prefix`
1520
1520
  );
1521
- return H.from(e, "hex");
1521
+ return O.from(e, "hex");
1522
1522
  }
1523
- function de(e, t) {
1524
- if (typeof e != "string" || !Zo.test(e))
1525
- throw new b(
1523
+ function pe(e, t) {
1524
+ if (typeof e != "string" || !es.test(e))
1525
+ throw new w(
1526
1526
  `Graph ${t} is not 32 bytes of lowercase hex`
1527
1527
  );
1528
1528
  return e;
1529
1529
  }
1530
1530
  function ot(e, t) {
1531
- const r = B(e, t), o = new S();
1531
+ const r = I(e, t), o = new S();
1532
1532
  return o.version = Q(
1533
- k(r, "version", t),
1533
+ $(r, "version", t),
1534
1534
  `${t}.version`,
1535
- ts,
1536
- rs
1535
+ rs,
1536
+ os
1537
1537
  ), o.locktime = Q(
1538
- k(r, "lock_time", t),
1538
+ $(r, "lock_time", t),
1539
1539
  `${t}.lock_time`,
1540
1540
  0,
1541
1541
  Ee
1542
- ), te(k(r, "input", t), `${t}.input`).forEach((s, n) => {
1543
- const a = `${t}.input[${n}]`, i = B(s, a), u = k(i, "previous_output", a), l = typeof u == "string" && es.exec(u);
1542
+ ), te($(r, "input", t), `${t}.input`).forEach((s, n) => {
1543
+ const a = `${t}.input[${n}]`, i = I(s, a), u = $(i, "previous_output", a), l = typeof u == "string" && ts.exec(u);
1544
1544
  if (!l)
1545
- throw new b(
1545
+ throw new w(
1546
1546
  `Graph tx ${a}.previous_output is not "<txid>:<vout>"`
1547
1547
  );
1548
1548
  const c = Q(Number(l[2]), `${a}.previous_output vout`, 0, Ee);
1549
1549
  o.addInput(
1550
- H.from(l[1], "hex").reverse(),
1550
+ O.from(l[1], "hex").reverse(),
1551
1551
  c,
1552
- Q(k(i, "sequence", a), `${a}.sequence`, 0, Ee),
1553
- ke(k(i, "script_sig", a), `${a}.script_sig`)
1552
+ Q($(i, "sequence", a), `${a}.sequence`, 0, Ee),
1553
+ $e($(i, "script_sig", a), `${a}.script_sig`)
1554
1554
  ), o.ins[n].witness = te(
1555
- k(i, "witness", a),
1555
+ $(i, "witness", a),
1556
1556
  `${a}.witness`
1557
- ).map((d, p) => ke(d, `${a}.witness[${p}]`));
1558
- }), te(k(r, "output", t), `${t}.output`).forEach((s, n) => {
1559
- const a = `${t}.output[${n}]`, i = B(s, a);
1557
+ ).map((p, d) => $e(p, `${a}.witness[${d}]`));
1558
+ }), te($(r, "output", t), `${t}.output`).forEach((s, n) => {
1559
+ const a = `${t}.output[${n}]`, i = I(s, a);
1560
1560
  o.addOutput(
1561
- ke(k(i, "script_pubkey", a), `${a}.script_pubkey`),
1562
- Q(k(i, "value", a), `${a}.value`, 0, Number.MAX_SAFE_INTEGER)
1561
+ $e($(i, "script_pubkey", a), `${a}.script_pubkey`),
1562
+ Q($(i, "value", a), `${a}.value`, 0, Number.MAX_SAFE_INTEGER)
1563
1563
  );
1564
1564
  }), new Uint8Array(o.toBuffer());
1565
1565
  }
1566
- function D(e, t) {
1566
+ function L(e, t) {
1567
1567
  const r = P(e).toLowerCase();
1568
1568
  let o;
1569
1569
  try {
1570
1570
  o = S.fromHex(r);
1571
1571
  } catch (s) {
1572
- throw new b(
1572
+ throw new w(
1573
1573
  `Presign ${t} is not one transaction: ${s instanceof Error ? s.message : String(s)}`
1574
1574
  );
1575
1575
  }
1576
1576
  if (o.toHex() !== r)
1577
- throw new b(
1577
+ throw new w(
1578
1578
  `Presign ${t} is not a canonical transaction encoding`
1579
1579
  );
1580
1580
  return o;
1581
1581
  }
1582
- function Ut(e, t) {
1582
+ function Ft(e, t) {
1583
1583
  const r = e.ins[t];
1584
1584
  if (r)
1585
1585
  return {
1586
- txid: H.from(r.hash).reverse().toString("hex"),
1586
+ txid: O.from(r.hash).reverse().toString("hex"),
1587
1587
  vout: r.index
1588
1588
  };
1589
1589
  }
1590
- function Ft(e, t) {
1591
- if (!e.outs[pe])
1592
- throw new b(
1593
- `Presign ${t}.claim_tx must have output ${pe}`
1590
+ function qt(e, t) {
1591
+ if (!e.outs[de])
1592
+ throw new w(
1593
+ `Presign ${t}.claim_tx must have output ${de}`
1594
1594
  );
1595
1595
  }
1596
- function os(e, t, r) {
1596
+ function ss(e, t, r) {
1597
1597
  if (e.ins.length !== 1)
1598
- throw new b(
1598
+ throw new w(
1599
1599
  `Presign ${r}.claim_tx must have exactly one input, got ${e.ins.length}`
1600
1600
  );
1601
- Ft(e, r);
1602
- const o = Ut(e, 0);
1603
- if ((o == null ? void 0 : o.txid) !== t || o.vout !== X) {
1601
+ qt(e, r);
1602
+ const o = Ft(e, 0);
1603
+ if ((o == null ? void 0 : o.txid) !== t || o.vout !== z) {
1604
1604
  const s = o ? `${o.txid}:${o.vout}` : "no input";
1605
- throw new b(
1606
- `Presign ${r}.claim_tx must spend ${t}:${X}, got ${s}`
1605
+ throw new w(
1606
+ `Presign ${r}.claim_tx must spend ${t}:${z}, got ${s}`
1607
1607
  );
1608
1608
  }
1609
1609
  }
1610
1610
  function Oe(e, t, r) {
1611
- const o = Ut(e, 0);
1612
- if ((o == null ? void 0 : o.txid) !== t || o.vout !== pe) {
1611
+ const o = Ft(e, 0);
1612
+ if ((o == null ? void 0 : o.txid) !== t || o.vout !== de) {
1613
1613
  const s = o ? `${o.txid}:${o.vout}` : "no input";
1614
- throw new b(
1615
- `Presign ${r}.assert_tx input 0 must spend ${t}:${pe}, got ${s}`
1614
+ throw new w(
1615
+ `Presign ${r}.assert_tx input 0 must spend ${t}:${de}, got ${s}`
1616
1616
  );
1617
1617
  }
1618
1618
  }
1619
- function qt(e) {
1620
- const t = D(e.peginTxHex, `${e.path}.pegin_tx`), r = D(e.claimTxHex, `${e.path}.claim_tx`), o = D(e.assertTxHex, `${e.path}.assert_tx`);
1619
+ function Gt(e) {
1620
+ const t = L(e.peginTxHex, `${e.path}.pegin_tx`), r = L(e.claimTxHex, `${e.path}.claim_tx`), o = L(e.assertTxHex, `${e.path}.assert_tx`);
1621
1621
  return { peginTx: t, claimTx: r, assertTx: o };
1622
1622
  }
1623
- function ss(e) {
1624
- const t = D(e.claimTxHex, `${e.path}.claim_tx`), r = D(e.assertTxHex, `${e.path}.assert_tx`);
1625
- Ft(t, e.path), Oe(r, t.getId(), e.path);
1626
- }
1627
1623
  function ns(e) {
1628
- const { peginTx: t, claimTx: r, assertTx: o } = qt(e);
1629
- os(r, t.getId(), e.path), Oe(o, r.getId(), e.path);
1624
+ const t = L(e.claimTxHex, `${e.path}.claim_tx`), r = L(e.assertTxHex, `${e.path}.assert_tx`);
1625
+ qt(t, e.path), Oe(r, t.getId(), e.path);
1626
+ }
1627
+ function is(e) {
1628
+ const { peginTx: t, claimTx: r, assertTx: o } = Gt(e);
1629
+ ss(r, t.getId(), e.path), Oe(o, r.getId(), e.path);
1630
1630
  }
1631
- function is(e, t) {
1631
+ function as(e, t) {
1632
1632
  const [r, ...o] = e.ins;
1633
1633
  if (!r || o.length > 0)
1634
- throw new b(
1634
+ throw new w(
1635
1635
  `Presign claim_tx must have exactly one input, got ${e.ins.length}`
1636
1636
  );
1637
- const s = H.from(r.hash).reverse().toString("hex");
1638
- if (s !== t || r.index !== X)
1639
- throw new b(
1640
- `Presign claim_tx must spend ${t}:${X}, got ${s}:${r.index}`
1637
+ const s = O.from(r.hash).reverse().toString("hex");
1638
+ if (s !== t || r.index !== z)
1639
+ throw new w(
1640
+ `Presign claim_tx must spend ${t}:${z}, got ${s}:${r.index}`
1641
1641
  );
1642
1642
  if (e.version !== tt)
1643
- throw new b(
1643
+ throw new w(
1644
1644
  `Presign claim_tx version must be ${tt}, got ${e.version}`
1645
1645
  );
1646
1646
  if (r.witness.length > 0)
1647
- throw new b(
1647
+ throw new w(
1648
1648
  `Presign claim_tx input must have an empty witness, got ${r.witness.length} item(s)`
1649
1649
  );
1650
1650
  if (e.outs.length !== rt)
1651
- throw new b(
1651
+ throw new w(
1652
1652
  `Presign claim_tx must have exactly ${rt} outputs, got ${e.outs.length}`
1653
1653
  );
1654
1654
  }
1655
- function Gt(e) {
1655
+ function Xt(e) {
1656
1656
  const t = [...e.challengers].sort(
1657
1657
  (o, s) => o.pubkey < s.pubkey ? -1 : o.pubkey > s.pubkey ? 1 : 0
1658
1658
  ), r = [e.peginTx, e.claimTx, e.assertTx, e.payoutTx];
1659
1659
  return t.forEach((o, s) => {
1660
- const n = de(o.pubkey, "challenger pubkey");
1660
+ const n = pe(o.pubkey, "challenger pubkey");
1661
1661
  if (s > 0 && t[s - 1].pubkey === n)
1662
- throw new b(`Graph lists challenger ${n} twice`);
1662
+ throw new w(`Graph lists challenger ${n} twice`);
1663
1663
  r.push(We(n), o.nopayoutTx);
1664
1664
  for (const a of o.outputLabelHashes)
1665
- r.push(We(de(a, "output_label_hashes entry")));
1666
- }), qr(Gr(Xr(...r)));
1665
+ r.push(We(pe(a, "output_label_hashes entry")));
1666
+ }), Gr(Xr(zr(...r)));
1667
1667
  }
1668
- function as(e) {
1669
- const t = P(e.peginTxid).toLowerCase(), { peginTx: r, claimTx: o, assertTx: s } = qt({
1668
+ function us(e) {
1669
+ const t = P(e.peginTxid).toLowerCase(), { peginTx: r, claimTx: o, assertTx: s } = Gt({
1670
1670
  peginTxHex: e.peginTxHex,
1671
1671
  claimTxHex: e.claimTxHex,
1672
1672
  assertTxHex: e.assertTxHex,
1673
1673
  path: "depositor_graph"
1674
1674
  });
1675
1675
  if (r.getId() !== t)
1676
- throw new b(
1676
+ throw new w(
1677
1677
  `Presign pegin_tx hashes to ${r.getId()}, expected ${t}`
1678
1678
  );
1679
- is(o, t), Oe(s, o.getId(), "depositor_graph");
1679
+ as(o, t), Oe(s, o.getId(), "depositor_graph");
1680
1680
  const n = (a) => new Uint8Array(a.toBuffer());
1681
- return Gt({
1681
+ return Xt({
1682
1682
  peginTx: n(r),
1683
1683
  claimTx: n(o),
1684
1684
  assertTx: n(s),
1685
- payoutTx: n(D(e.payoutTxHex, "payout_tx")),
1685
+ payoutTx: n(L(e.payoutTxHex, "payout_tx")),
1686
1686
  challengers: e.challengers.map((a) => ({
1687
1687
  pubkey: _(a.challenger_pubkey),
1688
- nopayoutTx: n(D(a.nopayout_tx.tx_hex, "nopayout_tx")),
1688
+ nopayoutTx: n(L(a.nopayout_tx.tx_hex, "nopayout_tx")),
1689
1689
  outputLabelHashes: a.output_label_hashes.map(
1690
1690
  (i) => P(i).toLowerCase()
1691
1691
  )
1692
1692
  }))
1693
1693
  });
1694
1694
  }
1695
- function us(e) {
1696
- const t = (o) => ot(B(k(e, o, "graph"), o).tx, o), r = B(
1697
- k(e, "challenger_subgraphs", "graph"),
1695
+ function cs(e) {
1696
+ const t = (o) => ot(I($(e, o, "graph"), o).tx, o), r = I(
1697
+ $(e, "challenger_subgraphs", "graph"),
1698
1698
  "challenger_subgraphs"
1699
1699
  );
1700
- return Gt({
1700
+ return Xt({
1701
1701
  peginTx: t("pegin_tx"),
1702
1702
  claimTx: t("claim_tx"),
1703
1703
  assertTx: t("assert_tx"),
1704
1704
  payoutTx: t("payout_tx"),
1705
1705
  challengers: Object.entries(r).map(([o, s]) => {
1706
- const n = `challenger_subgraphs[${o}]`, a = B(s, n);
1706
+ const n = `challenger_subgraphs[${o}]`, a = I(s, n);
1707
1707
  return {
1708
1708
  pubkey: o,
1709
1709
  nopayoutTx: ot(
1710
- B(k(a, "nopayout_tx", n), `${n}.nopayout_tx`).tx,
1710
+ I($(a, "nopayout_tx", n), `${n}.nopayout_tx`).tx,
1711
1711
  `${n}.nopayout_tx`
1712
1712
  ),
1713
1713
  outputLabelHashes: te(
1714
- k(a, "output_label_hashes", n),
1714
+ $(a, "output_label_hashes", n),
1715
1715
  `${n}.output_label_hashes`
1716
1716
  ).map(
1717
- (i, u) => de(i, `${n}.output_label_hashes[${u}]`)
1717
+ (i, u) => pe(i, `${n}.output_label_hashes[${u}]`)
1718
1718
  )
1719
1719
  };
1720
1720
  })
1721
1721
  });
1722
1722
  }
1723
- function cs(e) {
1724
- const t = B(
1725
- k(e, "challenger_pubkeys", "graph"),
1723
+ function ls(e) {
1724
+ const t = I(
1725
+ $(e, "challenger_pubkeys", "graph"),
1726
1726
  "challenger_pubkeys"
1727
1727
  ), r = /* @__PURE__ */ new Set();
1728
1728
  for (const o of ["local", "universal"])
1729
1729
  te(
1730
- k(t, o, "challenger_pubkeys"),
1730
+ $(t, o, "challenger_pubkeys"),
1731
1731
  `challenger_pubkeys.${o}`
1732
1732
  ).forEach((s, n) => {
1733
- const a = de(s, `challenger_pubkeys.${o}[${n}]`);
1733
+ const a = pe(s, `challenger_pubkeys.${o}[${n}]`);
1734
1734
  if (r.has(a))
1735
- throw new b(
1735
+ throw new w(
1736
1736
  `Graph declares challenger ${a} more than once`
1737
1737
  );
1738
1738
  r.add(a);
1739
1739
  });
1740
1740
  return r;
1741
1741
  }
1742
- function Pn(e, t) {
1743
- const r = us(e);
1742
+ function wn(e, t) {
1743
+ const r = cs(e);
1744
1744
  if (r !== t)
1745
- throw new b(
1745
+ throw new w(
1746
1746
  `Graph fingerprint ${r} does not match the presign fingerprint ${t}`
1747
1747
  );
1748
1748
  const o = Object.keys(
1749
- B(e.challenger_subgraphs, "challenger_subgraphs")
1750
- ), s = cs(e);
1749
+ I(e.challenger_subgraphs, "challenger_subgraphs")
1750
+ ), s = ls(e);
1751
1751
  if (o.length !== s.size || o.some((n) => !s.has(n)))
1752
- throw new b(
1752
+ throw new w(
1753
1753
  `Graph challenger_subgraphs keys ${o.join(", ")} do not match challenger_pubkeys ${[...s].join(", ")}`
1754
1754
  );
1755
1755
  }
1756
- const ls = 1;
1756
+ const ds = 1;
1757
1757
  function ps(e, t, r) {
1758
1758
  const o = r.map(
1759
- (d) => P(d).toLowerCase()
1760
- ), s = t.filter((d) => o.includes(d));
1759
+ (p) => P(p).toLowerCase()
1760
+ ), s = t.filter((p) => o.includes(p));
1761
1761
  if (s.length > 0)
1762
1762
  throw new Error(
1763
1763
  `Cannot validate challenger set: vault keepers and universal challengers overlap (${s.join(", ")})`
1764
1764
  );
1765
1765
  const n = [...t, ...o], a = e.map(
1766
- (d) => P(d.challenger_pubkey).toLowerCase()
1766
+ (p) => P(p.challenger_pubkey).toLowerCase()
1767
1767
  ), i = new Set(a);
1768
1768
  if (i.size !== a.length)
1769
1769
  throw new Error(
1770
1770
  "Depositor graph contains duplicate challenger entries in challenger_presign_data"
1771
1771
  );
1772
- const u = new Set(n), l = n.filter((d) => !i.has(d)), c = a.filter((d) => !u.has(d));
1772
+ const u = new Set(n), l = n.filter((p) => !i.has(p)), c = a.filter((p) => !u.has(p));
1773
1773
  if (l.length > 0 || c.length > 0)
1774
1774
  throw new Error(
1775
1775
  "Depositor graph challenger set does not match expected (local ∪ universal)" + (l.length > 0 ? ` (missing: ${l.join(", ")})` : "") + (c.length > 0 ? ` (unexpected: ${c.join(", ")})` : "")
1776
1776
  );
1777
- return nr(n);
1777
+ return ir(n);
1778
1778
  }
1779
- function ds(e, t) {
1780
- const r = Ar + Br * t + Ir;
1779
+ function hs(e, t) {
1780
+ const r = Br + Ir * t + Vr;
1781
1781
  if (e.outs.length !== r)
1782
1782
  throw new Error(
1783
1783
  `Assert must have ${r} outputs for ${t} challengers, got ${e.outs.length}`
1784
1784
  );
1785
1785
  }
1786
- async function Xt(e, t) {
1787
- const r = wt({
1786
+ async function zt(e, t) {
1787
+ const r = xt({
1788
1788
  claimerBtcPubkey: t.depositorBtcPubkey,
1789
1789
  depositorBtcPubkey: t.depositorBtcPubkey,
1790
1790
  vaultProviderBtcPubkey: t.vaultProviderBtcPubkey,
@@ -1796,12 +1796,12 @@ async function Xt(e, t) {
1796
1796
  ), s = P(t.depositorBtcPubkey), n = S.fromHex(
1797
1797
  P(e.assert_tx.tx_hex)
1798
1798
  );
1799
- ds(n, o.length);
1799
+ hs(n, o.length);
1800
1800
  const a = [];
1801
1801
  for (const i of e.challenger_presign_data) {
1802
1802
  const u = P(i.challenger_pubkey), l = o.indexOf(
1803
1803
  u.toLowerCase()
1804
- ), c = await hs({
1804
+ ), c = await gs({
1805
1805
  challenger: i,
1806
1806
  challengerPubkey: u,
1807
1807
  challengerIndex: l,
@@ -1814,7 +1814,7 @@ async function Xt(e, t) {
1814
1814
  }
1815
1815
  return { localChallengers: r, noPayouts: a };
1816
1816
  }
1817
- async function hs(e) {
1817
+ async function gs(e) {
1818
1818
  const {
1819
1819
  challenger: t,
1820
1820
  challengerPubkey: r,
@@ -1824,7 +1824,7 @@ async function hs(e) {
1824
1824
  assertTx: a,
1825
1825
  ctx: i
1826
1826
  } = e;
1827
- jr(
1827
+ Wr(
1828
1828
  t.nopayout_tx.tx_hex,
1829
1829
  r,
1830
1830
  i.network
@@ -1835,7 +1835,7 @@ async function hs(e) {
1835
1835
  P(t.challenge_assert_x_tx.tx_hex)
1836
1836
  ), c = S.fromHex(
1837
1837
  P(t.challenge_assert_y_tx.tx_hex)
1838
- ), d = await br({
1838
+ ), p = await wr({
1839
1839
  txGraphVersion: i.vaultCoreVersion,
1840
1840
  claimer: n,
1841
1841
  challenger: r,
@@ -1849,38 +1849,38 @@ async function hs(e) {
1849
1849
  ["X", l],
1850
1850
  ["Y", c]
1851
1851
  ])
1852
- Wr({
1852
+ Yr({
1853
1853
  challengeAssertTx: h,
1854
1854
  assertTx: a,
1855
1855
  half: g,
1856
1856
  challengerIndex: o,
1857
1857
  challengerCount: s,
1858
1858
  challengerPubkey: r,
1859
- outputConnectorScriptPubKey: d
1859
+ outputConnectorScriptPubKey: p
1860
1860
  });
1861
- const p = [
1862
- a.outs[G],
1861
+ const d = [
1862
+ a.outs[X],
1863
1863
  l.outs[Xe],
1864
1864
  c.outs[Xe]
1865
1865
  ];
1866
- return Yr({
1866
+ return Qr({
1867
1867
  noPayoutTx: u,
1868
1868
  assertTxid: a.getId(),
1869
1869
  challengeAssertXTxid: l.getId(),
1870
1870
  challengeAssertYTxid: c.getId(),
1871
1871
  timelockChallengeAssert: i.timelockChallengeAssert,
1872
1872
  prevoutValues: [
1873
- p[0].value,
1874
- p[1].value,
1875
- p[2].value
1873
+ d[0].value,
1874
+ d[1].value,
1875
+ d[2].value
1876
1876
  ]
1877
- }), p.map((g) => ({
1878
- script_pubkey: yt(new Uint8Array(g.script)),
1877
+ }), d.map((g) => ({
1878
+ script_pubkey: vt(new Uint8Array(g.script)),
1879
1879
  value: g.value
1880
1880
  }));
1881
1881
  }
1882
- async function gs(e, t, r) {
1883
- const o = [], s = [], n = [], { localChallengers: a, noPayouts: i } = await Xt(e, r), u = await Kr({
1882
+ async function fs(e, t, r) {
1883
+ const o = [], s = [], n = [], { localChallengers: a, noPayouts: i } = await zt(e, r), u = await Hr({
1884
1884
  vaultCoreVersion: r.vaultCoreVersion,
1885
1885
  vkClaimerPayoutScriptPubKeys: r.vkClaimerPayoutScriptPubKeys,
1886
1886
  vpCommissionScriptPubKey: r.vpCommissionScriptPubKey,
@@ -1896,7 +1896,7 @@ async function gs(e, t, r) {
1896
1896
  network: r.network,
1897
1897
  claimerBtcPubkey: r.depositorBtcPubkey,
1898
1898
  registeredPayoutScriptPubKey: r.registeredPayoutScriptPubKey,
1899
- commissionBps: ls,
1899
+ commissionBps: ds,
1900
1900
  protocolFeeRate: r.protocolFeeRate,
1901
1901
  councilMembers: r.councilMembers,
1902
1902
  councilQuorum: r.councilQuorum
@@ -1908,11 +1908,11 @@ async function gs(e, t, r) {
1908
1908
  )
1909
1909
  );
1910
1910
  const l = P(r.depositorBtcPubkey);
1911
- for (const { challenger: c, challengerPubkey: d, prevouts: p } of i) {
1912
- const g = o.length, h = await zr({
1911
+ for (const { challenger: c, challengerPubkey: p, prevouts: d } of i) {
1912
+ const g = o.length, h = await jr({
1913
1913
  noPayoutTxHex: c.nopayout_tx.tx_hex,
1914
- challengerPubkey: d,
1915
- prevouts: p,
1914
+ challengerPubkey: p,
1915
+ prevouts: d,
1916
1916
  connectorParams: {
1917
1917
  txGraphVersion: r.vaultCoreVersion,
1918
1918
  claimer: l,
@@ -1929,13 +1929,13 @@ async function gs(e, t, r) {
1929
1929
  Ge
1930
1930
  )
1931
1931
  ), n.push({
1932
- challengerPubkey: d,
1932
+ challengerPubkey: p,
1933
1933
  noPayoutIdx: g
1934
1934
  });
1935
1935
  }
1936
1936
  return { psbtHexes: o, signOptions: s, challengerEntries: n };
1937
1937
  }
1938
- function fs(e, t, r) {
1938
+ function ys(e, t, r) {
1939
1939
  ae(e[0]);
1940
1940
  const s = ue(
1941
1941
  e[0].returnedPsbtHex,
@@ -1970,54 +1970,54 @@ function fs(e, t, r) {
1970
1970
  per_challenger: n
1971
1971
  };
1972
1972
  }
1973
- async function ys(e) {
1973
+ async function vs(e) {
1974
1974
  const { depositorGraph: t, btcWallet: r, signingContext: o } = e;
1975
- ns({
1975
+ is({
1976
1976
  peginTxHex: o.peginTxHex,
1977
1977
  claimTxHex: t.claim_tx.tx_hex,
1978
1978
  assertTxHex: t.assert_tx.tx_hex,
1979
1979
  path: "depositor_graph"
1980
1980
  });
1981
- const s = await r.getPublicKeyHex(), { depositorPubkey: n } = sr(
1981
+ const s = await r.getPublicKeyHex(), { depositorPubkey: n } = nr(
1982
1982
  s,
1983
1983
  P(o.depositorBtcPubkey)
1984
- ), { psbtHexes: a, signOptions: i, challengerEntries: u } = await gs(
1984
+ ), { psbtHexes: a, signOptions: i, challengerEntries: u } = await fs(
1985
1985
  t,
1986
1986
  s,
1987
1987
  o
1988
- ), l = await Pt(
1988
+ ), l = await mt(
1989
1989
  r,
1990
1990
  a,
1991
1991
  i
1992
- ), c = a.map((d, p) => ({
1993
- requestedPsbtHex: d,
1994
- returnedPsbtHex: l[p]
1992
+ ), c = a.map((p, d) => ({
1993
+ requestedPsbtHex: p,
1994
+ returnedPsbtHex: l[d]
1995
1995
  }));
1996
- return fs(
1996
+ return ys(
1997
1997
  c,
1998
1998
  u,
1999
1999
  n
2000
2000
  );
2001
2001
  }
2002
- const vs = 1e4, M = 10;
2003
- async function zt(e) {
2002
+ const Ps = 1e4, U = 10;
2003
+ async function jt(e) {
2004
2004
  const {
2005
2005
  statusReader: t,
2006
2006
  vaultId: r,
2007
2007
  peginTxid: o,
2008
2008
  targetStatuses: s,
2009
2009
  timeoutMs: n,
2010
- pollIntervalMs: a = vs,
2010
+ pollIntervalMs: a = Ps,
2011
2011
  signal: i
2012
2012
  } = e, u = Date.now();
2013
2013
  for (; ; ) {
2014
2014
  if (i != null && i.aborted)
2015
2015
  throw new Error(
2016
- `Polling aborted for vault ${r.slice(0, M)}… (target: ${[...s].join(", ")})`
2016
+ `Polling aborted for vault ${r.slice(0, U)}… (target: ${[...s].join(", ")})`
2017
2017
  );
2018
2018
  if (Date.now() - u >= n)
2019
2019
  throw new Error(
2020
- `Polling timeout after ${n}ms for vault ${r.slice(0, M)}… (target: ${[...s].join(", ")})`
2020
+ `Polling timeout after ${n}ms for vault ${r.slice(0, U)}… (target: ${[...s].join(", ")})`
2021
2021
  );
2022
2022
  try {
2023
2023
  const l = await t.getPeginStatusByVaultId(
@@ -2026,57 +2026,57 @@ async function zt(e) {
2026
2026
  );
2027
2027
  if (je(l.vault_id) !== je(r))
2028
2028
  throw new Error(
2029
- `getPeginStatusByVaultId returned status for vault ${l.vault_id.slice(0, M)}…, requested ${r.slice(0, M)}…`
2029
+ `getPeginStatusByVaultId returned status for vault ${l.vault_id.slice(0, U)}…, requested ${r.slice(0, U)}…`
2030
2030
  );
2031
2031
  if (l.pegin_txid.toLowerCase() !== o.toLowerCase())
2032
2032
  throw new Error(
2033
2033
  `getPeginStatusByVaultId returned status for pegin ${l.pegin_txid.slice(0, 8)}…, requested ${o.slice(0, 8)}…`
2034
2034
  );
2035
2035
  const c = l.status;
2036
- if (s.has(c) || c === R.ACTIVATED)
2036
+ if (s.has(c) || c === K.ACTIVATED)
2037
2037
  return c;
2038
- if (c === R.EXPIRED || Mr.has(c))
2038
+ if (c === K.EXPIRED || Ur.has(c))
2039
2039
  throw new Error(
2040
- `Vault ${r.slice(0, M)}… reached terminal status "${c}" while waiting for ${[...s].join(", ")}`
2040
+ `Vault ${r.slice(0, U)}… reached terminal status "${c}" while waiting for ${[...s].join(", ")}`
2041
2041
  );
2042
2042
  } catch (l) {
2043
- if (!(l instanceof Ur && l.code === Fr.PEGIN_NOT_FOUND))
2043
+ if (!(l instanceof Fr && l.code === qr.PEGIN_NOT_FOUND))
2044
2044
  throw l;
2045
2045
  }
2046
2046
  await new Promise((l, c) => {
2047
- const d = () => {
2048
- clearTimeout(p), c(
2047
+ const p = () => {
2048
+ clearTimeout(d), c(
2049
2049
  new Error(
2050
- `Polling aborted for vault ${r.slice(0, M)}… (target: ${[...s].join(", ")})`
2050
+ `Polling aborted for vault ${r.slice(0, U)}… (target: ${[...s].join(", ")})`
2051
2051
  )
2052
2052
  );
2053
- }, p = setTimeout(() => {
2054
- i == null || i.removeEventListener("abort", d), l();
2053
+ }, d = setTimeout(() => {
2054
+ i == null || i.removeEventListener("abort", p), l();
2055
2055
  }, a);
2056
- i == null || i.addEventListener("abort", d, { once: !0 });
2056
+ i == null || i.addEventListener("abort", p, { once: !0 });
2057
2057
  });
2058
2058
  }
2059
2059
  }
2060
- const Ps = 1200 * 1e3, jt = /* @__PURE__ */ new Set([
2061
- R.PENDING_ACKS,
2062
- R.PENDING_ACTIVATION,
2063
- R.ACTIVATED_PENDING_BROADCAST,
2064
- R.ACTIVATED
2065
- ]), ms = /* @__PURE__ */ new Set([
2066
- R.PENDING_DEPOSITOR_SIGNATURES,
2067
- ...jt
2060
+ const ms = 1200 * 1e3, Wt = /* @__PURE__ */ new Set([
2061
+ K.PENDING_ACKS,
2062
+ K.PENDING_ACTIVATION,
2063
+ K.ACTIVATED_PENDING_BROADCAST,
2064
+ K.ACTIVATED
2065
+ ]), bs = /* @__PURE__ */ new Set([
2066
+ K.PENDING_DEPOSITOR_SIGNATURES,
2067
+ ...Wt
2068
2068
  ]);
2069
- function bs(e) {
2069
+ function ws(e) {
2070
2070
  return e.map((t) => ({
2071
2071
  claimerPubkeyXOnly: he(t.claimer_pubkey),
2072
2072
  payoutTxHex: t.payout_tx.tx_hex,
2073
2073
  assertTxHex: t.assert_tx.tx_hex
2074
2074
  }));
2075
2075
  }
2076
- function I(e) {
2076
+ function V(e) {
2077
2077
  return he(e).toLowerCase();
2078
2078
  }
2079
- function ws(e, t) {
2079
+ function xs(e, t) {
2080
2080
  const r = (u, l, c) => {
2081
2081
  throw new Error(
2082
2082
  `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.`
@@ -2089,9 +2089,9 @@ function ws(e, t) {
2089
2089
  ];
2090
2090
  for (const [u, l, c] of o)
2091
2091
  l !== c && r(u, l, c);
2092
- const s = (u) => u.map(I).sort(), n = (u, l) => {
2093
- const c = s(u), d = s(l);
2094
- return c.length === d.length && c.every((p, g) => p === d[g]);
2092
+ const s = (u) => u.map(V).sort(), n = (u, l) => {
2093
+ const c = s(u), p = s(l);
2094
+ return c.length === p.length && c.every((d, g) => d === p[g]);
2095
2095
  };
2096
2096
  n(e.vaultKeeperBtcPubkeys, t.vaultKeeperBtcPubkeys) || r(
2097
2097
  "vaultKeeperBtcPubkeys",
@@ -2105,8 +2105,8 @@ function ws(e, t) {
2105
2105
  e.universalChallengerBtcPubkeys.join(","),
2106
2106
  t.universalChallengerBtcPubkeys.join(",")
2107
2107
  );
2108
- const a = I(t.vaultProviderBtcPubkey), i = e.vaults.map(
2109
- (u) => I(u.vaultProviderBtcPubkey)
2108
+ const a = V(t.vaultProviderBtcPubkey), i = e.vaults.map(
2109
+ (u) => V(u.vaultProviderBtcPubkey)
2110
2110
  );
2111
2111
  i.includes(a) || r(
2112
2112
  "vaults[].vaultProviderBtcPubkey",
@@ -2114,10 +2114,10 @@ function ws(e, t) {
2114
2114
  t.vaultProviderBtcPubkey
2115
2115
  );
2116
2116
  }
2117
- function xs(e, t, r, o) {
2118
- const s = I(o), n = [
2119
- I(t),
2120
- ...r.map(I)
2117
+ function Es(e, t, r, o) {
2118
+ const s = V(o), n = [
2119
+ V(t),
2120
+ ...r.map(V)
2121
2121
  ], a = new Set(n);
2122
2122
  if (a.size !== n.length)
2123
2123
  throw new Error(
@@ -2128,14 +2128,14 @@ function xs(e, t, r, o) {
2128
2128
  "Cannot validate claimer set: depositor key overlaps with vault provider or vault keeper set"
2129
2129
  );
2130
2130
  const i = e.map(
2131
- (p) => I(p.claimer_pubkey)
2131
+ (d) => V(d.claimer_pubkey)
2132
2132
  );
2133
2133
  if (new Set(i).size !== i.length)
2134
2134
  throw new Error("Presign response contains duplicate claimer entries");
2135
- const u = i.filter((p) => p !== s), l = new Set(u), c = n.filter((p) => !l.has(p)), d = u.filter((p) => !a.has(p));
2136
- if (c.length > 0 || d.length > 0)
2135
+ const u = i.filter((d) => d !== s), l = new Set(u), c = n.filter((d) => !l.has(d)), p = u.filter((d) => !a.has(d));
2136
+ if (c.length > 0 || p.length > 0)
2137
2137
  throw new Error(
2138
- "Presign response claimer set does not match expected (vault provider ∪ vault keepers)" + (c.length > 0 ? ` (missing: ${c.join(", ")})` : "") + (d.length > 0 ? ` (unexpected: ${d.join(", ")})` : "")
2138
+ "Presign response claimer set does not match expected (vault provider ∪ vault keepers)" + (c.length > 0 ? ` (missing: ${c.join(", ")})` : "") + (p.length > 0 ? ` (unexpected: ${p.join(", ")})` : "")
2139
2139
  );
2140
2140
  }
2141
2141
  function st(e, t) {
@@ -2160,8 +2160,8 @@ function st(e, t) {
2160
2160
  vpCommissionScriptPubKey: t.vpCommissionScriptPubKey
2161
2161
  };
2162
2162
  }
2163
- async function Es(e, t, r, o) {
2164
- const s = new ar({
2163
+ async function $s(e, t, r, o) {
2164
+ const s = new ur({
2165
2165
  network: t.network,
2166
2166
  btcWallet: e
2167
2167
  }), n = r.length;
@@ -2188,7 +2188,7 @@ async function Es(e, t, r, o) {
2188
2188
  };
2189
2189
  return o == null || o(n, n), i;
2190
2190
  }
2191
- async function mn(e) {
2191
+ async function xn(e) {
2192
2192
  const {
2193
2193
  statusReader: t,
2194
2194
  presignClient: r,
@@ -2198,22 +2198,22 @@ async function mn(e) {
2198
2198
  depositorPk: a,
2199
2199
  signingContext: i,
2200
2200
  depositTerms: u,
2201
- timeoutMs: l = Ps,
2201
+ timeoutMs: l = ms,
2202
2202
  signal: c,
2203
- onProgress: d,
2204
- recordGraphFingerprint: p
2205
- } = e, g = await zt({
2203
+ onProgress: p,
2204
+ recordGraphFingerprint: d
2205
+ } = e, g = await jt({
2206
2206
  statusReader: t,
2207
2207
  vaultId: s,
2208
2208
  peginTxid: n,
2209
- targetStatuses: ms,
2209
+ targetStatuses: bs,
2210
2210
  timeoutMs: l,
2211
2211
  signal: c
2212
2212
  });
2213
- if (jt.has(g))
2213
+ if (Wt.has(g))
2214
2214
  return;
2215
- c == null || c.throwIfAborted(), u !== void 0 && ws(u, i);
2216
- const h = vt(o) ? o : void 0;
2215
+ c == null || c.throwIfAborted(), u !== void 0 && xs(u, i);
2216
+ const h = Pt(o) ? o : void 0;
2217
2217
  let y;
2218
2218
  if (h) {
2219
2219
  if (!u)
@@ -2229,21 +2229,21 @@ async function mn(e) {
2229
2229
  },
2230
2230
  c
2231
2231
  );
2232
- c == null || c.throwIfAborted(), f.txs.forEach((O, se) => {
2233
- ss({
2234
- claimTxHex: O.claim_tx.tx_hex,
2235
- assertTxHex: O.assert_tx.tx_hex,
2232
+ c == null || c.throwIfAborted(), f.txs.forEach((N, se) => {
2233
+ ns({
2234
+ claimTxHex: N.claim_tx.tx_hex,
2235
+ assertTxHex: N.assert_tx.tx_hex,
2236
2236
  path: `txs[${se}]`
2237
2237
  });
2238
2238
  });
2239
- const m = as({
2239
+ const b = us({
2240
2240
  peginTxid: n,
2241
2241
  peginTxHex: i.peginTxHex,
2242
2242
  claimTxHex: f.depositor_graph.claim_tx.tx_hex,
2243
2243
  assertTxHex: f.depositor_graph.assert_tx.tx_hex,
2244
2244
  payoutTxHex: f.depositor_graph.payout_tx.tx_hex,
2245
2245
  challengers: f.depositor_graph.challenger_presign_data
2246
- }), $ = {
2246
+ }), k = {
2247
2247
  vaultCoreVersion: i.vaultCoreVersion,
2248
2248
  peginTxHex: i.peginTxHex,
2249
2249
  depositorBtcPubkey: a,
@@ -2261,50 +2261,50 @@ async function mn(e) {
2261
2261
  vkClaimerPayoutScriptPubKeys: i.vkClaimerPayoutScriptPubKeys,
2262
2262
  vpCommissionScriptPubKey: i.vpCommissionScriptPubKey
2263
2263
  };
2264
- await Xt(
2264
+ await zt(
2265
2265
  f.depositor_graph,
2266
- $
2266
+ k
2267
2267
  ), c == null || c.throwIfAborted();
2268
- const x = I(a);
2269
- xs(
2268
+ const x = V(a);
2269
+ Es(
2270
2270
  f.txs,
2271
2271
  i.vaultProviderBtcPubkey,
2272
2272
  i.vaultKeeperBtcPubkeys,
2273
2273
  a
2274
2274
  );
2275
2275
  const v = f.txs.filter(
2276
- (O) => I(O.claimer_pubkey) !== x
2277
- ), E = bs(v);
2276
+ (N) => V(N.claimer_pubkey) !== x
2277
+ ), E = ws(v);
2278
2278
  h && y && (typeof h.validateDepositTerms == "function" && await h.validateDepositTerms(y), await h.approveDepositTerms(y)), c == null || c.throwIfAborted();
2279
- const T = await Es(
2279
+ const C = await $s(
2280
2280
  o,
2281
2281
  i,
2282
2282
  E,
2283
- d
2283
+ p
2284
2284
  );
2285
2285
  c == null || c.throwIfAborted();
2286
- const w = await ys({
2286
+ const m = await vs({
2287
2287
  depositorGraph: f.depositor_graph,
2288
2288
  btcWallet: o,
2289
- signingContext: $
2289
+ signingContext: k
2290
2290
  });
2291
- c == null || c.throwIfAborted(), await p(m), c == null || c.throwIfAborted();
2292
- const j = { ...T };
2293
- j[P(a)] = w.payout_signatures, await r.submitDepositorPresignatures(
2291
+ c == null || c.throwIfAborted(), await d(b), c == null || c.throwIfAborted();
2292
+ const W = { ...C };
2293
+ W[P(a)] = m.payout_signatures, await r.submitDepositorPresignatures(
2294
2294
  {
2295
2295
  pegin_txid: n,
2296
2296
  depositor_pk: a,
2297
- signatures: j,
2298
- depositor_claimer_presignatures: w
2297
+ signatures: W,
2298
+ depositor_claimer_presignatures: m
2299
2299
  },
2300
2300
  c
2301
2301
  );
2302
2302
  }
2303
- const ks = 300 * 1e3, $s = /* @__PURE__ */ new Set([
2304
- R.PENDING_DEPOSITOR_WOTS_PK,
2305
- ...Ct
2303
+ const ks = 300 * 1e3, Cs = /* @__PURE__ */ new Set([
2304
+ K.PENDING_DEPOSITOR_WOTS_PK,
2305
+ ...Tt
2306
2306
  ]);
2307
- async function bn(e) {
2307
+ async function En(e) {
2308
2308
  const {
2309
2309
  statusReader: t,
2310
2310
  wotsSubmitter: r,
@@ -2316,15 +2316,15 @@ async function bn(e) {
2316
2316
  signal: u
2317
2317
  } = e;
2318
2318
  u == null || u.throwIfAborted();
2319
- const l = await zt({
2319
+ const l = await jt({
2320
2320
  statusReader: t,
2321
2321
  vaultId: o,
2322
2322
  peginTxid: s,
2323
- targetStatuses: $s,
2323
+ targetStatuses: Cs,
2324
2324
  timeoutMs: i,
2325
2325
  signal: u
2326
2326
  });
2327
- Ct.has(l) || (u == null || u.throwIfAborted(), await r.submitDepositorWotsKey(
2327
+ Tt.has(l) || (u == null || u.throwIfAborted(), await r.submitDepositorWotsKey(
2328
2328
  {
2329
2329
  pegin_txid: s,
2330
2330
  depositor_pk: n,
@@ -2333,10 +2333,10 @@ async function bn(e) {
2333
2333
  u
2334
2334
  ));
2335
2335
  }
2336
- function $e(e) {
2336
+ function ke(e) {
2337
2337
  return e.registration || e.operation;
2338
2338
  }
2339
- function Cs(e, t, r) {
2339
+ function Ts(e, t, r) {
2340
2340
  const o = _(e);
2341
2341
  return {
2342
2342
  registration: o === _(t),
@@ -2356,7 +2356,7 @@ function Ce(e) {
2356
2356
  function it(e, t) {
2357
2357
  return e.length === t.length && e.every((r, o) => r === t[o]);
2358
2358
  }
2359
- async function wn(e) {
2359
+ async function $n(e) {
2360
2360
  const {
2361
2361
  vaultProviderEthAddress: t,
2362
2362
  hintBtcPubkey: r,
@@ -2380,11 +2380,11 @@ class Se extends Error {
2380
2380
  super(t), this.name = "ApplicationEntryPointMismatchError";
2381
2381
  }
2382
2382
  }
2383
- function xn(e) {
2383
+ function kn(e) {
2384
2384
  return e instanceof Se || e instanceof Error && e.name === "ApplicationEntryPointMismatchError";
2385
2385
  }
2386
2386
  const at = (e) => e.map(_).sort();
2387
- async function En(e) {
2387
+ async function Cn(e) {
2388
2388
  const {
2389
2389
  vaultRegistryReader: t,
2390
2390
  vaultKeeperReader: r,
@@ -2396,8 +2396,8 @@ async function En(e) {
2396
2396
  expectedUniversalChallengerBtcPubkeys: u,
2397
2397
  operationKeyReader: l,
2398
2398
  onIndexerServingOperationKeys: c,
2399
- onIndexerHintsInconsistent: d,
2400
- blockNumber: p
2399
+ onIndexerHintsInconsistent: p,
2400
+ blockNumber: d
2401
2401
  } = e, [
2402
2402
  g,
2403
2403
  h,
@@ -2406,49 +2406,49 @@ async function En(e) {
2406
2406
  ] = await Promise.all([
2407
2407
  t.getVaultProviderApplication(
2408
2408
  s,
2409
- p
2409
+ d
2410
2410
  ),
2411
2411
  t.getVaultProviderGenesisBtcPubKey(
2412
2412
  s,
2413
- p
2413
+ d
2414
2414
  ),
2415
- o.getLatestUniversalChallengersVersion(p),
2416
- o.getCurrentUcKeyEpoch(p)
2415
+ o.getLatestUniversalChallengersVersion(d),
2416
+ o.getCurrentUcKeyEpoch(d)
2417
2417
  ]);
2418
- if (!Dr(n, { strict: !1 }))
2418
+ if (!Lr(n, { strict: !1 }))
2419
2419
  throw new Se(
2420
2420
  `The application entry point this deposit was prepared for is not a valid address: ${n}`
2421
2421
  );
2422
- if (!Lr(g, n))
2422
+ if (!Mr(g, n))
2423
2423
  throw new Se(
2424
2424
  `Vault provider ${s} is registered to application ${g}, but this deposit was prepared for ${n}. 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.`
2425
2425
  );
2426
- const [m, $] = await Promise.all(
2426
+ const [b, k] = await Promise.all(
2427
2427
  [
2428
2428
  r.getCurrentVaultKeepersVersion(
2429
2429
  g,
2430
- p
2430
+ d
2431
2431
  ),
2432
2432
  r.getCurrentAppKeeperKeyEpoch(
2433
2433
  g,
2434
- p
2434
+ d
2435
2435
  )
2436
2436
  ]
2437
2437
  ), [x, v] = await Promise.all([
2438
2438
  r.getVaultKeepersByVersion(
2439
2439
  g,
2440
- m,
2441
- p
2440
+ b,
2441
+ d
2442
2442
  ),
2443
2443
  o.getUniversalChallengersByVersion(
2444
2444
  y,
2445
- p
2445
+ d
2446
2446
  )
2447
2447
  ]), E = {
2448
2448
  vaultProvider: _(h),
2449
- vaultKeepers: at(x.map((C) => C.btcPubKey)),
2450
- universalChallengers: at(v.map((C) => C.btcPubKey))
2451
- }, T = await Xo({
2449
+ vaultKeepers: at(x.map((T) => T.btcPubKey)),
2450
+ universalChallengers: at(v.map((T) => T.btcPubKey))
2451
+ }, C = await zo({
2452
2452
  operationKeyReader: l,
2453
2453
  query: {
2454
2454
  vaultProviderEthAddress: s,
@@ -2457,61 +2457,61 @@ async function En(e) {
2457
2457
  vaultKeepers: x,
2458
2458
  universalChallengers: v
2459
2459
  },
2460
- blockNumber: p
2461
- }), w = {
2462
- vaultProvider: T.vaultProvider.operationBtcPubkey,
2463
- vaultKeepers: [...T.vaultKeeperOperationKeysSorted],
2460
+ blockNumber: d
2461
+ }), m = {
2462
+ vaultProvider: C.vaultProvider.operationBtcPubkey,
2463
+ vaultKeepers: [...C.vaultKeeperOperationKeysSorted],
2464
2464
  universalChallengers: [
2465
- ...T.universalChallengerOperationKeysSorted
2465
+ ...C.universalChallengerOperationKeysSorted
2466
2466
  ]
2467
- }, j = Cs(
2467
+ }, W = Ts(
2468
2468
  a,
2469
2469
  E.vaultProvider,
2470
- w.vaultProvider
2471
- ), O = nt(
2470
+ m.vaultProvider
2471
+ ), N = nt(
2472
2472
  i,
2473
2473
  E.vaultKeepers,
2474
- w.vaultKeepers
2474
+ m.vaultKeepers
2475
2475
  ), se = nt(
2476
2476
  u,
2477
2477
  E.universalChallengers,
2478
- w.universalChallengers
2478
+ m.universalChallengers
2479
2479
  );
2480
- if (!$e(j))
2480
+ if (!ke(W))
2481
2481
  throw new Error(
2482
2482
  `Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${s}. Refresh and try again.`
2483
2483
  );
2484
- if (!$e(O))
2484
+ if (!ke(N))
2485
2485
  throw new Error(
2486
- `Vault keeper BTC pubkeys (v${m}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
2486
+ `Vault keeper BTC pubkeys (v${b}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
2487
2487
  );
2488
- if (!$e(se))
2488
+ if (!ke(se))
2489
2489
  throw new Error(
2490
2490
  `Universal challenger BTC pubkeys (v${y}) indexer set does not match ProtocolParams on-chain set. Refresh and try again.`
2491
2491
  );
2492
- const Ne = [j, O, se], er = Ne.some((C) => C.registration && !C.operation), De = Ne.some((C) => C.operation && !C.registration);
2493
- if (er && De) {
2494
- const C = `Indexer participant hints are internally inconsistent for vault provider ${s}: some roles match the registration keys while others match the rotated operation keys.`;
2495
- throw d == null || d(C), new Error(`${C} Refresh and try again.`);
2492
+ const Ne = [W, N, se], tr = Ne.some((T) => T.registration && !T.operation), De = Ne.some((T) => T.operation && !T.registration);
2493
+ if (tr && De) {
2494
+ const T = `Indexer participant hints are internally inconsistent for vault provider ${s}: some roles match the registration keys while others match the rotated operation keys.`;
2495
+ throw p == null || p(T), new Error(`${T} Refresh and try again.`);
2496
2496
  }
2497
2497
  return De && (c == null || c(
2498
2498
  `Indexer is serving rotated operation keys for vault provider ${s}`
2499
2499
  )), {
2500
- vaultProviderBtcPubkeyXOnly: w.vaultProvider,
2501
- vaultKeeperBtcPubkeysSorted: w.vaultKeepers,
2502
- universalChallengerBtcPubkeysSorted: w.universalChallengers,
2503
- expectedAppVaultKeepersVersion: m,
2500
+ vaultProviderBtcPubkeyXOnly: m.vaultProvider,
2501
+ vaultKeeperBtcPubkeysSorted: m.vaultKeepers,
2502
+ universalChallengerBtcPubkeysSorted: m.universalChallengers,
2503
+ expectedAppVaultKeepersVersion: b,
2504
2504
  expectedUniversalChallengersVersion: y,
2505
- appKeeperKeyEpoch: $,
2505
+ appKeeperKeyEpoch: k,
2506
2506
  ucKeyEpoch: f,
2507
2507
  registrationKeys: E,
2508
- participantKeys: T
2508
+ participantKeys: C
2509
2509
  };
2510
2510
  }
2511
- function Ts(e) {
2511
+ function _s(e) {
2512
2512
  return /^[0-9a-fA-F]{64}$/.test(e);
2513
2513
  }
2514
- function kn(e) {
2514
+ function Tn(e) {
2515
2515
  const {
2516
2516
  amountSats: t,
2517
2517
  minDeposit: r,
@@ -2522,29 +2522,29 @@ function kn(e) {
2522
2522
  } = e;
2523
2523
  return !(t <= 0n || t < r || o && o > 0n && t > o || n == null || a == null || t + n + a > s);
2524
2524
  }
2525
- function $n(e, t, r) {
2525
+ function _n(e, t, r) {
2526
2526
  return e <= 0n ? {
2527
2527
  valid: !1,
2528
2528
  error: "Deposit amount must be greater than zero"
2529
2529
  } : e < t ? {
2530
2530
  valid: !1,
2531
- error: `Minimum deposit is ${N(t)} BTC`
2531
+ error: `Minimum deposit is ${D(t)} BTC`
2532
2532
  } : r && r > 0n && e > r ? {
2533
2533
  valid: !1,
2534
- error: `Maximum deposit is ${N(r)} BTC`
2534
+ error: `Maximum deposit is ${D(r)} BTC`
2535
2535
  } : { valid: !0 };
2536
2536
  }
2537
- function Cn(e) {
2537
+ function Sn(e) {
2538
2538
  const { amount: t, effectiveRemaining: r } = e;
2539
2539
  return r === null ? { valid: !0 } : r === 0n ? {
2540
2540
  valid: !1,
2541
2541
  error: "Supply cap reached — deposits temporarily paused"
2542
2542
  } : t > r ? {
2543
2543
  valid: !1,
2544
- error: `Vault size exceeds remaining capacity (${N(r)} BTC)`
2544
+ error: `Vault size exceeds remaining capacity (${D(r)} BTC)`
2545
2545
  } : { valid: !0 };
2546
2546
  }
2547
- function Tn(e, t) {
2547
+ function An(e, t) {
2548
2548
  if (!e || e.length === 0)
2549
2549
  return {
2550
2550
  valid: !1,
@@ -2560,7 +2560,7 @@ function Tn(e, t) {
2560
2560
  error: "Invalid vault provider selected"
2561
2561
  } : { valid: !0 };
2562
2562
  }
2563
- function _s(e, t, r) {
2563
+ function Ss(e, t, r) {
2564
2564
  if (!e || e.length === 0)
2565
2565
  return {
2566
2566
  valid: !1,
@@ -2576,40 +2576,40 @@ function _s(e, t, r) {
2576
2576
  if (t && s < t)
2577
2577
  return {
2578
2578
  valid: !1,
2579
- error: `Vault ${o + 1} amount ${N(s)} BTC is below minimum deposit ${N(t)} BTC`
2579
+ error: `Vault ${o + 1} amount ${D(s)} BTC is below minimum deposit ${D(t)} BTC`
2580
2580
  };
2581
2581
  if (r && s > r)
2582
2582
  return {
2583
2583
  valid: !1,
2584
- error: `Vault ${o + 1} amount ${N(s)} BTC exceeds maximum deposit ${N(r)} BTC`
2584
+ error: `Vault ${o + 1} amount ${D(s)} BTC exceeds maximum deposit ${D(r)} BTC`
2585
2585
  };
2586
2586
  }
2587
2587
  return { valid: !0 };
2588
2588
  }
2589
- function Ss(e) {
2589
+ function As(e) {
2590
2590
  const t = P(e);
2591
- return Ts(t) ? { valid: !0 } : {
2591
+ return _s(t) ? { valid: !0 } : {
2592
2592
  valid: !1,
2593
2593
  error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
2594
2594
  };
2595
2595
  }
2596
- function As(e) {
2596
+ function Bs(e) {
2597
2597
  if (!e || e.length === 0)
2598
2598
  throw new Error(
2599
2599
  "No vault keepers available. The system requires at least one vault keeper to create a deposit."
2600
2600
  );
2601
2601
  }
2602
- function Bs(e) {
2602
+ function Is(e) {
2603
2603
  if (!e || e.length === 0)
2604
2604
  throw new Error(
2605
2605
  "No universal challengers available. The system requires at least one universal challenger to create a deposit."
2606
2606
  );
2607
2607
  }
2608
- function Is(e) {
2608
+ function Vs(e) {
2609
2609
  if (e.length === 0)
2610
2610
  throw new Error("No spendable UTXOs available");
2611
2611
  }
2612
- function _n(e) {
2612
+ function Bn(e) {
2613
2613
  const {
2614
2614
  vaultAmounts: t,
2615
2615
  confirmedUTXOs: r,
@@ -2618,38 +2618,38 @@ function _n(e) {
2618
2618
  universalChallengerBtcPubkeys: n,
2619
2619
  minDeposit: a,
2620
2620
  maxDeposit: i
2621
- } = e, u = _s(
2621
+ } = e, u = Ss(
2622
2622
  t,
2623
2623
  a,
2624
2624
  i
2625
2625
  );
2626
2626
  if (!u.valid)
2627
2627
  throw new Error(u.error);
2628
- const l = Ss(o);
2628
+ const l = As(o);
2629
2629
  if (!l.valid)
2630
2630
  throw new Error(l.error);
2631
- As(s), Bs(n), Is(r);
2631
+ Bs(s), Is(n), Vs(r);
2632
2632
  }
2633
- class Wt extends Error {
2633
+ class Yt extends Error {
2634
2634
  constructor(t) {
2635
2635
  super(t), this.name = "ParticipantKeyDriftError";
2636
2636
  }
2637
2637
  }
2638
- function Sn(e) {
2639
- return e instanceof Wt || e instanceof Error && e.name === "ParticipantKeyDriftError";
2638
+ function In(e) {
2639
+ return e instanceof Yt || e instanceof Error && e.name === "ParticipantKeyDriftError";
2640
2640
  }
2641
- class Yt extends Error {
2641
+ class Qt extends Error {
2642
2642
  constructor(t) {
2643
2643
  super(t), this.name = "UnsupportedPayoutScriptError";
2644
2644
  }
2645
2645
  }
2646
- function An(e) {
2647
- return e instanceof Yt || e instanceof Error && e.name === "UnsupportedPayoutScriptError";
2646
+ function Vn(e) {
2647
+ return e instanceof Qt || e instanceof Error && e.name === "UnsupportedPayoutScriptError";
2648
2648
  }
2649
2649
  function ut(e, t, r) {
2650
2650
  return t.length === r.length && t.every((o, s) => o === r[s]) ? null : `${e} expected [${t.join(", ")}], got [${r.join(", ")}]`;
2651
2651
  }
2652
- async function Vs(e) {
2652
+ async function Rs(e) {
2653
2653
  const { operationKeyReader: t, query: r, epochs: o, vaultIds: s } = e, n = await t.getPayoutScriptsAtEpochs(
2654
2654
  r,
2655
2655
  o
@@ -2660,7 +2660,7 @@ async function Vs(e) {
2660
2660
  );
2661
2661
  const a = [], i = (u, l) => {
2662
2662
  try {
2663
- Hr(u, l);
2663
+ Or(u, l);
2664
2664
  } catch (c) {
2665
2665
  a.push(
2666
2666
  `vaults ${s.join(", ")}: ${c.message}`
@@ -2677,57 +2677,57 @@ async function Vs(e) {
2677
2677
  `Vault keeper ${l.ethAddress} payout script`
2678
2678
  );
2679
2679
  if (a.length > 0)
2680
- throw new Yt(
2680
+ throw new Qt(
2681
2681
  `Aborting Pre-PegIn broadcast: an operator payout script registered for this vault is not a standard output type this app can verify (${a.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
2682
2682
  );
2683
2683
  }
2684
- async function Bn(e) {
2684
+ async function Rn(e) {
2685
2685
  const { vaultRegistryReader: t, operationKeyReader: r, vaultIds: o, expected: s } = e, n = s.query;
2686
2686
  if (o.length === 0) return;
2687
2687
  const a = await t.getVaultKeyEpochsBatch(o), i = [];
2688
2688
  for (const [l, c] of a.entries()) {
2689
- const d = o[l];
2690
- let p;
2689
+ const p = o[l];
2690
+ let d;
2691
2691
  try {
2692
- p = await Nt({
2692
+ d = await Dt({
2693
2693
  operationKeyReader: r,
2694
2694
  query: n,
2695
2695
  epochs: c
2696
2696
  });
2697
2697
  } catch (y) {
2698
2698
  i.push(
2699
- `vault ${d}: could not resolve participants at frozen epochs (vp=${c.vpKeyEpoch}, keeper=${c.appKeeperKeyEpoch}, uc=${c.ucKeyEpoch}): ${y.message}`
2699
+ `vault ${p}: could not resolve participants at frozen epochs (vp=${c.vpKeyEpoch}, keeper=${c.appKeeperKeyEpoch}, uc=${c.ucKeyEpoch}): ${y.message}`
2700
2700
  );
2701
2701
  continue;
2702
2702
  }
2703
- p.vaultProvider.operationBtcPubkey !== s.vaultProvider.operationBtcPubkey && i.push(
2704
- `vault ${d}: vault provider key expected ${s.vaultProvider.operationBtcPubkey}, got ${p.vaultProvider.operationBtcPubkey}`
2703
+ d.vaultProvider.operationBtcPubkey !== s.vaultProvider.operationBtcPubkey && i.push(
2704
+ `vault ${p}: vault provider key expected ${s.vaultProvider.operationBtcPubkey}, got ${d.vaultProvider.operationBtcPubkey}`
2705
2705
  );
2706
2706
  const g = ut(
2707
- `vault ${d}: vault keeper keys`,
2707
+ `vault ${p}: vault keeper keys`,
2708
2708
  s.vaultKeeperOperationKeysSorted,
2709
- p.vaultKeeperOperationKeysSorted
2709
+ d.vaultKeeperOperationKeysSorted
2710
2710
  );
2711
2711
  g && i.push(g);
2712
2712
  const h = ut(
2713
- `vault ${d}: universal challenger keys`,
2713
+ `vault ${p}: universal challenger keys`,
2714
2714
  s.universalChallengerOperationKeysSorted,
2715
- p.universalChallengerOperationKeysSorted
2715
+ d.universalChallengerOperationKeysSorted
2716
2716
  );
2717
2717
  h && i.push(h);
2718
2718
  }
2719
2719
  if (i.length > 0)
2720
- throw new Wt(
2720
+ throw new Yt(
2721
2721
  `Aborting BTC broadcast: participant operation keys changed during registration (${i.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
2722
2722
  );
2723
2723
  const u = /* @__PURE__ */ new Map();
2724
2724
  for (const [l, c] of a.entries()) {
2725
- const d = `${c.vpKeyEpoch}:${c.appKeeperKeyEpoch}:${c.ucKeyEpoch}`, p = u.get(d);
2726
- p ? p.vaultIds.push(o[l]) : u.set(d, { epochs: c, vaultIds: [o[l]] });
2725
+ const p = `${c.vpKeyEpoch}:${c.appKeeperKeyEpoch}:${c.ucKeyEpoch}`, d = u.get(p);
2726
+ d ? d.vaultIds.push(o[l]) : u.set(p, { epochs: c, vaultIds: [o[l]] });
2727
2727
  }
2728
2728
  await Promise.all(
2729
2729
  [...u.values()].map(
2730
- ({ epochs: l, vaultIds: c }) => Vs({
2730
+ ({ epochs: l, vaultIds: c }) => Rs({
2731
2731
  operationKeyReader: r,
2732
2732
  query: n,
2733
2733
  epochs: l,
@@ -2736,15 +2736,15 @@ async function Bn(e) {
2736
2736
  )
2737
2737
  );
2738
2738
  }
2739
- class Qt extends Error {
2739
+ class Jt extends Error {
2740
2740
  constructor(t) {
2741
2741
  super(t), this.name = "RegisteredVaultVersionMismatchError";
2742
2742
  }
2743
2743
  }
2744
- function In(e) {
2745
- return e instanceof Qt || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
2744
+ function Kn(e) {
2745
+ return e instanceof Jt || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
2746
2746
  }
2747
- async function Vn(e) {
2747
+ async function Hn(e) {
2748
2748
  const {
2749
2749
  vaultRegistryReader: t,
2750
2750
  vaultIds: r,
@@ -2754,44 +2754,56 @@ async function Vn(e) {
2754
2754
  expectedVaultCoreVersion: a
2755
2755
  } = e, i = await t.getProtocolInfoBatch(r), u = [];
2756
2756
  if (i.forEach((l, c) => {
2757
- const d = r[c];
2757
+ const p = r[c];
2758
2758
  l.offchainParamsVersion !== o && u.push(
2759
- `vault ${d}: offchainParams expected v${o}, got v${l.offchainParamsVersion}`
2759
+ `vault ${p}: offchainParams expected v${o}, got v${l.offchainParamsVersion}`
2760
2760
  ), l.appVaultKeepersVersion !== s && u.push(
2761
- `vault ${d}: appVaultKeepers expected v${s}, got v${l.appVaultKeepersVersion}`
2761
+ `vault ${p}: appVaultKeepers expected v${s}, got v${l.appVaultKeepersVersion}`
2762
2762
  ), l.universalChallengersVersion !== n && u.push(
2763
- `vault ${d}: universalChallengers expected v${n}, got v${l.universalChallengersVersion}`
2763
+ `vault ${p}: universalChallengers expected v${n}, got v${l.universalChallengersVersion}`
2764
2764
  ), l.vaultCoreVersion !== a && u.push(
2765
- `vault ${d}: vaultCoreVersion expected v${a} (build-time active), got v${l.vaultCoreVersion}`
2765
+ `vault ${p}: vaultCoreVersion expected v${a} (build-time active), got v${l.vaultCoreVersion}`
2766
2766
  );
2767
2767
  }), u.length > 0)
2768
- throw new Qt(
2768
+ throw new Jt(
2769
2769
  `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.`
2770
2770
  );
2771
2771
  }
2772
- class Rs extends Error {
2772
+ class Ks extends Error {
2773
2773
  constructor(r, o) {
2774
2774
  super(`Refund not yet mature (BIP68 not final): ${o.message}`);
2775
- W(this, "vaultId");
2776
- W(this, "cause");
2775
+ B(this, "vaultId");
2776
+ B(this, "cause");
2777
2777
  this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = o;
2778
2778
  }
2779
2779
  }
2780
- const Ks = /^0x[0-9a-fA-F]{64}$/, Hs = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, Jt = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, Zt = 160, ct = 2e3, lt = 10n, pt = 100n;
2781
- function Rn(e) {
2780
+ class ct extends Error {
2781
+ constructor(r, o, s, n) {
2782
+ super(
2783
+ `Refund broadcast rejected (bitcoind code ${r}): ${n.message}`
2784
+ );
2785
+ B(this, "code");
2786
+ B(this, "vaultId");
2787
+ B(this, "signedTxHex");
2788
+ B(this, "cause");
2789
+ this.name = "RefundBroadcastRejectedError", this.code = r, this.vaultId = o, this.signedTxHex = s, this.cause = n;
2790
+ }
2791
+ }
2792
+ const Hs = /^0x[0-9a-fA-F]{64}$/, Os = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, Zt = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, er = 160, lt = 2e3, dt = 10n, pt = 100n;
2793
+ function On(e) {
2782
2794
  if (!Number.isFinite(e) || e <= 0)
2783
2795
  throw new Error(
2784
2796
  `feeRateSatsVb must be a positive finite number, got ${e}`
2785
2797
  );
2786
- return BigInt(Math.ceil(e * Zt));
2798
+ return BigInt(Math.ceil(e * er));
2787
2799
  }
2788
- const Os = 1, Ns = /non-BIP68-final/i;
2800
+ const Ns = 1, Ds = /non-BIP68-final/i, Ls = /"code"\s*:\s*-27\b/, Ms = /"code"\s*:\s*-25\b/;
2789
2801
  function Ae(e, t) {
2790
2802
  if (e.length !== 66)
2791
2803
  throw new Error(
2792
2804
  `${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
2793
2805
  );
2794
- if (!Ks.test(e))
2806
+ if (!Hs.test(e))
2795
2807
  throw new Error(
2796
2808
  `${t} must contain only hex characters after the 0x prefix`
2797
2809
  );
@@ -2800,7 +2812,7 @@ function Te(e, t) {
2800
2812
  if (!Number.isInteger(e) || e < 0)
2801
2813
  throw new Error(`${t} must be a non-negative integer, got ${e}`);
2802
2814
  }
2803
- function Ds(e) {
2815
+ function Us(e) {
2804
2816
  if (Ae(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0)
2805
2817
  throw new Error(
2806
2818
  `htlcVout must be a non-negative integer, got ${e.htlcVout}`
@@ -2834,24 +2846,24 @@ function Ds(e) {
2834
2846
  if (Te(e.offchainParamsVersion, "offchainParamsVersion"), Te(e.appVaultKeepersVersion, "appVaultKeepersVersion"), Te(
2835
2847
  e.universalChallengersVersion,
2836
2848
  "universalChallengersVersion"
2837
- ), eo(
2849
+ ), to(
2838
2850
  e.vaultCoreVersion,
2839
2851
  "VaultRefundData.vaultCoreVersion"
2840
2852
  ), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
2841
2853
  throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
2842
- if (!Hs.test(e.unsignedPrePeginTxHex))
2854
+ if (!Os.test(e.unsignedPrePeginTxHex))
2843
2855
  throw new Error(
2844
2856
  "unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
2845
2857
  );
2846
- if (!e.depositorBtcPubkey || !Jt.test(e.depositorBtcPubkey))
2858
+ if (!e.depositorBtcPubkey || !Zt.test(e.depositorBtcPubkey))
2847
2859
  throw new Error(
2848
2860
  "depositorBtcPubkey must be 32 or 33 bytes of hex (optional 0x prefix)"
2849
2861
  );
2850
2862
  if (typeof e.amount != "bigint" || e.amount <= 0n)
2851
2863
  throw new Error(`amount must be a positive bigint, got ${e.amount}`);
2852
2864
  }
2853
- function Ls(e) {
2854
- if (!e.vaultProviderPubkey || !Jt.test(e.vaultProviderPubkey))
2865
+ function Fs(e) {
2866
+ if (!e.vaultProviderPubkey || !Zt.test(e.vaultProviderPubkey))
2855
2867
  throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
2856
2868
  if (e.vaultKeeperPubkeys.length === 0)
2857
2869
  throw new Error("vaultKeeperPubkeys must be non-empty");
@@ -2876,7 +2888,7 @@ function Ls(e) {
2876
2888
  `councilQuorum (${e.councilQuorum}) must be in [1, councilSize=${e.councilSize}]`
2877
2889
  );
2878
2890
  }
2879
- async function Kn(e) {
2891
+ async function Nn(e) {
2880
2892
  const {
2881
2893
  vaultId: t,
2882
2894
  readVault: r,
@@ -2888,23 +2900,23 @@ async function Kn(e) {
2888
2900
  } = e;
2889
2901
  i == null || i.throwIfAborted(), Ae(t, "vaultId");
2890
2902
  const u = await r();
2891
- Ds(u), i == null || i.throwIfAborted();
2903
+ Us(u), i == null || i.throwIfAborted();
2892
2904
  const l = await o(u);
2893
- if (Ls(l), i == null || i.throwIfAborted(), !Number.isFinite(s) || s <= 0)
2905
+ if (Fs(l), i == null || i.throwIfAborted(), !Number.isFinite(s) || s <= 0)
2894
2906
  throw new Error(`feeRate must be a positive number, got ${s}`);
2895
- if (s > ct)
2907
+ if (s > lt)
2896
2908
  throw new Error(
2897
- `feeRate ${s} sat/vB exceeds refund safety cap ${ct} sat/vB; refusing to sign refund.`
2909
+ `feeRate ${s} sat/vB exceeds refund safety cap ${lt} sat/vB; refusing to sign refund.`
2898
2910
  );
2899
- const c = BigInt(Math.ceil(s * Zt)), d = u.amount * lt / pt;
2900
- if (c > d)
2911
+ const c = BigInt(Math.ceil(s * er)), p = u.amount * dt / pt;
2912
+ if (c > p)
2901
2913
  throw new Error(
2902
- `Refund fee ${c} sats exceeds the per-vault safety cap of ${d} sats (${lt}/${pt} of vault.amount=${u.amount}); refusing to sign refund.`
2914
+ `Refund fee ${c} sats exceeds the per-vault safety cap of ${p} sats (${dt}/${pt} of vault.amount=${u.amount}); refusing to sign refund.`
2903
2915
  );
2904
2916
  i == null || i.throwIfAborted();
2905
- const p = he(
2917
+ const d = he(
2906
2918
  u.depositorBtcPubkey
2907
- ), g = P(u.unsignedPrePeginTxHex), h = ur(g);
2919
+ ), g = P(u.unsignedPrePeginTxHex), h = cr(g);
2908
2920
  if (h !== void 0 && h.vout !== u.batch.length)
2909
2921
  throw new Error(
2910
2922
  `Auth-anchor OP_RETURN at vout ${h.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.`
@@ -2913,23 +2925,23 @@ async function Kn(e) {
2913
2925
  let f;
2914
2926
  try {
2915
2927
  f = S.fromHex(g);
2916
- } catch (w) {
2928
+ } catch (m) {
2917
2929
  throw new Error(
2918
- `Failed to parse funded Pre-PegIn transaction hex: ${w instanceof Error ? w.message : String(w)}`
2930
+ `Failed to parse funded Pre-PegIn transaction hex: ${m instanceof Error ? m.message : String(m)}`
2919
2931
  );
2920
2932
  }
2921
2933
  if (f.outs.length < u.batch.length)
2922
2934
  throw new Error(
2923
2935
  `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.`
2924
2936
  );
2925
- const { psbtHex: m } = await Qr({
2937
+ const { psbtHex: b } = await Jr({
2926
2938
  prePeginParams: {
2927
2939
  vaultCoreVersion: u.vaultCoreVersion,
2928
- depositorPubkey: p,
2940
+ depositorPubkey: d,
2929
2941
  vaultProviderPubkey: P(l.vaultProviderPubkey),
2930
2942
  vaultKeeperPubkeys: l.vaultKeeperPubkeys.map(P),
2931
2943
  universalChallengerPubkeys: l.universalChallengerPubkeys.map(P),
2932
- hashlocks: u.batch.map((w) => P(w.hashlock)),
2944
+ hashlocks: u.batch.map((m) => P(m.hashlock)),
2933
2945
  timelockRefund: l.timelockRefund,
2934
2946
  // `batch[i].amount` is the on-chain vault deposit (peg-in) amount, which
2935
2947
  // is exactly what WASM's `pegInAmounts` expects — it re-adds the protocol
@@ -2937,7 +2949,7 @@ async function Kn(e) {
2937
2949
  // HTLC output. `buildRefundPsbt`'s value cross-check then binds the result
2938
2950
  // to the funded tx bytes, refusing the refund if the template's HTLC value
2939
2951
  // disagrees with the on-chain commitment.
2940
- pegInAmounts: u.batch.map((w) => w.amount),
2952
+ pegInAmounts: u.batch.map((m) => m.amount),
2941
2953
  feeRate: l.feeRate,
2942
2954
  minPeginFeeRate: l.minPeginFeeRate,
2943
2955
  numLocalChallengers: l.numLocalChallengers,
@@ -2956,40 +2968,48 @@ async function Kn(e) {
2956
2968
  hashlock: P(u.hashlock)
2957
2969
  });
2958
2970
  i == null || i.throwIfAborted();
2959
- const $ = ce(
2971
+ const k = ce(
2960
2972
  u.depositorBtcPubkey,
2961
- Os
2962
- ), x = await n(m, $);
2973
+ Ns
2974
+ ), x = await n(b, k);
2963
2975
  ae({
2964
- requestedPsbtHex: m,
2976
+ requestedPsbtHex: b,
2965
2977
  returnedPsbtHex: x
2966
2978
  });
2967
2979
  const v = 0, E = ue(
2968
2980
  x,
2969
- p,
2981
+ d,
2970
2982
  v
2971
2983
  );
2972
2984
  oe({
2973
- requestedPsbtHex: m,
2985
+ requestedPsbtHex: b,
2974
2986
  signatureHex: E,
2975
- signerXOnlyPubkeyHex: p,
2987
+ signerXOnlyPubkeyHex: d,
2976
2988
  inputIndex: v
2977
2989
  });
2978
- const T = Tt({
2979
- requestedPsbtHex: m,
2990
+ const C = _t({
2991
+ requestedPsbtHex: b,
2980
2992
  signaturesHex: [E],
2981
- signerXOnlyPubkeyHex: p
2993
+ signerXOnlyPubkeyHex: d
2982
2994
  });
2983
2995
  i == null || i.throwIfAborted();
2984
2996
  try {
2985
- return await a(T);
2986
- } catch (w) {
2987
- throw w instanceof Error && Ns.test(w.message) ? new Rs(t, w) : w;
2997
+ return await a(C);
2998
+ } catch (m) {
2999
+ if (m instanceof Error) {
3000
+ if (Ds.test(m.message))
3001
+ throw new Ks(t, m);
3002
+ if (Ls.test(m.message))
3003
+ throw new ct(-27, t, C, m);
3004
+ if (Ms.test(m.message))
3005
+ throw new ct(-25, t, C, m);
3006
+ }
3007
+ throw m;
2988
3008
  }
2989
3009
  }
2990
- async function Hn(e) {
3010
+ async function Dn(e) {
2991
3011
  const { vaultId: t, vault: r, readers: o, network: s } = e, [n, a] = await Promise.all([
2992
- Dt({
3012
+ Lt({
2993
3013
  vaultId: t,
2994
3014
  vault: {
2995
3015
  basic: {
@@ -3023,21 +3043,21 @@ async function Hn(e) {
3023
3043
  network: s
3024
3044
  };
3025
3045
  }
3026
- class dt extends Error {
3046
+ class ht extends Error {
3027
3047
  constructor(r, o, s) {
3028
3048
  super(r);
3029
3049
  /** Fee the reclaim would have paid, in satoshis. */
3030
- W(this, "feeSats");
3050
+ B(this, "feeSats");
3031
3051
  /** Sum of the reserves the reclaim would have swept, in satoshis. */
3032
- W(this, "sweptTotalSats");
3052
+ B(this, "sweptTotalSats");
3033
3053
  this.name = "ReclaimUneconomicalError", this.feeSats = o, this.sweptTotalSats = s;
3034
3054
  }
3035
3055
  }
3036
- const ht = 2e3, gt = 25n, ft = 100n, On = 10n;
3037
- async function Ms(e, t, r) {
3056
+ const gt = 2e3, ft = 25n, yt = 100n, Ln = 10n;
3057
+ async function qs(e, t, r) {
3038
3058
  for (let o = 0; o < e.length; o++) {
3039
- const s = to(e[o].depositorSignedPeginTxHex), n = Ie(
3040
- await wr(
3059
+ const s = ro(e[o].depositorSignedPeginTxHex), n = Ie(
3060
+ await xr(
3041
3061
  P(s),
3042
3062
  P(r)
3043
3063
  )
@@ -3048,7 +3068,7 @@ async function Ms(e, t, r) {
3048
3068
  );
3049
3069
  }
3050
3070
  }
3051
- async function Nn(e) {
3071
+ async function Mn(e) {
3052
3072
  const {
3053
3073
  vaultIds: t,
3054
3074
  depositorEthAddress: r,
@@ -3063,9 +3083,9 @@ async function Nn(e) {
3063
3083
  throw new Error("Reclaim requires at least one vault id; got none.");
3064
3084
  if (!Number.isFinite(n) || n <= 0)
3065
3085
  throw new Error(`feeRate must be a positive number, got ${n}`);
3066
- if (n > ht)
3067
- throw new dt(
3068
- `Fee rate ${n} sat/vB exceeds the reclaim safety cap of ${ht} sat/vB; refusing to sign.`,
3086
+ if (n > gt)
3087
+ throw new ht(
3088
+ `Fee rate ${n} sat/vB exceeds the reclaim safety cap of ${gt} sat/vB; refusing to sign.`,
3069
3089
  0n,
3070
3090
  0n
3071
3091
  );
@@ -3074,131 +3094,132 @@ async function Nn(e) {
3074
3094
  throw new Error(
3075
3095
  `readVaults returned ${l.length} reserves for ${t.length} vault id(s); refusing to sweep a set that does not match the request.`
3076
3096
  );
3077
- await Ms(l, t, r), u == null || u.throwIfAborted();
3078
- const c = he(o), d = l.map((v) => ({
3097
+ await qs(l, t, r), u == null || u.throwIfAborted();
3098
+ const c = he(o), p = l.map((v) => ({
3079
3099
  depositorSignedPeginTxHex: v.depositorSignedPeginTxHex,
3080
3100
  observed: v.observed,
3081
3101
  expectedValue: v.expectedClaimValue
3082
- })), p = Jr(n, d.length), g = d.reduce((v, E) => v + E.expectedValue, 0n), h = g * gt / ft;
3083
- if (p > h)
3084
- throw new dt(
3085
- `Reclaim fee ${p} sats exceeds ${gt}/${ft} of the swept total (${g} sats, cap ${h} sats). The reserve is not at risk — it stays where it is until fee rates fall.`,
3086
- p,
3102
+ })), d = Zr(n, p.length), g = p.reduce((v, E) => v + E.expectedValue, 0n), h = g * ft / yt;
3103
+ if (d > h)
3104
+ throw new ht(
3105
+ `Reclaim fee ${d} sats exceeds ${ft}/${yt} of the swept total (${g} sats, cap ${h} sats). The reserve is not at risk — it stays where it is until fee rates fall.`,
3106
+ d,
3087
3107
  g
3088
3108
  );
3089
3109
  u == null || u.throwIfAborted();
3090
- const { psbtHex: y } = Zr({
3110
+ const { psbtHex: y } = eo({
3091
3111
  depositorPubkey: c,
3092
- inputs: d,
3093
- feeSats: p
3112
+ inputs: p,
3113
+ feeSats: d
3094
3114
  });
3095
3115
  u == null || u.throwIfAborted();
3096
3116
  const f = ce(
3097
3117
  o,
3098
- d.length
3099
- ), m = await a(y, f);
3118
+ p.length
3119
+ ), b = await a(y, f);
3100
3120
  ae({
3101
3121
  requestedPsbtHex: y,
3102
- returnedPsbtHex: m
3122
+ returnedPsbtHex: b
3103
3123
  });
3104
- const $ = d.map((v, E) => {
3105
- const T = ue(
3106
- m,
3124
+ const k = p.map((v, E) => {
3125
+ const C = ue(
3126
+ b,
3107
3127
  c,
3108
3128
  E
3109
3129
  );
3110
3130
  return oe({
3111
3131
  requestedPsbtHex: y,
3112
- signatureHex: T,
3132
+ signatureHex: C,
3113
3133
  signerXOnlyPubkeyHex: c,
3114
3134
  inputIndex: E
3115
- }), T;
3116
- }), x = Tt({
3135
+ }), C;
3136
+ }), x = _t({
3117
3137
  requestedPsbtHex: y,
3118
- signaturesHex: $,
3138
+ signaturesHex: k,
3119
3139
  signerXOnlyPubkeyHex: c
3120
3140
  });
3121
3141
  return u == null || u.throwIfAborted(), i(x);
3122
3142
  }
3123
3143
  export {
3124
- Bn as $,
3125
- K as A,
3126
- Pn as B,
3127
- po as C,
3128
- F as D,
3129
- us as E,
3130
- mn as F,
3131
- b as G,
3132
- ys as H,
3133
- bn as I,
3144
+ Rn as $,
3145
+ H as A,
3146
+ wn as B,
3147
+ ho as C,
3148
+ q as D,
3149
+ cs as E,
3150
+ xn as F,
3151
+ w as G,
3152
+ vs as H,
3153
+ En as I,
3134
3154
  Se as J,
3135
- xn as K,
3136
- En as L,
3137
- kn as M,
3138
- $n as N,
3139
- _n as O,
3140
- go as P,
3141
- Tn as Q,
3142
- Cn as R,
3155
+ kn as K,
3156
+ Cn as L,
3157
+ Tn as M,
3158
+ _n as N,
3159
+ Bn as O,
3160
+ fo as P,
3161
+ An as Q,
3162
+ Sn as R,
3143
3163
  Y as S,
3144
- _s as T,
3145
- Ss as U,
3146
- Po as V,
3147
- Wt as W,
3148
- Yt as X,
3149
- Vs as Y,
3150
- Sn as Z,
3151
- An as _,
3152
- cn as a,
3153
- Qt as a0,
3154
- In as a1,
3155
- Vn as a2,
3156
- zt as a3,
3157
- wn as a4,
3158
- $e as a5,
3159
- Cs as a6,
3164
+ Ss as T,
3165
+ As as U,
3166
+ mo as V,
3167
+ Yt as W,
3168
+ Qt as X,
3169
+ Rs as Y,
3170
+ In as Z,
3171
+ Vn as _,
3172
+ pn as a,
3173
+ Jt as a0,
3174
+ Kn as a1,
3175
+ Hn as a2,
3176
+ jt as a3,
3177
+ $n as a4,
3178
+ ke as a5,
3179
+ Ts as a6,
3160
3180
  nt as a7,
3161
- Dt as a8,
3162
- Xo as a9,
3163
- Nt as aa,
3164
- Rs as ab,
3165
- Kn as ac,
3166
- Rn as ad,
3167
- pt as ae,
3168
- lt as af,
3169
- ct as ag,
3170
- Zt as ah,
3171
- Hn as ai,
3172
- dt as aj,
3173
- Nn as ak,
3174
- ft as al,
3175
- gt as am,
3176
- ht as an,
3177
- On as ao,
3178
- ln as b,
3179
- pn as c,
3180
- hn as d,
3181
- Io as e,
3182
- co as f,
3183
- ho as g,
3184
- gn as h,
3185
- fo as i,
3181
+ Lt as a8,
3182
+ zo as a9,
3183
+ Dt as aa,
3184
+ Ks as ab,
3185
+ ct as ac,
3186
+ Nn as ad,
3187
+ On as ae,
3188
+ pt as af,
3189
+ dt as ag,
3190
+ lt as ah,
3191
+ er as ai,
3192
+ Dn as aj,
3193
+ ht as ak,
3194
+ Mn as al,
3195
+ yt as am,
3196
+ ft as an,
3197
+ gt as ao,
3198
+ Ln as ap,
3199
+ hn as b,
3200
+ gn as c,
3201
+ yn as d,
3202
+ Vo as e,
3203
+ lo as f,
3204
+ go as g,
3205
+ vn as h,
3206
+ yo as i,
3186
3207
  ne as j,
3187
- vo as k,
3188
- wo as l,
3189
- dn as m,
3190
- Ro as n,
3191
- Lo as o,
3192
- So as p,
3193
- Ho as q,
3194
- fn as r,
3208
+ Po as k,
3209
+ xo as l,
3210
+ fn as m,
3211
+ Ko as n,
3212
+ Mo as o,
3213
+ Ao as p,
3214
+ Oo as q,
3215
+ Pn as r,
3195
3216
  ko as s,
3196
- St as t,
3197
- zo as u,
3198
- Lt as v,
3199
- Mt as w,
3200
- Qo as x,
3201
- yn as y,
3202
- vn as z
3217
+ At as t,
3218
+ jo as u,
3219
+ Mt as v,
3220
+ Ut as w,
3221
+ Jo as x,
3222
+ mn as y,
3223
+ bn as z
3203
3224
  };
3204
- //# sourceMappingURL=buildAndBroadcastReclaim-Acz637Vf.js.map
3225
+ //# sourceMappingURL=buildAndBroadcastReclaim-Bs_zdDGN.js.map