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