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