@babylonlabs-io/ts-sdk 0.71.0 → 0.71.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/dist/PeginManager-Bn8FxM35.cjs +2 -0
  2. package/dist/{PeginManager-BIKAnZ-X.cjs.map → PeginManager-Bn8FxM35.cjs.map} +1 -1
  3. package/dist/{PeginManager-Byvmccdd.js → PeginManager-C3ojNTlv.js} +6 -6
  4. package/dist/{PeginManager-Byvmccdd.js.map → PeginManager-C3ojNTlv.js.map} +1 -1
  5. package/dist/{buildAndBroadcastReclaim-C0TdwO2M.js → buildAndBroadcastReclaim-YvWDRAN8.js} +492 -489
  6. package/dist/{buildAndBroadcastReclaim-C0TdwO2M.js.map → buildAndBroadcastReclaim-YvWDRAN8.js.map} +1 -1
  7. package/dist/buildAndBroadcastReclaim-zfjDI5__.cjs +2 -0
  8. package/dist/{buildAndBroadcastReclaim-kRx7-o2y.cjs.map → buildAndBroadcastReclaim-zfjDI5__.cjs.map} +1 -1
  9. package/dist/index.cjs +1 -1
  10. package/dist/index.js +227 -226
  11. package/dist/{mempoolApi-CRNMOsbC.js → mempoolApi-CKD_IbrM.js} +32 -33
  12. package/dist/mempoolApi-CKD_IbrM.js.map +1 -0
  13. package/dist/mempoolApi-DronQ5xn.cjs +2 -0
  14. package/dist/mempoolApi-DronQ5xn.cjs.map +1 -0
  15. package/dist/noPayout-DpGRzidi.js +353 -0
  16. package/dist/noPayout-DpGRzidi.js.map +1 -0
  17. package/dist/noPayout-zEifyecV.cjs +2 -0
  18. package/dist/noPayout-zEifyecV.cjs.map +1 -0
  19. package/dist/{primeVpAuth-tEXx9TGx.cjs → primeVpAuth-Cjq6qFHq.cjs} +2 -2
  20. package/dist/primeVpAuth-Cjq6qFHq.cjs.map +1 -0
  21. package/dist/{primeVpAuth-D1qbOkhb.js → primeVpAuth-tLRjdHwZ.js} +2 -2
  22. package/dist/primeVpAuth-tLRjdHwZ.js.map +1 -0
  23. package/dist/{signPsbtsWithFallback-BjXdnI0X.js → signPsbtsWithFallback-CCFTzE0o.js} +3 -3
  24. package/dist/{signPsbtsWithFallback-BjXdnI0X.js.map → signPsbtsWithFallback-CCFTzE0o.js.map} +1 -1
  25. package/dist/{signPsbtsWithFallback-zOQWokmk.cjs → signPsbtsWithFallback-CrkvpSJz.cjs} +2 -2
  26. package/dist/{signPsbtsWithFallback-zOQWokmk.cjs.map → signPsbtsWithFallback-CrkvpSJz.cjs.map} +1 -1
  27. package/dist/signing-BJ3X66b-.cjs +2 -0
  28. package/dist/signing-BJ3X66b-.cjs.map +1 -0
  29. package/dist/signing-Cm-McVR2.js +22 -0
  30. package/dist/signing-Cm-McVR2.js.map +1 -0
  31. package/dist/tbv/core/clients/eth/types.d.ts +0 -2
  32. package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
  33. package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts.map +1 -1
  34. package/dist/tbv/core/clients/index.cjs +1 -1
  35. package/dist/tbv/core/clients/index.js +2 -2
  36. package/dist/tbv/core/clients/mempool/mempoolApi.d.ts +9 -1
  37. package/dist/tbv/core/clients/mempool/mempoolApi.d.ts.map +1 -1
  38. package/dist/tbv/core/index.cjs +1 -1
  39. package/dist/tbv/core/index.js +222 -221
  40. package/dist/tbv/core/managers/index.cjs +1 -1
  41. package/dist/tbv/core/managers/index.js +2 -2
  42. package/dist/tbv/core/primitives/index.cjs +1 -1
  43. package/dist/tbv/core/primitives/index.d.ts +2 -0
  44. package/dist/tbv/core/primitives/index.d.ts.map +1 -1
  45. package/dist/tbv/core/primitives/index.js +23 -22
  46. package/dist/tbv/core/primitives/psbt/__tests__/finalizeScriptPathWithSignatures.test.d.ts +11 -0
  47. package/dist/tbv/core/primitives/psbt/__tests__/finalizeScriptPathWithSignatures.test.d.ts.map +1 -0
  48. package/dist/tbv/core/primitives/psbt/finalizeScriptPathWithSignatures.d.ts +52 -0
  49. package/dist/tbv/core/primitives/psbt/finalizeScriptPathWithSignatures.d.ts.map +1 -0
  50. package/dist/tbv/core/primitives/psbt/reclaim.d.ts +23 -1
  51. package/dist/tbv/core/primitives/psbt/reclaim.d.ts.map +1 -1
  52. package/dist/tbv/core/services/index.cjs +1 -1
  53. package/dist/tbv/core/services/index.js +2 -2
  54. package/dist/tbv/core/services/reclaim/__tests__/buildAndBroadcastReclaim.walletPsbt.test.d.ts +14 -0
  55. package/dist/tbv/core/services/reclaim/__tests__/buildAndBroadcastReclaim.walletPsbt.test.d.ts.map +1 -0
  56. package/dist/tbv/core/services/reclaim/buildAndBroadcastReclaim.d.ts +14 -2
  57. package/dist/tbv/core/services/reclaim/buildAndBroadcastReclaim.d.ts.map +1 -1
  58. package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts.map +1 -1
  59. package/dist/tbv/core/utils/index.cjs +1 -1
  60. package/dist/tbv/core/utils/index.js +13 -13
  61. package/dist/tbv/index.cjs +1 -1
  62. package/dist/tbv/index.js +222 -221
  63. package/dist/toRefundInputs-CY9u84U9.cjs +2 -0
  64. package/dist/{toRefundInputs-Bdtz8p27.cjs.map → toRefundInputs-CY9u84U9.cjs.map} +1 -1
  65. package/dist/{toRefundInputs-CgXMcHrk.js → toRefundInputs-Df1vi23S.js} +5 -5
  66. package/dist/{toRefundInputs-CgXMcHrk.js.map → toRefundInputs-Df1vi23S.js.map} +1 -1
  67. package/dist/{verifyScriptPathSchnorrSignature-mzYCzaSy.cjs → verifyScriptPathSchnorrSignature-BfNUSgA7.cjs} +2 -2
  68. package/dist/{verifyScriptPathSchnorrSignature-mzYCzaSy.cjs.map → verifyScriptPathSchnorrSignature-BfNUSgA7.cjs.map} +1 -1
  69. package/dist/{verifyScriptPathSchnorrSignature-ZAZfFJ6S.js → verifyScriptPathSchnorrSignature-Ciq_xZhw.js} +5 -4
  70. package/dist/{verifyScriptPathSchnorrSignature-ZAZfFJ6S.js.map → verifyScriptPathSchnorrSignature-Ciq_xZhw.js.map} +1 -1
  71. package/dist/waitForTransactionReceiptSmartAware-DpQ69ySe.cjs +2 -0
  72. package/dist/waitForTransactionReceiptSmartAware-DpQ69ySe.cjs.map +1 -0
  73. package/dist/{waitForTransactionReceiptSmartAware-B6oYRdFO.js → waitForTransactionReceiptSmartAware-z3Xfmo44.js} +42 -47
  74. package/dist/waitForTransactionReceiptSmartAware-z3Xfmo44.js.map +1 -0
  75. package/package.json +1 -1
  76. package/dist/PeginManager-BIKAnZ-X.cjs +0 -2
  77. package/dist/buildAndBroadcastReclaim-kRx7-o2y.cjs +0 -2
  78. package/dist/mempoolApi-BQllf-ji.cjs +0 -2
  79. package/dist/mempoolApi-BQllf-ji.cjs.map +0 -1
  80. package/dist/mempoolApi-CRNMOsbC.js.map +0 -1
  81. package/dist/noPayout--lxo7qe4.js +0 -300
  82. package/dist/noPayout--lxo7qe4.js.map +0 -1
  83. package/dist/noPayout-CegnEwfp.cjs +0 -2
  84. package/dist/noPayout-CegnEwfp.cjs.map +0 -1
  85. package/dist/primeVpAuth-D1qbOkhb.js.map +0 -1
  86. package/dist/primeVpAuth-tEXx9TGx.cjs.map +0 -1
  87. package/dist/signing-Bnsro0hE.cjs +0 -2
  88. package/dist/signing-Bnsro0hE.cjs.map +0 -1
  89. package/dist/signing-DaLvGwQe.js +0 -16
  90. package/dist/signing-DaLvGwQe.js.map +0 -1
  91. package/dist/toRefundInputs-Bdtz8p27.cjs +0 -2
  92. package/dist/waitForTransactionReceiptSmartAware-B6oYRdFO.js.map +0 -1
  93. package/dist/waitForTransactionReceiptSmartAware-Ct7LPwPI.cjs +0 -2
  94. package/dist/waitForTransactionReceiptSmartAware-Ct7LPwPI.cjs.map +0 -1
@@ -1,51 +1,52 @@
1
1
  var Ee = Object.defineProperty;
2
- var ke = (e, t, r) => t in e ? Ee(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var C = (e, t, r) => ke(e, typeof t != "symbol" ? t + "" : t, r);
2
+ var xe = (e, t, r) => t in e ? Ee(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var S = (e, t, r) => xe(e, typeof t != "symbol" ? t + "" : t, r);
4
4
  import { B as ae } from "./BTCVaultRegistry.abi-CJwWI2EO.js";
5
- import { e as xe, v as Te, s as y, u as ie, p as O, c as x, f as R } from "./bitcoin-C-TuHb-v.js";
6
- import { v as Ae, d as Re, s as Ce, P as _e, a as Se } from "./signPsbtsWithFallback-BjXdnI0X.js";
5
+ import { e as ie, v as Te, s as v, u as ue, p as O, c as R, f as _ } from "./bitcoin-C-TuHb-v.js";
6
+ import { v as Re, d as Ce, s as Ae, P as _e, a as Se } from "./signPsbtsWithFallback-CCFTzE0o.js";
7
7
  import { zeroAddress as $e } from "viem";
8
- import { D as T, c as Be, b as Ie, R as Ve, d as ue } from "./json-rpc-client-DuUARJvV.js";
9
- import { Transaction as _, Psbt as le } from "bitcoinjs-lib";
10
- import { m as Ke, f as Oe, i as B, g as I, j as V } from "./verifyScriptPathSchnorrSignature-ZAZfFJ6S.js";
11
- import { D as X } from "./constants-CPzppOdq.js";
12
- import { d as Ne, c as He, b as De, e as Fe, a as Me } from "./noPayout--lxo7qe4.js";
13
- import { c as K } from "./signing-DaLvGwQe.js";
14
- import { a as G } from "./onChainBtcPubkey-DATNfAAl.js";
8
+ import { D as C, c as Be, b as Ie, R as Ve, d as le } from "./json-rpc-client-DuUARJvV.js";
9
+ import { Transaction as $ } from "bitcoinjs-lib";
10
+ import { o as Ke, f as Oe, i as B, g as I, j as V } from "./verifyScriptPathSchnorrSignature-Ciq_xZhw.js";
11
+ import { D as G } from "./constants-CPzppOdq.js";
12
+ import { d as He, c as Ne, b as De, f as ce, e as Fe, a as Me } from "./noPayout-DpGRzidi.js";
13
+ import { a as K, c as Le } from "./signing-Cm-McVR2.js";
14
+ import { a as q } from "./onChainBtcPubkey-DATNfAAl.js";
15
15
  import { a as Ue } from "./vaultCoreVersion-D_fP9P3C.js";
16
- const Le = /^0x[0-9a-fA-F]{64}$/, ze = /^0x[0-9a-fA-F]{40}$/, Xe = /^0x([0-9a-fA-F]{2})*$/;
17
- function N(e, t) {
16
+ import { deriveVaultId as Xe } from "./tbv/core/wasm/index.js";
17
+ const Ge = /^0x[0-9a-fA-F]{64}$/, qe = /^0x[0-9a-fA-F]{40}$/, ze = /^0x([0-9a-fA-F]{2})*$/;
18
+ function H(e, t) {
18
19
  if (e.length !== 66)
19
20
  throw new Error(
20
21
  `${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
21
22
  );
22
- if (!Le.test(e))
23
+ if (!Ge.test(e))
23
24
  throw new Error(
24
25
  `${t} must contain only hex characters after the 0x prefix`
25
26
  );
26
27
  }
27
- function Ge(e, t) {
28
- if (!ze.test(e))
28
+ function je(e, t) {
29
+ if (!qe.test(e))
29
30
  throw new Error(
30
31
  `${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
31
32
  );
32
33
  }
33
- function qe(e, t) {
34
- if (!Xe.test(e))
34
+ function Qe(e, t) {
35
+ if (!ze.test(e))
35
36
  throw new Error(
36
37
  `${t} must be a 0x-prefixed hex string with an even number of hex chars`
37
38
  );
38
39
  }
39
- function ce(e) {
40
- Ge(e.btcVaultRegistryAddress, "btcVaultRegistryAddress"), N(e.vaultId, "vaultId");
41
- const t = xe(e.secret);
42
- if (N(t, "secret"), e.hashlock !== void 0 && (N(e.hashlock, "hashlock"), !Ae(t, e.hashlock)))
40
+ function he(e) {
41
+ je(e.btcVaultRegistryAddress, "btcVaultRegistryAddress"), H(e.vaultId, "vaultId");
42
+ const t = ie(e.secret);
43
+ if (H(t, "secret"), e.hashlock !== void 0 && (H(e.hashlock, "hashlock"), !Re(t, e.hashlock)))
43
44
  throw new Error(
44
45
  "Invalid secret: SHA256(secret) does not match the provided hashlock"
45
46
  );
46
47
  return t;
47
48
  }
48
- async function jt(e) {
49
+ async function Wt(e) {
49
50
  const {
50
51
  btcVaultRegistryAddress: t,
51
52
  vaultId: r,
@@ -55,23 +56,23 @@ async function jt(e) {
55
56
  signal: s
56
57
  } = e;
57
58
  s == null || s.throwIfAborted();
58
- const n = ce({
59
+ const i = he({
59
60
  btcVaultRegistryAddress: t,
60
61
  vaultId: r,
61
62
  secret: e.secret,
62
63
  hashlock: o
63
64
  });
64
- return qe(a, "activationMetadata"), l({
65
+ return Qe(a, "activationMetadata"), l({
65
66
  address: t,
66
67
  abi: ae,
67
68
  functionName: "activateVaultWithSecret",
68
- args: [r, n, a]
69
+ args: [r, i, a]
69
70
  });
70
71
  }
71
- async function Qt(e) {
72
+ async function Yt(e) {
72
73
  const { btcVaultRegistryAddress: t, vaultId: r, hashlock: o, writeContract: a, signal: l } = e;
73
74
  l == null || l.throwIfAborted();
74
- const s = ce({
75
+ const s = he({
75
76
  btcVaultRegistryAddress: t,
76
77
  vaultId: r,
77
78
  secret: e.secret,
@@ -84,37 +85,37 @@ async function Qt(e) {
84
85
  args: [r, s]
85
86
  });
86
87
  }
87
- const je = 8, Qe = 6e3, We = 10 * 6e4, Ye = 10;
88
- class he extends Error {
88
+ const We = 8, Ye = 6e3, Je = 10 * 6e4, Ze = 10;
89
+ class de extends Error {
89
90
  constructor(t) {
90
91
  super(t), this.name = "PeginRegistrationMissingError";
91
92
  }
92
93
  }
93
- class de extends Error {
94
+ class pe extends Error {
94
95
  constructor(t) {
95
96
  super(t), this.name = "PeginRegistrationNotFinalError";
96
97
  }
97
98
  }
98
- function Je(e) {
99
- return e instanceof he || e instanceof Error && e.name === "PeginRegistrationMissingError";
99
+ function et(e) {
100
+ return e instanceof de || e instanceof Error && e.name === "PeginRegistrationMissingError";
100
101
  }
101
- function Wt(e) {
102
- return e instanceof de || e instanceof Error && e.name === "PeginRegistrationNotFinalError";
102
+ function Jt(e) {
103
+ return e instanceof pe || e instanceof Error && e.name === "PeginRegistrationNotFinalError";
103
104
  }
104
- function q(e) {
105
+ function z(e) {
105
106
  const { currentBlock: t, createdAtBlock: r } = e, o = t - r + 1n;
106
107
  return o < 0n ? 0 : Number(o);
107
108
  }
108
- async function Yt(e) {
109
+ async function Zt(e) {
109
110
  const {
110
111
  vaultRegistryReader: t,
111
112
  getBlockNumber: r,
112
113
  vaultIds: o,
113
- required: a = je,
114
- pollIntervalMs: l = Qe,
115
- timeoutMs: s = We,
116
- signal: n,
117
- onProgress: i
114
+ required: a = We,
115
+ pollIntervalMs: l = Ye,
116
+ timeoutMs: s = Je,
117
+ signal: i,
118
+ onProgress: n
118
119
  } = e;
119
120
  if (o.length === 0)
120
121
  throw new Error(
@@ -123,116 +124,116 @@ async function Yt(e) {
123
124
  const u = Date.now();
124
125
  let h = !1, c = 0, d;
125
126
  for (; ; ) {
126
- if (n != null && n.aborted)
127
+ if (i != null && i.aborted)
127
128
  throw new Error(
128
129
  `Aborted while waiting for peg-in registration depth (${o.length} vault(s))`
129
130
  );
130
131
  if (Date.now() - u >= s)
131
- throw new de(
132
+ throw new pe(
132
133
  `Peg-in registration did not reach ${a} Ethereum confirmations within ${s}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}` : "")
133
134
  );
134
135
  try {
135
136
  const p = await r(), g = await Promise.all(
136
- o.map((f) => t.getVaultBasicInfo(f))
137
- ), b = g.findIndex(
138
- (f) => f.depositor === $e || f.createdAt === 0n
137
+ o.map((m) => t.getVaultBasicInfo(m))
138
+ ), P = g.findIndex(
139
+ (m) => m.depositor === $e || m.createdAt === 0n
139
140
  );
140
- if (b !== -1) {
141
- if (c += 1, !h && c > Ye)
142
- throw new he(
143
- `Vault ${o[b]} is still not visible on-chain after ${c} reads — the registration does not exist.`
141
+ if (P !== -1) {
142
+ if (c += 1, !h && c > Ze)
143
+ throw new de(
144
+ `Vault ${o[P]} is still not visible on-chain after ${c} reads — the registration does not exist.`
144
145
  );
145
146
  console.warn(
146
- `Peg-in registration for vault ${o[b]} is not visible in chain state at block ${p} — a lagging RPC backend or an Ethereum reorg. Still polling.`
147
- ), i == null || i({ confirmations: 0, required: a });
147
+ `Peg-in registration for vault ${o[P]} is not visible in chain state at block ${p} — a lagging RPC backend or an Ethereum reorg. Still polling.`
148
+ ), n == null || n({ confirmations: 0, required: a });
148
149
  } else {
149
150
  h = !0, c = 0, d = void 0;
150
- let f = g[0], P = q({
151
+ let m = g[0], f = z({
151
152
  currentBlock: p,
152
153
  createdAtBlock: g[0].createdAt
153
154
  });
154
- for (const v of g.slice(1)) {
155
- const m = q({
155
+ for (const w of g.slice(1)) {
156
+ const y = z({
156
157
  currentBlock: p,
157
- createdAtBlock: v.createdAt
158
+ createdAtBlock: w.createdAt
158
159
  });
159
- m < P && (P = m, f = v);
160
+ y < f && (f = y, m = w);
160
161
  }
161
- if (i == null || i({ confirmations: P, required: a }), P >= a)
162
- return { confirmations: P, basicInfo: f };
162
+ if (n == null || n({ confirmations: f, required: a }), f >= a)
163
+ return { confirmations: f, basicInfo: m };
163
164
  }
164
165
  } catch (p) {
165
- if (Je(p))
166
+ if (et(p))
166
167
  throw p;
167
168
  console.warn(
168
169
  `Registration-depth read failed (retrying in ${l}ms): ` + (p instanceof Error ? p.message : String(p))
169
170
  ), d = p;
170
171
  }
171
172
  await new Promise((p, g) => {
172
- const b = () => {
173
- clearTimeout(f), g(
173
+ const P = () => {
174
+ clearTimeout(m), g(
174
175
  new Error(
175
176
  `Aborted while waiting for peg-in registration depth (${o.length} vault(s))`
176
177
  )
177
178
  );
178
- }, f = setTimeout(() => {
179
- n == null || n.removeEventListener("abort", b), p();
179
+ }, m = setTimeout(() => {
180
+ i == null || i.removeEventListener("abort", P), p();
180
181
  }, l);
181
- n == null || n.addEventListener("abort", b, { once: !0 });
182
+ i == null || i.addEventListener("abort", P, { once: !0 });
182
183
  });
183
184
  }
184
185
  }
185
- const Ze = 1;
186
- function et(e, t, r) {
186
+ const tt = 1;
187
+ function rt(e, t, r) {
187
188
  const o = r.map(
188
- (c) => y(c).toLowerCase()
189
+ (c) => v(c).toLowerCase()
189
190
  ), a = t.filter((c) => o.includes(c));
190
191
  if (a.length > 0)
191
192
  throw new Error(
192
193
  `Cannot validate challenger set: vault keepers and universal challengers overlap (${a.join(", ")})`
193
194
  );
194
195
  const l = [...t, ...o], s = e.map(
195
- (c) => y(c.challenger_pubkey).toLowerCase()
196
- ), n = new Set(s);
197
- if (n.size !== s.length)
196
+ (c) => v(c.challenger_pubkey).toLowerCase()
197
+ ), i = new Set(s);
198
+ if (i.size !== s.length)
198
199
  throw new Error(
199
200
  "Depositor graph contains duplicate challenger entries in challenger_presign_data"
200
201
  );
201
- const i = new Set(l), u = l.filter((c) => !n.has(c)), h = s.filter((c) => !i.has(c));
202
+ const n = new Set(l), u = l.filter((c) => !i.has(c)), h = s.filter((c) => !n.has(c));
202
203
  if (u.length > 0 || h.length > 0)
203
204
  throw new Error(
204
205
  "Depositor graph challenger set does not match expected (local ∪ universal)" + (u.length > 0 ? ` (missing: ${u.join(", ")})` : "") + (h.length > 0 ? ` (unexpected: ${h.join(", ")})` : "")
205
206
  );
206
207
  }
207
- function tt(e, t) {
208
+ function ot(e, t) {
208
209
  const r = e.ins[t];
209
- return ie(new Uint8Array(r.hash).slice().reverse());
210
+ return ue(new Uint8Array(r.hash).slice().reverse());
210
211
  }
211
- function H(e, t, r, o, a) {
212
+ function N(e, t, r, o, a) {
212
213
  const l = e.ins[t];
213
214
  if (l.index !== 0)
214
215
  throw new Error(
215
216
  `NoPayout (challenger ${a}) input ${t} expected to spend ${o} vout 0, got vout ${l.index}`
216
217
  );
217
- const s = r.getId(), n = tt(e, t);
218
- if (n !== s)
218
+ const s = r.getId(), i = ot(e, t);
219
+ if (i !== s)
219
220
  throw new Error(
220
- `NoPayout (challenger ${a}) input ${t} does not reference ${o} (expected txid ${s}, got ${n})`
221
+ `NoPayout (challenger ${a}) input ${t} does not reference ${o} (expected txid ${s}, got ${i})`
221
222
  );
222
223
  }
223
- async function rt(e, t, r) {
224
+ async function nt(e, t, r) {
224
225
  const o = [], a = [], l = [], s = Ke({
225
226
  claimerBtcPubkey: r.depositorBtcPubkey,
226
227
  depositorBtcPubkey: r.depositorBtcPubkey,
227
228
  vaultProviderBtcPubkey: r.vaultProviderBtcPubkey,
228
229
  vaultKeeperBtcPubkeys: r.vaultKeeperBtcPubkeys
229
230
  });
230
- et(
231
+ rt(
231
232
  e.challenger_presign_data,
232
233
  s,
233
234
  r.universalChallengerBtcPubkeys
234
235
  );
235
- const n = await Oe({
236
+ const i = await Oe({
236
237
  vaultCoreVersion: r.vaultCoreVersion,
237
238
  vkClaimerPayoutScriptPubKeys: r.vkClaimerPayoutScriptPubKeys,
238
239
  vpCommissionScriptPubKey: r.vpCommissionScriptPubKey,
@@ -248,25 +249,25 @@ async function rt(e, t, r) {
248
249
  network: r.network,
249
250
  claimerBtcPubkey: r.depositorBtcPubkey,
250
251
  registeredPayoutScriptPubKey: r.registeredPayoutScriptPubKey,
251
- commissionBps: Ze,
252
+ commissionBps: tt,
252
253
  protocolFeeRate: r.protocolFeeRate,
253
254
  councilMembers: r.councilMembers,
254
255
  councilQuorum: r.councilQuorum
255
256
  });
256
- o.push(n.psbtHex), a.push(
257
+ o.push(i.psbtHex), a.push(
257
258
  K(
258
259
  t,
259
- X
260
+ G
260
261
  )
261
262
  );
262
- const i = y(r.depositorBtcPubkey), u = _.fromHex(
263
- y(e.assert_tx.tx_hex)
263
+ const n = v(r.depositorBtcPubkey), u = $.fromHex(
264
+ v(e.assert_tx.tx_hex)
264
265
  );
265
266
  for (const h of e.challenger_presign_data) {
266
- const c = y(h.challenger_pubkey), d = o.length, p = await ot({
267
+ const c = v(h.challenger_pubkey), d = o.length, p = await st({
267
268
  challenger: h,
268
269
  challengerPubkey: c,
269
- claimerPubkey: i,
270
+ claimerPubkey: n,
270
271
  localChallengers: s,
271
272
  assertTxParsed: u,
272
273
  ctx: r
@@ -274,7 +275,7 @@ async function rt(e, t, r) {
274
275
  o.push(p), a.push(
275
276
  K(
276
277
  t,
277
- X
278
+ G
278
279
  )
279
280
  ), l.push({
280
281
  challengerPubkey: c,
@@ -283,7 +284,7 @@ async function rt(e, t, r) {
283
284
  }
284
285
  return { psbtHexes: o, signOptions: a, challengerEntries: l };
285
286
  }
286
- async function ot(e) {
287
+ async function st(e) {
287
288
  const {
288
289
  challenger: t,
289
290
  challengerPubkey: r,
@@ -292,36 +293,36 @@ async function ot(e) {
292
293
  assertTxParsed: l,
293
294
  ctx: s
294
295
  } = e;
295
- Ne(
296
+ He(
296
297
  t.nopayout_tx.tx_hex,
297
298
  r,
298
299
  s.network
299
300
  );
300
- const n = _.fromHex(
301
- y(t.nopayout_tx.tx_hex)
302
- ), i = _.fromHex(
303
- y(t.challenge_assert_x_tx.tx_hex)
304
- ), u = _.fromHex(
305
- y(t.challenge_assert_y_tx.tx_hex)
301
+ const i = $.fromHex(
302
+ v(t.nopayout_tx.tx_hex)
303
+ ), n = $.fromHex(
304
+ v(t.challenge_assert_x_tx.tx_hex)
305
+ ), u = $.fromHex(
306
+ v(t.challenge_assert_y_tx.tx_hex)
306
307
  );
307
- if (n.ins.length !== 3)
308
+ if (i.ins.length !== 3)
308
309
  throw new Error(
309
- `NoPayout (challenger ${r}) must have exactly 3 inputs, got ${n.ins.length}`
310
+ `NoPayout (challenger ${r}) must have exactly 3 inputs, got ${i.ins.length}`
310
311
  );
311
- H(
312
- n,
312
+ N(
313
+ i,
313
314
  0,
314
315
  l,
315
316
  "Assert",
316
317
  r
317
- ), H(
318
- n,
319
- 1,
318
+ ), N(
320
319
  i,
320
+ 1,
321
+ n,
321
322
  "ChallengeAssertX",
322
323
  r
323
- ), H(
324
- n,
324
+ ), N(
325
+ i,
325
326
  2,
326
327
  u,
327
328
  "ChallengeAssertY",
@@ -329,13 +330,13 @@ async function ot(e) {
329
330
  );
330
331
  const h = [
331
332
  l.outs[0],
332
- i.outs[0],
333
+ n.outs[0],
333
334
  u.outs[0]
334
335
  ].map((c) => ({
335
- script_pubkey: ie(new Uint8Array(c.script)),
336
+ script_pubkey: ue(new Uint8Array(c.script)),
336
337
  value: c.value
337
338
  }));
338
- return He({
339
+ return Ne({
339
340
  noPayoutTxHex: t.nopayout_tx.tx_hex,
340
341
  challengerPubkey: r,
341
342
  prevouts: h,
@@ -350,7 +351,7 @@ async function ot(e) {
350
351
  }
351
352
  });
352
353
  }
353
- function nt(e, t, r) {
354
+ function at(e, t, r) {
354
355
  B(e[0]);
355
356
  const a = I(
356
357
  e[0].returnedPsbtHex,
@@ -365,17 +366,17 @@ function nt(e, t, r) {
365
366
  const l = {};
366
367
  for (const s of t) {
367
368
  B(e[s.noPayoutIdx]);
368
- const n = I(
369
+ const i = I(
369
370
  e[s.noPayoutIdx].returnedPsbtHex,
370
371
  r
371
372
  );
372
373
  V({
373
374
  requestedPsbtHex: e[s.noPayoutIdx].requestedPsbtHex,
374
- signatureHex: n,
375
+ signatureHex: i,
375
376
  signerXOnlyPubkeyHex: r,
376
377
  inputIndex: 0
377
378
  }), l[s.challengerPubkey] = {
378
- nopayout_signature: n
379
+ nopayout_signature: i
379
380
  };
380
381
  }
381
382
  return {
@@ -385,68 +386,68 @@ function nt(e, t, r) {
385
386
  per_challenger: l
386
387
  };
387
388
  }
388
- async function st(e) {
389
+ async function it(e) {
389
390
  const { depositorGraph: t, btcWallet: r, signingContext: o } = e, a = await r.getPublicKeyHex(), { depositorPubkey: l } = Te(
390
391
  a,
391
- y(o.depositorBtcPubkey)
392
- ), { psbtHexes: s, signOptions: n, challengerEntries: i } = await rt(
392
+ v(o.depositorBtcPubkey)
393
+ ), { psbtHexes: s, signOptions: i, challengerEntries: n } = await nt(
393
394
  t,
394
395
  a,
395
396
  o
396
- ), u = await Re(
397
+ ), u = await Ce(
397
398
  r,
398
399
  s,
399
- n
400
+ i
400
401
  ), h = s.map((c, d) => ({
401
402
  requestedPsbtHex: c,
402
403
  returnedPsbtHex: u[d]
403
404
  }));
404
- return nt(
405
+ return at(
405
406
  h,
406
- i,
407
+ n,
407
408
  l
408
409
  );
409
410
  }
410
- const at = 1e4;
411
- async function pe(e) {
411
+ const ut = 1e4;
412
+ async function ge(e) {
412
413
  const {
413
414
  statusReader: t,
414
415
  peginTxid: r,
415
416
  targetStatuses: o,
416
417
  timeoutMs: a,
417
- pollIntervalMs: l = at,
418
+ pollIntervalMs: l = ut,
418
419
  signal: s
419
- } = e, n = Date.now();
420
+ } = e, i = Date.now();
420
421
  for (; ; ) {
421
422
  if (s != null && s.aborted)
422
423
  throw new Error(
423
424
  `Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
424
425
  );
425
- if (Date.now() - n >= a)
426
+ if (Date.now() - i >= a)
426
427
  throw new Error(
427
428
  `Polling timeout after ${a}ms for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
428
429
  );
429
430
  try {
430
- const i = await t.getPeginStatus(
431
+ const n = await t.getPeginStatus(
431
432
  { pegin_txid: r },
432
433
  s
433
434
  );
434
- if (i.pegin_txid.toLowerCase() !== r.toLowerCase())
435
+ if (n.pegin_txid.toLowerCase() !== r.toLowerCase())
435
436
  throw new Error(
436
- `getPeginStatus returned status for pegin ${i.pegin_txid.slice(0, 8)}…, requested ${r.slice(0, 8)}…`
437
+ `getPeginStatus returned status for pegin ${n.pegin_txid.slice(0, 8)}…, requested ${r.slice(0, 8)}…`
437
438
  );
438
- const u = i.status;
439
- if (o.has(u) || u === T.ACTIVATED)
439
+ const u = n.status;
440
+ if (o.has(u) || u === C.ACTIVATED)
440
441
  return u;
441
- if (u === T.EXPIRED || Be.has(u))
442
+ if (u === C.EXPIRED || Be.has(u))
442
443
  throw new Error(
443
444
  `Pegin ${r.slice(0, 8)}… reached terminal status "${u}" while waiting for ${[...o].join(", ")}`
444
445
  );
445
- } catch (i) {
446
- if (!(i instanceof Ie && i.code === Ve.PEGIN_NOT_FOUND))
447
- throw i;
446
+ } catch (n) {
447
+ if (!(n instanceof Ie && n.code === Ve.PEGIN_NOT_FOUND))
448
+ throw n;
448
449
  }
449
- await new Promise((i, u) => {
450
+ await new Promise((n, u) => {
450
451
  const h = () => {
451
452
  clearTimeout(c), u(
452
453
  new Error(
@@ -454,35 +455,35 @@ async function pe(e) {
454
455
  )
455
456
  );
456
457
  }, c = setTimeout(() => {
457
- s == null || s.removeEventListener("abort", h), i();
458
+ s == null || s.removeEventListener("abort", h), n();
458
459
  }, l);
459
460
  s == null || s.addEventListener("abort", h, { once: !0 });
460
461
  });
461
462
  }
462
463
  }
463
- const it = 1200 * 1e3, ge = /* @__PURE__ */ new Set([
464
- T.PENDING_ACKS,
465
- T.PENDING_ACTIVATION,
466
- T.ACTIVATED_PENDING_BROADCAST,
467
- T.ACTIVATED
468
- ]), ut = /* @__PURE__ */ new Set([
469
- T.PENDING_DEPOSITOR_SIGNATURES,
470
- ...ge
464
+ const lt = 1200 * 1e3, fe = /* @__PURE__ */ new Set([
465
+ C.PENDING_ACKS,
466
+ C.PENDING_ACTIVATION,
467
+ C.ACTIVATED_PENDING_BROADCAST,
468
+ C.ACTIVATED
469
+ ]), ct = /* @__PURE__ */ new Set([
470
+ C.PENDING_DEPOSITOR_SIGNATURES,
471
+ ...fe
471
472
  ]);
472
- function lt(e) {
473
+ function ht(e) {
473
474
  return e.map((t) => ({
474
475
  claimerPubkeyXOnly: O(t.claimer_pubkey),
475
476
  payoutTxHex: t.payout_tx.tx_hex,
476
477
  assertTxHex: t.assert_tx.tx_hex
477
478
  }));
478
479
  }
479
- function k(e) {
480
+ function T(e) {
480
481
  return O(e).toLowerCase();
481
482
  }
482
- function ct(e, t) {
483
- const r = (i, u, h) => {
483
+ function dt(e, t) {
484
+ const r = (n, u, h) => {
484
485
  throw new Error(
485
- `Deposit terms ${i} (${String(u)}) does not match the vault's version-locked signing context (${String(h)}); refusing to sign payouts against terms that describe a different graph.`
486
+ `Deposit terms ${n} (${String(u)}) does not match the vault's version-locked signing context (${String(h)}); refusing to sign payouts against terms that describe a different graph.`
486
487
  );
487
488
  }, o = [
488
489
  ["protocolFeeRate", e.protocolFeeRate, t.protocolFeeRate],
@@ -490,10 +491,10 @@ function ct(e, t) {
490
491
  ["timelockPegin", e.timelockPegin, t.timelockPegin],
491
492
  ["timelockAssert", e.timelockAssert, t.timelockAssert]
492
493
  ];
493
- for (const [i, u, h] of o)
494
- u !== h && r(i, u, h);
495
- const a = (i) => i.map(k).sort(), l = (i, u) => {
496
- const h = a(i), c = a(u);
494
+ for (const [n, u, h] of o)
495
+ u !== h && r(n, u, h);
496
+ const a = (n) => n.map(T).sort(), l = (n, u) => {
497
+ const h = a(n), c = a(u);
497
498
  return h.length === c.length && h.every((d, p) => d === c[p]);
498
499
  };
499
500
  l(e.vaultKeeperBtcPubkeys, t.vaultKeeperBtcPubkeys) || r(
@@ -508,19 +509,19 @@ function ct(e, t) {
508
509
  e.universalChallengerBtcPubkeys.join(","),
509
510
  t.universalChallengerBtcPubkeys.join(",")
510
511
  );
511
- const s = k(t.vaultProviderBtcPubkey), n = e.vaults.map(
512
- (i) => k(i.vaultProviderBtcPubkey)
512
+ const s = T(t.vaultProviderBtcPubkey), i = e.vaults.map(
513
+ (n) => T(n.vaultProviderBtcPubkey)
513
514
  );
514
- n.includes(s) || r(
515
+ i.includes(s) || r(
515
516
  "vaults[].vaultProviderBtcPubkey",
516
- n.join(",") || "<no vaults>",
517
+ i.join(",") || "<no vaults>",
517
518
  t.vaultProviderBtcPubkey
518
519
  );
519
520
  }
520
- function ht(e, t, r, o) {
521
- const a = k(o), l = [
522
- k(t),
523
- ...r.map(k)
521
+ function pt(e, t, r, o) {
522
+ const a = T(o), l = [
523
+ T(t),
524
+ ...r.map(T)
524
525
  ], s = new Set(l);
525
526
  if (s.size !== l.length)
526
527
  throw new Error(
@@ -530,12 +531,12 @@ function ht(e, t, r, o) {
530
531
  throw new Error(
531
532
  "Cannot validate claimer set: depositor key overlaps with vault provider or vault keeper set"
532
533
  );
533
- const n = e.map(
534
- (d) => k(d.claimer_pubkey)
534
+ const i = e.map(
535
+ (d) => T(d.claimer_pubkey)
535
536
  );
536
- if (new Set(n).size !== n.length)
537
+ if (new Set(i).size !== i.length)
537
538
  throw new Error("Presign response contains duplicate claimer entries");
538
- const i = n.filter((d) => d !== a), u = new Set(i), h = l.filter((d) => !u.has(d)), c = i.filter((d) => !s.has(d));
539
+ const n = i.filter((d) => d !== a), u = new Set(n), h = l.filter((d) => !u.has(d)), c = n.filter((d) => !s.has(d));
539
540
  if (h.length > 0 || c.length > 0)
540
541
  throw new Error(
541
542
  "Presign response claimer set does not match expected (vault provider ∪ vault keepers)" + (h.length > 0 ? ` (missing: ${h.join(", ")})` : "") + (c.length > 0 ? ` (unexpected: ${c.join(", ")})` : "")
@@ -563,7 +564,7 @@ function j(e, t) {
563
564
  vpCommissionScriptPubKey: t.vpCommissionScriptPubKey
564
565
  };
565
566
  }
566
- async function dt(e, t, r, o) {
567
+ async function gt(e, t, r, o) {
567
568
  const a = new _e({
568
569
  network: t.network,
569
570
  btcWallet: e
@@ -576,22 +577,22 @@ async function dt(e, t, r, o) {
576
577
  )).map((u) => u.payoutSignature);
577
578
  else {
578
579
  s = [];
579
- for (let i = 0; i < r.length; i++) {
580
- o == null || o(i, l);
580
+ for (let n = 0; n < r.length; n++) {
581
+ o == null || o(n, l);
581
582
  const u = await a.signPayoutTransaction(
582
- j(r[i], t)
583
+ j(r[n], t)
583
584
  );
584
585
  s.push(u.signature);
585
586
  }
586
587
  }
587
- const n = {};
588
- for (let i = 0; i < r.length; i++)
589
- n[r[i].claimerPubkeyXOnly] = {
590
- payout_signature: s[i]
588
+ const i = {};
589
+ for (let n = 0; n < r.length; n++)
590
+ i[r[n].claimerPubkeyXOnly] = {
591
+ payout_signature: s[n]
591
592
  };
592
- return o == null || o(l, l), n;
593
+ return o == null || o(l, l), i;
593
594
  }
594
- async function Jt(e) {
595
+ async function er(e) {
595
596
  const {
596
597
  statusReader: t,
597
598
  presignClient: r,
@@ -599,25 +600,25 @@ async function Jt(e) {
599
600
  peginTxid: a,
600
601
  depositorPk: l,
601
602
  signingContext: s,
602
- depositTerms: n,
603
- timeoutMs: i = it,
603
+ depositTerms: i,
604
+ timeoutMs: n = lt,
604
605
  signal: u,
605
606
  onProgress: h
606
- } = e, c = await pe({
607
+ } = e, c = await ge({
607
608
  statusReader: t,
608
609
  peginTxid: a,
609
- targetStatuses: ut,
610
- timeoutMs: i,
610
+ targetStatuses: ct,
611
+ timeoutMs: n,
611
612
  signal: u
612
613
  });
613
- if (ge.has(c))
614
+ if (fe.has(c))
614
615
  return;
615
- if (u == null || u.throwIfAborted(), n !== void 0 && ct(n, s), Ce(o)) {
616
- if (!n)
616
+ if (u == null || u.throwIfAborted(), i !== void 0 && dt(i, s), Ae(o)) {
617
+ if (!i)
617
618
  throw new Error(
618
619
  "runDepositorPresignFlow: this wallet requires approved deposit terms but none were provided. Fresh deposits must pass PreparePeginResult.depositTerms; resume flows must rebuild them from on-chain state (the vault app's rebuildDepositTerms)."
619
620
  );
620
- typeof o.validateDepositTerms == "function" && await o.validateDepositTerms(n), await o.approveDepositTerms(n);
621
+ typeof o.validateDepositTerms == "function" && await o.validateDepositTerms(i), await o.approveDepositTerms(i);
621
622
  }
622
623
  const d = await r.requestDepositorPresignTransactions(
623
624
  {
@@ -627,23 +628,23 @@ async function Jt(e) {
627
628
  u
628
629
  );
629
630
  u == null || u.throwIfAborted();
630
- const p = k(l);
631
- ht(
631
+ const p = T(l);
632
+ pt(
632
633
  d.txs,
633
634
  s.vaultProviderBtcPubkey,
634
635
  s.vaultKeeperBtcPubkeys,
635
636
  l
636
637
  );
637
638
  const g = d.txs.filter(
638
- (m) => k(m.claimer_pubkey) !== p
639
- ), b = lt(g), f = await dt(
639
+ (y) => T(y.claimer_pubkey) !== p
640
+ ), P = ht(g), m = await gt(
640
641
  o,
641
642
  s,
642
- b,
643
+ P,
643
644
  h
644
645
  );
645
646
  u == null || u.throwIfAborted();
646
- const P = await st({
647
+ const f = await it({
647
648
  depositorGraph: d.depositor_graph,
648
649
  btcWallet: o,
649
650
  signingContext: {
@@ -665,56 +666,56 @@ async function Jt(e) {
665
666
  }
666
667
  });
667
668
  u == null || u.throwIfAborted();
668
- const v = { ...f };
669
- v[y(l)] = P.payout_signatures, await r.submitDepositorPresignatures(
669
+ const w = { ...m };
670
+ w[v(l)] = f.payout_signatures, await r.submitDepositorPresignatures(
670
671
  {
671
672
  pegin_txid: a,
672
673
  depositor_pk: l,
673
- signatures: v,
674
- depositor_claimer_presignatures: P
674
+ signatures: w,
675
+ depositor_claimer_presignatures: f
675
676
  },
676
677
  u
677
678
  );
678
679
  }
679
- const pt = 300 * 1e3, gt = /* @__PURE__ */ new Set([
680
- T.PENDING_DEPOSITOR_WOTS_PK,
681
- ...ue
680
+ const ft = 300 * 1e3, mt = /* @__PURE__ */ new Set([
681
+ C.PENDING_DEPOSITOR_WOTS_PK,
682
+ ...le
682
683
  ]);
683
- async function Zt(e) {
684
+ async function tr(e) {
684
685
  const {
685
686
  statusReader: t,
686
687
  wotsSubmitter: r,
687
688
  peginTxid: o,
688
689
  depositorPk: a,
689
690
  wotsPublicKeys: l,
690
- timeoutMs: s = pt,
691
- signal: n
691
+ timeoutMs: s = ft,
692
+ signal: i
692
693
  } = e;
693
- n == null || n.throwIfAborted();
694
- const i = await pe({
694
+ i == null || i.throwIfAborted();
695
+ const n = await ge({
695
696
  statusReader: t,
696
697
  peginTxid: o,
697
- targetStatuses: gt,
698
+ targetStatuses: mt,
698
699
  timeoutMs: s,
699
- signal: n
700
+ signal: i
700
701
  });
701
- ue.has(i) || (n == null || n.throwIfAborted(), await r.submitDepositorWotsKey(
702
+ le.has(n) || (i == null || i.throwIfAborted(), await r.submitDepositorWotsKey(
702
703
  {
703
704
  pegin_txid: o,
704
705
  depositor_pk: a,
705
706
  wots_public_keys: l
706
707
  },
707
- n
708
+ i
708
709
  ));
709
710
  }
710
711
  function D(e) {
711
712
  return e.registration || e.operation;
712
713
  }
713
- function ft(e, t, r) {
714
- const o = x(e);
714
+ function vt(e, t, r) {
715
+ const o = R(e);
715
716
  return {
716
- registration: o === x(t),
717
- operation: o === x(r)
717
+ registration: o === R(t),
718
+ operation: o === R(r)
718
719
  };
719
720
  }
720
721
  function Q(e, t, r) {
@@ -725,12 +726,12 @@ function Q(e, t, r) {
725
726
  };
726
727
  }
727
728
  function F(e) {
728
- return e.map(x).sort();
729
+ return e.map(R).sort();
729
730
  }
730
731
  function W(e, t) {
731
732
  return e.length === t.length && e.every((r, o) => r === t[o]);
732
733
  }
733
- async function er(e) {
734
+ async function rr(e) {
734
735
  const {
735
736
  vaultProviderEthAddress: t,
736
737
  hintBtcPubkey: r,
@@ -739,21 +740,21 @@ async function er(e) {
739
740
  context: l
740
741
  } = e;
741
742
  if (!r) return;
742
- const s = x(r);
743
- if (s === x(o)) return;
744
- const n = x(
743
+ const s = R(r);
744
+ if (s === R(o)) return;
745
+ const i = R(
745
746
  await a()
746
747
  );
747
- if (s !== n)
748
+ if (s !== i)
748
749
  throw new Error(
749
750
  `Vault provider BTC pubkey mismatch for ${t}: indexer hint matches neither the registration key nor the current operation key on-chain.${l ? ` ${l}` : ""}`
750
751
  );
751
752
  }
752
753
  function M(e, t, r) {
753
- const o = `${e} operation key (admin=${t.ethAddress})`, a = G(
754
+ const o = `${e} operation key (admin=${t.ethAddress})`, a = q(
754
755
  t.btcPubKey,
755
756
  `${e} roster key (admin=${t.ethAddress})`
756
- ), l = G(r, o);
757
+ ), l = q(r, o);
757
758
  return {
758
759
  adminAddress: t.ethAddress,
759
760
  genesisBtcPubkey: a,
@@ -761,7 +762,7 @@ function M(e, t, r) {
761
762
  rotated: l !== a
762
763
  };
763
764
  }
764
- function mt(e) {
765
+ function Pt(e) {
765
766
  const t = /* @__PURE__ */ new Map();
766
767
  for (const r of e) {
767
768
  const o = t.get(r.operationBtcPubkey);
@@ -772,7 +773,7 @@ function mt(e) {
772
773
  t.set(r.operationBtcPubkey, r.adminAddress);
773
774
  }
774
775
  }
775
- function fe(e, t, r) {
776
+ function me(e, t, r) {
776
777
  if (t.vaultKeepers.length !== e.vaultKeepers.length || t.universalChallengers.length !== e.universalChallengers.length)
777
778
  throw new Error(
778
779
  `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`
@@ -785,11 +786,11 @@ function fe(e, t, r) {
785
786
  },
786
787
  t.vaultProvider
787
788
  ), a = e.vaultKeepers.map(
788
- (s, n) => M("vault keeper", s, t.vaultKeepers[n])
789
+ (s, i) => M("vault keeper", s, t.vaultKeepers[i])
789
790
  ), l = e.universalChallengers.map(
790
- (s, n) => M("universal challenger", s, t.universalChallengers[n])
791
+ (s, i) => M("universal challenger", s, t.universalChallengers[i])
791
792
  );
792
- return mt([
793
+ return Pt([
793
794
  o,
794
795
  ...a,
795
796
  ...l
@@ -804,24 +805,24 @@ function fe(e, t, r) {
804
805
  query: e
805
806
  };
806
807
  }
807
- async function Pt(e) {
808
+ async function yt(e) {
808
809
  const t = await e.operationKeyReader.getCurrentOperationKeys(
809
810
  e.query
810
811
  );
811
- return fe(e.query, t, { mode: "current" });
812
+ return me(e.query, t, { mode: "current" });
812
813
  }
813
- async function vt(e) {
814
+ async function bt(e) {
814
815
  const t = await e.operationKeyReader.getOperationKeysAtEpochs(
815
816
  e.query,
816
817
  e.epochs
817
818
  );
818
- return fe(e.query, t, {
819
+ return me(e.query, t, {
819
820
  mode: "epochs",
820
821
  epochs: e.epochs
821
822
  });
822
823
  }
823
- const Y = (e) => e.map(x).sort();
824
- async function tr(e) {
824
+ const Y = (e) => e.map(R).sort();
825
+ async function or(e) {
825
826
  const {
826
827
  vaultRegistryReader: t,
827
828
  vaultKeeperReader: r,
@@ -829,8 +830,8 @@ async function tr(e) {
829
830
  vaultProviderEthAddress: a,
830
831
  applicationEntryPoint: l,
831
832
  expectedVaultProviderBtcPubkey: s,
832
- expectedVaultKeeperBtcPubkeys: n,
833
- expectedUniversalChallengerBtcPubkeys: i,
833
+ expectedVaultKeeperBtcPubkeys: i,
834
+ expectedUniversalChallengerBtcPubkeys: n,
834
835
  operationKeyReader: u,
835
836
  onIndexerServingOperationKeys: h,
836
837
  onIndexerHintsInconsistent: c
@@ -844,7 +845,7 @@ async function tr(e) {
844
845
  ),
845
846
  r.getCurrentVaultKeepersVersion(l),
846
847
  o.getLatestUniversalChallengersVersion()
847
- ]), [b, f] = await Promise.all([
848
+ ]), [P, m] = await Promise.all([
848
849
  r.getVaultKeepersByVersion(
849
850
  l,
850
851
  p
@@ -852,71 +853,71 @@ async function tr(e) {
852
853
  o.getUniversalChallengersByVersion(
853
854
  g
854
855
  )
855
- ]), P = {
856
- vaultProvider: x(d),
857
- vaultKeepers: Y(b.map((E) => E.btcPubKey)),
858
- universalChallengers: Y(f.map((E) => E.btcPubKey))
859
- }, v = await Pt({
856
+ ]), f = {
857
+ vaultProvider: R(d),
858
+ vaultKeepers: Y(P.map((E) => E.btcPubKey)),
859
+ universalChallengers: Y(m.map((E) => E.btcPubKey))
860
+ }, w = await yt({
860
861
  operationKeyReader: u,
861
862
  query: {
862
863
  vaultProviderEthAddress: a,
863
864
  vaultProviderGenesisBtcPubkey: `0x${d}`,
864
865
  applicationEntryPoint: l,
865
- vaultKeepers: b,
866
- universalChallengers: f
866
+ vaultKeepers: P,
867
+ universalChallengers: m
867
868
  }
868
- }), m = {
869
- vaultProvider: v.vaultProvider.operationBtcPubkey,
870
- vaultKeepers: [...v.vaultKeeperOperationKeysSorted],
869
+ }), y = {
870
+ vaultProvider: w.vaultProvider.operationBtcPubkey,
871
+ vaultKeepers: [...w.vaultKeeperOperationKeysSorted],
871
872
  universalChallengers: [
872
- ...v.universalChallengerOperationKeysSorted
873
+ ...w.universalChallengerOperationKeysSorted
873
874
  ]
874
- }, A = ft(
875
+ }, k = vt(
875
876
  s,
876
- P.vaultProvider,
877
- m.vaultProvider
878
- ), S = Q(
879
- n,
880
- P.vaultKeepers,
881
- m.vaultKeepers
882
- ), $ = Q(
877
+ f.vaultProvider,
878
+ y.vaultProvider
879
+ ), x = Q(
883
880
  i,
884
- P.universalChallengers,
885
- m.universalChallengers
881
+ f.vaultKeepers,
882
+ y.vaultKeepers
883
+ ), A = Q(
884
+ n,
885
+ f.universalChallengers,
886
+ y.universalChallengers
886
887
  );
887
- if (!D(A))
888
+ if (!D(k))
888
889
  throw new Error(
889
890
  `Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${a}. Refresh and try again.`
890
891
  );
891
- if (!D(S))
892
+ if (!D(x))
892
893
  throw new Error(
893
894
  `Vault keeper BTC pubkeys (v${p}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
894
895
  );
895
- if (!D($))
896
+ if (!D(A))
896
897
  throw new Error(
897
898
  `Universal challenger BTC pubkeys (v${g}) indexer set does not match ProtocolParams on-chain set. Refresh and try again.`
898
899
  );
899
- const w = [A, S, $], we = w.some((E) => E.registration && !E.operation), z = w.some((E) => E.operation && !E.registration);
900
- if (we && z) {
900
+ const b = [k, x, A], ke = b.some((E) => E.registration && !E.operation), X = b.some((E) => E.operation && !E.registration);
901
+ if (ke && X) {
901
902
  const E = `Indexer participant hints are internally inconsistent for vault provider ${a}: some roles match the registration keys while others match the rotated operation keys.`;
902
903
  throw c == null || c(E), new Error(`${E} Refresh and try again.`);
903
904
  }
904
- return z && (h == null || h(
905
+ return X && (h == null || h(
905
906
  `Indexer is serving rotated operation keys for vault provider ${a}`
906
907
  )), {
907
- vaultProviderBtcPubkeyXOnly: m.vaultProvider,
908
- vaultKeeperBtcPubkeysSorted: m.vaultKeepers,
909
- universalChallengerBtcPubkeysSorted: m.universalChallengers,
908
+ vaultProviderBtcPubkeyXOnly: y.vaultProvider,
909
+ vaultKeeperBtcPubkeysSorted: y.vaultKeepers,
910
+ universalChallengerBtcPubkeysSorted: y.universalChallengers,
910
911
  expectedAppVaultKeepersVersion: p,
911
912
  expectedUniversalChallengersVersion: g,
912
- registrationKeys: P,
913
- participantKeys: v
913
+ registrationKeys: f,
914
+ participantKeys: w
914
915
  };
915
916
  }
916
- function yt(e) {
917
+ function wt(e) {
917
918
  return /^[0-9a-fA-F]{64}$/.test(e);
918
919
  }
919
- function rr(e) {
920
+ function nr(e) {
920
921
  const {
921
922
  amountSats: t,
922
923
  minDeposit: r,
@@ -927,29 +928,29 @@ function rr(e) {
927
928
  } = e;
928
929
  return !(t <= 0n || t < r || o && o > 0n && t > o || l == null || s == null || t + l + s > a);
929
930
  }
930
- function or(e, t, r) {
931
+ function sr(e, t, r) {
931
932
  return e <= 0n ? {
932
933
  valid: !1,
933
934
  error: "Deposit amount must be greater than zero"
934
935
  } : e < t ? {
935
936
  valid: !1,
936
- error: `Minimum deposit is ${R(t)} BTC`
937
+ error: `Minimum deposit is ${_(t)} BTC`
937
938
  } : r && r > 0n && e > r ? {
938
939
  valid: !1,
939
- error: `Maximum deposit is ${R(r)} BTC`
940
+ error: `Maximum deposit is ${_(r)} BTC`
940
941
  } : { valid: !0 };
941
942
  }
942
- function nr(e) {
943
+ function ar(e) {
943
944
  const { amount: t, effectiveRemaining: r } = e;
944
945
  return r === null ? { valid: !0 } : r === 0n ? {
945
946
  valid: !1,
946
947
  error: "Supply cap reached — deposits temporarily paused"
947
948
  } : t > r ? {
948
949
  valid: !1,
949
- error: `Vault size exceeds remaining capacity (${R(r)} BTC)`
950
+ error: `Vault size exceeds remaining capacity (${_(r)} BTC)`
950
951
  } : { valid: !0 };
951
952
  }
952
- function sr(e, t) {
953
+ function ir(e, t) {
953
954
  if (!e || e.length === 0)
954
955
  return {
955
956
  valid: !1,
@@ -965,7 +966,7 @@ function sr(e, t) {
965
966
  error: "Invalid vault provider selected"
966
967
  } : { valid: !0 };
967
968
  }
968
- function bt(e, t, r) {
969
+ function kt(e, t, r) {
969
970
  if (!e || e.length === 0)
970
971
  return {
971
972
  valid: !1,
@@ -981,40 +982,40 @@ function bt(e, t, r) {
981
982
  if (t && a < t)
982
983
  return {
983
984
  valid: !1,
984
- error: `Vault ${o + 1} amount ${R(a)} BTC is below minimum deposit ${R(t)} BTC`
985
+ error: `Vault ${o + 1} amount ${_(a)} BTC is below minimum deposit ${_(t)} BTC`
985
986
  };
986
987
  if (r && a > r)
987
988
  return {
988
989
  valid: !1,
989
- error: `Vault ${o + 1} amount ${R(a)} BTC exceeds maximum deposit ${R(r)} BTC`
990
+ error: `Vault ${o + 1} amount ${_(a)} BTC exceeds maximum deposit ${_(r)} BTC`
990
991
  };
991
992
  }
992
993
  return { valid: !0 };
993
994
  }
994
- function wt(e) {
995
- const t = y(e);
996
- return yt(t) ? { valid: !0 } : {
995
+ function Et(e) {
996
+ const t = v(e);
997
+ return wt(t) ? { valid: !0 } : {
997
998
  valid: !1,
998
999
  error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
999
1000
  };
1000
1001
  }
1001
- function Et(e) {
1002
+ function xt(e) {
1002
1003
  if (!e || e.length === 0)
1003
1004
  throw new Error(
1004
1005
  "No vault keepers available. The system requires at least one vault keeper to create a deposit."
1005
1006
  );
1006
1007
  }
1007
- function kt(e) {
1008
+ function Tt(e) {
1008
1009
  if (!e || e.length === 0)
1009
1010
  throw new Error(
1010
1011
  "No universal challengers available. The system requires at least one universal challenger to create a deposit."
1011
1012
  );
1012
1013
  }
1013
- function xt(e) {
1014
+ function Rt(e) {
1014
1015
  if (e.length === 0)
1015
1016
  throw new Error("No spendable UTXOs available");
1016
1017
  }
1017
- function ar(e) {
1018
+ function ur(e) {
1018
1019
  const {
1019
1020
  vaultAmounts: t,
1020
1021
  confirmedUTXOs: r,
@@ -1022,50 +1023,50 @@ function ar(e) {
1022
1023
  vaultKeeperBtcPubkeys: a,
1023
1024
  universalChallengerBtcPubkeys: l,
1024
1025
  minDeposit: s,
1025
- maxDeposit: n
1026
- } = e, i = bt(
1026
+ maxDeposit: i
1027
+ } = e, n = kt(
1027
1028
  t,
1028
1029
  s,
1029
- n
1030
+ i
1030
1031
  );
1031
- if (!i.valid)
1032
- throw new Error(i.error);
1033
- const u = wt(o);
1032
+ if (!n.valid)
1033
+ throw new Error(n.error);
1034
+ const u = Et(o);
1034
1035
  if (!u.valid)
1035
1036
  throw new Error(u.error);
1036
- Et(a), kt(l), xt(r);
1037
+ xt(a), Tt(l), Rt(r);
1037
1038
  }
1038
- class me extends Error {
1039
+ class ve extends Error {
1039
1040
  constructor(t) {
1040
1041
  super(t), this.name = "ParticipantKeyDriftError";
1041
1042
  }
1042
1043
  }
1043
- function ir(e) {
1044
- return e instanceof me || e instanceof Error && e.name === "ParticipantKeyDriftError";
1044
+ function lr(e) {
1045
+ return e instanceof ve || e instanceof Error && e.name === "ParticipantKeyDriftError";
1045
1046
  }
1046
1047
  function J(e, t, r) {
1047
1048
  return t.length === r.length && t.every((o, a) => o === r[a]) ? null : `${e} expected [${t.join(", ")}], got [${r.join(", ")}]`;
1048
1049
  }
1049
- async function ur(e) {
1050
+ async function cr(e) {
1050
1051
  const { vaultRegistryReader: t, operationKeyReader: r, vaultIds: o, expected: a } = e, l = a.query;
1051
1052
  if (o.length === 0) return;
1052
- const s = await t.getVaultKeyEpochsBatch(o), n = [];
1053
- for (const [i, u] of s.entries()) {
1054
- const h = o[i];
1053
+ const s = await t.getVaultKeyEpochsBatch(o), i = [];
1054
+ for (const [n, u] of s.entries()) {
1055
+ const h = o[n];
1055
1056
  let c;
1056
1057
  try {
1057
- c = await vt({
1058
+ c = await bt({
1058
1059
  operationKeyReader: r,
1059
1060
  query: l,
1060
1061
  epochs: u
1061
1062
  });
1062
1063
  } catch (g) {
1063
- n.push(
1064
+ i.push(
1064
1065
  `vault ${h}: could not resolve participants at frozen epochs (vp=${u.vpKeyEpoch}, keeper=${u.appKeeperKeyEpoch}, uc=${u.ucKeyEpoch}): ${g.message}`
1065
1066
  );
1066
1067
  continue;
1067
1068
  }
1068
- c.vaultProvider.operationBtcPubkey !== a.vaultProvider.operationBtcPubkey && n.push(
1069
+ c.vaultProvider.operationBtcPubkey !== a.vaultProvider.operationBtcPubkey && i.push(
1069
1070
  `vault ${h}: vault provider key expected ${a.vaultProvider.operationBtcPubkey}, got ${c.vaultProvider.operationBtcPubkey}`
1070
1071
  );
1071
1072
  const d = J(
@@ -1073,17 +1074,17 @@ async function ur(e) {
1073
1074
  a.vaultKeeperOperationKeysSorted,
1074
1075
  c.vaultKeeperOperationKeysSorted
1075
1076
  );
1076
- d && n.push(d);
1077
+ d && i.push(d);
1077
1078
  const p = J(
1078
1079
  `vault ${h}: universal challenger keys`,
1079
1080
  a.universalChallengerOperationKeysSorted,
1080
1081
  c.universalChallengerOperationKeysSorted
1081
1082
  );
1082
- p && n.push(p);
1083
+ p && i.push(p);
1083
1084
  }
1084
- if (n.length > 0)
1085
- throw new me(
1086
- `Aborting BTC broadcast: participant operation keys changed during registration (${n.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
1085
+ if (i.length > 0)
1086
+ throw new ve(
1087
+ `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.`
1087
1088
  );
1088
1089
  }
1089
1090
  class Pe extends Error {
@@ -1091,10 +1092,10 @@ class Pe extends Error {
1091
1092
  super(t), this.name = "RegisteredVaultVersionMismatchError";
1092
1093
  }
1093
1094
  }
1094
- function lr(e) {
1095
+ function hr(e) {
1095
1096
  return e instanceof Pe || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
1096
1097
  }
1097
- async function cr(e) {
1098
+ async function dr(e) {
1098
1099
  const {
1099
1100
  vaultRegistryReader: t,
1100
1101
  vaultIds: r,
@@ -1102,70 +1103,70 @@ async function cr(e) {
1102
1103
  expectedAppVaultKeepersVersion: a,
1103
1104
  expectedUniversalChallengersVersion: l,
1104
1105
  expectedVaultCoreVersion: s
1105
- } = e, n = await t.getProtocolInfoBatch(r), i = [];
1106
- if (n.forEach((u, h) => {
1106
+ } = e, i = await t.getProtocolInfoBatch(r), n = [];
1107
+ if (i.forEach((u, h) => {
1107
1108
  const c = r[h];
1108
- u.offchainParamsVersion !== o && i.push(
1109
+ u.offchainParamsVersion !== o && n.push(
1109
1110
  `vault ${c}: offchainParams expected v${o}, got v${u.offchainParamsVersion}`
1110
- ), u.appVaultKeepersVersion !== a && i.push(
1111
+ ), u.appVaultKeepersVersion !== a && n.push(
1111
1112
  `vault ${c}: appVaultKeepers expected v${a}, got v${u.appVaultKeepersVersion}`
1112
- ), u.universalChallengersVersion !== l && i.push(
1113
+ ), u.universalChallengersVersion !== l && n.push(
1113
1114
  `vault ${c}: universalChallengers expected v${l}, got v${u.universalChallengersVersion}`
1114
- ), u.vaultCoreVersion !== s && i.push(
1115
+ ), u.vaultCoreVersion !== s && n.push(
1115
1116
  `vault ${c}: vaultCoreVersion expected v${s} (build-time active), got v${u.vaultCoreVersion}`
1116
1117
  );
1117
- }), i.length > 0)
1118
+ }), n.length > 0)
1118
1119
  throw new Pe(
1119
- `Aborting BTC broadcast: signer-set or offchain-params versions changed during registration (${i.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
1120
+ `Aborting BTC broadcast: signer-set or offchain-params versions changed during registration (${n.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
1120
1121
  );
1121
1122
  }
1122
- var ve = /* @__PURE__ */ ((e) => (e.CLAIM_EVENT_RECEIVED = "ClaimEventReceived", e.CLAIM_BROADCAST = "ClaimBroadcast", e.ASSERT_BROADCAST = "AssertBroadcast", e.PAYOUT_BROADCAST = "PayoutBroadcast", e.PAYOUT_BLOCKED = "PayoutBlocked", e))(ve || {});
1123
- const Tt = /* @__PURE__ */ new Set([
1123
+ var ye = /* @__PURE__ */ ((e) => (e.CLAIM_EVENT_RECEIVED = "ClaimEventReceived", e.CLAIM_BROADCAST = "ClaimBroadcast", e.ASSERT_BROADCAST = "AssertBroadcast", e.PAYOUT_BROADCAST = "PayoutBroadcast", e.PAYOUT_BLOCKED = "PayoutBlocked", e))(ye || {});
1124
+ const Ct = /* @__PURE__ */ new Set([
1124
1125
  "PayoutBroadcast",
1125
1126
  "PayoutBlocked"
1126
1127
  /* PAYOUT_BLOCKED */
1127
1128
  ]);
1128
- function hr(e) {
1129
- return Object.values(ve).includes(
1129
+ function pr(e) {
1130
+ return Object.values(ye).includes(
1130
1131
  e
1131
1132
  );
1132
1133
  }
1133
- function dr(e) {
1134
- return !!e && Tt.has(e);
1134
+ function gr(e) {
1135
+ return !!e && Ct.has(e);
1135
1136
  }
1136
1137
  class At extends Error {
1137
1138
  constructor(r, o) {
1138
1139
  super(`Refund not yet mature (BIP68 not final): ${o.message}`);
1139
- C(this, "vaultId");
1140
- C(this, "cause");
1140
+ S(this, "vaultId");
1141
+ S(this, "cause");
1141
1142
  this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = o;
1142
1143
  }
1143
1144
  }
1144
- const Rt = /^0x[0-9a-fA-F]{64}$/, Ct = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, ye = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, be = 160, Z = 2e3, ee = 10n, te = 100n;
1145
- function pr(e) {
1145
+ const _t = /^0x[0-9a-fA-F]{64}$/, St = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, be = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, we = 160, Z = 2e3, ee = 10n, te = 100n;
1146
+ function fr(e) {
1146
1147
  if (!Number.isFinite(e) || e <= 0)
1147
1148
  throw new Error(
1148
1149
  `feeRateSatsVb must be a positive finite number, got ${e}`
1149
1150
  );
1150
- return BigInt(Math.ceil(e * be));
1151
+ return BigInt(Math.ceil(e * we));
1151
1152
  }
1152
- const _t = 1, St = /non-BIP68-final/i;
1153
- function L(e, t) {
1153
+ const $t = 1, Bt = /non-BIP68-final/i;
1154
+ function U(e, t) {
1154
1155
  if (e.length !== 66)
1155
1156
  throw new Error(
1156
1157
  `${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
1157
1158
  );
1158
- if (!Rt.test(e))
1159
+ if (!_t.test(e))
1159
1160
  throw new Error(
1160
1161
  `${t} must contain only hex characters after the 0x prefix`
1161
1162
  );
1162
1163
  }
1163
- function U(e, t) {
1164
+ function L(e, t) {
1164
1165
  if (!Number.isInteger(e) || e < 0)
1165
1166
  throw new Error(`${t} must be a non-negative integer, got ${e}`);
1166
1167
  }
1167
- function $t(e) {
1168
- if (L(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0)
1168
+ function It(e) {
1169
+ if (U(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0)
1169
1170
  throw new Error(
1170
1171
  `htlcVout must be a non-negative integer, got ${e.htlcVout}`
1171
1172
  );
@@ -1177,7 +1178,7 @@ function $t(e) {
1177
1178
  );
1178
1179
  for (let r = 0; r < e.batch.length; r++) {
1179
1180
  const o = e.batch[r];
1180
- if (L(o.hashlock, `batch[${r}].hashlock`), !Number.isInteger(o.htlcVout) || o.htlcVout !== r)
1181
+ if (U(o.hashlock, `batch[${r}].hashlock`), !Number.isInteger(o.htlcVout) || o.htlcVout !== r)
1181
1182
  throw new Error(
1182
1183
  `batch[${r}].htlcVout must equal ${r} (contiguous vout-ordered vector), got ${o.htlcVout}`
1183
1184
  );
@@ -1195,7 +1196,7 @@ function $t(e) {
1195
1196
  throw new Error(
1196
1197
  `batch[${e.htlcVout}].amount (${t.amount}) does not match target amount (${e.amount})`
1197
1198
  );
1198
- if (U(e.offchainParamsVersion, "offchainParamsVersion"), U(e.appVaultKeepersVersion, "appVaultKeepersVersion"), U(
1199
+ if (L(e.offchainParamsVersion, "offchainParamsVersion"), L(e.appVaultKeepersVersion, "appVaultKeepersVersion"), L(
1199
1200
  e.universalChallengersVersion,
1200
1201
  "universalChallengersVersion"
1201
1202
  ), Ue(
@@ -1203,19 +1204,19 @@ function $t(e) {
1203
1204
  "VaultRefundData.vaultCoreVersion"
1204
1205
  ), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
1205
1206
  throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
1206
- if (!Ct.test(e.unsignedPrePeginTxHex))
1207
+ if (!St.test(e.unsignedPrePeginTxHex))
1207
1208
  throw new Error(
1208
1209
  "unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
1209
1210
  );
1210
- if (!e.depositorBtcPubkey || !ye.test(e.depositorBtcPubkey))
1211
+ if (!e.depositorBtcPubkey || !be.test(e.depositorBtcPubkey))
1211
1212
  throw new Error(
1212
1213
  "depositorBtcPubkey must be 32 or 33 bytes of hex (optional 0x prefix)"
1213
1214
  );
1214
1215
  if (typeof e.amount != "bigint" || e.amount <= 0n)
1215
1216
  throw new Error(`amount must be a positive bigint, got ${e.amount}`);
1216
1217
  }
1217
- function Bt(e) {
1218
- if (!e.vaultProviderPubkey || !ye.test(e.vaultProviderPubkey))
1218
+ function Vt(e) {
1219
+ if (!e.vaultProviderPubkey || !be.test(e.vaultProviderPubkey))
1219
1220
  throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
1220
1221
  if (e.vaultKeeperPubkeys.length === 0)
1221
1222
  throw new Error("vaultKeeperPubkeys must be non-empty");
@@ -1240,18 +1241,7 @@ function Bt(e) {
1240
1241
  `councilQuorum (${e.councilQuorum}) must be in [1, councilSize=${e.councilSize}]`
1241
1242
  );
1242
1243
  }
1243
- function It(e) {
1244
- const t = le.fromHex(e);
1245
- try {
1246
- t.finalizeAllInputs();
1247
- } catch (r) {
1248
- const o = r instanceof Error ? r.message : String(r);
1249
- if (!o.includes("already finalized"))
1250
- throw new Error(`Failed to finalize refund PSBT: ${o}`);
1251
- }
1252
- return t.extractTransaction().toHex();
1253
- }
1254
- async function gr(e) {
1244
+ async function mr(e) {
1255
1245
  const {
1256
1246
  vaultId: t,
1257
1247
  readVault: r,
@@ -1259,52 +1249,52 @@ async function gr(e) {
1259
1249
  feeRate: a,
1260
1250
  signPsbt: l,
1261
1251
  broadcastTx: s,
1262
- signal: n
1252
+ signal: i
1263
1253
  } = e;
1264
- n == null || n.throwIfAborted(), L(t, "vaultId");
1265
- const i = await r();
1266
- $t(i), n == null || n.throwIfAborted();
1267
- const u = await o(i);
1268
- if (Bt(u), n == null || n.throwIfAborted(), !Number.isFinite(a) || a <= 0)
1254
+ i == null || i.throwIfAborted(), U(t, "vaultId");
1255
+ const n = await r();
1256
+ It(n), i == null || i.throwIfAborted();
1257
+ const u = await o(n);
1258
+ if (Vt(u), i == null || i.throwIfAborted(), !Number.isFinite(a) || a <= 0)
1269
1259
  throw new Error(`feeRate must be a positive number, got ${a}`);
1270
1260
  if (a > Z)
1271
1261
  throw new Error(
1272
1262
  `feeRate ${a} sat/vB exceeds refund safety cap ${Z} sat/vB; refusing to sign refund.`
1273
1263
  );
1274
- const h = BigInt(Math.ceil(a * be)), c = i.amount * ee / te;
1264
+ const h = BigInt(Math.ceil(a * we)), c = n.amount * ee / te;
1275
1265
  if (h > c)
1276
1266
  throw new Error(
1277
- `Refund fee ${h} sats exceeds the per-vault safety cap of ${c} sats (${ee}/${te} of vault.amount=${i.amount}); refusing to sign refund.`
1267
+ `Refund fee ${h} sats exceeds the per-vault safety cap of ${c} sats (${ee}/${te} of vault.amount=${n.amount}); refusing to sign refund.`
1278
1268
  );
1279
- n == null || n.throwIfAborted();
1269
+ i == null || i.throwIfAborted();
1280
1270
  const d = O(
1281
- i.depositorBtcPubkey
1282
- ), p = y(i.unsignedPrePeginTxHex), g = Se(p);
1283
- if (g !== void 0 && g.vout !== i.batch.length)
1271
+ n.depositorBtcPubkey
1272
+ ), p = v(n.unsignedPrePeginTxHex), g = Se(p);
1273
+ if (g !== void 0 && g.vout !== n.batch.length)
1284
1274
  throw new Error(
1285
- `Auth-anchor OP_RETURN at vout ${g.vout} does not match batch size (${i.batch.length} HTLC outputs expect the anchor at vout ${i.batch.length}). Refund refused — sibling HTLC vector is incomplete.`
1275
+ `Auth-anchor OP_RETURN at vout ${g.vout} does not match batch size (${n.batch.length} HTLC outputs expect the anchor at vout ${n.batch.length}). Refund refused — sibling HTLC vector is incomplete.`
1286
1276
  );
1287
- const b = g == null ? void 0 : g.hash;
1288
- let f;
1277
+ const P = g == null ? void 0 : g.hash;
1278
+ let m;
1289
1279
  try {
1290
- f = _.fromHex(p);
1291
- } catch (w) {
1280
+ m = $.fromHex(p);
1281
+ } catch (b) {
1292
1282
  throw new Error(
1293
- `Failed to parse funded Pre-PegIn transaction hex: ${w instanceof Error ? w.message : String(w)}`
1283
+ `Failed to parse funded Pre-PegIn transaction hex: ${b instanceof Error ? b.message : String(b)}`
1294
1284
  );
1295
1285
  }
1296
- if (f.outs.length < i.batch.length)
1286
+ if (m.outs.length < n.batch.length)
1297
1287
  throw new Error(
1298
- `Funded Pre-PegIn tx has ${f.outs.length} outputs but batch requires at least ${i.batch.length} HTLC outputs. Refund refused — funded tx shape disagrees with sibling vector.`
1288
+ `Funded Pre-PegIn tx has ${m.outs.length} outputs but batch requires at least ${n.batch.length} HTLC outputs. Refund refused — funded tx shape disagrees with sibling vector.`
1299
1289
  );
1300
- const { psbtHex: P } = await De({
1290
+ const { psbtHex: f } = await De({
1301
1291
  prePeginParams: {
1302
- vaultCoreVersion: i.vaultCoreVersion,
1292
+ vaultCoreVersion: n.vaultCoreVersion,
1303
1293
  depositorPubkey: d,
1304
- vaultProviderPubkey: y(u.vaultProviderPubkey),
1305
- vaultKeeperPubkeys: u.vaultKeeperPubkeys.map(y),
1306
- universalChallengerPubkeys: u.universalChallengerPubkeys.map(y),
1307
- hashlocks: i.batch.map((w) => y(w.hashlock)),
1294
+ vaultProviderPubkey: v(u.vaultProviderPubkey),
1295
+ vaultKeeperPubkeys: u.vaultKeeperPubkeys.map(v),
1296
+ universalChallengerPubkeys: u.universalChallengerPubkeys.map(v),
1297
+ hashlocks: n.batch.map((b) => v(b.hashlock)),
1308
1298
  timelockRefund: u.timelockRefund,
1309
1299
  // `batch[i].amount` is the on-chain vault deposit (peg-in) amount, which
1310
1300
  // is exactly what WASM's `pegInAmounts` expects — it re-adds the protocol
@@ -1312,188 +1302,201 @@ async function gr(e) {
1312
1302
  // HTLC output. `buildRefundPsbt`'s value cross-check then binds the result
1313
1303
  // to the funded tx bytes, refusing the refund if the template's HTLC value
1314
1304
  // disagrees with the on-chain commitment.
1315
- pegInAmounts: i.batch.map((w) => w.amount),
1305
+ pegInAmounts: n.batch.map((b) => b.amount),
1316
1306
  feeRate: u.feeRate,
1317
1307
  minPeginFeeRate: u.minPeginFeeRate,
1318
1308
  numLocalChallengers: u.numLocalChallengers,
1319
1309
  councilQuorum: u.councilQuorum,
1320
1310
  councilSize: u.councilSize,
1321
1311
  network: u.network,
1322
- authAnchorHash: b
1312
+ authAnchorHash: P
1323
1313
  },
1324
1314
  fundedPrePeginTxHex: p,
1325
- htlcVout: i.htlcVout,
1315
+ htlcVout: n.htlcVout,
1326
1316
  refundFee: h,
1327
1317
  // buildRefundPsbt's top-level `hashlock` param is documented as "no 0x
1328
1318
  // prefix" and flows into the WASM HTLC connector derivation; a prefixed
1329
1319
  // value would derive the wrong refund script leaf and yield an
1330
1320
  // unspendable PSBT. Match the `hashlocks` array handling above.
1331
- hashlock: y(i.hashlock)
1321
+ hashlock: v(n.hashlock)
1332
1322
  });
1333
- n == null || n.throwIfAborted();
1334
- const v = K(
1335
- i.depositorBtcPubkey,
1336
- _t
1337
- ), m = await l(P, v);
1323
+ i == null || i.throwIfAborted();
1324
+ const w = K(
1325
+ n.depositorBtcPubkey,
1326
+ $t
1327
+ ), y = await l(f, w);
1338
1328
  B({
1339
- requestedPsbtHex: P,
1340
- returnedPsbtHex: m
1329
+ requestedPsbtHex: f,
1330
+ returnedPsbtHex: y
1341
1331
  });
1342
- const A = 0, S = I(
1343
- m,
1332
+ const k = 0, x = I(
1333
+ y,
1344
1334
  d,
1345
- A
1335
+ k
1346
1336
  );
1347
1337
  V({
1348
- requestedPsbtHex: P,
1349
- signatureHex: S,
1338
+ requestedPsbtHex: f,
1339
+ signatureHex: x,
1350
1340
  signerXOnlyPubkeyHex: d,
1351
- inputIndex: A
1341
+ inputIndex: k
1352
1342
  });
1353
- const $ = It(m);
1354
- n == null || n.throwIfAborted();
1343
+ const A = ce({
1344
+ requestedPsbtHex: f,
1345
+ signaturesHex: [x],
1346
+ signerXOnlyPubkeyHex: d
1347
+ });
1348
+ i == null || i.throwIfAborted();
1355
1349
  try {
1356
- return await s($);
1357
- } catch (w) {
1358
- throw w instanceof Error && St.test(w.message) ? new At(t, w) : w;
1350
+ return await s(A);
1351
+ } catch (b) {
1352
+ throw b instanceof Error && Bt.test(b.message) ? new At(t, b) : b;
1359
1353
  }
1360
1354
  }
1361
1355
  class re extends Error {
1362
1356
  constructor(r, o, a) {
1363
1357
  super(r);
1364
1358
  /** Fee the reclaim would have paid, in satoshis. */
1365
- C(this, "feeSats");
1359
+ S(this, "feeSats");
1366
1360
  /** Sum of the reserves the reclaim would have swept, in satoshis. */
1367
- C(this, "sweptTotalSats");
1361
+ S(this, "sweptTotalSats");
1368
1362
  this.name = "ReclaimUneconomicalError", this.feeSats = o, this.sweptTotalSats = a;
1369
1363
  }
1370
1364
  }
1371
- const oe = 2e3, ne = 25n, se = 100n, fr = 10n;
1372
- function Vt(e) {
1373
- const t = le.fromHex(e);
1374
- try {
1375
- t.finalizeAllInputs();
1376
- } catch (r) {
1377
- const o = r instanceof Error ? r.message : String(r);
1378
- if (!o.includes("already finalized"))
1379
- throw new Error(`Failed to finalize reclaim PSBT: ${o}`);
1365
+ const oe = 2e3, ne = 25n, se = 100n, vr = 10n;
1366
+ async function Kt(e, t, r) {
1367
+ for (let o = 0; o < e.length; o++) {
1368
+ const a = Le(e[o].depositorSignedPeginTxHex), l = ie(
1369
+ await Xe(
1370
+ v(a),
1371
+ v(r)
1372
+ )
1373
+ ).toLowerCase();
1374
+ if (l !== t[o].toLowerCase())
1375
+ throw new Error(
1376
+ `Reserve ${o} belongs to vault ${l}, not the requested ${t[o].toLowerCase()}. Refusing to sweep a reserve whose vault is not the one the caller asked for — the reserve funds that vault's claim transaction and cannot be replaced.`
1377
+ );
1380
1378
  }
1381
- return t.extractTransaction().toHex();
1382
1379
  }
1383
- async function mr(e) {
1380
+ async function Pr(e) {
1384
1381
  const {
1385
1382
  vaultIds: t,
1386
- depositorBtcPubkey: r,
1387
- readVaults: o,
1388
- feeRate: a,
1389
- signPsbt: l,
1390
- broadcastTx: s,
1383
+ depositorEthAddress: r,
1384
+ depositorBtcPubkey: o,
1385
+ readVaults: a,
1386
+ feeRate: l,
1387
+ signPsbt: s,
1388
+ broadcastTx: i,
1391
1389
  signal: n
1392
1390
  } = e;
1393
1391
  if (n == null || n.throwIfAborted(), t.length === 0)
1394
1392
  throw new Error("Reclaim requires at least one vault id; got none.");
1395
- if (!Number.isFinite(a) || a <= 0)
1396
- throw new Error(`feeRate must be a positive number, got ${a}`);
1397
- if (a > oe)
1393
+ if (!Number.isFinite(l) || l <= 0)
1394
+ throw new Error(`feeRate must be a positive number, got ${l}`);
1395
+ if (l > oe)
1398
1396
  throw new re(
1399
- `Fee rate ${a} sat/vB exceeds the reclaim safety cap of ${oe} sat/vB; refusing to sign.`,
1397
+ `Fee rate ${l} sat/vB exceeds the reclaim safety cap of ${oe} sat/vB; refusing to sign.`,
1400
1398
  0n,
1401
1399
  0n
1402
1400
  );
1403
- const i = await o();
1404
- if (n == null || n.throwIfAborted(), i.length !== t.length)
1401
+ const u = await a();
1402
+ if (n == null || n.throwIfAborted(), u.length !== t.length)
1405
1403
  throw new Error(
1406
- `readVaults returned ${i.length} reserves for ${t.length} vault id(s); refusing to sweep a set that does not match the request.`
1404
+ `readVaults returned ${u.length} reserves for ${t.length} vault id(s); refusing to sweep a set that does not match the request.`
1407
1405
  );
1408
- const u = O(r), h = i.map((v) => ({
1409
- depositorSignedPeginTxHex: v.depositorSignedPeginTxHex,
1410
- observed: v.observed,
1411
- expectedValue: v.expectedClaimValue
1412
- })), c = Fe(a, h.length), d = h.reduce((v, m) => v + m.expectedValue, 0n), p = d * ne / se;
1413
- if (c > p)
1406
+ await Kt(u, t, r), n == null || n.throwIfAborted();
1407
+ const h = O(o), c = u.map((k) => ({
1408
+ depositorSignedPeginTxHex: k.depositorSignedPeginTxHex,
1409
+ observed: k.observed,
1410
+ expectedValue: k.expectedClaimValue
1411
+ })), d = Fe(l, c.length), p = c.reduce((k, x) => k + x.expectedValue, 0n), g = p * ne / se;
1412
+ if (d > g)
1414
1413
  throw new re(
1415
- `Reclaim fee ${c} sats exceeds ${ne}/${se} of the swept total (${d} sats, cap ${p} sats). The reserve is not at risk — it stays where it is until fee rates fall.`,
1416
- c,
1417
- d
1414
+ `Reclaim fee ${d} sats exceeds ${ne}/${se} of the swept total (${p} sats, cap ${g} sats). The reserve is not at risk — it stays where it is until fee rates fall.`,
1415
+ d,
1416
+ p
1418
1417
  );
1419
1418
  n == null || n.throwIfAborted();
1420
- const { psbtHex: g } = Me({
1421
- depositorPubkey: u,
1422
- inputs: h,
1423
- feeSats: c
1419
+ const { psbtHex: P } = Me({
1420
+ depositorPubkey: h,
1421
+ inputs: c,
1422
+ feeSats: d
1424
1423
  });
1425
1424
  n == null || n.throwIfAborted();
1426
- const b = K(
1427
- r,
1428
- h.length
1429
- ), f = await l(g, b);
1425
+ const m = K(
1426
+ o,
1427
+ c.length
1428
+ ), f = await s(P, m);
1430
1429
  B({
1431
- requestedPsbtHex: g,
1430
+ requestedPsbtHex: P,
1432
1431
  returnedPsbtHex: f
1433
- }), h.forEach((v, m) => {
1432
+ });
1433
+ const w = c.map((k, x) => {
1434
1434
  const A = I(
1435
1435
  f,
1436
- u,
1437
- m
1436
+ h,
1437
+ x
1438
1438
  );
1439
- V({
1440
- requestedPsbtHex: g,
1439
+ return V({
1440
+ requestedPsbtHex: P,
1441
1441
  signatureHex: A,
1442
- signerXOnlyPubkeyHex: u,
1443
- inputIndex: m
1444
- });
1442
+ signerXOnlyPubkeyHex: h,
1443
+ inputIndex: x
1444
+ }), A;
1445
+ }), y = ce({
1446
+ requestedPsbtHex: P,
1447
+ signaturesHex: w,
1448
+ signerXOnlyPubkeyHex: h
1445
1449
  });
1446
- const P = Vt(f);
1447
- return n == null || n.throwIfAborted(), s(P);
1450
+ return n == null || n.throwIfAborted(), i(y);
1448
1451
  }
1449
1452
  export {
1450
- ft as A,
1453
+ vt as A,
1451
1454
  Q as B,
1452
- Pt as C,
1453
- vt as D,
1454
- ve as E,
1455
- hr as F,
1456
- dr as G,
1455
+ yt as C,
1456
+ bt as D,
1457
+ ye as E,
1458
+ pr as F,
1459
+ gr as G,
1457
1460
  At as H,
1458
- gr as I,
1459
- pr as J,
1461
+ mr as I,
1462
+ fr as J,
1460
1463
  te as K,
1461
1464
  ee as L,
1462
1465
  Z as M,
1463
- be as N,
1466
+ we as N,
1464
1467
  re as O,
1465
- je as P,
1466
- mr as Q,
1468
+ We as P,
1469
+ Pr as Q,
1467
1470
  Pe as R,
1468
1471
  se as S,
1469
1472
  ne as T,
1470
1473
  oe as U,
1471
- fr as V,
1472
- jt as a,
1473
- Qt as b,
1474
- he as c,
1475
- de as d,
1476
- Wt as e,
1477
- Zt as f,
1478
- rr as g,
1479
- or as h,
1480
- Je as i,
1481
- ar as j,
1482
- sr as k,
1483
- nr as l,
1484
- bt as m,
1485
- wt as n,
1486
- me as o,
1487
- ir as p,
1488
- ur as q,
1489
- Jt as r,
1490
- st as s,
1491
- lr as t,
1492
- cr as u,
1493
- tr as v,
1494
- Yt as w,
1495
- pe as x,
1496
- er as y,
1474
+ vr as V,
1475
+ Wt as a,
1476
+ Yt as b,
1477
+ de as c,
1478
+ pe as d,
1479
+ Jt as e,
1480
+ tr as f,
1481
+ nr as g,
1482
+ sr as h,
1483
+ et as i,
1484
+ ur as j,
1485
+ ir as k,
1486
+ ar as l,
1487
+ kt as m,
1488
+ Et as n,
1489
+ ve as o,
1490
+ lr as p,
1491
+ cr as q,
1492
+ er as r,
1493
+ it as s,
1494
+ hr as t,
1495
+ dr as u,
1496
+ or as v,
1497
+ Zt as w,
1498
+ ge as x,
1499
+ rr as y,
1497
1500
  D as z
1498
1501
  };
1499
- //# sourceMappingURL=buildAndBroadcastReclaim-C0TdwO2M.js.map
1502
+ //# sourceMappingURL=buildAndBroadcastReclaim-YvWDRAN8.js.map