@babylonlabs-io/ts-sdk 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{PayoutManager-CpfQjtL0.cjs → PayoutManager-B6GFbG3X.cjs} +2 -2
- package/dist/{PayoutManager-CpfQjtL0.cjs.map → PayoutManager-B6GFbG3X.cjs.map} +1 -1
- package/dist/{PayoutManager-CHTOwj0E.js → PayoutManager-BSwbUQeF.js} +2 -2
- package/dist/{PayoutManager-CHTOwj0E.js.map → PayoutManager-BSwbUQeF.js.map} +1 -1
- package/dist/{PeginManager-DEldv_Ro.js → PeginManager-CKf7Bjmj.js} +6 -6
- package/dist/{PeginManager-DEldv_Ro.js.map → PeginManager-CKf7Bjmj.js.map} +1 -1
- package/dist/{PeginManager-6tjlGd0t.cjs → PeginManager-Dt2Z5ljw.cjs} +2 -2
- package/dist/{PeginManager-6tjlGd0t.cjs.map → PeginManager-Dt2Z5ljw.cjs.map} +1 -1
- package/dist/{bip322Verify-DSco3Yhl.js → bip322Verify-BXYrHBh8.js} +2 -2
- package/dist/{bip322Verify-DSco3Yhl.js.map → bip322Verify-BXYrHBh8.js.map} +1 -1
- package/dist/{bip322Verify-B7_gIhRk.cjs → bip322Verify-DLxJR9CQ.cjs} +2 -2
- package/dist/{bip322Verify-B7_gIhRk.cjs.map → bip322Verify-DLxJR9CQ.cjs.map} +1 -1
- package/dist/{buildAndBroadcastReclaim-CqO2DoP8.js → buildAndBroadcastReclaim-B19cyK69.js} +952 -724
- package/dist/buildAndBroadcastReclaim-B19cyK69.js.map +1 -0
- package/dist/buildAndBroadcastReclaim-DcbsjJdf.cjs +2 -0
- package/dist/buildAndBroadcastReclaim-DcbsjJdf.cjs.map +1 -0
- package/dist/{deriveVaultRoot-BwbXmN0x.js → deriveVaultRoot-BcvmER1E.js} +2 -2
- package/dist/{deriveVaultRoot-BwbXmN0x.js.map → deriveVaultRoot-BcvmER1E.js.map} +1 -1
- package/dist/{deriveVaultRoot-DvhkHzNb.cjs → deriveVaultRoot-C3uqnJto.cjs} +2 -2
- package/dist/{deriveVaultRoot-DvhkHzNb.cjs.map → deriveVaultRoot-C3uqnJto.cjs.map} +1 -1
- package/dist/{index-DQ5bfoT3.js → index-Bnavi_r3.js} +115 -99
- package/dist/index-Bnavi_r3.js.map +1 -0
- package/dist/index-CcdCNFLM.cjs +2 -0
- package/dist/index-CcdCNFLM.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +159 -154
- package/dist/{json-rpc-client-DuUARJvV.js → json-rpc-client-CQLbpuKK.js} +31 -30
- package/dist/json-rpc-client-CQLbpuKK.js.map +1 -0
- package/dist/json-rpc-client-DbpFfa_o.cjs +2 -0
- package/dist/json-rpc-client-DbpFfa_o.cjs.map +1 -0
- package/dist/{onChainBtcPubkey-BXry_CM4.cjs → onChainBtcPubkey-BlzxYImF.cjs} +2 -2
- package/dist/{onChainBtcPubkey-BXry_CM4.cjs.map → onChainBtcPubkey-BlzxYImF.cjs.map} +1 -1
- package/dist/{onChainBtcPubkey-C1WqyxPM.js → onChainBtcPubkey-CCTdl53s.js} +2 -2
- package/dist/{onChainBtcPubkey-C1WqyxPM.js.map → onChainBtcPubkey-CCTdl53s.js.map} +1 -1
- package/dist/{pegin-registration-client-BNV44jzw.cjs → pegin-registration-client-BdJ6c7si.cjs} +2 -2
- package/dist/{pegin-registration-client-BNV44jzw.cjs.map → pegin-registration-client-BdJ6c7si.cjs.map} +1 -1
- package/dist/{pegin-registration-client-1sZ-74UC.js → pegin-registration-client-C5Hktrja.js} +3 -3
- package/dist/{pegin-registration-client-1sZ-74UC.js.map → pegin-registration-client-C5Hktrja.js.map} +1 -1
- package/dist/peginState-BU2ONFXF.js +68 -0
- package/dist/{peginState-CxDiaKuk.js.map → peginState-BU2ONFXF.js.map} +1 -1
- package/dist/peginState-DUv10EJR.cjs +2 -0
- package/dist/{peginState-eaQ4IO_R.cjs.map → peginState-DUv10EJR.cjs.map} +1 -1
- package/dist/{primeVpAuth-BOGKniTl.cjs → primeVpAuth-D21PXgg2.cjs} +2 -2
- package/dist/{primeVpAuth-BOGKniTl.cjs.map → primeVpAuth-D21PXgg2.cjs.map} +1 -1
- package/dist/{primeVpAuth-DdfHSC53.js → primeVpAuth-PiUJksAq.js} +5 -5
- package/dist/{primeVpAuth-DdfHSC53.js.map → primeVpAuth-PiUJksAq.js.map} +1 -1
- package/dist/{reservation-Cj9F0rP9.js → reservation-DOAHVT3B.js} +2 -2
- package/dist/{reservation-Cj9F0rP9.js.map → reservation-DOAHVT3B.js.map} +1 -1
- package/dist/{reservation-Dr2HLCxx.cjs → reservation-ECxjZi5t.cjs} +2 -2
- package/dist/{reservation-Dr2HLCxx.cjs.map → reservation-ECxjZi5t.cjs.map} +1 -1
- package/dist/sha2-Ce6KewYx.cjs +2 -0
- package/dist/{sha2-DI0-0SHr.cjs.map → sha2-Ce6KewYx.cjs.map} +1 -1
- package/dist/{sha2-CLpQd0Rd.js → sha2-YqVHJiFj.js} +91 -77
- package/dist/{sha2-CLpQd0Rd.js.map → sha2-YqVHJiFj.js.map} +1 -1
- package/dist/tbv/core/clients/eth/index.cjs +1 -1
- package/dist/tbv/core/clients/eth/index.js +3 -3
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +27 -26
- package/dist/tbv/core/clients/vault-provider/index.d.ts +1 -1
- package/dist/tbv/core/clients/vault-provider/index.d.ts.map +1 -1
- package/dist/tbv/core/clients/vault-provider/status/index.cjs +1 -1
- package/dist/tbv/core/clients/vault-provider/status/index.d.ts +1 -1
- package/dist/tbv/core/clients/vault-provider/status/index.d.ts.map +1 -1
- package/dist/tbv/core/clients/vault-provider/status/index.js +10 -9
- package/dist/tbv/core/clients/vault-provider/types.d.ts +7 -3
- package/dist/tbv/core/clients/vault-provider/types.d.ts.map +1 -1
- package/dist/tbv/core/clients/vault-provider/validators.d.ts +8 -0
- package/dist/tbv/core/clients/vault-provider/validators.d.ts.map +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +158 -153
- package/dist/tbv/core/managers/index.cjs +1 -1
- package/dist/tbv/core/managers/index.js +2 -2
- package/dist/tbv/core/services/deposit/__tests__/graphFingerprint.test.d.ts +2 -0
- package/dist/tbv/core/services/deposit/__tests__/graphFingerprint.test.d.ts.map +1 -0
- package/dist/tbv/core/services/deposit/graphFingerprint.d.ts +115 -0
- package/dist/tbv/core/services/deposit/graphFingerprint.d.ts.map +1 -0
- package/dist/tbv/core/services/deposit/index.d.ts +2 -1
- package/dist/tbv/core/services/deposit/index.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/peginState.d.ts +23 -0
- package/dist/tbv/core/services/deposit/peginState.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts +11 -0
- package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts.map +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +66 -62
- package/dist/tbv/core/utils/index.cjs +1 -1
- package/dist/tbv/core/utils/index.js +1 -1
- package/dist/tbv/core/vault-secrets/index.cjs +1 -1
- package/dist/tbv/core/vault-secrets/index.js +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +158 -153
- package/dist/testing/index.cjs +1 -1
- package/dist/testing/index.js +1 -1
- package/dist/{toRefundInputs-BaN9XluU.cjs → toRefundInputs-B_GlIXjk.cjs} +2 -2
- package/dist/{toRefundInputs-BaN9XluU.cjs.map → toRefundInputs-B_GlIXjk.cjs.map} +1 -1
- package/dist/{toRefundInputs-mtuuYezp.js → toRefundInputs-DIIdhjvu.js} +5 -5
- package/dist/{toRefundInputs-mtuuYezp.js.map → toRefundInputs-DIIdhjvu.js.map} +1 -1
- package/dist/{types-BuxreSq4.cjs → types-DJxOEU3P.cjs} +2 -2
- package/dist/{types-BuxreSq4.cjs.map → types-DJxOEU3P.cjs.map} +1 -1
- package/dist/{types-BdCEoANP.js → types-Dz1kVqn6.js} +2 -2
- package/dist/{types-BdCEoANP.js.map → types-Dz1kVqn6.js.map} +1 -1
- package/package.json +1 -1
- package/dist/buildAndBroadcastReclaim-BwT6Jxp5.cjs +0 -2
- package/dist/buildAndBroadcastReclaim-BwT6Jxp5.cjs.map +0 -1
- package/dist/buildAndBroadcastReclaim-CqO2DoP8.js.map +0 -1
- package/dist/index-CK1Xvq4K.cjs +0 -2
- package/dist/index-CK1Xvq4K.cjs.map +0 -1
- package/dist/index-DQ5bfoT3.js.map +0 -1
- package/dist/json-rpc-client-BiAmg_ho.cjs +0 -2
- package/dist/json-rpc-client-BiAmg_ho.cjs.map +0 -1
- package/dist/json-rpc-client-DuUARJvV.js.map +0 -1
- package/dist/peginState-CxDiaKuk.js +0 -63
- package/dist/peginState-eaQ4IO_R.cjs +0 -2
- package/dist/sha2-DI0-0SHr.cjs +0 -2
|
@@ -1,80 +1,81 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { B as
|
|
5
|
-
import { e as
|
|
6
|
-
import { v as
|
|
7
|
-
import { Buffer as
|
|
8
|
-
import { b as
|
|
9
|
-
import { buildClaimPsbt as
|
|
10
|
-
import { p as
|
|
11
|
-
import { Psbt as
|
|
12
|
-
import { m as
|
|
13
|
-
import { d as
|
|
14
|
-
import { d as
|
|
15
|
-
import { zeroAddress as
|
|
16
|
-
import { D as
|
|
17
|
-
import {
|
|
18
|
-
import { a as
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
var it = Object.defineProperty;
|
|
2
|
+
var ut = (e, t, r) => t in e ? it(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var O = (e, t, r) => ut(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { B as Ne } from "./BTCVaultRegistry.abi-B0x9_Bza.js";
|
|
5
|
+
import { e as He, s as f, i as ct, c as $, v as lt, u as Ke, p as j, f as V } from "./bitcoin-C-TuHb-v.js";
|
|
6
|
+
import { v as ht, d as De, s as pt, P as dt, a as gt } from "./PayoutManager-BSwbUQeF.js";
|
|
7
|
+
import { Buffer as I } from "buffer";
|
|
8
|
+
import { b as ft, a as M, c as yt } from "./signing-Dhr2t0Z6.js";
|
|
9
|
+
import { buildClaimPsbt as bt, buildAssertClaimerPsbt as mt, buildPayoutClaimerPsbt as Pt, buildWronglyChallengedPsbts as vt, buildPayoutDepositorPsbt as wt, finalizeClaimTx as xt, buildWatchtowerArtifacts as Et, extractTapScriptSig as kt, expandWotsSeed as _t, wotsKeypairFromSeed as Tt, validateWotsKeypairAgainstGraph as $t, verifyWatchtowerArtifacts as At, deriveVaultId as Ct } from "./tbv/core/wasm/index.js";
|
|
10
|
+
import { p as Me, P as le, f as St, i as F, g as U, j as L } from "./verifyScriptPathSchnorrSignature-CpjSTfMj.js";
|
|
11
|
+
import { Psbt as Fe, Transaction as B } from "bitcoinjs-lib";
|
|
12
|
+
import { m as he, n as pe, N as q, o as de, D as ge } from "./constants-D5vORbQE.js";
|
|
13
|
+
import { d as It } from "./deriveVaultRoot-BcvmER1E.js";
|
|
14
|
+
import { d as Rt, a as fe } from "./onChainBtcPubkey-CCTdl53s.js";
|
|
15
|
+
import { zeroAddress as Bt, isAddress as Vt, isAddressEqual as Ot } from "viem";
|
|
16
|
+
import { D as R, c as Nt, b as Ht, R as Kt, d as Ue } from "./json-rpc-client-CQLbpuKK.js";
|
|
17
|
+
import { h as ye, b as Dt, s as Mt, j as Ft } from "./sha2-YqVHJiFj.js";
|
|
18
|
+
import { d as Ut, c as Lt, b as Gt, f as Le, e as Xt, a as jt } from "./noPayout-qBXWKwav.js";
|
|
19
|
+
import { a as qt } from "./secp256k1-D-H9jmd7.js";
|
|
20
|
+
const zt = /^0x[0-9a-fA-F]{64}$/, Wt = /^0x[0-9a-fA-F]{40}$/, Yt = /^0x([0-9a-fA-F]{2})*$/;
|
|
21
|
+
function z(e, t) {
|
|
21
22
|
if (e.length !== 66)
|
|
22
23
|
throw new Error(
|
|
23
24
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
24
25
|
);
|
|
25
|
-
if (!
|
|
26
|
+
if (!zt.test(e))
|
|
26
27
|
throw new Error(
|
|
27
28
|
`${t} must contain only hex characters after the 0x prefix`
|
|
28
29
|
);
|
|
29
30
|
}
|
|
30
|
-
function
|
|
31
|
-
if (
|
|
31
|
+
function Qt(e, t) {
|
|
32
|
+
if (!Wt.test(e))
|
|
32
33
|
throw new Error(
|
|
33
34
|
`${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
|
|
34
35
|
);
|
|
35
36
|
}
|
|
36
|
-
function
|
|
37
|
-
if (!
|
|
37
|
+
function Jt(e, t) {
|
|
38
|
+
if (!Yt.test(e))
|
|
38
39
|
throw new Error(
|
|
39
40
|
`${t} must be a 0x-prefixed hex string with an even number of hex chars`
|
|
40
41
|
);
|
|
41
42
|
}
|
|
42
|
-
function
|
|
43
|
-
|
|
44
|
-
const t =
|
|
45
|
-
if (
|
|
43
|
+
function Ge(e) {
|
|
44
|
+
Qt(e.btcVaultRegistryAddress, "btcVaultRegistryAddress"), z(e.vaultId, "vaultId");
|
|
45
|
+
const t = He(e.secret);
|
|
46
|
+
if (z(t, "secret"), e.hashlock !== void 0 && (z(e.hashlock, "hashlock"), !ht(t, e.hashlock)))
|
|
46
47
|
throw new Error(
|
|
47
48
|
"Invalid secret: SHA256(secret) does not match the provided hashlock"
|
|
48
49
|
);
|
|
49
50
|
return t;
|
|
50
51
|
}
|
|
51
|
-
async function
|
|
52
|
+
async function Oo(e) {
|
|
52
53
|
const {
|
|
53
54
|
btcVaultRegistryAddress: t,
|
|
54
55
|
vaultId: r,
|
|
55
56
|
hashlock: o,
|
|
56
57
|
activationMetadata: n,
|
|
57
|
-
writeContract:
|
|
58
|
+
writeContract: a,
|
|
58
59
|
signal: s
|
|
59
60
|
} = e;
|
|
60
61
|
s == null || s.throwIfAborted();
|
|
61
|
-
const i =
|
|
62
|
+
const i = Ge({
|
|
62
63
|
btcVaultRegistryAddress: t,
|
|
63
64
|
vaultId: r,
|
|
64
65
|
secret: e.secret,
|
|
65
66
|
hashlock: o
|
|
66
67
|
});
|
|
67
|
-
return
|
|
68
|
+
return Jt(n, "activationMetadata"), a({
|
|
68
69
|
address: t,
|
|
69
|
-
abi:
|
|
70
|
+
abi: Ne,
|
|
70
71
|
functionName: "activateVaultWithSecret",
|
|
71
72
|
args: [r, i, n]
|
|
72
73
|
});
|
|
73
74
|
}
|
|
74
|
-
async function
|
|
75
|
-
const { btcVaultRegistryAddress: t, vaultId: r, hashlock: o, writeContract: n, signal:
|
|
76
|
-
|
|
77
|
-
const s =
|
|
75
|
+
async function No(e) {
|
|
76
|
+
const { btcVaultRegistryAddress: t, vaultId: r, hashlock: o, writeContract: n, signal: a } = e;
|
|
77
|
+
a == null || a.throwIfAborted();
|
|
78
|
+
const s = Ge({
|
|
78
79
|
btcVaultRegistryAddress: t,
|
|
79
80
|
vaultId: r,
|
|
80
81
|
secret: e.secret,
|
|
@@ -82,200 +83,200 @@ async function io(e) {
|
|
|
82
83
|
});
|
|
83
84
|
return n({
|
|
84
85
|
address: t,
|
|
85
|
-
abi:
|
|
86
|
+
abi: Ne,
|
|
86
87
|
functionName: "activateVaultWithSecretAndRedeem",
|
|
87
88
|
args: [r, s]
|
|
88
89
|
});
|
|
89
90
|
}
|
|
90
|
-
class
|
|
91
|
+
class Zt extends Error {
|
|
91
92
|
constructor(t, r) {
|
|
92
93
|
super(
|
|
93
94
|
"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."
|
|
94
95
|
), this.missing = t, this.unexpected = r, this.name = "ChallengerSetMismatchError";
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
|
-
function
|
|
98
|
-
const t =
|
|
98
|
+
function er(e) {
|
|
99
|
+
const t = Me({
|
|
99
100
|
claimerBtcPubkey: e.depositorBtcPubkey,
|
|
100
101
|
depositorBtcPubkey: e.depositorBtcPubkey,
|
|
101
102
|
vaultProviderBtcPubkey: e.vaultProviderBtcPubkey,
|
|
102
103
|
vaultKeeperBtcPubkeys: e.vaultKeeperBtcPubkeys
|
|
103
|
-
}), r = e.universalChallengerBtcPubkeys.map(
|
|
104
|
+
}), r = e.universalChallengerBtcPubkeys.map(be), o = t.filter((h) => r.includes(h));
|
|
104
105
|
if (o.length > 0)
|
|
105
106
|
throw new Error(
|
|
106
107
|
`Cannot check the challenger set: vault keepers and universal challengers overlap (${o.join(", ")}).`
|
|
107
108
|
);
|
|
108
|
-
const n = e.graphChallengerPubkeys.map(
|
|
109
|
-
if (
|
|
109
|
+
const n = e.graphChallengerPubkeys.map(be), a = new Set(n);
|
|
110
|
+
if (a.size !== n.length)
|
|
110
111
|
throw new Error(
|
|
111
112
|
"Transaction graph lists the same challenger more than once."
|
|
112
113
|
);
|
|
113
|
-
const s = [...t, ...r], i = new Set(s),
|
|
114
|
-
if (
|
|
115
|
-
throw new
|
|
114
|
+
const s = [...t, ...r], i = new Set(s), u = s.filter((h) => !a.has(h)), c = n.filter((h) => !i.has(h));
|
|
115
|
+
if (u.length > 0 || c.length > 0)
|
|
116
|
+
throw new Zt(u, c);
|
|
116
117
|
}
|
|
117
|
-
function
|
|
118
|
-
return
|
|
118
|
+
function be(e) {
|
|
119
|
+
return f(e).toLowerCase();
|
|
119
120
|
}
|
|
120
|
-
const
|
|
121
|
-
class
|
|
121
|
+
const Xe = 0;
|
|
122
|
+
class tr extends Error {
|
|
122
123
|
constructor(t, r) {
|
|
123
124
|
super(
|
|
124
|
-
`Payout transaction output ${
|
|
125
|
+
`Payout transaction output ${Xe} pays ${r}, not the vault's registered payout script ${t}. Refusing to sign a payout to another destination.`
|
|
125
126
|
), this.expectedScriptHex = t, this.actualScriptHex = r, this.name = "PayoutDestinationError";
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
|
-
function
|
|
129
|
+
function rr(e) {
|
|
129
130
|
let t;
|
|
130
131
|
try {
|
|
131
|
-
t =
|
|
132
|
-
} catch (
|
|
133
|
-
throw new Error("Payout PSBT cannot be parsed.", { cause:
|
|
132
|
+
t = Fe.fromBase64(e.payoutPsbtBase64);
|
|
133
|
+
} catch (u) {
|
|
134
|
+
throw new Error("Payout PSBT cannot be parsed.", { cause: u });
|
|
134
135
|
}
|
|
135
|
-
const { version: r, locktime: o, outs: n } =
|
|
136
|
-
if (r !==
|
|
136
|
+
const { version: r, locktime: o, outs: n } = or(t);
|
|
137
|
+
if (r !== he || o !== pe)
|
|
137
138
|
throw new Error(
|
|
138
|
-
`Payout transaction has version ${r} and locktime ${o}, expected ${
|
|
139
|
+
`Payout transaction has version ${r} and locktime ${o}, expected ${he} and ${pe}.`
|
|
139
140
|
);
|
|
140
|
-
if (n.length !==
|
|
141
|
+
if (n.length !== q)
|
|
141
142
|
throw new Error(
|
|
142
|
-
`Payout transaction has ${n.length} output(s), expected exactly ${
|
|
143
|
+
`Payout transaction has ${n.length} output(s), expected exactly ${q} for a depositor-as-claimer payout.`
|
|
143
144
|
);
|
|
144
|
-
const
|
|
145
|
+
const a = f(
|
|
145
146
|
e.registeredPayoutScriptPubKey
|
|
146
147
|
).toLowerCase();
|
|
147
|
-
if (
|
|
148
|
+
if (a.length === 0)
|
|
148
149
|
throw new Error(
|
|
149
150
|
"registeredPayoutScriptPubKey is empty; the vault's on-chain payout script is required to check the Payout destination."
|
|
150
151
|
);
|
|
151
|
-
const s = n[
|
|
152
|
-
if (
|
|
153
|
-
throw new
|
|
154
|
-
const i = n[
|
|
155
|
-
if (i.value !==
|
|
152
|
+
const s = n[Xe].script.toString("hex").toLowerCase();
|
|
153
|
+
if (!I.from(s, "hex").equals(I.from(a, "hex")))
|
|
154
|
+
throw new tr(a, s);
|
|
155
|
+
const i = n[q - 1];
|
|
156
|
+
if (i.value !== de)
|
|
156
157
|
throw new Error(
|
|
157
|
-
`Payout CPFP anchor value ${i.value} sats must equal ${
|
|
158
|
+
`Payout CPFP anchor value ${i.value} sats must equal ${de} sats.`
|
|
158
159
|
);
|
|
159
160
|
}
|
|
160
|
-
function
|
|
161
|
+
function or(e) {
|
|
161
162
|
return {
|
|
162
163
|
version: e.version,
|
|
163
164
|
locktime: e.locktime,
|
|
164
165
|
outs: e.txOutputs.map((t) => ({
|
|
165
|
-
script:
|
|
166
|
+
script: I.from(t.script),
|
|
166
167
|
value: t.value
|
|
167
168
|
}))
|
|
168
169
|
};
|
|
169
170
|
}
|
|
170
|
-
const
|
|
171
|
-
class
|
|
171
|
+
const je = 0;
|
|
172
|
+
class nr extends Error {
|
|
172
173
|
constructor(t, r, o) {
|
|
173
174
|
super(
|
|
174
175
|
`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.`
|
|
175
176
|
), this.expectedVaultId = t, this.derivedVaultId = r, this.peginTxid = o, this.name = "VaultIdBindingError";
|
|
176
177
|
}
|
|
177
178
|
}
|
|
178
|
-
function
|
|
179
|
+
function sr(e) {
|
|
179
180
|
let t;
|
|
180
181
|
try {
|
|
181
|
-
t =
|
|
182
|
+
t = Fe.fromBase64(e);
|
|
182
183
|
} catch (o) {
|
|
183
184
|
throw new Error("Claim PSBT cannot be parsed.", { cause: o });
|
|
184
185
|
}
|
|
185
|
-
const r = t.txInputs[
|
|
186
|
+
const r = t.txInputs[je];
|
|
186
187
|
if (!r)
|
|
187
188
|
throw new Error("Claim PSBT carries no PegIn input to bind the vault to.");
|
|
188
|
-
return
|
|
189
|
+
return ze(r.hash);
|
|
189
190
|
}
|
|
190
|
-
function
|
|
191
|
-
const t = e.ins[
|
|
191
|
+
function ar(e) {
|
|
192
|
+
const t = e.ins[je];
|
|
192
193
|
if (!t)
|
|
193
194
|
throw new Error(
|
|
194
195
|
"Artifacts file's claim_tx carries no PegIn input to bind the vault to."
|
|
195
196
|
);
|
|
196
|
-
return
|
|
197
|
+
return ze(t.hash);
|
|
197
198
|
}
|
|
198
|
-
function
|
|
199
|
-
const t =
|
|
200
|
-
|
|
201
|
-
), r =
|
|
199
|
+
function qe(e) {
|
|
200
|
+
const t = G(
|
|
201
|
+
Rt(e.peginTxid, e.depositorEthAddress)
|
|
202
|
+
), r = G(e.expectedVaultId);
|
|
202
203
|
if (t !== r)
|
|
203
|
-
throw new
|
|
204
|
+
throw new nr(r, t, e.peginTxid);
|
|
204
205
|
}
|
|
205
|
-
function
|
|
206
|
+
function G(e) {
|
|
206
207
|
return `0x${(e.startsWith("0x") ? e.slice(2) : e).toLowerCase()}`;
|
|
207
208
|
}
|
|
208
|
-
function
|
|
209
|
-
return
|
|
209
|
+
function ze(e) {
|
|
210
|
+
return I.from(e).reverse().toString("hex");
|
|
210
211
|
}
|
|
211
|
-
const
|
|
212
|
-
async function
|
|
213
|
-
const { txGraphVersion: t } = e.vault, r = e.source.txGraphJson, [o, n,
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
212
|
+
const ir = 0, ur = 0, cr = 1, lr = 0, hr = 0;
|
|
213
|
+
async function Ho(e) {
|
|
214
|
+
const { txGraphVersion: t } = e.vault, r = e.source.txGraphJson, [o, n, a, s] = await Promise.all([
|
|
215
|
+
bt(t, r),
|
|
216
|
+
mt(t, r),
|
|
217
|
+
Pt(t, r),
|
|
218
|
+
vt(t, r)
|
|
218
219
|
]);
|
|
219
|
-
|
|
220
|
-
peginTxid:
|
|
220
|
+
qe({
|
|
221
|
+
peginTxid: sr(o),
|
|
221
222
|
depositorEthAddress: e.vault.depositorEthAddress,
|
|
222
223
|
expectedVaultId: e.vault.vaultId
|
|
223
224
|
});
|
|
224
|
-
const i = await
|
|
225
|
+
const i = await wt(
|
|
225
226
|
t,
|
|
226
227
|
r
|
|
227
228
|
);
|
|
228
|
-
for (const
|
|
229
|
-
|
|
230
|
-
payoutPsbtBase64:
|
|
229
|
+
for (const x of [a, i])
|
|
230
|
+
rr({
|
|
231
|
+
payoutPsbtBase64: x,
|
|
231
232
|
registeredPayoutScriptPubKey: e.vault.registeredPayoutScriptPubKey
|
|
232
233
|
});
|
|
233
|
-
|
|
234
|
+
er({
|
|
234
235
|
graphChallengerPubkeys: Object.keys(s),
|
|
235
236
|
depositorBtcPubkey: e.depositorPublicKey,
|
|
236
237
|
vaultProviderBtcPubkey: e.vault.vaultProviderBtcPubkey,
|
|
237
238
|
vaultKeeperBtcPubkeys: e.vault.vaultKeeperBtcPubkeys,
|
|
238
239
|
universalChallengerBtcPubkeys: e.vault.universalChallengerBtcPubkeys
|
|
239
240
|
});
|
|
240
|
-
const
|
|
241
|
-
{ psbtBase64: o, inputIndex:
|
|
242
|
-
{ psbtBase64: n, inputIndex:
|
|
243
|
-
{ psbtBase64:
|
|
241
|
+
const u = [
|
|
242
|
+
{ psbtBase64: o, inputIndex: ir },
|
|
243
|
+
{ psbtBase64: n, inputIndex: ur },
|
|
244
|
+
{ psbtBase64: a, inputIndex: cr },
|
|
244
245
|
{
|
|
245
246
|
psbtBase64: i,
|
|
246
|
-
inputIndex:
|
|
247
|
+
inputIndex: lr
|
|
247
248
|
}
|
|
248
249
|
], c = Object.keys(s);
|
|
249
|
-
for (const
|
|
250
|
-
for (const w of s[
|
|
251
|
-
|
|
252
|
-
const h = await
|
|
250
|
+
for (const x of c)
|
|
251
|
+
for (const w of s[x])
|
|
252
|
+
u.push({ psbtBase64: w, inputIndex: hr });
|
|
253
|
+
const h = await dr(
|
|
253
254
|
e.btcWallet,
|
|
254
255
|
e.depositorPublicKey,
|
|
255
256
|
e.btcNetwork,
|
|
256
|
-
|
|
257
|
+
u
|
|
257
258
|
);
|
|
258
259
|
let l = 0;
|
|
259
|
-
const
|
|
260
|
-
for (const
|
|
261
|
-
const w = s[
|
|
262
|
-
|
|
260
|
+
const p = h[l++], d = h[l++], g = h[l++], b = h[l++], y = {};
|
|
261
|
+
for (const x of c) {
|
|
262
|
+
const w = s[x].length;
|
|
263
|
+
y[x] = h.slice(
|
|
263
264
|
l,
|
|
264
265
|
l + w
|
|
265
266
|
), l += w;
|
|
266
267
|
}
|
|
267
|
-
const
|
|
268
|
+
const m = await xt(
|
|
268
269
|
t,
|
|
269
270
|
r,
|
|
270
|
-
|
|
271
|
+
p
|
|
271
272
|
);
|
|
272
|
-
return
|
|
273
|
+
return Et({
|
|
273
274
|
txGraphVersion: t,
|
|
274
275
|
graphJson: r,
|
|
275
|
-
signedClaimTxHex:
|
|
276
|
-
assertClaimerSigHex:
|
|
276
|
+
signedClaimTxHex: m,
|
|
277
|
+
assertClaimerSigHex: d,
|
|
277
278
|
payoutClaimerSigHex: g,
|
|
278
|
-
wronglyChallengedSigs:
|
|
279
|
+
wronglyChallengedSigs: y,
|
|
279
280
|
depositorPayoutSigHex: b,
|
|
280
281
|
verifyingKeyHex: e.source.verifyingKeyHex,
|
|
281
282
|
claimableEventBlockNumber: e.vault.claimableEventBlockNumber,
|
|
@@ -285,7 +286,7 @@ async function uo(e) {
|
|
|
285
286
|
expectedVaultCoreVersion: e.vault.vaultCoreVersion
|
|
286
287
|
});
|
|
287
288
|
}
|
|
288
|
-
function
|
|
289
|
+
function me(e) {
|
|
289
290
|
const t = e.replace(/^0x/, "").toLowerCase();
|
|
290
291
|
if (t.length === 66) return t.slice(2);
|
|
291
292
|
if (t.length === 64) return t;
|
|
@@ -293,29 +294,29 @@ function ie(e) {
|
|
|
293
294
|
`Public key must be 33-byte compressed or 32-byte x-only hex, got ${t.length / 2} bytes.`
|
|
294
295
|
);
|
|
295
296
|
}
|
|
296
|
-
async function
|
|
297
|
+
async function pr(e, t, r) {
|
|
297
298
|
const o = await e.getPublicKeyHex();
|
|
298
|
-
if (
|
|
299
|
+
if (me(o) !== me(t))
|
|
299
300
|
throw new Error(
|
|
300
301
|
"Connected wallet does not hold the vault's depositor key. Select the account that made the deposit, then try again."
|
|
301
302
|
);
|
|
302
303
|
const n = await e.getAddress();
|
|
303
|
-
if (!
|
|
304
|
+
if (!ct(n, t, r))
|
|
304
305
|
throw new Error(
|
|
305
306
|
`Connected wallet reports address "${n}", which is not derived from the vault's depositor key. Select the account that made the deposit, then try again.`
|
|
306
307
|
);
|
|
307
308
|
return n;
|
|
308
309
|
}
|
|
309
|
-
async function
|
|
310
|
-
const n = await
|
|
310
|
+
async function dr(e, t, r, o) {
|
|
311
|
+
const n = await pr(
|
|
311
312
|
e,
|
|
312
313
|
t,
|
|
313
314
|
r
|
|
314
|
-
),
|
|
315
|
+
), a = await De(
|
|
315
316
|
e,
|
|
316
|
-
o.map((s) =>
|
|
317
|
+
o.map((s) => gr(s.psbtBase64)),
|
|
317
318
|
o.map(
|
|
318
|
-
(s) =>
|
|
319
|
+
(s) => ft(
|
|
319
320
|
t,
|
|
320
321
|
s.inputIndex,
|
|
321
322
|
n
|
|
@@ -323,32 +324,32 @@ async function Wt(e, t, r, o) {
|
|
|
323
324
|
)
|
|
324
325
|
);
|
|
325
326
|
return Promise.all(
|
|
326
|
-
|
|
327
|
-
(s, i) =>
|
|
327
|
+
a.map(
|
|
328
|
+
(s, i) => kt(fr(s), o[i].inputIndex)
|
|
328
329
|
)
|
|
329
330
|
);
|
|
330
331
|
}
|
|
331
|
-
function
|
|
332
|
-
return
|
|
332
|
+
function gr(e) {
|
|
333
|
+
return I.from(e, "base64").toString("hex");
|
|
333
334
|
}
|
|
334
|
-
function
|
|
335
|
-
return
|
|
335
|
+
function fr(e) {
|
|
336
|
+
return I.from(e, "hex").toString("base64");
|
|
336
337
|
}
|
|
337
|
-
async function
|
|
338
|
-
const t = await
|
|
338
|
+
async function Ko(e) {
|
|
339
|
+
const t = await It(e.btcWallet, e.vaultContext);
|
|
339
340
|
let r;
|
|
340
341
|
try {
|
|
341
|
-
r = await
|
|
342
|
+
r = await _t(t, e.htlcVout);
|
|
342
343
|
} finally {
|
|
343
344
|
t.fill(0);
|
|
344
345
|
}
|
|
345
346
|
let o;
|
|
346
347
|
try {
|
|
347
|
-
o = await
|
|
348
|
+
o = await Tt(r);
|
|
348
349
|
} finally {
|
|
349
350
|
r.fill(0);
|
|
350
351
|
}
|
|
351
|
-
return
|
|
352
|
+
return yr(o.pk_hash, e.expectedWotsPkHash), await $t(
|
|
352
353
|
e.txGraphVersion,
|
|
353
354
|
o.keypair,
|
|
354
355
|
e.txGraphJson
|
|
@@ -357,61 +358,61 @@ async function co(e) {
|
|
|
357
358
|
pkHash: o.pk_hash
|
|
358
359
|
};
|
|
359
360
|
}
|
|
360
|
-
function
|
|
361
|
-
if (
|
|
361
|
+
function yr(e, t) {
|
|
362
|
+
if (D(e) !== D(t))
|
|
362
363
|
throw new Error(
|
|
363
|
-
`Derived WOTS public-key hash ${
|
|
364
|
+
`Derived WOTS public-key hash ${D(e)} does not match the vault's on-chain depositorWotsPkHash ${D(t)}. The wallet, the HTLC output index, or the derivation itself is not the one this vault was created with.`
|
|
364
365
|
);
|
|
365
366
|
}
|
|
366
|
-
function
|
|
367
|
+
function D(e) {
|
|
367
368
|
return `0x${(e.startsWith("0x") ? e.slice(2) : e).toLowerCase()}`;
|
|
368
369
|
}
|
|
369
|
-
const
|
|
370
|
-
class
|
|
370
|
+
const br = 3;
|
|
371
|
+
class mr extends Error {
|
|
371
372
|
constructor(t, r) {
|
|
372
373
|
super(
|
|
373
374
|
`Artifacts belong to vault ${r}, not ${t}. Select the artifacts file saved for this vault.`
|
|
374
375
|
), this.expectedVaultId = t, this.actualVaultId = r, this.name = "ArtifactsVaultMismatchError";
|
|
375
376
|
}
|
|
376
377
|
}
|
|
377
|
-
function
|
|
378
|
+
function Pr(e) {
|
|
378
379
|
let t;
|
|
379
380
|
try {
|
|
380
381
|
t = JSON.parse(e);
|
|
381
382
|
} catch (s) {
|
|
382
383
|
throw new Error("Artifacts file is not valid JSON.", { cause: s });
|
|
383
384
|
}
|
|
384
|
-
const r =
|
|
385
|
+
const r = Pe(t.vault_id, "vault_id"), o = vr(Pe(t.claim_tx, "claim_tx")), n = W(
|
|
385
386
|
t.prover_circuit_version,
|
|
386
387
|
"prover_circuit_version"
|
|
387
|
-
),
|
|
388
|
-
|
|
388
|
+
), a = t.claimable_event_block_number === void 0 ? 0n : BigInt(
|
|
389
|
+
W(
|
|
389
390
|
t.claimable_event_block_number,
|
|
390
391
|
"claimable_event_block_number"
|
|
391
392
|
)
|
|
392
393
|
);
|
|
393
394
|
return {
|
|
394
|
-
vaultCoreVersion: t.vault_core_version === void 0 ? void 0 :
|
|
395
|
+
vaultCoreVersion: t.vault_core_version === void 0 ? void 0 : W(t.vault_core_version, "vault_core_version"),
|
|
395
396
|
vaultId: r,
|
|
396
397
|
claimTxid: o.getId(),
|
|
397
|
-
peginTxid:
|
|
398
|
+
peginTxid: ar(o),
|
|
398
399
|
proverCircuitVersion: n,
|
|
399
|
-
claimableEventBlockNumber:
|
|
400
|
+
claimableEventBlockNumber: a,
|
|
400
401
|
babeSessionChallengerPubkeys: Object.keys(
|
|
401
|
-
|
|
402
|
+
wr(t.babe_sessions, "babe_sessions")
|
|
402
403
|
)
|
|
403
404
|
};
|
|
404
405
|
}
|
|
405
|
-
async function
|
|
406
|
-
const t =
|
|
406
|
+
async function Do(e) {
|
|
407
|
+
const t = Pr(e.artifactsJson), r = G(e.expectedVaultId), o = G(t.vaultId);
|
|
407
408
|
if (r !== o)
|
|
408
|
-
throw new
|
|
409
|
-
|
|
409
|
+
throw new mr(r, o);
|
|
410
|
+
qe({
|
|
410
411
|
peginTxid: t.peginTxid,
|
|
411
412
|
depositorEthAddress: e.depositorEthAddress,
|
|
412
413
|
expectedVaultId: r
|
|
413
414
|
});
|
|
414
|
-
const n = e.txGraphVersion ??
|
|
415
|
+
const n = e.txGraphVersion ?? br;
|
|
415
416
|
if (t.vaultCoreVersion !== void 0 && t.vaultCoreVersion !== n)
|
|
416
417
|
throw new Error(
|
|
417
418
|
`Artifacts record vault core version ${t.vaultCoreVersion}, but verification was asked for version ${n}.`
|
|
@@ -420,9 +421,9 @@ async function lo(e) {
|
|
|
420
421
|
throw new Error(
|
|
421
422
|
"Artifacts carry no claimable event block number. They were assembled before the Ethereum withdrawal was initiated; assemble them again."
|
|
422
423
|
);
|
|
423
|
-
return await
|
|
424
|
+
return await At(n, e.artifactsJson), t;
|
|
424
425
|
}
|
|
425
|
-
function
|
|
426
|
+
function vr(e) {
|
|
426
427
|
try {
|
|
427
428
|
return B.fromHex(e);
|
|
428
429
|
} catch (t) {
|
|
@@ -431,171 +432,387 @@ function rr(e) {
|
|
|
431
432
|
});
|
|
432
433
|
}
|
|
433
434
|
}
|
|
434
|
-
function
|
|
435
|
+
function Pe(e, t) {
|
|
435
436
|
if (typeof e != "string" || e.length === 0)
|
|
436
437
|
throw new Error(`Artifacts file is missing a usable "${t}".`);
|
|
437
438
|
return e;
|
|
438
439
|
}
|
|
439
|
-
function
|
|
440
|
+
function W(e, t) {
|
|
440
441
|
if (typeof e != "number" || !Number.isSafeInteger(e) || e < 0)
|
|
441
442
|
throw new Error(`Artifacts file is missing a usable "${t}".`);
|
|
442
443
|
return e;
|
|
443
444
|
}
|
|
444
|
-
function
|
|
445
|
+
function wr(e, t) {
|
|
445
446
|
if (e === void 0) return {};
|
|
446
447
|
if (typeof e != "object" || e === null || Array.isArray(e))
|
|
447
448
|
throw new Error(`Artifacts file is missing a usable "${t}".`);
|
|
448
449
|
return e;
|
|
449
450
|
}
|
|
450
|
-
const
|
|
451
|
-
class
|
|
451
|
+
const xr = 8, Er = 6e3, kr = 10 * 6e4, _r = 10;
|
|
452
|
+
class We extends Error {
|
|
452
453
|
constructor(t) {
|
|
453
454
|
super(t), this.name = "PeginRegistrationMissingError";
|
|
454
455
|
}
|
|
455
456
|
}
|
|
456
|
-
class
|
|
457
|
+
class Ye extends Error {
|
|
457
458
|
constructor(t) {
|
|
458
459
|
super(t), this.name = "PeginRegistrationNotFinalError";
|
|
459
460
|
}
|
|
460
461
|
}
|
|
461
|
-
function
|
|
462
|
-
return e instanceof
|
|
462
|
+
function Tr(e) {
|
|
463
|
+
return e instanceof We || e instanceof Error && e.name === "PeginRegistrationMissingError";
|
|
463
464
|
}
|
|
464
|
-
function
|
|
465
|
-
return e instanceof
|
|
465
|
+
function Mo(e) {
|
|
466
|
+
return e instanceof Ye || e instanceof Error && e.name === "PeginRegistrationNotFinalError";
|
|
466
467
|
}
|
|
467
|
-
function
|
|
468
|
+
function ve(e) {
|
|
468
469
|
const { currentBlock: t, createdAtBlock: r } = e, o = t - r + 1n;
|
|
469
470
|
return o < 0n ? 0 : Number(o);
|
|
470
471
|
}
|
|
471
|
-
async function
|
|
472
|
+
async function Fo(e) {
|
|
472
473
|
const {
|
|
473
474
|
vaultRegistryReader: t,
|
|
474
475
|
getBlockNumber: r,
|
|
475
476
|
vaultIds: o,
|
|
476
|
-
required: n =
|
|
477
|
-
pollIntervalMs:
|
|
478
|
-
timeoutMs: s =
|
|
477
|
+
required: n = xr,
|
|
478
|
+
pollIntervalMs: a = Er,
|
|
479
|
+
timeoutMs: s = kr,
|
|
479
480
|
signal: i,
|
|
480
|
-
onProgress:
|
|
481
|
+
onProgress: u
|
|
481
482
|
} = e;
|
|
482
483
|
if (o.length === 0)
|
|
483
484
|
throw new Error(
|
|
484
485
|
"waitForPeginRegistrationDepth requires at least one vault ID"
|
|
485
486
|
);
|
|
486
487
|
const c = Date.now();
|
|
487
|
-
let h = !1, l = 0,
|
|
488
|
+
let h = !1, l = 0, p;
|
|
488
489
|
for (; ; ) {
|
|
489
490
|
if (i != null && i.aborted)
|
|
490
491
|
throw new Error(
|
|
491
492
|
`Aborted while waiting for peg-in registration depth (${o.length} vault(s))`
|
|
492
493
|
);
|
|
493
494
|
if (Date.now() - c >= s)
|
|
494
|
-
throw new
|
|
495
|
-
`Peg-in registration did not reach ${n} Ethereum confirmations within ${s}ms. The registration transaction was submitted but is not yet final, so the Pre-PegIn Bitcoin transaction was never sent and no funds are at risk. Resume this deposit from the dashboard once the network settles.` + (
|
|
495
|
+
throw new Ye(
|
|
496
|
+
`Peg-in registration did not reach ${n} Ethereum confirmations within ${s}ms. The registration transaction was submitted but is not yet final, so the Pre-PegIn Bitcoin transaction was never sent and no funds are at risk. Resume this deposit from the dashboard once the network settles.` + (p instanceof Error ? ` Last read error: ${p.message}` : "")
|
|
496
497
|
);
|
|
497
498
|
try {
|
|
498
|
-
const
|
|
499
|
-
o.map((
|
|
499
|
+
const d = await r(), g = await Promise.all(
|
|
500
|
+
o.map((y) => t.getVaultBasicInfo(y))
|
|
500
501
|
), b = g.findIndex(
|
|
501
|
-
(
|
|
502
|
+
(y) => y.depositor === Bt || y.createdAt === 0n
|
|
502
503
|
);
|
|
503
504
|
if (b !== -1) {
|
|
504
|
-
if (l += 1, !h && l >
|
|
505
|
-
throw new
|
|
505
|
+
if (l += 1, !h && l > _r)
|
|
506
|
+
throw new We(
|
|
506
507
|
`Vault ${o[b]} is still not visible on-chain after ${l} reads — the registration does not exist.`
|
|
507
508
|
);
|
|
508
509
|
console.warn(
|
|
509
|
-
`Peg-in registration for vault ${o[b]} is not visible in chain state at block ${
|
|
510
|
-
),
|
|
510
|
+
`Peg-in registration for vault ${o[b]} is not visible in chain state at block ${d} — a lagging RPC backend or an Ethereum reorg. Still polling.`
|
|
511
|
+
), u == null || u({ confirmations: 0, required: n });
|
|
511
512
|
} else {
|
|
512
|
-
h = !0, l = 0,
|
|
513
|
-
let
|
|
514
|
-
currentBlock:
|
|
513
|
+
h = !0, l = 0, p = void 0;
|
|
514
|
+
let y = g[0], m = ve({
|
|
515
|
+
currentBlock: d,
|
|
515
516
|
createdAtBlock: g[0].createdAt
|
|
516
517
|
});
|
|
517
|
-
for (const
|
|
518
|
-
const w =
|
|
519
|
-
currentBlock:
|
|
520
|
-
createdAtBlock:
|
|
518
|
+
for (const x of g.slice(1)) {
|
|
519
|
+
const w = ve({
|
|
520
|
+
currentBlock: d,
|
|
521
|
+
createdAtBlock: x.createdAt
|
|
521
522
|
});
|
|
522
|
-
w <
|
|
523
|
+
w < m && (m = w, y = x);
|
|
523
524
|
}
|
|
524
|
-
if (
|
|
525
|
-
return { confirmations:
|
|
525
|
+
if (u == null || u({ confirmations: m, required: n }), m >= n)
|
|
526
|
+
return { confirmations: m, basicInfo: y };
|
|
526
527
|
}
|
|
527
|
-
} catch (
|
|
528
|
-
if (
|
|
529
|
-
throw
|
|
528
|
+
} catch (d) {
|
|
529
|
+
if (Tr(d))
|
|
530
|
+
throw d;
|
|
530
531
|
console.warn(
|
|
531
|
-
`Registration-depth read failed (retrying in ${
|
|
532
|
-
),
|
|
532
|
+
`Registration-depth read failed (retrying in ${a}ms): ` + (d instanceof Error ? d.message : String(d))
|
|
533
|
+
), p = d;
|
|
533
534
|
}
|
|
534
|
-
await new Promise((
|
|
535
|
+
await new Promise((d, g) => {
|
|
535
536
|
const b = () => {
|
|
536
|
-
clearTimeout(
|
|
537
|
+
clearTimeout(y), g(
|
|
537
538
|
new Error(
|
|
538
539
|
`Aborted while waiting for peg-in registration depth (${o.length} vault(s))`
|
|
539
540
|
)
|
|
540
541
|
);
|
|
541
|
-
},
|
|
542
|
-
i == null || i.removeEventListener("abort", b),
|
|
543
|
-
},
|
|
542
|
+
}, y = setTimeout(() => {
|
|
543
|
+
i == null || i.removeEventListener("abort", b), d();
|
|
544
|
+
}, a);
|
|
544
545
|
i == null || i.addEventListener("abort", b, { once: !0 });
|
|
545
546
|
});
|
|
546
547
|
}
|
|
547
548
|
}
|
|
548
|
-
const
|
|
549
|
-
|
|
549
|
+
const $r = /^(?:[0-9a-f]{2})*$/, Ar = /^[0-9a-f]{64}$/, Cr = /^([0-9a-f]{64}):(0|[1-9][0-9]*)$/, Sr = -2147483648, Ir = 2147483647, Y = 4294967295, we = 2, xe = 2;
|
|
550
|
+
class v extends Error {
|
|
551
|
+
constructor(t) {
|
|
552
|
+
super(t), this.name = "GraphFingerprintError";
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
function E(e, t, r) {
|
|
556
|
+
const o = e[t];
|
|
557
|
+
if (o === void 0)
|
|
558
|
+
throw new v(`Graph tx ${r} is missing "${t}"`);
|
|
559
|
+
return o;
|
|
560
|
+
}
|
|
561
|
+
function K(e, t) {
|
|
562
|
+
if (!Array.isArray(e))
|
|
563
|
+
throw new v(`Graph tx ${t} is not an array`);
|
|
564
|
+
return e;
|
|
565
|
+
}
|
|
566
|
+
function C(e, t) {
|
|
567
|
+
if (e === null || typeof e != "object" || Array.isArray(e))
|
|
568
|
+
throw new v(`Graph tx ${t} is not an object`);
|
|
569
|
+
return e;
|
|
570
|
+
}
|
|
571
|
+
function N(e, t, r, o) {
|
|
572
|
+
if (typeof e != "number" || !Number.isSafeInteger(e) || e < r || e > o)
|
|
573
|
+
throw new v(
|
|
574
|
+
`Graph tx ${t} is not an integer in [${r}, ${o}]`
|
|
575
|
+
);
|
|
576
|
+
return e;
|
|
577
|
+
}
|
|
578
|
+
function Q(e, t) {
|
|
579
|
+
if (typeof e != "string" || !$r.test(e))
|
|
580
|
+
throw new v(
|
|
581
|
+
`Graph tx ${t} is not lowercase hex without a prefix`
|
|
582
|
+
);
|
|
583
|
+
return I.from(e, "hex");
|
|
584
|
+
}
|
|
585
|
+
function X(e, t) {
|
|
586
|
+
if (typeof e != "string" || !Ar.test(e))
|
|
587
|
+
throw new v(
|
|
588
|
+
`Graph ${t} is not 32 bytes of lowercase hex`
|
|
589
|
+
);
|
|
590
|
+
return e;
|
|
591
|
+
}
|
|
592
|
+
function Ee(e, t) {
|
|
593
|
+
const r = C(e, t), o = new B();
|
|
594
|
+
return o.version = N(
|
|
595
|
+
E(r, "version", t),
|
|
596
|
+
`${t}.version`,
|
|
597
|
+
Sr,
|
|
598
|
+
Ir
|
|
599
|
+
), o.locktime = N(
|
|
600
|
+
E(r, "lock_time", t),
|
|
601
|
+
`${t}.lock_time`,
|
|
602
|
+
0,
|
|
603
|
+
Y
|
|
604
|
+
), K(E(r, "input", t), `${t}.input`).forEach((n, a) => {
|
|
605
|
+
const s = `${t}.input[${a}]`, i = C(n, s), u = E(i, "previous_output", s), c = typeof u == "string" && Cr.exec(u);
|
|
606
|
+
if (!c)
|
|
607
|
+
throw new v(
|
|
608
|
+
`Graph tx ${s}.previous_output is not "<txid>:<vout>"`
|
|
609
|
+
);
|
|
610
|
+
const h = N(Number(c[2]), `${s}.previous_output vout`, 0, Y);
|
|
611
|
+
o.addInput(
|
|
612
|
+
I.from(c[1], "hex").reverse(),
|
|
613
|
+
h,
|
|
614
|
+
N(E(i, "sequence", s), `${s}.sequence`, 0, Y),
|
|
615
|
+
Q(E(i, "script_sig", s), `${s}.script_sig`)
|
|
616
|
+
), o.ins[a].witness = K(
|
|
617
|
+
E(i, "witness", s),
|
|
618
|
+
`${s}.witness`
|
|
619
|
+
).map((l, p) => Q(l, `${s}.witness[${p}]`));
|
|
620
|
+
}), K(E(r, "output", t), `${t}.output`).forEach((n, a) => {
|
|
621
|
+
const s = `${t}.output[${a}]`, i = C(n, s);
|
|
622
|
+
o.addOutput(
|
|
623
|
+
Q(E(i, "script_pubkey", s), `${s}.script_pubkey`),
|
|
624
|
+
N(E(i, "value", s), `${s}.value`, 0, Number.MAX_SAFE_INTEGER)
|
|
625
|
+
);
|
|
626
|
+
}), new Uint8Array(o.toBuffer());
|
|
627
|
+
}
|
|
628
|
+
function H(e, t) {
|
|
629
|
+
const r = f(e).toLowerCase();
|
|
630
|
+
let o;
|
|
631
|
+
try {
|
|
632
|
+
o = B.fromHex(r);
|
|
633
|
+
} catch (n) {
|
|
634
|
+
throw new v(
|
|
635
|
+
`Presign ${t} is not one transaction: ${n instanceof Error ? n.message : String(n)}`
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
if (o.toHex() !== r)
|
|
639
|
+
throw new v(
|
|
640
|
+
`Presign ${t} is not a canonical transaction encoding`
|
|
641
|
+
);
|
|
642
|
+
return o;
|
|
643
|
+
}
|
|
644
|
+
function Rr(e, t) {
|
|
645
|
+
const [r, ...o] = e.ins;
|
|
646
|
+
if (!r || o.length > 0)
|
|
647
|
+
throw new v(
|
|
648
|
+
`Presign claim_tx must have exactly one input, got ${e.ins.length}`
|
|
649
|
+
);
|
|
650
|
+
const n = I.from(r.hash).reverse().toString("hex");
|
|
651
|
+
if (n !== t || r.index !== le)
|
|
652
|
+
throw new v(
|
|
653
|
+
`Presign claim_tx must spend ${t}:${le}, got ${n}:${r.index}`
|
|
654
|
+
);
|
|
655
|
+
if (e.version !== we)
|
|
656
|
+
throw new v(
|
|
657
|
+
`Presign claim_tx version must be ${we}, got ${e.version}`
|
|
658
|
+
);
|
|
659
|
+
if (r.witness.length > 0)
|
|
660
|
+
throw new v(
|
|
661
|
+
`Presign claim_tx input must have an empty witness, got ${r.witness.length} item(s)`
|
|
662
|
+
);
|
|
663
|
+
if (e.outs.length !== xe)
|
|
664
|
+
throw new v(
|
|
665
|
+
`Presign claim_tx must have exactly ${xe} outputs, got ${e.outs.length}`
|
|
666
|
+
);
|
|
667
|
+
}
|
|
668
|
+
function Qe(e) {
|
|
669
|
+
const t = [...e.challengers].sort(
|
|
670
|
+
(o, n) => o.pubkey < n.pubkey ? -1 : o.pubkey > n.pubkey ? 1 : 0
|
|
671
|
+
), r = [e.peginTx, e.claimTx, e.assertTx, e.payoutTx];
|
|
672
|
+
return t.forEach((o, n) => {
|
|
673
|
+
const a = X(o.pubkey, "challenger pubkey");
|
|
674
|
+
if (n > 0 && t[n - 1].pubkey === a)
|
|
675
|
+
throw new v(`Graph lists challenger ${a} twice`);
|
|
676
|
+
r.push(ye(a), o.nopayoutTx);
|
|
677
|
+
for (const s of o.outputLabelHashes)
|
|
678
|
+
r.push(ye(X(s, "output_label_hashes entry")));
|
|
679
|
+
}), Dt(Mt(Ft(...r)));
|
|
680
|
+
}
|
|
681
|
+
function Br(e) {
|
|
682
|
+
const t = f(e.peginTxid).toLowerCase(), r = H(e.peginTxHex, "pegin_tx");
|
|
683
|
+
if (r.getId() !== t)
|
|
684
|
+
throw new v(
|
|
685
|
+
`Presign pegin_tx hashes to ${r.getId()}, expected ${t}`
|
|
686
|
+
);
|
|
687
|
+
const o = H(e.claimTxHex, "claim_tx");
|
|
688
|
+
Rr(o, t);
|
|
689
|
+
const n = (a) => new Uint8Array(a.toBuffer());
|
|
690
|
+
return Qe({
|
|
691
|
+
peginTx: n(r),
|
|
692
|
+
claimTx: n(o),
|
|
693
|
+
assertTx: n(H(e.assertTxHex, "assert_tx")),
|
|
694
|
+
payoutTx: n(H(e.payoutTxHex, "payout_tx")),
|
|
695
|
+
challengers: e.challengers.map((a) => ({
|
|
696
|
+
pubkey: $(a.challenger_pubkey),
|
|
697
|
+
nopayoutTx: n(H(a.nopayout_tx.tx_hex, "nopayout_tx")),
|
|
698
|
+
outputLabelHashes: a.output_label_hashes.map(
|
|
699
|
+
(s) => f(s).toLowerCase()
|
|
700
|
+
)
|
|
701
|
+
}))
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
function Vr(e) {
|
|
705
|
+
const t = (o) => Ee(C(E(e, o, "graph"), o).tx, o), r = C(
|
|
706
|
+
E(e, "challenger_subgraphs", "graph"),
|
|
707
|
+
"challenger_subgraphs"
|
|
708
|
+
);
|
|
709
|
+
return Qe({
|
|
710
|
+
peginTx: t("pegin_tx"),
|
|
711
|
+
claimTx: t("claim_tx"),
|
|
712
|
+
assertTx: t("assert_tx"),
|
|
713
|
+
payoutTx: t("payout_tx"),
|
|
714
|
+
challengers: Object.entries(r).map(([o, n]) => {
|
|
715
|
+
const a = `challenger_subgraphs[${o}]`, s = C(n, a);
|
|
716
|
+
return {
|
|
717
|
+
pubkey: o,
|
|
718
|
+
nopayoutTx: Ee(
|
|
719
|
+
C(E(s, "nopayout_tx", a), `${a}.nopayout_tx`).tx,
|
|
720
|
+
`${a}.nopayout_tx`
|
|
721
|
+
),
|
|
722
|
+
outputLabelHashes: K(
|
|
723
|
+
E(s, "output_label_hashes", a),
|
|
724
|
+
`${a}.output_label_hashes`
|
|
725
|
+
).map(
|
|
726
|
+
(i, u) => X(i, `${a}.output_label_hashes[${u}]`)
|
|
727
|
+
)
|
|
728
|
+
};
|
|
729
|
+
})
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
function Or(e) {
|
|
733
|
+
const t = C(
|
|
734
|
+
E(e, "challenger_pubkeys", "graph"),
|
|
735
|
+
"challenger_pubkeys"
|
|
736
|
+
), r = /* @__PURE__ */ new Set();
|
|
737
|
+
for (const o of ["local", "universal"])
|
|
738
|
+
K(
|
|
739
|
+
E(t, o, "challenger_pubkeys"),
|
|
740
|
+
`challenger_pubkeys.${o}`
|
|
741
|
+
).forEach((n, a) => {
|
|
742
|
+
const s = X(n, `challenger_pubkeys.${o}[${a}]`);
|
|
743
|
+
if (r.has(s))
|
|
744
|
+
throw new v(
|
|
745
|
+
`Graph declares challenger ${s} more than once`
|
|
746
|
+
);
|
|
747
|
+
r.add(s);
|
|
748
|
+
});
|
|
749
|
+
return r;
|
|
750
|
+
}
|
|
751
|
+
function Uo(e, t) {
|
|
752
|
+
const r = Vr(e);
|
|
753
|
+
if (r !== t)
|
|
754
|
+
throw new v(
|
|
755
|
+
`Graph fingerprint ${r} does not match the presign fingerprint ${t}`
|
|
756
|
+
);
|
|
757
|
+
const o = Object.keys(
|
|
758
|
+
C(e.challenger_subgraphs, "challenger_subgraphs")
|
|
759
|
+
), n = Or(e);
|
|
760
|
+
if (o.length !== n.size || o.some((a) => !n.has(a)))
|
|
761
|
+
throw new v(
|
|
762
|
+
`Graph challenger_subgraphs keys ${o.join(", ")} do not match challenger_pubkeys ${[...n].join(", ")}`
|
|
763
|
+
);
|
|
764
|
+
}
|
|
765
|
+
const Nr = 1;
|
|
766
|
+
function Hr(e, t, r) {
|
|
550
767
|
const o = r.map(
|
|
551
|
-
(l) =>
|
|
768
|
+
(l) => f(l).toLowerCase()
|
|
552
769
|
), n = t.filter((l) => o.includes(l));
|
|
553
770
|
if (n.length > 0)
|
|
554
771
|
throw new Error(
|
|
555
772
|
`Cannot validate challenger set: vault keepers and universal challengers overlap (${n.join(", ")})`
|
|
556
773
|
);
|
|
557
|
-
const
|
|
558
|
-
(l) =>
|
|
774
|
+
const a = [...t, ...o], s = e.map(
|
|
775
|
+
(l) => f(l.challenger_pubkey).toLowerCase()
|
|
559
776
|
), i = new Set(s);
|
|
560
777
|
if (i.size !== s.length)
|
|
561
778
|
throw new Error(
|
|
562
779
|
"Depositor graph contains duplicate challenger entries in challenger_presign_data"
|
|
563
780
|
);
|
|
564
|
-
const
|
|
781
|
+
const u = new Set(a), c = a.filter((l) => !i.has(l)), h = s.filter((l) => !u.has(l));
|
|
565
782
|
if (c.length > 0 || h.length > 0)
|
|
566
783
|
throw new Error(
|
|
567
784
|
"Depositor graph challenger set does not match expected (local ∪ universal)" + (c.length > 0 ? ` (missing: ${c.join(", ")})` : "") + (h.length > 0 ? ` (unexpected: ${h.join(", ")})` : "")
|
|
568
785
|
);
|
|
569
786
|
}
|
|
570
|
-
function
|
|
787
|
+
function Kr(e, t) {
|
|
571
788
|
const r = e.ins[t];
|
|
572
|
-
return
|
|
789
|
+
return Ke(new Uint8Array(r.hash).slice().reverse());
|
|
573
790
|
}
|
|
574
|
-
function
|
|
575
|
-
const
|
|
576
|
-
if (
|
|
791
|
+
function J(e, t, r, o, n) {
|
|
792
|
+
const a = e.ins[t];
|
|
793
|
+
if (a.index !== 0)
|
|
577
794
|
throw new Error(
|
|
578
|
-
`NoPayout (challenger ${n}) input ${t} expected to spend ${o} vout 0, got vout ${
|
|
795
|
+
`NoPayout (challenger ${n}) input ${t} expected to spend ${o} vout 0, got vout ${a.index}`
|
|
579
796
|
);
|
|
580
|
-
const s = r.getId(), i =
|
|
797
|
+
const s = r.getId(), i = Kr(e, t);
|
|
581
798
|
if (i !== s)
|
|
582
799
|
throw new Error(
|
|
583
800
|
`NoPayout (challenger ${n}) input ${t} does not reference ${o} (expected txid ${s}, got ${i})`
|
|
584
801
|
);
|
|
585
802
|
}
|
|
586
|
-
async function
|
|
587
|
-
const o = [], n = [],
|
|
803
|
+
async function Dr(e, t, r) {
|
|
804
|
+
const o = [], n = [], a = [], s = Me({
|
|
588
805
|
claimerBtcPubkey: r.depositorBtcPubkey,
|
|
589
806
|
depositorBtcPubkey: r.depositorBtcPubkey,
|
|
590
807
|
vaultProviderBtcPubkey: r.vaultProviderBtcPubkey,
|
|
591
808
|
vaultKeeperBtcPubkeys: r.vaultKeeperBtcPubkeys
|
|
592
809
|
});
|
|
593
|
-
|
|
810
|
+
Hr(
|
|
594
811
|
e.challenger_presign_data,
|
|
595
812
|
s,
|
|
596
813
|
r.universalChallengerBtcPubkeys
|
|
597
814
|
);
|
|
598
|
-
const i = await
|
|
815
|
+
const i = await St({
|
|
599
816
|
vaultCoreVersion: r.vaultCoreVersion,
|
|
600
817
|
vkClaimerPayoutScriptPubKeys: r.vkClaimerPayoutScriptPubKeys,
|
|
601
818
|
vpCommissionScriptPubKey: r.vpCommissionScriptPubKey,
|
|
@@ -611,79 +828,79 @@ async function dr(e, t, r) {
|
|
|
611
828
|
network: r.network,
|
|
612
829
|
claimerBtcPubkey: r.depositorBtcPubkey,
|
|
613
830
|
registeredPayoutScriptPubKey: r.registeredPayoutScriptPubKey,
|
|
614
|
-
commissionBps:
|
|
831
|
+
commissionBps: Nr,
|
|
615
832
|
protocolFeeRate: r.protocolFeeRate,
|
|
616
833
|
councilMembers: r.councilMembers,
|
|
617
834
|
councilQuorum: r.councilQuorum
|
|
618
835
|
});
|
|
619
836
|
o.push(i.psbtHex), n.push(
|
|
620
|
-
|
|
837
|
+
M(
|
|
621
838
|
t,
|
|
622
|
-
|
|
839
|
+
ge
|
|
623
840
|
)
|
|
624
841
|
);
|
|
625
|
-
const
|
|
626
|
-
|
|
842
|
+
const u = f(r.depositorBtcPubkey), c = B.fromHex(
|
|
843
|
+
f(e.assert_tx.tx_hex)
|
|
627
844
|
);
|
|
628
845
|
for (const h of e.challenger_presign_data) {
|
|
629
|
-
const l =
|
|
846
|
+
const l = f(h.challenger_pubkey), p = o.length, d = await Mr({
|
|
630
847
|
challenger: h,
|
|
631
848
|
challengerPubkey: l,
|
|
632
|
-
claimerPubkey:
|
|
849
|
+
claimerPubkey: u,
|
|
633
850
|
localChallengers: s,
|
|
634
851
|
assertTxParsed: c,
|
|
635
852
|
ctx: r
|
|
636
853
|
});
|
|
637
|
-
o.push(
|
|
638
|
-
|
|
854
|
+
o.push(d), n.push(
|
|
855
|
+
M(
|
|
639
856
|
t,
|
|
640
|
-
|
|
857
|
+
ge
|
|
641
858
|
)
|
|
642
|
-
),
|
|
859
|
+
), a.push({
|
|
643
860
|
challengerPubkey: l,
|
|
644
|
-
noPayoutIdx:
|
|
861
|
+
noPayoutIdx: p
|
|
645
862
|
});
|
|
646
863
|
}
|
|
647
|
-
return { psbtHexes: o, signOptions: n, challengerEntries:
|
|
864
|
+
return { psbtHexes: o, signOptions: n, challengerEntries: a };
|
|
648
865
|
}
|
|
649
|
-
async function
|
|
866
|
+
async function Mr(e) {
|
|
650
867
|
const {
|
|
651
868
|
challenger: t,
|
|
652
869
|
challengerPubkey: r,
|
|
653
870
|
claimerPubkey: o,
|
|
654
871
|
localChallengers: n,
|
|
655
|
-
assertTxParsed:
|
|
872
|
+
assertTxParsed: a,
|
|
656
873
|
ctx: s
|
|
657
874
|
} = e;
|
|
658
|
-
|
|
875
|
+
Ut(
|
|
659
876
|
t.nopayout_tx.tx_hex,
|
|
660
877
|
r,
|
|
661
878
|
s.network
|
|
662
879
|
);
|
|
663
880
|
const i = B.fromHex(
|
|
664
|
-
|
|
665
|
-
),
|
|
666
|
-
|
|
881
|
+
f(t.nopayout_tx.tx_hex)
|
|
882
|
+
), u = B.fromHex(
|
|
883
|
+
f(t.challenge_assert_x_tx.tx_hex)
|
|
667
884
|
), c = B.fromHex(
|
|
668
|
-
|
|
885
|
+
f(t.challenge_assert_y_tx.tx_hex)
|
|
669
886
|
);
|
|
670
887
|
if (i.ins.length !== 3)
|
|
671
888
|
throw new Error(
|
|
672
889
|
`NoPayout (challenger ${r}) must have exactly 3 inputs, got ${i.ins.length}`
|
|
673
890
|
);
|
|
674
|
-
|
|
891
|
+
J(
|
|
675
892
|
i,
|
|
676
893
|
0,
|
|
677
|
-
|
|
894
|
+
a,
|
|
678
895
|
"Assert",
|
|
679
896
|
r
|
|
680
|
-
),
|
|
897
|
+
), J(
|
|
681
898
|
i,
|
|
682
899
|
1,
|
|
683
|
-
|
|
900
|
+
u,
|
|
684
901
|
"ChallengeAssertX",
|
|
685
902
|
r
|
|
686
|
-
),
|
|
903
|
+
), J(
|
|
687
904
|
i,
|
|
688
905
|
2,
|
|
689
906
|
c,
|
|
@@ -691,14 +908,14 @@ async function pr(e) {
|
|
|
691
908
|
r
|
|
692
909
|
);
|
|
693
910
|
const h = [
|
|
694
|
-
u.outs[0],
|
|
695
911
|
a.outs[0],
|
|
912
|
+
u.outs[0],
|
|
696
913
|
c.outs[0]
|
|
697
914
|
].map((l) => ({
|
|
698
|
-
script_pubkey:
|
|
915
|
+
script_pubkey: Ke(new Uint8Array(l.script)),
|
|
699
916
|
value: l.value
|
|
700
917
|
}));
|
|
701
|
-
return
|
|
918
|
+
return Lt({
|
|
702
919
|
noPayoutTxHex: t.nopayout_tx.tx_hex,
|
|
703
920
|
challengerPubkey: r,
|
|
704
921
|
prevouts: h,
|
|
@@ -713,31 +930,31 @@ async function pr(e) {
|
|
|
713
930
|
}
|
|
714
931
|
});
|
|
715
932
|
}
|
|
716
|
-
function
|
|
717
|
-
|
|
718
|
-
const n =
|
|
933
|
+
function Fr(e, t, r) {
|
|
934
|
+
F(e[0]);
|
|
935
|
+
const n = U(
|
|
719
936
|
e[0].returnedPsbtHex,
|
|
720
937
|
r
|
|
721
938
|
);
|
|
722
|
-
|
|
939
|
+
L({
|
|
723
940
|
requestedPsbtHex: e[0].requestedPsbtHex,
|
|
724
941
|
signatureHex: n,
|
|
725
942
|
signerXOnlyPubkeyHex: r,
|
|
726
943
|
inputIndex: 0
|
|
727
944
|
});
|
|
728
|
-
const
|
|
945
|
+
const a = {};
|
|
729
946
|
for (const s of t) {
|
|
730
|
-
|
|
731
|
-
const i =
|
|
947
|
+
F(e[s.noPayoutIdx]);
|
|
948
|
+
const i = U(
|
|
732
949
|
e[s.noPayoutIdx].returnedPsbtHex,
|
|
733
950
|
r
|
|
734
951
|
);
|
|
735
|
-
|
|
952
|
+
L({
|
|
736
953
|
requestedPsbtHex: e[s.noPayoutIdx].requestedPsbtHex,
|
|
737
954
|
signatureHex: i,
|
|
738
955
|
signerXOnlyPubkeyHex: r,
|
|
739
956
|
inputIndex: 0
|
|
740
|
-
}),
|
|
957
|
+
}), a[s.challengerPubkey] = {
|
|
741
958
|
nopayout_signature: i
|
|
742
959
|
};
|
|
743
960
|
}
|
|
@@ -745,39 +962,39 @@ function gr(e, t, r) {
|
|
|
745
962
|
payout_signatures: {
|
|
746
963
|
payout_signature: n
|
|
747
964
|
},
|
|
748
|
-
per_challenger:
|
|
965
|
+
per_challenger: a
|
|
749
966
|
};
|
|
750
967
|
}
|
|
751
|
-
async function
|
|
752
|
-
const { depositorGraph: t, btcWallet: r, signingContext: o } = e, n = await r.getPublicKeyHex(), { depositorPubkey:
|
|
968
|
+
async function Ur(e) {
|
|
969
|
+
const { depositorGraph: t, btcWallet: r, signingContext: o } = e, n = await r.getPublicKeyHex(), { depositorPubkey: a } = lt(
|
|
753
970
|
n,
|
|
754
|
-
|
|
755
|
-
), { psbtHexes: s, signOptions: i, challengerEntries:
|
|
971
|
+
f(o.depositorBtcPubkey)
|
|
972
|
+
), { psbtHexes: s, signOptions: i, challengerEntries: u } = await Dr(
|
|
756
973
|
t,
|
|
757
974
|
n,
|
|
758
975
|
o
|
|
759
|
-
), c = await
|
|
976
|
+
), c = await De(
|
|
760
977
|
r,
|
|
761
978
|
s,
|
|
762
979
|
i
|
|
763
|
-
), h = s.map((l,
|
|
980
|
+
), h = s.map((l, p) => ({
|
|
764
981
|
requestedPsbtHex: l,
|
|
765
|
-
returnedPsbtHex: c[
|
|
982
|
+
returnedPsbtHex: c[p]
|
|
766
983
|
}));
|
|
767
|
-
return
|
|
984
|
+
return Fr(
|
|
768
985
|
h,
|
|
769
|
-
|
|
770
|
-
|
|
986
|
+
u,
|
|
987
|
+
a
|
|
771
988
|
);
|
|
772
989
|
}
|
|
773
|
-
const
|
|
774
|
-
async function
|
|
990
|
+
const Lr = 1e4;
|
|
991
|
+
async function Je(e) {
|
|
775
992
|
const {
|
|
776
993
|
statusReader: t,
|
|
777
994
|
peginTxid: r,
|
|
778
995
|
targetStatuses: o,
|
|
779
996
|
timeoutMs: n,
|
|
780
|
-
pollIntervalMs:
|
|
997
|
+
pollIntervalMs: a = Lr,
|
|
781
998
|
signal: s
|
|
782
999
|
} = e, i = Date.now();
|
|
783
1000
|
for (; ; ) {
|
|
@@ -790,26 +1007,26 @@ async function Ne(e) {
|
|
|
790
1007
|
`Polling timeout after ${n}ms for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
|
|
791
1008
|
);
|
|
792
1009
|
try {
|
|
793
|
-
const
|
|
1010
|
+
const u = await t.getPeginStatus(
|
|
794
1011
|
{ pegin_txid: r },
|
|
795
1012
|
s
|
|
796
1013
|
);
|
|
797
|
-
if (
|
|
1014
|
+
if (u.pegin_txid.toLowerCase() !== r.toLowerCase())
|
|
798
1015
|
throw new Error(
|
|
799
|
-
`getPeginStatus returned status for pegin ${
|
|
1016
|
+
`getPeginStatus returned status for pegin ${u.pegin_txid.slice(0, 8)}…, requested ${r.slice(0, 8)}…`
|
|
800
1017
|
);
|
|
801
|
-
const c =
|
|
802
|
-
if (o.has(c) || c ===
|
|
1018
|
+
const c = u.status;
|
|
1019
|
+
if (o.has(c) || c === R.ACTIVATED)
|
|
803
1020
|
return c;
|
|
804
|
-
if (c ===
|
|
1021
|
+
if (c === R.EXPIRED || Nt.has(c))
|
|
805
1022
|
throw new Error(
|
|
806
1023
|
`Pegin ${r.slice(0, 8)}… reached terminal status "${c}" while waiting for ${[...o].join(", ")}`
|
|
807
1024
|
);
|
|
808
|
-
} catch (
|
|
809
|
-
if (!(
|
|
810
|
-
throw
|
|
1025
|
+
} catch (u) {
|
|
1026
|
+
if (!(u instanceof Ht && u.code === Kt.PEGIN_NOT_FOUND))
|
|
1027
|
+
throw u;
|
|
811
1028
|
}
|
|
812
|
-
await new Promise((
|
|
1029
|
+
await new Promise((u, c) => {
|
|
813
1030
|
const h = () => {
|
|
814
1031
|
clearTimeout(l), c(
|
|
815
1032
|
new Error(
|
|
@@ -817,35 +1034,35 @@ async function Ne(e) {
|
|
|
817
1034
|
)
|
|
818
1035
|
);
|
|
819
1036
|
}, l = setTimeout(() => {
|
|
820
|
-
s == null || s.removeEventListener("abort", h),
|
|
821
|
-
},
|
|
1037
|
+
s == null || s.removeEventListener("abort", h), u();
|
|
1038
|
+
}, a);
|
|
822
1039
|
s == null || s.addEventListener("abort", h, { once: !0 });
|
|
823
1040
|
});
|
|
824
1041
|
}
|
|
825
1042
|
}
|
|
826
|
-
const
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
]),
|
|
832
|
-
|
|
833
|
-
...
|
|
1043
|
+
const Gr = 1200 * 1e3, Ze = /* @__PURE__ */ new Set([
|
|
1044
|
+
R.PENDING_ACKS,
|
|
1045
|
+
R.PENDING_ACTIVATION,
|
|
1046
|
+
R.ACTIVATED_PENDING_BROADCAST,
|
|
1047
|
+
R.ACTIVATED
|
|
1048
|
+
]), Xr = /* @__PURE__ */ new Set([
|
|
1049
|
+
R.PENDING_DEPOSITOR_SIGNATURES,
|
|
1050
|
+
...Ze
|
|
834
1051
|
]);
|
|
835
|
-
function
|
|
1052
|
+
function jr(e) {
|
|
836
1053
|
return e.map((t) => ({
|
|
837
|
-
claimerPubkeyXOnly:
|
|
1054
|
+
claimerPubkeyXOnly: j(t.claimer_pubkey),
|
|
838
1055
|
payoutTxHex: t.payout_tx.tx_hex,
|
|
839
1056
|
assertTxHex: t.assert_tx.tx_hex
|
|
840
1057
|
}));
|
|
841
1058
|
}
|
|
842
|
-
function
|
|
843
|
-
return
|
|
1059
|
+
function S(e) {
|
|
1060
|
+
return j(e).toLowerCase();
|
|
844
1061
|
}
|
|
845
|
-
function
|
|
846
|
-
const r = (
|
|
1062
|
+
function qr(e, t) {
|
|
1063
|
+
const r = (u, c, h) => {
|
|
847
1064
|
throw new Error(
|
|
848
|
-
`Deposit terms ${
|
|
1065
|
+
`Deposit terms ${u} (${String(c)}) does not match the vault's version-locked signing context (${String(h)}); refusing to sign payouts against terms that describe a different graph.`
|
|
849
1066
|
);
|
|
850
1067
|
}, o = [
|
|
851
1068
|
["protocolFeeRate", e.protocolFeeRate, t.protocolFeeRate],
|
|
@@ -853,17 +1070,17 @@ function mr(e, t) {
|
|
|
853
1070
|
["timelockPegin", e.timelockPegin, t.timelockPegin],
|
|
854
1071
|
["timelockAssert", e.timelockAssert, t.timelockAssert]
|
|
855
1072
|
];
|
|
856
|
-
for (const [
|
|
857
|
-
c !== h && r(
|
|
858
|
-
const n = (
|
|
859
|
-
const h = n(
|
|
860
|
-
return h.length === l.length && h.every((
|
|
1073
|
+
for (const [u, c, h] of o)
|
|
1074
|
+
c !== h && r(u, c, h);
|
|
1075
|
+
const n = (u) => u.map(S).sort(), a = (u, c) => {
|
|
1076
|
+
const h = n(u), l = n(c);
|
|
1077
|
+
return h.length === l.length && h.every((p, d) => p === l[d]);
|
|
861
1078
|
};
|
|
862
|
-
|
|
1079
|
+
a(e.vaultKeeperBtcPubkeys, t.vaultKeeperBtcPubkeys) || r(
|
|
863
1080
|
"vaultKeeperBtcPubkeys",
|
|
864
1081
|
e.vaultKeeperBtcPubkeys.join(","),
|
|
865
1082
|
t.vaultKeeperBtcPubkeys.join(",")
|
|
866
|
-
),
|
|
1083
|
+
), a(
|
|
867
1084
|
e.universalChallengerBtcPubkeys,
|
|
868
1085
|
t.universalChallengerBtcPubkeys
|
|
869
1086
|
) || r(
|
|
@@ -871,8 +1088,8 @@ function mr(e, t) {
|
|
|
871
1088
|
e.universalChallengerBtcPubkeys.join(","),
|
|
872
1089
|
t.universalChallengerBtcPubkeys.join(",")
|
|
873
1090
|
);
|
|
874
|
-
const s =
|
|
875
|
-
(
|
|
1091
|
+
const s = S(t.vaultProviderBtcPubkey), i = e.vaults.map(
|
|
1092
|
+
(u) => S(u.vaultProviderBtcPubkey)
|
|
876
1093
|
);
|
|
877
1094
|
i.includes(s) || r(
|
|
878
1095
|
"vaults[].vaultProviderBtcPubkey",
|
|
@@ -880,12 +1097,12 @@ function mr(e, t) {
|
|
|
880
1097
|
t.vaultProviderBtcPubkey
|
|
881
1098
|
);
|
|
882
1099
|
}
|
|
883
|
-
function
|
|
884
|
-
const n =
|
|
885
|
-
|
|
886
|
-
...r.map(
|
|
887
|
-
], s = new Set(
|
|
888
|
-
if (s.size !==
|
|
1100
|
+
function zr(e, t, r, o) {
|
|
1101
|
+
const n = S(o), a = [
|
|
1102
|
+
S(t),
|
|
1103
|
+
...r.map(S)
|
|
1104
|
+
], s = new Set(a);
|
|
1105
|
+
if (s.size !== a.length)
|
|
889
1106
|
throw new Error(
|
|
890
1107
|
"Cannot validate claimer set: signing context contains duplicate vault provider or vault keeper key"
|
|
891
1108
|
);
|
|
@@ -894,17 +1111,17 @@ function wr(e, t, r, o) {
|
|
|
894
1111
|
"Cannot validate claimer set: depositor key overlaps with vault provider or vault keeper set"
|
|
895
1112
|
);
|
|
896
1113
|
const i = e.map(
|
|
897
|
-
(
|
|
1114
|
+
(p) => S(p.claimer_pubkey)
|
|
898
1115
|
);
|
|
899
1116
|
if (new Set(i).size !== i.length)
|
|
900
1117
|
throw new Error("Presign response contains duplicate claimer entries");
|
|
901
|
-
const
|
|
1118
|
+
const u = i.filter((p) => p !== n), c = new Set(u), h = a.filter((p) => !c.has(p)), l = u.filter((p) => !s.has(p));
|
|
902
1119
|
if (h.length > 0 || l.length > 0)
|
|
903
1120
|
throw new Error(
|
|
904
1121
|
"Presign response claimer set does not match expected (vault provider ∪ vault keepers)" + (h.length > 0 ? ` (missing: ${h.join(", ")})` : "") + (l.length > 0 ? ` (unexpected: ${l.join(", ")})` : "")
|
|
905
1122
|
);
|
|
906
1123
|
}
|
|
907
|
-
function
|
|
1124
|
+
function ke(e, t) {
|
|
908
1125
|
return {
|
|
909
1126
|
vaultCoreVersion: t.vaultCoreVersion,
|
|
910
1127
|
payoutTxHex: e.payoutTxHex,
|
|
@@ -926,56 +1143,57 @@ function le(e, t) {
|
|
|
926
1143
|
vpCommissionScriptPubKey: t.vpCommissionScriptPubKey
|
|
927
1144
|
};
|
|
928
1145
|
}
|
|
929
|
-
async function
|
|
930
|
-
const n = new
|
|
1146
|
+
async function Wr(e, t, r, o) {
|
|
1147
|
+
const n = new dt({
|
|
931
1148
|
network: t.network,
|
|
932
1149
|
btcWallet: e
|
|
933
|
-
}),
|
|
934
|
-
o == null || o(0,
|
|
1150
|
+
}), a = r.length;
|
|
1151
|
+
o == null || o(0, a);
|
|
935
1152
|
let s;
|
|
936
1153
|
if (n.supportsBatchSigning())
|
|
937
1154
|
s = (await n.signPayoutTransactionsBatch(
|
|
938
|
-
r.map((c) =>
|
|
1155
|
+
r.map((c) => ke(c, t))
|
|
939
1156
|
)).map((c) => c.payoutSignature);
|
|
940
1157
|
else {
|
|
941
1158
|
s = [];
|
|
942
|
-
for (let
|
|
943
|
-
o == null || o(
|
|
1159
|
+
for (let u = 0; u < r.length; u++) {
|
|
1160
|
+
o == null || o(u, a);
|
|
944
1161
|
const c = await n.signPayoutTransaction(
|
|
945
|
-
|
|
1162
|
+
ke(r[u], t)
|
|
946
1163
|
);
|
|
947
1164
|
s.push(c.signature);
|
|
948
1165
|
}
|
|
949
1166
|
}
|
|
950
1167
|
const i = {};
|
|
951
|
-
for (let
|
|
952
|
-
i[r[
|
|
953
|
-
payout_signature: s[
|
|
1168
|
+
for (let u = 0; u < r.length; u++)
|
|
1169
|
+
i[r[u].claimerPubkeyXOnly] = {
|
|
1170
|
+
payout_signature: s[u]
|
|
954
1171
|
};
|
|
955
|
-
return o == null || o(
|
|
1172
|
+
return o == null || o(a, a), i;
|
|
956
1173
|
}
|
|
957
|
-
async function
|
|
1174
|
+
async function Lo(e) {
|
|
958
1175
|
const {
|
|
959
1176
|
statusReader: t,
|
|
960
1177
|
presignClient: r,
|
|
961
1178
|
btcWallet: o,
|
|
962
1179
|
peginTxid: n,
|
|
963
|
-
depositorPk:
|
|
1180
|
+
depositorPk: a,
|
|
964
1181
|
signingContext: s,
|
|
965
1182
|
depositTerms: i,
|
|
966
|
-
timeoutMs:
|
|
1183
|
+
timeoutMs: u = Gr,
|
|
967
1184
|
signal: c,
|
|
968
|
-
onProgress: h
|
|
969
|
-
|
|
1185
|
+
onProgress: h,
|
|
1186
|
+
recordGraphFingerprint: l
|
|
1187
|
+
} = e, p = await Je({
|
|
970
1188
|
statusReader: t,
|
|
971
1189
|
peginTxid: n,
|
|
972
|
-
targetStatuses:
|
|
973
|
-
timeoutMs:
|
|
1190
|
+
targetStatuses: Xr,
|
|
1191
|
+
timeoutMs: u,
|
|
974
1192
|
signal: c
|
|
975
1193
|
});
|
|
976
|
-
if (
|
|
1194
|
+
if (Ze.has(p))
|
|
977
1195
|
return;
|
|
978
|
-
if (c == null || c.throwIfAborted(), i !== void 0 &&
|
|
1196
|
+
if (c == null || c.throwIfAborted(), i !== void 0 && qr(i, s), pt(o)) {
|
|
979
1197
|
if (!i)
|
|
980
1198
|
throw new Error(
|
|
981
1199
|
"runDepositorPresignFlow: this wallet requires approved deposit terms but none were provided. Fresh deposits must pass PreparePeginResult.depositTerms; resume flows must rebuild them from on-chain state (the vault app's rebuildDepositTerms)."
|
|
@@ -985,34 +1203,41 @@ async function go(e) {
|
|
|
985
1203
|
const d = await r.requestDepositorPresignTransactions(
|
|
986
1204
|
{
|
|
987
1205
|
pegin_txid: n,
|
|
988
|
-
depositor_pk:
|
|
1206
|
+
depositor_pk: a
|
|
989
1207
|
},
|
|
990
1208
|
c
|
|
991
1209
|
);
|
|
992
1210
|
c == null || c.throwIfAborted();
|
|
993
|
-
const
|
|
994
|
-
|
|
1211
|
+
const g = Br({
|
|
1212
|
+
peginTxid: n,
|
|
1213
|
+
peginTxHex: s.peginTxHex,
|
|
1214
|
+
claimTxHex: d.depositor_graph.claim_tx.tx_hex,
|
|
1215
|
+
assertTxHex: d.depositor_graph.assert_tx.tx_hex,
|
|
1216
|
+
payoutTxHex: d.depositor_graph.payout_tx.tx_hex,
|
|
1217
|
+
challengers: d.depositor_graph.challenger_presign_data
|
|
1218
|
+
}), b = S(a);
|
|
1219
|
+
zr(
|
|
995
1220
|
d.txs,
|
|
996
1221
|
s.vaultProviderBtcPubkey,
|
|
997
1222
|
s.vaultKeeperBtcPubkeys,
|
|
998
|
-
|
|
1223
|
+
a
|
|
999
1224
|
);
|
|
1000
|
-
const
|
|
1001
|
-
(
|
|
1002
|
-
),
|
|
1225
|
+
const y = d.txs.filter(
|
|
1226
|
+
(_) => S(_.claimer_pubkey) !== b
|
|
1227
|
+
), m = jr(y), x = await Wr(
|
|
1003
1228
|
o,
|
|
1004
1229
|
s,
|
|
1005
|
-
|
|
1230
|
+
m,
|
|
1006
1231
|
h
|
|
1007
1232
|
);
|
|
1008
1233
|
c == null || c.throwIfAborted();
|
|
1009
|
-
const
|
|
1234
|
+
const w = await Ur({
|
|
1010
1235
|
depositorGraph: d.depositor_graph,
|
|
1011
1236
|
btcWallet: o,
|
|
1012
1237
|
signingContext: {
|
|
1013
1238
|
vaultCoreVersion: s.vaultCoreVersion,
|
|
1014
1239
|
peginTxHex: s.peginTxHex,
|
|
1015
|
-
depositorBtcPubkey:
|
|
1240
|
+
depositorBtcPubkey: a,
|
|
1016
1241
|
vaultProviderBtcPubkey: s.vaultProviderBtcPubkey,
|
|
1017
1242
|
vaultKeeperBtcPubkeys: s.vaultKeeperBtcPubkeys,
|
|
1018
1243
|
universalChallengerBtcPubkeys: s.universalChallengerBtcPubkeys,
|
|
@@ -1027,104 +1252,104 @@ async function go(e) {
|
|
|
1027
1252
|
vpCommissionScriptPubKey: s.vpCommissionScriptPubKey
|
|
1028
1253
|
}
|
|
1029
1254
|
});
|
|
1030
|
-
c == null || c.throwIfAborted();
|
|
1031
|
-
const
|
|
1032
|
-
|
|
1255
|
+
c == null || c.throwIfAborted(), await l(g), c == null || c.throwIfAborted();
|
|
1256
|
+
const k = { ...x };
|
|
1257
|
+
k[f(a)] = w.payout_signatures, await r.submitDepositorPresignatures(
|
|
1033
1258
|
{
|
|
1034
1259
|
pegin_txid: n,
|
|
1035
|
-
depositor_pk:
|
|
1036
|
-
signatures:
|
|
1037
|
-
depositor_claimer_presignatures:
|
|
1260
|
+
depositor_pk: a,
|
|
1261
|
+
signatures: k,
|
|
1262
|
+
depositor_claimer_presignatures: w
|
|
1038
1263
|
},
|
|
1039
1264
|
c
|
|
1040
1265
|
);
|
|
1041
1266
|
}
|
|
1042
|
-
const
|
|
1043
|
-
|
|
1044
|
-
...
|
|
1267
|
+
const Yr = 300 * 1e3, Qr = /* @__PURE__ */ new Set([
|
|
1268
|
+
R.PENDING_DEPOSITOR_WOTS_PK,
|
|
1269
|
+
...Ue
|
|
1045
1270
|
]);
|
|
1046
|
-
async function
|
|
1271
|
+
async function Go(e) {
|
|
1047
1272
|
const {
|
|
1048
1273
|
statusReader: t,
|
|
1049
1274
|
wotsSubmitter: r,
|
|
1050
1275
|
peginTxid: o,
|
|
1051
1276
|
depositorPk: n,
|
|
1052
|
-
wotsPublicKeys:
|
|
1053
|
-
timeoutMs: s =
|
|
1277
|
+
wotsPublicKeys: a,
|
|
1278
|
+
timeoutMs: s = Yr,
|
|
1054
1279
|
signal: i
|
|
1055
1280
|
} = e;
|
|
1056
1281
|
i == null || i.throwIfAborted();
|
|
1057
|
-
const
|
|
1282
|
+
const u = await Je({
|
|
1058
1283
|
statusReader: t,
|
|
1059
1284
|
peginTxid: o,
|
|
1060
|
-
targetStatuses:
|
|
1285
|
+
targetStatuses: Qr,
|
|
1061
1286
|
timeoutMs: s,
|
|
1062
1287
|
signal: i
|
|
1063
1288
|
});
|
|
1064
|
-
|
|
1289
|
+
Ue.has(u) || (i == null || i.throwIfAborted(), await r.submitDepositorWotsKey(
|
|
1065
1290
|
{
|
|
1066
1291
|
pegin_txid: o,
|
|
1067
1292
|
depositor_pk: n,
|
|
1068
|
-
wots_public_keys:
|
|
1293
|
+
wots_public_keys: a
|
|
1069
1294
|
},
|
|
1070
1295
|
i
|
|
1071
1296
|
));
|
|
1072
1297
|
}
|
|
1073
|
-
function
|
|
1298
|
+
function Z(e) {
|
|
1074
1299
|
return e.registration || e.operation;
|
|
1075
1300
|
}
|
|
1076
|
-
function
|
|
1077
|
-
const o =
|
|
1301
|
+
function Jr(e, t, r) {
|
|
1302
|
+
const o = $(e);
|
|
1078
1303
|
return {
|
|
1079
|
-
registration: o ===
|
|
1080
|
-
operation: o ===
|
|
1304
|
+
registration: o === $(t),
|
|
1305
|
+
operation: o === $(r)
|
|
1081
1306
|
};
|
|
1082
1307
|
}
|
|
1083
|
-
function
|
|
1084
|
-
const o =
|
|
1308
|
+
function _e(e, t, r) {
|
|
1309
|
+
const o = ee(e);
|
|
1085
1310
|
return {
|
|
1086
|
-
registration:
|
|
1087
|
-
operation:
|
|
1311
|
+
registration: Te(o, ee(t)),
|
|
1312
|
+
operation: Te(o, ee(r))
|
|
1088
1313
|
};
|
|
1089
1314
|
}
|
|
1090
|
-
function
|
|
1091
|
-
return e.map(
|
|
1315
|
+
function ee(e) {
|
|
1316
|
+
return e.map($).sort();
|
|
1092
1317
|
}
|
|
1093
|
-
function
|
|
1318
|
+
function Te(e, t) {
|
|
1094
1319
|
return e.length === t.length && e.every((r, o) => r === t[o]);
|
|
1095
1320
|
}
|
|
1096
|
-
async function
|
|
1321
|
+
async function Xo(e) {
|
|
1097
1322
|
const {
|
|
1098
1323
|
vaultProviderEthAddress: t,
|
|
1099
1324
|
hintBtcPubkey: r,
|
|
1100
1325
|
registrationBtcPubkey: o,
|
|
1101
1326
|
readCurrentOperationBtcPubkey: n,
|
|
1102
|
-
context:
|
|
1327
|
+
context: a
|
|
1103
1328
|
} = e;
|
|
1104
1329
|
if (!r) return;
|
|
1105
|
-
const s =
|
|
1106
|
-
if (s ===
|
|
1107
|
-
const i =
|
|
1330
|
+
const s = $(r);
|
|
1331
|
+
if (s === $(o)) return;
|
|
1332
|
+
const i = $(
|
|
1108
1333
|
await n()
|
|
1109
1334
|
);
|
|
1110
1335
|
if (s !== i)
|
|
1111
1336
|
throw new Error(
|
|
1112
|
-
`Vault provider BTC pubkey mismatch for ${t}: indexer hint matches neither the registration key nor the current operation key on-chain.${
|
|
1337
|
+
`Vault provider BTC pubkey mismatch for ${t}: indexer hint matches neither the registration key nor the current operation key on-chain.${a ? ` ${a}` : ""}`
|
|
1113
1338
|
);
|
|
1114
1339
|
}
|
|
1115
|
-
function
|
|
1116
|
-
const o = `${e} operation key (admin=${t.ethAddress})`, n =
|
|
1340
|
+
function te(e, t, r) {
|
|
1341
|
+
const o = `${e} operation key (admin=${t.ethAddress})`, n = fe(
|
|
1117
1342
|
t.btcPubKey,
|
|
1118
1343
|
`${e} roster key (admin=${t.ethAddress})`
|
|
1119
|
-
),
|
|
1344
|
+
), a = fe(r, o);
|
|
1120
1345
|
return {
|
|
1121
1346
|
adminAddress: t.ethAddress,
|
|
1122
1347
|
genesisBtcPubkey: n,
|
|
1123
|
-
operationBtcPubkey:
|
|
1124
|
-
rotated:
|
|
1348
|
+
operationBtcPubkey: a,
|
|
1349
|
+
rotated: a !== n
|
|
1125
1350
|
};
|
|
1126
1351
|
}
|
|
1127
|
-
function
|
|
1352
|
+
function Zr(e) {
|
|
1128
1353
|
const t = /* @__PURE__ */ new Map();
|
|
1129
1354
|
for (const r of e) {
|
|
1130
1355
|
const o = t.get(r.operationBtcPubkey);
|
|
@@ -1135,12 +1360,12 @@ function Cr(e) {
|
|
|
1135
1360
|
t.set(r.operationBtcPubkey, r.adminAddress);
|
|
1136
1361
|
}
|
|
1137
1362
|
}
|
|
1138
|
-
function
|
|
1363
|
+
function et(e, t, r) {
|
|
1139
1364
|
if (t.vaultKeepers.length !== e.vaultKeepers.length || t.universalChallengers.length !== e.universalChallengers.length)
|
|
1140
1365
|
throw new Error(
|
|
1141
1366
|
`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
1367
|
);
|
|
1143
|
-
const o =
|
|
1368
|
+
const o = te(
|
|
1144
1369
|
"vault provider",
|
|
1145
1370
|
{
|
|
1146
1371
|
ethAddress: e.vaultProviderEthAddress,
|
|
@@ -1148,212 +1373,212 @@ function De(e, t, r) {
|
|
|
1148
1373
|
},
|
|
1149
1374
|
t.vaultProvider
|
|
1150
1375
|
), n = e.vaultKeepers.map(
|
|
1151
|
-
(s, i) =>
|
|
1152
|
-
),
|
|
1153
|
-
(s, i) =>
|
|
1376
|
+
(s, i) => te("vault keeper", s, t.vaultKeepers[i])
|
|
1377
|
+
), a = e.universalChallengers.map(
|
|
1378
|
+
(s, i) => te("universal challenger", s, t.universalChallengers[i])
|
|
1154
1379
|
);
|
|
1155
|
-
return
|
|
1380
|
+
return Zr([
|
|
1156
1381
|
o,
|
|
1157
1382
|
...n,
|
|
1158
|
-
...
|
|
1383
|
+
...a
|
|
1159
1384
|
]), {
|
|
1160
1385
|
vaultProvider: o,
|
|
1161
1386
|
vaultKeepers: n,
|
|
1162
|
-
universalChallengers:
|
|
1387
|
+
universalChallengers: a,
|
|
1163
1388
|
// Derived from the pairs, never the reverse — see ParticipantKeySet.
|
|
1164
1389
|
vaultKeeperOperationKeysSorted: n.map((s) => s.operationBtcPubkey).sort(),
|
|
1165
|
-
universalChallengerOperationKeysSorted:
|
|
1390
|
+
universalChallengerOperationKeysSorted: a.map((s) => s.operationBtcPubkey).sort(),
|
|
1166
1391
|
resolvedAt: r,
|
|
1167
1392
|
query: e
|
|
1168
1393
|
};
|
|
1169
1394
|
}
|
|
1170
|
-
async function
|
|
1395
|
+
async function eo(e) {
|
|
1171
1396
|
const t = await e.operationKeyReader.getCurrentOperationKeys(
|
|
1172
1397
|
e.query,
|
|
1173
1398
|
e.blockNumber
|
|
1174
1399
|
);
|
|
1175
|
-
return
|
|
1400
|
+
return et(e.query, t, { mode: "current" });
|
|
1176
1401
|
}
|
|
1177
|
-
async function
|
|
1402
|
+
async function to(e) {
|
|
1178
1403
|
const t = await e.operationKeyReader.getOperationKeysAtEpochs(
|
|
1179
1404
|
e.query,
|
|
1180
1405
|
e.epochs
|
|
1181
1406
|
);
|
|
1182
|
-
return
|
|
1407
|
+
return et(e.query, t, {
|
|
1183
1408
|
mode: "epochs",
|
|
1184
1409
|
epochs: e.epochs
|
|
1185
1410
|
});
|
|
1186
1411
|
}
|
|
1187
|
-
class
|
|
1412
|
+
class oe extends Error {
|
|
1188
1413
|
constructor(t) {
|
|
1189
1414
|
super(t), this.name = "ApplicationEntryPointMismatchError";
|
|
1190
1415
|
}
|
|
1191
1416
|
}
|
|
1192
|
-
function
|
|
1193
|
-
return e instanceof
|
|
1417
|
+
function jo(e) {
|
|
1418
|
+
return e instanceof oe || e instanceof Error && e.name === "ApplicationEntryPointMismatchError";
|
|
1194
1419
|
}
|
|
1195
|
-
const
|
|
1196
|
-
async function
|
|
1420
|
+
const $e = (e) => e.map($).sort();
|
|
1421
|
+
async function qo(e) {
|
|
1197
1422
|
const {
|
|
1198
1423
|
vaultRegistryReader: t,
|
|
1199
1424
|
vaultKeeperReader: r,
|
|
1200
1425
|
universalChallengerReader: o,
|
|
1201
1426
|
vaultProviderEthAddress: n,
|
|
1202
|
-
applicationEntryPoint:
|
|
1427
|
+
applicationEntryPoint: a,
|
|
1203
1428
|
expectedVaultProviderBtcPubkey: s,
|
|
1204
1429
|
expectedVaultKeeperBtcPubkeys: i,
|
|
1205
|
-
expectedUniversalChallengerBtcPubkeys:
|
|
1430
|
+
expectedUniversalChallengerBtcPubkeys: u,
|
|
1206
1431
|
operationKeyReader: c,
|
|
1207
1432
|
onIndexerServingOperationKeys: h,
|
|
1208
1433
|
onIndexerHintsInconsistent: l,
|
|
1209
|
-
blockNumber:
|
|
1434
|
+
blockNumber: p
|
|
1210
1435
|
} = e, [
|
|
1211
|
-
|
|
1436
|
+
d,
|
|
1212
1437
|
g,
|
|
1213
1438
|
b,
|
|
1214
|
-
|
|
1439
|
+
y
|
|
1215
1440
|
] = await Promise.all([
|
|
1216
1441
|
t.getVaultProviderApplication(
|
|
1217
1442
|
n,
|
|
1218
|
-
|
|
1443
|
+
p
|
|
1219
1444
|
),
|
|
1220
1445
|
t.getVaultProviderGenesisBtcPubKey(
|
|
1221
1446
|
n,
|
|
1222
|
-
|
|
1447
|
+
p
|
|
1223
1448
|
),
|
|
1224
|
-
o.getLatestUniversalChallengersVersion(
|
|
1225
|
-
o.getCurrentUcKeyEpoch(
|
|
1449
|
+
o.getLatestUniversalChallengersVersion(p),
|
|
1450
|
+
o.getCurrentUcKeyEpoch(p)
|
|
1226
1451
|
]);
|
|
1227
|
-
if (!
|
|
1228
|
-
throw new
|
|
1229
|
-
`The application entry point this deposit was prepared for is not a valid address: ${
|
|
1452
|
+
if (!Vt(a, { strict: !1 }))
|
|
1453
|
+
throw new oe(
|
|
1454
|
+
`The application entry point this deposit was prepared for is not a valid address: ${a}`
|
|
1230
1455
|
);
|
|
1231
|
-
if (!
|
|
1232
|
-
throw new
|
|
1233
|
-
`Vault provider ${n} is registered to application ${
|
|
1456
|
+
if (!Ot(d, a))
|
|
1457
|
+
throw new oe(
|
|
1458
|
+
`Vault provider ${n} is registered to application ${d}, but this deposit was prepared for ${a}. 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.`
|
|
1234
1459
|
);
|
|
1235
|
-
const [
|
|
1460
|
+
const [m, x] = await Promise.all(
|
|
1236
1461
|
[
|
|
1237
1462
|
r.getCurrentVaultKeepersVersion(
|
|
1238
|
-
|
|
1239
|
-
|
|
1463
|
+
d,
|
|
1464
|
+
p
|
|
1240
1465
|
),
|
|
1241
1466
|
r.getCurrentAppKeeperKeyEpoch(
|
|
1242
|
-
|
|
1243
|
-
|
|
1467
|
+
d,
|
|
1468
|
+
p
|
|
1244
1469
|
)
|
|
1245
1470
|
]
|
|
1246
|
-
), [w,
|
|
1471
|
+
), [w, k] = await Promise.all([
|
|
1247
1472
|
r.getVaultKeepersByVersion(
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1473
|
+
d,
|
|
1474
|
+
m,
|
|
1475
|
+
p
|
|
1251
1476
|
),
|
|
1252
1477
|
o.getUniversalChallengersByVersion(
|
|
1253
1478
|
b,
|
|
1254
|
-
|
|
1479
|
+
p
|
|
1255
1480
|
)
|
|
1256
|
-
]),
|
|
1257
|
-
vaultProvider:
|
|
1258
|
-
vaultKeepers:
|
|
1259
|
-
universalChallengers:
|
|
1260
|
-
},
|
|
1481
|
+
]), _ = {
|
|
1482
|
+
vaultProvider: $(g),
|
|
1483
|
+
vaultKeepers: $e(w.map((T) => T.btcPubKey)),
|
|
1484
|
+
universalChallengers: $e(k.map((T) => T.btcPubKey))
|
|
1485
|
+
}, A = await eo({
|
|
1261
1486
|
operationKeyReader: c,
|
|
1262
1487
|
query: {
|
|
1263
1488
|
vaultProviderEthAddress: n,
|
|
1264
1489
|
vaultProviderGenesisBtcPubkey: `0x${g}`,
|
|
1265
|
-
applicationEntryPoint:
|
|
1490
|
+
applicationEntryPoint: d,
|
|
1266
1491
|
vaultKeepers: w,
|
|
1267
|
-
universalChallengers:
|
|
1492
|
+
universalChallengers: k
|
|
1268
1493
|
},
|
|
1269
|
-
blockNumber:
|
|
1270
|
-
}),
|
|
1271
|
-
vaultProvider:
|
|
1272
|
-
vaultKeepers: [...
|
|
1494
|
+
blockNumber: p
|
|
1495
|
+
}), P = {
|
|
1496
|
+
vaultProvider: A.vaultProvider.operationBtcPubkey,
|
|
1497
|
+
vaultKeepers: [...A.vaultKeeperOperationKeysSorted],
|
|
1273
1498
|
universalChallengers: [
|
|
1274
|
-
...
|
|
1499
|
+
...A.universalChallengerOperationKeysSorted
|
|
1275
1500
|
]
|
|
1276
|
-
},
|
|
1501
|
+
}, se = Jr(
|
|
1277
1502
|
s,
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
),
|
|
1503
|
+
_.vaultProvider,
|
|
1504
|
+
P.vaultProvider
|
|
1505
|
+
), ae = _e(
|
|
1281
1506
|
i,
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
),
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1507
|
+
_.vaultKeepers,
|
|
1508
|
+
P.vaultKeepers
|
|
1509
|
+
), ie = _e(
|
|
1510
|
+
u,
|
|
1511
|
+
_.universalChallengers,
|
|
1512
|
+
P.universalChallengers
|
|
1288
1513
|
);
|
|
1289
|
-
if (!
|
|
1514
|
+
if (!Z(se))
|
|
1290
1515
|
throw new Error(
|
|
1291
1516
|
`Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${n}. Refresh and try again.`
|
|
1292
1517
|
);
|
|
1293
|
-
if (!
|
|
1518
|
+
if (!Z(ae))
|
|
1294
1519
|
throw new Error(
|
|
1295
|
-
`Vault keeper BTC pubkeys (v${
|
|
1520
|
+
`Vault keeper BTC pubkeys (v${m}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
|
|
1296
1521
|
);
|
|
1297
|
-
if (!
|
|
1522
|
+
if (!Z(ie))
|
|
1298
1523
|
throw new Error(
|
|
1299
1524
|
`Universal challenger BTC pubkeys (v${b}) indexer set does not match ProtocolParams on-chain set. Refresh and try again.`
|
|
1300
1525
|
);
|
|
1301
|
-
const
|
|
1302
|
-
if (
|
|
1303
|
-
const
|
|
1304
|
-
throw l == null || l(
|
|
1526
|
+
const ue = [se, ae, ie], at = ue.some((T) => T.registration && !T.operation), ce = ue.some((T) => T.operation && !T.registration);
|
|
1527
|
+
if (at && ce) {
|
|
1528
|
+
const T = `Indexer participant hints are internally inconsistent for vault provider ${n}: some roles match the registration keys while others match the rotated operation keys.`;
|
|
1529
|
+
throw l == null || l(T), new Error(`${T} Refresh and try again.`);
|
|
1305
1530
|
}
|
|
1306
|
-
return
|
|
1531
|
+
return ce && (h == null || h(
|
|
1307
1532
|
`Indexer is serving rotated operation keys for vault provider ${n}`
|
|
1308
1533
|
)), {
|
|
1309
|
-
vaultProviderBtcPubkeyXOnly:
|
|
1310
|
-
vaultKeeperBtcPubkeysSorted:
|
|
1311
|
-
universalChallengerBtcPubkeysSorted:
|
|
1312
|
-
expectedAppVaultKeepersVersion:
|
|
1534
|
+
vaultProviderBtcPubkeyXOnly: P.vaultProvider,
|
|
1535
|
+
vaultKeeperBtcPubkeysSorted: P.vaultKeepers,
|
|
1536
|
+
universalChallengerBtcPubkeysSorted: P.universalChallengers,
|
|
1537
|
+
expectedAppVaultKeepersVersion: m,
|
|
1313
1538
|
expectedUniversalChallengersVersion: b,
|
|
1314
|
-
appKeeperKeyEpoch:
|
|
1315
|
-
ucKeyEpoch:
|
|
1316
|
-
registrationKeys:
|
|
1317
|
-
participantKeys:
|
|
1539
|
+
appKeeperKeyEpoch: x,
|
|
1540
|
+
ucKeyEpoch: y,
|
|
1541
|
+
registrationKeys: _,
|
|
1542
|
+
participantKeys: A
|
|
1318
1543
|
};
|
|
1319
1544
|
}
|
|
1320
|
-
function
|
|
1545
|
+
function ro(e) {
|
|
1321
1546
|
return /^[0-9a-fA-F]{64}$/.test(e);
|
|
1322
1547
|
}
|
|
1323
|
-
function
|
|
1548
|
+
function zo(e) {
|
|
1324
1549
|
const {
|
|
1325
1550
|
amountSats: t,
|
|
1326
1551
|
minDeposit: r,
|
|
1327
1552
|
maxDeposit: o,
|
|
1328
1553
|
btcBalance: n,
|
|
1329
|
-
estimatedFeeSats:
|
|
1554
|
+
estimatedFeeSats: a,
|
|
1330
1555
|
depositorClaimValue: s
|
|
1331
1556
|
} = e;
|
|
1332
|
-
return !(t <= 0n || t < r || o && o > 0n && t > o ||
|
|
1557
|
+
return !(t <= 0n || t < r || o && o > 0n && t > o || a == null || s == null || t + a + s > n);
|
|
1333
1558
|
}
|
|
1334
|
-
function
|
|
1559
|
+
function Wo(e, t, r) {
|
|
1335
1560
|
return e <= 0n ? {
|
|
1336
1561
|
valid: !1,
|
|
1337
1562
|
error: "Deposit amount must be greater than zero"
|
|
1338
1563
|
} : e < t ? {
|
|
1339
1564
|
valid: !1,
|
|
1340
|
-
error: `Minimum deposit is ${
|
|
1565
|
+
error: `Minimum deposit is ${V(t)} BTC`
|
|
1341
1566
|
} : r && r > 0n && e > r ? {
|
|
1342
1567
|
valid: !1,
|
|
1343
|
-
error: `Maximum deposit is ${
|
|
1568
|
+
error: `Maximum deposit is ${V(r)} BTC`
|
|
1344
1569
|
} : { valid: !0 };
|
|
1345
1570
|
}
|
|
1346
|
-
function
|
|
1571
|
+
function Yo(e) {
|
|
1347
1572
|
const { amount: t, effectiveRemaining: r } = e;
|
|
1348
1573
|
return r === null ? { valid: !0 } : r === 0n ? {
|
|
1349
1574
|
valid: !1,
|
|
1350
1575
|
error: "Supply cap reached — deposits temporarily paused"
|
|
1351
1576
|
} : t > r ? {
|
|
1352
1577
|
valid: !1,
|
|
1353
|
-
error: `Vault size exceeds remaining capacity (${
|
|
1578
|
+
error: `Vault size exceeds remaining capacity (${V(r)} BTC)`
|
|
1354
1579
|
} : { valid: !0 };
|
|
1355
1580
|
}
|
|
1356
|
-
function
|
|
1581
|
+
function Qo(e, t) {
|
|
1357
1582
|
if (!e || e.length === 0)
|
|
1358
1583
|
return {
|
|
1359
1584
|
valid: !1,
|
|
@@ -1369,7 +1594,7 @@ function Eo(e, t) {
|
|
|
1369
1594
|
error: "Invalid vault provider selected"
|
|
1370
1595
|
} : { valid: !0 };
|
|
1371
1596
|
}
|
|
1372
|
-
function
|
|
1597
|
+
function oo(e, t, r) {
|
|
1373
1598
|
if (!e || e.length === 0)
|
|
1374
1599
|
return {
|
|
1375
1600
|
valid: !1,
|
|
@@ -1385,82 +1610,82 @@ function Br(e, t, r) {
|
|
|
1385
1610
|
if (t && n < t)
|
|
1386
1611
|
return {
|
|
1387
1612
|
valid: !1,
|
|
1388
|
-
error: `Vault ${o + 1} amount ${
|
|
1613
|
+
error: `Vault ${o + 1} amount ${V(n)} BTC is below minimum deposit ${V(t)} BTC`
|
|
1389
1614
|
};
|
|
1390
1615
|
if (r && n > r)
|
|
1391
1616
|
return {
|
|
1392
1617
|
valid: !1,
|
|
1393
|
-
error: `Vault ${o + 1} amount ${
|
|
1618
|
+
error: `Vault ${o + 1} amount ${V(n)} BTC exceeds maximum deposit ${V(r)} BTC`
|
|
1394
1619
|
};
|
|
1395
1620
|
}
|
|
1396
1621
|
return { valid: !0 };
|
|
1397
1622
|
}
|
|
1398
|
-
function
|
|
1399
|
-
const t =
|
|
1400
|
-
return
|
|
1623
|
+
function no(e) {
|
|
1624
|
+
const t = f(e);
|
|
1625
|
+
return ro(t) ? { valid: !0 } : {
|
|
1401
1626
|
valid: !1,
|
|
1402
1627
|
error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
|
|
1403
1628
|
};
|
|
1404
1629
|
}
|
|
1405
|
-
function
|
|
1630
|
+
function so(e) {
|
|
1406
1631
|
if (!e || e.length === 0)
|
|
1407
1632
|
throw new Error(
|
|
1408
1633
|
"No vault keepers available. The system requires at least one vault keeper to create a deposit."
|
|
1409
1634
|
);
|
|
1410
1635
|
}
|
|
1411
|
-
function
|
|
1636
|
+
function ao(e) {
|
|
1412
1637
|
if (!e || e.length === 0)
|
|
1413
1638
|
throw new Error(
|
|
1414
1639
|
"No universal challengers available. The system requires at least one universal challenger to create a deposit."
|
|
1415
1640
|
);
|
|
1416
1641
|
}
|
|
1417
|
-
function
|
|
1642
|
+
function io(e) {
|
|
1418
1643
|
if (e.length === 0)
|
|
1419
1644
|
throw new Error("No spendable UTXOs available");
|
|
1420
1645
|
}
|
|
1421
|
-
function
|
|
1646
|
+
function Jo(e) {
|
|
1422
1647
|
const {
|
|
1423
1648
|
vaultAmounts: t,
|
|
1424
1649
|
confirmedUTXOs: r,
|
|
1425
1650
|
vaultProviderBtcPubkey: o,
|
|
1426
1651
|
vaultKeeperBtcPubkeys: n,
|
|
1427
|
-
universalChallengerBtcPubkeys:
|
|
1652
|
+
universalChallengerBtcPubkeys: a,
|
|
1428
1653
|
minDeposit: s,
|
|
1429
1654
|
maxDeposit: i
|
|
1430
|
-
} = e,
|
|
1655
|
+
} = e, u = oo(
|
|
1431
1656
|
t,
|
|
1432
1657
|
s,
|
|
1433
1658
|
i
|
|
1434
1659
|
);
|
|
1435
|
-
if (!
|
|
1436
|
-
throw new Error(
|
|
1437
|
-
const c =
|
|
1660
|
+
if (!u.valid)
|
|
1661
|
+
throw new Error(u.error);
|
|
1662
|
+
const c = no(o);
|
|
1438
1663
|
if (!c.valid)
|
|
1439
1664
|
throw new Error(c.error);
|
|
1440
|
-
|
|
1665
|
+
so(n), ao(a), io(r);
|
|
1441
1666
|
}
|
|
1442
|
-
class
|
|
1667
|
+
class tt extends Error {
|
|
1443
1668
|
constructor(t) {
|
|
1444
1669
|
super(t), this.name = "ParticipantKeyDriftError";
|
|
1445
1670
|
}
|
|
1446
1671
|
}
|
|
1447
|
-
function
|
|
1448
|
-
return e instanceof
|
|
1672
|
+
function Zo(e) {
|
|
1673
|
+
return e instanceof tt || e instanceof Error && e.name === "ParticipantKeyDriftError";
|
|
1449
1674
|
}
|
|
1450
|
-
function
|
|
1675
|
+
function Ae(e, t, r) {
|
|
1451
1676
|
return t.length === r.length && t.every((o, n) => o === r[n]) ? null : `${e} expected [${t.join(", ")}], got [${r.join(", ")}]`;
|
|
1452
1677
|
}
|
|
1453
|
-
async function
|
|
1454
|
-
const { vaultRegistryReader: t, operationKeyReader: r, vaultIds: o, expected: n } = e,
|
|
1678
|
+
async function en(e) {
|
|
1679
|
+
const { vaultRegistryReader: t, operationKeyReader: r, vaultIds: o, expected: n } = e, a = n.query;
|
|
1455
1680
|
if (o.length === 0) return;
|
|
1456
1681
|
const s = await t.getVaultKeyEpochsBatch(o), i = [];
|
|
1457
|
-
for (const [
|
|
1458
|
-
const h = o[
|
|
1682
|
+
for (const [u, c] of s.entries()) {
|
|
1683
|
+
const h = o[u];
|
|
1459
1684
|
let l;
|
|
1460
1685
|
try {
|
|
1461
|
-
l = await
|
|
1686
|
+
l = await to({
|
|
1462
1687
|
operationKeyReader: r,
|
|
1463
|
-
query:
|
|
1688
|
+
query: a,
|
|
1464
1689
|
epochs: c
|
|
1465
1690
|
});
|
|
1466
1691
|
} catch (g) {
|
|
@@ -1472,104 +1697,104 @@ async function To(e) {
|
|
|
1472
1697
|
l.vaultProvider.operationBtcPubkey !== n.vaultProvider.operationBtcPubkey && i.push(
|
|
1473
1698
|
`vault ${h}: vault provider key expected ${n.vaultProvider.operationBtcPubkey}, got ${l.vaultProvider.operationBtcPubkey}`
|
|
1474
1699
|
);
|
|
1475
|
-
const
|
|
1700
|
+
const p = Ae(
|
|
1476
1701
|
`vault ${h}: vault keeper keys`,
|
|
1477
1702
|
n.vaultKeeperOperationKeysSorted,
|
|
1478
1703
|
l.vaultKeeperOperationKeysSorted
|
|
1479
1704
|
);
|
|
1480
|
-
|
|
1481
|
-
const
|
|
1705
|
+
p && i.push(p);
|
|
1706
|
+
const d = Ae(
|
|
1482
1707
|
`vault ${h}: universal challenger keys`,
|
|
1483
1708
|
n.universalChallengerOperationKeysSorted,
|
|
1484
1709
|
l.universalChallengerOperationKeysSorted
|
|
1485
1710
|
);
|
|
1486
|
-
|
|
1711
|
+
d && i.push(d);
|
|
1487
1712
|
}
|
|
1488
1713
|
if (i.length > 0)
|
|
1489
|
-
throw new
|
|
1714
|
+
throw new tt(
|
|
1490
1715
|
`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.`
|
|
1491
1716
|
);
|
|
1492
1717
|
}
|
|
1493
|
-
class
|
|
1718
|
+
class rt extends Error {
|
|
1494
1719
|
constructor(t) {
|
|
1495
1720
|
super(t), this.name = "RegisteredVaultVersionMismatchError";
|
|
1496
1721
|
}
|
|
1497
1722
|
}
|
|
1498
|
-
function
|
|
1499
|
-
return e instanceof
|
|
1723
|
+
function tn(e) {
|
|
1724
|
+
return e instanceof rt || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
|
|
1500
1725
|
}
|
|
1501
|
-
async function
|
|
1726
|
+
async function rn(e) {
|
|
1502
1727
|
const {
|
|
1503
1728
|
vaultRegistryReader: t,
|
|
1504
1729
|
vaultIds: r,
|
|
1505
1730
|
expectedOffchainParamsVersion: o,
|
|
1506
1731
|
expectedAppVaultKeepersVersion: n,
|
|
1507
|
-
expectedUniversalChallengersVersion:
|
|
1732
|
+
expectedUniversalChallengersVersion: a,
|
|
1508
1733
|
expectedVaultCoreVersion: s
|
|
1509
|
-
} = e, i = await t.getProtocolInfoBatch(r),
|
|
1734
|
+
} = e, i = await t.getProtocolInfoBatch(r), u = [];
|
|
1510
1735
|
if (i.forEach((c, h) => {
|
|
1511
1736
|
const l = r[h];
|
|
1512
|
-
c.offchainParamsVersion !== o &&
|
|
1737
|
+
c.offchainParamsVersion !== o && u.push(
|
|
1513
1738
|
`vault ${l}: offchainParams expected v${o}, got v${c.offchainParamsVersion}`
|
|
1514
|
-
), c.appVaultKeepersVersion !== n &&
|
|
1739
|
+
), c.appVaultKeepersVersion !== n && u.push(
|
|
1515
1740
|
`vault ${l}: appVaultKeepers expected v${n}, got v${c.appVaultKeepersVersion}`
|
|
1516
|
-
), c.universalChallengersVersion !==
|
|
1517
|
-
`vault ${l}: universalChallengers expected v${
|
|
1518
|
-
), c.vaultCoreVersion !== s &&
|
|
1741
|
+
), c.universalChallengersVersion !== a && u.push(
|
|
1742
|
+
`vault ${l}: universalChallengers expected v${a}, got v${c.universalChallengersVersion}`
|
|
1743
|
+
), c.vaultCoreVersion !== s && u.push(
|
|
1519
1744
|
`vault ${l}: vaultCoreVersion expected v${s} (build-time active), got v${c.vaultCoreVersion}`
|
|
1520
1745
|
);
|
|
1521
|
-
}),
|
|
1522
|
-
throw new
|
|
1523
|
-
`Aborting BTC broadcast: signer-set or offchain-params versions changed during registration (${
|
|
1746
|
+
}), u.length > 0)
|
|
1747
|
+
throw new rt(
|
|
1748
|
+
`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.`
|
|
1524
1749
|
);
|
|
1525
1750
|
}
|
|
1526
|
-
var
|
|
1527
|
-
const
|
|
1751
|
+
var ot = /* @__PURE__ */ ((e) => (e.CLAIM_EVENT_RECEIVED = "ClaimEventReceived", e.CLAIM_BROADCAST = "ClaimBroadcast", e.ASSERT_BROADCAST = "AssertBroadcast", e.PAYOUT_BROADCAST = "PayoutBroadcast", e.PAYOUT_BLOCKED = "PayoutBlocked", e))(ot || {});
|
|
1752
|
+
const uo = /* @__PURE__ */ new Set([
|
|
1528
1753
|
"PayoutBroadcast",
|
|
1529
1754
|
"PayoutBlocked"
|
|
1530
1755
|
/* PAYOUT_BLOCKED */
|
|
1531
1756
|
]);
|
|
1532
|
-
function
|
|
1533
|
-
return Object.values(
|
|
1757
|
+
function on(e) {
|
|
1758
|
+
return Object.values(ot).includes(
|
|
1534
1759
|
e
|
|
1535
1760
|
);
|
|
1536
1761
|
}
|
|
1537
|
-
function
|
|
1538
|
-
return !!e &&
|
|
1762
|
+
function nn(e) {
|
|
1763
|
+
return !!e && uo.has(e);
|
|
1539
1764
|
}
|
|
1540
|
-
class
|
|
1765
|
+
class co extends Error {
|
|
1541
1766
|
constructor(r, o) {
|
|
1542
1767
|
super(`Refund not yet mature (BIP68 not final): ${o.message}`);
|
|
1543
|
-
|
|
1544
|
-
|
|
1768
|
+
O(this, "vaultId");
|
|
1769
|
+
O(this, "cause");
|
|
1545
1770
|
this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = o;
|
|
1546
1771
|
}
|
|
1547
1772
|
}
|
|
1548
|
-
const
|
|
1549
|
-
function
|
|
1773
|
+
const lo = /^0x[0-9a-fA-F]{64}$/, ho = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, nt = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, st = 160, Ce = 2e3, Se = 10n, Ie = 100n;
|
|
1774
|
+
function sn(e) {
|
|
1550
1775
|
if (!Number.isFinite(e) || e <= 0)
|
|
1551
1776
|
throw new Error(
|
|
1552
1777
|
`feeRateSatsVb must be a positive finite number, got ${e}`
|
|
1553
1778
|
);
|
|
1554
|
-
return BigInt(Math.ceil(e *
|
|
1779
|
+
return BigInt(Math.ceil(e * st));
|
|
1555
1780
|
}
|
|
1556
|
-
const
|
|
1557
|
-
function
|
|
1781
|
+
const po = 1, go = /non-BIP68-final/i;
|
|
1782
|
+
function ne(e, t) {
|
|
1558
1783
|
if (e.length !== 66)
|
|
1559
1784
|
throw new Error(
|
|
1560
1785
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
1561
1786
|
);
|
|
1562
|
-
if (!
|
|
1787
|
+
if (!lo.test(e))
|
|
1563
1788
|
throw new Error(
|
|
1564
1789
|
`${t} must contain only hex characters after the 0x prefix`
|
|
1565
1790
|
);
|
|
1566
1791
|
}
|
|
1567
|
-
function
|
|
1792
|
+
function re(e, t) {
|
|
1568
1793
|
if (!Number.isInteger(e) || e < 0)
|
|
1569
1794
|
throw new Error(`${t} must be a non-negative integer, got ${e}`);
|
|
1570
1795
|
}
|
|
1571
|
-
function
|
|
1572
|
-
if (
|
|
1796
|
+
function fo(e) {
|
|
1797
|
+
if (ne(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0)
|
|
1573
1798
|
throw new Error(
|
|
1574
1799
|
`htlcVout must be a non-negative integer, got ${e.htlcVout}`
|
|
1575
1800
|
);
|
|
@@ -1581,7 +1806,7 @@ function Fr(e) {
|
|
|
1581
1806
|
);
|
|
1582
1807
|
for (let r = 0; r < e.batch.length; r++) {
|
|
1583
1808
|
const o = e.batch[r];
|
|
1584
|
-
if (
|
|
1809
|
+
if (ne(o.hashlock, `batch[${r}].hashlock`), !Number.isInteger(o.htlcVout) || o.htlcVout !== r)
|
|
1585
1810
|
throw new Error(
|
|
1586
1811
|
`batch[${r}].htlcVout must equal ${r} (contiguous vout-ordered vector), got ${o.htlcVout}`
|
|
1587
1812
|
);
|
|
@@ -1599,27 +1824,27 @@ function Fr(e) {
|
|
|
1599
1824
|
throw new Error(
|
|
1600
1825
|
`batch[${e.htlcVout}].amount (${t.amount}) does not match target amount (${e.amount})`
|
|
1601
1826
|
);
|
|
1602
|
-
if (
|
|
1827
|
+
if (re(e.offchainParamsVersion, "offchainParamsVersion"), re(e.appVaultKeepersVersion, "appVaultKeepersVersion"), re(
|
|
1603
1828
|
e.universalChallengersVersion,
|
|
1604
1829
|
"universalChallengersVersion"
|
|
1605
|
-
),
|
|
1830
|
+
), qt(
|
|
1606
1831
|
e.vaultCoreVersion,
|
|
1607
1832
|
"VaultRefundData.vaultCoreVersion"
|
|
1608
1833
|
), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
|
|
1609
1834
|
throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
|
|
1610
|
-
if (!
|
|
1835
|
+
if (!ho.test(e.unsignedPrePeginTxHex))
|
|
1611
1836
|
throw new Error(
|
|
1612
1837
|
"unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
|
|
1613
1838
|
);
|
|
1614
|
-
if (!e.depositorBtcPubkey || !
|
|
1839
|
+
if (!e.depositorBtcPubkey || !nt.test(e.depositorBtcPubkey))
|
|
1615
1840
|
throw new Error(
|
|
1616
1841
|
"depositorBtcPubkey must be 32 or 33 bytes of hex (optional 0x prefix)"
|
|
1617
1842
|
);
|
|
1618
1843
|
if (typeof e.amount != "bigint" || e.amount <= 0n)
|
|
1619
1844
|
throw new Error(`amount must be a positive bigint, got ${e.amount}`);
|
|
1620
1845
|
}
|
|
1621
|
-
function
|
|
1622
|
-
if (!e.vaultProviderPubkey || !
|
|
1846
|
+
function yo(e) {
|
|
1847
|
+
if (!e.vaultProviderPubkey || !nt.test(e.vaultProviderPubkey))
|
|
1623
1848
|
throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
|
|
1624
1849
|
if (e.vaultKeeperPubkeys.length === 0)
|
|
1625
1850
|
throw new Error("vaultKeeperPubkeys must be non-empty");
|
|
@@ -1644,60 +1869,60 @@ function Ur(e) {
|
|
|
1644
1869
|
`councilQuorum (${e.councilQuorum}) must be in [1, councilSize=${e.councilSize}]`
|
|
1645
1870
|
);
|
|
1646
1871
|
}
|
|
1647
|
-
async function
|
|
1872
|
+
async function an(e) {
|
|
1648
1873
|
const {
|
|
1649
1874
|
vaultId: t,
|
|
1650
1875
|
readVault: r,
|
|
1651
1876
|
readPrePeginContext: o,
|
|
1652
1877
|
feeRate: n,
|
|
1653
|
-
signPsbt:
|
|
1878
|
+
signPsbt: a,
|
|
1654
1879
|
broadcastTx: s,
|
|
1655
1880
|
signal: i
|
|
1656
1881
|
} = e;
|
|
1657
|
-
i == null || i.throwIfAborted(),
|
|
1658
|
-
const
|
|
1659
|
-
|
|
1660
|
-
const c = await o(
|
|
1661
|
-
if (
|
|
1882
|
+
i == null || i.throwIfAborted(), ne(t, "vaultId");
|
|
1883
|
+
const u = await r();
|
|
1884
|
+
fo(u), i == null || i.throwIfAborted();
|
|
1885
|
+
const c = await o(u);
|
|
1886
|
+
if (yo(c), i == null || i.throwIfAborted(), !Number.isFinite(n) || n <= 0)
|
|
1662
1887
|
throw new Error(`feeRate must be a positive number, got ${n}`);
|
|
1663
|
-
if (n >
|
|
1888
|
+
if (n > Ce)
|
|
1664
1889
|
throw new Error(
|
|
1665
|
-
`feeRate ${n} sat/vB exceeds refund safety cap ${
|
|
1890
|
+
`feeRate ${n} sat/vB exceeds refund safety cap ${Ce} sat/vB; refusing to sign refund.`
|
|
1666
1891
|
);
|
|
1667
|
-
const h = BigInt(Math.ceil(n *
|
|
1892
|
+
const h = BigInt(Math.ceil(n * st)), l = u.amount * Se / Ie;
|
|
1668
1893
|
if (h > l)
|
|
1669
1894
|
throw new Error(
|
|
1670
|
-
`Refund fee ${h} sats exceeds the per-vault safety cap of ${l} sats (${
|
|
1895
|
+
`Refund fee ${h} sats exceeds the per-vault safety cap of ${l} sats (${Se}/${Ie} of vault.amount=${u.amount}); refusing to sign refund.`
|
|
1671
1896
|
);
|
|
1672
1897
|
i == null || i.throwIfAborted();
|
|
1673
|
-
const
|
|
1674
|
-
|
|
1675
|
-
),
|
|
1676
|
-
if (g !== void 0 && g.vout !==
|
|
1898
|
+
const p = j(
|
|
1899
|
+
u.depositorBtcPubkey
|
|
1900
|
+
), d = f(u.unsignedPrePeginTxHex), g = gt(d);
|
|
1901
|
+
if (g !== void 0 && g.vout !== u.batch.length)
|
|
1677
1902
|
throw new Error(
|
|
1678
|
-
`Auth-anchor OP_RETURN at vout ${g.vout} does not match batch size (${
|
|
1903
|
+
`Auth-anchor OP_RETURN at vout ${g.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.`
|
|
1679
1904
|
);
|
|
1680
1905
|
const b = g == null ? void 0 : g.hash;
|
|
1681
|
-
let
|
|
1906
|
+
let y;
|
|
1682
1907
|
try {
|
|
1683
|
-
|
|
1684
|
-
} catch (
|
|
1908
|
+
y = B.fromHex(d);
|
|
1909
|
+
} catch (P) {
|
|
1685
1910
|
throw new Error(
|
|
1686
|
-
`Failed to parse funded Pre-PegIn transaction hex: ${
|
|
1911
|
+
`Failed to parse funded Pre-PegIn transaction hex: ${P instanceof Error ? P.message : String(P)}`
|
|
1687
1912
|
);
|
|
1688
1913
|
}
|
|
1689
|
-
if (
|
|
1914
|
+
if (y.outs.length < u.batch.length)
|
|
1690
1915
|
throw new Error(
|
|
1691
|
-
`Funded Pre-PegIn tx has ${
|
|
1916
|
+
`Funded Pre-PegIn tx has ${y.outs.length} outputs but batch requires at least ${u.batch.length} HTLC outputs. Refund refused — funded tx shape disagrees with sibling vector.`
|
|
1692
1917
|
);
|
|
1693
|
-
const { psbtHex:
|
|
1918
|
+
const { psbtHex: m } = await Gt({
|
|
1694
1919
|
prePeginParams: {
|
|
1695
|
-
vaultCoreVersion:
|
|
1696
|
-
depositorPubkey:
|
|
1697
|
-
vaultProviderPubkey:
|
|
1698
|
-
vaultKeeperPubkeys: c.vaultKeeperPubkeys.map(
|
|
1699
|
-
universalChallengerPubkeys: c.universalChallengerPubkeys.map(
|
|
1700
|
-
hashlocks:
|
|
1920
|
+
vaultCoreVersion: u.vaultCoreVersion,
|
|
1921
|
+
depositorPubkey: p,
|
|
1922
|
+
vaultProviderPubkey: f(c.vaultProviderPubkey),
|
|
1923
|
+
vaultKeeperPubkeys: c.vaultKeeperPubkeys.map(f),
|
|
1924
|
+
universalChallengerPubkeys: c.universalChallengerPubkeys.map(f),
|
|
1925
|
+
hashlocks: u.batch.map((P) => f(P.hashlock)),
|
|
1701
1926
|
timelockRefund: c.timelockRefund,
|
|
1702
1927
|
// `batch[i].amount` is the on-chain vault deposit (peg-in) amount, which
|
|
1703
1928
|
// is exactly what WASM's `pegInAmounts` expects — it re-adds the protocol
|
|
@@ -1705,7 +1930,7 @@ async function $o(e) {
|
|
|
1705
1930
|
// HTLC output. `buildRefundPsbt`'s value cross-check then binds the result
|
|
1706
1931
|
// to the funded tx bytes, refusing the refund if the template's HTLC value
|
|
1707
1932
|
// disagrees with the on-chain commitment.
|
|
1708
|
-
pegInAmounts:
|
|
1933
|
+
pegInAmounts: u.batch.map((P) => P.amount),
|
|
1709
1934
|
feeRate: c.feeRate,
|
|
1710
1935
|
minPeginFeeRate: c.minPeginFeeRate,
|
|
1711
1936
|
numLocalChallengers: c.numLocalChallengers,
|
|
@@ -1714,206 +1939,209 @@ async function $o(e) {
|
|
|
1714
1939
|
network: c.network,
|
|
1715
1940
|
authAnchorHash: b
|
|
1716
1941
|
},
|
|
1717
|
-
fundedPrePeginTxHex:
|
|
1718
|
-
htlcVout:
|
|
1942
|
+
fundedPrePeginTxHex: d,
|
|
1943
|
+
htlcVout: u.htlcVout,
|
|
1719
1944
|
refundFee: h,
|
|
1720
1945
|
// buildRefundPsbt's top-level `hashlock` param is documented as "no 0x
|
|
1721
1946
|
// prefix" and flows into the WASM HTLC connector derivation; a prefixed
|
|
1722
1947
|
// value would derive the wrong refund script leaf and yield an
|
|
1723
1948
|
// unspendable PSBT. Match the `hashlocks` array handling above.
|
|
1724
|
-
hashlock:
|
|
1949
|
+
hashlock: f(u.hashlock)
|
|
1725
1950
|
});
|
|
1726
1951
|
i == null || i.throwIfAborted();
|
|
1727
|
-
const
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
), w = await
|
|
1731
|
-
|
|
1732
|
-
requestedPsbtHex:
|
|
1952
|
+
const x = M(
|
|
1953
|
+
u.depositorBtcPubkey,
|
|
1954
|
+
po
|
|
1955
|
+
), w = await a(m, x);
|
|
1956
|
+
F({
|
|
1957
|
+
requestedPsbtHex: m,
|
|
1733
1958
|
returnedPsbtHex: w
|
|
1734
1959
|
});
|
|
1735
|
-
const
|
|
1960
|
+
const k = 0, _ = U(
|
|
1736
1961
|
w,
|
|
1737
|
-
|
|
1738
|
-
|
|
1962
|
+
p,
|
|
1963
|
+
k
|
|
1739
1964
|
);
|
|
1740
|
-
|
|
1741
|
-
requestedPsbtHex:
|
|
1742
|
-
signatureHex:
|
|
1743
|
-
signerXOnlyPubkeyHex:
|
|
1744
|
-
inputIndex:
|
|
1965
|
+
L({
|
|
1966
|
+
requestedPsbtHex: m,
|
|
1967
|
+
signatureHex: _,
|
|
1968
|
+
signerXOnlyPubkeyHex: p,
|
|
1969
|
+
inputIndex: k
|
|
1745
1970
|
});
|
|
1746
|
-
const
|
|
1747
|
-
requestedPsbtHex:
|
|
1748
|
-
signaturesHex: [
|
|
1749
|
-
signerXOnlyPubkeyHex:
|
|
1971
|
+
const A = Le({
|
|
1972
|
+
requestedPsbtHex: m,
|
|
1973
|
+
signaturesHex: [_],
|
|
1974
|
+
signerXOnlyPubkeyHex: p
|
|
1750
1975
|
});
|
|
1751
1976
|
i == null || i.throwIfAborted();
|
|
1752
1977
|
try {
|
|
1753
|
-
return await s(
|
|
1754
|
-
} catch (
|
|
1755
|
-
throw
|
|
1978
|
+
return await s(A);
|
|
1979
|
+
} catch (P) {
|
|
1980
|
+
throw P instanceof Error && go.test(P.message) ? new co(t, P) : P;
|
|
1756
1981
|
}
|
|
1757
1982
|
}
|
|
1758
|
-
class
|
|
1983
|
+
class Re extends Error {
|
|
1759
1984
|
constructor(r, o, n) {
|
|
1760
1985
|
super(r);
|
|
1761
1986
|
/** Fee the reclaim would have paid, in satoshis. */
|
|
1762
|
-
|
|
1987
|
+
O(this, "feeSats");
|
|
1763
1988
|
/** Sum of the reserves the reclaim would have swept, in satoshis. */
|
|
1764
|
-
|
|
1989
|
+
O(this, "sweptTotalSats");
|
|
1765
1990
|
this.name = "ReclaimUneconomicalError", this.feeSats = o, this.sweptTotalSats = n;
|
|
1766
1991
|
}
|
|
1767
1992
|
}
|
|
1768
|
-
const
|
|
1769
|
-
async function
|
|
1993
|
+
const Be = 2e3, Ve = 25n, Oe = 100n, un = 10n;
|
|
1994
|
+
async function bo(e, t, r) {
|
|
1770
1995
|
for (let o = 0; o < e.length; o++) {
|
|
1771
|
-
const n =
|
|
1772
|
-
await
|
|
1773
|
-
|
|
1774
|
-
|
|
1996
|
+
const n = yt(e[o].depositorSignedPeginTxHex), a = He(
|
|
1997
|
+
await Ct(
|
|
1998
|
+
f(n),
|
|
1999
|
+
f(r)
|
|
1775
2000
|
)
|
|
1776
2001
|
).toLowerCase();
|
|
1777
|
-
if (
|
|
2002
|
+
if (a !== t[o].toLowerCase())
|
|
1778
2003
|
throw new Error(
|
|
1779
|
-
`Reserve ${o} belongs to vault ${
|
|
2004
|
+
`Reserve ${o} belongs to vault ${a}, not the requested ${t[o].toLowerCase()}. Refusing to sweep a reserve whose vault is not the one the caller asked for — the reserve funds that vault's claim transaction and cannot be replaced.`
|
|
1780
2005
|
);
|
|
1781
2006
|
}
|
|
1782
2007
|
}
|
|
1783
|
-
async function
|
|
2008
|
+
async function cn(e) {
|
|
1784
2009
|
const {
|
|
1785
2010
|
vaultIds: t,
|
|
1786
2011
|
depositorEthAddress: r,
|
|
1787
2012
|
depositorBtcPubkey: o,
|
|
1788
2013
|
readVaults: n,
|
|
1789
|
-
feeRate:
|
|
2014
|
+
feeRate: a,
|
|
1790
2015
|
signPsbt: s,
|
|
1791
2016
|
broadcastTx: i,
|
|
1792
|
-
signal:
|
|
2017
|
+
signal: u
|
|
1793
2018
|
} = e;
|
|
1794
|
-
if (
|
|
2019
|
+
if (u == null || u.throwIfAborted(), t.length === 0)
|
|
1795
2020
|
throw new Error("Reclaim requires at least one vault id; got none.");
|
|
1796
|
-
if (!Number.isFinite(
|
|
1797
|
-
throw new Error(`feeRate must be a positive number, got ${
|
|
1798
|
-
if (
|
|
1799
|
-
throw new
|
|
1800
|
-
`Fee rate ${
|
|
2021
|
+
if (!Number.isFinite(a) || a <= 0)
|
|
2022
|
+
throw new Error(`feeRate must be a positive number, got ${a}`);
|
|
2023
|
+
if (a > Be)
|
|
2024
|
+
throw new Re(
|
|
2025
|
+
`Fee rate ${a} sat/vB exceeds the reclaim safety cap of ${Be} sat/vB; refusing to sign.`,
|
|
1801
2026
|
0n,
|
|
1802
2027
|
0n
|
|
1803
2028
|
);
|
|
1804
2029
|
const c = await n();
|
|
1805
|
-
if (
|
|
2030
|
+
if (u == null || u.throwIfAborted(), c.length !== t.length)
|
|
1806
2031
|
throw new Error(
|
|
1807
2032
|
`readVaults returned ${c.length} reserves for ${t.length} vault id(s); refusing to sweep a set that does not match the request.`
|
|
1808
2033
|
);
|
|
1809
|
-
await
|
|
1810
|
-
const h =
|
|
1811
|
-
depositorSignedPeginTxHex:
|
|
1812
|
-
observed:
|
|
1813
|
-
expectedValue:
|
|
1814
|
-
})),
|
|
1815
|
-
if (
|
|
1816
|
-
throw new
|
|
1817
|
-
`Reclaim fee ${
|
|
1818
|
-
|
|
1819
|
-
|
|
2034
|
+
await bo(c, t, r), u == null || u.throwIfAborted();
|
|
2035
|
+
const h = j(o), l = c.map((k) => ({
|
|
2036
|
+
depositorSignedPeginTxHex: k.depositorSignedPeginTxHex,
|
|
2037
|
+
observed: k.observed,
|
|
2038
|
+
expectedValue: k.expectedClaimValue
|
|
2039
|
+
})), p = Xt(a, l.length), d = l.reduce((k, _) => k + _.expectedValue, 0n), g = d * Ve / Oe;
|
|
2040
|
+
if (p > g)
|
|
2041
|
+
throw new Re(
|
|
2042
|
+
`Reclaim fee ${p} sats exceeds ${Ve}/${Oe} of the swept total (${d} sats, cap ${g} sats). The reserve is not at risk — it stays where it is until fee rates fall.`,
|
|
2043
|
+
p,
|
|
2044
|
+
d
|
|
1820
2045
|
);
|
|
1821
|
-
|
|
1822
|
-
const { psbtHex: b } =
|
|
2046
|
+
u == null || u.throwIfAborted();
|
|
2047
|
+
const { psbtHex: b } = jt({
|
|
1823
2048
|
depositorPubkey: h,
|
|
1824
2049
|
inputs: l,
|
|
1825
|
-
feeSats:
|
|
2050
|
+
feeSats: p
|
|
1826
2051
|
});
|
|
1827
|
-
|
|
1828
|
-
const
|
|
2052
|
+
u == null || u.throwIfAborted();
|
|
2053
|
+
const y = M(
|
|
1829
2054
|
o,
|
|
1830
2055
|
l.length
|
|
1831
|
-
),
|
|
1832
|
-
|
|
2056
|
+
), m = await s(b, y);
|
|
2057
|
+
F({
|
|
1833
2058
|
requestedPsbtHex: b,
|
|
1834
|
-
returnedPsbtHex:
|
|
2059
|
+
returnedPsbtHex: m
|
|
1835
2060
|
});
|
|
1836
|
-
const
|
|
1837
|
-
const
|
|
1838
|
-
|
|
2061
|
+
const x = l.map((k, _) => {
|
|
2062
|
+
const A = U(
|
|
2063
|
+
m,
|
|
1839
2064
|
h,
|
|
1840
|
-
|
|
2065
|
+
_
|
|
1841
2066
|
);
|
|
1842
|
-
return
|
|
2067
|
+
return L({
|
|
1843
2068
|
requestedPsbtHex: b,
|
|
1844
|
-
signatureHex:
|
|
2069
|
+
signatureHex: A,
|
|
1845
2070
|
signerXOnlyPubkeyHex: h,
|
|
1846
|
-
inputIndex:
|
|
1847
|
-
}),
|
|
1848
|
-
}), w =
|
|
2071
|
+
inputIndex: _
|
|
2072
|
+
}), A;
|
|
2073
|
+
}), w = Le({
|
|
1849
2074
|
requestedPsbtHex: b,
|
|
1850
|
-
signaturesHex:
|
|
2075
|
+
signaturesHex: x,
|
|
1851
2076
|
signerXOnlyPubkeyHex: h
|
|
1852
2077
|
});
|
|
1853
|
-
return
|
|
2078
|
+
return u == null || u.throwIfAborted(), i(w);
|
|
1854
2079
|
}
|
|
1855
2080
|
export {
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
2081
|
+
an as $,
|
|
2082
|
+
mr as A,
|
|
2083
|
+
Qo as B,
|
|
2084
|
+
Zt as C,
|
|
2085
|
+
br as D,
|
|
2086
|
+
Yo as E,
|
|
2087
|
+
oo as F,
|
|
2088
|
+
v as G,
|
|
2089
|
+
no as H,
|
|
2090
|
+
tt as I,
|
|
2091
|
+
Zo as J,
|
|
2092
|
+
en as K,
|
|
2093
|
+
tn as L,
|
|
2094
|
+
rn as M,
|
|
2095
|
+
Je as N,
|
|
2096
|
+
Xo as O,
|
|
2097
|
+
tr as P,
|
|
2098
|
+
Z as Q,
|
|
2099
|
+
rt as R,
|
|
2100
|
+
Jr as S,
|
|
2101
|
+
_e as T,
|
|
2102
|
+
eo as U,
|
|
2103
|
+
nr as V,
|
|
2104
|
+
to as W,
|
|
2105
|
+
ot as X,
|
|
2106
|
+
on as Y,
|
|
2107
|
+
nn as Z,
|
|
2108
|
+
co as _,
|
|
2109
|
+
Oo as a,
|
|
2110
|
+
sn as a0,
|
|
2111
|
+
Ie as a1,
|
|
2112
|
+
Se as a2,
|
|
2113
|
+
Ce as a3,
|
|
2114
|
+
st as a4,
|
|
2115
|
+
Re as a5,
|
|
2116
|
+
cn as a6,
|
|
2117
|
+
Oe as a7,
|
|
2118
|
+
Ve as a8,
|
|
2119
|
+
Be as a9,
|
|
2120
|
+
un as aa,
|
|
2121
|
+
No as b,
|
|
2122
|
+
Ho as c,
|
|
2123
|
+
Ko as d,
|
|
2124
|
+
Do as e,
|
|
2125
|
+
er as f,
|
|
2126
|
+
rr as g,
|
|
2127
|
+
qe as h,
|
|
2128
|
+
xr as i,
|
|
2129
|
+
We as j,
|
|
2130
|
+
Ye as k,
|
|
2131
|
+
Tr as l,
|
|
2132
|
+
Mo as m,
|
|
2133
|
+
Uo as n,
|
|
2134
|
+
Vr as o,
|
|
2135
|
+
Ur as p,
|
|
2136
|
+
Go as q,
|
|
2137
|
+
Lo as r,
|
|
2138
|
+
Pr as s,
|
|
2139
|
+
oe as t,
|
|
2140
|
+
jo as u,
|
|
2141
|
+
qo as v,
|
|
2142
|
+
Fo as w,
|
|
2143
|
+
zo as x,
|
|
2144
|
+
Wo as y,
|
|
2145
|
+
Jo as z
|
|
1918
2146
|
};
|
|
1919
|
-
//# sourceMappingURL=buildAndBroadcastReclaim-
|
|
2147
|
+
//# sourceMappingURL=buildAndBroadcastReclaim-B19cyK69.js.map
|