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