@babylonlabs-io/ts-sdk 3.2.0 → 3.3.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-DOdsgcUR.cjs → PayoutManager-B1Ev0r7o.cjs} +2 -2
- package/dist/{PayoutManager-DOdsgcUR.cjs.map → PayoutManager-B1Ev0r7o.cjs.map} +1 -1
- package/dist/{PayoutManager-BZ212yml.js → PayoutManager-xEGvTbhL.js} +3 -3
- package/dist/{PayoutManager-BZ212yml.js.map → PayoutManager-xEGvTbhL.js.map} +1 -1
- package/dist/{PeginManager-DcwGom01.js → PeginManager-BJnUgW8C.js} +7 -7
- package/dist/{PeginManager-DcwGom01.js.map → PeginManager-BJnUgW8C.js.map} +1 -1
- package/dist/{PeginManager-BHplS4dM.cjs → PeginManager-Co43rW_x.cjs} +2 -2
- package/dist/{PeginManager-BHplS4dM.cjs.map → PeginManager-Co43rW_x.cjs.map} +1 -1
- package/dist/ProtocolParams.abi-BgEZaQ2I.cjs +2 -0
- package/dist/ProtocolParams.abi-BgEZaQ2I.cjs.map +1 -0
- package/dist/{ProtocolParams.abi-CKOVqFJP.js → ProtocolParams.abi-Cv77fsUe.js} +15 -9
- package/dist/ProtocolParams.abi-Cv77fsUe.js.map +1 -0
- package/dist/{buildAndBroadcastReclaim-CcQ0b1be.js → buildAndBroadcastReclaim-CQANDXVJ.js} +846 -822
- package/dist/buildAndBroadcastReclaim-CQANDXVJ.js.map +1 -0
- package/dist/buildAndBroadcastReclaim-DPk36Uhp.cjs +2 -0
- package/dist/buildAndBroadcastReclaim-DPk36Uhp.cjs.map +1 -0
- package/dist/challengeAssert-B2otuf7y.js +509 -0
- package/dist/challengeAssert-B2otuf7y.js.map +1 -0
- package/dist/challengeAssert-C3eMcM5Y.cjs +2 -0
- package/dist/challengeAssert-C3eMcM5Y.cjs.map +1 -0
- package/dist/constants-CAm10Qwp.cjs +2 -0
- package/dist/constants-CAm10Qwp.cjs.map +1 -0
- package/dist/constants-CvQZuxKv.js +48 -0
- package/dist/constants-CvQZuxKv.js.map +1 -0
- package/dist/{index-CVBtBjQ5.js → index-BRsWXDlv.js} +6 -6
- package/dist/{index-CVBtBjQ5.js.map → index-BRsWXDlv.js.map} +1 -1
- package/dist/{index-DpjYs5yr.cjs → index-C6avwx1s.cjs} +2 -2
- package/dist/{index-DpjYs5yr.cjs.map → index-C6avwx1s.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +302 -303
- package/dist/index.js.map +1 -1
- package/dist/{pegin-registration-client-BogzOk8B.cjs → pegin-registration-client-CdRyXP3j.cjs} +2 -2
- package/dist/{pegin-registration-client-BogzOk8B.cjs.map → pegin-registration-client-CdRyXP3j.cjs.map} +1 -1
- package/dist/{pegin-registration-client-DvyrUNku.js → pegin-registration-client-Cvjk4ILq.js} +3 -3
- package/dist/{pegin-registration-client-DvyrUNku.js.map → pegin-registration-client-Cvjk4ILq.js.map} +1 -1
- package/dist/{primeVpAuth-BPj2TPdD.cjs → primeVpAuth-CXNXYKrh.cjs} +2 -2
- package/dist/{primeVpAuth-BPj2TPdD.cjs.map → primeVpAuth-CXNXYKrh.cjs.map} +1 -1
- package/dist/{primeVpAuth-CiCdRNGf.js → primeVpAuth-D4UWXQ76.js} +2 -2
- package/dist/{primeVpAuth-CiCdRNGf.js.map → primeVpAuth-D4UWXQ76.js.map} +1 -1
- package/dist/{registration-records-CKLAv3gw.js → registration-records-DJJC2NiO.js} +92 -90
- package/dist/{registration-records-CKLAv3gw.js.map → registration-records-DJJC2NiO.js.map} +1 -1
- package/dist/{registration-records-DFQgBaYi.cjs → registration-records-XQMIKjGV.cjs} +2 -2
- package/dist/{registration-records-DFQgBaYi.cjs.map → registration-records-XQMIKjGV.cjs.map} +1 -1
- package/dist/{signer-set-reader-DFF9MgQN.js → signer-set-reader-CSUe92zE.js} +2 -2
- package/dist/{signer-set-reader-DFF9MgQN.js.map → signer-set-reader-CSUe92zE.js.map} +1 -1
- package/dist/{signer-set-reader-D-CyIYR5.cjs → signer-set-reader-GrFe_rsW.cjs} +2 -2
- package/dist/{signer-set-reader-D-CyIYR5.cjs.map → signer-set-reader-GrFe_rsW.cjs.map} +1 -1
- package/dist/tbv/core/clients/eth/index.cjs +1 -1
- package/dist/tbv/core/clients/eth/index.js +4 -4
- package/dist/tbv/core/clients/eth/protocol-params-reader.d.ts +1 -0
- package/dist/tbv/core/clients/eth/protocol-params-reader.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/protocol-params-validation.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/types.d.ts +12 -6
- package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +6 -6
- package/dist/tbv/core/clients/vault-provider/status/index.cjs +1 -1
- package/dist/tbv/core/clients/vault-provider/status/index.js +1 -1
- package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts +8 -0
- package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts.map +1 -1
- package/dist/tbv/core/contracts/index.cjs +1 -1
- package/dist/tbv/core/contracts/index.js +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +300 -301
- package/dist/tbv/core/index.js.map +1 -1
- 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 +29 -30
- package/dist/tbv/core/primitives/index.js.map +1 -1
- package/dist/tbv/core/primitives/psbt/__tests__/challengeAssert.test.d.ts +2 -0
- package/dist/tbv/core/primitives/psbt/__tests__/challengeAssert.test.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/__tests__/noPayout.test.d.ts +2 -0
- package/dist/tbv/core/primitives/psbt/__tests__/noPayout.test.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/challengeAssert.d.ts +43 -0
- package/dist/tbv/core/primitives/psbt/challengeAssert.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/constants.d.ts +50 -2
- package/dist/tbv/core/primitives/psbt/constants.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/noPayout.d.ts +42 -0
- package/dist/tbv/core/primitives/psbt/noPayout.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/__tests__/signDepositorGraph.realGraph.test.d.ts +12 -0
- package/dist/tbv/core/services/deposit/__tests__/signDepositorGraph.realGraph.test.d.ts.map +1 -0
- package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts +7 -0
- package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts +46 -1
- package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts.map +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +2 -2
- package/dist/tbv/core/wasm/__tests__/challengeAssertOutputConnector.test.d.ts +2 -0
- package/dist/tbv/core/wasm/__tests__/challengeAssertOutputConnector.test.d.ts.map +1 -0
- package/dist/tbv/core/wasm/index.cjs +1 -1
- package/dist/tbv/core/wasm/index.cjs.map +1 -1
- package/dist/tbv/core/wasm/index.d.ts +14 -2
- package/dist/tbv/core/wasm/index.d.ts.map +1 -1
- package/dist/tbv/core/wasm/index.js +81 -77
- package/dist/tbv/core/wasm/index.js.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +300 -301
- package/dist/tbv/index.js.map +1 -1
- package/dist/{toRefundInputs-8DgBT_Bg.cjs → toRefundInputs-DTuWi--u.cjs} +2 -2
- package/dist/{toRefundInputs-8DgBT_Bg.cjs.map → toRefundInputs-DTuWi--u.cjs.map} +1 -1
- package/dist/{toRefundInputs-CCMNAoRx.js → toRefundInputs-Dzw1cteD.js} +5 -5
- package/dist/{toRefundInputs-CCMNAoRx.js.map → toRefundInputs-Dzw1cteD.js.map} +1 -1
- package/dist/types-24A9Qoxb.js +274 -0
- package/dist/types-24A9Qoxb.js.map +1 -0
- package/dist/types-BC2TGzcp.cjs +2 -0
- package/dist/types-BC2TGzcp.cjs.map +1 -0
- package/dist/{verifyKeyPathSchnorrSignature-CQUut2-O.cjs → verifyKeyPathSchnorrSignature-BRTpEH9X.cjs} +2 -2
- package/dist/{verifyKeyPathSchnorrSignature-CQUut2-O.cjs.map → verifyKeyPathSchnorrSignature-BRTpEH9X.cjs.map} +1 -1
- package/dist/{verifyKeyPathSchnorrSignature-DxPbeSdQ.js → verifyKeyPathSchnorrSignature-IIj3Z2se.js} +2 -2
- package/dist/{verifyKeyPathSchnorrSignature-DxPbeSdQ.js.map → verifyKeyPathSchnorrSignature-IIj3Z2se.js.map} +1 -1
- package/dist/{verifyScriptPathSchnorrSignature-D2t1yACC.cjs → verifyScriptPathSchnorrSignature-CahYx5Td.cjs} +2 -2
- package/dist/{verifyScriptPathSchnorrSignature-D2t1yACC.cjs.map → verifyScriptPathSchnorrSignature-CahYx5Td.cjs.map} +1 -1
- package/dist/{verifyScriptPathSchnorrSignature-B3-VkvnK.js → verifyScriptPathSchnorrSignature-owu3BfyT.js} +2 -2
- package/dist/{verifyScriptPathSchnorrSignature-B3-VkvnK.js.map → verifyScriptPathSchnorrSignature-owu3BfyT.js.map} +1 -1
- package/package.json +3 -3
- package/dist/ProtocolParams.abi-CKOVqFJP.js.map +0 -1
- package/dist/ProtocolParams.abi-CjrT0545.cjs +0 -2
- package/dist/ProtocolParams.abi-CjrT0545.cjs.map +0 -1
- package/dist/buildAndBroadcastReclaim-C7bq5wNM.cjs +0 -2
- package/dist/buildAndBroadcastReclaim-C7bq5wNM.cjs.map +0 -1
- package/dist/buildAndBroadcastReclaim-CcQ0b1be.js.map +0 -1
- package/dist/challengeAssert-Cp_GeRg8.js +0 -64
- package/dist/challengeAssert-Cp_GeRg8.js.map +0 -1
- package/dist/challengeAssert-Z7_YULBb.cjs +0 -2
- package/dist/challengeAssert-Z7_YULBb.cjs.map +0 -1
- package/dist/constants-BeYquVd-.js +0 -36
- package/dist/constants-BeYquVd-.js.map +0 -1
- package/dist/constants-BwCg5K6R.cjs +0 -2
- package/dist/constants-BwCg5K6R.cjs.map +0 -1
- package/dist/noPayout-B-vGXJ-V.js +0 -361
- package/dist/noPayout-B-vGXJ-V.js.map +0 -1
- package/dist/noPayout-DOHak0ui.cjs +0 -2
- package/dist/noPayout-DOHak0ui.cjs.map +0 -1
- package/dist/types-Bda75Od0.cjs +0 -2
- package/dist/types-Bda75Od0.cjs.map +0 -1
- package/dist/types-C5jj3Cc-.js +0 -198
- package/dist/types-C5jj3Cc-.js.map +0 -1
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
1
|
+
var Zt = Object.defineProperty;
|
|
2
|
+
var er = (e, t, r) => t in e ? Zt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var W = (e, t, r) => er(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
4
|
import { B as Be } from "./BTCVaultRegistry.abi-BzNTa_EU.js";
|
|
5
|
-
import { e as Ie, s as b, i as
|
|
6
|
-
import { v as
|
|
7
|
-
import { verifyWatchtowerArtifacts as
|
|
8
|
-
import { m as
|
|
5
|
+
import { e as Ie, s as b, i as tr, u as yt, c as _, v as rr, g as or, p as pe, f as N } from "./bitcoin-C-TuHb-v.js";
|
|
6
|
+
import { v as sr, s as vt, b as bt, P as nr, d as ir } from "./PayoutManager-xEGvTbhL.js";
|
|
7
|
+
import { verifyWatchtowerArtifacts as ar, buildClaimPsbt as ur, buildAssertClaimerPsbt as cr, buildPayoutClaimerPsbt as lr, buildWronglyChallengedPsbts as dr, buildPayoutDepositorPsbt as hr, finalizeClaimTx as pr, buildWatchtowerArtifacts as gr, extractTapScriptSig as mt, expandWotsSeed as fr, wotsKeypairFromSeed as yr, validateWotsKeypairAgainstGraph as vr, getChallengeAssertOutputScriptPubKey as br, deriveVaultId as mr } from "./tbv/core/wasm/index.js";
|
|
8
|
+
import { m as Pr, d as Pt, k as wr, a as _e, V as Le, i as xr, g as Er, f as kr, r as $r, h as Cr } from "./registration-records-DJJC2NiO.js";
|
|
9
9
|
import { Psbt as q, Transaction as S } from "bitcoinjs-lib";
|
|
10
|
-
import {
|
|
11
|
-
import { p as
|
|
10
|
+
import { z as F, E as A, F as re, G as Q, A as G, x as Z, H as ge, t as Me, y as ee, I as Ve, u as Fe, v as Ue, w as qe, W as Tr, D as Ge, C as Xe, J as _r, K as Sr, L as Ar } from "./constants-CvQZuxKv.js";
|
|
11
|
+
import { p as Br, q as Ir, r as wt, P as X, j as oe, f as Vr, i as ae, g as ue } from "./verifyScriptPathSchnorrSignature-owu3BfyT.js";
|
|
12
12
|
import { Buffer as H } from "buffer";
|
|
13
13
|
import { C as xt, X as Et } from "./validation-OSC0xTHB.js";
|
|
14
|
-
import { a as
|
|
15
|
-
import { d as
|
|
16
|
-
import { O as
|
|
17
|
-
import { zeroAddress as
|
|
18
|
-
import { v as
|
|
19
|
-
import { h as
|
|
20
|
-
import {
|
|
21
|
-
import { a as
|
|
22
|
-
import { c as
|
|
23
|
-
const
|
|
24
|
-
function
|
|
14
|
+
import { a as kt, c as ce } from "./signing-C1rR4tqs.js";
|
|
15
|
+
import { d as $t } from "./deriveVaultRoot-BcvmER1E.js";
|
|
16
|
+
import { O as ze, d as Rr } from "./types-24A9Qoxb.js";
|
|
17
|
+
import { zeroAddress as Kr, isAddress as Hr, isAddressEqual as Or } from "viem";
|
|
18
|
+
import { v as je, D as R, c as Nr, b as Dr, R as Lr, d as Ct } from "./state-CFn1rT74.js";
|
|
19
|
+
import { h as We, b as Mr, s as Fr, j as Ur } from "./sha2-YqVHJiFj.js";
|
|
20
|
+
import { c as qr, g as Gr, h as Xr, i as zr, b as jr, f as Tt, e as Wr, a as Yr } from "./challengeAssert-B2otuf7y.js";
|
|
21
|
+
import { a as Jr } from "./secp256k1-BuxBFUHm.js";
|
|
22
|
+
import { c as Qr } from "./btcTxHash-BRZ8_EZq.js";
|
|
23
|
+
const Zr = /^0x[0-9a-fA-F]{64}$/, eo = /^0x[0-9a-fA-F]{40}$/, to = /^0x([0-9a-fA-F]{2})*$/;
|
|
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 (!Zr.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 ro(e, t) {
|
|
35
|
+
if (!eo.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 oo(e, t) {
|
|
41
|
+
if (!to.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
|
-
function
|
|
47
|
-
|
|
46
|
+
function Re(e) {
|
|
47
|
+
ro(e.btcVaultRegistryAddress, "btcVaultRegistryAddress"), ye(e.vaultId, "vaultId");
|
|
48
48
|
const t = Ie(e.secret);
|
|
49
|
-
if (
|
|
49
|
+
if (ye(t, "secret"), e.hashlock !== void 0 && (ye(e.hashlock, "hashlock"), !sr(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 nn(e) {
|
|
56
56
|
const {
|
|
57
57
|
btcVaultRegistryAddress: t,
|
|
58
58
|
vaultId: r,
|
|
@@ -62,23 +62,23 @@ async function Js(e) {
|
|
|
62
62
|
signal: a
|
|
63
63
|
} = e;
|
|
64
64
|
a == null || a.throwIfAborted();
|
|
65
|
-
const i =
|
|
65
|
+
const i = Re({
|
|
66
66
|
btcVaultRegistryAddress: t,
|
|
67
67
|
vaultId: r,
|
|
68
68
|
secret: e.secret,
|
|
69
69
|
hashlock: o
|
|
70
70
|
});
|
|
71
|
-
return
|
|
71
|
+
return oo(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 an(e) {
|
|
79
79
|
const { btcVaultRegistryAddress: t, vaultId: r, hashlock: o, writeContract: s, signal: n } = e;
|
|
80
80
|
n == null || n.throwIfAborted();
|
|
81
|
-
const a =
|
|
81
|
+
const a = Re({
|
|
82
82
|
btcVaultRegistryAddress: t,
|
|
83
83
|
vaultId: r,
|
|
84
84
|
secret: e.secret,
|
|
@@ -91,11 +91,11 @@ async function Qs(e) {
|
|
|
91
91
|
args: [r, a]
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
|
-
async function
|
|
94
|
+
async function un(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");
|
|
98
|
-
const a =
|
|
98
|
+
const a = Re({
|
|
99
99
|
btcVaultRegistryAddress: t,
|
|
100
100
|
vaultId: r,
|
|
101
101
|
secret: e.secret,
|
|
@@ -113,25 +113,25 @@ class K extends Error {
|
|
|
113
113
|
super(t, r), this.name = "AssertBindingError";
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
-
function
|
|
116
|
+
function ve(e, t) {
|
|
117
117
|
try {
|
|
118
118
|
return q.fromBase64(t);
|
|
119
119
|
} catch (r) {
|
|
120
120
|
throw new K(`${e} PSBT cannot be parsed.`, { cause: r });
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
-
function
|
|
123
|
+
function so(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}.`);
|
|
127
127
|
return o.hash;
|
|
128
128
|
}
|
|
129
|
-
function
|
|
129
|
+
function Ye(e) {
|
|
130
130
|
return S.fromBuffer(
|
|
131
131
|
e.data.globalMap.unsignedTx.toBuffer()
|
|
132
132
|
).getHash();
|
|
133
133
|
}
|
|
134
|
-
function
|
|
134
|
+
function be(e, t, r, o, s, n) {
|
|
135
135
|
const a = t.txInputs[r];
|
|
136
136
|
if (!a)
|
|
137
137
|
throw new K(`${e} PSBT has no input ${r}.`);
|
|
@@ -140,71 +140,71 @@ function ve(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 no(e, t) {
|
|
144
144
|
var s;
|
|
145
145
|
const r = (s = e.data.inputs[F]) == null ? void 0 : s.witnessUtxo;
|
|
146
146
|
if (r === void 0)
|
|
147
147
|
throw new K(
|
|
148
148
|
`Assert input ${F} carries no witnessUtxo, so the amount and script its signature commits to cannot be checked; refusing to sign assert.`
|
|
149
149
|
);
|
|
150
|
-
const o = t.txOutputs[
|
|
150
|
+
const o = t.txOutputs[Q];
|
|
151
151
|
if (!o)
|
|
152
152
|
throw new K(
|
|
153
|
-
`Claim PSBT has no output ${
|
|
153
|
+
`Claim PSBT has no output ${Q} for the Assert to spend; refusing to sign assert.`
|
|
154
154
|
);
|
|
155
155
|
if (r.value !== o.value)
|
|
156
156
|
throw new K(
|
|
157
|
-
`Assert input ${F} declares a prevout of ${r.value} sats but the Claim's output ${
|
|
157
|
+
`Assert input ${F} declares a prevout of ${r.value} sats but the Claim's output ${Q} 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 ${F} declares a prevout script that is not the Claim's output ${
|
|
161
|
+
`Assert input ${F} declares a prevout script that is not the Claim's output ${Q} script; refusing to sign assert.`
|
|
162
162
|
);
|
|
163
163
|
}
|
|
164
|
-
function
|
|
165
|
-
const t =
|
|
166
|
-
|
|
164
|
+
function io(e) {
|
|
165
|
+
const t = ve("Claim", e.claimPsbtBase64), r = ve("Assert", e.assertPsbtBase64), o = ve("Payout", e.payoutClaimerPsbtBase64);
|
|
166
|
+
be(
|
|
167
167
|
"Assert",
|
|
168
168
|
r,
|
|
169
169
|
F,
|
|
170
|
-
|
|
171
|
-
|
|
170
|
+
Ye(t),
|
|
171
|
+
Q,
|
|
172
172
|
"Claim:0"
|
|
173
|
-
),
|
|
173
|
+
), no(r, t), be(
|
|
174
174
|
"Payout",
|
|
175
175
|
o,
|
|
176
176
|
A,
|
|
177
|
-
|
|
178
|
-
|
|
177
|
+
Ye(r),
|
|
178
|
+
G,
|
|
179
179
|
"Assert:0"
|
|
180
|
-
),
|
|
180
|
+
), be(
|
|
181
181
|
"Payout",
|
|
182
182
|
o,
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
183
|
+
re,
|
|
184
|
+
so("Claim", t, ge),
|
|
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) {
|
|
193
193
|
throw new Error(`${e} PSBT cannot be parsed.`, { cause: r });
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
-
function
|
|
196
|
+
function Je(e, t, r, o) {
|
|
197
197
|
var a;
|
|
198
198
|
const s = [
|
|
199
199
|
{
|
|
200
|
-
inputIndex:
|
|
200
|
+
inputIndex: re,
|
|
201
201
|
expectedSats: r,
|
|
202
|
-
source: `the vault's PegIn output ${
|
|
202
|
+
source: `the vault's PegIn output ${Z}`
|
|
203
203
|
},
|
|
204
204
|
{
|
|
205
205
|
inputIndex: A,
|
|
206
206
|
expectedSats: o.value,
|
|
207
|
-
source: `the Assert's output ${
|
|
207
|
+
source: `the Assert's output ${G}`
|
|
208
208
|
}
|
|
209
209
|
];
|
|
210
210
|
for (const { inputIndex: i, expectedSats: u, source: l } of s) {
|
|
@@ -221,10 +221,10 @@ function Qe(e, t, r, o) {
|
|
|
221
221
|
const n = t.data.inputs[A].witnessUtxo;
|
|
222
222
|
if (!(n != null && n.script.equals(o.script)))
|
|
223
223
|
throw new Error(
|
|
224
|
-
`${e} Payout input ${A} declares a prevout script that is not the Assert's output ${
|
|
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 ao(e) {
|
|
228
228
|
const { vault: t } = e, r = {
|
|
229
229
|
vaultCoreVersion: t.vaultCoreVersion,
|
|
230
230
|
numVaultKeepers: t.vaultKeeperBtcPubkeys.length,
|
|
@@ -232,114 +232,114 @@ async function Zr(e) {
|
|
|
232
232
|
councilSize: t.councilSize,
|
|
233
233
|
protocolFeeRate: t.protocolFeeRate
|
|
234
234
|
};
|
|
235
|
-
|
|
236
|
-
const o =
|
|
235
|
+
Br(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."
|
|
243
243
|
);
|
|
244
|
-
const a = n.txOutputs[
|
|
244
|
+
const a = n.txOutputs[G];
|
|
245
245
|
if (a === void 0)
|
|
246
246
|
throw new Error(
|
|
247
|
-
`Assert transaction has no output ${
|
|
247
|
+
`Assert transaction has no output ${G}; the Payout's implicit fee cannot be measured.`
|
|
248
248
|
);
|
|
249
|
-
if (o.txInputs.length !==
|
|
249
|
+
if (o.txInputs.length !== Me)
|
|
250
250
|
throw new Error(
|
|
251
|
-
`Payout transaction must have exactly ${
|
|
251
|
+
`Payout transaction must have exactly ${Me} inputs, got ${o.txInputs.length}`
|
|
252
252
|
);
|
|
253
|
-
const i = o.txInputs[
|
|
253
|
+
const i = o.txInputs[re].sequence;
|
|
254
254
|
if (i !== t.timelockPegin)
|
|
255
255
|
throw new Error(
|
|
256
|
-
`Payout input ${
|
|
256
|
+
`Payout input ${re} sequence ${i} must equal the PegIn CSV timelock ${t.timelockPegin}; refusing to sign payout.`
|
|
257
257
|
);
|
|
258
258
|
const u = o.txInputs[A].sequence;
|
|
259
259
|
if (u !== t.timelockAssert)
|
|
260
260
|
throw new Error(
|
|
261
261
|
`Payout input ${A} sequence ${u} must equal the Assert CSV timelock ${t.timelockAssert}; refusing to sign payout.`
|
|
262
262
|
);
|
|
263
|
-
|
|
263
|
+
Je(
|
|
264
264
|
"Claimer",
|
|
265
265
|
o,
|
|
266
266
|
t.peginVaultOutputValueSats,
|
|
267
267
|
a
|
|
268
|
-
),
|
|
268
|
+
), Je(
|
|
269
269
|
"Depositor",
|
|
270
270
|
s,
|
|
271
271
|
t.peginVaultOutputValueSats,
|
|
272
272
|
a
|
|
273
273
|
);
|
|
274
274
|
const l = t.peginVaultOutputValueSats + a.value, c = o.txOutputs;
|
|
275
|
-
if (c.length !==
|
|
275
|
+
if (c.length !== ee)
|
|
276
276
|
throw new Error(
|
|
277
|
-
`Payout transaction has ${c.length} output(s), expected exactly ${
|
|
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 h = 0;
|
|
280
|
+
for (const d of c) h += d.value;
|
|
281
|
+
if (h > l)
|
|
282
282
|
throw new Error(
|
|
283
|
-
`Payout outputs (${
|
|
283
|
+
`Payout outputs (${h} sats) exceed inputs (${l} sats); invalid transaction.`
|
|
284
284
|
);
|
|
285
|
-
await
|
|
286
|
-
implicitFeeSats: l -
|
|
287
|
-
out0Len: c[
|
|
285
|
+
await Ir(r, {
|
|
286
|
+
implicitFeeSats: l - h,
|
|
287
|
+
out0Len: c[Ve].script.length,
|
|
288
288
|
out1Len: void 0
|
|
289
289
|
});
|
|
290
290
|
}
|
|
291
|
-
class
|
|
291
|
+
class uo 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 co(e) {
|
|
299
299
|
const t = wt({
|
|
300
300
|
claimerBtcPubkey: e.depositorBtcPubkey,
|
|
301
301
|
depositorBtcPubkey: e.depositorBtcPubkey,
|
|
302
302
|
vaultProviderBtcPubkey: e.vaultProviderBtcPubkey,
|
|
303
303
|
vaultKeeperBtcPubkeys: e.vaultKeeperBtcPubkeys
|
|
304
|
-
}), r = e.universalChallengerBtcPubkeys.map(
|
|
304
|
+
}), r = e.universalChallengerBtcPubkeys.map(Qe), o = t.filter((c) => r.includes(c));
|
|
305
305
|
if (o.length > 0)
|
|
306
306
|
throw new Error(
|
|
307
307
|
`Cannot check the challenger set: vault keepers and universal challengers overlap (${o.join(", ")}).`
|
|
308
308
|
);
|
|
309
|
-
const s = e.graphChallengerPubkeys.map(
|
|
309
|
+
const s = e.graphChallengerPubkeys.map(Qe), n = new Set(s);
|
|
310
310
|
if (n.size !== s.length)
|
|
311
311
|
throw new Error(
|
|
312
312
|
"Transaction graph lists the same challenger more than once."
|
|
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 uo(u, l);
|
|
317
317
|
}
|
|
318
|
-
function
|
|
318
|
+
function Qe(e) {
|
|
319
319
|
return b(e).toLowerCase();
|
|
320
320
|
}
|
|
321
|
-
class
|
|
321
|
+
class lo extends Error {
|
|
322
322
|
constructor(t, r) {
|
|
323
323
|
super(
|
|
324
|
-
`Payout transaction output ${
|
|
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 ho(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 } = po(t);
|
|
336
|
+
if (r !== Fe || o !== Ue)
|
|
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 ${Fe} and ${Ue}.`
|
|
339
339
|
);
|
|
340
|
-
if (s.length !==
|
|
340
|
+
if (s.length !== ee)
|
|
341
341
|
throw new Error(
|
|
342
|
-
`Payout transaction has ${s.length} output(s), expected exactly ${
|
|
342
|
+
`Payout transaction has ${s.length} output(s), expected exactly ${ee} for a depositor-as-claimer payout.`
|
|
343
343
|
);
|
|
344
344
|
const n = b(
|
|
345
345
|
e.registeredPayoutScriptPubKey
|
|
@@ -348,23 +348,23 @@ function oo(e) {
|
|
|
348
348
|
throw new Error(
|
|
349
349
|
"registeredPayoutScriptPubKey is empty; the vault's on-chain payout script is required to check the Payout destination."
|
|
350
350
|
);
|
|
351
|
-
const a = s[
|
|
351
|
+
const a = s[Ve].script.toString("hex").toLowerCase();
|
|
352
352
|
if (a !== n)
|
|
353
|
-
throw new
|
|
354
|
-
const i = s[
|
|
355
|
-
if (i.value !==
|
|
353
|
+
throw new lo(n, a);
|
|
354
|
+
const i = s[ee - 1];
|
|
355
|
+
if (i.value !== qe)
|
|
356
356
|
throw new Error(
|
|
357
|
-
`Payout CPFP anchor value ${i.value} sats must equal ${
|
|
357
|
+
`Payout CPFP anchor value ${i.value} sats must equal ${qe} sats.`
|
|
358
358
|
);
|
|
359
359
|
const u = b(
|
|
360
|
-
|
|
360
|
+
Pr(b(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 po(e) {
|
|
368
368
|
return {
|
|
369
369
|
version: e.version,
|
|
370
370
|
locktime: e.locktime,
|
|
@@ -374,28 +374,28 @@ function so(e) {
|
|
|
374
374
|
}))
|
|
375
375
|
};
|
|
376
376
|
}
|
|
377
|
-
class
|
|
377
|
+
class ne extends Error {
|
|
378
378
|
constructor(t) {
|
|
379
379
|
super(t), this.name = "PayoutInputLeafError";
|
|
380
380
|
}
|
|
381
381
|
}
|
|
382
|
-
function
|
|
382
|
+
function go(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
|
-
throw new
|
|
385
|
+
throw new ne(
|
|
386
386
|
"Depositor and claimer Payout PSBTs describe different transactions; the graph is inconsistent."
|
|
387
387
|
);
|
|
388
388
|
const n = r.data.inputs[A], a = t.data.inputs[A];
|
|
389
389
|
if (!n || !a)
|
|
390
|
-
throw new
|
|
390
|
+
throw new ne(
|
|
391
391
|
"Payout PSBT has no Assert-connector input."
|
|
392
392
|
);
|
|
393
393
|
if (!n.tapLeafScript || n.tapLeafScript.length !== 1)
|
|
394
|
-
throw new
|
|
394
|
+
throw new ne(
|
|
395
395
|
"Claimer Payout PSBT must carry exactly one leaf on the Assert-connector input."
|
|
396
396
|
);
|
|
397
397
|
if (a.tapLeafScript && a.tapLeafScript.length > 0)
|
|
398
|
-
throw new
|
|
398
|
+
throw new ne(
|
|
399
399
|
"Depositor Payout PSBT already carries an Assert-connector leaf; refusing to overwrite it."
|
|
400
400
|
);
|
|
401
401
|
return t.updateInput(A, {
|
|
@@ -404,31 +404,31 @@ function no(e) {
|
|
|
404
404
|
...n.tapMerkleRoot ? { tapMerkleRoot: n.tapMerkleRoot } : {}
|
|
405
405
|
}), t.toBase64();
|
|
406
406
|
}
|
|
407
|
-
class
|
|
407
|
+
class fo 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 yo(e) {
|
|
415
415
|
let t;
|
|
416
416
|
try {
|
|
417
417
|
t = q.fromBase64(e);
|
|
418
418
|
} catch (o) {
|
|
419
419
|
throw new Error("Claim PSBT cannot be parsed.", { cause: o });
|
|
420
420
|
}
|
|
421
|
-
const r = t.txInputs[
|
|
421
|
+
const r = t.txInputs[ge];
|
|
422
422
|
if (!r)
|
|
423
423
|
throw new Error("Claim PSBT carries no PegIn input to bind the vault to.");
|
|
424
424
|
return _t(
|
|
425
425
|
"Claim PSBT",
|
|
426
426
|
t.txInputs.length,
|
|
427
427
|
r.index
|
|
428
|
-
),
|
|
428
|
+
), Ke(r.hash);
|
|
429
429
|
}
|
|
430
|
-
function
|
|
431
|
-
const t = e.ins[
|
|
430
|
+
function vo(e) {
|
|
431
|
+
const t = e.ins[ge];
|
|
432
432
|
if (!t)
|
|
433
433
|
throw new Error(
|
|
434
434
|
"Artifacts file's claim_tx carries no PegIn input to bind the vault to."
|
|
@@ -437,7 +437,7 @@ function uo(e) {
|
|
|
437
437
|
"Artifacts file's claim_tx",
|
|
438
438
|
e.ins.length,
|
|
439
439
|
t.index
|
|
440
|
-
),
|
|
440
|
+
), Ke(t.hash);
|
|
441
441
|
}
|
|
442
442
|
function _t(e, t, r) {
|
|
443
443
|
if (t !== 1 || r !== X)
|
|
@@ -446,29 +446,29 @@ function _t(e, t, r) {
|
|
|
446
446
|
);
|
|
447
447
|
}
|
|
448
448
|
function St(e) {
|
|
449
|
-
const t =
|
|
449
|
+
const t = z(
|
|
450
450
|
Pt(e.peginTxid, e.depositorEthAddress)
|
|
451
|
-
), r =
|
|
451
|
+
), r = z(e.expectedVaultId);
|
|
452
452
|
if (t !== r)
|
|
453
|
-
throw new
|
|
453
|
+
throw new fo(r, t, e.peginTxid);
|
|
454
454
|
}
|
|
455
|
-
function
|
|
455
|
+
function z(e) {
|
|
456
456
|
return `0x${(e.startsWith("0x") ? e.slice(2) : e).toLowerCase()}`;
|
|
457
457
|
}
|
|
458
|
-
function
|
|
458
|
+
function Ke(e) {
|
|
459
459
|
return H.from(e).reverse().toString("hex");
|
|
460
460
|
}
|
|
461
|
-
function
|
|
461
|
+
function le(e, t) {
|
|
462
462
|
const r = b(e);
|
|
463
463
|
if (!/^(?:[0-9a-fA-F]{2})+$/.test(r))
|
|
464
464
|
throw new Error(`${t} must be non-empty, even-length hex.`);
|
|
465
465
|
return r.toLowerCase();
|
|
466
466
|
}
|
|
467
467
|
function At(e) {
|
|
468
|
-
const t =
|
|
468
|
+
const t = le(
|
|
469
469
|
e.servedVerifyingKeyHex,
|
|
470
470
|
"source.verifyingKeyHex"
|
|
471
|
-
), r =
|
|
471
|
+
), r = le(
|
|
472
472
|
e.trustedVerifyingKeyHex,
|
|
473
473
|
"trustedVerifyingKeyHex"
|
|
474
474
|
);
|
|
@@ -478,61 +478,61 @@ function At(e) {
|
|
|
478
478
|
);
|
|
479
479
|
}
|
|
480
480
|
const U = 3;
|
|
481
|
-
class
|
|
481
|
+
class bo 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 mo = /^(?:[0-9a-fA-F]{2})+$/;
|
|
489
|
+
function Po(e) {
|
|
490
|
+
const t = Eo(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" || !mo.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 wo(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 = Pe(t.vault_id, "vault_id"), o = xo(Pe(t.claim_tx, "claim_tx")), s = we(
|
|
510
510
|
t.prover_circuit_version,
|
|
511
511
|
"prover_circuit_version"
|
|
512
512
|
), n = t.claimable_event_block_number === void 0 ? 0n : BigInt(
|
|
513
|
-
|
|
513
|
+
we(
|
|
514
514
|
t.claimable_event_block_number,
|
|
515
515
|
"claimable_event_block_number"
|
|
516
516
|
)
|
|
517
517
|
);
|
|
518
518
|
return {
|
|
519
|
-
vaultCoreVersion: t.vault_core_version === void 0 ? void 0 :
|
|
519
|
+
vaultCoreVersion: t.vault_core_version === void 0 ? void 0 : we(t.vault_core_version, "vault_core_version"),
|
|
520
520
|
vaultId: r,
|
|
521
521
|
claimTxid: o.getId(),
|
|
522
|
-
peginTxid:
|
|
522
|
+
peginTxid: vo(o),
|
|
523
523
|
proverCircuitVersion: s,
|
|
524
524
|
claimableEventBlockNumber: n,
|
|
525
525
|
// Required: btc-vault's builder always writes it
|
|
526
526
|
// (`delegated_claim.rs:874` @ b534ff9e), so an absent one is not a file
|
|
527
527
|
// this SDK or the CLI produced.
|
|
528
|
-
verifyingKeyHex:
|
|
529
|
-
babeSessions:
|
|
528
|
+
verifyingKeyHex: Pe(t.verifying_key, "verifying_key"),
|
|
529
|
+
babeSessions: Po(t.babe_sessions)
|
|
530
530
|
};
|
|
531
531
|
}
|
|
532
|
-
async function
|
|
533
|
-
const t =
|
|
532
|
+
async function cn(e) {
|
|
533
|
+
const t = wo(e.artifactsJson), r = z(e.expectedVaultId), o = z(t.vaultId);
|
|
534
534
|
if (r !== o)
|
|
535
|
-
throw new
|
|
535
|
+
throw new bo(r, o);
|
|
536
536
|
St({
|
|
537
537
|
peginTxid: t.peginTxid,
|
|
538
538
|
depositorEthAddress: e.depositorEthAddress,
|
|
@@ -555,10 +555,10 @@ async function en(e) {
|
|
|
555
555
|
throw new Error(
|
|
556
556
|
`Artifacts record prover circuit version ${t.proverCircuitVersion} but the vault's stamped params say ${e.expectedProverCircuitVersion}; a proof for the wrong circuit fails at start-claim, so refusing the file.`
|
|
557
557
|
);
|
|
558
|
-
const n =
|
|
558
|
+
const n = le(
|
|
559
559
|
t.verifyingKeyHex,
|
|
560
560
|
'Artifacts file "verifying_key"'
|
|
561
|
-
), a =
|
|
561
|
+
), a = le(
|
|
562
562
|
e.trustedVerifyingKeyHex,
|
|
563
563
|
"trustedVerifyingKeyHex"
|
|
564
564
|
);
|
|
@@ -566,9 +566,9 @@ async function en(e) {
|
|
|
566
566
|
throw new Error(
|
|
567
567
|
`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.`
|
|
568
568
|
);
|
|
569
|
-
return await
|
|
569
|
+
return await ar(s, e.artifactsJson), t;
|
|
570
570
|
}
|
|
571
|
-
function
|
|
571
|
+
function xo(e) {
|
|
572
572
|
try {
|
|
573
573
|
return S.fromHex(e);
|
|
574
574
|
} catch (t) {
|
|
@@ -577,17 +577,17 @@ function go(e) {
|
|
|
577
577
|
});
|
|
578
578
|
}
|
|
579
579
|
}
|
|
580
|
-
function
|
|
580
|
+
function Pe(e, t) {
|
|
581
581
|
if (typeof e != "string" || e.length === 0)
|
|
582
582
|
throw new Error(`Artifacts file is missing a usable "${t}".`);
|
|
583
583
|
return e;
|
|
584
584
|
}
|
|
585
|
-
function
|
|
585
|
+
function we(e, t) {
|
|
586
586
|
if (typeof e != "number" || !Number.isSafeInteger(e) || e < 0)
|
|
587
587
|
throw new Error(`Artifacts file is missing a usable "${t}".`);
|
|
588
588
|
return e;
|
|
589
589
|
}
|
|
590
|
-
function
|
|
590
|
+
function Eo(e, t) {
|
|
591
591
|
if (e === void 0) return {};
|
|
592
592
|
if (typeof e != "object" || e === null || Array.isArray(e))
|
|
593
593
|
throw new Error(`Artifacts file is missing a usable "${t}".`);
|
|
@@ -602,7 +602,7 @@ function It(e) {
|
|
|
602
602
|
id: "claim",
|
|
603
603
|
kind: "claim",
|
|
604
604
|
psbtBase64: e.claim,
|
|
605
|
-
inputIndex:
|
|
605
|
+
inputIndex: ge
|
|
606
606
|
},
|
|
607
607
|
{
|
|
608
608
|
id: "assert",
|
|
@@ -620,7 +620,7 @@ function It(e) {
|
|
|
620
620
|
id: "payoutDepositor",
|
|
621
621
|
kind: "payoutDepositor",
|
|
622
622
|
psbtBase64: e.payoutDepositor,
|
|
623
|
-
inputIndex:
|
|
623
|
+
inputIndex: re
|
|
624
624
|
}
|
|
625
625
|
];
|
|
626
626
|
for (const r of Object.keys(e.wronglyChallenged))
|
|
@@ -629,29 +629,29 @@ function It(e) {
|
|
|
629
629
|
id: Bt(r, s),
|
|
630
630
|
kind: "wronglyChallenged",
|
|
631
631
|
psbtBase64: o,
|
|
632
|
-
inputIndex:
|
|
632
|
+
inputIndex: Tr
|
|
633
633
|
});
|
|
634
634
|
});
|
|
635
635
|
return t;
|
|
636
636
|
}
|
|
637
|
-
const
|
|
637
|
+
const ko = "{}", $o = xt - Et;
|
|
638
638
|
function V(e) {
|
|
639
639
|
const t = e.replace(/^0x/, "").toLowerCase();
|
|
640
640
|
if (t.length === xt)
|
|
641
|
-
return t.slice(
|
|
641
|
+
return t.slice($o);
|
|
642
642
|
if (t.length === Et) return t;
|
|
643
643
|
throw new Error(
|
|
644
644
|
`Public key must be 33-byte compressed or 32-byte x-only hex, got ${t.length / 2} bytes.`
|
|
645
645
|
);
|
|
646
646
|
}
|
|
647
|
-
async function
|
|
647
|
+
async function Ze(e, t, r) {
|
|
648
648
|
const o = await e.getPublicKeyHex();
|
|
649
649
|
if (V(o) !== V(t))
|
|
650
650
|
throw new Error(
|
|
651
651
|
"Connected wallet does not hold the vault's depositor key. Select the account that made the deposit, then try again."
|
|
652
652
|
);
|
|
653
653
|
const s = await e.getAddress();
|
|
654
|
-
if (!
|
|
654
|
+
if (!tr(s, o, r))
|
|
655
655
|
throw new Error(
|
|
656
656
|
`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.`
|
|
657
657
|
);
|
|
@@ -664,15 +664,15 @@ async function Vt(e, t, r, o) {
|
|
|
664
664
|
`Depositor key ${s} is not the vault's registered depositor key ${r.depositorBtcPubkey}; refusing to plan a claim for another key.`
|
|
665
665
|
);
|
|
666
666
|
try {
|
|
667
|
-
|
|
667
|
+
wr(
|
|
668
668
|
Ie(r.registeredPayoutScriptPubKey),
|
|
669
669
|
r.depositorBtcPubkey,
|
|
670
670
|
o
|
|
671
671
|
);
|
|
672
|
-
} catch (
|
|
672
|
+
} catch (h) {
|
|
673
673
|
throw new Error(
|
|
674
|
-
`Registered payout script ${r.registeredPayoutScriptPubKey} failed the depositor-key derivation check: ${
|
|
675
|
-
{ cause:
|
|
674
|
+
`Registered payout script ${r.registeredPayoutScriptPubKey} failed the depositor-key derivation check: ${h instanceof Error ? h.message : String(h)}. 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.`,
|
|
675
|
+
{ cause: h }
|
|
676
676
|
);
|
|
677
677
|
}
|
|
678
678
|
if (e !== U)
|
|
@@ -684,37 +684,37 @@ async function Vt(e, t, r, o) {
|
|
|
684
684
|
`Graph version ${e} does not match the vault context's vault core version ${r.vaultCoreVersion}; they are one axis and must agree.`
|
|
685
685
|
);
|
|
686
686
|
const [n, a, i, u, l] = await Promise.all([
|
|
687
|
-
ir(e, t),
|
|
688
|
-
ar(e, t),
|
|
689
687
|
ur(e, t),
|
|
690
688
|
cr(e, t),
|
|
691
|
-
lr(e, t)
|
|
689
|
+
lr(e, t),
|
|
690
|
+
dr(e, t),
|
|
691
|
+
hr(e, t)
|
|
692
692
|
]);
|
|
693
693
|
St({
|
|
694
|
-
peginTxid:
|
|
694
|
+
peginTxid: yo(n),
|
|
695
695
|
depositorEthAddress: r.depositorEthAddress,
|
|
696
696
|
expectedVaultId: r.vaultId
|
|
697
|
-
}),
|
|
697
|
+
}), io({
|
|
698
698
|
claimPsbtBase64: n,
|
|
699
699
|
assertPsbtBase64: a,
|
|
700
700
|
payoutClaimerPsbtBase64: i
|
|
701
701
|
});
|
|
702
|
-
for (const
|
|
703
|
-
|
|
704
|
-
payoutPsbtBase64:
|
|
702
|
+
for (const h of [i, l])
|
|
703
|
+
ho({
|
|
704
|
+
payoutPsbtBase64: h,
|
|
705
705
|
registeredPayoutScriptPubKey: r.registeredPayoutScriptPubKey,
|
|
706
706
|
depositorBtcPubkey: r.depositorBtcPubkey
|
|
707
707
|
});
|
|
708
|
-
const c =
|
|
708
|
+
const c = go({
|
|
709
709
|
payoutDepositorPsbtBase64: l,
|
|
710
710
|
payoutClaimerPsbtBase64: i
|
|
711
711
|
});
|
|
712
|
-
return await
|
|
712
|
+
return await ao({
|
|
713
713
|
payoutClaimerPsbtBase64: i,
|
|
714
714
|
payoutDepositorPsbtBase64: c,
|
|
715
715
|
assertPsbtBase64: a,
|
|
716
716
|
vault: r
|
|
717
|
-
}),
|
|
717
|
+
}), co({
|
|
718
718
|
graphChallengerPubkeys: Object.keys(u),
|
|
719
719
|
depositorBtcPubkey: o,
|
|
720
720
|
vaultProviderBtcPubkey: r.vaultProviderBtcPubkey,
|
|
@@ -722,7 +722,7 @@ async function Vt(e, t, r, o) {
|
|
|
722
722
|
universalChallengerBtcPubkeys: r.universalChallengerBtcPubkeys
|
|
723
723
|
}), { claim: n, assert: a, payoutClaimer: i, payoutDepositor: c, wronglyChallenged: u };
|
|
724
724
|
}
|
|
725
|
-
async function
|
|
725
|
+
async function Co(e) {
|
|
726
726
|
At({
|
|
727
727
|
servedVerifyingKeyHex: e.source.verifyingKeyHex,
|
|
728
728
|
trustedVerifyingKeyHex: e.trustedVerifyingKeyHex,
|
|
@@ -741,55 +741,55 @@ async function bo(e) {
|
|
|
741
741
|
source: e.source,
|
|
742
742
|
vault: e.vault,
|
|
743
743
|
// Omitted means unjoined: the browser cannot hold the real sessions.
|
|
744
|
-
babeSessionsJson: e.babeSessionsJson === void 0 ?
|
|
744
|
+
babeSessionsJson: e.babeSessionsJson === void 0 ? ko : e.babeSessionsJson,
|
|
745
745
|
requests: It(t)
|
|
746
746
|
};
|
|
747
747
|
}
|
|
748
|
-
function
|
|
749
|
-
|
|
750
|
-
requestedPsbtHex:
|
|
748
|
+
function fe(e, t, r) {
|
|
749
|
+
oe({
|
|
750
|
+
requestedPsbtHex: He(t.psbtBase64),
|
|
751
751
|
signatureHex: r,
|
|
752
752
|
signerXOnlyPubkeyHex: V(e.depositorPublicKey),
|
|
753
753
|
inputIndex: t.inputIndex
|
|
754
754
|
});
|
|
755
755
|
}
|
|
756
|
-
function
|
|
756
|
+
function He(e) {
|
|
757
757
|
return H.from(e, "base64").toString("hex");
|
|
758
758
|
}
|
|
759
759
|
function Rt(e) {
|
|
760
760
|
return H.from(e, "hex").toString("base64");
|
|
761
761
|
}
|
|
762
|
-
class
|
|
762
|
+
class Y extends Error {
|
|
763
763
|
constructor(t) {
|
|
764
764
|
super(t), this.name = "SigningPlanMismatchError";
|
|
765
765
|
}
|
|
766
766
|
}
|
|
767
|
-
function
|
|
767
|
+
function To(e, t) {
|
|
768
768
|
if (e.length !== t.length)
|
|
769
|
-
throw new
|
|
769
|
+
throw new Y(
|
|
770
770
|
`Plan has ${e.length} requests but the graph builds ${t.length}; the plan was altered after planning.`
|
|
771
771
|
);
|
|
772
772
|
for (let r = 0; r < t.length; r++) {
|
|
773
773
|
const o = t[r], s = e[r];
|
|
774
774
|
if (s.id !== o.id)
|
|
775
|
-
throw new
|
|
775
|
+
throw new Y(
|
|
776
776
|
`Plan request at position ${r} is "${s.id}" but the graph builds "${o.id}" there; the plan was altered after planning.`
|
|
777
777
|
);
|
|
778
778
|
if (s.kind !== o.kind)
|
|
779
|
-
throw new
|
|
779
|
+
throw new Y(
|
|
780
780
|
`Plan request "${s.id}" has kind "${s.kind}" but the graph builds "${o.kind}"; the plan was altered after planning.`
|
|
781
781
|
);
|
|
782
782
|
if (s.inputIndex !== o.inputIndex)
|
|
783
|
-
throw new
|
|
783
|
+
throw new Y(
|
|
784
784
|
`Plan request "${s.id}" signs inputIndex ${s.inputIndex} but the graph builds ${o.inputIndex}; the plan was altered after planning.`
|
|
785
785
|
);
|
|
786
786
|
if (s.psbtBase64 !== o.psbtBase64)
|
|
787
|
-
throw new
|
|
787
|
+
throw new Y(
|
|
788
788
|
`Plan request "${s.id}" carries a psbt that differs from the one the graph builds; the plan was altered after planning.`
|
|
789
789
|
);
|
|
790
790
|
}
|
|
791
791
|
}
|
|
792
|
-
function
|
|
792
|
+
function _o(e, t) {
|
|
793
793
|
const r = new Set(e.map((a) => a.id)), o = [...r].filter((a) => !t.has(a)), s = [...t.keys()].filter((a) => !r.has(a));
|
|
794
794
|
if (o.length === 0 && s.length === 0) return;
|
|
795
795
|
const n = (a) => a.map((i) => `"${i}"`).join(", ");
|
|
@@ -797,7 +797,7 @@ function Po(e, t) {
|
|
|
797
797
|
`Signatures do not cover the plan: ${t.size} signatures for ${e.length} requests` + (o.length > 0 ? `; missing ${n(o)}` : "") + (s.length > 0 ? `; extra ${n(s)}` : "") + "."
|
|
798
798
|
);
|
|
799
799
|
}
|
|
800
|
-
function
|
|
800
|
+
function L(e, t) {
|
|
801
801
|
const r = e.get(t);
|
|
802
802
|
if (r === void 0)
|
|
803
803
|
throw new Error(
|
|
@@ -805,7 +805,7 @@ function M(e, t) {
|
|
|
805
805
|
);
|
|
806
806
|
return r;
|
|
807
807
|
}
|
|
808
|
-
async function
|
|
808
|
+
async function So(e) {
|
|
809
809
|
const { plan: t, signatures: r } = e, { txGraphVersion: o } = t.vault, s = t.source.txGraphJson, n = At({
|
|
810
810
|
servedVerifyingKeyHex: t.source.verifyingKeyHex,
|
|
811
811
|
trustedVerifyingKeyHex: t.trustedVerifyingKeyHex,
|
|
@@ -816,34 +816,34 @@ async function wo(e) {
|
|
|
816
816
|
t.vault,
|
|
817
817
|
t.depositorPublicKey
|
|
818
818
|
), i = It(a);
|
|
819
|
-
|
|
819
|
+
To(t.requests, i), _o(i, r);
|
|
820
820
|
for (const c of i)
|
|
821
|
-
|
|
821
|
+
fe(
|
|
822
822
|
t,
|
|
823
823
|
c,
|
|
824
|
-
|
|
824
|
+
L(r, c.id)
|
|
825
825
|
);
|
|
826
826
|
const u = {};
|
|
827
827
|
for (const c of Object.keys(a.wronglyChallenged))
|
|
828
828
|
u[c] = a.wronglyChallenged[c].map(
|
|
829
|
-
(
|
|
829
|
+
(h, d) => L(
|
|
830
830
|
r,
|
|
831
|
-
Bt(c,
|
|
831
|
+
Bt(c, d)
|
|
832
832
|
)
|
|
833
833
|
);
|
|
834
|
-
const l = await
|
|
834
|
+
const l = await pr(
|
|
835
835
|
o,
|
|
836
836
|
s,
|
|
837
|
-
|
|
837
|
+
L(r, "claim")
|
|
838
838
|
);
|
|
839
|
-
return
|
|
839
|
+
return gr({
|
|
840
840
|
txGraphVersion: o,
|
|
841
841
|
graphJson: s,
|
|
842
842
|
signedClaimTxHex: l,
|
|
843
|
-
assertClaimerSigHex:
|
|
844
|
-
payoutClaimerSigHex:
|
|
843
|
+
assertClaimerSigHex: L(r, "assert"),
|
|
844
|
+
payoutClaimerSigHex: L(r, "payoutClaimer"),
|
|
845
845
|
wronglyChallengedSigs: u,
|
|
846
|
-
depositorPayoutSigHex:
|
|
846
|
+
depositorPayoutSigHex: L(r, "payoutDepositor"),
|
|
847
847
|
verifyingKeyHex: n,
|
|
848
848
|
claimableEventBlockNumber: t.vault.claimableEventBlockNumber,
|
|
849
849
|
proverCircuitVersion: t.vault.proverCircuitVersion,
|
|
@@ -852,10 +852,10 @@ async function wo(e) {
|
|
|
852
852
|
expectedVaultCoreVersion: t.vault.vaultCoreVersion
|
|
853
853
|
});
|
|
854
854
|
}
|
|
855
|
-
function
|
|
855
|
+
function Ao(e) {
|
|
856
856
|
return typeof e.signDelegatedClaimPsbt == "function";
|
|
857
857
|
}
|
|
858
|
-
class
|
|
858
|
+
class Bo extends Error {
|
|
859
859
|
constructor(t, r, o, s) {
|
|
860
860
|
super(t, s), this.signatures = r, this.failedRequestId = o, this.name = "DelegatedClaimSigningIncompleteError";
|
|
861
861
|
}
|
|
@@ -866,30 +866,30 @@ const Kt = {
|
|
|
866
866
|
payoutClaimer: "standalone",
|
|
867
867
|
claim: "standalone",
|
|
868
868
|
wronglyChallenged: "standalone"
|
|
869
|
-
},
|
|
869
|
+
}, Io = [
|
|
870
870
|
"payoutClaimer",
|
|
871
871
|
"claim",
|
|
872
872
|
"wronglyChallenged"
|
|
873
873
|
];
|
|
874
|
-
async function
|
|
874
|
+
async function Vo(e, t, r = {}) {
|
|
875
875
|
var s;
|
|
876
|
-
if ((s = r.signal) == null || s.throwIfAborted(),
|
|
876
|
+
if ((s = r.signal) == null || s.throwIfAborted(), Ro(e), V(e.depositorPublicKey) !== e.vault.depositorBtcPubkey)
|
|
877
877
|
throw new Error(
|
|
878
878
|
`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.`
|
|
879
879
|
);
|
|
880
880
|
if (vt(t)) {
|
|
881
|
-
if (!
|
|
881
|
+
if (!Ao(t))
|
|
882
882
|
throw new Error(
|
|
883
883
|
"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."
|
|
884
884
|
);
|
|
885
|
-
const n =
|
|
886
|
-
|
|
887
|
-
const a =
|
|
885
|
+
const n = Ho(r, e);
|
|
886
|
+
Oo(n.depositTerms, e.vault);
|
|
887
|
+
const a = Ko(e), i = await Ze(
|
|
888
888
|
t,
|
|
889
889
|
e.depositorPublicKey,
|
|
890
890
|
e.btcNetwork
|
|
891
891
|
);
|
|
892
|
-
return
|
|
892
|
+
return No(
|
|
893
893
|
e,
|
|
894
894
|
t,
|
|
895
895
|
i,
|
|
@@ -898,14 +898,14 @@ async function ko(e, t, r = {}) {
|
|
|
898
898
|
r
|
|
899
899
|
);
|
|
900
900
|
}
|
|
901
|
-
const o = await
|
|
901
|
+
const o = await Ze(
|
|
902
902
|
t,
|
|
903
903
|
e.depositorPublicKey,
|
|
904
904
|
e.btcNetwork
|
|
905
905
|
);
|
|
906
|
-
return
|
|
906
|
+
return Lo(e, t, o, r.signal);
|
|
907
907
|
}
|
|
908
|
-
function
|
|
908
|
+
function Ro(e) {
|
|
909
909
|
const t = /* @__PURE__ */ new Set();
|
|
910
910
|
for (const r of e.requests) {
|
|
911
911
|
if (t.has(r.id))
|
|
@@ -915,10 +915,10 @@ function To(e) {
|
|
|
915
915
|
t.add(r.id);
|
|
916
916
|
}
|
|
917
917
|
}
|
|
918
|
-
function
|
|
918
|
+
function Ko(e) {
|
|
919
919
|
const t = e.requests.filter(
|
|
920
920
|
(s) => Kt[s.kind] === "intentBound"
|
|
921
|
-
), r =
|
|
921
|
+
), r = Io.flatMap(
|
|
922
922
|
(s) => e.requests.filter((n) => n.kind === s)
|
|
923
923
|
), o = t.length + r.length;
|
|
924
924
|
if (o !== e.requests.length)
|
|
@@ -933,7 +933,7 @@ function Ht(e, t) {
|
|
|
933
933
|
`Delegated-claim signing ended with ${t.size} signatures for ${e.requests.length} requests; the set is incomplete and must not be treated as signed.`
|
|
934
934
|
);
|
|
935
935
|
}
|
|
936
|
-
function
|
|
936
|
+
function Ho(e, t) {
|
|
937
937
|
if (e.depositTerms === void 0)
|
|
938
938
|
throw new Error(
|
|
939
939
|
"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."
|
|
@@ -942,14 +942,14 @@ function _o(e, t) {
|
|
|
942
942
|
throw new Error(
|
|
943
943
|
"An approval wallet releases a loaded intent only through the vault-root derivation; pass vaultContext so that derivation can run before and after the intent-bound signatures."
|
|
944
944
|
);
|
|
945
|
-
const r =
|
|
945
|
+
const r = yt(e.vaultContext.depositorBtcPubkey);
|
|
946
946
|
if (r !== t.vault.depositorBtcPubkey)
|
|
947
947
|
throw new Error(
|
|
948
948
|
`vaultContext derives from depositor key ${r} but this plan's vault is registered to ${t.vault.depositorBtcPubkey}; the device would derive for another depositor.`
|
|
949
949
|
);
|
|
950
950
|
return { depositTerms: e.depositTerms, vaultContext: e.vaultContext };
|
|
951
951
|
}
|
|
952
|
-
function
|
|
952
|
+
function Oo(e, t) {
|
|
953
953
|
const r = (s) => s.map((n) => V(n)).sort().join(",");
|
|
954
954
|
if (r(e.vaultKeeperBtcPubkeys) !== r(t.vaultKeeperBtcPubkeys) || r(e.universalChallengerBtcPubkeys) !== r(t.universalChallengerBtcPubkeys))
|
|
955
955
|
throw new Error(
|
|
@@ -982,18 +982,18 @@ function So(e, t) {
|
|
|
982
982
|
`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.`
|
|
983
983
|
);
|
|
984
984
|
}
|
|
985
|
-
async function
|
|
985
|
+
async function No(e, t, r, o, { intentBound: s, standalone: n }, a) {
|
|
986
986
|
var g;
|
|
987
|
-
const i =
|
|
987
|
+
const i = Do(e, a.resume), u = [...s, ...n];
|
|
988
988
|
let l = 0;
|
|
989
989
|
const c = {
|
|
990
990
|
phase: "clearing any loaded intent"
|
|
991
|
-
},
|
|
991
|
+
}, h = async (p) => {
|
|
992
992
|
var m;
|
|
993
993
|
c.phase = "signing", (m = a.signal) == null || m.throwIfAborted();
|
|
994
994
|
const y = await t.signDelegatedClaimPsbt(
|
|
995
|
-
|
|
996
|
-
|
|
995
|
+
He(p.psbtBase64),
|
|
996
|
+
kt(
|
|
997
997
|
e.depositorPublicKey,
|
|
998
998
|
p.inputIndex,
|
|
999
999
|
r
|
|
@@ -1002,24 +1002,24 @@ async function Ao(e, t, r, o, { intentBound: s, standalone: n }, a) {
|
|
|
1002
1002
|
Rt(y),
|
|
1003
1003
|
p.inputIndex
|
|
1004
1004
|
);
|
|
1005
|
-
|
|
1006
|
-
},
|
|
1005
|
+
fe(e, p, f), i.set(p.id, f);
|
|
1006
|
+
}, d = async (p) => {
|
|
1007
1007
|
var f;
|
|
1008
|
-
c.phase = p, (f = a.signal) == null || f.throwIfAborted(), (await
|
|
1008
|
+
c.phase = p, (f = a.signal) == null || f.throwIfAborted(), (await $t(t, o.vaultContext)).fill(0);
|
|
1009
1009
|
};
|
|
1010
1010
|
typeof t.validateDepositTerms == "function" && await t.validateDepositTerms(o.depositTerms);
|
|
1011
1011
|
try {
|
|
1012
|
-
await
|
|
1012
|
+
await d("clearing any loaded intent"), c.phase = "approving the deposit terms", (g = a.signal) == null || g.throwIfAborted(), await t.approveDepositTerms(o.depositTerms);
|
|
1013
1013
|
for (const p of s)
|
|
1014
|
-
await
|
|
1015
|
-
await
|
|
1014
|
+
await h(p), l++;
|
|
1015
|
+
await d("releasing the loaded intent");
|
|
1016
1016
|
for (const p of n)
|
|
1017
|
-
i.has(p.id) || await
|
|
1017
|
+
i.has(p.id) || await h(p), l++;
|
|
1018
1018
|
} catch (p) {
|
|
1019
1019
|
const y = u[l];
|
|
1020
1020
|
if (i.size === 0 || y === void 0) throw p;
|
|
1021
1021
|
const f = c.phase === "signing" ? `stopped at "${y.id}"` : `stopped before "${y.id}" while ${c.phase}`;
|
|
1022
|
-
throw new
|
|
1022
|
+
throw new Bo(
|
|
1023
1023
|
`Delegated-claim signing ${f}; ${i.size} of ${e.requests.length} signatures were collected.`,
|
|
1024
1024
|
i,
|
|
1025
1025
|
y.id,
|
|
@@ -1028,14 +1028,14 @@ async function Ao(e, t, r, o, { intentBound: s, standalone: n }, a) {
|
|
|
1028
1028
|
}
|
|
1029
1029
|
return Ht(e, i), i;
|
|
1030
1030
|
}
|
|
1031
|
-
function
|
|
1031
|
+
function Do(e, t) {
|
|
1032
1032
|
const r = /* @__PURE__ */ new Map();
|
|
1033
1033
|
if (!t) return r;
|
|
1034
1034
|
for (const o of e.requests) {
|
|
1035
1035
|
const s = t.get(o.id);
|
|
1036
1036
|
if (!(s === void 0 || Kt[o.kind] === "intentBound")) {
|
|
1037
1037
|
try {
|
|
1038
|
-
|
|
1038
|
+
fe(e, o, s);
|
|
1039
1039
|
} catch {
|
|
1040
1040
|
continue;
|
|
1041
1041
|
}
|
|
@@ -1044,12 +1044,12 @@ function Bo(e, t) {
|
|
|
1044
1044
|
}
|
|
1045
1045
|
return r;
|
|
1046
1046
|
}
|
|
1047
|
-
async function
|
|
1047
|
+
async function Lo(e, t, r, o) {
|
|
1048
1048
|
const s = e.requests, n = await bt(
|
|
1049
1049
|
t,
|
|
1050
|
-
s.map((i) =>
|
|
1050
|
+
s.map((i) => He(i.psbtBase64)),
|
|
1051
1051
|
s.map(
|
|
1052
|
-
(i) =>
|
|
1052
|
+
(i) => kt(
|
|
1053
1053
|
e.depositorPublicKey,
|
|
1054
1054
|
i.inputIndex,
|
|
1055
1055
|
r
|
|
@@ -1062,39 +1062,39 @@ async function Io(e, t, r, o) {
|
|
|
1062
1062
|
Rt(n[i]),
|
|
1063
1063
|
s[i].inputIndex
|
|
1064
1064
|
);
|
|
1065
|
-
|
|
1065
|
+
fe(e, s[i], u), a.set(s[i].id, u);
|
|
1066
1066
|
}
|
|
1067
1067
|
return Ht(e, a), a;
|
|
1068
1068
|
}
|
|
1069
|
-
async function
|
|
1070
|
-
const t = await
|
|
1069
|
+
async function ln(e) {
|
|
1070
|
+
const t = await Co({
|
|
1071
1071
|
depositorPublicKey: e.depositorPublicKey,
|
|
1072
1072
|
btcNetwork: e.btcNetwork,
|
|
1073
1073
|
source: e.source,
|
|
1074
1074
|
trustedVerifyingKeyHex: e.trustedVerifyingKeyHex,
|
|
1075
1075
|
vault: e.vault,
|
|
1076
1076
|
babeSessionsJson: e.babeSessionsJson
|
|
1077
|
-
}), r = await
|
|
1077
|
+
}), r = await Vo(t, e.btcWallet, {
|
|
1078
1078
|
depositTerms: e.depositTerms,
|
|
1079
1079
|
vaultContext: e.vaultContext
|
|
1080
1080
|
});
|
|
1081
|
-
return
|
|
1081
|
+
return So({ plan: t, signatures: r });
|
|
1082
1082
|
}
|
|
1083
|
-
async function
|
|
1084
|
-
const t = await
|
|
1083
|
+
async function dn(e) {
|
|
1084
|
+
const t = await $t(e.btcWallet, e.vaultContext);
|
|
1085
1085
|
let r;
|
|
1086
1086
|
try {
|
|
1087
|
-
r = await
|
|
1087
|
+
r = await fr(t, e.htlcVout);
|
|
1088
1088
|
} finally {
|
|
1089
1089
|
t.fill(0);
|
|
1090
1090
|
}
|
|
1091
1091
|
let o;
|
|
1092
1092
|
try {
|
|
1093
|
-
o = await
|
|
1093
|
+
o = await yr(r);
|
|
1094
1094
|
} finally {
|
|
1095
1095
|
r.fill(0);
|
|
1096
1096
|
}
|
|
1097
|
-
return
|
|
1097
|
+
return Mo(o.pk_hash, e.expectedWotsPkHash), await vr(
|
|
1098
1098
|
e.txGraphVersion,
|
|
1099
1099
|
o.keypair,
|
|
1100
1100
|
e.txGraphJson
|
|
@@ -1103,16 +1103,16 @@ async function rn(e) {
|
|
|
1103
1103
|
pkHash: o.pk_hash
|
|
1104
1104
|
};
|
|
1105
1105
|
}
|
|
1106
|
-
function
|
|
1107
|
-
if (
|
|
1106
|
+
function Mo(e, t) {
|
|
1107
|
+
if (ie(e) !== ie(t))
|
|
1108
1108
|
throw new Error(
|
|
1109
|
-
`Derived WOTS public-key hash ${
|
|
1109
|
+
`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.`
|
|
1110
1110
|
);
|
|
1111
1111
|
}
|
|
1112
|
-
function
|
|
1112
|
+
function ie(e) {
|
|
1113
1113
|
return `0x${(e.startsWith("0x") ? e.slice(2) : e).toLowerCase()}`;
|
|
1114
1114
|
}
|
|
1115
|
-
function
|
|
1115
|
+
function xe(e, t, r) {
|
|
1116
1116
|
const o = `${e} operation key (admin=${t.ethAddress})`, s = _e(
|
|
1117
1117
|
t.btcPubKey,
|
|
1118
1118
|
`${e} roster key (admin=${t.ethAddress})`
|
|
@@ -1124,7 +1124,7 @@ function we(e, t, r) {
|
|
|
1124
1124
|
rotated: n !== s
|
|
1125
1125
|
};
|
|
1126
1126
|
}
|
|
1127
|
-
function
|
|
1127
|
+
function Fo(e) {
|
|
1128
1128
|
const t = /* @__PURE__ */ new Map();
|
|
1129
1129
|
for (const r of e) {
|
|
1130
1130
|
const o = t.get(r.operationBtcPubkey);
|
|
@@ -1135,12 +1135,12 @@ function Ro(e) {
|
|
|
1135
1135
|
t.set(r.operationBtcPubkey, r.adminAddress);
|
|
1136
1136
|
}
|
|
1137
1137
|
}
|
|
1138
|
-
function
|
|
1138
|
+
function Ot(e, t, r) {
|
|
1139
1139
|
if (t.vaultKeepers.length !== e.vaultKeepers.length || t.universalChallengers.length !== e.universalChallengers.length)
|
|
1140
1140
|
throw new Error(
|
|
1141
1141
|
`Operation-key resolution returned ${t.vaultKeepers.length} keeper and ${t.universalChallengers.length} challenger keys for a roster of ${e.vaultKeepers.length} keepers and ${e.universalChallengers.length} challengers`
|
|
1142
1142
|
);
|
|
1143
|
-
const o =
|
|
1143
|
+
const o = xe(
|
|
1144
1144
|
"vault provider",
|
|
1145
1145
|
{
|
|
1146
1146
|
ethAddress: e.vaultProviderEthAddress,
|
|
@@ -1148,11 +1148,11 @@ function Nt(e, t, r) {
|
|
|
1148
1148
|
},
|
|
1149
1149
|
t.vaultProvider
|
|
1150
1150
|
), s = e.vaultKeepers.map(
|
|
1151
|
-
(a, i) =>
|
|
1151
|
+
(a, i) => xe("vault keeper", a, t.vaultKeepers[i])
|
|
1152
1152
|
), n = e.universalChallengers.map(
|
|
1153
|
-
(a, i) =>
|
|
1153
|
+
(a, i) => xe("universal challenger", a, t.universalChallengers[i])
|
|
1154
1154
|
);
|
|
1155
|
-
return
|
|
1155
|
+
return Fo([
|
|
1156
1156
|
o,
|
|
1157
1157
|
...s,
|
|
1158
1158
|
...n
|
|
@@ -1167,24 +1167,24 @@ function Nt(e, t, r) {
|
|
|
1167
1167
|
query: e
|
|
1168
1168
|
};
|
|
1169
1169
|
}
|
|
1170
|
-
async function
|
|
1170
|
+
async function Uo(e) {
|
|
1171
1171
|
const t = await e.operationKeyReader.getCurrentOperationKeys(
|
|
1172
1172
|
e.query,
|
|
1173
1173
|
e.blockNumber
|
|
1174
1174
|
);
|
|
1175
|
-
return
|
|
1175
|
+
return Ot(e.query, t, { mode: "current" });
|
|
1176
1176
|
}
|
|
1177
|
-
async function
|
|
1177
|
+
async function Nt(e) {
|
|
1178
1178
|
const t = await e.operationKeyReader.getOperationKeysAtEpochs(
|
|
1179
1179
|
e.query,
|
|
1180
1180
|
e.epochs
|
|
1181
1181
|
);
|
|
1182
|
-
return
|
|
1182
|
+
return Ot(e.query, t, {
|
|
1183
1183
|
mode: "epochs",
|
|
1184
1184
|
epochs: e.epochs
|
|
1185
1185
|
});
|
|
1186
1186
|
}
|
|
1187
|
-
async function
|
|
1187
|
+
async function qo(e) {
|
|
1188
1188
|
const { basic: t, protocol: r } = e.vault, {
|
|
1189
1189
|
registryReader: o,
|
|
1190
1190
|
vaultKeeperReader: s,
|
|
@@ -1214,7 +1214,7 @@ async function Ho(e) {
|
|
|
1214
1214
|
throw new Error(
|
|
1215
1215
|
`No universal challengers for version ${r.universalChallengersVersion}`
|
|
1216
1216
|
);
|
|
1217
|
-
return
|
|
1217
|
+
return Nt({
|
|
1218
1218
|
operationKeyReader: a,
|
|
1219
1219
|
query: {
|
|
1220
1220
|
vaultProviderEthAddress: t.vaultProvider,
|
|
@@ -1226,7 +1226,7 @@ async function Ho(e) {
|
|
|
1226
1226
|
epochs: c
|
|
1227
1227
|
});
|
|
1228
1228
|
}
|
|
1229
|
-
async function
|
|
1229
|
+
async function hn(e) {
|
|
1230
1230
|
const { vaultId: t, readers: r } = e, o = await r.registryReader.getVaultData(t), { basic: s, protocol: n } = o;
|
|
1231
1231
|
if (n.vaultCoreVersion !== U)
|
|
1232
1232
|
throw new Error(
|
|
@@ -1236,19 +1236,19 @@ async function on(e) {
|
|
|
1236
1236
|
s.depositorBtcPubKey,
|
|
1237
1237
|
`getBtcVaultBasicInfo(${t}).depositorBtcPubKey`
|
|
1238
1238
|
);
|
|
1239
|
-
if (s.status !==
|
|
1240
|
-
throw new
|
|
1239
|
+
if (s.status !== ze.REDEEMED)
|
|
1240
|
+
throw new Le(
|
|
1241
1241
|
t,
|
|
1242
1242
|
s.depositorBtcPubKey,
|
|
1243
1243
|
s.createdAt,
|
|
1244
1244
|
s.createdAt,
|
|
1245
|
-
`the vault's status is ${s.status}, not Redeemed (${
|
|
1245
|
+
`the vault's status is ${s.status}, not Redeemed (${ze.REDEEMED}); no scan was made`
|
|
1246
1246
|
);
|
|
1247
1247
|
const [i, u, l, c] = await Promise.all([
|
|
1248
|
-
|
|
1248
|
+
qo({ vaultId: t, vault: o, readers: r }),
|
|
1249
1249
|
r.registryReader.getRegistrationRecordsAtBlock(s.createdAt),
|
|
1250
1250
|
r.registryReader.getVaultClaimableBy(t, s.depositorBtcPubKey, s.createdAt).catch((v) => {
|
|
1251
|
-
throw
|
|
1251
|
+
throw xr(v) ? new Le(
|
|
1252
1252
|
t,
|
|
1253
1253
|
s.depositorBtcPubKey,
|
|
1254
1254
|
v.fromBlock,
|
|
@@ -1260,54 +1260,54 @@ async function on(e) {
|
|
|
1260
1260
|
r.protocolParamsReader.getOffchainParamsByVersion(
|
|
1261
1261
|
n.offchainParamsVersion
|
|
1262
1262
|
)
|
|
1263
|
-
]),
|
|
1264
|
-
|
|
1265
|
-
const g =
|
|
1263
|
+
]), h = Rr(c.timelockAssert), d = Er(u, t, s.createdAt);
|
|
1264
|
+
kr(d);
|
|
1265
|
+
const g = $r(d);
|
|
1266
1266
|
if (g.toLowerCase() !== n.prePeginTxHash.toLowerCase())
|
|
1267
1267
|
throw new Error(
|
|
1268
1268
|
`Registration log of vault ${t} records prePeginTxHash ${g} but the vault record says ${n.prePeginTxHash}; refusing an inconsistent node.`
|
|
1269
1269
|
);
|
|
1270
|
-
if (
|
|
1270
|
+
if (d.vaultCoreVersion !== n.vaultCoreVersion)
|
|
1271
1271
|
throw new Error(
|
|
1272
|
-
`Registration log of vault ${t} records vault core version ${
|
|
1272
|
+
`Registration log of vault ${t} records vault core version ${d.vaultCoreVersion} but the vault record says ${n.vaultCoreVersion}; refusing an inconsistent node.`
|
|
1273
1273
|
);
|
|
1274
|
-
if (
|
|
1274
|
+
if (d.amount !== s.amount)
|
|
1275
1275
|
throw new Error(
|
|
1276
|
-
`Registration log of vault ${t} records amount ${
|
|
1276
|
+
`Registration log of vault ${t} records amount ${d.amount} sats but the vault record says ${s.amount}; refusing an inconsistent node.`
|
|
1277
1277
|
);
|
|
1278
|
-
if (
|
|
1278
|
+
if (d.depositor.toLowerCase() !== s.depositor.toLowerCase())
|
|
1279
1279
|
throw new Error(
|
|
1280
|
-
`Registration log of vault ${t} records depositor ${
|
|
1280
|
+
`Registration log of vault ${t} records depositor ${d.depositor} but the vault record says ${s.depositor}; refusing an inconsistent node.`
|
|
1281
1281
|
);
|
|
1282
|
-
if (
|
|
1282
|
+
if (d.vaultProvider.toLowerCase() !== s.vaultProvider.toLowerCase())
|
|
1283
1283
|
throw new Error(
|
|
1284
|
-
`Registration log of vault ${t} records vaultProvider ${
|
|
1284
|
+
`Registration log of vault ${t} records vaultProvider ${d.vaultProvider} but the vault record says ${s.vaultProvider}; refusing an inconsistent node.`
|
|
1285
1285
|
);
|
|
1286
1286
|
if (l.vaultCoreVersion !== n.vaultCoreVersion)
|
|
1287
1287
|
throw new Error(
|
|
1288
1288
|
`Redemption log of vault ${t} records vault core version ${l.vaultCoreVersion} but the vault record says ${n.vaultCoreVersion}; refusing an inconsistent node.`
|
|
1289
1289
|
);
|
|
1290
|
-
if (l.proverCircuitVersion !==
|
|
1290
|
+
if (l.proverCircuitVersion !== d.proverCircuitVersion)
|
|
1291
1291
|
throw new Error(
|
|
1292
|
-
`Redemption log of vault ${t} records proverCircuitVersion ${l.proverCircuitVersion} but the registration log says ${
|
|
1292
|
+
`Redemption log of vault ${t} records proverCircuitVersion ${l.proverCircuitVersion} but the registration log says ${d.proverCircuitVersion}; refusing an inconsistent node.`
|
|
1293
1293
|
);
|
|
1294
|
-
if (
|
|
1294
|
+
if (d.proverCircuitVersion !== c.proverCircuitVersion)
|
|
1295
1295
|
throw new Error(
|
|
1296
|
-
`Registration log of vault ${t} records proverCircuitVersion ${
|
|
1296
|
+
`Registration log of vault ${t} records proverCircuitVersion ${d.proverCircuitVersion} but the stamped offchain params say ${c.proverCircuitVersion}; refusing an inconsistent node.`
|
|
1297
1297
|
);
|
|
1298
|
-
const p =
|
|
1298
|
+
const p = Cr(n.depositorSignedPeginTx);
|
|
1299
1299
|
for (const [v, E] of [
|
|
1300
|
-
["Registration",
|
|
1300
|
+
["Registration", d.peginTxHash],
|
|
1301
1301
|
["Redemption", l.peginTxHash]
|
|
1302
1302
|
])
|
|
1303
1303
|
if (E.toLowerCase() !== p.toLowerCase())
|
|
1304
1304
|
throw new Error(
|
|
1305
1305
|
`${v} log of vault ${t} records peginTxHash ${E} but the vault's depositor-signed PegIn hashes to ${p}; refusing an inconsistent node.`
|
|
1306
1306
|
);
|
|
1307
|
-
const y =
|
|
1307
|
+
const y = z(
|
|
1308
1308
|
Pt(p, s.depositor)
|
|
1309
1309
|
);
|
|
1310
|
-
if (y !==
|
|
1310
|
+
if (y !== z(t))
|
|
1311
1311
|
throw new Error(
|
|
1312
1312
|
`Depositor-signed PegIn of vault ${t} derives vault id ${y} with depositor ${s.depositor}; refusing an inconsistent node.`
|
|
1313
1313
|
);
|
|
@@ -1316,9 +1316,9 @@ async function on(e) {
|
|
|
1316
1316
|
"universalChallengersVersion",
|
|
1317
1317
|
"appVaultKeepersVersion"
|
|
1318
1318
|
]) {
|
|
1319
|
-
if (
|
|
1319
|
+
if (d[v] !== n[v])
|
|
1320
1320
|
throw new Error(
|
|
1321
|
-
`Registration log of vault ${t} records ${v} ${
|
|
1321
|
+
`Registration log of vault ${t} records ${v} ${d[v]} but the vault record says ${n[v]}; refusing an inconsistent node.`
|
|
1322
1322
|
);
|
|
1323
1323
|
if (l[v] !== n[v])
|
|
1324
1324
|
throw new Error(
|
|
@@ -1332,19 +1332,19 @@ async function on(e) {
|
|
|
1332
1332
|
throw new Error(
|
|
1333
1333
|
`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.`
|
|
1334
1334
|
);
|
|
1335
|
-
const m =
|
|
1336
|
-
if (m !== b(n.prePeginTxHash).toLowerCase() ||
|
|
1335
|
+
const m = Ke(f.ins[0].hash), $ = f.ins[0].index;
|
|
1336
|
+
if (m !== b(n.prePeginTxHash).toLowerCase() || $ !== n.htlcVout)
|
|
1337
1337
|
throw new Error(
|
|
1338
|
-
`Depositor-signed PegIn of vault ${t} spends ${m}:${
|
|
1338
|
+
`Depositor-signed PegIn of vault ${t} spends ${m}:${$} but the vault record says Pre-PegIn ${n.prePeginTxHash} output ${n.htlcVout}; refusing an inconsistent node.`
|
|
1339
1339
|
);
|
|
1340
|
-
const x = f.outs[
|
|
1340
|
+
const x = f.outs[Z];
|
|
1341
1341
|
if (x === void 0)
|
|
1342
1342
|
throw new Error(
|
|
1343
|
-
`Depositor-signed PegIn of vault ${t} has no output ${
|
|
1343
|
+
`Depositor-signed PegIn of vault ${t} has no output ${Z}; the Payout cannot spend the Vault UTXO.`
|
|
1344
1344
|
);
|
|
1345
1345
|
if (BigInt(x.value) !== s.amount)
|
|
1346
1346
|
throw new Error(
|
|
1347
|
-
`Depositor-signed PegIn of vault ${t} pays ${x.value} sats to output ${
|
|
1347
|
+
`Depositor-signed PegIn of vault ${t} pays ${x.value} sats to output ${Z} but the vault record says ${s.amount}; refusing an inconsistent node.`
|
|
1348
1348
|
);
|
|
1349
1349
|
return {
|
|
1350
1350
|
context: {
|
|
@@ -1352,7 +1352,7 @@ async function on(e) {
|
|
|
1352
1352
|
depositorEthAddress: s.depositor,
|
|
1353
1353
|
depositorBtcPubkey: a,
|
|
1354
1354
|
registeredPayoutScriptPubKey: b(
|
|
1355
|
-
|
|
1355
|
+
d.depositorPayoutScriptPubKey
|
|
1356
1356
|
),
|
|
1357
1357
|
vaultProviderBtcPubkey: i.vaultProvider.operationBtcPubkey,
|
|
1358
1358
|
vaultKeeperBtcPubkeys: [
|
|
@@ -1368,11 +1368,11 @@ async function on(e) {
|
|
|
1368
1368
|
peginVaultOutputValueSats: x.value,
|
|
1369
1369
|
protocolFeeRate: c.feeRate,
|
|
1370
1370
|
councilSize: c.securityCouncilKeys.length,
|
|
1371
|
-
timelockPegin:
|
|
1371
|
+
timelockPegin: h,
|
|
1372
1372
|
timelockAssert: Number(c.timelockAssert)
|
|
1373
1373
|
},
|
|
1374
1374
|
vault: o,
|
|
1375
|
-
registrationRecord:
|
|
1375
|
+
registrationRecord: d,
|
|
1376
1376
|
registrationRecords: u,
|
|
1377
1377
|
participantKeys: i,
|
|
1378
1378
|
offchainParams: c,
|
|
@@ -1384,35 +1384,35 @@ async function on(e) {
|
|
|
1384
1384
|
htlcVout: n.htlcVout
|
|
1385
1385
|
};
|
|
1386
1386
|
}
|
|
1387
|
-
const
|
|
1387
|
+
const Go = 8, Xo = 6e3, zo = 10 * 6e4, jo = 10;
|
|
1388
1388
|
class Dt extends Error {
|
|
1389
1389
|
constructor(t) {
|
|
1390
1390
|
super(t), this.name = "PeginRegistrationMissingError";
|
|
1391
1391
|
}
|
|
1392
1392
|
}
|
|
1393
|
-
class
|
|
1393
|
+
class Lt extends Error {
|
|
1394
1394
|
constructor(t) {
|
|
1395
1395
|
super(t), this.name = "PeginRegistrationNotFinalError";
|
|
1396
1396
|
}
|
|
1397
1397
|
}
|
|
1398
|
-
function
|
|
1398
|
+
function Wo(e) {
|
|
1399
1399
|
return e instanceof Dt || e instanceof Error && e.name === "PeginRegistrationMissingError";
|
|
1400
1400
|
}
|
|
1401
|
-
function
|
|
1402
|
-
return e instanceof
|
|
1401
|
+
function pn(e) {
|
|
1402
|
+
return e instanceof Lt || e instanceof Error && e.name === "PeginRegistrationNotFinalError";
|
|
1403
1403
|
}
|
|
1404
|
-
function
|
|
1404
|
+
function et(e) {
|
|
1405
1405
|
const { currentBlock: t, createdAtBlock: r } = e, o = t - r + 1n;
|
|
1406
1406
|
return o < 0n ? 0 : Number(o);
|
|
1407
1407
|
}
|
|
1408
|
-
async function
|
|
1408
|
+
async function gn(e) {
|
|
1409
1409
|
const {
|
|
1410
1410
|
vaultRegistryReader: t,
|
|
1411
1411
|
getBlockNumber: r,
|
|
1412
1412
|
vaultIds: o,
|
|
1413
|
-
required: s =
|
|
1414
|
-
pollIntervalMs: n =
|
|
1415
|
-
timeoutMs: a =
|
|
1413
|
+
required: s = Go,
|
|
1414
|
+
pollIntervalMs: n = Xo,
|
|
1415
|
+
timeoutMs: a = zo,
|
|
1416
1416
|
signal: i,
|
|
1417
1417
|
onProgress: u
|
|
1418
1418
|
} = e;
|
|
@@ -1421,52 +1421,52 @@ async function nn(e) {
|
|
|
1421
1421
|
"waitForPeginRegistrationDepth requires at least one vault ID"
|
|
1422
1422
|
);
|
|
1423
1423
|
const l = Date.now();
|
|
1424
|
-
let c = !1,
|
|
1424
|
+
let c = !1, h = 0, d;
|
|
1425
1425
|
for (; ; ) {
|
|
1426
1426
|
if (i != null && i.aborted)
|
|
1427
1427
|
throw new Error(
|
|
1428
1428
|
`Aborted while waiting for peg-in registration depth (${o.length} vault(s))`
|
|
1429
1429
|
);
|
|
1430
1430
|
if (Date.now() - l >= a)
|
|
1431
|
-
throw new
|
|
1432
|
-
`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.` + (
|
|
1431
|
+
throw new Lt(
|
|
1432
|
+
`Peg-in registration did not reach ${s} Ethereum confirmations within ${a}ms. The registration transaction was submitted but is not yet final, so the Pre-PegIn Bitcoin transaction was never sent and no funds are at risk. Resume this deposit from the dashboard once the network settles.` + (d instanceof Error ? ` Last read error: ${d.message}` : "")
|
|
1433
1433
|
);
|
|
1434
1434
|
try {
|
|
1435
1435
|
const g = await r(), p = await Promise.all(
|
|
1436
1436
|
o.map((f) => t.getVaultBasicInfo(f))
|
|
1437
1437
|
), y = p.findIndex(
|
|
1438
|
-
(f) => f.depositor ===
|
|
1438
|
+
(f) => f.depositor === Kr || f.createdAt === 0n
|
|
1439
1439
|
);
|
|
1440
1440
|
if (y !== -1) {
|
|
1441
|
-
if (
|
|
1441
|
+
if (h += 1, !c && h > jo)
|
|
1442
1442
|
throw new Dt(
|
|
1443
|
-
`Vault ${o[y]} is still not visible on-chain after ${
|
|
1443
|
+
`Vault ${o[y]} is still not visible on-chain after ${h} reads — the registration does not exist.`
|
|
1444
1444
|
);
|
|
1445
1445
|
console.warn(
|
|
1446
1446
|
`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.`
|
|
1447
1447
|
), u == null || u({ confirmations: 0, required: s });
|
|
1448
1448
|
} else {
|
|
1449
|
-
c = !0,
|
|
1450
|
-
let f = p[0], m =
|
|
1449
|
+
c = !0, h = 0, d = void 0;
|
|
1450
|
+
let f = p[0], m = et({
|
|
1451
1451
|
currentBlock: g,
|
|
1452
1452
|
createdAtBlock: p[0].createdAt
|
|
1453
1453
|
});
|
|
1454
|
-
for (const
|
|
1455
|
-
const x =
|
|
1454
|
+
for (const $ of p.slice(1)) {
|
|
1455
|
+
const x = et({
|
|
1456
1456
|
currentBlock: g,
|
|
1457
|
-
createdAtBlock:
|
|
1457
|
+
createdAtBlock: $.createdAt
|
|
1458
1458
|
});
|
|
1459
|
-
x < m && (m = x, f =
|
|
1459
|
+
x < m && (m = x, f = $);
|
|
1460
1460
|
}
|
|
1461
1461
|
if (u == null || u({ confirmations: m, required: s }), m >= s)
|
|
1462
1462
|
return { confirmations: m, basicInfo: f };
|
|
1463
1463
|
}
|
|
1464
1464
|
} catch (g) {
|
|
1465
|
-
if (
|
|
1465
|
+
if (Wo(g))
|
|
1466
1466
|
throw g;
|
|
1467
1467
|
console.warn(
|
|
1468
1468
|
`Registration-depth read failed (retrying in ${n}ms): ` + (g instanceof Error ? g.message : String(g))
|
|
1469
|
-
),
|
|
1469
|
+
), d = g;
|
|
1470
1470
|
}
|
|
1471
1471
|
await new Promise((g, p) => {
|
|
1472
1472
|
const y = () => {
|
|
@@ -1482,19 +1482,19 @@ async function nn(e) {
|
|
|
1482
1482
|
});
|
|
1483
1483
|
}
|
|
1484
1484
|
}
|
|
1485
|
-
const
|
|
1485
|
+
const Yo = /^(?:[0-9a-f]{2})*$/, Jo = /^[0-9a-f]{64}$/, Qo = /^([0-9a-f]{64}):(0|[1-9][0-9]*)$/, Zo = -2147483648, es = 2147483647, Ee = 4294967295, tt = 2, rt = 2, de = 0;
|
|
1486
1486
|
class P extends Error {
|
|
1487
1487
|
constructor(t) {
|
|
1488
1488
|
super(t), this.name = "GraphFingerprintError";
|
|
1489
1489
|
}
|
|
1490
1490
|
}
|
|
1491
|
-
function
|
|
1491
|
+
function k(e, t, r) {
|
|
1492
1492
|
const o = e[t];
|
|
1493
1493
|
if (o === void 0)
|
|
1494
1494
|
throw new P(`Graph tx ${r} is missing "${t}"`);
|
|
1495
1495
|
return o;
|
|
1496
1496
|
}
|
|
1497
|
-
function
|
|
1497
|
+
function te(e, t) {
|
|
1498
1498
|
if (!Array.isArray(e))
|
|
1499
1499
|
throw new P(`Graph tx ${t} is not an array`);
|
|
1500
1500
|
return e;
|
|
@@ -1504,60 +1504,60 @@ function B(e, t) {
|
|
|
1504
1504
|
throw new P(`Graph tx ${t} is not an object`);
|
|
1505
1505
|
return e;
|
|
1506
1506
|
}
|
|
1507
|
-
function
|
|
1507
|
+
function J(e, t, r, o) {
|
|
1508
1508
|
if (typeof e != "number" || !Number.isSafeInteger(e) || e < r || e > o)
|
|
1509
1509
|
throw new P(
|
|
1510
1510
|
`Graph tx ${t} is not an integer in [${r}, ${o}]`
|
|
1511
1511
|
);
|
|
1512
1512
|
return e;
|
|
1513
1513
|
}
|
|
1514
|
-
function
|
|
1515
|
-
if (typeof e != "string" || !
|
|
1514
|
+
function ke(e, t) {
|
|
1515
|
+
if (typeof e != "string" || !Yo.test(e))
|
|
1516
1516
|
throw new P(
|
|
1517
1517
|
`Graph tx ${t} is not lowercase hex without a prefix`
|
|
1518
1518
|
);
|
|
1519
1519
|
return H.from(e, "hex");
|
|
1520
1520
|
}
|
|
1521
|
-
function
|
|
1522
|
-
if (typeof e != "string" || !
|
|
1521
|
+
function he(e, t) {
|
|
1522
|
+
if (typeof e != "string" || !Jo.test(e))
|
|
1523
1523
|
throw new P(
|
|
1524
1524
|
`Graph ${t} is not 32 bytes of lowercase hex`
|
|
1525
1525
|
);
|
|
1526
1526
|
return e;
|
|
1527
1527
|
}
|
|
1528
|
-
function
|
|
1528
|
+
function ot(e, t) {
|
|
1529
1529
|
const r = B(e, t), o = new S();
|
|
1530
|
-
return o.version =
|
|
1531
|
-
|
|
1530
|
+
return o.version = J(
|
|
1531
|
+
k(r, "version", t),
|
|
1532
1532
|
`${t}.version`,
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
), o.locktime =
|
|
1536
|
-
|
|
1533
|
+
Zo,
|
|
1534
|
+
es
|
|
1535
|
+
), o.locktime = J(
|
|
1536
|
+
k(r, "lock_time", t),
|
|
1537
1537
|
`${t}.lock_time`,
|
|
1538
1538
|
0,
|
|
1539
|
-
|
|
1540
|
-
),
|
|
1541
|
-
const a = `${t}.input[${n}]`, i = B(s, a), u =
|
|
1539
|
+
Ee
|
|
1540
|
+
), te(k(r, "input", t), `${t}.input`).forEach((s, n) => {
|
|
1541
|
+
const a = `${t}.input[${n}]`, i = B(s, a), u = k(i, "previous_output", a), l = typeof u == "string" && Qo.exec(u);
|
|
1542
1542
|
if (!l)
|
|
1543
1543
|
throw new P(
|
|
1544
1544
|
`Graph tx ${a}.previous_output is not "<txid>:<vout>"`
|
|
1545
1545
|
);
|
|
1546
|
-
const c =
|
|
1546
|
+
const c = J(Number(l[2]), `${a}.previous_output vout`, 0, Ee);
|
|
1547
1547
|
o.addInput(
|
|
1548
1548
|
H.from(l[1], "hex").reverse(),
|
|
1549
1549
|
c,
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
), o.ins[n].witness =
|
|
1553
|
-
|
|
1550
|
+
J(k(i, "sequence", a), `${a}.sequence`, 0, Ee),
|
|
1551
|
+
ke(k(i, "script_sig", a), `${a}.script_sig`)
|
|
1552
|
+
), o.ins[n].witness = te(
|
|
1553
|
+
k(i, "witness", a),
|
|
1554
1554
|
`${a}.witness`
|
|
1555
|
-
).map((
|
|
1556
|
-
}),
|
|
1555
|
+
).map((h, d) => ke(h, `${a}.witness[${d}]`));
|
|
1556
|
+
}), te(k(r, "output", t), `${t}.output`).forEach((s, n) => {
|
|
1557
1557
|
const a = `${t}.output[${n}]`, i = B(s, a);
|
|
1558
1558
|
o.addOutput(
|
|
1559
|
-
|
|
1560
|
-
|
|
1559
|
+
ke(k(i, "script_pubkey", a), `${a}.script_pubkey`),
|
|
1560
|
+
J(k(i, "value", a), `${a}.value`, 0, Number.MAX_SAFE_INTEGER)
|
|
1561
1561
|
);
|
|
1562
1562
|
}), new Uint8Array(o.toBuffer());
|
|
1563
1563
|
}
|
|
@@ -1577,7 +1577,7 @@ function D(e, t) {
|
|
|
1577
1577
|
);
|
|
1578
1578
|
return o;
|
|
1579
1579
|
}
|
|
1580
|
-
function
|
|
1580
|
+
function Mt(e, t) {
|
|
1581
1581
|
const r = e.ins[t];
|
|
1582
1582
|
if (r)
|
|
1583
1583
|
return {
|
|
@@ -1586,18 +1586,18 @@ function Lt(e, t) {
|
|
|
1586
1586
|
};
|
|
1587
1587
|
}
|
|
1588
1588
|
function Ft(e, t) {
|
|
1589
|
-
if (!e.outs[
|
|
1589
|
+
if (!e.outs[de])
|
|
1590
1590
|
throw new P(
|
|
1591
|
-
`Presign ${t}.claim_tx must have output ${
|
|
1591
|
+
`Presign ${t}.claim_tx must have output ${de}`
|
|
1592
1592
|
);
|
|
1593
1593
|
}
|
|
1594
|
-
function
|
|
1594
|
+
function ts(e, t, r) {
|
|
1595
1595
|
if (e.ins.length !== 1)
|
|
1596
1596
|
throw new P(
|
|
1597
1597
|
`Presign ${r}.claim_tx must have exactly one input, got ${e.ins.length}`
|
|
1598
1598
|
);
|
|
1599
1599
|
Ft(e, r);
|
|
1600
|
-
const o =
|
|
1600
|
+
const o = Mt(e, 0);
|
|
1601
1601
|
if ((o == null ? void 0 : o.txid) !== t || o.vout !== X) {
|
|
1602
1602
|
const s = o ? `${o.txid}:${o.vout}` : "no input";
|
|
1603
1603
|
throw new P(
|
|
@@ -1606,11 +1606,11 @@ function zo(e, t, r) {
|
|
|
1606
1606
|
}
|
|
1607
1607
|
}
|
|
1608
1608
|
function Oe(e, t, r) {
|
|
1609
|
-
const o =
|
|
1610
|
-
if ((o == null ? void 0 : o.txid) !== t || o.vout !==
|
|
1609
|
+
const o = Mt(e, 0);
|
|
1610
|
+
if ((o == null ? void 0 : o.txid) !== t || o.vout !== de) {
|
|
1611
1611
|
const s = o ? `${o.txid}:${o.vout}` : "no input";
|
|
1612
1612
|
throw new P(
|
|
1613
|
-
`Presign ${r}.assert_tx input 0 must spend ${t}:${
|
|
1613
|
+
`Presign ${r}.assert_tx input 0 must spend ${t}:${de}, got ${s}`
|
|
1614
1614
|
);
|
|
1615
1615
|
}
|
|
1616
1616
|
}
|
|
@@ -1618,15 +1618,15 @@ function Ut(e) {
|
|
|
1618
1618
|
const t = D(e.peginTxHex, `${e.path}.pegin_tx`), r = D(e.claimTxHex, `${e.path}.claim_tx`), o = D(e.assertTxHex, `${e.path}.assert_tx`);
|
|
1619
1619
|
return { peginTx: t, claimTx: r, assertTx: o };
|
|
1620
1620
|
}
|
|
1621
|
-
function
|
|
1621
|
+
function rs(e) {
|
|
1622
1622
|
const t = D(e.claimTxHex, `${e.path}.claim_tx`), r = D(e.assertTxHex, `${e.path}.assert_tx`);
|
|
1623
1623
|
Ft(t, e.path), Oe(r, t.getId(), e.path);
|
|
1624
1624
|
}
|
|
1625
|
-
function
|
|
1625
|
+
function os(e) {
|
|
1626
1626
|
const { peginTx: t, claimTx: r, assertTx: o } = Ut(e);
|
|
1627
|
-
|
|
1627
|
+
ts(r, t.getId(), e.path), Oe(o, r.getId(), e.path);
|
|
1628
1628
|
}
|
|
1629
|
-
function
|
|
1629
|
+
function ss(e, t) {
|
|
1630
1630
|
const [r, ...o] = e.ins;
|
|
1631
1631
|
if (!r || o.length > 0)
|
|
1632
1632
|
throw new P(
|
|
@@ -1637,17 +1637,17 @@ function Yo(e, t) {
|
|
|
1637
1637
|
throw new P(
|
|
1638
1638
|
`Presign claim_tx must spend ${t}:${X}, got ${s}:${r.index}`
|
|
1639
1639
|
);
|
|
1640
|
-
if (e.version !==
|
|
1640
|
+
if (e.version !== tt)
|
|
1641
1641
|
throw new P(
|
|
1642
|
-
`Presign claim_tx version must be ${
|
|
1642
|
+
`Presign claim_tx version must be ${tt}, got ${e.version}`
|
|
1643
1643
|
);
|
|
1644
1644
|
if (r.witness.length > 0)
|
|
1645
1645
|
throw new P(
|
|
1646
1646
|
`Presign claim_tx input must have an empty witness, got ${r.witness.length} item(s)`
|
|
1647
1647
|
);
|
|
1648
|
-
if (e.outs.length !==
|
|
1648
|
+
if (e.outs.length !== rt)
|
|
1649
1649
|
throw new P(
|
|
1650
|
-
`Presign claim_tx must have exactly ${
|
|
1650
|
+
`Presign claim_tx must have exactly ${rt} outputs, got ${e.outs.length}`
|
|
1651
1651
|
);
|
|
1652
1652
|
}
|
|
1653
1653
|
function qt(e) {
|
|
@@ -1655,15 +1655,15 @@ function qt(e) {
|
|
|
1655
1655
|
(o, s) => o.pubkey < s.pubkey ? -1 : o.pubkey > s.pubkey ? 1 : 0
|
|
1656
1656
|
), r = [e.peginTx, e.claimTx, e.assertTx, e.payoutTx];
|
|
1657
1657
|
return t.forEach((o, s) => {
|
|
1658
|
-
const n =
|
|
1658
|
+
const n = he(o.pubkey, "challenger pubkey");
|
|
1659
1659
|
if (s > 0 && t[s - 1].pubkey === n)
|
|
1660
1660
|
throw new P(`Graph lists challenger ${n} twice`);
|
|
1661
|
-
r.push(
|
|
1661
|
+
r.push(We(n), o.nopayoutTx);
|
|
1662
1662
|
for (const a of o.outputLabelHashes)
|
|
1663
|
-
r.push(
|
|
1664
|
-
}),
|
|
1663
|
+
r.push(We(he(a, "output_label_hashes entry")));
|
|
1664
|
+
}), Mr(Fr(Ur(...r)));
|
|
1665
1665
|
}
|
|
1666
|
-
function
|
|
1666
|
+
function ns(e) {
|
|
1667
1667
|
const t = b(e.peginTxid).toLowerCase(), { peginTx: r, claimTx: o, assertTx: s } = Ut({
|
|
1668
1668
|
peginTxHex: e.peginTxHex,
|
|
1669
1669
|
claimTxHex: e.claimTxHex,
|
|
@@ -1674,7 +1674,7 @@ function Jo(e) {
|
|
|
1674
1674
|
throw new P(
|
|
1675
1675
|
`Presign pegin_tx hashes to ${r.getId()}, expected ${t}`
|
|
1676
1676
|
);
|
|
1677
|
-
|
|
1677
|
+
ss(o, t), Oe(s, o.getId(), "depositor_graph");
|
|
1678
1678
|
const n = (a) => new Uint8Array(a.toBuffer());
|
|
1679
1679
|
return qt({
|
|
1680
1680
|
peginTx: n(r),
|
|
@@ -1690,9 +1690,9 @@ function Jo(e) {
|
|
|
1690
1690
|
}))
|
|
1691
1691
|
});
|
|
1692
1692
|
}
|
|
1693
|
-
function
|
|
1694
|
-
const t = (o) =>
|
|
1695
|
-
|
|
1693
|
+
function is(e) {
|
|
1694
|
+
const t = (o) => ot(B(k(e, o, "graph"), o).tx, o), r = B(
|
|
1695
|
+
k(e, "challenger_subgraphs", "graph"),
|
|
1696
1696
|
"challenger_subgraphs"
|
|
1697
1697
|
);
|
|
1698
1698
|
return qt({
|
|
@@ -1704,31 +1704,31 @@ function Qo(e) {
|
|
|
1704
1704
|
const n = `challenger_subgraphs[${o}]`, a = B(s, n);
|
|
1705
1705
|
return {
|
|
1706
1706
|
pubkey: o,
|
|
1707
|
-
nopayoutTx:
|
|
1708
|
-
B(
|
|
1707
|
+
nopayoutTx: ot(
|
|
1708
|
+
B(k(a, "nopayout_tx", n), `${n}.nopayout_tx`).tx,
|
|
1709
1709
|
`${n}.nopayout_tx`
|
|
1710
1710
|
),
|
|
1711
|
-
outputLabelHashes:
|
|
1712
|
-
|
|
1711
|
+
outputLabelHashes: te(
|
|
1712
|
+
k(a, "output_label_hashes", n),
|
|
1713
1713
|
`${n}.output_label_hashes`
|
|
1714
1714
|
).map(
|
|
1715
|
-
(i, u) =>
|
|
1715
|
+
(i, u) => he(i, `${n}.output_label_hashes[${u}]`)
|
|
1716
1716
|
)
|
|
1717
1717
|
};
|
|
1718
1718
|
})
|
|
1719
1719
|
});
|
|
1720
1720
|
}
|
|
1721
|
-
function
|
|
1721
|
+
function as(e) {
|
|
1722
1722
|
const t = B(
|
|
1723
|
-
|
|
1723
|
+
k(e, "challenger_pubkeys", "graph"),
|
|
1724
1724
|
"challenger_pubkeys"
|
|
1725
1725
|
), r = /* @__PURE__ */ new Set();
|
|
1726
1726
|
for (const o of ["local", "universal"])
|
|
1727
|
-
|
|
1728
|
-
|
|
1727
|
+
te(
|
|
1728
|
+
k(t, o, "challenger_pubkeys"),
|
|
1729
1729
|
`challenger_pubkeys.${o}`
|
|
1730
1730
|
).forEach((s, n) => {
|
|
1731
|
-
const a =
|
|
1731
|
+
const a = he(s, `challenger_pubkeys.${o}[${n}]`);
|
|
1732
1732
|
if (r.has(a))
|
|
1733
1733
|
throw new P(
|
|
1734
1734
|
`Graph declares challenger ${a} more than once`
|
|
@@ -1737,71 +1737,152 @@ function Zo(e) {
|
|
|
1737
1737
|
});
|
|
1738
1738
|
return r;
|
|
1739
1739
|
}
|
|
1740
|
-
function
|
|
1741
|
-
const r =
|
|
1740
|
+
function fn(e, t) {
|
|
1741
|
+
const r = is(e);
|
|
1742
1742
|
if (r !== t)
|
|
1743
1743
|
throw new P(
|
|
1744
1744
|
`Graph fingerprint ${r} does not match the presign fingerprint ${t}`
|
|
1745
1745
|
);
|
|
1746
1746
|
const o = Object.keys(
|
|
1747
1747
|
B(e.challenger_subgraphs, "challenger_subgraphs")
|
|
1748
|
-
), s =
|
|
1748
|
+
), s = as(e);
|
|
1749
1749
|
if (o.length !== s.size || o.some((n) => !s.has(n)))
|
|
1750
1750
|
throw new P(
|
|
1751
1751
|
`Graph challenger_subgraphs keys ${o.join(", ")} do not match challenger_pubkeys ${[...s].join(", ")}`
|
|
1752
1752
|
);
|
|
1753
1753
|
}
|
|
1754
|
-
const
|
|
1755
|
-
function
|
|
1754
|
+
const us = 1;
|
|
1755
|
+
function cs(e, t, r) {
|
|
1756
1756
|
const o = r.map(
|
|
1757
|
-
(
|
|
1758
|
-
), s = t.filter((
|
|
1757
|
+
(h) => b(h).toLowerCase()
|
|
1758
|
+
), s = t.filter((h) => o.includes(h));
|
|
1759
1759
|
if (s.length > 0)
|
|
1760
1760
|
throw new Error(
|
|
1761
1761
|
`Cannot validate challenger set: vault keepers and universal challengers overlap (${s.join(", ")})`
|
|
1762
1762
|
);
|
|
1763
1763
|
const n = [...t, ...o], a = e.map(
|
|
1764
|
-
(
|
|
1764
|
+
(h) => b(h.challenger_pubkey).toLowerCase()
|
|
1765
1765
|
), i = new Set(a);
|
|
1766
1766
|
if (i.size !== a.length)
|
|
1767
1767
|
throw new Error(
|
|
1768
1768
|
"Depositor graph contains duplicate challenger entries in challenger_presign_data"
|
|
1769
1769
|
);
|
|
1770
|
-
const u = new Set(n), l = n.filter((
|
|
1770
|
+
const u = new Set(n), l = n.filter((h) => !i.has(h)), c = a.filter((h) => !u.has(h));
|
|
1771
1771
|
if (l.length > 0 || c.length > 0)
|
|
1772
1772
|
throw new Error(
|
|
1773
1773
|
"Depositor graph challenger set does not match expected (local ∪ universal)" + (l.length > 0 ? ` (missing: ${l.join(", ")})` : "") + (c.length > 0 ? ` (unexpected: ${c.join(", ")})` : "")
|
|
1774
1774
|
);
|
|
1775
|
+
return or(n);
|
|
1775
1776
|
}
|
|
1776
|
-
function
|
|
1777
|
-
const r =
|
|
1778
|
-
|
|
1779
|
-
}
|
|
1780
|
-
function $e(e, t, r, o, s) {
|
|
1781
|
-
const n = e.ins[t];
|
|
1782
|
-
if (n.index !== 0)
|
|
1777
|
+
function ls(e, t, r) {
|
|
1778
|
+
const o = r >= Ar ? 1 : 0, s = _r + Sr * t + o;
|
|
1779
|
+
if (e.outs.length !== s)
|
|
1783
1780
|
throw new Error(
|
|
1784
|
-
`
|
|
1785
|
-
);
|
|
1786
|
-
const a = r.getId(), i = rs(e, t);
|
|
1787
|
-
if (i !== a)
|
|
1788
|
-
throw new Error(
|
|
1789
|
-
`NoPayout (challenger ${s}) input ${t} does not reference ${o} (expected txid ${a}, got ${i})`
|
|
1781
|
+
`Assert must have ${s} outputs for ${t} challengers (vault core version ${r}), got ${e.outs.length}`
|
|
1790
1782
|
);
|
|
1791
1783
|
}
|
|
1792
|
-
async function
|
|
1793
|
-
const
|
|
1794
|
-
claimerBtcPubkey:
|
|
1795
|
-
depositorBtcPubkey:
|
|
1796
|
-
vaultProviderBtcPubkey:
|
|
1797
|
-
vaultKeeperBtcPubkeys:
|
|
1798
|
-
})
|
|
1799
|
-
ts(
|
|
1784
|
+
async function Gt(e, t) {
|
|
1785
|
+
const r = wt({
|
|
1786
|
+
claimerBtcPubkey: t.depositorBtcPubkey,
|
|
1787
|
+
depositorBtcPubkey: t.depositorBtcPubkey,
|
|
1788
|
+
vaultProviderBtcPubkey: t.vaultProviderBtcPubkey,
|
|
1789
|
+
vaultKeeperBtcPubkeys: t.vaultKeeperBtcPubkeys
|
|
1790
|
+
}), o = cs(
|
|
1800
1791
|
e.challenger_presign_data,
|
|
1801
|
-
|
|
1802
|
-
|
|
1792
|
+
r,
|
|
1793
|
+
t.universalChallengerBtcPubkeys
|
|
1794
|
+
), s = b(t.depositorBtcPubkey), n = S.fromHex(
|
|
1795
|
+
b(e.assert_tx.tx_hex)
|
|
1796
|
+
);
|
|
1797
|
+
ls(
|
|
1798
|
+
n,
|
|
1799
|
+
o.length,
|
|
1800
|
+
t.vaultCoreVersion
|
|
1801
|
+
);
|
|
1802
|
+
const a = [];
|
|
1803
|
+
for (const i of e.challenger_presign_data) {
|
|
1804
|
+
const u = b(i.challenger_pubkey), l = o.indexOf(
|
|
1805
|
+
u.toLowerCase()
|
|
1806
|
+
), c = await ds({
|
|
1807
|
+
challenger: i,
|
|
1808
|
+
challengerPubkey: u,
|
|
1809
|
+
challengerIndex: l,
|
|
1810
|
+
challengerCount: o.length,
|
|
1811
|
+
claimerPubkey: s,
|
|
1812
|
+
assertTx: n,
|
|
1813
|
+
ctx: t
|
|
1814
|
+
});
|
|
1815
|
+
a.push({ challenger: i, challengerPubkey: u, prevouts: c });
|
|
1816
|
+
}
|
|
1817
|
+
return { localChallengers: r, noPayouts: a };
|
|
1818
|
+
}
|
|
1819
|
+
async function ds(e) {
|
|
1820
|
+
const {
|
|
1821
|
+
challenger: t,
|
|
1822
|
+
challengerPubkey: r,
|
|
1823
|
+
challengerIndex: o,
|
|
1824
|
+
challengerCount: s,
|
|
1825
|
+
claimerPubkey: n,
|
|
1826
|
+
assertTx: a,
|
|
1827
|
+
ctx: i
|
|
1828
|
+
} = e;
|
|
1829
|
+
Gr(
|
|
1830
|
+
t.nopayout_tx.tx_hex,
|
|
1831
|
+
r,
|
|
1832
|
+
i.network
|
|
1803
1833
|
);
|
|
1804
|
-
const
|
|
1834
|
+
const u = S.fromHex(
|
|
1835
|
+
b(t.nopayout_tx.tx_hex)
|
|
1836
|
+
), l = S.fromHex(
|
|
1837
|
+
b(t.challenge_assert_x_tx.tx_hex)
|
|
1838
|
+
), c = S.fromHex(
|
|
1839
|
+
b(t.challenge_assert_y_tx.tx_hex)
|
|
1840
|
+
), h = await br({
|
|
1841
|
+
txGraphVersion: i.vaultCoreVersion,
|
|
1842
|
+
claimer: n,
|
|
1843
|
+
challenger: r,
|
|
1844
|
+
timelockChallengeAssert: i.timelockChallengeAssert,
|
|
1845
|
+
outputLabelHashes: t.output_label_hashes.map(
|
|
1846
|
+
(g) => g.toLowerCase()
|
|
1847
|
+
),
|
|
1848
|
+
network: i.network
|
|
1849
|
+
});
|
|
1850
|
+
for (const [g, p] of [
|
|
1851
|
+
["X", l],
|
|
1852
|
+
["Y", c]
|
|
1853
|
+
])
|
|
1854
|
+
Xr({
|
|
1855
|
+
challengeAssertTx: p,
|
|
1856
|
+
assertTx: a,
|
|
1857
|
+
half: g,
|
|
1858
|
+
challengerIndex: o,
|
|
1859
|
+
challengerCount: s,
|
|
1860
|
+
challengerPubkey: r,
|
|
1861
|
+
outputConnectorScriptPubKey: h
|
|
1862
|
+
});
|
|
1863
|
+
const d = [
|
|
1864
|
+
a.outs[G],
|
|
1865
|
+
l.outs[Xe],
|
|
1866
|
+
c.outs[Xe]
|
|
1867
|
+
];
|
|
1868
|
+
return zr({
|
|
1869
|
+
noPayoutTx: u,
|
|
1870
|
+
assertTxid: a.getId(),
|
|
1871
|
+
challengeAssertXTxid: l.getId(),
|
|
1872
|
+
challengeAssertYTxid: c.getId(),
|
|
1873
|
+
timelockChallengeAssert: i.timelockChallengeAssert,
|
|
1874
|
+
prevoutValues: [
|
|
1875
|
+
d[0].value,
|
|
1876
|
+
d[1].value,
|
|
1877
|
+
d[2].value
|
|
1878
|
+
]
|
|
1879
|
+
}), d.map((g) => ({
|
|
1880
|
+
script_pubkey: yt(new Uint8Array(g.script)),
|
|
1881
|
+
value: g.value
|
|
1882
|
+
}));
|
|
1883
|
+
}
|
|
1884
|
+
async function hs(e, t, r) {
|
|
1885
|
+
const o = [], s = [], n = [], { localChallengers: a, noPayouts: i } = await Gt(e, r), u = await Vr({
|
|
1805
1886
|
vaultCoreVersion: r.vaultCoreVersion,
|
|
1806
1887
|
vkClaimerPayoutScriptPubKeys: r.vkClaimerPayoutScriptPubKeys,
|
|
1807
1888
|
vpCommissionScriptPubKey: r.vpCommissionScriptPubKey,
|
|
@@ -1817,115 +1898,52 @@ async function os(e, t, r) {
|
|
|
1817
1898
|
network: r.network,
|
|
1818
1899
|
claimerBtcPubkey: r.depositorBtcPubkey,
|
|
1819
1900
|
registeredPayoutScriptPubKey: r.registeredPayoutScriptPubKey,
|
|
1820
|
-
commissionBps:
|
|
1901
|
+
commissionBps: us,
|
|
1821
1902
|
protocolFeeRate: r.protocolFeeRate,
|
|
1822
1903
|
councilMembers: r.councilMembers,
|
|
1823
1904
|
councilQuorum: r.councilQuorum
|
|
1824
1905
|
});
|
|
1825
|
-
o.push(
|
|
1826
|
-
|
|
1906
|
+
o.push(u.psbtHex), s.push(
|
|
1907
|
+
ce(
|
|
1827
1908
|
t,
|
|
1828
|
-
|
|
1909
|
+
Ge
|
|
1829
1910
|
)
|
|
1830
1911
|
);
|
|
1831
|
-
const
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1912
|
+
const l = b(r.depositorBtcPubkey);
|
|
1913
|
+
for (const { challenger: c, challengerPubkey: h, prevouts: d } of i) {
|
|
1914
|
+
const g = o.length, p = await qr({
|
|
1915
|
+
noPayoutTxHex: c.nopayout_tx.tx_hex,
|
|
1916
|
+
challengerPubkey: h,
|
|
1917
|
+
prevouts: d,
|
|
1918
|
+
connectorParams: {
|
|
1919
|
+
txGraphVersion: r.vaultCoreVersion,
|
|
1920
|
+
claimer: l,
|
|
1921
|
+
localChallengers: a,
|
|
1922
|
+
universalChallengers: r.universalChallengerBtcPubkeys,
|
|
1923
|
+
timelockAssert: r.timelockAssert,
|
|
1924
|
+
councilMembers: r.councilMembers,
|
|
1925
|
+
councilQuorum: r.councilQuorum
|
|
1926
|
+
}
|
|
1842
1927
|
});
|
|
1843
|
-
o.push(
|
|
1844
|
-
|
|
1928
|
+
o.push(p), s.push(
|
|
1929
|
+
ce(
|
|
1845
1930
|
t,
|
|
1846
|
-
|
|
1931
|
+
Ge
|
|
1847
1932
|
)
|
|
1848
1933
|
), n.push({
|
|
1849
|
-
challengerPubkey:
|
|
1850
|
-
noPayoutIdx:
|
|
1934
|
+
challengerPubkey: h,
|
|
1935
|
+
noPayoutIdx: g
|
|
1851
1936
|
});
|
|
1852
1937
|
}
|
|
1853
1938
|
return { psbtHexes: o, signOptions: s, challengerEntries: n };
|
|
1854
1939
|
}
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
challengerPubkey: r,
|
|
1859
|
-
claimerPubkey: o,
|
|
1860
|
-
localChallengers: s,
|
|
1861
|
-
assertTxParsed: n,
|
|
1862
|
-
ctx: a
|
|
1863
|
-
} = e;
|
|
1864
|
-
Or(
|
|
1865
|
-
t.nopayout_tx.tx_hex,
|
|
1866
|
-
r,
|
|
1867
|
-
a.network
|
|
1868
|
-
);
|
|
1869
|
-
const i = S.fromHex(
|
|
1870
|
-
b(t.nopayout_tx.tx_hex)
|
|
1871
|
-
), u = S.fromHex(
|
|
1872
|
-
b(t.challenge_assert_x_tx.tx_hex)
|
|
1873
|
-
), l = S.fromHex(
|
|
1874
|
-
b(t.challenge_assert_y_tx.tx_hex)
|
|
1875
|
-
);
|
|
1876
|
-
if (i.ins.length !== 3)
|
|
1877
|
-
throw new Error(
|
|
1878
|
-
`NoPayout (challenger ${r}) must have exactly 3 inputs, got ${i.ins.length}`
|
|
1879
|
-
);
|
|
1880
|
-
$e(
|
|
1881
|
-
i,
|
|
1882
|
-
0,
|
|
1883
|
-
n,
|
|
1884
|
-
"Assert",
|
|
1885
|
-
r
|
|
1886
|
-
), $e(
|
|
1887
|
-
i,
|
|
1888
|
-
1,
|
|
1889
|
-
u,
|
|
1890
|
-
"ChallengeAssertX",
|
|
1891
|
-
r
|
|
1892
|
-
), $e(
|
|
1893
|
-
i,
|
|
1894
|
-
2,
|
|
1895
|
-
l,
|
|
1896
|
-
"ChallengeAssertY",
|
|
1897
|
-
r
|
|
1898
|
-
);
|
|
1899
|
-
const c = [
|
|
1900
|
-
n.outs[0],
|
|
1901
|
-
u.outs[0],
|
|
1902
|
-
l.outs[0]
|
|
1903
|
-
].map((d) => ({
|
|
1904
|
-
script_pubkey: Ve(new Uint8Array(d.script)),
|
|
1905
|
-
value: d.value
|
|
1906
|
-
}));
|
|
1907
|
-
return Dr({
|
|
1908
|
-
noPayoutTxHex: t.nopayout_tx.tx_hex,
|
|
1909
|
-
challengerPubkey: r,
|
|
1910
|
-
prevouts: c,
|
|
1911
|
-
connectorParams: {
|
|
1912
|
-
txGraphVersion: a.vaultCoreVersion,
|
|
1913
|
-
claimer: o,
|
|
1914
|
-
localChallengers: s,
|
|
1915
|
-
universalChallengers: a.universalChallengerBtcPubkeys,
|
|
1916
|
-
timelockAssert: a.timelockAssert,
|
|
1917
|
-
councilMembers: a.councilMembers,
|
|
1918
|
-
councilQuorum: a.councilQuorum
|
|
1919
|
-
}
|
|
1920
|
-
});
|
|
1921
|
-
}
|
|
1922
|
-
function ns(e, t, r) {
|
|
1923
|
-
ie(e[0]);
|
|
1924
|
-
const s = ae(
|
|
1940
|
+
function ps(e, t, r) {
|
|
1941
|
+
ae(e[0]);
|
|
1942
|
+
const s = ue(
|
|
1925
1943
|
e[0].returnedPsbtHex,
|
|
1926
1944
|
r
|
|
1927
1945
|
);
|
|
1928
|
-
|
|
1946
|
+
oe({
|
|
1929
1947
|
requestedPsbtHex: e[0].requestedPsbtHex,
|
|
1930
1948
|
signatureHex: s,
|
|
1931
1949
|
signerXOnlyPubkeyHex: r,
|
|
@@ -1933,12 +1951,12 @@ function ns(e, t, r) {
|
|
|
1933
1951
|
});
|
|
1934
1952
|
const n = {};
|
|
1935
1953
|
for (const a of t) {
|
|
1936
|
-
|
|
1937
|
-
const i =
|
|
1954
|
+
ae(e[a.noPayoutIdx]);
|
|
1955
|
+
const i = ue(
|
|
1938
1956
|
e[a.noPayoutIdx].returnedPsbtHex,
|
|
1939
1957
|
r
|
|
1940
1958
|
);
|
|
1941
|
-
|
|
1959
|
+
oe({
|
|
1942
1960
|
requestedPsbtHex: e[a.noPayoutIdx].requestedPsbtHex,
|
|
1943
1961
|
signatureHex: i,
|
|
1944
1962
|
signerXOnlyPubkeyHex: r,
|
|
@@ -1954,18 +1972,18 @@ function ns(e, t, r) {
|
|
|
1954
1972
|
per_challenger: n
|
|
1955
1973
|
};
|
|
1956
1974
|
}
|
|
1957
|
-
async function
|
|
1975
|
+
async function gs(e) {
|
|
1958
1976
|
const { depositorGraph: t, btcWallet: r, signingContext: o } = e;
|
|
1959
|
-
|
|
1977
|
+
os({
|
|
1960
1978
|
peginTxHex: o.peginTxHex,
|
|
1961
1979
|
claimTxHex: t.claim_tx.tx_hex,
|
|
1962
1980
|
assertTxHex: t.assert_tx.tx_hex,
|
|
1963
1981
|
path: "depositor_graph"
|
|
1964
1982
|
});
|
|
1965
|
-
const s = await r.getPublicKeyHex(), { depositorPubkey: n } =
|
|
1983
|
+
const s = await r.getPublicKeyHex(), { depositorPubkey: n } = rr(
|
|
1966
1984
|
s,
|
|
1967
1985
|
b(o.depositorBtcPubkey)
|
|
1968
|
-
), { psbtHexes: a, signOptions: i, challengerEntries: u } = await
|
|
1986
|
+
), { psbtHexes: a, signOptions: i, challengerEntries: u } = await hs(
|
|
1969
1987
|
t,
|
|
1970
1988
|
s,
|
|
1971
1989
|
o
|
|
@@ -1973,17 +1991,17 @@ async function is(e) {
|
|
|
1973
1991
|
r,
|
|
1974
1992
|
a,
|
|
1975
1993
|
i
|
|
1976
|
-
), c = a.map((
|
|
1977
|
-
requestedPsbtHex:
|
|
1978
|
-
returnedPsbtHex: l[
|
|
1994
|
+
), c = a.map((h, d) => ({
|
|
1995
|
+
requestedPsbtHex: h,
|
|
1996
|
+
returnedPsbtHex: l[d]
|
|
1979
1997
|
}));
|
|
1980
|
-
return
|
|
1998
|
+
return ps(
|
|
1981
1999
|
c,
|
|
1982
2000
|
u,
|
|
1983
2001
|
n
|
|
1984
2002
|
);
|
|
1985
2003
|
}
|
|
1986
|
-
const
|
|
2004
|
+
const fs = 1e4, M = 10;
|
|
1987
2005
|
async function Xt(e) {
|
|
1988
2006
|
const {
|
|
1989
2007
|
statusReader: t,
|
|
@@ -1991,26 +2009,26 @@ async function Xt(e) {
|
|
|
1991
2009
|
peginTxid: o,
|
|
1992
2010
|
targetStatuses: s,
|
|
1993
2011
|
timeoutMs: n,
|
|
1994
|
-
pollIntervalMs: a =
|
|
2012
|
+
pollIntervalMs: a = fs,
|
|
1995
2013
|
signal: i
|
|
1996
2014
|
} = e, u = Date.now();
|
|
1997
2015
|
for (; ; ) {
|
|
1998
2016
|
if (i != null && i.aborted)
|
|
1999
2017
|
throw new Error(
|
|
2000
|
-
`Polling aborted for vault ${r.slice(0,
|
|
2018
|
+
`Polling aborted for vault ${r.slice(0, M)}… (target: ${[...s].join(", ")})`
|
|
2001
2019
|
);
|
|
2002
2020
|
if (Date.now() - u >= n)
|
|
2003
2021
|
throw new Error(
|
|
2004
|
-
`Polling timeout after ${n}ms for vault ${r.slice(0,
|
|
2022
|
+
`Polling timeout after ${n}ms for vault ${r.slice(0, M)}… (target: ${[...s].join(", ")})`
|
|
2005
2023
|
);
|
|
2006
2024
|
try {
|
|
2007
2025
|
const l = await t.getPeginStatusByVaultId(
|
|
2008
2026
|
{ vault_id: r },
|
|
2009
2027
|
i
|
|
2010
2028
|
);
|
|
2011
|
-
if (
|
|
2029
|
+
if (je(l.vault_id) !== je(r))
|
|
2012
2030
|
throw new Error(
|
|
2013
|
-
`getPeginStatusByVaultId returned status for vault ${l.vault_id.slice(0,
|
|
2031
|
+
`getPeginStatusByVaultId returned status for vault ${l.vault_id.slice(0, M)}…, requested ${r.slice(0, M)}…`
|
|
2014
2032
|
);
|
|
2015
2033
|
if (l.pegin_txid.toLowerCase() !== o.toLowerCase())
|
|
2016
2034
|
throw new Error(
|
|
@@ -2019,48 +2037,48 @@ async function Xt(e) {
|
|
|
2019
2037
|
const c = l.status;
|
|
2020
2038
|
if (s.has(c) || c === R.ACTIVATED)
|
|
2021
2039
|
return c;
|
|
2022
|
-
if (c === R.EXPIRED ||
|
|
2040
|
+
if (c === R.EXPIRED || Nr.has(c))
|
|
2023
2041
|
throw new Error(
|
|
2024
|
-
`Vault ${r.slice(0,
|
|
2042
|
+
`Vault ${r.slice(0, M)}… reached terminal status "${c}" while waiting for ${[...s].join(", ")}`
|
|
2025
2043
|
);
|
|
2026
2044
|
} catch (l) {
|
|
2027
|
-
if (!(l instanceof
|
|
2045
|
+
if (!(l instanceof Dr && l.code === Lr.PEGIN_NOT_FOUND))
|
|
2028
2046
|
throw l;
|
|
2029
2047
|
}
|
|
2030
2048
|
await new Promise((l, c) => {
|
|
2031
|
-
const
|
|
2032
|
-
clearTimeout(
|
|
2049
|
+
const h = () => {
|
|
2050
|
+
clearTimeout(d), c(
|
|
2033
2051
|
new Error(
|
|
2034
|
-
`Polling aborted for vault ${r.slice(0,
|
|
2052
|
+
`Polling aborted for vault ${r.slice(0, M)}… (target: ${[...s].join(", ")})`
|
|
2035
2053
|
)
|
|
2036
2054
|
);
|
|
2037
|
-
},
|
|
2038
|
-
i == null || i.removeEventListener("abort",
|
|
2055
|
+
}, d = setTimeout(() => {
|
|
2056
|
+
i == null || i.removeEventListener("abort", h), l();
|
|
2039
2057
|
}, a);
|
|
2040
|
-
i == null || i.addEventListener("abort",
|
|
2058
|
+
i == null || i.addEventListener("abort", h, { once: !0 });
|
|
2041
2059
|
});
|
|
2042
2060
|
}
|
|
2043
2061
|
}
|
|
2044
|
-
const
|
|
2062
|
+
const ys = 1200 * 1e3, zt = /* @__PURE__ */ new Set([
|
|
2045
2063
|
R.PENDING_ACKS,
|
|
2046
2064
|
R.PENDING_ACTIVATION,
|
|
2047
2065
|
R.ACTIVATED_PENDING_BROADCAST,
|
|
2048
2066
|
R.ACTIVATED
|
|
2049
|
-
]),
|
|
2067
|
+
]), vs = /* @__PURE__ */ new Set([
|
|
2050
2068
|
R.PENDING_DEPOSITOR_SIGNATURES,
|
|
2051
|
-
...
|
|
2069
|
+
...zt
|
|
2052
2070
|
]);
|
|
2053
|
-
function
|
|
2071
|
+
function bs(e) {
|
|
2054
2072
|
return e.map((t) => ({
|
|
2055
|
-
claimerPubkeyXOnly:
|
|
2073
|
+
claimerPubkeyXOnly: pe(t.claimer_pubkey),
|
|
2056
2074
|
payoutTxHex: t.payout_tx.tx_hex,
|
|
2057
2075
|
assertTxHex: t.assert_tx.tx_hex
|
|
2058
2076
|
}));
|
|
2059
2077
|
}
|
|
2060
2078
|
function I(e) {
|
|
2061
|
-
return
|
|
2079
|
+
return pe(e).toLowerCase();
|
|
2062
2080
|
}
|
|
2063
|
-
function
|
|
2081
|
+
function ms(e, t) {
|
|
2064
2082
|
const r = (u, l, c) => {
|
|
2065
2083
|
throw new Error(
|
|
2066
2084
|
`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.`
|
|
@@ -2074,8 +2092,8 @@ function ds(e, t) {
|
|
|
2074
2092
|
for (const [u, l, c] of o)
|
|
2075
2093
|
l !== c && r(u, l, c);
|
|
2076
2094
|
const s = (u) => u.map(I).sort(), n = (u, l) => {
|
|
2077
|
-
const c = s(u),
|
|
2078
|
-
return c.length ===
|
|
2095
|
+
const c = s(u), h = s(l);
|
|
2096
|
+
return c.length === h.length && c.every((d, g) => d === h[g]);
|
|
2079
2097
|
};
|
|
2080
2098
|
n(e.vaultKeeperBtcPubkeys, t.vaultKeeperBtcPubkeys) || r(
|
|
2081
2099
|
"vaultKeeperBtcPubkeys",
|
|
@@ -2098,7 +2116,7 @@ function ds(e, t) {
|
|
|
2098
2116
|
t.vaultProviderBtcPubkey
|
|
2099
2117
|
);
|
|
2100
2118
|
}
|
|
2101
|
-
function
|
|
2119
|
+
function Ps(e, t, r, o) {
|
|
2102
2120
|
const s = I(o), n = [
|
|
2103
2121
|
I(t),
|
|
2104
2122
|
...r.map(I)
|
|
@@ -2112,17 +2130,17 @@ function hs(e, t, r, o) {
|
|
|
2112
2130
|
"Cannot validate claimer set: depositor key overlaps with vault provider or vault keeper set"
|
|
2113
2131
|
);
|
|
2114
2132
|
const i = e.map(
|
|
2115
|
-
(
|
|
2133
|
+
(d) => I(d.claimer_pubkey)
|
|
2116
2134
|
);
|
|
2117
2135
|
if (new Set(i).size !== i.length)
|
|
2118
2136
|
throw new Error("Presign response contains duplicate claimer entries");
|
|
2119
|
-
const u = i.filter((
|
|
2120
|
-
if (c.length > 0 ||
|
|
2137
|
+
const u = i.filter((d) => d !== s), l = new Set(u), c = n.filter((d) => !l.has(d)), h = u.filter((d) => !a.has(d));
|
|
2138
|
+
if (c.length > 0 || h.length > 0)
|
|
2121
2139
|
throw new Error(
|
|
2122
|
-
"Presign response claimer set does not match expected (vault provider ∪ vault keepers)" + (c.length > 0 ? ` (missing: ${c.join(", ")})` : "") + (
|
|
2140
|
+
"Presign response claimer set does not match expected (vault provider ∪ vault keepers)" + (c.length > 0 ? ` (missing: ${c.join(", ")})` : "") + (h.length > 0 ? ` (unexpected: ${h.join(", ")})` : "")
|
|
2123
2141
|
);
|
|
2124
2142
|
}
|
|
2125
|
-
function
|
|
2143
|
+
function st(e, t) {
|
|
2126
2144
|
return {
|
|
2127
2145
|
vaultCoreVersion: t.vaultCoreVersion,
|
|
2128
2146
|
payoutTxHex: e.payoutTxHex,
|
|
@@ -2144,8 +2162,8 @@ function nt(e, t) {
|
|
|
2144
2162
|
vpCommissionScriptPubKey: t.vpCommissionScriptPubKey
|
|
2145
2163
|
};
|
|
2146
2164
|
}
|
|
2147
|
-
async function
|
|
2148
|
-
const s = new
|
|
2165
|
+
async function ws(e, t, r, o) {
|
|
2166
|
+
const s = new nr({
|
|
2149
2167
|
network: t.network,
|
|
2150
2168
|
btcWallet: e
|
|
2151
2169
|
}), n = r.length;
|
|
@@ -2153,14 +2171,14 @@ async function ps(e, t, r, o) {
|
|
|
2153
2171
|
let a;
|
|
2154
2172
|
if (s.supportsBatchSigning())
|
|
2155
2173
|
a = (await s.signPayoutTransactionsBatch(
|
|
2156
|
-
r.map((l) =>
|
|
2174
|
+
r.map((l) => st(l, t))
|
|
2157
2175
|
)).map((l) => l.payoutSignature);
|
|
2158
2176
|
else {
|
|
2159
2177
|
a = [];
|
|
2160
2178
|
for (let u = 0; u < r.length; u++) {
|
|
2161
2179
|
o == null || o(u, n);
|
|
2162
2180
|
const l = await s.signPayoutTransaction(
|
|
2163
|
-
|
|
2181
|
+
st(r[u], t)
|
|
2164
2182
|
);
|
|
2165
2183
|
a.push(l.signature);
|
|
2166
2184
|
}
|
|
@@ -2172,7 +2190,7 @@ async function ps(e, t, r, o) {
|
|
|
2172
2190
|
};
|
|
2173
2191
|
return o == null || o(n, n), i;
|
|
2174
2192
|
}
|
|
2175
|
-
async function
|
|
2193
|
+
async function yn(e) {
|
|
2176
2194
|
const {
|
|
2177
2195
|
statusReader: t,
|
|
2178
2196
|
presignClient: r,
|
|
@@ -2182,21 +2200,21 @@ async function un(e) {
|
|
|
2182
2200
|
depositorPk: a,
|
|
2183
2201
|
signingContext: i,
|
|
2184
2202
|
depositTerms: u,
|
|
2185
|
-
timeoutMs: l =
|
|
2203
|
+
timeoutMs: l = ys,
|
|
2186
2204
|
signal: c,
|
|
2187
|
-
onProgress:
|
|
2188
|
-
recordGraphFingerprint:
|
|
2205
|
+
onProgress: h,
|
|
2206
|
+
recordGraphFingerprint: d
|
|
2189
2207
|
} = e, g = await Xt({
|
|
2190
2208
|
statusReader: t,
|
|
2191
2209
|
vaultId: s,
|
|
2192
2210
|
peginTxid: n,
|
|
2193
|
-
targetStatuses:
|
|
2211
|
+
targetStatuses: vs,
|
|
2194
2212
|
timeoutMs: l,
|
|
2195
2213
|
signal: c
|
|
2196
2214
|
});
|
|
2197
|
-
if (
|
|
2215
|
+
if (zt.has(g))
|
|
2198
2216
|
return;
|
|
2199
|
-
c == null || c.throwIfAborted(), u !== void 0 &&
|
|
2217
|
+
c == null || c.throwIfAborted(), u !== void 0 && ms(u, i);
|
|
2200
2218
|
const p = vt(o) ? o : void 0;
|
|
2201
2219
|
let y;
|
|
2202
2220
|
if (p) {
|
|
@@ -2213,76 +2231,82 @@ async function un(e) {
|
|
|
2213
2231
|
},
|
|
2214
2232
|
c
|
|
2215
2233
|
);
|
|
2216
|
-
c == null || c.throwIfAborted(), f.txs.forEach((
|
|
2217
|
-
|
|
2218
|
-
claimTxHex:
|
|
2219
|
-
assertTxHex:
|
|
2220
|
-
path: `txs[${
|
|
2234
|
+
c == null || c.throwIfAborted(), f.txs.forEach((O, se) => {
|
|
2235
|
+
rs({
|
|
2236
|
+
claimTxHex: O.claim_tx.tx_hex,
|
|
2237
|
+
assertTxHex: O.assert_tx.tx_hex,
|
|
2238
|
+
path: `txs[${se}]`
|
|
2221
2239
|
});
|
|
2222
2240
|
});
|
|
2223
|
-
const m =
|
|
2241
|
+
const m = ns({
|
|
2224
2242
|
peginTxid: n,
|
|
2225
2243
|
peginTxHex: i.peginTxHex,
|
|
2226
2244
|
claimTxHex: f.depositor_graph.claim_tx.tx_hex,
|
|
2227
2245
|
assertTxHex: f.depositor_graph.assert_tx.tx_hex,
|
|
2228
2246
|
payoutTxHex: f.depositor_graph.payout_tx.tx_hex,
|
|
2229
2247
|
challengers: f.depositor_graph.challenger_presign_data
|
|
2230
|
-
}),
|
|
2231
|
-
|
|
2248
|
+
}), $ = {
|
|
2249
|
+
vaultCoreVersion: i.vaultCoreVersion,
|
|
2250
|
+
peginTxHex: i.peginTxHex,
|
|
2251
|
+
depositorBtcPubkey: a,
|
|
2252
|
+
vaultProviderBtcPubkey: i.vaultProviderBtcPubkey,
|
|
2253
|
+
vaultKeeperBtcPubkeys: i.vaultKeeperBtcPubkeys,
|
|
2254
|
+
universalChallengerBtcPubkeys: i.universalChallengerBtcPubkeys,
|
|
2255
|
+
timelockPegin: i.timelockPegin,
|
|
2256
|
+
timelockAssert: i.timelockAssert,
|
|
2257
|
+
timelockChallengeAssert: i.timelockChallengeAssert,
|
|
2258
|
+
councilMembers: i.councilMembers,
|
|
2259
|
+
councilQuorum: i.councilQuorum,
|
|
2260
|
+
network: i.network,
|
|
2261
|
+
registeredPayoutScriptPubKey: i.registeredPayoutScriptPubKey,
|
|
2262
|
+
protocolFeeRate: i.protocolFeeRate,
|
|
2263
|
+
vkClaimerPayoutScriptPubKeys: i.vkClaimerPayoutScriptPubKeys,
|
|
2264
|
+
vpCommissionScriptPubKey: i.vpCommissionScriptPubKey
|
|
2265
|
+
};
|
|
2266
|
+
await Gt(
|
|
2267
|
+
f.depositor_graph,
|
|
2268
|
+
$
|
|
2269
|
+
), c == null || c.throwIfAborted();
|
|
2270
|
+
const x = I(a);
|
|
2271
|
+
Ps(
|
|
2232
2272
|
f.txs,
|
|
2233
2273
|
i.vaultProviderBtcPubkey,
|
|
2234
2274
|
i.vaultKeeperBtcPubkeys,
|
|
2235
2275
|
a
|
|
2236
2276
|
);
|
|
2237
|
-
const
|
|
2238
|
-
(
|
|
2239
|
-
),
|
|
2277
|
+
const v = f.txs.filter(
|
|
2278
|
+
(O) => I(O.claimer_pubkey) !== x
|
|
2279
|
+
), E = bs(v);
|
|
2240
2280
|
p && y && (typeof p.validateDepositTerms == "function" && await p.validateDepositTerms(y), await p.approveDepositTerms(y)), c == null || c.throwIfAborted();
|
|
2241
|
-
const
|
|
2281
|
+
const T = await ws(
|
|
2242
2282
|
o,
|
|
2243
2283
|
i,
|
|
2244
|
-
|
|
2245
|
-
|
|
2284
|
+
E,
|
|
2285
|
+
h
|
|
2246
2286
|
);
|
|
2247
2287
|
c == null || c.throwIfAborted();
|
|
2248
|
-
const
|
|
2288
|
+
const w = await gs({
|
|
2249
2289
|
depositorGraph: f.depositor_graph,
|
|
2250
2290
|
btcWallet: o,
|
|
2251
|
-
signingContext:
|
|
2252
|
-
vaultCoreVersion: i.vaultCoreVersion,
|
|
2253
|
-
peginTxHex: i.peginTxHex,
|
|
2254
|
-
depositorBtcPubkey: a,
|
|
2255
|
-
vaultProviderBtcPubkey: i.vaultProviderBtcPubkey,
|
|
2256
|
-
vaultKeeperBtcPubkeys: i.vaultKeeperBtcPubkeys,
|
|
2257
|
-
universalChallengerBtcPubkeys: i.universalChallengerBtcPubkeys,
|
|
2258
|
-
timelockPegin: i.timelockPegin,
|
|
2259
|
-
timelockAssert: i.timelockAssert,
|
|
2260
|
-
councilMembers: i.councilMembers,
|
|
2261
|
-
councilQuorum: i.councilQuorum,
|
|
2262
|
-
network: i.network,
|
|
2263
|
-
registeredPayoutScriptPubKey: i.registeredPayoutScriptPubKey,
|
|
2264
|
-
protocolFeeRate: i.protocolFeeRate,
|
|
2265
|
-
vkClaimerPayoutScriptPubKeys: i.vkClaimerPayoutScriptPubKeys,
|
|
2266
|
-
vpCommissionScriptPubKey: i.vpCommissionScriptPubKey
|
|
2267
|
-
}
|
|
2291
|
+
signingContext: $
|
|
2268
2292
|
});
|
|
2269
|
-
c == null || c.throwIfAborted(), await
|
|
2270
|
-
const
|
|
2271
|
-
|
|
2293
|
+
c == null || c.throwIfAborted(), await d(m), c == null || c.throwIfAborted();
|
|
2294
|
+
const j = { ...T };
|
|
2295
|
+
j[b(a)] = w.payout_signatures, await r.submitDepositorPresignatures(
|
|
2272
2296
|
{
|
|
2273
2297
|
pegin_txid: n,
|
|
2274
2298
|
depositor_pk: a,
|
|
2275
|
-
signatures:
|
|
2276
|
-
depositor_claimer_presignatures:
|
|
2299
|
+
signatures: j,
|
|
2300
|
+
depositor_claimer_presignatures: w
|
|
2277
2301
|
},
|
|
2278
2302
|
c
|
|
2279
2303
|
);
|
|
2280
2304
|
}
|
|
2281
|
-
const
|
|
2305
|
+
const xs = 300 * 1e3, Es = /* @__PURE__ */ new Set([
|
|
2282
2306
|
R.PENDING_DEPOSITOR_WOTS_PK,
|
|
2283
|
-
...
|
|
2307
|
+
...Ct
|
|
2284
2308
|
]);
|
|
2285
|
-
async function
|
|
2309
|
+
async function vn(e) {
|
|
2286
2310
|
const {
|
|
2287
2311
|
statusReader: t,
|
|
2288
2312
|
wotsSubmitter: r,
|
|
@@ -2290,7 +2314,7 @@ async function cn(e) {
|
|
|
2290
2314
|
peginTxid: s,
|
|
2291
2315
|
depositorPk: n,
|
|
2292
2316
|
wotsPublicKeys: a,
|
|
2293
|
-
timeoutMs: i =
|
|
2317
|
+
timeoutMs: i = xs,
|
|
2294
2318
|
signal: u
|
|
2295
2319
|
} = e;
|
|
2296
2320
|
u == null || u.throwIfAborted();
|
|
@@ -2298,11 +2322,11 @@ async function cn(e) {
|
|
|
2298
2322
|
statusReader: t,
|
|
2299
2323
|
vaultId: o,
|
|
2300
2324
|
peginTxid: s,
|
|
2301
|
-
targetStatuses:
|
|
2325
|
+
targetStatuses: Es,
|
|
2302
2326
|
timeoutMs: i,
|
|
2303
2327
|
signal: u
|
|
2304
2328
|
});
|
|
2305
|
-
|
|
2329
|
+
Ct.has(l) || (u == null || u.throwIfAborted(), await r.submitDepositorWotsKey(
|
|
2306
2330
|
{
|
|
2307
2331
|
pegin_txid: s,
|
|
2308
2332
|
depositor_pk: n,
|
|
@@ -2311,30 +2335,30 @@ async function cn(e) {
|
|
|
2311
2335
|
u
|
|
2312
2336
|
));
|
|
2313
2337
|
}
|
|
2314
|
-
function
|
|
2338
|
+
function $e(e) {
|
|
2315
2339
|
return e.registration || e.operation;
|
|
2316
2340
|
}
|
|
2317
|
-
function
|
|
2341
|
+
function ks(e, t, r) {
|
|
2318
2342
|
const o = _(e);
|
|
2319
2343
|
return {
|
|
2320
2344
|
registration: o === _(t),
|
|
2321
2345
|
operation: o === _(r)
|
|
2322
2346
|
};
|
|
2323
2347
|
}
|
|
2324
|
-
function
|
|
2325
|
-
const o =
|
|
2348
|
+
function nt(e, t, r) {
|
|
2349
|
+
const o = Ce(e);
|
|
2326
2350
|
return {
|
|
2327
|
-
registration:
|
|
2328
|
-
operation:
|
|
2351
|
+
registration: it(o, Ce(t)),
|
|
2352
|
+
operation: it(o, Ce(r))
|
|
2329
2353
|
};
|
|
2330
2354
|
}
|
|
2331
|
-
function
|
|
2355
|
+
function Ce(e) {
|
|
2332
2356
|
return e.map(_).sort();
|
|
2333
2357
|
}
|
|
2334
|
-
function
|
|
2358
|
+
function it(e, t) {
|
|
2335
2359
|
return e.length === t.length && e.every((r, o) => r === t[o]);
|
|
2336
2360
|
}
|
|
2337
|
-
async function
|
|
2361
|
+
async function bn(e) {
|
|
2338
2362
|
const {
|
|
2339
2363
|
vaultProviderEthAddress: t,
|
|
2340
2364
|
hintBtcPubkey: r,
|
|
@@ -2358,11 +2382,11 @@ class Se extends Error {
|
|
|
2358
2382
|
super(t), this.name = "ApplicationEntryPointMismatchError";
|
|
2359
2383
|
}
|
|
2360
2384
|
}
|
|
2361
|
-
function
|
|
2385
|
+
function mn(e) {
|
|
2362
2386
|
return e instanceof Se || e instanceof Error && e.name === "ApplicationEntryPointMismatchError";
|
|
2363
2387
|
}
|
|
2364
|
-
const
|
|
2365
|
-
async function
|
|
2388
|
+
const at = (e) => e.map(_).sort();
|
|
2389
|
+
async function Pn(e) {
|
|
2366
2390
|
const {
|
|
2367
2391
|
vaultRegistryReader: t,
|
|
2368
2392
|
vaultKeeperReader: r,
|
|
@@ -2374,8 +2398,8 @@ async function hn(e) {
|
|
|
2374
2398
|
expectedUniversalChallengerBtcPubkeys: u,
|
|
2375
2399
|
operationKeyReader: l,
|
|
2376
2400
|
onIndexerServingOperationKeys: c,
|
|
2377
|
-
onIndexerHintsInconsistent:
|
|
2378
|
-
blockNumber:
|
|
2401
|
+
onIndexerHintsInconsistent: h,
|
|
2402
|
+
blockNumber: d
|
|
2379
2403
|
} = e, [
|
|
2380
2404
|
g,
|
|
2381
2405
|
p,
|
|
@@ -2384,49 +2408,49 @@ async function hn(e) {
|
|
|
2384
2408
|
] = await Promise.all([
|
|
2385
2409
|
t.getVaultProviderApplication(
|
|
2386
2410
|
s,
|
|
2387
|
-
|
|
2411
|
+
d
|
|
2388
2412
|
),
|
|
2389
2413
|
t.getVaultProviderGenesisBtcPubKey(
|
|
2390
2414
|
s,
|
|
2391
|
-
|
|
2415
|
+
d
|
|
2392
2416
|
),
|
|
2393
|
-
o.getLatestUniversalChallengersVersion(
|
|
2394
|
-
o.getCurrentUcKeyEpoch(
|
|
2417
|
+
o.getLatestUniversalChallengersVersion(d),
|
|
2418
|
+
o.getCurrentUcKeyEpoch(d)
|
|
2395
2419
|
]);
|
|
2396
|
-
if (!
|
|
2420
|
+
if (!Hr(n, { strict: !1 }))
|
|
2397
2421
|
throw new Se(
|
|
2398
2422
|
`The application entry point this deposit was prepared for is not a valid address: ${n}`
|
|
2399
2423
|
);
|
|
2400
|
-
if (!
|
|
2424
|
+
if (!Or(g, n))
|
|
2401
2425
|
throw new Se(
|
|
2402
2426
|
`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.`
|
|
2403
2427
|
);
|
|
2404
|
-
const [m,
|
|
2428
|
+
const [m, $] = await Promise.all(
|
|
2405
2429
|
[
|
|
2406
2430
|
r.getCurrentVaultKeepersVersion(
|
|
2407
2431
|
g,
|
|
2408
|
-
|
|
2432
|
+
d
|
|
2409
2433
|
),
|
|
2410
2434
|
r.getCurrentAppKeeperKeyEpoch(
|
|
2411
2435
|
g,
|
|
2412
|
-
|
|
2436
|
+
d
|
|
2413
2437
|
)
|
|
2414
2438
|
]
|
|
2415
2439
|
), [x, v] = await Promise.all([
|
|
2416
2440
|
r.getVaultKeepersByVersion(
|
|
2417
2441
|
g,
|
|
2418
2442
|
m,
|
|
2419
|
-
|
|
2443
|
+
d
|
|
2420
2444
|
),
|
|
2421
2445
|
o.getUniversalChallengersByVersion(
|
|
2422
2446
|
y,
|
|
2423
|
-
|
|
2447
|
+
d
|
|
2424
2448
|
)
|
|
2425
2449
|
]), E = {
|
|
2426
2450
|
vaultProvider: _(p),
|
|
2427
|
-
vaultKeepers:
|
|
2428
|
-
universalChallengers:
|
|
2429
|
-
}, T = await
|
|
2451
|
+
vaultKeepers: at(x.map((C) => C.btcPubKey)),
|
|
2452
|
+
universalChallengers: at(v.map((C) => C.btcPubKey))
|
|
2453
|
+
}, T = await Uo({
|
|
2430
2454
|
operationKeyReader: l,
|
|
2431
2455
|
query: {
|
|
2432
2456
|
vaultProviderEthAddress: s,
|
|
@@ -2435,44 +2459,44 @@ async function hn(e) {
|
|
|
2435
2459
|
vaultKeepers: x,
|
|
2436
2460
|
universalChallengers: v
|
|
2437
2461
|
},
|
|
2438
|
-
blockNumber:
|
|
2462
|
+
blockNumber: d
|
|
2439
2463
|
}), w = {
|
|
2440
2464
|
vaultProvider: T.vaultProvider.operationBtcPubkey,
|
|
2441
2465
|
vaultKeepers: [...T.vaultKeeperOperationKeysSorted],
|
|
2442
2466
|
universalChallengers: [
|
|
2443
2467
|
...T.universalChallengerOperationKeysSorted
|
|
2444
2468
|
]
|
|
2445
|
-
},
|
|
2469
|
+
}, j = ks(
|
|
2446
2470
|
a,
|
|
2447
2471
|
E.vaultProvider,
|
|
2448
2472
|
w.vaultProvider
|
|
2449
|
-
),
|
|
2473
|
+
), O = nt(
|
|
2450
2474
|
i,
|
|
2451
2475
|
E.vaultKeepers,
|
|
2452
2476
|
w.vaultKeepers
|
|
2453
|
-
),
|
|
2477
|
+
), se = nt(
|
|
2454
2478
|
u,
|
|
2455
2479
|
E.universalChallengers,
|
|
2456
2480
|
w.universalChallengers
|
|
2457
2481
|
);
|
|
2458
|
-
if (
|
|
2482
|
+
if (!$e(j))
|
|
2459
2483
|
throw new Error(
|
|
2460
2484
|
`Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${s}. Refresh and try again.`
|
|
2461
2485
|
);
|
|
2462
|
-
if (
|
|
2486
|
+
if (!$e(O))
|
|
2463
2487
|
throw new Error(
|
|
2464
2488
|
`Vault keeper BTC pubkeys (v${m}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
|
|
2465
2489
|
);
|
|
2466
|
-
if (
|
|
2490
|
+
if (!$e(se))
|
|
2467
2491
|
throw new Error(
|
|
2468
2492
|
`Universal challenger BTC pubkeys (v${y}) indexer set does not match ProtocolParams on-chain set. Refresh and try again.`
|
|
2469
2493
|
);
|
|
2470
|
-
const
|
|
2471
|
-
if (
|
|
2494
|
+
const Ne = [j, O, se], Qt = Ne.some((C) => C.registration && !C.operation), De = Ne.some((C) => C.operation && !C.registration);
|
|
2495
|
+
if (Qt && De) {
|
|
2472
2496
|
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.`;
|
|
2473
|
-
throw
|
|
2497
|
+
throw h == null || h(C), new Error(`${C} Refresh and try again.`);
|
|
2474
2498
|
}
|
|
2475
|
-
return
|
|
2499
|
+
return De && (c == null || c(
|
|
2476
2500
|
`Indexer is serving rotated operation keys for vault provider ${s}`
|
|
2477
2501
|
)), {
|
|
2478
2502
|
vaultProviderBtcPubkeyXOnly: w.vaultProvider,
|
|
@@ -2480,16 +2504,16 @@ async function hn(e) {
|
|
|
2480
2504
|
universalChallengerBtcPubkeysSorted: w.universalChallengers,
|
|
2481
2505
|
expectedAppVaultKeepersVersion: m,
|
|
2482
2506
|
expectedUniversalChallengersVersion: y,
|
|
2483
|
-
appKeeperKeyEpoch:
|
|
2507
|
+
appKeeperKeyEpoch: $,
|
|
2484
2508
|
ucKeyEpoch: f,
|
|
2485
2509
|
registrationKeys: E,
|
|
2486
2510
|
participantKeys: T
|
|
2487
2511
|
};
|
|
2488
2512
|
}
|
|
2489
|
-
function
|
|
2513
|
+
function $s(e) {
|
|
2490
2514
|
return /^[0-9a-fA-F]{64}$/.test(e);
|
|
2491
2515
|
}
|
|
2492
|
-
function
|
|
2516
|
+
function wn(e) {
|
|
2493
2517
|
const {
|
|
2494
2518
|
amountSats: t,
|
|
2495
2519
|
minDeposit: r,
|
|
@@ -2500,29 +2524,29 @@ function pn(e) {
|
|
|
2500
2524
|
} = e;
|
|
2501
2525
|
return !(t <= 0n || t < r || o && o > 0n && t > o || n == null || a == null || t + n + a > s);
|
|
2502
2526
|
}
|
|
2503
|
-
function
|
|
2527
|
+
function xn(e, t, r) {
|
|
2504
2528
|
return e <= 0n ? {
|
|
2505
2529
|
valid: !1,
|
|
2506
2530
|
error: "Deposit amount must be greater than zero"
|
|
2507
2531
|
} : e < t ? {
|
|
2508
2532
|
valid: !1,
|
|
2509
|
-
error: `Minimum deposit is ${
|
|
2533
|
+
error: `Minimum deposit is ${N(t)} BTC`
|
|
2510
2534
|
} : r && r > 0n && e > r ? {
|
|
2511
2535
|
valid: !1,
|
|
2512
|
-
error: `Maximum deposit is ${
|
|
2536
|
+
error: `Maximum deposit is ${N(r)} BTC`
|
|
2513
2537
|
} : { valid: !0 };
|
|
2514
2538
|
}
|
|
2515
|
-
function
|
|
2539
|
+
function En(e) {
|
|
2516
2540
|
const { amount: t, effectiveRemaining: r } = e;
|
|
2517
2541
|
return r === null ? { valid: !0 } : r === 0n ? {
|
|
2518
2542
|
valid: !1,
|
|
2519
2543
|
error: "Supply cap reached — deposits temporarily paused"
|
|
2520
2544
|
} : t > r ? {
|
|
2521
2545
|
valid: !1,
|
|
2522
|
-
error: `Vault size exceeds remaining capacity (${
|
|
2546
|
+
error: `Vault size exceeds remaining capacity (${N(r)} BTC)`
|
|
2523
2547
|
} : { valid: !0 };
|
|
2524
2548
|
}
|
|
2525
|
-
function
|
|
2549
|
+
function kn(e, t) {
|
|
2526
2550
|
if (!e || e.length === 0)
|
|
2527
2551
|
return {
|
|
2528
2552
|
valid: !1,
|
|
@@ -2538,7 +2562,7 @@ function yn(e, t) {
|
|
|
2538
2562
|
error: "Invalid vault provider selected"
|
|
2539
2563
|
} : { valid: !0 };
|
|
2540
2564
|
}
|
|
2541
|
-
function
|
|
2565
|
+
function Cs(e, t, r) {
|
|
2542
2566
|
if (!e || e.length === 0)
|
|
2543
2567
|
return {
|
|
2544
2568
|
valid: !1,
|
|
@@ -2554,40 +2578,40 @@ function bs(e, t, r) {
|
|
|
2554
2578
|
if (t && s < t)
|
|
2555
2579
|
return {
|
|
2556
2580
|
valid: !1,
|
|
2557
|
-
error: `Vault ${o + 1} amount ${
|
|
2581
|
+
error: `Vault ${o + 1} amount ${N(s)} BTC is below minimum deposit ${N(t)} BTC`
|
|
2558
2582
|
};
|
|
2559
2583
|
if (r && s > r)
|
|
2560
2584
|
return {
|
|
2561
2585
|
valid: !1,
|
|
2562
|
-
error: `Vault ${o + 1} amount ${
|
|
2586
|
+
error: `Vault ${o + 1} amount ${N(s)} BTC exceeds maximum deposit ${N(r)} BTC`
|
|
2563
2587
|
};
|
|
2564
2588
|
}
|
|
2565
2589
|
return { valid: !0 };
|
|
2566
2590
|
}
|
|
2567
|
-
function
|
|
2591
|
+
function Ts(e) {
|
|
2568
2592
|
const t = b(e);
|
|
2569
|
-
return
|
|
2593
|
+
return $s(t) ? { valid: !0 } : {
|
|
2570
2594
|
valid: !1,
|
|
2571
2595
|
error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
|
|
2572
2596
|
};
|
|
2573
2597
|
}
|
|
2574
|
-
function
|
|
2598
|
+
function _s(e) {
|
|
2575
2599
|
if (!e || e.length === 0)
|
|
2576
2600
|
throw new Error(
|
|
2577
2601
|
"No vault keepers available. The system requires at least one vault keeper to create a deposit."
|
|
2578
2602
|
);
|
|
2579
2603
|
}
|
|
2580
|
-
function
|
|
2604
|
+
function Ss(e) {
|
|
2581
2605
|
if (!e || e.length === 0)
|
|
2582
2606
|
throw new Error(
|
|
2583
2607
|
"No universal challengers available. The system requires at least one universal challenger to create a deposit."
|
|
2584
2608
|
);
|
|
2585
2609
|
}
|
|
2586
|
-
function
|
|
2610
|
+
function As(e) {
|
|
2587
2611
|
if (e.length === 0)
|
|
2588
2612
|
throw new Error("No spendable UTXOs available");
|
|
2589
2613
|
}
|
|
2590
|
-
function
|
|
2614
|
+
function $n(e) {
|
|
2591
2615
|
const {
|
|
2592
2616
|
vaultAmounts: t,
|
|
2593
2617
|
confirmedUTXOs: r,
|
|
@@ -2596,38 +2620,38 @@ function vn(e) {
|
|
|
2596
2620
|
universalChallengerBtcPubkeys: n,
|
|
2597
2621
|
minDeposit: a,
|
|
2598
2622
|
maxDeposit: i
|
|
2599
|
-
} = e, u =
|
|
2623
|
+
} = e, u = Cs(
|
|
2600
2624
|
t,
|
|
2601
2625
|
a,
|
|
2602
2626
|
i
|
|
2603
2627
|
);
|
|
2604
2628
|
if (!u.valid)
|
|
2605
2629
|
throw new Error(u.error);
|
|
2606
|
-
const l =
|
|
2630
|
+
const l = Ts(o);
|
|
2607
2631
|
if (!l.valid)
|
|
2608
2632
|
throw new Error(l.error);
|
|
2609
|
-
|
|
2633
|
+
_s(s), Ss(n), As(r);
|
|
2610
2634
|
}
|
|
2611
|
-
class
|
|
2635
|
+
class jt extends Error {
|
|
2612
2636
|
constructor(t) {
|
|
2613
2637
|
super(t), this.name = "ParticipantKeyDriftError";
|
|
2614
2638
|
}
|
|
2615
2639
|
}
|
|
2616
|
-
function
|
|
2617
|
-
return e instanceof
|
|
2640
|
+
function Cn(e) {
|
|
2641
|
+
return e instanceof jt || e instanceof Error && e.name === "ParticipantKeyDriftError";
|
|
2618
2642
|
}
|
|
2619
|
-
function
|
|
2643
|
+
function ut(e, t, r) {
|
|
2620
2644
|
return t.length === r.length && t.every((o, s) => o === r[s]) ? null : `${e} expected [${t.join(", ")}], got [${r.join(", ")}]`;
|
|
2621
2645
|
}
|
|
2622
|
-
async function
|
|
2646
|
+
async function Tn(e) {
|
|
2623
2647
|
const { vaultRegistryReader: t, operationKeyReader: r, vaultIds: o, expected: s } = e, n = s.query;
|
|
2624
2648
|
if (o.length === 0) return;
|
|
2625
2649
|
const a = await t.getVaultKeyEpochsBatch(o), i = [];
|
|
2626
2650
|
for (const [u, l] of a.entries()) {
|
|
2627
2651
|
const c = o[u];
|
|
2628
|
-
let
|
|
2652
|
+
let h;
|
|
2629
2653
|
try {
|
|
2630
|
-
|
|
2654
|
+
h = await Nt({
|
|
2631
2655
|
operationKeyReader: r,
|
|
2632
2656
|
query: n,
|
|
2633
2657
|
epochs: l
|
|
@@ -2638,36 +2662,36 @@ async function mn(e) {
|
|
|
2638
2662
|
);
|
|
2639
2663
|
continue;
|
|
2640
2664
|
}
|
|
2641
|
-
|
|
2642
|
-
`vault ${c}: vault provider key expected ${s.vaultProvider.operationBtcPubkey}, got ${
|
|
2665
|
+
h.vaultProvider.operationBtcPubkey !== s.vaultProvider.operationBtcPubkey && i.push(
|
|
2666
|
+
`vault ${c}: vault provider key expected ${s.vaultProvider.operationBtcPubkey}, got ${h.vaultProvider.operationBtcPubkey}`
|
|
2643
2667
|
);
|
|
2644
|
-
const
|
|
2668
|
+
const d = ut(
|
|
2645
2669
|
`vault ${c}: vault keeper keys`,
|
|
2646
2670
|
s.vaultKeeperOperationKeysSorted,
|
|
2647
|
-
|
|
2671
|
+
h.vaultKeeperOperationKeysSorted
|
|
2648
2672
|
);
|
|
2649
|
-
|
|
2650
|
-
const g =
|
|
2673
|
+
d && i.push(d);
|
|
2674
|
+
const g = ut(
|
|
2651
2675
|
`vault ${c}: universal challenger keys`,
|
|
2652
2676
|
s.universalChallengerOperationKeysSorted,
|
|
2653
|
-
|
|
2677
|
+
h.universalChallengerOperationKeysSorted
|
|
2654
2678
|
);
|
|
2655
2679
|
g && i.push(g);
|
|
2656
2680
|
}
|
|
2657
2681
|
if (i.length > 0)
|
|
2658
|
-
throw new
|
|
2682
|
+
throw new jt(
|
|
2659
2683
|
`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.`
|
|
2660
2684
|
);
|
|
2661
2685
|
}
|
|
2662
|
-
class
|
|
2686
|
+
class Wt extends Error {
|
|
2663
2687
|
constructor(t) {
|
|
2664
2688
|
super(t), this.name = "RegisteredVaultVersionMismatchError";
|
|
2665
2689
|
}
|
|
2666
2690
|
}
|
|
2667
|
-
function
|
|
2668
|
-
return e instanceof
|
|
2691
|
+
function _n(e) {
|
|
2692
|
+
return e instanceof Wt || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
|
|
2669
2693
|
}
|
|
2670
|
-
async function
|
|
2694
|
+
async function Sn(e) {
|
|
2671
2695
|
const {
|
|
2672
2696
|
vaultRegistryReader: t,
|
|
2673
2697
|
vaultIds: r,
|
|
@@ -2677,53 +2701,53 @@ async function wn(e) {
|
|
|
2677
2701
|
expectedVaultCoreVersion: a
|
|
2678
2702
|
} = e, i = await t.getProtocolInfoBatch(r), u = [];
|
|
2679
2703
|
if (i.forEach((l, c) => {
|
|
2680
|
-
const
|
|
2704
|
+
const h = r[c];
|
|
2681
2705
|
l.offchainParamsVersion !== o && u.push(
|
|
2682
|
-
`vault ${
|
|
2706
|
+
`vault ${h}: offchainParams expected v${o}, got v${l.offchainParamsVersion}`
|
|
2683
2707
|
), l.appVaultKeepersVersion !== s && u.push(
|
|
2684
|
-
`vault ${
|
|
2708
|
+
`vault ${h}: appVaultKeepers expected v${s}, got v${l.appVaultKeepersVersion}`
|
|
2685
2709
|
), l.universalChallengersVersion !== n && u.push(
|
|
2686
|
-
`vault ${
|
|
2710
|
+
`vault ${h}: universalChallengers expected v${n}, got v${l.universalChallengersVersion}`
|
|
2687
2711
|
), l.vaultCoreVersion !== a && u.push(
|
|
2688
|
-
`vault ${
|
|
2712
|
+
`vault ${h}: vaultCoreVersion expected v${a} (build-time active), got v${l.vaultCoreVersion}`
|
|
2689
2713
|
);
|
|
2690
2714
|
}), u.length > 0)
|
|
2691
|
-
throw new
|
|
2715
|
+
throw new Wt(
|
|
2692
2716
|
`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.`
|
|
2693
2717
|
);
|
|
2694
2718
|
}
|
|
2695
|
-
class
|
|
2719
|
+
class Bs extends Error {
|
|
2696
2720
|
constructor(r, o) {
|
|
2697
2721
|
super(`Refund not yet mature (BIP68 not final): ${o.message}`);
|
|
2698
|
-
|
|
2699
|
-
|
|
2722
|
+
W(this, "vaultId");
|
|
2723
|
+
W(this, "cause");
|
|
2700
2724
|
this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = o;
|
|
2701
2725
|
}
|
|
2702
2726
|
}
|
|
2703
|
-
const
|
|
2704
|
-
function
|
|
2727
|
+
const Is = /^0x[0-9a-fA-F]{64}$/, Vs = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, Yt = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, Jt = 160, ct = 2e3, lt = 10n, dt = 100n;
|
|
2728
|
+
function An(e) {
|
|
2705
2729
|
if (!Number.isFinite(e) || e <= 0)
|
|
2706
2730
|
throw new Error(
|
|
2707
2731
|
`feeRateSatsVb must be a positive finite number, got ${e}`
|
|
2708
2732
|
);
|
|
2709
|
-
return BigInt(Math.ceil(e *
|
|
2733
|
+
return BigInt(Math.ceil(e * Jt));
|
|
2710
2734
|
}
|
|
2711
|
-
const
|
|
2735
|
+
const Rs = 1, Ks = /non-BIP68-final/i;
|
|
2712
2736
|
function Ae(e, t) {
|
|
2713
2737
|
if (e.length !== 66)
|
|
2714
2738
|
throw new Error(
|
|
2715
2739
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
2716
2740
|
);
|
|
2717
|
-
if (
|
|
2741
|
+
if (!Is.test(e))
|
|
2718
2742
|
throw new Error(
|
|
2719
2743
|
`${t} must contain only hex characters after the 0x prefix`
|
|
2720
2744
|
);
|
|
2721
2745
|
}
|
|
2722
|
-
function
|
|
2746
|
+
function Te(e, t) {
|
|
2723
2747
|
if (!Number.isInteger(e) || e < 0)
|
|
2724
2748
|
throw new Error(`${t} must be a non-negative integer, got ${e}`);
|
|
2725
2749
|
}
|
|
2726
|
-
function
|
|
2750
|
+
function Hs(e) {
|
|
2727
2751
|
if (Ae(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0)
|
|
2728
2752
|
throw new Error(
|
|
2729
2753
|
`htlcVout must be a non-negative integer, got ${e.htlcVout}`
|
|
@@ -2754,27 +2778,27 @@ function _s(e) {
|
|
|
2754
2778
|
throw new Error(
|
|
2755
2779
|
`batch[${e.htlcVout}].amount (${t.amount}) does not match target amount (${e.amount})`
|
|
2756
2780
|
);
|
|
2757
|
-
if (
|
|
2781
|
+
if (Te(e.offchainParamsVersion, "offchainParamsVersion"), Te(e.appVaultKeepersVersion, "appVaultKeepersVersion"), Te(
|
|
2758
2782
|
e.universalChallengersVersion,
|
|
2759
2783
|
"universalChallengersVersion"
|
|
2760
|
-
),
|
|
2784
|
+
), Jr(
|
|
2761
2785
|
e.vaultCoreVersion,
|
|
2762
2786
|
"VaultRefundData.vaultCoreVersion"
|
|
2763
2787
|
), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
|
|
2764
2788
|
throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
|
|
2765
|
-
if (!
|
|
2789
|
+
if (!Vs.test(e.unsignedPrePeginTxHex))
|
|
2766
2790
|
throw new Error(
|
|
2767
2791
|
"unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
|
|
2768
2792
|
);
|
|
2769
|
-
if (!e.depositorBtcPubkey || !
|
|
2793
|
+
if (!e.depositorBtcPubkey || !Yt.test(e.depositorBtcPubkey))
|
|
2770
2794
|
throw new Error(
|
|
2771
2795
|
"depositorBtcPubkey must be 32 or 33 bytes of hex (optional 0x prefix)"
|
|
2772
2796
|
);
|
|
2773
2797
|
if (typeof e.amount != "bigint" || e.amount <= 0n)
|
|
2774
2798
|
throw new Error(`amount must be a positive bigint, got ${e.amount}`);
|
|
2775
2799
|
}
|
|
2776
|
-
function
|
|
2777
|
-
if (!e.vaultProviderPubkey || !
|
|
2800
|
+
function Os(e) {
|
|
2801
|
+
if (!e.vaultProviderPubkey || !Yt.test(e.vaultProviderPubkey))
|
|
2778
2802
|
throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
|
|
2779
2803
|
if (e.vaultKeeperPubkeys.length === 0)
|
|
2780
2804
|
throw new Error("vaultKeeperPubkeys must be non-empty");
|
|
@@ -2799,7 +2823,7 @@ function Ss(e) {
|
|
|
2799
2823
|
`councilQuorum (${e.councilQuorum}) must be in [1, councilSize=${e.councilSize}]`
|
|
2800
2824
|
);
|
|
2801
2825
|
}
|
|
2802
|
-
async function
|
|
2826
|
+
async function Bn(e) {
|
|
2803
2827
|
const {
|
|
2804
2828
|
vaultId: t,
|
|
2805
2829
|
readVault: r,
|
|
@@ -2811,23 +2835,23 @@ async function En(e) {
|
|
|
2811
2835
|
} = e;
|
|
2812
2836
|
i == null || i.throwIfAborted(), Ae(t, "vaultId");
|
|
2813
2837
|
const u = await r();
|
|
2814
|
-
|
|
2838
|
+
Hs(u), i == null || i.throwIfAborted();
|
|
2815
2839
|
const l = await o(u);
|
|
2816
|
-
if (
|
|
2840
|
+
if (Os(l), i == null || i.throwIfAborted(), !Number.isFinite(s) || s <= 0)
|
|
2817
2841
|
throw new Error(`feeRate must be a positive number, got ${s}`);
|
|
2818
|
-
if (s >
|
|
2842
|
+
if (s > ct)
|
|
2819
2843
|
throw new Error(
|
|
2820
|
-
`feeRate ${s} sat/vB exceeds refund safety cap ${
|
|
2844
|
+
`feeRate ${s} sat/vB exceeds refund safety cap ${ct} sat/vB; refusing to sign refund.`
|
|
2821
2845
|
);
|
|
2822
|
-
const c = BigInt(Math.ceil(s *
|
|
2823
|
-
if (c >
|
|
2846
|
+
const c = BigInt(Math.ceil(s * Jt)), h = u.amount * lt / dt;
|
|
2847
|
+
if (c > h)
|
|
2824
2848
|
throw new Error(
|
|
2825
|
-
`Refund fee ${c} sats exceeds the per-vault safety cap of ${
|
|
2849
|
+
`Refund fee ${c} sats exceeds the per-vault safety cap of ${h} sats (${lt}/${dt} of vault.amount=${u.amount}); refusing to sign refund.`
|
|
2826
2850
|
);
|
|
2827
2851
|
i == null || i.throwIfAborted();
|
|
2828
|
-
const
|
|
2852
|
+
const d = pe(
|
|
2829
2853
|
u.depositorBtcPubkey
|
|
2830
|
-
), g = b(u.unsignedPrePeginTxHex), p =
|
|
2854
|
+
), g = b(u.unsignedPrePeginTxHex), p = ir(g);
|
|
2831
2855
|
if (p !== void 0 && p.vout !== u.batch.length)
|
|
2832
2856
|
throw new Error(
|
|
2833
2857
|
`Auth-anchor OP_RETURN at vout ${p.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.`
|
|
@@ -2845,10 +2869,10 @@ async function En(e) {
|
|
|
2845
2869
|
throw new Error(
|
|
2846
2870
|
`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.`
|
|
2847
2871
|
);
|
|
2848
|
-
const { psbtHex: m } = await
|
|
2872
|
+
const { psbtHex: m } = await jr({
|
|
2849
2873
|
prePeginParams: {
|
|
2850
2874
|
vaultCoreVersion: u.vaultCoreVersion,
|
|
2851
|
-
depositorPubkey:
|
|
2875
|
+
depositorPubkey: d,
|
|
2852
2876
|
vaultProviderPubkey: b(l.vaultProviderPubkey),
|
|
2853
2877
|
vaultKeeperPubkeys: l.vaultKeeperPubkeys.map(b),
|
|
2854
2878
|
universalChallengerPubkeys: l.universalChallengerPubkeys.map(b),
|
|
@@ -2879,52 +2903,52 @@ async function En(e) {
|
|
|
2879
2903
|
hashlock: b(u.hashlock)
|
|
2880
2904
|
});
|
|
2881
2905
|
i == null || i.throwIfAborted();
|
|
2882
|
-
const
|
|
2906
|
+
const $ = ce(
|
|
2883
2907
|
u.depositorBtcPubkey,
|
|
2884
|
-
|
|
2885
|
-
), x = await n(m,
|
|
2886
|
-
|
|
2908
|
+
Rs
|
|
2909
|
+
), x = await n(m, $);
|
|
2910
|
+
ae({
|
|
2887
2911
|
requestedPsbtHex: m,
|
|
2888
2912
|
returnedPsbtHex: x
|
|
2889
2913
|
});
|
|
2890
|
-
const v = 0, E =
|
|
2914
|
+
const v = 0, E = ue(
|
|
2891
2915
|
x,
|
|
2892
|
-
|
|
2916
|
+
d,
|
|
2893
2917
|
v
|
|
2894
2918
|
);
|
|
2895
|
-
|
|
2919
|
+
oe({
|
|
2896
2920
|
requestedPsbtHex: m,
|
|
2897
2921
|
signatureHex: E,
|
|
2898
|
-
signerXOnlyPubkeyHex:
|
|
2922
|
+
signerXOnlyPubkeyHex: d,
|
|
2899
2923
|
inputIndex: v
|
|
2900
2924
|
});
|
|
2901
|
-
const T =
|
|
2925
|
+
const T = Tt({
|
|
2902
2926
|
requestedPsbtHex: m,
|
|
2903
2927
|
signaturesHex: [E],
|
|
2904
|
-
signerXOnlyPubkeyHex:
|
|
2928
|
+
signerXOnlyPubkeyHex: d
|
|
2905
2929
|
});
|
|
2906
2930
|
i == null || i.throwIfAborted();
|
|
2907
2931
|
try {
|
|
2908
2932
|
return await a(T);
|
|
2909
2933
|
} catch (w) {
|
|
2910
|
-
throw w instanceof Error &&
|
|
2934
|
+
throw w instanceof Error && Ks.test(w.message) ? new Bs(t, w) : w;
|
|
2911
2935
|
}
|
|
2912
2936
|
}
|
|
2913
|
-
class
|
|
2937
|
+
class ht extends Error {
|
|
2914
2938
|
constructor(r, o, s) {
|
|
2915
2939
|
super(r);
|
|
2916
2940
|
/** Fee the reclaim would have paid, in satoshis. */
|
|
2917
|
-
|
|
2941
|
+
W(this, "feeSats");
|
|
2918
2942
|
/** Sum of the reserves the reclaim would have swept, in satoshis. */
|
|
2919
|
-
|
|
2943
|
+
W(this, "sweptTotalSats");
|
|
2920
2944
|
this.name = "ReclaimUneconomicalError", this.feeSats = o, this.sweptTotalSats = s;
|
|
2921
2945
|
}
|
|
2922
2946
|
}
|
|
2923
|
-
const
|
|
2924
|
-
async function
|
|
2947
|
+
const pt = 2e3, gt = 25n, ft = 100n, In = 10n;
|
|
2948
|
+
async function Ns(e, t, r) {
|
|
2925
2949
|
for (let o = 0; o < e.length; o++) {
|
|
2926
|
-
const s =
|
|
2927
|
-
await
|
|
2950
|
+
const s = Qr(e[o].depositorSignedPeginTxHex), n = Ie(
|
|
2951
|
+
await mr(
|
|
2928
2952
|
b(s),
|
|
2929
2953
|
b(r)
|
|
2930
2954
|
)
|
|
@@ -2935,7 +2959,7 @@ async function As(e, t, r) {
|
|
|
2935
2959
|
);
|
|
2936
2960
|
}
|
|
2937
2961
|
}
|
|
2938
|
-
async function
|
|
2962
|
+
async function Vn(e) {
|
|
2939
2963
|
const {
|
|
2940
2964
|
vaultIds: t,
|
|
2941
2965
|
depositorEthAddress: r,
|
|
@@ -2950,9 +2974,9 @@ async function kn(e) {
|
|
|
2950
2974
|
throw new Error("Reclaim requires at least one vault id; got none.");
|
|
2951
2975
|
if (!Number.isFinite(n) || n <= 0)
|
|
2952
2976
|
throw new Error(`feeRate must be a positive number, got ${n}`);
|
|
2953
|
-
if (n >
|
|
2954
|
-
throw new
|
|
2955
|
-
`Fee rate ${n} sat/vB exceeds the reclaim safety cap of ${
|
|
2977
|
+
if (n > pt)
|
|
2978
|
+
throw new ht(
|
|
2979
|
+
`Fee rate ${n} sat/vB exceeds the reclaim safety cap of ${pt} sat/vB; refusing to sign.`,
|
|
2956
2980
|
0n,
|
|
2957
2981
|
0n
|
|
2958
2982
|
);
|
|
@@ -2961,127 +2985,127 @@ async function kn(e) {
|
|
|
2961
2985
|
throw new Error(
|
|
2962
2986
|
`readVaults returned ${l.length} reserves for ${t.length} vault id(s); refusing to sweep a set that does not match the request.`
|
|
2963
2987
|
);
|
|
2964
|
-
await
|
|
2965
|
-
const c =
|
|
2988
|
+
await Ns(l, t, r), u == null || u.throwIfAborted();
|
|
2989
|
+
const c = pe(o), h = l.map((v) => ({
|
|
2966
2990
|
depositorSignedPeginTxHex: v.depositorSignedPeginTxHex,
|
|
2967
2991
|
observed: v.observed,
|
|
2968
2992
|
expectedValue: v.expectedClaimValue
|
|
2969
|
-
})),
|
|
2970
|
-
if (
|
|
2971
|
-
throw new
|
|
2972
|
-
`Reclaim fee ${
|
|
2973
|
-
|
|
2993
|
+
})), d = Wr(n, h.length), g = h.reduce((v, E) => v + E.expectedValue, 0n), p = g * gt / ft;
|
|
2994
|
+
if (d > p)
|
|
2995
|
+
throw new ht(
|
|
2996
|
+
`Reclaim fee ${d} sats exceeds ${gt}/${ft} of the swept total (${g} sats, cap ${p} sats). The reserve is not at risk — it stays where it is until fee rates fall.`,
|
|
2997
|
+
d,
|
|
2974
2998
|
g
|
|
2975
2999
|
);
|
|
2976
3000
|
u == null || u.throwIfAborted();
|
|
2977
|
-
const { psbtHex: y } =
|
|
3001
|
+
const { psbtHex: y } = Yr({
|
|
2978
3002
|
depositorPubkey: c,
|
|
2979
|
-
inputs:
|
|
2980
|
-
feeSats:
|
|
3003
|
+
inputs: h,
|
|
3004
|
+
feeSats: d
|
|
2981
3005
|
});
|
|
2982
3006
|
u == null || u.throwIfAborted();
|
|
2983
|
-
const f =
|
|
3007
|
+
const f = ce(
|
|
2984
3008
|
o,
|
|
2985
|
-
|
|
3009
|
+
h.length
|
|
2986
3010
|
), m = await a(y, f);
|
|
2987
|
-
|
|
3011
|
+
ae({
|
|
2988
3012
|
requestedPsbtHex: y,
|
|
2989
3013
|
returnedPsbtHex: m
|
|
2990
3014
|
});
|
|
2991
|
-
const
|
|
2992
|
-
const T =
|
|
3015
|
+
const $ = h.map((v, E) => {
|
|
3016
|
+
const T = ue(
|
|
2993
3017
|
m,
|
|
2994
3018
|
c,
|
|
2995
3019
|
E
|
|
2996
3020
|
);
|
|
2997
|
-
return
|
|
3021
|
+
return oe({
|
|
2998
3022
|
requestedPsbtHex: y,
|
|
2999
3023
|
signatureHex: T,
|
|
3000
3024
|
signerXOnlyPubkeyHex: c,
|
|
3001
3025
|
inputIndex: E
|
|
3002
3026
|
}), T;
|
|
3003
|
-
}), x =
|
|
3027
|
+
}), x = Tt({
|
|
3004
3028
|
requestedPsbtHex: y,
|
|
3005
|
-
signaturesHex:
|
|
3029
|
+
signaturesHex: $,
|
|
3006
3030
|
signerXOnlyPubkeyHex: c
|
|
3007
3031
|
});
|
|
3008
3032
|
return u == null || u.throwIfAborted(), i(x);
|
|
3009
3033
|
}
|
|
3010
3034
|
export {
|
|
3011
|
-
|
|
3035
|
+
Sn as $,
|
|
3012
3036
|
K as A,
|
|
3013
|
-
|
|
3014
|
-
|
|
3037
|
+
fn as B,
|
|
3038
|
+
uo as C,
|
|
3015
3039
|
U as D,
|
|
3016
|
-
|
|
3017
|
-
|
|
3040
|
+
is as E,
|
|
3041
|
+
yn as F,
|
|
3018
3042
|
P as G,
|
|
3019
|
-
|
|
3020
|
-
|
|
3043
|
+
gs as H,
|
|
3044
|
+
vn as I,
|
|
3021
3045
|
Se as J,
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3046
|
+
mn as K,
|
|
3047
|
+
Pn as L,
|
|
3048
|
+
wn as M,
|
|
3049
|
+
xn as N,
|
|
3050
|
+
$n as O,
|
|
3051
|
+
lo as P,
|
|
3052
|
+
kn as Q,
|
|
3053
|
+
En as R,
|
|
3054
|
+
Y as S,
|
|
3055
|
+
Cs as T,
|
|
3056
|
+
Ts as U,
|
|
3057
|
+
fo as V,
|
|
3058
|
+
jt as W,
|
|
3059
|
+
Cn as X,
|
|
3060
|
+
Tn as Y,
|
|
3061
|
+
Wt as Z,
|
|
3062
|
+
_n as _,
|
|
3063
|
+
nn as a,
|
|
3040
3064
|
Xt as a0,
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3065
|
+
bn as a1,
|
|
3066
|
+
$e as a2,
|
|
3067
|
+
ks as a3,
|
|
3068
|
+
nt as a4,
|
|
3069
|
+
qo as a5,
|
|
3070
|
+
Uo as a6,
|
|
3071
|
+
Nt as a7,
|
|
3072
|
+
Bs as a8,
|
|
3073
|
+
Bn as a9,
|
|
3074
|
+
An as aa,
|
|
3075
|
+
dt as ab,
|
|
3076
|
+
lt as ac,
|
|
3077
|
+
ct as ad,
|
|
3078
|
+
Jt as ae,
|
|
3079
|
+
ht as af,
|
|
3080
|
+
Vn as ag,
|
|
3081
|
+
ft as ah,
|
|
3082
|
+
gt as ai,
|
|
3083
|
+
pt as aj,
|
|
3084
|
+
In as ak,
|
|
3085
|
+
an as b,
|
|
3086
|
+
un as c,
|
|
3087
|
+
ln as d,
|
|
3088
|
+
So as e,
|
|
3089
|
+
io as f,
|
|
3090
|
+
co as g,
|
|
3091
|
+
dn as h,
|
|
3092
|
+
ho as i,
|
|
3093
|
+
ne as j,
|
|
3094
|
+
go as k,
|
|
3095
|
+
bo as l,
|
|
3096
|
+
cn as m,
|
|
3097
|
+
Bo as n,
|
|
3098
|
+
Oo as o,
|
|
3099
|
+
Co as p,
|
|
3100
|
+
Vo as q,
|
|
3101
|
+
hn as r,
|
|
3102
|
+
wo as s,
|
|
3079
3103
|
St as t,
|
|
3080
|
-
|
|
3104
|
+
Go as u,
|
|
3081
3105
|
Dt as v,
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3106
|
+
Lt as w,
|
|
3107
|
+
Wo as x,
|
|
3108
|
+
pn as y,
|
|
3109
|
+
gn as z
|
|
3086
3110
|
};
|
|
3087
|
-
//# sourceMappingURL=buildAndBroadcastReclaim-
|
|
3111
|
+
//# sourceMappingURL=buildAndBroadcastReclaim-CQANDXVJ.js.map
|