@babylonlabs-io/ts-sdk 0.36.0 → 0.36.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/PeginManager-BPXVXu8t.cjs +2 -0
- package/dist/{PeginManager-cPQuJTB9.cjs.map → PeginManager-BPXVXu8t.cjs.map} +1 -1
- package/dist/{PeginManager-DF1oinIQ.js → PeginManager-CB-dVkT2.js} +387 -369
- package/dist/{PeginManager-DF1oinIQ.js.map → PeginManager-CB-dVkT2.js.map} +1 -1
- package/dist/buildAndBroadcastRefund-C2VqXiOx.js +893 -0
- package/dist/buildAndBroadcastRefund-C2VqXiOx.js.map +1 -0
- package/dist/buildAndBroadcastRefund-CBIfcF47.cjs +2 -0
- package/dist/buildAndBroadcastRefund-CBIfcF47.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +74 -70
- package/dist/tbv/core/clients/eth/types.d.ts +1 -0
- package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts +1 -0
- package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts.map +1 -1
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +67 -63
- package/dist/tbv/core/managers/PeginManager.d.ts +22 -4
- package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
- package/dist/tbv/core/managers/index.cjs +1 -1
- package/dist/tbv/core/managers/index.js +1 -1
- package/dist/tbv/core/services/deposit/__tests__/validateOnChainParticipantKeys.test.d.ts +2 -0
- package/dist/tbv/core/services/deposit/__tests__/validateOnChainParticipantKeys.test.d.ts.map +1 -0
- package/dist/tbv/core/services/deposit/__tests__/verifyRegisteredVaultVersions.test.d.ts +2 -0
- package/dist/tbv/core/services/deposit/__tests__/verifyRegisteredVaultVersions.test.d.ts.map +1 -0
- package/dist/tbv/core/services/deposit/index.d.ts +8 -12
- package/dist/tbv/core/services/deposit/index.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/validateOnChainParticipantKeys.d.ts +21 -0
- package/dist/tbv/core/services/deposit/validateOnChainParticipantKeys.d.ts.map +1 -0
- package/dist/tbv/core/services/deposit/verifyRegisteredVaultVersions.d.ts +15 -0
- package/dist/tbv/core/services/deposit/verifyRegisteredVaultVersions.d.ts.map +1 -0
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +23 -19
- package/dist/tbv/core/vault-secrets/index.d.ts +1 -0
- package/dist/tbv/core/vault-secrets/index.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +67 -63
- package/dist/tbv/integrations/aave/constants.d.ts +15 -2
- package/dist/tbv/integrations/aave/constants.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/index.cjs +1 -1
- package/dist/tbv/integrations/aave/index.cjs.map +1 -1
- package/dist/tbv/integrations/aave/index.d.ts +1 -1
- package/dist/tbv/integrations/aave/index.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/index.js +94 -93
- package/dist/tbv/integrations/aave/index.js.map +1 -1
- package/dist/{vault-registry-reader-Cufa-ZkW.cjs → vault-registry-reader-CLnhAUN4.cjs} +2 -2
- package/dist/{vault-registry-reader-Cufa-ZkW.cjs.map → vault-registry-reader-CLnhAUN4.cjs.map} +1 -1
- package/dist/{vault-registry-reader-Bz8uu0dh.js → vault-registry-reader-CrLodprY.js} +220 -190
- package/dist/{vault-registry-reader-Bz8uu0dh.js.map → vault-registry-reader-CrLodprY.js.map} +1 -1
- package/package.json +1 -1
- package/dist/PeginManager-cPQuJTB9.cjs +0 -2
- package/dist/buildAndBroadcastRefund-BQ0CaL6Q.cjs +0 -2
- package/dist/buildAndBroadcastRefund-BQ0CaL6Q.cjs.map +0 -1
- package/dist/buildAndBroadcastRefund-DzX11N9S.js +0 -785
- package/dist/buildAndBroadcastRefund-DzX11N9S.js.map +0 -1
|
@@ -0,0 +1,893 @@
|
|
|
1
|
+
var G = Object.defineProperty;
|
|
2
|
+
var W = (e, t, r) => t in e ? G(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var S = (e, t, r) => W(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { B as Q } from "./BTCVaultRegistry.abi-DbJ5lsFJ.js";
|
|
5
|
+
import { e as Y, v as j, s as c, u as N, p as k, f as m } from "./bitcoin-B0S8SHCX.js";
|
|
6
|
+
import { v as q, P as J } from "./PayoutManager-s_uH8Uuj.js";
|
|
7
|
+
import { c as Z, a as ee, R as te, d as H, D as x } from "./types-TiIjyo2b.js";
|
|
8
|
+
import * as re from "bitcoinjs-lib";
|
|
9
|
+
import { Transaction as T, Psbt as ne } from "bitcoinjs-lib";
|
|
10
|
+
import { Buffer as oe } from "buffer";
|
|
11
|
+
import { c as ae, a as se, b as ie } from "./noPayout-DBX6G96_.js";
|
|
12
|
+
import { a as ue, b as le, e as V } from "./payout-BNFMBXS6.js";
|
|
13
|
+
import { c as R } from "./signing-DaLvGwQe.js";
|
|
14
|
+
const ce = /^0x[0-9a-fA-F]{64}$/, de = /^0x[0-9a-fA-F]{40}$/, he = /^0x([0-9a-fA-F]{2})*$/;
|
|
15
|
+
function C(e, t) {
|
|
16
|
+
if (e.length !== 66)
|
|
17
|
+
throw new Error(
|
|
18
|
+
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
19
|
+
);
|
|
20
|
+
if (!ce.test(e))
|
|
21
|
+
throw new Error(
|
|
22
|
+
`${t} must contain only hex characters after the 0x prefix`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
function pe(e, t) {
|
|
26
|
+
if (!de.test(e))
|
|
27
|
+
throw new Error(
|
|
28
|
+
`${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
function fe(e, t) {
|
|
32
|
+
if (!he.test(e))
|
|
33
|
+
throw new Error(
|
|
34
|
+
`${t} must be a 0x-prefixed hex string with an even number of hex chars`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
async function nt(e) {
|
|
38
|
+
const {
|
|
39
|
+
btcVaultRegistryAddress: t,
|
|
40
|
+
vaultId: r,
|
|
41
|
+
hashlock: n,
|
|
42
|
+
activationMetadata: i,
|
|
43
|
+
writeContract: u,
|
|
44
|
+
signal: a
|
|
45
|
+
} = e;
|
|
46
|
+
a == null || a.throwIfAborted(), pe(t, "btcVaultRegistryAddress"), C(r, "vaultId");
|
|
47
|
+
const o = Y(e.secret);
|
|
48
|
+
if (C(o, "secret"), n !== void 0 && (C(n, "hashlock"), !q(o, n)))
|
|
49
|
+
throw new Error(
|
|
50
|
+
"Invalid secret: SHA256(secret) does not match the provided hashlock"
|
|
51
|
+
);
|
|
52
|
+
return fe(i, "activationMetadata"), u({
|
|
53
|
+
address: t,
|
|
54
|
+
abi: Q,
|
|
55
|
+
functionName: "activateVaultWithSecret",
|
|
56
|
+
args: [r, o, i]
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const ge = 1e4;
|
|
60
|
+
async function L(e) {
|
|
61
|
+
const {
|
|
62
|
+
statusReader: t,
|
|
63
|
+
peginTxid: r,
|
|
64
|
+
targetStatuses: n,
|
|
65
|
+
timeoutMs: i,
|
|
66
|
+
pollIntervalMs: u = ge,
|
|
67
|
+
signal: a
|
|
68
|
+
} = e, o = Date.now();
|
|
69
|
+
for (; ; ) {
|
|
70
|
+
if (a != null && a.aborted)
|
|
71
|
+
throw new Error(
|
|
72
|
+
`Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...n].join(", ")})`
|
|
73
|
+
);
|
|
74
|
+
if (Date.now() - o >= i)
|
|
75
|
+
throw new Error(
|
|
76
|
+
`Polling timeout after ${i}ms for pegin ${r.slice(0, 8)}… (target: ${[...n].join(", ")})`
|
|
77
|
+
);
|
|
78
|
+
try {
|
|
79
|
+
const s = await t.getPeginStatus(
|
|
80
|
+
{ pegin_txid: r },
|
|
81
|
+
a
|
|
82
|
+
);
|
|
83
|
+
if (s.pegin_txid.toLowerCase() !== r.toLowerCase())
|
|
84
|
+
throw new Error(
|
|
85
|
+
`getPeginStatus returned status for pegin ${s.pegin_txid.slice(0, 8)}…, requested ${r.slice(0, 8)}…`
|
|
86
|
+
);
|
|
87
|
+
const l = s.status;
|
|
88
|
+
if (n.has(l))
|
|
89
|
+
return l;
|
|
90
|
+
if (Z.has(l) && !n.has(l))
|
|
91
|
+
throw new Error(
|
|
92
|
+
`Pegin ${r.slice(0, 8)}… reached terminal status "${l}" while waiting for ${[...n].join(", ")}`
|
|
93
|
+
);
|
|
94
|
+
} catch (s) {
|
|
95
|
+
if (!(s instanceof ee && s.code === te.NOT_FOUND || s instanceof Error && s.message.includes("PegIn not found")))
|
|
96
|
+
throw s;
|
|
97
|
+
}
|
|
98
|
+
await new Promise((s, l) => {
|
|
99
|
+
const d = () => {
|
|
100
|
+
clearTimeout(h), l(
|
|
101
|
+
new Error(
|
|
102
|
+
`Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...n].join(", ")})`
|
|
103
|
+
)
|
|
104
|
+
);
|
|
105
|
+
}, h = setTimeout(() => {
|
|
106
|
+
a == null || a.removeEventListener("abort", d), s();
|
|
107
|
+
}, u);
|
|
108
|
+
a == null || a.addEventListener("abort", d, { once: !0 });
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const ye = 300 * 1e3, Pe = /* @__PURE__ */ new Set([
|
|
113
|
+
x.PENDING_DEPOSITOR_WOTS_PK,
|
|
114
|
+
...H
|
|
115
|
+
]);
|
|
116
|
+
async function ot(e) {
|
|
117
|
+
const {
|
|
118
|
+
statusReader: t,
|
|
119
|
+
wotsSubmitter: r,
|
|
120
|
+
peginTxid: n,
|
|
121
|
+
depositorPk: i,
|
|
122
|
+
wotsPublicKeys: u,
|
|
123
|
+
timeoutMs: a = ye,
|
|
124
|
+
signal: o
|
|
125
|
+
} = e;
|
|
126
|
+
o == null || o.throwIfAborted();
|
|
127
|
+
const s = await L({
|
|
128
|
+
statusReader: t,
|
|
129
|
+
peginTxid: n,
|
|
130
|
+
targetStatuses: Pe,
|
|
131
|
+
timeoutMs: a,
|
|
132
|
+
signal: o
|
|
133
|
+
});
|
|
134
|
+
H.has(s) || (o == null || o.throwIfAborted(), await r.submitDepositorWotsKey(
|
|
135
|
+
{
|
|
136
|
+
pegin_txid: n,
|
|
137
|
+
depositor_pk: i,
|
|
138
|
+
wots_public_keys: u
|
|
139
|
+
},
|
|
140
|
+
o
|
|
141
|
+
));
|
|
142
|
+
}
|
|
143
|
+
const I = 1;
|
|
144
|
+
function me(e, t, r) {
|
|
145
|
+
const n = c(r).toLowerCase(), u = [e, ...t].map(
|
|
146
|
+
(a) => c(a).toLowerCase()
|
|
147
|
+
).filter((a) => a !== n);
|
|
148
|
+
if (u.length === 0)
|
|
149
|
+
throw new Error(
|
|
150
|
+
"Cannot derive localChallengers: removing depositor from {vaultProvider, vaultKeepers} left an empty set"
|
|
151
|
+
);
|
|
152
|
+
if (new Set(u).size !== u.length)
|
|
153
|
+
throw new Error(
|
|
154
|
+
"Cannot derive localChallengers: vaultProvider key duplicates a vaultKeeper key — signing context is misconfigured"
|
|
155
|
+
);
|
|
156
|
+
return u;
|
|
157
|
+
}
|
|
158
|
+
function be(e, t) {
|
|
159
|
+
const r = e.map(
|
|
160
|
+
(o) => c(o.challenger_pubkey).toLowerCase()
|
|
161
|
+
), n = new Set(r);
|
|
162
|
+
if (n.size !== r.length)
|
|
163
|
+
throw new Error(
|
|
164
|
+
"Depositor graph contains duplicate challenger entries in challenger_presign_data"
|
|
165
|
+
);
|
|
166
|
+
const i = new Set(t), u = t.filter((o) => !n.has(o)), a = r.filter((o) => !i.has(o));
|
|
167
|
+
if (u.length > 0 || a.length > 0)
|
|
168
|
+
throw new Error(
|
|
169
|
+
"Depositor graph challenger set does not match localChallengers" + (u.length > 0 ? ` (missing: ${u.join(", ")})` : "") + (a.length > 0 ? ` (unexpected: ${a.join(", ")})` : "")
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
function we(e, t) {
|
|
173
|
+
const r = e.ins[t];
|
|
174
|
+
return N(new Uint8Array(r.hash).slice().reverse());
|
|
175
|
+
}
|
|
176
|
+
function B(e, t, r, n, i) {
|
|
177
|
+
const u = e.ins[t];
|
|
178
|
+
if (u.index !== 0)
|
|
179
|
+
throw new Error(
|
|
180
|
+
`NoPayout (challenger ${i}) input ${t} expected to spend ${n} vout 0, got vout ${u.index}`
|
|
181
|
+
);
|
|
182
|
+
const a = r.getId(), o = we(e, t);
|
|
183
|
+
if (o !== a)
|
|
184
|
+
throw new Error(
|
|
185
|
+
`NoPayout (challenger ${i}) input ${t} does not reference ${n} (expected txid ${a}, got ${o})`
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
async function ve(e, t, r) {
|
|
189
|
+
const n = [], i = [], u = [], a = me(
|
|
190
|
+
r.vaultProviderBtcPubkey,
|
|
191
|
+
r.vaultKeeperBtcPubkeys,
|
|
192
|
+
r.depositorBtcPubkey
|
|
193
|
+
);
|
|
194
|
+
be(
|
|
195
|
+
e.challenger_presign_data,
|
|
196
|
+
a
|
|
197
|
+
), ue(
|
|
198
|
+
e.payout_tx.tx_hex,
|
|
199
|
+
r.registeredPayoutScriptPubKey
|
|
200
|
+
);
|
|
201
|
+
const o = await le({
|
|
202
|
+
payoutTxHex: e.payout_tx.tx_hex,
|
|
203
|
+
peginTxHex: r.peginTxHex,
|
|
204
|
+
assertTxHex: e.assert_tx.tx_hex,
|
|
205
|
+
depositorBtcPubkey: r.depositorBtcPubkey,
|
|
206
|
+
vaultProviderBtcPubkey: r.vaultProviderBtcPubkey,
|
|
207
|
+
vaultKeeperBtcPubkeys: r.vaultKeeperBtcPubkeys,
|
|
208
|
+
universalChallengerBtcPubkeys: r.universalChallengerBtcPubkeys,
|
|
209
|
+
timelockPegin: r.timelockPegin,
|
|
210
|
+
network: r.network
|
|
211
|
+
});
|
|
212
|
+
n.push(o.psbtHex), i.push(
|
|
213
|
+
R(
|
|
214
|
+
t,
|
|
215
|
+
I
|
|
216
|
+
)
|
|
217
|
+
);
|
|
218
|
+
const s = c(r.depositorBtcPubkey), l = T.fromHex(
|
|
219
|
+
c(e.assert_tx.tx_hex)
|
|
220
|
+
);
|
|
221
|
+
for (const d of e.challenger_presign_data) {
|
|
222
|
+
const h = c(d.challenger_pubkey), y = n.length, P = await xe({
|
|
223
|
+
challenger: d,
|
|
224
|
+
challengerPubkey: h,
|
|
225
|
+
claimerPubkey: s,
|
|
226
|
+
localChallengers: a,
|
|
227
|
+
assertTxParsed: l,
|
|
228
|
+
ctx: r
|
|
229
|
+
});
|
|
230
|
+
n.push(P), i.push(
|
|
231
|
+
R(
|
|
232
|
+
t,
|
|
233
|
+
I
|
|
234
|
+
)
|
|
235
|
+
), u.push({
|
|
236
|
+
challengerPubkey: h,
|
|
237
|
+
noPayoutIdx: y
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
return { psbtHexes: n, signOptions: i, challengerEntries: u };
|
|
241
|
+
}
|
|
242
|
+
async function xe(e) {
|
|
243
|
+
const {
|
|
244
|
+
challenger: t,
|
|
245
|
+
challengerPubkey: r,
|
|
246
|
+
claimerPubkey: n,
|
|
247
|
+
localChallengers: i,
|
|
248
|
+
assertTxParsed: u,
|
|
249
|
+
ctx: a
|
|
250
|
+
} = e;
|
|
251
|
+
ae(
|
|
252
|
+
t.nopayout_tx.tx_hex,
|
|
253
|
+
r,
|
|
254
|
+
a.network
|
|
255
|
+
);
|
|
256
|
+
const o = T.fromHex(
|
|
257
|
+
c(t.nopayout_tx.tx_hex)
|
|
258
|
+
), s = T.fromHex(
|
|
259
|
+
c(t.challenge_assert_x_tx.tx_hex)
|
|
260
|
+
), l = T.fromHex(
|
|
261
|
+
c(t.challenge_assert_y_tx.tx_hex)
|
|
262
|
+
);
|
|
263
|
+
if (o.ins.length !== 3)
|
|
264
|
+
throw new Error(
|
|
265
|
+
`NoPayout (challenger ${r}) must have exactly 3 inputs, got ${o.ins.length}`
|
|
266
|
+
);
|
|
267
|
+
B(
|
|
268
|
+
o,
|
|
269
|
+
0,
|
|
270
|
+
u,
|
|
271
|
+
"Assert",
|
|
272
|
+
r
|
|
273
|
+
), B(
|
|
274
|
+
o,
|
|
275
|
+
1,
|
|
276
|
+
s,
|
|
277
|
+
"ChallengeAssertX",
|
|
278
|
+
r
|
|
279
|
+
), B(
|
|
280
|
+
o,
|
|
281
|
+
2,
|
|
282
|
+
l,
|
|
283
|
+
"ChallengeAssertY",
|
|
284
|
+
r
|
|
285
|
+
);
|
|
286
|
+
const d = [
|
|
287
|
+
u.outs[0],
|
|
288
|
+
s.outs[0],
|
|
289
|
+
l.outs[0]
|
|
290
|
+
].map((h) => ({
|
|
291
|
+
script_pubkey: N(new Uint8Array(h.script)),
|
|
292
|
+
value: h.value
|
|
293
|
+
}));
|
|
294
|
+
return se({
|
|
295
|
+
noPayoutTxHex: t.nopayout_tx.tx_hex,
|
|
296
|
+
challengerPubkey: r,
|
|
297
|
+
prevouts: d,
|
|
298
|
+
connectorParams: {
|
|
299
|
+
claimer: n,
|
|
300
|
+
localChallengers: i,
|
|
301
|
+
universalChallengers: a.universalChallengerBtcPubkeys,
|
|
302
|
+
timelockAssert: a.timelockAssert,
|
|
303
|
+
councilMembers: a.councilMembers,
|
|
304
|
+
councilQuorum: a.councilQuorum
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
function ke(e, t, r) {
|
|
309
|
+
const n = V(
|
|
310
|
+
e[0],
|
|
311
|
+
r
|
|
312
|
+
), i = {};
|
|
313
|
+
for (const u of t)
|
|
314
|
+
i[u.challengerPubkey] = {
|
|
315
|
+
nopayout_signature: V(
|
|
316
|
+
e[u.noPayoutIdx],
|
|
317
|
+
r
|
|
318
|
+
)
|
|
319
|
+
};
|
|
320
|
+
return {
|
|
321
|
+
payout_signatures: {
|
|
322
|
+
payout_signature: n
|
|
323
|
+
},
|
|
324
|
+
per_challenger: i
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
async function Te(e, t, r) {
|
|
328
|
+
if (typeof e.signPsbts == "function")
|
|
329
|
+
return e.signPsbts(t, r);
|
|
330
|
+
const n = [];
|
|
331
|
+
for (let i = 0; i < t.length; i++)
|
|
332
|
+
n.push(await e.signPsbt(t[i], r == null ? void 0 : r[i]));
|
|
333
|
+
return n;
|
|
334
|
+
}
|
|
335
|
+
async function Ee(e) {
|
|
336
|
+
const { depositorGraph: t, btcWallet: r, signingContext: n } = e, i = await r.getPublicKeyHex(), { depositorPubkey: u } = j(
|
|
337
|
+
i,
|
|
338
|
+
c(n.depositorBtcPubkey)
|
|
339
|
+
), { psbtHexes: a, signOptions: o, challengerEntries: s } = await ve(
|
|
340
|
+
t,
|
|
341
|
+
i,
|
|
342
|
+
n
|
|
343
|
+
), l = await Te(
|
|
344
|
+
r,
|
|
345
|
+
a,
|
|
346
|
+
o
|
|
347
|
+
);
|
|
348
|
+
if (l.length !== a.length)
|
|
349
|
+
throw new Error(
|
|
350
|
+
`Wallet returned ${l.length} signed PSBTs, expected ${a.length}`
|
|
351
|
+
);
|
|
352
|
+
return ke(
|
|
353
|
+
l,
|
|
354
|
+
s,
|
|
355
|
+
u
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
const _e = 1200 * 1e3, D = /* @__PURE__ */ new Set([
|
|
359
|
+
x.PENDING_ACKS,
|
|
360
|
+
x.PENDING_ACTIVATION,
|
|
361
|
+
x.ACTIVATED
|
|
362
|
+
]), Se = /* @__PURE__ */ new Set([
|
|
363
|
+
x.PENDING_DEPOSITOR_SIGNATURES,
|
|
364
|
+
...D
|
|
365
|
+
]);
|
|
366
|
+
function Ce(e) {
|
|
367
|
+
return e.map((t) => ({
|
|
368
|
+
claimerPubkeyXOnly: k(t.claimer_pubkey),
|
|
369
|
+
payoutTxHex: t.payout_tx.tx_hex,
|
|
370
|
+
assertTxHex: t.assert_tx.tx_hex
|
|
371
|
+
}));
|
|
372
|
+
}
|
|
373
|
+
function Be(e) {
|
|
374
|
+
const { output: t } = re.payments.p2tr({
|
|
375
|
+
internalPubkey: oe.from(e, "hex")
|
|
376
|
+
});
|
|
377
|
+
if (!t)
|
|
378
|
+
throw new Error("Failed to derive BIP-86 P2TR scriptPubKey");
|
|
379
|
+
return t.toString("hex");
|
|
380
|
+
}
|
|
381
|
+
function Ae(e, t) {
|
|
382
|
+
const r = c(e).toLowerCase(), n = c(
|
|
383
|
+
t.vaultProviderBtcPubkey
|
|
384
|
+
).toLowerCase(), i = c(
|
|
385
|
+
t.depositorBtcPubkey
|
|
386
|
+
).toLowerCase();
|
|
387
|
+
if (r === n || r === i)
|
|
388
|
+
return t.registeredPayoutScriptPubKey;
|
|
389
|
+
if (!t.vaultKeeperBtcPubkeys.some(
|
|
390
|
+
(o) => c(o).toLowerCase() === r
|
|
391
|
+
))
|
|
392
|
+
throw new Error(
|
|
393
|
+
`Unknown claimer pubkey ${r}: not VP, depositor, or a registered vault keeper`
|
|
394
|
+
);
|
|
395
|
+
return `0x${Be(r)}`;
|
|
396
|
+
}
|
|
397
|
+
function K(e, t) {
|
|
398
|
+
return {
|
|
399
|
+
payoutTxHex: e.payoutTxHex,
|
|
400
|
+
peginTxHex: t.peginTxHex,
|
|
401
|
+
assertTxHex: e.assertTxHex,
|
|
402
|
+
vaultProviderBtcPubkey: t.vaultProviderBtcPubkey,
|
|
403
|
+
vaultKeeperBtcPubkeys: t.vaultKeeperBtcPubkeys,
|
|
404
|
+
universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys,
|
|
405
|
+
depositorBtcPubkey: t.depositorBtcPubkey,
|
|
406
|
+
timelockPegin: t.timelockPegin,
|
|
407
|
+
registeredPayoutScriptPubKey: Ae(
|
|
408
|
+
e.claimerPubkeyXOnly,
|
|
409
|
+
t
|
|
410
|
+
)
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
async function Re(e, t, r, n) {
|
|
414
|
+
const i = new J({
|
|
415
|
+
network: t.network,
|
|
416
|
+
btcWallet: e
|
|
417
|
+
}), u = r.length;
|
|
418
|
+
n == null || n(0, u);
|
|
419
|
+
let a;
|
|
420
|
+
if (i.supportsBatchSigning())
|
|
421
|
+
a = (await i.signPayoutTransactionsBatch(
|
|
422
|
+
r.map((l) => K(l, t))
|
|
423
|
+
)).map((l) => l.payoutSignature);
|
|
424
|
+
else {
|
|
425
|
+
a = [];
|
|
426
|
+
for (let s = 0; s < r.length; s++) {
|
|
427
|
+
n == null || n(s, u);
|
|
428
|
+
const l = await i.signPayoutTransaction(
|
|
429
|
+
K(r[s], t)
|
|
430
|
+
);
|
|
431
|
+
a.push(l.signature);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
const o = {};
|
|
435
|
+
for (let s = 0; s < r.length; s++)
|
|
436
|
+
o[r[s].claimerPubkeyXOnly] = {
|
|
437
|
+
payout_signature: a[s]
|
|
438
|
+
};
|
|
439
|
+
return n == null || n(u, u), o;
|
|
440
|
+
}
|
|
441
|
+
async function at(e) {
|
|
442
|
+
const {
|
|
443
|
+
statusReader: t,
|
|
444
|
+
presignClient: r,
|
|
445
|
+
btcWallet: n,
|
|
446
|
+
peginTxid: i,
|
|
447
|
+
depositorPk: u,
|
|
448
|
+
signingContext: a,
|
|
449
|
+
timeoutMs: o = _e,
|
|
450
|
+
signal: s,
|
|
451
|
+
onProgress: l
|
|
452
|
+
} = e, d = await L({
|
|
453
|
+
statusReader: t,
|
|
454
|
+
peginTxid: i,
|
|
455
|
+
targetStatuses: Se,
|
|
456
|
+
timeoutMs: o,
|
|
457
|
+
signal: s
|
|
458
|
+
});
|
|
459
|
+
if (D.has(d))
|
|
460
|
+
return;
|
|
461
|
+
s == null || s.throwIfAborted();
|
|
462
|
+
const h = await r.requestDepositorPresignTransactions(
|
|
463
|
+
{
|
|
464
|
+
pegin_txid: i,
|
|
465
|
+
depositor_pk: u
|
|
466
|
+
},
|
|
467
|
+
s
|
|
468
|
+
);
|
|
469
|
+
s == null || s.throwIfAborted();
|
|
470
|
+
const y = k(u), P = h.txs.filter(
|
|
471
|
+
(v) => k(v.claimer_pubkey) !== y
|
|
472
|
+
), b = Ce(P), f = await Re(
|
|
473
|
+
n,
|
|
474
|
+
a,
|
|
475
|
+
b,
|
|
476
|
+
l
|
|
477
|
+
);
|
|
478
|
+
s == null || s.throwIfAborted();
|
|
479
|
+
const g = await Ee({
|
|
480
|
+
depositorGraph: h.depositor_graph,
|
|
481
|
+
btcWallet: n,
|
|
482
|
+
signingContext: {
|
|
483
|
+
peginTxHex: a.peginTxHex,
|
|
484
|
+
depositorBtcPubkey: u,
|
|
485
|
+
vaultProviderBtcPubkey: a.vaultProviderBtcPubkey,
|
|
486
|
+
vaultKeeperBtcPubkeys: a.vaultKeeperBtcPubkeys,
|
|
487
|
+
universalChallengerBtcPubkeys: a.universalChallengerBtcPubkeys,
|
|
488
|
+
timelockPegin: a.timelockPegin,
|
|
489
|
+
timelockAssert: a.timelockAssert,
|
|
490
|
+
councilMembers: a.councilMembers,
|
|
491
|
+
councilQuorum: a.councilQuorum,
|
|
492
|
+
network: a.network,
|
|
493
|
+
registeredPayoutScriptPubKey: a.registeredPayoutScriptPubKey
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
s == null || s.throwIfAborted();
|
|
497
|
+
const w = { ...f };
|
|
498
|
+
w[c(u)] = g.payout_signatures, await r.submitDepositorPresignatures(
|
|
499
|
+
{
|
|
500
|
+
pegin_txid: i,
|
|
501
|
+
depositor_pk: u,
|
|
502
|
+
signatures: w,
|
|
503
|
+
depositor_claimer_presignatures: g
|
|
504
|
+
},
|
|
505
|
+
s
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
function $e(e) {
|
|
509
|
+
return /^[0-9a-fA-F]{64}$/.test(e);
|
|
510
|
+
}
|
|
511
|
+
function st(e) {
|
|
512
|
+
const {
|
|
513
|
+
amountSats: t,
|
|
514
|
+
minDeposit: r,
|
|
515
|
+
maxDeposit: n,
|
|
516
|
+
btcBalance: i,
|
|
517
|
+
estimatedFeeSats: u,
|
|
518
|
+
depositorClaimValue: a
|
|
519
|
+
} = e;
|
|
520
|
+
return !(t <= 0n || t < r || n && n > 0n && t > n || u == null || a == null || t + u + a > i);
|
|
521
|
+
}
|
|
522
|
+
function it(e, t, r) {
|
|
523
|
+
return e <= 0n ? {
|
|
524
|
+
valid: !1,
|
|
525
|
+
error: "Deposit amount must be greater than zero"
|
|
526
|
+
} : e < t ? {
|
|
527
|
+
valid: !1,
|
|
528
|
+
error: `Minimum deposit is ${m(t)} BTC`
|
|
529
|
+
} : r && r > 0n && e > r ? {
|
|
530
|
+
valid: !1,
|
|
531
|
+
error: `Maximum deposit is ${m(r)} BTC`
|
|
532
|
+
} : { valid: !0 };
|
|
533
|
+
}
|
|
534
|
+
function ut(e) {
|
|
535
|
+
const { amount: t, effectiveRemaining: r } = e;
|
|
536
|
+
return r === null ? { valid: !0 } : r === 0n ? {
|
|
537
|
+
valid: !1,
|
|
538
|
+
error: "Supply cap reached — deposits temporarily paused"
|
|
539
|
+
} : t > r ? {
|
|
540
|
+
valid: !1,
|
|
541
|
+
error: `Vault size exceeds remaining capacity (${m(r)} BTC)`
|
|
542
|
+
} : { valid: !0 };
|
|
543
|
+
}
|
|
544
|
+
function lt(e, t) {
|
|
545
|
+
if (!e || e.length === 0)
|
|
546
|
+
return {
|
|
547
|
+
valid: !1,
|
|
548
|
+
error: "At least one vault provider must be selected"
|
|
549
|
+
};
|
|
550
|
+
const r = t.map(
|
|
551
|
+
(i) => i.toLowerCase()
|
|
552
|
+
);
|
|
553
|
+
return e.filter(
|
|
554
|
+
(i) => !r.includes(i.toLowerCase())
|
|
555
|
+
).length > 0 ? {
|
|
556
|
+
valid: !1,
|
|
557
|
+
error: "Invalid vault provider selected"
|
|
558
|
+
} : { valid: !0 };
|
|
559
|
+
}
|
|
560
|
+
function Ve(e, t, r) {
|
|
561
|
+
if (!e || e.length === 0)
|
|
562
|
+
return {
|
|
563
|
+
valid: !1,
|
|
564
|
+
error: "At least one vault amount required"
|
|
565
|
+
};
|
|
566
|
+
for (let n = 0; n < e.length; n++) {
|
|
567
|
+
const i = e[n];
|
|
568
|
+
if (i <= 0n)
|
|
569
|
+
return {
|
|
570
|
+
valid: !1,
|
|
571
|
+
error: `Vault ${n + 1} amount must be positive`
|
|
572
|
+
};
|
|
573
|
+
if (t && i < t)
|
|
574
|
+
return {
|
|
575
|
+
valid: !1,
|
|
576
|
+
error: `Vault ${n + 1} amount ${m(i)} BTC is below minimum deposit ${m(t)} BTC`
|
|
577
|
+
};
|
|
578
|
+
if (r && i > r)
|
|
579
|
+
return {
|
|
580
|
+
valid: !1,
|
|
581
|
+
error: `Vault ${n + 1} amount ${m(i)} BTC exceeds maximum deposit ${m(r)} BTC`
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
return { valid: !0 };
|
|
585
|
+
}
|
|
586
|
+
function Ie(e) {
|
|
587
|
+
const t = c(e);
|
|
588
|
+
return $e(t) ? { valid: !0 } : {
|
|
589
|
+
valid: !1,
|
|
590
|
+
error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
function Ke(e) {
|
|
594
|
+
if (!e || e.length === 0)
|
|
595
|
+
throw new Error(
|
|
596
|
+
"No vault keepers available. The system requires at least one vault keeper to create a deposit."
|
|
597
|
+
);
|
|
598
|
+
}
|
|
599
|
+
function Oe(e) {
|
|
600
|
+
if (!e || e.length === 0)
|
|
601
|
+
throw new Error(
|
|
602
|
+
"No universal challengers available. The system requires at least one universal challenger to create a deposit."
|
|
603
|
+
);
|
|
604
|
+
}
|
|
605
|
+
function Ne(e) {
|
|
606
|
+
if (e.length === 0)
|
|
607
|
+
throw new Error("No spendable UTXOs available");
|
|
608
|
+
}
|
|
609
|
+
function ct(e) {
|
|
610
|
+
const {
|
|
611
|
+
vaultAmounts: t,
|
|
612
|
+
confirmedUTXOs: r,
|
|
613
|
+
vaultProviderBtcPubkey: n,
|
|
614
|
+
vaultKeeperBtcPubkeys: i,
|
|
615
|
+
universalChallengerBtcPubkeys: u,
|
|
616
|
+
minDeposit: a,
|
|
617
|
+
maxDeposit: o
|
|
618
|
+
} = e, s = Ve(
|
|
619
|
+
t,
|
|
620
|
+
a,
|
|
621
|
+
o
|
|
622
|
+
);
|
|
623
|
+
if (!s.valid)
|
|
624
|
+
throw new Error(s.error);
|
|
625
|
+
const l = Ie(n);
|
|
626
|
+
if (!l.valid)
|
|
627
|
+
throw new Error(l.error);
|
|
628
|
+
Ke(i), Oe(u), Ne(r);
|
|
629
|
+
}
|
|
630
|
+
async function dt(e) {
|
|
631
|
+
const {
|
|
632
|
+
vaultRegistryReader: t,
|
|
633
|
+
vaultKeeperReader: r,
|
|
634
|
+
universalChallengerReader: n,
|
|
635
|
+
vaultProviderEthAddress: i,
|
|
636
|
+
applicationEntryPoint: u,
|
|
637
|
+
expectedVaultProviderBtcPubkey: a,
|
|
638
|
+
expectedVaultKeeperBtcPubkeys: o,
|
|
639
|
+
expectedUniversalChallengerBtcPubkeys: s
|
|
640
|
+
} = e, [
|
|
641
|
+
l,
|
|
642
|
+
d,
|
|
643
|
+
h
|
|
644
|
+
] = await Promise.all([
|
|
645
|
+
t.getVaultProviderBtcPubKey(i),
|
|
646
|
+
r.getCurrentVaultKeepersVersion(u),
|
|
647
|
+
n.getLatestUniversalChallengersVersion()
|
|
648
|
+
]), [y, P] = await Promise.all([
|
|
649
|
+
r.getVaultKeepersByVersion(
|
|
650
|
+
u,
|
|
651
|
+
d
|
|
652
|
+
),
|
|
653
|
+
n.getUniversalChallengersByVersion(
|
|
654
|
+
h
|
|
655
|
+
)
|
|
656
|
+
]), b = (p) => k(p).toLowerCase(), f = (p) => p.map(b).sort();
|
|
657
|
+
if (b(a) !== l)
|
|
658
|
+
throw new Error(
|
|
659
|
+
`Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${i}. Refresh and try again.`
|
|
660
|
+
);
|
|
661
|
+
const w = f(o), v = f(
|
|
662
|
+
y.map((p) => p.btcPubKey)
|
|
663
|
+
);
|
|
664
|
+
if (w.length !== v.length || w.some((p, _) => p !== v[_]))
|
|
665
|
+
throw new Error(
|
|
666
|
+
`Vault keeper BTC pubkeys (v${d}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
|
|
667
|
+
);
|
|
668
|
+
const $ = f(s), E = f(
|
|
669
|
+
P.map((p) => p.btcPubKey)
|
|
670
|
+
);
|
|
671
|
+
if ($.length !== E.length || $.some((p, _) => p !== E[_]))
|
|
672
|
+
throw new Error(
|
|
673
|
+
`Universal challenger BTC pubkeys (v${h}) indexer set does not match ProtocolParams on-chain set. Refresh and try again.`
|
|
674
|
+
);
|
|
675
|
+
return {
|
|
676
|
+
vaultProviderBtcPubkeyXOnly: l,
|
|
677
|
+
vaultKeeperBtcPubkeysSorted: v,
|
|
678
|
+
universalChallengerBtcPubkeysSorted: E,
|
|
679
|
+
expectedAppVaultKeepersVersion: d,
|
|
680
|
+
expectedUniversalChallengersVersion: h
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
class M extends Error {
|
|
684
|
+
constructor(t) {
|
|
685
|
+
super(t), this.name = "RegisteredVaultVersionMismatchError";
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
function ht(e) {
|
|
689
|
+
return e instanceof M || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
|
|
690
|
+
}
|
|
691
|
+
async function pt(e) {
|
|
692
|
+
const {
|
|
693
|
+
vaultRegistryReader: t,
|
|
694
|
+
vaultIds: r,
|
|
695
|
+
expectedOffchainParamsVersion: n,
|
|
696
|
+
expectedAppVaultKeepersVersion: i,
|
|
697
|
+
expectedUniversalChallengersVersion: u
|
|
698
|
+
} = e, a = await t.getProtocolInfoBatch(r), o = [];
|
|
699
|
+
if (a.forEach((s, l) => {
|
|
700
|
+
const d = r[l];
|
|
701
|
+
s.offchainParamsVersion !== n && o.push(
|
|
702
|
+
`vault ${d}: offchainParams expected v${n}, got v${s.offchainParamsVersion}`
|
|
703
|
+
), s.appVaultKeepersVersion !== i && o.push(
|
|
704
|
+
`vault ${d}: appVaultKeepers expected v${i}, got v${s.appVaultKeepersVersion}`
|
|
705
|
+
), s.universalChallengersVersion !== u && o.push(
|
|
706
|
+
`vault ${d}: universalChallengers expected v${u}, got v${s.universalChallengersVersion}`
|
|
707
|
+
);
|
|
708
|
+
}), o.length > 0)
|
|
709
|
+
throw new M(
|
|
710
|
+
`Aborting BTC broadcast: signer-set or offchain-params versions changed during registration (${o.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
|
|
711
|
+
);
|
|
712
|
+
}
|
|
713
|
+
var U = /* @__PURE__ */ ((e) => (e.CLAIM_EVENT_RECEIVED = "ClaimEventReceived", e.CLAIM_BROADCAST = "ClaimBroadcast", e.ASSERT_BROADCAST = "AssertBroadcast", e.CHALLENGE_ASSERT_OBSERVED = "ChallengeAssertObserved", e.WRONGLY_CHALLENGED_BROADCAST = "WronglyChallengedBroadcast", e.PAYOUT_BROADCAST = "PayoutBroadcast", e.FAILED = "Failed", e))(U || {});
|
|
714
|
+
const He = /* @__PURE__ */ new Set([
|
|
715
|
+
"PayoutBroadcast",
|
|
716
|
+
"Failed"
|
|
717
|
+
/* FAILED */
|
|
718
|
+
]);
|
|
719
|
+
function ft(e) {
|
|
720
|
+
return Object.values(U).includes(
|
|
721
|
+
e
|
|
722
|
+
);
|
|
723
|
+
}
|
|
724
|
+
function gt(e) {
|
|
725
|
+
return !!e && He.has(e);
|
|
726
|
+
}
|
|
727
|
+
class Le extends Error {
|
|
728
|
+
constructor(r, n) {
|
|
729
|
+
super(`Refund not yet mature (BIP68 not final): ${n.message}`);
|
|
730
|
+
S(this, "vaultId");
|
|
731
|
+
S(this, "cause");
|
|
732
|
+
this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = n;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
const De = /^0x[0-9a-fA-F]{64}$/, Me = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, F = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, X = 160;
|
|
736
|
+
function yt(e) {
|
|
737
|
+
if (!Number.isFinite(e) || e <= 0)
|
|
738
|
+
throw new Error(
|
|
739
|
+
`feeRateSatsVb must be a positive finite number, got ${e}`
|
|
740
|
+
);
|
|
741
|
+
return BigInt(Math.ceil(e * X));
|
|
742
|
+
}
|
|
743
|
+
const Ue = 1, O = 65535, Fe = /non-BIP68-final/i;
|
|
744
|
+
function z(e, t) {
|
|
745
|
+
if (e.length !== 66)
|
|
746
|
+
throw new Error(
|
|
747
|
+
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
748
|
+
);
|
|
749
|
+
if (!De.test(e))
|
|
750
|
+
throw new Error(
|
|
751
|
+
`${t} must contain only hex characters after the 0x prefix`
|
|
752
|
+
);
|
|
753
|
+
}
|
|
754
|
+
function A(e, t) {
|
|
755
|
+
if (!Number.isInteger(e) || e < 0)
|
|
756
|
+
throw new Error(`${t} must be a non-negative integer, got ${e}`);
|
|
757
|
+
}
|
|
758
|
+
function Xe(e) {
|
|
759
|
+
if (z(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0 || e.htlcVout > O)
|
|
760
|
+
throw new Error(
|
|
761
|
+
`htlcVout must be an integer 0-${O}, got ${e.htlcVout}`
|
|
762
|
+
);
|
|
763
|
+
if (A(e.offchainParamsVersion, "offchainParamsVersion"), A(e.appVaultKeepersVersion, "appVaultKeepersVersion"), A(
|
|
764
|
+
e.universalChallengersVersion,
|
|
765
|
+
"universalChallengersVersion"
|
|
766
|
+
), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
|
|
767
|
+
throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
|
|
768
|
+
if (!Me.test(e.unsignedPrePeginTxHex))
|
|
769
|
+
throw new Error(
|
|
770
|
+
"unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
|
|
771
|
+
);
|
|
772
|
+
if (!e.depositorBtcPubkey || !F.test(e.depositorBtcPubkey))
|
|
773
|
+
throw new Error(
|
|
774
|
+
"depositorBtcPubkey must be 32 or 33 bytes of hex (optional 0x prefix)"
|
|
775
|
+
);
|
|
776
|
+
if (typeof e.amount != "bigint" || e.amount <= 0n)
|
|
777
|
+
throw new Error(`amount must be a positive bigint, got ${e.amount}`);
|
|
778
|
+
}
|
|
779
|
+
function ze(e) {
|
|
780
|
+
if (!e.vaultProviderPubkey || !F.test(e.vaultProviderPubkey))
|
|
781
|
+
throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
|
|
782
|
+
if (e.vaultKeeperPubkeys.length === 0)
|
|
783
|
+
throw new Error("vaultKeeperPubkeys must be non-empty");
|
|
784
|
+
if (e.universalChallengerPubkeys.length === 0)
|
|
785
|
+
throw new Error("universalChallengerPubkeys must be non-empty");
|
|
786
|
+
if (!Number.isInteger(e.timelockRefund) || e.timelockRefund <= 0)
|
|
787
|
+
throw new Error(
|
|
788
|
+
`timelockRefund must be a positive integer, got ${e.timelockRefund}`
|
|
789
|
+
);
|
|
790
|
+
if (typeof e.feeRate != "bigint" || e.feeRate <= 0n)
|
|
791
|
+
throw new Error(
|
|
792
|
+
`protocol feeRate must be a positive bigint, got ${e.feeRate}`
|
|
793
|
+
);
|
|
794
|
+
if (!Number.isInteger(e.numLocalChallengers) || e.numLocalChallengers < 0)
|
|
795
|
+
throw new Error("numLocalChallengers must be a non-negative integer");
|
|
796
|
+
if (!Number.isInteger(e.councilQuorum) || !Number.isInteger(e.councilSize) || e.councilQuorum <= 0 || e.councilSize <= 0 || e.councilQuorum > e.councilSize)
|
|
797
|
+
throw new Error(
|
|
798
|
+
`councilQuorum (${e.councilQuorum}) must be in [1, councilSize=${e.councilSize}]`
|
|
799
|
+
);
|
|
800
|
+
}
|
|
801
|
+
function Ge(e) {
|
|
802
|
+
const t = ne.fromHex(e);
|
|
803
|
+
try {
|
|
804
|
+
t.finalizeAllInputs();
|
|
805
|
+
} catch (r) {
|
|
806
|
+
const n = r instanceof Error ? r.message : String(r);
|
|
807
|
+
if (!n.includes("already finalized"))
|
|
808
|
+
throw new Error(`Failed to finalize refund PSBT: ${n}`);
|
|
809
|
+
}
|
|
810
|
+
return t.extractTransaction().toHex();
|
|
811
|
+
}
|
|
812
|
+
async function Pt(e) {
|
|
813
|
+
const {
|
|
814
|
+
vaultId: t,
|
|
815
|
+
readVault: r,
|
|
816
|
+
readPrePeginContext: n,
|
|
817
|
+
feeRate: i,
|
|
818
|
+
signPsbt: u,
|
|
819
|
+
broadcastTx: a,
|
|
820
|
+
signal: o
|
|
821
|
+
} = e;
|
|
822
|
+
o == null || o.throwIfAborted(), z(t, "vaultId");
|
|
823
|
+
const s = await r();
|
|
824
|
+
Xe(s), o == null || o.throwIfAborted();
|
|
825
|
+
const l = await n(s);
|
|
826
|
+
if (ze(l), o == null || o.throwIfAborted(), !Number.isFinite(i) || i <= 0)
|
|
827
|
+
throw new Error(`feeRate must be a positive number, got ${i}`);
|
|
828
|
+
const d = BigInt(Math.ceil(i * X));
|
|
829
|
+
o == null || o.throwIfAborted();
|
|
830
|
+
const h = k(
|
|
831
|
+
s.depositorBtcPubkey
|
|
832
|
+
), { psbtHex: y } = await ie({
|
|
833
|
+
prePeginParams: {
|
|
834
|
+
depositorPubkey: h,
|
|
835
|
+
vaultProviderPubkey: c(l.vaultProviderPubkey),
|
|
836
|
+
vaultKeeperPubkeys: l.vaultKeeperPubkeys.map(c),
|
|
837
|
+
universalChallengerPubkeys: l.universalChallengerPubkeys.map(c),
|
|
838
|
+
hashlocks: [c(s.hashlock)],
|
|
839
|
+
timelockRefund: l.timelockRefund,
|
|
840
|
+
pegInAmounts: [s.amount],
|
|
841
|
+
feeRate: l.feeRate,
|
|
842
|
+
numLocalChallengers: l.numLocalChallengers,
|
|
843
|
+
councilQuorum: l.councilQuorum,
|
|
844
|
+
councilSize: l.councilSize,
|
|
845
|
+
network: l.network
|
|
846
|
+
},
|
|
847
|
+
fundedPrePeginTxHex: c(s.unsignedPrePeginTxHex),
|
|
848
|
+
htlcVout: s.htlcVout,
|
|
849
|
+
refundFee: d,
|
|
850
|
+
// buildRefundPsbt's top-level `hashlock` param is documented as "no 0x
|
|
851
|
+
// prefix" and flows into the WASM HTLC connector derivation; a prefixed
|
|
852
|
+
// value would derive the wrong refund script leaf and yield an
|
|
853
|
+
// unspendable PSBT. Match the `hashlocks` array handling above.
|
|
854
|
+
hashlock: c(s.hashlock)
|
|
855
|
+
});
|
|
856
|
+
o == null || o.throwIfAborted();
|
|
857
|
+
const P = R(
|
|
858
|
+
s.depositorBtcPubkey,
|
|
859
|
+
Ue
|
|
860
|
+
), b = await u(y, P), f = Ge(b);
|
|
861
|
+
o == null || o.throwIfAborted();
|
|
862
|
+
try {
|
|
863
|
+
return await a(f);
|
|
864
|
+
} catch (g) {
|
|
865
|
+
throw g instanceof Error && Fe.test(g.message) ? new Le(t, g) : g;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
export {
|
|
869
|
+
Le as B,
|
|
870
|
+
U as C,
|
|
871
|
+
M as R,
|
|
872
|
+
nt as a,
|
|
873
|
+
Ee as b,
|
|
874
|
+
ut as c,
|
|
875
|
+
lt as d,
|
|
876
|
+
Ve as e,
|
|
877
|
+
Ie as f,
|
|
878
|
+
ct as g,
|
|
879
|
+
dt as h,
|
|
880
|
+
st as i,
|
|
881
|
+
ht as j,
|
|
882
|
+
pt as k,
|
|
883
|
+
ft as l,
|
|
884
|
+
gt as m,
|
|
885
|
+
Pt as n,
|
|
886
|
+
yt as o,
|
|
887
|
+
X as p,
|
|
888
|
+
at as r,
|
|
889
|
+
ot as s,
|
|
890
|
+
it as v,
|
|
891
|
+
L as w
|
|
892
|
+
};
|
|
893
|
+
//# sourceMappingURL=buildAndBroadcastRefund-C2VqXiOx.js.map
|