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