@babylonlabs-io/ts-sdk 3.1.2 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BTCVaultRegistry.abi-BH2-LHxN.cjs +2 -0
- package/dist/BTCVaultRegistry.abi-BH2-LHxN.cjs.map +1 -0
- package/dist/{BTCVaultRegistry.abi-BmHpMUWD.js → BTCVaultRegistry.abi-BzNTa_EU.js} +19 -1
- package/dist/BTCVaultRegistry.abi-BzNTa_EU.js.map +1 -0
- package/dist/{PeginManager-PyKbfy5q.cjs → PeginManager-BHplS4dM.cjs} +2 -2
- package/dist/{PeginManager-PyKbfy5q.cjs.map → PeginManager-BHplS4dM.cjs.map} +1 -1
- package/dist/{PeginManager-Dfr5Qe1g.js → PeginManager-DcwGom01.js} +2 -2
- package/dist/{PeginManager-Dfr5Qe1g.js.map → PeginManager-DcwGom01.js.map} +1 -1
- package/dist/buildAndBroadcastReclaim-C7bq5wNM.cjs +2 -0
- package/dist/buildAndBroadcastReclaim-C7bq5wNM.cjs.map +1 -0
- package/dist/{buildAndBroadcastReclaim-R0HNpLMD.js → buildAndBroadcastReclaim-CcQ0b1be.js} +466 -456
- package/dist/buildAndBroadcastReclaim-CcQ0b1be.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +74 -74
- package/dist/pegin-registration-client-BogzOk8B.cjs +2 -0
- package/dist/pegin-registration-client-BogzOk8B.cjs.map +1 -0
- package/dist/{pegin-registration-client-kdz4fT5_.js → pegin-registration-client-DvyrUNku.js} +44 -43
- package/dist/pegin-registration-client-DvyrUNku.js.map +1 -0
- package/dist/peginState-CIibG9S_.js +75 -0
- package/dist/peginState-CIibG9S_.js.map +1 -0
- package/dist/peginState-IyE22wWh.cjs +2 -0
- package/dist/peginState-IyE22wWh.cjs.map +1 -0
- package/dist/{reservation-DOAHVT3B.js → reservation-BZQABu4g.js} +2 -2
- package/dist/{reservation-DOAHVT3B.js.map → reservation-BZQABu4g.js.map} +1 -1
- package/dist/{reservation-ECxjZi5t.cjs → reservation-CA5knoQ0.cjs} +2 -2
- package/dist/{reservation-ECxjZi5t.cjs.map → reservation-CA5knoQ0.cjs.map} +1 -1
- package/dist/{signer-set-reader-DFAu6I-v.cjs → signer-set-reader-D-CyIYR5.cjs} +2 -2
- package/dist/{signer-set-reader-DFAu6I-v.cjs.map → signer-set-reader-D-CyIYR5.cjs.map} +1 -1
- package/dist/{signer-set-reader-BCtmSKUM.js → signer-set-reader-DFF9MgQN.js} +2 -2
- package/dist/{signer-set-reader-BCtmSKUM.js.map → signer-set-reader-DFF9MgQN.js.map} +1 -1
- 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 +8 -0
- package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
- 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 +2 -2
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts +14 -0
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts.map +1 -1
- package/dist/tbv/core/contracts/index.cjs +1 -1
- package/dist/tbv/core/contracts/index.js +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +84 -84
- package/dist/tbv/core/managers/index.cjs +1 -1
- package/dist/tbv/core/managers/index.js +1 -1
- package/dist/tbv/core/services/activation/activateVault.d.ts +50 -0
- package/dist/tbv/core/services/activation/activateVault.d.ts.map +1 -1
- package/dist/tbv/core/services/activation/index.d.ts +1 -1
- package/dist/tbv/core/services/activation/index.d.ts.map +1 -1
- package/dist/tbv/core/services/delegated-claim/__tests__/realWasmWatchtowerArtifacts.test.d.ts +9 -0
- package/dist/tbv/core/services/delegated-claim/__tests__/realWasmWatchtowerArtifacts.test.d.ts.map +1 -0
- package/dist/tbv/core/services/delegated-claim/assembleWatchtowerArtifacts.d.ts +5 -7
- package/dist/tbv/core/services/delegated-claim/assembleWatchtowerArtifacts.d.ts.map +1 -1
- package/dist/tbv/core/services/delegated-claim/index.d.ts +3 -4
- package/dist/tbv/core/services/delegated-claim/index.d.ts.map +1 -1
- package/dist/tbv/core/services/delegated-claim/planDelegatedClaimSigning.d.ts.map +1 -1
- package/dist/tbv/core/services/delegated-claim/readWatchtowerArtifacts.d.ts +14 -8
- package/dist/tbv/core/services/delegated-claim/readWatchtowerArtifacts.d.ts.map +1 -1
- package/dist/tbv/core/services/delegated-claim/types.d.ts +32 -19
- package/dist/tbv/core/services/delegated-claim/types.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/peginState.d.ts +20 -1
- package/dist/tbv/core/services/deposit/peginState.d.ts.map +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +58 -58
- package/dist/tbv/core/utils/index.cjs +1 -1
- package/dist/tbv/core/utils/index.js +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +84 -84
- package/dist/{toRefundInputs-BbAOOUg6.cjs → toRefundInputs-8DgBT_Bg.cjs} +2 -2
- package/dist/{toRefundInputs-BbAOOUg6.cjs.map → toRefundInputs-8DgBT_Bg.cjs.map} +1 -1
- package/dist/{toRefundInputs-DW14g6wH.js → toRefundInputs-CCMNAoRx.js} +2 -2
- package/dist/{toRefundInputs-DW14g6wH.js.map → toRefundInputs-CCMNAoRx.js.map} +1 -1
- package/dist/types-Bda75Od0.cjs.map +1 -1
- package/dist/types-C5jj3Cc-.js.map +1 -1
- package/package.json +1 -1
- package/dist/BTCVaultRegistry.abi-BmHpMUWD.js.map +0 -1
- package/dist/BTCVaultRegistry.abi-DffWFdpA.cjs +0 -2
- package/dist/BTCVaultRegistry.abi-DffWFdpA.cjs.map +0 -1
- package/dist/buildAndBroadcastReclaim-Da8rD5Z7.cjs +0 -2
- package/dist/buildAndBroadcastReclaim-Da8rD5Z7.cjs.map +0 -1
- package/dist/buildAndBroadcastReclaim-R0HNpLMD.js.map +0 -1
- package/dist/pegin-registration-client-C-abxMWq.cjs +0 -2
- package/dist/pegin-registration-client-C-abxMWq.cjs.map +0 -1
- package/dist/pegin-registration-client-kdz4fT5_.js.map +0 -1
- package/dist/peginState-BU2ONFXF.js +0 -68
- package/dist/peginState-BU2ONFXF.js.map +0 -1
- package/dist/peginState-DUv10EJR.cjs +0 -2
- package/dist/peginState-DUv10EJR.cjs.map +0 -1
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
var
|
|
2
|
-
var Zt = (e, t, r) => t in e ?
|
|
1
|
+
var Qt = Object.defineProperty;
|
|
2
|
+
var Zt = (e, t, r) => t in e ? Qt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
3
|
var z = (e, t, r) => Zt(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
-
import { B as
|
|
5
|
-
import { e as
|
|
6
|
-
import { v as rr, s as
|
|
7
|
-
import { verifyWatchtowerArtifacts as nr, buildClaimPsbt as ir, buildAssertClaimerPsbt as ar, buildPayoutClaimerPsbt as ur, buildWronglyChallengedPsbts as cr, buildPayoutDepositorPsbt as lr, finalizeClaimTx as dr, buildWatchtowerArtifacts as hr, extractTapScriptSig as
|
|
8
|
-
import { m as vr, d as Pt, k as br, a as _e, V as
|
|
4
|
+
import { B as Be } from "./BTCVaultRegistry.abi-BzNTa_EU.js";
|
|
5
|
+
import { e as Ie, s as b, i as er, u as Ve, c as _, v as tr, p as he, f as O } from "./bitcoin-C-TuHb-v.js";
|
|
6
|
+
import { v as rr, s as vt, b as bt, P as or, d as sr } from "./PayoutManager-BZ212yml.js";
|
|
7
|
+
import { verifyWatchtowerArtifacts as nr, buildClaimPsbt as ir, buildAssertClaimerPsbt as ar, buildPayoutClaimerPsbt as ur, buildWronglyChallengedPsbts as cr, buildPayoutDepositorPsbt as lr, finalizeClaimTx as dr, buildWatchtowerArtifacts as hr, extractTapScriptSig as mt, expandWotsSeed as pr, wotsKeypairFromSeed as gr, validateWotsKeypairAgainstGraph as fr, deriveVaultId as yr } from "./tbv/core/wasm/index.js";
|
|
8
|
+
import { m as vr, d as Pt, k as br, a as _e, V as Fe, i as mr, g as Pr, f as wr, r as xr, h as Er } from "./registration-records-CKLAv3gw.js";
|
|
9
9
|
import { Psbt as q, Transaction as S } from "bitcoinjs-lib";
|
|
10
|
-
import { q as F, r as A, s as ee, C as Y, A as te, p as
|
|
11
|
-
import { p as kr, q as
|
|
10
|
+
import { q as F, r as A, s as ee, C as Y, A as te, p as J, t as pe, l as Ue, N as Q, u as Re, m as qe, n as Xe, o as Ge, W as $r, D as ze } from "./constants-BeYquVd-.js";
|
|
11
|
+
import { p as kr, q as Tr, r as wt, P as X, j as re, f as Cr, i as ie, g as ae } from "./verifyScriptPathSchnorrSignature-B3-VkvnK.js";
|
|
12
12
|
import { Buffer as H } from "buffer";
|
|
13
|
-
import { C as
|
|
14
|
-
import { a as
|
|
15
|
-
import { d as
|
|
16
|
-
import { O as
|
|
13
|
+
import { C as xt, X as Et } from "./validation-OSC0xTHB.js";
|
|
14
|
+
import { a as $t, c as ue } from "./signing-C1rR4tqs.js";
|
|
15
|
+
import { d as kt } from "./deriveVaultRoot-BcvmER1E.js";
|
|
16
|
+
import { O as je, d as _r } from "./types-C5jj3Cc-.js";
|
|
17
17
|
import { zeroAddress as Sr, isAddress as Ar, isAddressEqual as Br } from "viem";
|
|
18
|
-
import { v as
|
|
19
|
-
import { h as
|
|
20
|
-
import { d as
|
|
18
|
+
import { v as We, D as R, c as Ir, b as Vr, R as Rr, d as Tt } from "./state-CFn1rT74.js";
|
|
19
|
+
import { h as Ye, b as Kr, s as Hr, j as Nr } from "./sha2-YqVHJiFj.js";
|
|
20
|
+
import { d as Or, c as Dr, b as Mr, f as Ct, e as Lr, a as Fr } from "./noPayout-B-vGXJ-V.js";
|
|
21
21
|
import { a as Ur } from "./secp256k1-BuxBFUHm.js";
|
|
22
22
|
import { c as qr } from "./btcTxHash-BRZ8_EZq.js";
|
|
23
23
|
const Xr = /^0x[0-9a-fA-F]{64}$/, Gr = /^0x[0-9a-fA-F]{40}$/, zr = /^0x([0-9a-fA-F]{2})*$/;
|
|
@@ -43,16 +43,16 @@ function Wr(e, t) {
|
|
|
43
43
|
`${t} must be a 0x-prefixed hex string with an even number of hex chars`
|
|
44
44
|
);
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function Ke(e) {
|
|
47
47
|
jr(e.btcVaultRegistryAddress, "btcVaultRegistryAddress"), fe(e.vaultId, "vaultId");
|
|
48
|
-
const t =
|
|
48
|
+
const t = Ie(e.secret);
|
|
49
49
|
if (fe(t, "secret"), e.hashlock !== void 0 && (fe(e.hashlock, "hashlock"), !rr(t, e.hashlock)))
|
|
50
50
|
throw new Error(
|
|
51
51
|
"Invalid secret: SHA256(secret) does not match the provided hashlock"
|
|
52
52
|
);
|
|
53
53
|
return t;
|
|
54
54
|
}
|
|
55
|
-
async function
|
|
55
|
+
async function Js(e) {
|
|
56
56
|
const {
|
|
57
57
|
btcVaultRegistryAddress: t,
|
|
58
58
|
vaultId: r,
|
|
@@ -62,7 +62,7 @@ async function Ys(e) {
|
|
|
62
62
|
signal: a
|
|
63
63
|
} = e;
|
|
64
64
|
a == null || a.throwIfAborted();
|
|
65
|
-
const i =
|
|
65
|
+
const i = Ke({
|
|
66
66
|
btcVaultRegistryAddress: t,
|
|
67
67
|
vaultId: r,
|
|
68
68
|
secret: e.secret,
|
|
@@ -70,7 +70,7 @@ async function Ys(e) {
|
|
|
70
70
|
});
|
|
71
71
|
return Wr(s, "activationMetadata"), n({
|
|
72
72
|
address: t,
|
|
73
|
-
abi:
|
|
73
|
+
abi: Be,
|
|
74
74
|
functionName: "activateVaultWithSecret",
|
|
75
75
|
args: [r, i, s]
|
|
76
76
|
});
|
|
@@ -78,7 +78,7 @@ async function Ys(e) {
|
|
|
78
78
|
async function Qs(e) {
|
|
79
79
|
const { btcVaultRegistryAddress: t, vaultId: r, hashlock: o, writeContract: s, signal: n } = e;
|
|
80
80
|
n == null || n.throwIfAborted();
|
|
81
|
-
const a =
|
|
81
|
+
const a = Ke({
|
|
82
82
|
btcVaultRegistryAddress: t,
|
|
83
83
|
vaultId: r,
|
|
84
84
|
secret: e.secret,
|
|
@@ -86,11 +86,28 @@ async function Qs(e) {
|
|
|
86
86
|
});
|
|
87
87
|
return s({
|
|
88
88
|
address: t,
|
|
89
|
-
abi:
|
|
89
|
+
abi: Be,
|
|
90
90
|
functionName: "activateVaultWithSecretAndRedeem",
|
|
91
91
|
args: [r, a]
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
|
+
async function Zs(e) {
|
|
95
|
+
const { btcVaultRegistryAddress: t, vaultId: r, hashlock: o, writeContract: s, signal: n } = e;
|
|
96
|
+
if (n == null || n.throwIfAborted(), typeof o != "string")
|
|
97
|
+
throw new Error("hashlock is required to claim an expired vault");
|
|
98
|
+
const a = Ke({
|
|
99
|
+
btcVaultRegistryAddress: t,
|
|
100
|
+
vaultId: r,
|
|
101
|
+
secret: e.secret,
|
|
102
|
+
hashlock: o
|
|
103
|
+
});
|
|
104
|
+
return s({
|
|
105
|
+
address: t,
|
|
106
|
+
abi: Be,
|
|
107
|
+
functionName: "claimExpiredVault",
|
|
108
|
+
args: [r, a]
|
|
109
|
+
});
|
|
110
|
+
}
|
|
94
111
|
class K extends Error {
|
|
95
112
|
constructor(t, r) {
|
|
96
113
|
super(t, r), this.name = "AssertBindingError";
|
|
@@ -109,7 +126,7 @@ function Yr(e, t, r) {
|
|
|
109
126
|
throw new K(`${e} PSBT has no input ${r}.`);
|
|
110
127
|
return o.hash;
|
|
111
128
|
}
|
|
112
|
-
function
|
|
129
|
+
function Je(e) {
|
|
113
130
|
return S.fromBuffer(
|
|
114
131
|
e.data.globalMap.unsignedTx.toBuffer()
|
|
115
132
|
).getHash();
|
|
@@ -123,7 +140,7 @@ function ve(e, t, r, o, s, n) {
|
|
|
123
140
|
`${e} input ${r} does not spend ${n}: the graph pairs this ${e} with a different transaction.`
|
|
124
141
|
);
|
|
125
142
|
}
|
|
126
|
-
function
|
|
143
|
+
function Jr(e, t) {
|
|
127
144
|
var s;
|
|
128
145
|
const r = (s = e.data.inputs[F]) == null ? void 0 : s.witnessUtxo;
|
|
129
146
|
if (r === void 0)
|
|
@@ -144,20 +161,20 @@ function Qr(e, t) {
|
|
|
144
161
|
`Assert input ${F} declares a prevout script that is not the Claim's output ${Y} script; refusing to sign assert.`
|
|
145
162
|
);
|
|
146
163
|
}
|
|
147
|
-
function
|
|
164
|
+
function Qr(e) {
|
|
148
165
|
const t = ye("Claim", e.claimPsbtBase64), r = ye("Assert", e.assertPsbtBase64), o = ye("Payout", e.payoutClaimerPsbtBase64);
|
|
149
166
|
ve(
|
|
150
167
|
"Assert",
|
|
151
168
|
r,
|
|
152
169
|
F,
|
|
153
|
-
|
|
170
|
+
Je(t),
|
|
154
171
|
Y,
|
|
155
172
|
"Claim:0"
|
|
156
|
-
),
|
|
173
|
+
), Jr(r, t), ve(
|
|
157
174
|
"Payout",
|
|
158
175
|
o,
|
|
159
176
|
A,
|
|
160
|
-
|
|
177
|
+
Je(r),
|
|
161
178
|
te,
|
|
162
179
|
"Assert:0"
|
|
163
180
|
), ve(
|
|
@@ -165,7 +182,7 @@ function Jr(e) {
|
|
|
165
182
|
o,
|
|
166
183
|
ee,
|
|
167
184
|
Yr("Claim", t, pe),
|
|
168
|
-
|
|
185
|
+
J,
|
|
169
186
|
"this vault's PegIn:0"
|
|
170
187
|
);
|
|
171
188
|
}
|
|
@@ -176,13 +193,13 @@ function be(e, t) {
|
|
|
176
193
|
throw new Error(`${e} PSBT cannot be parsed.`, { cause: r });
|
|
177
194
|
}
|
|
178
195
|
}
|
|
179
|
-
function
|
|
196
|
+
function Qe(e, t, r, o) {
|
|
180
197
|
var a;
|
|
181
198
|
const s = [
|
|
182
199
|
{
|
|
183
200
|
inputIndex: ee,
|
|
184
201
|
expectedSats: r,
|
|
185
|
-
source: `the vault's PegIn output ${
|
|
202
|
+
source: `the vault's PegIn output ${J}`
|
|
186
203
|
},
|
|
187
204
|
{
|
|
188
205
|
inputIndex: A,
|
|
@@ -229,9 +246,9 @@ async function Zr(e) {
|
|
|
229
246
|
throw new Error(
|
|
230
247
|
`Assert transaction has no output ${te}; the Payout's implicit fee cannot be measured.`
|
|
231
248
|
);
|
|
232
|
-
if (o.txInputs.length !==
|
|
249
|
+
if (o.txInputs.length !== Ue)
|
|
233
250
|
throw new Error(
|
|
234
|
-
`Payout transaction must have exactly ${
|
|
251
|
+
`Payout transaction must have exactly ${Ue} inputs, got ${o.txInputs.length}`
|
|
235
252
|
);
|
|
236
253
|
const i = o.txInputs[ee].sequence;
|
|
237
254
|
if (i !== t.timelockPegin)
|
|
@@ -243,21 +260,21 @@ async function Zr(e) {
|
|
|
243
260
|
throw new Error(
|
|
244
261
|
`Payout input ${A} sequence ${u} must equal the Assert CSV timelock ${t.timelockAssert}; refusing to sign payout.`
|
|
245
262
|
);
|
|
246
|
-
|
|
263
|
+
Qe(
|
|
247
264
|
"Claimer",
|
|
248
265
|
o,
|
|
249
266
|
t.peginVaultOutputValueSats,
|
|
250
267
|
a
|
|
251
|
-
),
|
|
268
|
+
), Qe(
|
|
252
269
|
"Depositor",
|
|
253
270
|
s,
|
|
254
271
|
t.peginVaultOutputValueSats,
|
|
255
272
|
a
|
|
256
273
|
);
|
|
257
274
|
const l = t.peginVaultOutputValueSats + a.value, c = o.txOutputs;
|
|
258
|
-
if (c.length !==
|
|
275
|
+
if (c.length !== Q)
|
|
259
276
|
throw new Error(
|
|
260
|
-
`Payout transaction has ${c.length} output(s), expected exactly ${
|
|
277
|
+
`Payout transaction has ${c.length} output(s), expected exactly ${Q} for a depositor-as-claimer payout.`
|
|
261
278
|
);
|
|
262
279
|
let d = 0;
|
|
263
280
|
for (const h of c) d += h.value;
|
|
@@ -265,9 +282,9 @@ async function Zr(e) {
|
|
|
265
282
|
throw new Error(
|
|
266
283
|
`Payout outputs (${d} sats) exceed inputs (${l} sats); invalid transaction.`
|
|
267
284
|
);
|
|
268
|
-
await
|
|
285
|
+
await Tr(r, {
|
|
269
286
|
implicitFeeSats: l - d,
|
|
270
|
-
out0Len: c[
|
|
287
|
+
out0Len: c[Re].script.length,
|
|
271
288
|
out1Len: void 0
|
|
272
289
|
});
|
|
273
290
|
}
|
|
@@ -279,17 +296,17 @@ class eo extends Error {
|
|
|
279
296
|
}
|
|
280
297
|
}
|
|
281
298
|
function to(e) {
|
|
282
|
-
const t =
|
|
299
|
+
const t = wt({
|
|
283
300
|
claimerBtcPubkey: e.depositorBtcPubkey,
|
|
284
301
|
depositorBtcPubkey: e.depositorBtcPubkey,
|
|
285
302
|
vaultProviderBtcPubkey: e.vaultProviderBtcPubkey,
|
|
286
303
|
vaultKeeperBtcPubkeys: e.vaultKeeperBtcPubkeys
|
|
287
|
-
}), r = e.universalChallengerBtcPubkeys.map(
|
|
304
|
+
}), r = e.universalChallengerBtcPubkeys.map(Ze), o = t.filter((c) => r.includes(c));
|
|
288
305
|
if (o.length > 0)
|
|
289
306
|
throw new Error(
|
|
290
307
|
`Cannot check the challenger set: vault keepers and universal challengers overlap (${o.join(", ")}).`
|
|
291
308
|
);
|
|
292
|
-
const s = e.graphChallengerPubkeys.map(
|
|
309
|
+
const s = e.graphChallengerPubkeys.map(Ze), n = new Set(s);
|
|
293
310
|
if (n.size !== s.length)
|
|
294
311
|
throw new Error(
|
|
295
312
|
"Transaction graph lists the same challenger more than once."
|
|
@@ -298,13 +315,13 @@ function to(e) {
|
|
|
298
315
|
if (u.length > 0 || l.length > 0)
|
|
299
316
|
throw new eo(u, l);
|
|
300
317
|
}
|
|
301
|
-
function
|
|
318
|
+
function Ze(e) {
|
|
302
319
|
return b(e).toLowerCase();
|
|
303
320
|
}
|
|
304
321
|
class ro extends Error {
|
|
305
322
|
constructor(t, r) {
|
|
306
323
|
super(
|
|
307
|
-
`Payout transaction output ${
|
|
324
|
+
`Payout transaction output ${Re} pays ${r}, not the vault's registered payout script ${t}. Refusing to sign a payout to another destination.`
|
|
308
325
|
), this.expectedScriptHex = t, this.actualScriptHex = r, this.name = "PayoutDestinationError";
|
|
309
326
|
}
|
|
310
327
|
}
|
|
@@ -316,13 +333,13 @@ function oo(e) {
|
|
|
316
333
|
throw new Error("Payout PSBT cannot be parsed.", { cause: c });
|
|
317
334
|
}
|
|
318
335
|
const { version: r, locktime: o, outs: s } = so(t);
|
|
319
|
-
if (r !==
|
|
336
|
+
if (r !== qe || o !== Xe)
|
|
320
337
|
throw new Error(
|
|
321
|
-
`Payout transaction has version ${r} and locktime ${o}, expected ${
|
|
338
|
+
`Payout transaction has version ${r} and locktime ${o}, expected ${qe} and ${Xe}.`
|
|
322
339
|
);
|
|
323
|
-
if (s.length !==
|
|
340
|
+
if (s.length !== Q)
|
|
324
341
|
throw new Error(
|
|
325
|
-
`Payout transaction has ${s.length} output(s), expected exactly ${
|
|
342
|
+
`Payout transaction has ${s.length} output(s), expected exactly ${Q} for a depositor-as-claimer payout.`
|
|
326
343
|
);
|
|
327
344
|
const n = b(
|
|
328
345
|
e.registeredPayoutScriptPubKey
|
|
@@ -331,13 +348,13 @@ function oo(e) {
|
|
|
331
348
|
throw new Error(
|
|
332
349
|
"registeredPayoutScriptPubKey is empty; the vault's on-chain payout script is required to check the Payout destination."
|
|
333
350
|
);
|
|
334
|
-
const a = s[
|
|
351
|
+
const a = s[Re].script.toString("hex").toLowerCase();
|
|
335
352
|
if (a !== n)
|
|
336
353
|
throw new ro(n, a);
|
|
337
|
-
const i = s[
|
|
338
|
-
if (i.value !==
|
|
354
|
+
const i = s[Q - 1];
|
|
355
|
+
if (i.value !== Ge)
|
|
339
356
|
throw new Error(
|
|
340
|
-
`Payout CPFP anchor value ${i.value} sats must equal ${
|
|
357
|
+
`Payout CPFP anchor value ${i.value} sats must equal ${Ge} sats.`
|
|
341
358
|
);
|
|
342
359
|
const u = b(
|
|
343
360
|
vr(b(e.depositorBtcPubkey).toLowerCase())
|
|
@@ -387,15 +404,14 @@ function no(e) {
|
|
|
387
404
|
...n.tapMerkleRoot ? { tapMerkleRoot: n.tapMerkleRoot } : {}
|
|
388
405
|
}), t.toBase64();
|
|
389
406
|
}
|
|
390
|
-
|
|
391
|
-
class ao extends Error {
|
|
407
|
+
class io extends Error {
|
|
392
408
|
constructor(t, r, o) {
|
|
393
409
|
super(
|
|
394
410
|
`Transaction graph does not belong to vault ${t}: its Claim spends PegIn ${o}, which derives vault ${r}. Refusing to sign for a graph served for another vault.`
|
|
395
411
|
), this.expectedVaultId = t, this.derivedVaultId = r, this.peginTxid = o, this.name = "VaultIdBindingError";
|
|
396
412
|
}
|
|
397
413
|
}
|
|
398
|
-
function
|
|
414
|
+
function ao(e) {
|
|
399
415
|
let t;
|
|
400
416
|
try {
|
|
401
417
|
t = q.fromBase64(e);
|
|
@@ -409,9 +425,9 @@ function uo(e) {
|
|
|
409
425
|
"Claim PSBT",
|
|
410
426
|
t.txInputs.length,
|
|
411
427
|
r.index
|
|
412
|
-
),
|
|
428
|
+
), He(r.hash);
|
|
413
429
|
}
|
|
414
|
-
function
|
|
430
|
+
function uo(e) {
|
|
415
431
|
const t = e.ins[pe];
|
|
416
432
|
if (!t)
|
|
417
433
|
throw new Error(
|
|
@@ -421,7 +437,7 @@ function co(e) {
|
|
|
421
437
|
"Artifacts file's claim_tx",
|
|
422
438
|
e.ins.length,
|
|
423
439
|
t.index
|
|
424
|
-
),
|
|
440
|
+
), He(t.hash);
|
|
425
441
|
}
|
|
426
442
|
function _t(e, t, r) {
|
|
427
443
|
if (t !== 1 || r !== X)
|
|
@@ -434,12 +450,12 @@ function St(e) {
|
|
|
434
450
|
Pt(e.peginTxid, e.depositorEthAddress)
|
|
435
451
|
), r = G(e.expectedVaultId);
|
|
436
452
|
if (t !== r)
|
|
437
|
-
throw new
|
|
453
|
+
throw new io(r, t, e.peginTxid);
|
|
438
454
|
}
|
|
439
455
|
function G(e) {
|
|
440
456
|
return `0x${(e.startsWith("0x") ? e.slice(2) : e).toLowerCase()}`;
|
|
441
457
|
}
|
|
442
|
-
function
|
|
458
|
+
function He(e) {
|
|
443
459
|
return H.from(e).reverse().toString("hex");
|
|
444
460
|
}
|
|
445
461
|
function ce(e, t) {
|
|
@@ -462,63 +478,61 @@ function At(e) {
|
|
|
462
478
|
);
|
|
463
479
|
}
|
|
464
480
|
const U = 3;
|
|
465
|
-
class
|
|
481
|
+
class co extends Error {
|
|
466
482
|
constructor(t, r) {
|
|
467
483
|
super(
|
|
468
484
|
`Artifacts belong to vault ${r}, not ${t}. Select the artifacts file saved for this vault.`
|
|
469
485
|
), this.expectedVaultId = t, this.actualVaultId = r, this.name = "ArtifactsVaultMismatchError";
|
|
470
486
|
}
|
|
471
487
|
}
|
|
488
|
+
const lo = /^(?:[0-9a-fA-F]{2})+$/;
|
|
472
489
|
function ho(e) {
|
|
473
|
-
const t = fo(e, "babe_sessions"), r =
|
|
490
|
+
const t = fo(e, "babe_sessions"), r = Object.keys(t);
|
|
491
|
+
if (r.length === 0)
|
|
492
|
+
return { joined: !1 };
|
|
474
493
|
for (const [o, s] of Object.entries(t)) {
|
|
475
494
|
const n = typeof s == "object" && s !== null ? s.decryptor_artifacts_hex : void 0;
|
|
476
|
-
if (typeof n != "string" || n
|
|
495
|
+
if (typeof n != "string" || !lo.test(n))
|
|
477
496
|
throw new Error(
|
|
478
|
-
`Artifacts file is missing a usable "babe_sessions": the entry for ${o} carries no "decryptor_artifacts_hex"
|
|
497
|
+
`Artifacts file is missing a usable "babe_sessions": the entry for ${o} carries no non-empty hex "decryptor_artifacts_hex".`
|
|
479
498
|
);
|
|
480
|
-
n === io && r.push(o);
|
|
481
499
|
}
|
|
482
|
-
return {
|
|
483
|
-
challengerPubkeys: Object.keys(t),
|
|
484
|
-
placeholderChallengerPubkeys: r
|
|
485
|
-
};
|
|
500
|
+
return { joined: !0, challengerPubkeys: r };
|
|
486
501
|
}
|
|
487
502
|
function po(e) {
|
|
488
503
|
let t;
|
|
489
504
|
try {
|
|
490
505
|
t = JSON.parse(e);
|
|
491
|
-
} catch (
|
|
492
|
-
throw new Error("Artifacts file is not valid JSON.", { cause:
|
|
506
|
+
} catch (a) {
|
|
507
|
+
throw new Error("Artifacts file is not valid JSON.", { cause: a });
|
|
493
508
|
}
|
|
494
|
-
const r =
|
|
509
|
+
const r = me(t.vault_id, "vault_id"), o = go(me(t.claim_tx, "claim_tx")), s = Pe(
|
|
495
510
|
t.prover_circuit_version,
|
|
496
511
|
"prover_circuit_version"
|
|
497
512
|
), n = t.claimable_event_block_number === void 0 ? 0n : BigInt(
|
|
498
|
-
|
|
513
|
+
Pe(
|
|
499
514
|
t.claimable_event_block_number,
|
|
500
515
|
"claimable_event_block_number"
|
|
501
516
|
)
|
|
502
|
-
)
|
|
517
|
+
);
|
|
503
518
|
return {
|
|
504
|
-
vaultCoreVersion: t.vault_core_version === void 0 ? void 0 :
|
|
519
|
+
vaultCoreVersion: t.vault_core_version === void 0 ? void 0 : Pe(t.vault_core_version, "vault_core_version"),
|
|
505
520
|
vaultId: r,
|
|
506
521
|
claimTxid: o.getId(),
|
|
507
|
-
peginTxid:
|
|
522
|
+
peginTxid: uo(o),
|
|
508
523
|
proverCircuitVersion: s,
|
|
509
524
|
claimableEventBlockNumber: n,
|
|
510
525
|
// Required: btc-vault's builder always writes it
|
|
511
|
-
// (`delegated_claim.rs:
|
|
526
|
+
// (`delegated_claim.rs:874` @ b534ff9e), so an absent one is not a file
|
|
512
527
|
// this SDK or the CLI produced.
|
|
513
|
-
verifyingKeyHex:
|
|
514
|
-
|
|
515
|
-
babeSessionPlaceholderChallengerPubkeys: a.placeholderChallengerPubkeys
|
|
528
|
+
verifyingKeyHex: me(t.verifying_key, "verifying_key"),
|
|
529
|
+
babeSessions: ho(t.babe_sessions)
|
|
516
530
|
};
|
|
517
531
|
}
|
|
518
|
-
async function
|
|
532
|
+
async function en(e) {
|
|
519
533
|
const t = po(e.artifactsJson), r = G(e.expectedVaultId), o = G(t.vaultId);
|
|
520
534
|
if (r !== o)
|
|
521
|
-
throw new
|
|
535
|
+
throw new co(r, o);
|
|
522
536
|
St({
|
|
523
537
|
peginTxid: t.peginTxid,
|
|
524
538
|
depositorEthAddress: e.depositorEthAddress,
|
|
@@ -552,11 +566,6 @@ async function Js(e) {
|
|
|
552
566
|
throw new Error(
|
|
553
567
|
`Artifacts carry Groth16 verifying key ${n} but the trusted key for prover circuit version ${e.expectedProverCircuitVersion} is ${a}; refusing a file whose proof would verify under a substituted key.`
|
|
554
568
|
);
|
|
555
|
-
const [i] = t.babeSessionPlaceholderChallengerPubkeys;
|
|
556
|
-
if (i !== void 0)
|
|
557
|
-
throw new Error(
|
|
558
|
-
`Artifacts carry a placeholder BaBe session for challenger ${i}; join the real sessions into the file before using it (#2598).`
|
|
559
|
-
);
|
|
560
569
|
return await nr(s, e.artifactsJson), t;
|
|
561
570
|
}
|
|
562
571
|
function go(e) {
|
|
@@ -568,12 +577,12 @@ function go(e) {
|
|
|
568
577
|
});
|
|
569
578
|
}
|
|
570
579
|
}
|
|
571
|
-
function
|
|
580
|
+
function me(e, t) {
|
|
572
581
|
if (typeof e != "string" || e.length === 0)
|
|
573
582
|
throw new Error(`Artifacts file is missing a usable "${t}".`);
|
|
574
583
|
return e;
|
|
575
584
|
}
|
|
576
|
-
function
|
|
585
|
+
function Pe(e, t) {
|
|
577
586
|
if (typeof e != "number" || !Number.isSafeInteger(e) || e < 0)
|
|
578
587
|
throw new Error(`Artifacts file is missing a usable "${t}".`);
|
|
579
588
|
return e;
|
|
@@ -625,17 +634,17 @@ function It(e) {
|
|
|
625
634
|
});
|
|
626
635
|
return t;
|
|
627
636
|
}
|
|
628
|
-
const yo =
|
|
637
|
+
const yo = "{}", vo = xt - Et;
|
|
629
638
|
function V(e) {
|
|
630
639
|
const t = e.replace(/^0x/, "").toLowerCase();
|
|
631
|
-
if (t.length ===
|
|
632
|
-
return t.slice(
|
|
633
|
-
if (t.length ===
|
|
640
|
+
if (t.length === xt)
|
|
641
|
+
return t.slice(vo);
|
|
642
|
+
if (t.length === Et) return t;
|
|
634
643
|
throw new Error(
|
|
635
644
|
`Public key must be 33-byte compressed or 32-byte x-only hex, got ${t.length / 2} bytes.`
|
|
636
645
|
);
|
|
637
646
|
}
|
|
638
|
-
async function
|
|
647
|
+
async function et(e, t, r) {
|
|
639
648
|
const o = await e.getPublicKeyHex();
|
|
640
649
|
if (V(o) !== V(t))
|
|
641
650
|
throw new Error(
|
|
@@ -656,7 +665,7 @@ async function Vt(e, t, r, o) {
|
|
|
656
665
|
);
|
|
657
666
|
try {
|
|
658
667
|
br(
|
|
659
|
-
|
|
668
|
+
Ie(r.registeredPayoutScriptPubKey),
|
|
660
669
|
r.depositorBtcPubkey,
|
|
661
670
|
o
|
|
662
671
|
);
|
|
@@ -682,10 +691,10 @@ async function Vt(e, t, r, o) {
|
|
|
682
691
|
lr(e, t)
|
|
683
692
|
]);
|
|
684
693
|
St({
|
|
685
|
-
peginTxid:
|
|
694
|
+
peginTxid: ao(n),
|
|
686
695
|
depositorEthAddress: r.depositorEthAddress,
|
|
687
696
|
expectedVaultId: r.vaultId
|
|
688
|
-
}),
|
|
697
|
+
}), Qr({
|
|
689
698
|
claimPsbtBase64: n,
|
|
690
699
|
assertPsbtBase64: a,
|
|
691
700
|
payoutClaimerPsbtBase64: i
|
|
@@ -713,7 +722,7 @@ async function Vt(e, t, r, o) {
|
|
|
713
722
|
universalChallengerBtcPubkeys: r.universalChallengerBtcPubkeys
|
|
714
723
|
}), { claim: n, assert: a, payoutClaimer: i, payoutDepositor: c, wronglyChallenged: u };
|
|
715
724
|
}
|
|
716
|
-
async function
|
|
725
|
+
async function bo(e) {
|
|
717
726
|
At({
|
|
718
727
|
servedVerifyingKeyHex: e.source.verifyingKeyHex,
|
|
719
728
|
trustedVerifyingKeyHex: e.trustedVerifyingKeyHex,
|
|
@@ -731,19 +740,20 @@ async function vo(e) {
|
|
|
731
740
|
trustedVerifyingKeyHex: e.trustedVerifyingKeyHex,
|
|
732
741
|
source: e.source,
|
|
733
742
|
vault: e.vault,
|
|
734
|
-
|
|
743
|
+
// Omitted means unjoined: the browser cannot hold the real sessions.
|
|
744
|
+
babeSessionsJson: e.babeSessionsJson === void 0 ? yo : e.babeSessionsJson,
|
|
735
745
|
requests: It(t)
|
|
736
746
|
};
|
|
737
747
|
}
|
|
738
748
|
function ge(e, t, r) {
|
|
739
749
|
re({
|
|
740
|
-
requestedPsbtHex:
|
|
750
|
+
requestedPsbtHex: Ne(t.psbtBase64),
|
|
741
751
|
signatureHex: r,
|
|
742
752
|
signerXOnlyPubkeyHex: V(e.depositorPublicKey),
|
|
743
753
|
inputIndex: t.inputIndex
|
|
744
754
|
});
|
|
745
755
|
}
|
|
746
|
-
function
|
|
756
|
+
function Ne(e) {
|
|
747
757
|
return H.from(e, "base64").toString("hex");
|
|
748
758
|
}
|
|
749
759
|
function Rt(e) {
|
|
@@ -754,7 +764,7 @@ class j extends Error {
|
|
|
754
764
|
super(t), this.name = "SigningPlanMismatchError";
|
|
755
765
|
}
|
|
756
766
|
}
|
|
757
|
-
function
|
|
767
|
+
function mo(e, t) {
|
|
758
768
|
if (e.length !== t.length)
|
|
759
769
|
throw new j(
|
|
760
770
|
`Plan has ${e.length} requests but the graph builds ${t.length}; the plan was altered after planning.`
|
|
@@ -795,7 +805,7 @@ function M(e, t) {
|
|
|
795
805
|
);
|
|
796
806
|
return r;
|
|
797
807
|
}
|
|
798
|
-
async function
|
|
808
|
+
async function wo(e) {
|
|
799
809
|
const { plan: t, signatures: r } = e, { txGraphVersion: o } = t.vault, s = t.source.txGraphJson, n = At({
|
|
800
810
|
servedVerifyingKeyHex: t.source.verifyingKeyHex,
|
|
801
811
|
trustedVerifyingKeyHex: t.trustedVerifyingKeyHex,
|
|
@@ -806,7 +816,7 @@ async function mo(e) {
|
|
|
806
816
|
t.vault,
|
|
807
817
|
t.depositorPublicKey
|
|
808
818
|
), i = It(a);
|
|
809
|
-
|
|
819
|
+
mo(t.requests, i), Po(i, r);
|
|
810
820
|
for (const c of i)
|
|
811
821
|
ge(
|
|
812
822
|
t,
|
|
@@ -842,10 +852,10 @@ async function mo(e) {
|
|
|
842
852
|
expectedVaultCoreVersion: t.vault.vaultCoreVersion
|
|
843
853
|
});
|
|
844
854
|
}
|
|
845
|
-
function
|
|
855
|
+
function xo(e) {
|
|
846
856
|
return typeof e.signDelegatedClaimPsbt == "function";
|
|
847
857
|
}
|
|
848
|
-
class
|
|
858
|
+
class Eo extends Error {
|
|
849
859
|
constructor(t, r, o, s) {
|
|
850
860
|
super(t, s), this.signatures = r, this.failedRequestId = o, this.name = "DelegatedClaimSigningIncompleteError";
|
|
851
861
|
}
|
|
@@ -856,30 +866,30 @@ const Kt = {
|
|
|
856
866
|
payoutClaimer: "standalone",
|
|
857
867
|
claim: "standalone",
|
|
858
868
|
wronglyChallenged: "standalone"
|
|
859
|
-
},
|
|
869
|
+
}, $o = [
|
|
860
870
|
"payoutClaimer",
|
|
861
871
|
"claim",
|
|
862
872
|
"wronglyChallenged"
|
|
863
873
|
];
|
|
864
|
-
async function
|
|
874
|
+
async function ko(e, t, r = {}) {
|
|
865
875
|
var s;
|
|
866
|
-
if ((s = r.signal) == null || s.throwIfAborted(),
|
|
876
|
+
if ((s = r.signal) == null || s.throwIfAborted(), To(e), V(e.depositorPublicKey) !== e.vault.depositorBtcPubkey)
|
|
867
877
|
throw new Error(
|
|
868
878
|
`Plan depositor key ${V(e.depositorPublicKey)} is not the vault's registered depositor key ${e.vault.depositorBtcPubkey}; the plan was not built for this vault.`
|
|
869
879
|
);
|
|
870
|
-
if (
|
|
871
|
-
if (!
|
|
880
|
+
if (vt(t)) {
|
|
881
|
+
if (!xo(t))
|
|
872
882
|
throw new Error(
|
|
873
883
|
"Approval wallet does not implement signDelegatedClaimPsbt; the claim ceremony needs it because the device signs some claim PSBTs with no loaded intent and needs its own derivation fields on them."
|
|
874
884
|
);
|
|
875
|
-
const n =
|
|
876
|
-
|
|
877
|
-
const a = Co(e), i = await
|
|
885
|
+
const n = _o(r, e);
|
|
886
|
+
So(n.depositTerms, e.vault);
|
|
887
|
+
const a = Co(e), i = await et(
|
|
878
888
|
t,
|
|
879
889
|
e.depositorPublicKey,
|
|
880
890
|
e.btcNetwork
|
|
881
891
|
);
|
|
882
|
-
return
|
|
892
|
+
return Ao(
|
|
883
893
|
e,
|
|
884
894
|
t,
|
|
885
895
|
i,
|
|
@@ -888,14 +898,14 @@ async function $o(e, t, r = {}) {
|
|
|
888
898
|
r
|
|
889
899
|
);
|
|
890
900
|
}
|
|
891
|
-
const o = await
|
|
901
|
+
const o = await et(
|
|
892
902
|
t,
|
|
893
903
|
e.depositorPublicKey,
|
|
894
904
|
e.btcNetwork
|
|
895
905
|
);
|
|
896
|
-
return
|
|
906
|
+
return Io(e, t, o, r.signal);
|
|
897
907
|
}
|
|
898
|
-
function
|
|
908
|
+
function To(e) {
|
|
899
909
|
const t = /* @__PURE__ */ new Set();
|
|
900
910
|
for (const r of e.requests) {
|
|
901
911
|
if (t.has(r.id))
|
|
@@ -908,7 +918,7 @@ function ko(e) {
|
|
|
908
918
|
function Co(e) {
|
|
909
919
|
const t = e.requests.filter(
|
|
910
920
|
(s) => Kt[s.kind] === "intentBound"
|
|
911
|
-
), r =
|
|
921
|
+
), r = $o.flatMap(
|
|
912
922
|
(s) => e.requests.filter((n) => n.kind === s)
|
|
913
923
|
), o = t.length + r.length;
|
|
914
924
|
if (o !== e.requests.length)
|
|
@@ -923,7 +933,7 @@ function Ht(e, t) {
|
|
|
923
933
|
`Delegated-claim signing ended with ${t.size} signatures for ${e.requests.length} requests; the set is incomplete and must not be treated as signed.`
|
|
924
934
|
);
|
|
925
935
|
}
|
|
926
|
-
function
|
|
936
|
+
function _o(e, t) {
|
|
927
937
|
if (e.depositTerms === void 0)
|
|
928
938
|
throw new Error(
|
|
929
939
|
"An approval wallet signs Assert and the depositor Payout only under this vault's loaded intent; pass depositTerms (rebuilt from on-chain state) so it can be approved."
|
|
@@ -932,14 +942,14 @@ function To(e, t) {
|
|
|
932
942
|
throw new Error(
|
|
933
943
|
"An approval wallet releases a loaded intent only through the vault-root derivation; pass vaultContext so that derivation can run before and after the intent-bound signatures."
|
|
934
944
|
);
|
|
935
|
-
const r =
|
|
945
|
+
const r = Ve(e.vaultContext.depositorBtcPubkey);
|
|
936
946
|
if (r !== t.vault.depositorBtcPubkey)
|
|
937
947
|
throw new Error(
|
|
938
948
|
`vaultContext derives from depositor key ${r} but this plan's vault is registered to ${t.vault.depositorBtcPubkey}; the device would derive for another depositor.`
|
|
939
949
|
);
|
|
940
950
|
return { depositTerms: e.depositTerms, vaultContext: e.vaultContext };
|
|
941
951
|
}
|
|
942
|
-
function
|
|
952
|
+
function So(e, t) {
|
|
943
953
|
const r = (s) => s.map((n) => V(n)).sort().join(",");
|
|
944
954
|
if (r(e.vaultKeeperBtcPubkeys) !== r(t.vaultKeeperBtcPubkeys) || r(e.universalChallengerBtcPubkeys) !== r(t.universalChallengerBtcPubkeys))
|
|
945
955
|
throw new Error(
|
|
@@ -972,30 +982,30 @@ function _o(e, t) {
|
|
|
972
982
|
`Deposit terms group at htlcVout ${s.htlcVout} names a different vault provider than the vault context this claim signs for; the device would bind the Assert to the wrong intent.`
|
|
973
983
|
);
|
|
974
984
|
}
|
|
975
|
-
async function
|
|
985
|
+
async function Ao(e, t, r, o, { intentBound: s, standalone: n }, a) {
|
|
976
986
|
var g;
|
|
977
|
-
const i =
|
|
987
|
+
const i = Bo(e, a.resume), u = [...s, ...n];
|
|
978
988
|
let l = 0;
|
|
979
989
|
const c = {
|
|
980
990
|
phase: "clearing any loaded intent"
|
|
981
991
|
}, d = async (p) => {
|
|
982
|
-
var
|
|
983
|
-
c.phase = "signing", (
|
|
992
|
+
var m;
|
|
993
|
+
c.phase = "signing", (m = a.signal) == null || m.throwIfAborted();
|
|
984
994
|
const y = await t.signDelegatedClaimPsbt(
|
|
985
|
-
|
|
986
|
-
|
|
995
|
+
Ne(p.psbtBase64),
|
|
996
|
+
$t(
|
|
987
997
|
e.depositorPublicKey,
|
|
988
998
|
p.inputIndex,
|
|
989
999
|
r
|
|
990
1000
|
)
|
|
991
|
-
), f = await
|
|
1001
|
+
), f = await mt(
|
|
992
1002
|
Rt(y),
|
|
993
1003
|
p.inputIndex
|
|
994
1004
|
);
|
|
995
1005
|
ge(e, p, f), i.set(p.id, f);
|
|
996
1006
|
}, h = async (p) => {
|
|
997
1007
|
var f;
|
|
998
|
-
c.phase = p, (f = a.signal) == null || f.throwIfAborted(), (await
|
|
1008
|
+
c.phase = p, (f = a.signal) == null || f.throwIfAborted(), (await kt(t, o.vaultContext)).fill(0);
|
|
999
1009
|
};
|
|
1000
1010
|
typeof t.validateDepositTerms == "function" && await t.validateDepositTerms(o.depositTerms);
|
|
1001
1011
|
try {
|
|
@@ -1009,7 +1019,7 @@ async function So(e, t, r, o, { intentBound: s, standalone: n }, a) {
|
|
|
1009
1019
|
const y = u[l];
|
|
1010
1020
|
if (i.size === 0 || y === void 0) throw p;
|
|
1011
1021
|
const f = c.phase === "signing" ? `stopped at "${y.id}"` : `stopped before "${y.id}" while ${c.phase}`;
|
|
1012
|
-
throw new
|
|
1022
|
+
throw new Eo(
|
|
1013
1023
|
`Delegated-claim signing ${f}; ${i.size} of ${e.requests.length} signatures were collected.`,
|
|
1014
1024
|
i,
|
|
1015
1025
|
y.id,
|
|
@@ -1018,7 +1028,7 @@ async function So(e, t, r, o, { intentBound: s, standalone: n }, a) {
|
|
|
1018
1028
|
}
|
|
1019
1029
|
return Ht(e, i), i;
|
|
1020
1030
|
}
|
|
1021
|
-
function
|
|
1031
|
+
function Bo(e, t) {
|
|
1022
1032
|
const r = /* @__PURE__ */ new Map();
|
|
1023
1033
|
if (!t) return r;
|
|
1024
1034
|
for (const o of e.requests) {
|
|
@@ -1034,12 +1044,12 @@ function Ao(e, t) {
|
|
|
1034
1044
|
}
|
|
1035
1045
|
return r;
|
|
1036
1046
|
}
|
|
1037
|
-
async function
|
|
1038
|
-
const s = e.requests, n = await
|
|
1047
|
+
async function Io(e, t, r, o) {
|
|
1048
|
+
const s = e.requests, n = await bt(
|
|
1039
1049
|
t,
|
|
1040
|
-
s.map((i) =>
|
|
1050
|
+
s.map((i) => Ne(i.psbtBase64)),
|
|
1041
1051
|
s.map(
|
|
1042
|
-
(i) =>
|
|
1052
|
+
(i) => $t(
|
|
1043
1053
|
e.depositorPublicKey,
|
|
1044
1054
|
i.inputIndex,
|
|
1045
1055
|
r
|
|
@@ -1048,7 +1058,7 @@ async function Bo(e, t, r, o) {
|
|
|
1048
1058
|
o
|
|
1049
1059
|
), a = /* @__PURE__ */ new Map();
|
|
1050
1060
|
for (let i = 0; i < s.length; i++) {
|
|
1051
|
-
const u = await
|
|
1061
|
+
const u = await mt(
|
|
1052
1062
|
Rt(n[i]),
|
|
1053
1063
|
s[i].inputIndex
|
|
1054
1064
|
);
|
|
@@ -1056,22 +1066,22 @@ async function Bo(e, t, r, o) {
|
|
|
1056
1066
|
}
|
|
1057
1067
|
return Ht(e, a), a;
|
|
1058
1068
|
}
|
|
1059
|
-
async function
|
|
1060
|
-
const t = await
|
|
1069
|
+
async function tn(e) {
|
|
1070
|
+
const t = await bo({
|
|
1061
1071
|
depositorPublicKey: e.depositorPublicKey,
|
|
1062
1072
|
btcNetwork: e.btcNetwork,
|
|
1063
1073
|
source: e.source,
|
|
1064
1074
|
trustedVerifyingKeyHex: e.trustedVerifyingKeyHex,
|
|
1065
1075
|
vault: e.vault,
|
|
1066
1076
|
babeSessionsJson: e.babeSessionsJson
|
|
1067
|
-
}), r = await
|
|
1077
|
+
}), r = await ko(t, e.btcWallet, {
|
|
1068
1078
|
depositTerms: e.depositTerms,
|
|
1069
1079
|
vaultContext: e.vaultContext
|
|
1070
1080
|
});
|
|
1071
|
-
return
|
|
1081
|
+
return wo({ plan: t, signatures: r });
|
|
1072
1082
|
}
|
|
1073
|
-
async function
|
|
1074
|
-
const t = await
|
|
1083
|
+
async function rn(e) {
|
|
1084
|
+
const t = await kt(e.btcWallet, e.vaultContext);
|
|
1075
1085
|
let r;
|
|
1076
1086
|
try {
|
|
1077
1087
|
r = await pr(t, e.htlcVout);
|
|
@@ -1084,7 +1094,7 @@ async function en(e) {
|
|
|
1084
1094
|
} finally {
|
|
1085
1095
|
r.fill(0);
|
|
1086
1096
|
}
|
|
1087
|
-
return
|
|
1097
|
+
return Vo(o.pk_hash, e.expectedWotsPkHash), await fr(
|
|
1088
1098
|
e.txGraphVersion,
|
|
1089
1099
|
o.keypair,
|
|
1090
1100
|
e.txGraphJson
|
|
@@ -1093,7 +1103,7 @@ async function en(e) {
|
|
|
1093
1103
|
pkHash: o.pk_hash
|
|
1094
1104
|
};
|
|
1095
1105
|
}
|
|
1096
|
-
function
|
|
1106
|
+
function Vo(e, t) {
|
|
1097
1107
|
if (ne(e) !== ne(t))
|
|
1098
1108
|
throw new Error(
|
|
1099
1109
|
`Derived WOTS public-key hash ${ne(e)} does not match the vault's on-chain depositorWotsPkHash ${ne(t)}. The wallet, the HTLC output index, or the derivation itself is not the one this vault was created with.`
|
|
@@ -1114,7 +1124,7 @@ function we(e, t, r) {
|
|
|
1114
1124
|
rotated: n !== s
|
|
1115
1125
|
};
|
|
1116
1126
|
}
|
|
1117
|
-
function
|
|
1127
|
+
function Ro(e) {
|
|
1118
1128
|
const t = /* @__PURE__ */ new Map();
|
|
1119
1129
|
for (const r of e) {
|
|
1120
1130
|
const o = t.get(r.operationBtcPubkey);
|
|
@@ -1125,7 +1135,7 @@ function Vo(e) {
|
|
|
1125
1135
|
t.set(r.operationBtcPubkey, r.adminAddress);
|
|
1126
1136
|
}
|
|
1127
1137
|
}
|
|
1128
|
-
function
|
|
1138
|
+
function Nt(e, t, r) {
|
|
1129
1139
|
if (t.vaultKeepers.length !== e.vaultKeepers.length || t.universalChallengers.length !== e.universalChallengers.length)
|
|
1130
1140
|
throw new Error(
|
|
1131
1141
|
`Operation-key resolution returned ${t.vaultKeepers.length} keeper and ${t.universalChallengers.length} challenger keys for a roster of ${e.vaultKeepers.length} keepers and ${e.universalChallengers.length} challengers`
|
|
@@ -1142,7 +1152,7 @@ function Ot(e, t, r) {
|
|
|
1142
1152
|
), n = e.universalChallengers.map(
|
|
1143
1153
|
(a, i) => we("universal challenger", a, t.universalChallengers[i])
|
|
1144
1154
|
);
|
|
1145
|
-
return
|
|
1155
|
+
return Ro([
|
|
1146
1156
|
o,
|
|
1147
1157
|
...s,
|
|
1148
1158
|
...n
|
|
@@ -1157,24 +1167,24 @@ function Ot(e, t, r) {
|
|
|
1157
1167
|
query: e
|
|
1158
1168
|
};
|
|
1159
1169
|
}
|
|
1160
|
-
async function
|
|
1170
|
+
async function Ko(e) {
|
|
1161
1171
|
const t = await e.operationKeyReader.getCurrentOperationKeys(
|
|
1162
1172
|
e.query,
|
|
1163
1173
|
e.blockNumber
|
|
1164
1174
|
);
|
|
1165
|
-
return
|
|
1175
|
+
return Nt(e.query, t, { mode: "current" });
|
|
1166
1176
|
}
|
|
1167
|
-
async function
|
|
1177
|
+
async function Ot(e) {
|
|
1168
1178
|
const t = await e.operationKeyReader.getOperationKeysAtEpochs(
|
|
1169
1179
|
e.query,
|
|
1170
1180
|
e.epochs
|
|
1171
1181
|
);
|
|
1172
|
-
return
|
|
1182
|
+
return Nt(e.query, t, {
|
|
1173
1183
|
mode: "epochs",
|
|
1174
1184
|
epochs: e.epochs
|
|
1175
1185
|
});
|
|
1176
1186
|
}
|
|
1177
|
-
async function
|
|
1187
|
+
async function Ho(e) {
|
|
1178
1188
|
const { basic: t, protocol: r } = e.vault, {
|
|
1179
1189
|
registryReader: o,
|
|
1180
1190
|
vaultKeeperReader: s,
|
|
@@ -1204,7 +1214,7 @@ async function Ko(e) {
|
|
|
1204
1214
|
throw new Error(
|
|
1205
1215
|
`No universal challengers for version ${r.universalChallengersVersion}`
|
|
1206
1216
|
);
|
|
1207
|
-
return
|
|
1217
|
+
return Ot({
|
|
1208
1218
|
operationKeyReader: a,
|
|
1209
1219
|
query: {
|
|
1210
1220
|
vaultProviderEthAddress: t.vaultProvider,
|
|
@@ -1216,7 +1226,7 @@ async function Ko(e) {
|
|
|
1216
1226
|
epochs: c
|
|
1217
1227
|
});
|
|
1218
1228
|
}
|
|
1219
|
-
async function
|
|
1229
|
+
async function on(e) {
|
|
1220
1230
|
const { vaultId: t, readers: r } = e, o = await r.registryReader.getVaultData(t), { basic: s, protocol: n } = o;
|
|
1221
1231
|
if (n.vaultCoreVersion !== U)
|
|
1222
1232
|
throw new Error(
|
|
@@ -1226,19 +1236,19 @@ async function tn(e) {
|
|
|
1226
1236
|
s.depositorBtcPubKey,
|
|
1227
1237
|
`getBtcVaultBasicInfo(${t}).depositorBtcPubKey`
|
|
1228
1238
|
);
|
|
1229
|
-
if (s.status !==
|
|
1230
|
-
throw new
|
|
1239
|
+
if (s.status !== je.REDEEMED)
|
|
1240
|
+
throw new Fe(
|
|
1231
1241
|
t,
|
|
1232
1242
|
s.depositorBtcPubKey,
|
|
1233
1243
|
s.createdAt,
|
|
1234
1244
|
s.createdAt,
|
|
1235
|
-
`the vault's status is ${s.status}, not Redeemed (${
|
|
1245
|
+
`the vault's status is ${s.status}, not Redeemed (${je.REDEEMED}); no scan was made`
|
|
1236
1246
|
);
|
|
1237
1247
|
const [i, u, l, c] = await Promise.all([
|
|
1238
|
-
|
|
1248
|
+
Ho({ vaultId: t, vault: o, readers: r }),
|
|
1239
1249
|
r.registryReader.getRegistrationRecordsAtBlock(s.createdAt),
|
|
1240
1250
|
r.registryReader.getVaultClaimableBy(t, s.depositorBtcPubKey, s.createdAt).catch((v) => {
|
|
1241
|
-
throw
|
|
1251
|
+
throw mr(v) ? new Fe(
|
|
1242
1252
|
t,
|
|
1243
1253
|
s.depositorBtcPubKey,
|
|
1244
1254
|
v.fromBlock,
|
|
@@ -1250,7 +1260,7 @@ async function tn(e) {
|
|
|
1250
1260
|
r.protocolParamsReader.getOffchainParamsByVersion(
|
|
1251
1261
|
n.offchainParamsVersion
|
|
1252
1262
|
)
|
|
1253
|
-
]), d = _r(c.timelockAssert), h =
|
|
1263
|
+
]), d = _r(c.timelockAssert), h = Pr(u, t, s.createdAt);
|
|
1254
1264
|
wr(h);
|
|
1255
1265
|
const g = xr(h);
|
|
1256
1266
|
if (g.toLowerCase() !== n.prePeginTxHash.toLowerCase())
|
|
@@ -1322,19 +1332,19 @@ async function tn(e) {
|
|
|
1322
1332
|
throw new Error(
|
|
1323
1333
|
`Depositor-signed PegIn of vault ${t} has ${f.ins.length} inputs; it spends Pre-PegIn ${n.prePeginTxHash} output ${n.htlcVout} with exactly one; refusing an inconsistent node.`
|
|
1324
1334
|
);
|
|
1325
|
-
const
|
|
1326
|
-
if (
|
|
1335
|
+
const m = He(f.ins[0].hash), k = f.ins[0].index;
|
|
1336
|
+
if (m !== b(n.prePeginTxHash).toLowerCase() || k !== n.htlcVout)
|
|
1327
1337
|
throw new Error(
|
|
1328
|
-
`Depositor-signed PegIn of vault ${t} spends ${
|
|
1338
|
+
`Depositor-signed PegIn of vault ${t} spends ${m}:${k} but the vault record says Pre-PegIn ${n.prePeginTxHash} output ${n.htlcVout}; refusing an inconsistent node.`
|
|
1329
1339
|
);
|
|
1330
|
-
const x = f.outs[
|
|
1340
|
+
const x = f.outs[J];
|
|
1331
1341
|
if (x === void 0)
|
|
1332
1342
|
throw new Error(
|
|
1333
|
-
`Depositor-signed PegIn of vault ${t} has no output ${
|
|
1343
|
+
`Depositor-signed PegIn of vault ${t} has no output ${J}; the Payout cannot spend the Vault UTXO.`
|
|
1334
1344
|
);
|
|
1335
1345
|
if (BigInt(x.value) !== s.amount)
|
|
1336
1346
|
throw new Error(
|
|
1337
|
-
`Depositor-signed PegIn of vault ${t} pays ${x.value} sats to output ${
|
|
1347
|
+
`Depositor-signed PegIn of vault ${t} pays ${x.value} sats to output ${J} but the vault record says ${s.amount}; refusing an inconsistent node.`
|
|
1338
1348
|
);
|
|
1339
1349
|
return {
|
|
1340
1350
|
context: {
|
|
@@ -1374,7 +1384,7 @@ async function tn(e) {
|
|
|
1374
1384
|
htlcVout: n.htlcVout
|
|
1375
1385
|
};
|
|
1376
1386
|
}
|
|
1377
|
-
const
|
|
1387
|
+
const No = 8, Oo = 6e3, Do = 10 * 6e4, Mo = 10;
|
|
1378
1388
|
class Dt extends Error {
|
|
1379
1389
|
constructor(t) {
|
|
1380
1390
|
super(t), this.name = "PeginRegistrationMissingError";
|
|
@@ -1385,24 +1395,24 @@ class Mt extends Error {
|
|
|
1385
1395
|
super(t), this.name = "PeginRegistrationNotFinalError";
|
|
1386
1396
|
}
|
|
1387
1397
|
}
|
|
1388
|
-
function
|
|
1398
|
+
function Lo(e) {
|
|
1389
1399
|
return e instanceof Dt || e instanceof Error && e.name === "PeginRegistrationMissingError";
|
|
1390
1400
|
}
|
|
1391
|
-
function
|
|
1401
|
+
function sn(e) {
|
|
1392
1402
|
return e instanceof Mt || e instanceof Error && e.name === "PeginRegistrationNotFinalError";
|
|
1393
1403
|
}
|
|
1394
|
-
function
|
|
1404
|
+
function tt(e) {
|
|
1395
1405
|
const { currentBlock: t, createdAtBlock: r } = e, o = t - r + 1n;
|
|
1396
1406
|
return o < 0n ? 0 : Number(o);
|
|
1397
1407
|
}
|
|
1398
|
-
async function
|
|
1408
|
+
async function nn(e) {
|
|
1399
1409
|
const {
|
|
1400
1410
|
vaultRegistryReader: t,
|
|
1401
1411
|
getBlockNumber: r,
|
|
1402
1412
|
vaultIds: o,
|
|
1403
|
-
required: s =
|
|
1413
|
+
required: s = No,
|
|
1404
1414
|
pollIntervalMs: n = Oo,
|
|
1405
|
-
timeoutMs: a =
|
|
1415
|
+
timeoutMs: a = Do,
|
|
1406
1416
|
signal: i,
|
|
1407
1417
|
onProgress: u
|
|
1408
1418
|
} = e;
|
|
@@ -1428,7 +1438,7 @@ async function on(e) {
|
|
|
1428
1438
|
(f) => f.depositor === Sr || f.createdAt === 0n
|
|
1429
1439
|
);
|
|
1430
1440
|
if (y !== -1) {
|
|
1431
|
-
if (d += 1, !c && d >
|
|
1441
|
+
if (d += 1, !c && d > Mo)
|
|
1432
1442
|
throw new Dt(
|
|
1433
1443
|
`Vault ${o[y]} is still not visible on-chain after ${d} reads — the registration does not exist.`
|
|
1434
1444
|
);
|
|
@@ -1437,22 +1447,22 @@ async function on(e) {
|
|
|
1437
1447
|
), u == null || u({ confirmations: 0, required: s });
|
|
1438
1448
|
} else {
|
|
1439
1449
|
c = !0, d = 0, h = void 0;
|
|
1440
|
-
let f = p[0],
|
|
1450
|
+
let f = p[0], m = tt({
|
|
1441
1451
|
currentBlock: g,
|
|
1442
1452
|
createdAtBlock: p[0].createdAt
|
|
1443
1453
|
});
|
|
1444
1454
|
for (const k of p.slice(1)) {
|
|
1445
|
-
const x =
|
|
1455
|
+
const x = tt({
|
|
1446
1456
|
currentBlock: g,
|
|
1447
1457
|
createdAtBlock: k.createdAt
|
|
1448
1458
|
});
|
|
1449
|
-
x <
|
|
1459
|
+
x < m && (m = x, f = k);
|
|
1450
1460
|
}
|
|
1451
|
-
if (u == null || u({ confirmations:
|
|
1452
|
-
return { confirmations:
|
|
1461
|
+
if (u == null || u({ confirmations: m, required: s }), m >= s)
|
|
1462
|
+
return { confirmations: m, basicInfo: f };
|
|
1453
1463
|
}
|
|
1454
1464
|
} catch (g) {
|
|
1455
|
-
if (
|
|
1465
|
+
if (Lo(g))
|
|
1456
1466
|
throw g;
|
|
1457
1467
|
console.warn(
|
|
1458
1468
|
`Registration-depth read failed (retrying in ${n}ms): ` + (g instanceof Error ? g.message : String(g))
|
|
@@ -1472,8 +1482,8 @@ async function on(e) {
|
|
|
1472
1482
|
});
|
|
1473
1483
|
}
|
|
1474
1484
|
}
|
|
1475
|
-
const
|
|
1476
|
-
class
|
|
1485
|
+
const Fo = /^(?:[0-9a-f]{2})*$/, Uo = /^[0-9a-f]{64}$/, qo = /^([0-9a-f]{64}):(0|[1-9][0-9]*)$/, Xo = -2147483648, Go = 2147483647, xe = 4294967295, rt = 2, ot = 2, le = 0;
|
|
1486
|
+
class P extends Error {
|
|
1477
1487
|
constructor(t) {
|
|
1478
1488
|
super(t), this.name = "GraphFingerprintError";
|
|
1479
1489
|
}
|
|
@@ -1481,56 +1491,56 @@ class m extends Error {
|
|
|
1481
1491
|
function $(e, t, r) {
|
|
1482
1492
|
const o = e[t];
|
|
1483
1493
|
if (o === void 0)
|
|
1484
|
-
throw new
|
|
1494
|
+
throw new P(`Graph tx ${r} is missing "${t}"`);
|
|
1485
1495
|
return o;
|
|
1486
1496
|
}
|
|
1487
1497
|
function Z(e, t) {
|
|
1488
1498
|
if (!Array.isArray(e))
|
|
1489
|
-
throw new
|
|
1499
|
+
throw new P(`Graph tx ${t} is not an array`);
|
|
1490
1500
|
return e;
|
|
1491
1501
|
}
|
|
1492
1502
|
function B(e, t) {
|
|
1493
1503
|
if (e === null || typeof e != "object" || Array.isArray(e))
|
|
1494
|
-
throw new
|
|
1504
|
+
throw new P(`Graph tx ${t} is not an object`);
|
|
1495
1505
|
return e;
|
|
1496
1506
|
}
|
|
1497
1507
|
function W(e, t, r, o) {
|
|
1498
1508
|
if (typeof e != "number" || !Number.isSafeInteger(e) || e < r || e > o)
|
|
1499
|
-
throw new
|
|
1509
|
+
throw new P(
|
|
1500
1510
|
`Graph tx ${t} is not an integer in [${r}, ${o}]`
|
|
1501
1511
|
);
|
|
1502
1512
|
return e;
|
|
1503
1513
|
}
|
|
1504
1514
|
function Ee(e, t) {
|
|
1505
|
-
if (typeof e != "string" || !
|
|
1506
|
-
throw new
|
|
1515
|
+
if (typeof e != "string" || !Fo.test(e))
|
|
1516
|
+
throw new P(
|
|
1507
1517
|
`Graph tx ${t} is not lowercase hex without a prefix`
|
|
1508
1518
|
);
|
|
1509
1519
|
return H.from(e, "hex");
|
|
1510
1520
|
}
|
|
1511
1521
|
function de(e, t) {
|
|
1512
|
-
if (typeof e != "string" || !
|
|
1513
|
-
throw new
|
|
1522
|
+
if (typeof e != "string" || !Uo.test(e))
|
|
1523
|
+
throw new P(
|
|
1514
1524
|
`Graph ${t} is not 32 bytes of lowercase hex`
|
|
1515
1525
|
);
|
|
1516
1526
|
return e;
|
|
1517
1527
|
}
|
|
1518
|
-
function
|
|
1528
|
+
function st(e, t) {
|
|
1519
1529
|
const r = B(e, t), o = new S();
|
|
1520
1530
|
return o.version = W(
|
|
1521
1531
|
$(r, "version", t),
|
|
1522
1532
|
`${t}.version`,
|
|
1523
|
-
|
|
1524
|
-
|
|
1533
|
+
Xo,
|
|
1534
|
+
Go
|
|
1525
1535
|
), o.locktime = W(
|
|
1526
1536
|
$(r, "lock_time", t),
|
|
1527
1537
|
`${t}.lock_time`,
|
|
1528
1538
|
0,
|
|
1529
1539
|
xe
|
|
1530
1540
|
), Z($(r, "input", t), `${t}.input`).forEach((s, n) => {
|
|
1531
|
-
const a = `${t}.input[${n}]`, i = B(s, a), u = $(i, "previous_output", a), l = typeof u == "string" &&
|
|
1541
|
+
const a = `${t}.input[${n}]`, i = B(s, a), u = $(i, "previous_output", a), l = typeof u == "string" && qo.exec(u);
|
|
1532
1542
|
if (!l)
|
|
1533
|
-
throw new
|
|
1543
|
+
throw new P(
|
|
1534
1544
|
`Graph tx ${a}.previous_output is not "<txid>:<vout>"`
|
|
1535
1545
|
);
|
|
1536
1546
|
const c = W(Number(l[2]), `${a}.previous_output vout`, 0, xe);
|
|
@@ -1557,12 +1567,12 @@ function D(e, t) {
|
|
|
1557
1567
|
try {
|
|
1558
1568
|
o = S.fromHex(r);
|
|
1559
1569
|
} catch (s) {
|
|
1560
|
-
throw new
|
|
1570
|
+
throw new P(
|
|
1561
1571
|
`Presign ${t} is not one transaction: ${s instanceof Error ? s.message : String(s)}`
|
|
1562
1572
|
);
|
|
1563
1573
|
}
|
|
1564
1574
|
if (o.toHex() !== r)
|
|
1565
|
-
throw new
|
|
1575
|
+
throw new P(
|
|
1566
1576
|
`Presign ${t} is not a canonical transaction encoding`
|
|
1567
1577
|
);
|
|
1568
1578
|
return o;
|
|
@@ -1577,29 +1587,29 @@ function Lt(e, t) {
|
|
|
1577
1587
|
}
|
|
1578
1588
|
function Ft(e, t) {
|
|
1579
1589
|
if (!e.outs[le])
|
|
1580
|
-
throw new
|
|
1590
|
+
throw new P(
|
|
1581
1591
|
`Presign ${t}.claim_tx must have output ${le}`
|
|
1582
1592
|
);
|
|
1583
1593
|
}
|
|
1584
|
-
function
|
|
1594
|
+
function zo(e, t, r) {
|
|
1585
1595
|
if (e.ins.length !== 1)
|
|
1586
|
-
throw new
|
|
1596
|
+
throw new P(
|
|
1587
1597
|
`Presign ${r}.claim_tx must have exactly one input, got ${e.ins.length}`
|
|
1588
1598
|
);
|
|
1589
1599
|
Ft(e, r);
|
|
1590
1600
|
const o = Lt(e, 0);
|
|
1591
1601
|
if ((o == null ? void 0 : o.txid) !== t || o.vout !== X) {
|
|
1592
1602
|
const s = o ? `${o.txid}:${o.vout}` : "no input";
|
|
1593
|
-
throw new
|
|
1603
|
+
throw new P(
|
|
1594
1604
|
`Presign ${r}.claim_tx must spend ${t}:${X}, got ${s}`
|
|
1595
1605
|
);
|
|
1596
1606
|
}
|
|
1597
1607
|
}
|
|
1598
|
-
function
|
|
1608
|
+
function Oe(e, t, r) {
|
|
1599
1609
|
const o = Lt(e, 0);
|
|
1600
1610
|
if ((o == null ? void 0 : o.txid) !== t || o.vout !== le) {
|
|
1601
1611
|
const s = o ? `${o.txid}:${o.vout}` : "no input";
|
|
1602
|
-
throw new
|
|
1612
|
+
throw new P(
|
|
1603
1613
|
`Presign ${r}.assert_tx input 0 must spend ${t}:${le}, got ${s}`
|
|
1604
1614
|
);
|
|
1605
1615
|
}
|
|
@@ -1608,36 +1618,36 @@ function Ut(e) {
|
|
|
1608
1618
|
const t = D(e.peginTxHex, `${e.path}.pegin_tx`), r = D(e.claimTxHex, `${e.path}.claim_tx`), o = D(e.assertTxHex, `${e.path}.assert_tx`);
|
|
1609
1619
|
return { peginTx: t, claimTx: r, assertTx: o };
|
|
1610
1620
|
}
|
|
1611
|
-
function
|
|
1621
|
+
function jo(e) {
|
|
1612
1622
|
const t = D(e.claimTxHex, `${e.path}.claim_tx`), r = D(e.assertTxHex, `${e.path}.assert_tx`);
|
|
1613
|
-
Ft(t, e.path),
|
|
1623
|
+
Ft(t, e.path), Oe(r, t.getId(), e.path);
|
|
1614
1624
|
}
|
|
1615
|
-
function
|
|
1625
|
+
function Wo(e) {
|
|
1616
1626
|
const { peginTx: t, claimTx: r, assertTx: o } = Ut(e);
|
|
1617
|
-
|
|
1627
|
+
zo(r, t.getId(), e.path), Oe(o, r.getId(), e.path);
|
|
1618
1628
|
}
|
|
1619
|
-
function
|
|
1629
|
+
function Yo(e, t) {
|
|
1620
1630
|
const [r, ...o] = e.ins;
|
|
1621
1631
|
if (!r || o.length > 0)
|
|
1622
|
-
throw new
|
|
1632
|
+
throw new P(
|
|
1623
1633
|
`Presign claim_tx must have exactly one input, got ${e.ins.length}`
|
|
1624
1634
|
);
|
|
1625
1635
|
const s = H.from(r.hash).reverse().toString("hex");
|
|
1626
1636
|
if (s !== t || r.index !== X)
|
|
1627
|
-
throw new
|
|
1637
|
+
throw new P(
|
|
1628
1638
|
`Presign claim_tx must spend ${t}:${X}, got ${s}:${r.index}`
|
|
1629
1639
|
);
|
|
1630
|
-
if (e.version !==
|
|
1631
|
-
throw new
|
|
1632
|
-
`Presign claim_tx version must be ${
|
|
1640
|
+
if (e.version !== rt)
|
|
1641
|
+
throw new P(
|
|
1642
|
+
`Presign claim_tx version must be ${rt}, got ${e.version}`
|
|
1633
1643
|
);
|
|
1634
1644
|
if (r.witness.length > 0)
|
|
1635
|
-
throw new
|
|
1645
|
+
throw new P(
|
|
1636
1646
|
`Presign claim_tx input must have an empty witness, got ${r.witness.length} item(s)`
|
|
1637
1647
|
);
|
|
1638
|
-
if (e.outs.length !==
|
|
1639
|
-
throw new
|
|
1640
|
-
`Presign claim_tx must have exactly ${
|
|
1648
|
+
if (e.outs.length !== ot)
|
|
1649
|
+
throw new P(
|
|
1650
|
+
`Presign claim_tx must have exactly ${ot} outputs, got ${e.outs.length}`
|
|
1641
1651
|
);
|
|
1642
1652
|
}
|
|
1643
1653
|
function qt(e) {
|
|
@@ -1647,13 +1657,13 @@ function qt(e) {
|
|
|
1647
1657
|
return t.forEach((o, s) => {
|
|
1648
1658
|
const n = de(o.pubkey, "challenger pubkey");
|
|
1649
1659
|
if (s > 0 && t[s - 1].pubkey === n)
|
|
1650
|
-
throw new
|
|
1651
|
-
r.push(
|
|
1660
|
+
throw new P(`Graph lists challenger ${n} twice`);
|
|
1661
|
+
r.push(Ye(n), o.nopayoutTx);
|
|
1652
1662
|
for (const a of o.outputLabelHashes)
|
|
1653
|
-
r.push(
|
|
1654
|
-
}), Kr(Hr(
|
|
1663
|
+
r.push(Ye(de(a, "output_label_hashes entry")));
|
|
1664
|
+
}), Kr(Hr(Nr(...r)));
|
|
1655
1665
|
}
|
|
1656
|
-
function
|
|
1666
|
+
function Jo(e) {
|
|
1657
1667
|
const t = b(e.peginTxid).toLowerCase(), { peginTx: r, claimTx: o, assertTx: s } = Ut({
|
|
1658
1668
|
peginTxHex: e.peginTxHex,
|
|
1659
1669
|
claimTxHex: e.claimTxHex,
|
|
@@ -1661,10 +1671,10 @@ function Yo(e) {
|
|
|
1661
1671
|
path: "depositor_graph"
|
|
1662
1672
|
});
|
|
1663
1673
|
if (r.getId() !== t)
|
|
1664
|
-
throw new
|
|
1674
|
+
throw new P(
|
|
1665
1675
|
`Presign pegin_tx hashes to ${r.getId()}, expected ${t}`
|
|
1666
1676
|
);
|
|
1667
|
-
|
|
1677
|
+
Yo(o, t), Oe(s, o.getId(), "depositor_graph");
|
|
1668
1678
|
const n = (a) => new Uint8Array(a.toBuffer());
|
|
1669
1679
|
return qt({
|
|
1670
1680
|
peginTx: n(r),
|
|
@@ -1681,7 +1691,7 @@ function Yo(e) {
|
|
|
1681
1691
|
});
|
|
1682
1692
|
}
|
|
1683
1693
|
function Qo(e) {
|
|
1684
|
-
const t = (o) =>
|
|
1694
|
+
const t = (o) => st(B($(e, o, "graph"), o).tx, o), r = B(
|
|
1685
1695
|
$(e, "challenger_subgraphs", "graph"),
|
|
1686
1696
|
"challenger_subgraphs"
|
|
1687
1697
|
);
|
|
@@ -1694,7 +1704,7 @@ function Qo(e) {
|
|
|
1694
1704
|
const n = `challenger_subgraphs[${o}]`, a = B(s, n);
|
|
1695
1705
|
return {
|
|
1696
1706
|
pubkey: o,
|
|
1697
|
-
nopayoutTx:
|
|
1707
|
+
nopayoutTx: st(
|
|
1698
1708
|
B($(a, "nopayout_tx", n), `${n}.nopayout_tx`).tx,
|
|
1699
1709
|
`${n}.nopayout_tx`
|
|
1700
1710
|
),
|
|
@@ -1708,7 +1718,7 @@ function Qo(e) {
|
|
|
1708
1718
|
})
|
|
1709
1719
|
});
|
|
1710
1720
|
}
|
|
1711
|
-
function
|
|
1721
|
+
function Zo(e) {
|
|
1712
1722
|
const t = B(
|
|
1713
1723
|
$(e, "challenger_pubkeys", "graph"),
|
|
1714
1724
|
"challenger_pubkeys"
|
|
@@ -1720,29 +1730,29 @@ function Jo(e) {
|
|
|
1720
1730
|
).forEach((s, n) => {
|
|
1721
1731
|
const a = de(s, `challenger_pubkeys.${o}[${n}]`);
|
|
1722
1732
|
if (r.has(a))
|
|
1723
|
-
throw new
|
|
1733
|
+
throw new P(
|
|
1724
1734
|
`Graph declares challenger ${a} more than once`
|
|
1725
1735
|
);
|
|
1726
1736
|
r.add(a);
|
|
1727
1737
|
});
|
|
1728
1738
|
return r;
|
|
1729
1739
|
}
|
|
1730
|
-
function
|
|
1740
|
+
function an(e, t) {
|
|
1731
1741
|
const r = Qo(e);
|
|
1732
1742
|
if (r !== t)
|
|
1733
|
-
throw new
|
|
1743
|
+
throw new P(
|
|
1734
1744
|
`Graph fingerprint ${r} does not match the presign fingerprint ${t}`
|
|
1735
1745
|
);
|
|
1736
1746
|
const o = Object.keys(
|
|
1737
1747
|
B(e.challenger_subgraphs, "challenger_subgraphs")
|
|
1738
|
-
), s =
|
|
1748
|
+
), s = Zo(e);
|
|
1739
1749
|
if (o.length !== s.size || o.some((n) => !s.has(n)))
|
|
1740
|
-
throw new
|
|
1750
|
+
throw new P(
|
|
1741
1751
|
`Graph challenger_subgraphs keys ${o.join(", ")} do not match challenger_pubkeys ${[...s].join(", ")}`
|
|
1742
1752
|
);
|
|
1743
1753
|
}
|
|
1744
|
-
const
|
|
1745
|
-
function
|
|
1754
|
+
const es = 1;
|
|
1755
|
+
function ts(e, t, r) {
|
|
1746
1756
|
const o = r.map(
|
|
1747
1757
|
(d) => b(d).toLowerCase()
|
|
1748
1758
|
), s = t.filter((d) => o.includes(d));
|
|
@@ -1763,9 +1773,9 @@ function es(e, t, r) {
|
|
|
1763
1773
|
"Depositor graph challenger set does not match expected (local ∪ universal)" + (l.length > 0 ? ` (missing: ${l.join(", ")})` : "") + (c.length > 0 ? ` (unexpected: ${c.join(", ")})` : "")
|
|
1764
1774
|
);
|
|
1765
1775
|
}
|
|
1766
|
-
function
|
|
1776
|
+
function rs(e, t) {
|
|
1767
1777
|
const r = e.ins[t];
|
|
1768
|
-
return
|
|
1778
|
+
return Ve(new Uint8Array(r.hash).slice().reverse());
|
|
1769
1779
|
}
|
|
1770
1780
|
function $e(e, t, r, o, s) {
|
|
1771
1781
|
const n = e.ins[t];
|
|
@@ -1773,25 +1783,25 @@ function $e(e, t, r, o, s) {
|
|
|
1773
1783
|
throw new Error(
|
|
1774
1784
|
`NoPayout (challenger ${s}) input ${t} expected to spend ${o} vout 0, got vout ${n.index}`
|
|
1775
1785
|
);
|
|
1776
|
-
const a = r.getId(), i =
|
|
1786
|
+
const a = r.getId(), i = rs(e, t);
|
|
1777
1787
|
if (i !== a)
|
|
1778
1788
|
throw new Error(
|
|
1779
1789
|
`NoPayout (challenger ${s}) input ${t} does not reference ${o} (expected txid ${a}, got ${i})`
|
|
1780
1790
|
);
|
|
1781
1791
|
}
|
|
1782
|
-
async function
|
|
1783
|
-
const o = [], s = [], n = [], a =
|
|
1792
|
+
async function os(e, t, r) {
|
|
1793
|
+
const o = [], s = [], n = [], a = wt({
|
|
1784
1794
|
claimerBtcPubkey: r.depositorBtcPubkey,
|
|
1785
1795
|
depositorBtcPubkey: r.depositorBtcPubkey,
|
|
1786
1796
|
vaultProviderBtcPubkey: r.vaultProviderBtcPubkey,
|
|
1787
1797
|
vaultKeeperBtcPubkeys: r.vaultKeeperBtcPubkeys
|
|
1788
1798
|
});
|
|
1789
|
-
|
|
1799
|
+
ts(
|
|
1790
1800
|
e.challenger_presign_data,
|
|
1791
1801
|
a,
|
|
1792
1802
|
r.universalChallengerBtcPubkeys
|
|
1793
1803
|
);
|
|
1794
|
-
const i = await
|
|
1804
|
+
const i = await Cr({
|
|
1795
1805
|
vaultCoreVersion: r.vaultCoreVersion,
|
|
1796
1806
|
vkClaimerPayoutScriptPubKeys: r.vkClaimerPayoutScriptPubKeys,
|
|
1797
1807
|
vpCommissionScriptPubKey: r.vpCommissionScriptPubKey,
|
|
@@ -1807,7 +1817,7 @@ async function rs(e, t, r) {
|
|
|
1807
1817
|
network: r.network,
|
|
1808
1818
|
claimerBtcPubkey: r.depositorBtcPubkey,
|
|
1809
1819
|
registeredPayoutScriptPubKey: r.registeredPayoutScriptPubKey,
|
|
1810
|
-
commissionBps:
|
|
1820
|
+
commissionBps: es,
|
|
1811
1821
|
protocolFeeRate: r.protocolFeeRate,
|
|
1812
1822
|
councilMembers: r.councilMembers,
|
|
1813
1823
|
councilQuorum: r.councilQuorum
|
|
@@ -1815,14 +1825,14 @@ async function rs(e, t, r) {
|
|
|
1815
1825
|
o.push(i.psbtHex), s.push(
|
|
1816
1826
|
ue(
|
|
1817
1827
|
t,
|
|
1818
|
-
|
|
1828
|
+
ze
|
|
1819
1829
|
)
|
|
1820
1830
|
);
|
|
1821
1831
|
const u = b(r.depositorBtcPubkey), l = S.fromHex(
|
|
1822
1832
|
b(e.assert_tx.tx_hex)
|
|
1823
1833
|
);
|
|
1824
1834
|
for (const c of e.challenger_presign_data) {
|
|
1825
|
-
const d = b(c.challenger_pubkey), h = o.length, g = await
|
|
1835
|
+
const d = b(c.challenger_pubkey), h = o.length, g = await ss({
|
|
1826
1836
|
challenger: c,
|
|
1827
1837
|
challengerPubkey: d,
|
|
1828
1838
|
claimerPubkey: u,
|
|
@@ -1833,7 +1843,7 @@ async function rs(e, t, r) {
|
|
|
1833
1843
|
o.push(g), s.push(
|
|
1834
1844
|
ue(
|
|
1835
1845
|
t,
|
|
1836
|
-
|
|
1846
|
+
ze
|
|
1837
1847
|
)
|
|
1838
1848
|
), n.push({
|
|
1839
1849
|
challengerPubkey: d,
|
|
@@ -1842,7 +1852,7 @@ async function rs(e, t, r) {
|
|
|
1842
1852
|
}
|
|
1843
1853
|
return { psbtHexes: o, signOptions: s, challengerEntries: n };
|
|
1844
1854
|
}
|
|
1845
|
-
async function
|
|
1855
|
+
async function ss(e) {
|
|
1846
1856
|
const {
|
|
1847
1857
|
challenger: t,
|
|
1848
1858
|
challengerPubkey: r,
|
|
@@ -1851,7 +1861,7 @@ async function os(e) {
|
|
|
1851
1861
|
assertTxParsed: n,
|
|
1852
1862
|
ctx: a
|
|
1853
1863
|
} = e;
|
|
1854
|
-
|
|
1864
|
+
Or(
|
|
1855
1865
|
t.nopayout_tx.tx_hex,
|
|
1856
1866
|
r,
|
|
1857
1867
|
a.network
|
|
@@ -1891,7 +1901,7 @@ async function os(e) {
|
|
|
1891
1901
|
u.outs[0],
|
|
1892
1902
|
l.outs[0]
|
|
1893
1903
|
].map((d) => ({
|
|
1894
|
-
script_pubkey:
|
|
1904
|
+
script_pubkey: Ve(new Uint8Array(d.script)),
|
|
1895
1905
|
value: d.value
|
|
1896
1906
|
}));
|
|
1897
1907
|
return Dr({
|
|
@@ -1909,7 +1919,7 @@ async function os(e) {
|
|
|
1909
1919
|
}
|
|
1910
1920
|
});
|
|
1911
1921
|
}
|
|
1912
|
-
function
|
|
1922
|
+
function ns(e, t, r) {
|
|
1913
1923
|
ie(e[0]);
|
|
1914
1924
|
const s = ae(
|
|
1915
1925
|
e[0].returnedPsbtHex,
|
|
@@ -1944,9 +1954,9 @@ function ss(e, t, r) {
|
|
|
1944
1954
|
per_challenger: n
|
|
1945
1955
|
};
|
|
1946
1956
|
}
|
|
1947
|
-
async function
|
|
1957
|
+
async function is(e) {
|
|
1948
1958
|
const { depositorGraph: t, btcWallet: r, signingContext: o } = e;
|
|
1949
|
-
|
|
1959
|
+
Wo({
|
|
1950
1960
|
peginTxHex: o.peginTxHex,
|
|
1951
1961
|
claimTxHex: t.claim_tx.tx_hex,
|
|
1952
1962
|
assertTxHex: t.assert_tx.tx_hex,
|
|
@@ -1955,11 +1965,11 @@ async function ns(e) {
|
|
|
1955
1965
|
const s = await r.getPublicKeyHex(), { depositorPubkey: n } = tr(
|
|
1956
1966
|
s,
|
|
1957
1967
|
b(o.depositorBtcPubkey)
|
|
1958
|
-
), { psbtHexes: a, signOptions: i, challengerEntries: u } = await
|
|
1968
|
+
), { psbtHexes: a, signOptions: i, challengerEntries: u } = await os(
|
|
1959
1969
|
t,
|
|
1960
1970
|
s,
|
|
1961
1971
|
o
|
|
1962
|
-
), l = await
|
|
1972
|
+
), l = await bt(
|
|
1963
1973
|
r,
|
|
1964
1974
|
a,
|
|
1965
1975
|
i
|
|
@@ -1967,13 +1977,13 @@ async function ns(e) {
|
|
|
1967
1977
|
requestedPsbtHex: d,
|
|
1968
1978
|
returnedPsbtHex: l[h]
|
|
1969
1979
|
}));
|
|
1970
|
-
return
|
|
1980
|
+
return ns(
|
|
1971
1981
|
c,
|
|
1972
1982
|
u,
|
|
1973
1983
|
n
|
|
1974
1984
|
);
|
|
1975
1985
|
}
|
|
1976
|
-
const
|
|
1986
|
+
const as = 1e4, L = 10;
|
|
1977
1987
|
async function Xt(e) {
|
|
1978
1988
|
const {
|
|
1979
1989
|
statusReader: t,
|
|
@@ -1981,7 +1991,7 @@ async function Xt(e) {
|
|
|
1981
1991
|
peginTxid: o,
|
|
1982
1992
|
targetStatuses: s,
|
|
1983
1993
|
timeoutMs: n,
|
|
1984
|
-
pollIntervalMs: a =
|
|
1994
|
+
pollIntervalMs: a = as,
|
|
1985
1995
|
signal: i
|
|
1986
1996
|
} = e, u = Date.now();
|
|
1987
1997
|
for (; ; ) {
|
|
@@ -1998,7 +2008,7 @@ async function Xt(e) {
|
|
|
1998
2008
|
{ vault_id: r },
|
|
1999
2009
|
i
|
|
2000
2010
|
);
|
|
2001
|
-
if (
|
|
2011
|
+
if (We(l.vault_id) !== We(r))
|
|
2002
2012
|
throw new Error(
|
|
2003
2013
|
`getPeginStatusByVaultId returned status for vault ${l.vault_id.slice(0, L)}…, requested ${r.slice(0, L)}…`
|
|
2004
2014
|
);
|
|
@@ -2031,16 +2041,16 @@ async function Xt(e) {
|
|
|
2031
2041
|
});
|
|
2032
2042
|
}
|
|
2033
2043
|
}
|
|
2034
|
-
const
|
|
2044
|
+
const us = 1200 * 1e3, Gt = /* @__PURE__ */ new Set([
|
|
2035
2045
|
R.PENDING_ACKS,
|
|
2036
2046
|
R.PENDING_ACTIVATION,
|
|
2037
2047
|
R.ACTIVATED_PENDING_BROADCAST,
|
|
2038
2048
|
R.ACTIVATED
|
|
2039
|
-
]),
|
|
2049
|
+
]), cs = /* @__PURE__ */ new Set([
|
|
2040
2050
|
R.PENDING_DEPOSITOR_SIGNATURES,
|
|
2041
2051
|
...Gt
|
|
2042
2052
|
]);
|
|
2043
|
-
function
|
|
2053
|
+
function ls(e) {
|
|
2044
2054
|
return e.map((t) => ({
|
|
2045
2055
|
claimerPubkeyXOnly: he(t.claimer_pubkey),
|
|
2046
2056
|
payoutTxHex: t.payout_tx.tx_hex,
|
|
@@ -2050,7 +2060,7 @@ function cs(e) {
|
|
|
2050
2060
|
function I(e) {
|
|
2051
2061
|
return he(e).toLowerCase();
|
|
2052
2062
|
}
|
|
2053
|
-
function
|
|
2063
|
+
function ds(e, t) {
|
|
2054
2064
|
const r = (u, l, c) => {
|
|
2055
2065
|
throw new Error(
|
|
2056
2066
|
`Deposit terms ${u} (${String(l)}) does not match the vault's version-locked signing context (${String(c)}); refusing to sign payouts against terms that describe a different graph.`
|
|
@@ -2088,7 +2098,7 @@ function ls(e, t) {
|
|
|
2088
2098
|
t.vaultProviderBtcPubkey
|
|
2089
2099
|
);
|
|
2090
2100
|
}
|
|
2091
|
-
function
|
|
2101
|
+
function hs(e, t, r, o) {
|
|
2092
2102
|
const s = I(o), n = [
|
|
2093
2103
|
I(t),
|
|
2094
2104
|
...r.map(I)
|
|
@@ -2112,7 +2122,7 @@ function ds(e, t, r, o) {
|
|
|
2112
2122
|
"Presign response claimer set does not match expected (vault provider ∪ vault keepers)" + (c.length > 0 ? ` (missing: ${c.join(", ")})` : "") + (d.length > 0 ? ` (unexpected: ${d.join(", ")})` : "")
|
|
2113
2123
|
);
|
|
2114
2124
|
}
|
|
2115
|
-
function
|
|
2125
|
+
function nt(e, t) {
|
|
2116
2126
|
return {
|
|
2117
2127
|
vaultCoreVersion: t.vaultCoreVersion,
|
|
2118
2128
|
payoutTxHex: e.payoutTxHex,
|
|
@@ -2134,7 +2144,7 @@ function ot(e, t) {
|
|
|
2134
2144
|
vpCommissionScriptPubKey: t.vpCommissionScriptPubKey
|
|
2135
2145
|
};
|
|
2136
2146
|
}
|
|
2137
|
-
async function
|
|
2147
|
+
async function ps(e, t, r, o) {
|
|
2138
2148
|
const s = new or({
|
|
2139
2149
|
network: t.network,
|
|
2140
2150
|
btcWallet: e
|
|
@@ -2143,14 +2153,14 @@ async function hs(e, t, r, o) {
|
|
|
2143
2153
|
let a;
|
|
2144
2154
|
if (s.supportsBatchSigning())
|
|
2145
2155
|
a = (await s.signPayoutTransactionsBatch(
|
|
2146
|
-
r.map((l) =>
|
|
2156
|
+
r.map((l) => nt(l, t))
|
|
2147
2157
|
)).map((l) => l.payoutSignature);
|
|
2148
2158
|
else {
|
|
2149
2159
|
a = [];
|
|
2150
2160
|
for (let u = 0; u < r.length; u++) {
|
|
2151
2161
|
o == null || o(u, n);
|
|
2152
2162
|
const l = await s.signPayoutTransaction(
|
|
2153
|
-
|
|
2163
|
+
nt(r[u], t)
|
|
2154
2164
|
);
|
|
2155
2165
|
a.push(l.signature);
|
|
2156
2166
|
}
|
|
@@ -2162,7 +2172,7 @@ async function hs(e, t, r, o) {
|
|
|
2162
2172
|
};
|
|
2163
2173
|
return o == null || o(n, n), i;
|
|
2164
2174
|
}
|
|
2165
|
-
async function
|
|
2175
|
+
async function un(e) {
|
|
2166
2176
|
const {
|
|
2167
2177
|
statusReader: t,
|
|
2168
2178
|
presignClient: r,
|
|
@@ -2172,7 +2182,7 @@ async function nn(e) {
|
|
|
2172
2182
|
depositorPk: a,
|
|
2173
2183
|
signingContext: i,
|
|
2174
2184
|
depositTerms: u,
|
|
2175
|
-
timeoutMs: l =
|
|
2185
|
+
timeoutMs: l = us,
|
|
2176
2186
|
signal: c,
|
|
2177
2187
|
onProgress: d,
|
|
2178
2188
|
recordGraphFingerprint: h
|
|
@@ -2180,14 +2190,14 @@ async function nn(e) {
|
|
|
2180
2190
|
statusReader: t,
|
|
2181
2191
|
vaultId: s,
|
|
2182
2192
|
peginTxid: n,
|
|
2183
|
-
targetStatuses:
|
|
2193
|
+
targetStatuses: cs,
|
|
2184
2194
|
timeoutMs: l,
|
|
2185
2195
|
signal: c
|
|
2186
2196
|
});
|
|
2187
2197
|
if (Gt.has(g))
|
|
2188
2198
|
return;
|
|
2189
|
-
c == null || c.throwIfAborted(), u !== void 0 &&
|
|
2190
|
-
const p =
|
|
2199
|
+
c == null || c.throwIfAborted(), u !== void 0 && ds(u, i);
|
|
2200
|
+
const p = vt(o) ? o : void 0;
|
|
2191
2201
|
let y;
|
|
2192
2202
|
if (p) {
|
|
2193
2203
|
if (!u)
|
|
@@ -2203,14 +2213,14 @@ async function nn(e) {
|
|
|
2203
2213
|
},
|
|
2204
2214
|
c
|
|
2205
2215
|
);
|
|
2206
|
-
c == null || c.throwIfAborted(), f.txs.forEach((
|
|
2207
|
-
|
|
2208
|
-
claimTxHex:
|
|
2209
|
-
assertTxHex:
|
|
2216
|
+
c == null || c.throwIfAborted(), f.txs.forEach((N, oe) => {
|
|
2217
|
+
jo({
|
|
2218
|
+
claimTxHex: N.claim_tx.tx_hex,
|
|
2219
|
+
assertTxHex: N.assert_tx.tx_hex,
|
|
2210
2220
|
path: `txs[${oe}]`
|
|
2211
2221
|
});
|
|
2212
2222
|
});
|
|
2213
|
-
const
|
|
2223
|
+
const m = Jo({
|
|
2214
2224
|
peginTxid: n,
|
|
2215
2225
|
peginTxHex: i.peginTxHex,
|
|
2216
2226
|
claimTxHex: f.depositor_graph.claim_tx.tx_hex,
|
|
@@ -2218,24 +2228,24 @@ async function nn(e) {
|
|
|
2218
2228
|
payoutTxHex: f.depositor_graph.payout_tx.tx_hex,
|
|
2219
2229
|
challengers: f.depositor_graph.challenger_presign_data
|
|
2220
2230
|
}), k = I(a);
|
|
2221
|
-
|
|
2231
|
+
hs(
|
|
2222
2232
|
f.txs,
|
|
2223
2233
|
i.vaultProviderBtcPubkey,
|
|
2224
2234
|
i.vaultKeeperBtcPubkeys,
|
|
2225
2235
|
a
|
|
2226
2236
|
);
|
|
2227
2237
|
const x = f.txs.filter(
|
|
2228
|
-
(
|
|
2229
|
-
), v =
|
|
2238
|
+
(N) => I(N.claimer_pubkey) !== k
|
|
2239
|
+
), v = ls(x);
|
|
2230
2240
|
p && y && (typeof p.validateDepositTerms == "function" && await p.validateDepositTerms(y), await p.approveDepositTerms(y)), c == null || c.throwIfAborted();
|
|
2231
|
-
const E = await
|
|
2241
|
+
const E = await ps(
|
|
2232
2242
|
o,
|
|
2233
2243
|
i,
|
|
2234
2244
|
v,
|
|
2235
2245
|
d
|
|
2236
2246
|
);
|
|
2237
2247
|
c == null || c.throwIfAborted();
|
|
2238
|
-
const
|
|
2248
|
+
const T = await is({
|
|
2239
2249
|
depositorGraph: f.depositor_graph,
|
|
2240
2250
|
btcWallet: o,
|
|
2241
2251
|
signingContext: {
|
|
@@ -2256,23 +2266,23 @@ async function nn(e) {
|
|
|
2256
2266
|
vpCommissionScriptPubKey: i.vpCommissionScriptPubKey
|
|
2257
2267
|
}
|
|
2258
2268
|
});
|
|
2259
|
-
c == null || c.throwIfAborted(), await h(
|
|
2269
|
+
c == null || c.throwIfAborted(), await h(m), c == null || c.throwIfAborted();
|
|
2260
2270
|
const w = { ...E };
|
|
2261
|
-
w[b(a)] =
|
|
2271
|
+
w[b(a)] = T.payout_signatures, await r.submitDepositorPresignatures(
|
|
2262
2272
|
{
|
|
2263
2273
|
pegin_txid: n,
|
|
2264
2274
|
depositor_pk: a,
|
|
2265
2275
|
signatures: w,
|
|
2266
|
-
depositor_claimer_presignatures:
|
|
2276
|
+
depositor_claimer_presignatures: T
|
|
2267
2277
|
},
|
|
2268
2278
|
c
|
|
2269
2279
|
);
|
|
2270
2280
|
}
|
|
2271
|
-
const
|
|
2281
|
+
const gs = 300 * 1e3, fs = /* @__PURE__ */ new Set([
|
|
2272
2282
|
R.PENDING_DEPOSITOR_WOTS_PK,
|
|
2273
|
-
...
|
|
2283
|
+
...Tt
|
|
2274
2284
|
]);
|
|
2275
|
-
async function
|
|
2285
|
+
async function cn(e) {
|
|
2276
2286
|
const {
|
|
2277
2287
|
statusReader: t,
|
|
2278
2288
|
wotsSubmitter: r,
|
|
@@ -2280,7 +2290,7 @@ async function an(e) {
|
|
|
2280
2290
|
peginTxid: s,
|
|
2281
2291
|
depositorPk: n,
|
|
2282
2292
|
wotsPublicKeys: a,
|
|
2283
|
-
timeoutMs: i =
|
|
2293
|
+
timeoutMs: i = gs,
|
|
2284
2294
|
signal: u
|
|
2285
2295
|
} = e;
|
|
2286
2296
|
u == null || u.throwIfAborted();
|
|
@@ -2288,11 +2298,11 @@ async function an(e) {
|
|
|
2288
2298
|
statusReader: t,
|
|
2289
2299
|
vaultId: o,
|
|
2290
2300
|
peginTxid: s,
|
|
2291
|
-
targetStatuses:
|
|
2301
|
+
targetStatuses: fs,
|
|
2292
2302
|
timeoutMs: i,
|
|
2293
2303
|
signal: u
|
|
2294
2304
|
});
|
|
2295
|
-
|
|
2305
|
+
Tt.has(l) || (u == null || u.throwIfAborted(), await r.submitDepositorWotsKey(
|
|
2296
2306
|
{
|
|
2297
2307
|
pegin_txid: s,
|
|
2298
2308
|
depositor_pk: n,
|
|
@@ -2304,27 +2314,27 @@ async function an(e) {
|
|
|
2304
2314
|
function ke(e) {
|
|
2305
2315
|
return e.registration || e.operation;
|
|
2306
2316
|
}
|
|
2307
|
-
function
|
|
2317
|
+
function ys(e, t, r) {
|
|
2308
2318
|
const o = _(e);
|
|
2309
2319
|
return {
|
|
2310
2320
|
registration: o === _(t),
|
|
2311
2321
|
operation: o === _(r)
|
|
2312
2322
|
};
|
|
2313
2323
|
}
|
|
2314
|
-
function
|
|
2315
|
-
const o =
|
|
2324
|
+
function it(e, t, r) {
|
|
2325
|
+
const o = Te(e);
|
|
2316
2326
|
return {
|
|
2317
|
-
registration:
|
|
2318
|
-
operation:
|
|
2327
|
+
registration: at(o, Te(t)),
|
|
2328
|
+
operation: at(o, Te(r))
|
|
2319
2329
|
};
|
|
2320
2330
|
}
|
|
2321
|
-
function
|
|
2331
|
+
function Te(e) {
|
|
2322
2332
|
return e.map(_).sort();
|
|
2323
2333
|
}
|
|
2324
|
-
function
|
|
2334
|
+
function at(e, t) {
|
|
2325
2335
|
return e.length === t.length && e.every((r, o) => r === t[o]);
|
|
2326
2336
|
}
|
|
2327
|
-
async function
|
|
2337
|
+
async function ln(e) {
|
|
2328
2338
|
const {
|
|
2329
2339
|
vaultProviderEthAddress: t,
|
|
2330
2340
|
hintBtcPubkey: r,
|
|
@@ -2348,11 +2358,11 @@ class Se extends Error {
|
|
|
2348
2358
|
super(t), this.name = "ApplicationEntryPointMismatchError";
|
|
2349
2359
|
}
|
|
2350
2360
|
}
|
|
2351
|
-
function
|
|
2361
|
+
function dn(e) {
|
|
2352
2362
|
return e instanceof Se || e instanceof Error && e.name === "ApplicationEntryPointMismatchError";
|
|
2353
2363
|
}
|
|
2354
|
-
const
|
|
2355
|
-
async function
|
|
2364
|
+
const ut = (e) => e.map(_).sort();
|
|
2365
|
+
async function hn(e) {
|
|
2356
2366
|
const {
|
|
2357
2367
|
vaultRegistryReader: t,
|
|
2358
2368
|
vaultKeeperReader: r,
|
|
@@ -2391,7 +2401,7 @@ async function ln(e) {
|
|
|
2391
2401
|
throw new Se(
|
|
2392
2402
|
`Vault provider ${s} is registered to application ${g}, but this deposit was prepared for ${n}. Refusing to build: the vault keeper roster, its version, and the keeper key epoch would all resolve against a different application than the one selected.`
|
|
2393
2403
|
);
|
|
2394
|
-
const [
|
|
2404
|
+
const [m, k] = await Promise.all(
|
|
2395
2405
|
[
|
|
2396
2406
|
r.getCurrentVaultKeepersVersion(
|
|
2397
2407
|
g,
|
|
@@ -2405,7 +2415,7 @@ async function ln(e) {
|
|
|
2405
2415
|
), [x, v] = await Promise.all([
|
|
2406
2416
|
r.getVaultKeepersByVersion(
|
|
2407
2417
|
g,
|
|
2408
|
-
|
|
2418
|
+
m,
|
|
2409
2419
|
h
|
|
2410
2420
|
),
|
|
2411
2421
|
o.getUniversalChallengersByVersion(
|
|
@@ -2414,9 +2424,9 @@ async function ln(e) {
|
|
|
2414
2424
|
)
|
|
2415
2425
|
]), E = {
|
|
2416
2426
|
vaultProvider: _(p),
|
|
2417
|
-
vaultKeepers:
|
|
2418
|
-
universalChallengers:
|
|
2419
|
-
},
|
|
2427
|
+
vaultKeepers: ut(x.map((C) => C.btcPubKey)),
|
|
2428
|
+
universalChallengers: ut(v.map((C) => C.btcPubKey))
|
|
2429
|
+
}, T = await Ko({
|
|
2420
2430
|
operationKeyReader: l,
|
|
2421
2431
|
query: {
|
|
2422
2432
|
vaultProviderEthAddress: s,
|
|
@@ -2427,59 +2437,59 @@ async function ln(e) {
|
|
|
2427
2437
|
},
|
|
2428
2438
|
blockNumber: h
|
|
2429
2439
|
}), w = {
|
|
2430
|
-
vaultProvider:
|
|
2431
|
-
vaultKeepers: [...
|
|
2440
|
+
vaultProvider: T.vaultProvider.operationBtcPubkey,
|
|
2441
|
+
vaultKeepers: [...T.vaultKeeperOperationKeysSorted],
|
|
2432
2442
|
universalChallengers: [
|
|
2433
|
-
...
|
|
2443
|
+
...T.universalChallengerOperationKeysSorted
|
|
2434
2444
|
]
|
|
2435
|
-
},
|
|
2445
|
+
}, N = ys(
|
|
2436
2446
|
a,
|
|
2437
2447
|
E.vaultProvider,
|
|
2438
2448
|
w.vaultProvider
|
|
2439
|
-
), oe =
|
|
2449
|
+
), oe = it(
|
|
2440
2450
|
i,
|
|
2441
2451
|
E.vaultKeepers,
|
|
2442
2452
|
w.vaultKeepers
|
|
2443
|
-
),
|
|
2453
|
+
), De = it(
|
|
2444
2454
|
u,
|
|
2445
2455
|
E.universalChallengers,
|
|
2446
2456
|
w.universalChallengers
|
|
2447
2457
|
);
|
|
2448
|
-
if (!ke(
|
|
2458
|
+
if (!ke(N))
|
|
2449
2459
|
throw new Error(
|
|
2450
2460
|
`Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${s}. Refresh and try again.`
|
|
2451
2461
|
);
|
|
2452
2462
|
if (!ke(oe))
|
|
2453
2463
|
throw new Error(
|
|
2454
|
-
`Vault keeper BTC pubkeys (v${
|
|
2464
|
+
`Vault keeper BTC pubkeys (v${m}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
|
|
2455
2465
|
);
|
|
2456
|
-
if (!ke(
|
|
2466
|
+
if (!ke(De))
|
|
2457
2467
|
throw new Error(
|
|
2458
2468
|
`Universal challenger BTC pubkeys (v${y}) indexer set does not match ProtocolParams on-chain set. Refresh and try again.`
|
|
2459
2469
|
);
|
|
2460
|
-
const
|
|
2461
|
-
if (
|
|
2462
|
-
const
|
|
2463
|
-
throw d == null || d(
|
|
2470
|
+
const Me = [N, oe, De], Jt = Me.some((C) => C.registration && !C.operation), Le = Me.some((C) => C.operation && !C.registration);
|
|
2471
|
+
if (Jt && Le) {
|
|
2472
|
+
const C = `Indexer participant hints are internally inconsistent for vault provider ${s}: some roles match the registration keys while others match the rotated operation keys.`;
|
|
2473
|
+
throw d == null || d(C), new Error(`${C} Refresh and try again.`);
|
|
2464
2474
|
}
|
|
2465
|
-
return
|
|
2475
|
+
return Le && (c == null || c(
|
|
2466
2476
|
`Indexer is serving rotated operation keys for vault provider ${s}`
|
|
2467
2477
|
)), {
|
|
2468
2478
|
vaultProviderBtcPubkeyXOnly: w.vaultProvider,
|
|
2469
2479
|
vaultKeeperBtcPubkeysSorted: w.vaultKeepers,
|
|
2470
2480
|
universalChallengerBtcPubkeysSorted: w.universalChallengers,
|
|
2471
|
-
expectedAppVaultKeepersVersion:
|
|
2481
|
+
expectedAppVaultKeepersVersion: m,
|
|
2472
2482
|
expectedUniversalChallengersVersion: y,
|
|
2473
2483
|
appKeeperKeyEpoch: k,
|
|
2474
2484
|
ucKeyEpoch: f,
|
|
2475
2485
|
registrationKeys: E,
|
|
2476
|
-
participantKeys:
|
|
2486
|
+
participantKeys: T
|
|
2477
2487
|
};
|
|
2478
2488
|
}
|
|
2479
|
-
function
|
|
2489
|
+
function vs(e) {
|
|
2480
2490
|
return /^[0-9a-fA-F]{64}$/.test(e);
|
|
2481
2491
|
}
|
|
2482
|
-
function
|
|
2492
|
+
function pn(e) {
|
|
2483
2493
|
const {
|
|
2484
2494
|
amountSats: t,
|
|
2485
2495
|
minDeposit: r,
|
|
@@ -2490,29 +2500,29 @@ function dn(e) {
|
|
|
2490
2500
|
} = e;
|
|
2491
2501
|
return !(t <= 0n || t < r || o && o > 0n && t > o || n == null || a == null || t + n + a > s);
|
|
2492
2502
|
}
|
|
2493
|
-
function
|
|
2503
|
+
function gn(e, t, r) {
|
|
2494
2504
|
return e <= 0n ? {
|
|
2495
2505
|
valid: !1,
|
|
2496
2506
|
error: "Deposit amount must be greater than zero"
|
|
2497
2507
|
} : e < t ? {
|
|
2498
2508
|
valid: !1,
|
|
2499
|
-
error: `Minimum deposit is ${
|
|
2509
|
+
error: `Minimum deposit is ${O(t)} BTC`
|
|
2500
2510
|
} : r && r > 0n && e > r ? {
|
|
2501
2511
|
valid: !1,
|
|
2502
|
-
error: `Maximum deposit is ${
|
|
2512
|
+
error: `Maximum deposit is ${O(r)} BTC`
|
|
2503
2513
|
} : { valid: !0 };
|
|
2504
2514
|
}
|
|
2505
|
-
function
|
|
2515
|
+
function fn(e) {
|
|
2506
2516
|
const { amount: t, effectiveRemaining: r } = e;
|
|
2507
2517
|
return r === null ? { valid: !0 } : r === 0n ? {
|
|
2508
2518
|
valid: !1,
|
|
2509
2519
|
error: "Supply cap reached — deposits temporarily paused"
|
|
2510
2520
|
} : t > r ? {
|
|
2511
2521
|
valid: !1,
|
|
2512
|
-
error: `Vault size exceeds remaining capacity (${
|
|
2522
|
+
error: `Vault size exceeds remaining capacity (${O(r)} BTC)`
|
|
2513
2523
|
} : { valid: !0 };
|
|
2514
2524
|
}
|
|
2515
|
-
function
|
|
2525
|
+
function yn(e, t) {
|
|
2516
2526
|
if (!e || e.length === 0)
|
|
2517
2527
|
return {
|
|
2518
2528
|
valid: !1,
|
|
@@ -2528,7 +2538,7 @@ function gn(e, t) {
|
|
|
2528
2538
|
error: "Invalid vault provider selected"
|
|
2529
2539
|
} : { valid: !0 };
|
|
2530
2540
|
}
|
|
2531
|
-
function
|
|
2541
|
+
function bs(e, t, r) {
|
|
2532
2542
|
if (!e || e.length === 0)
|
|
2533
2543
|
return {
|
|
2534
2544
|
valid: !1,
|
|
@@ -2544,19 +2554,19 @@ function vs(e, t, r) {
|
|
|
2544
2554
|
if (t && s < t)
|
|
2545
2555
|
return {
|
|
2546
2556
|
valid: !1,
|
|
2547
|
-
error: `Vault ${o + 1} amount ${
|
|
2557
|
+
error: `Vault ${o + 1} amount ${O(s)} BTC is below minimum deposit ${O(t)} BTC`
|
|
2548
2558
|
};
|
|
2549
2559
|
if (r && s > r)
|
|
2550
2560
|
return {
|
|
2551
2561
|
valid: !1,
|
|
2552
|
-
error: `Vault ${o + 1} amount ${
|
|
2562
|
+
error: `Vault ${o + 1} amount ${O(s)} BTC exceeds maximum deposit ${O(r)} BTC`
|
|
2553
2563
|
};
|
|
2554
2564
|
}
|
|
2555
2565
|
return { valid: !0 };
|
|
2556
2566
|
}
|
|
2557
|
-
function
|
|
2567
|
+
function ms(e) {
|
|
2558
2568
|
const t = b(e);
|
|
2559
|
-
return
|
|
2569
|
+
return vs(t) ? { valid: !0 } : {
|
|
2560
2570
|
valid: !1,
|
|
2561
2571
|
error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
|
|
2562
2572
|
};
|
|
@@ -2567,17 +2577,17 @@ function Ps(e) {
|
|
|
2567
2577
|
"No vault keepers available. The system requires at least one vault keeper to create a deposit."
|
|
2568
2578
|
);
|
|
2569
2579
|
}
|
|
2570
|
-
function
|
|
2580
|
+
function ws(e) {
|
|
2571
2581
|
if (!e || e.length === 0)
|
|
2572
2582
|
throw new Error(
|
|
2573
2583
|
"No universal challengers available. The system requires at least one universal challenger to create a deposit."
|
|
2574
2584
|
);
|
|
2575
2585
|
}
|
|
2576
|
-
function
|
|
2586
|
+
function xs(e) {
|
|
2577
2587
|
if (e.length === 0)
|
|
2578
2588
|
throw new Error("No spendable UTXOs available");
|
|
2579
2589
|
}
|
|
2580
|
-
function
|
|
2590
|
+
function vn(e) {
|
|
2581
2591
|
const {
|
|
2582
2592
|
vaultAmounts: t,
|
|
2583
2593
|
confirmedUTXOs: r,
|
|
@@ -2586,30 +2596,30 @@ function fn(e) {
|
|
|
2586
2596
|
universalChallengerBtcPubkeys: n,
|
|
2587
2597
|
minDeposit: a,
|
|
2588
2598
|
maxDeposit: i
|
|
2589
|
-
} = e, u =
|
|
2599
|
+
} = e, u = bs(
|
|
2590
2600
|
t,
|
|
2591
2601
|
a,
|
|
2592
2602
|
i
|
|
2593
2603
|
);
|
|
2594
2604
|
if (!u.valid)
|
|
2595
2605
|
throw new Error(u.error);
|
|
2596
|
-
const l =
|
|
2606
|
+
const l = ms(o);
|
|
2597
2607
|
if (!l.valid)
|
|
2598
2608
|
throw new Error(l.error);
|
|
2599
|
-
Ps(s),
|
|
2609
|
+
Ps(s), ws(n), xs(r);
|
|
2600
2610
|
}
|
|
2601
2611
|
class zt extends Error {
|
|
2602
2612
|
constructor(t) {
|
|
2603
2613
|
super(t), this.name = "ParticipantKeyDriftError";
|
|
2604
2614
|
}
|
|
2605
2615
|
}
|
|
2606
|
-
function
|
|
2616
|
+
function bn(e) {
|
|
2607
2617
|
return e instanceof zt || e instanceof Error && e.name === "ParticipantKeyDriftError";
|
|
2608
2618
|
}
|
|
2609
|
-
function
|
|
2619
|
+
function ct(e, t, r) {
|
|
2610
2620
|
return t.length === r.length && t.every((o, s) => o === r[s]) ? null : `${e} expected [${t.join(", ")}], got [${r.join(", ")}]`;
|
|
2611
2621
|
}
|
|
2612
|
-
async function
|
|
2622
|
+
async function mn(e) {
|
|
2613
2623
|
const { vaultRegistryReader: t, operationKeyReader: r, vaultIds: o, expected: s } = e, n = s.query;
|
|
2614
2624
|
if (o.length === 0) return;
|
|
2615
2625
|
const a = await t.getVaultKeyEpochsBatch(o), i = [];
|
|
@@ -2617,7 +2627,7 @@ async function vn(e) {
|
|
|
2617
2627
|
const c = o[u];
|
|
2618
2628
|
let d;
|
|
2619
2629
|
try {
|
|
2620
|
-
d = await
|
|
2630
|
+
d = await Ot({
|
|
2621
2631
|
operationKeyReader: r,
|
|
2622
2632
|
query: n,
|
|
2623
2633
|
epochs: l
|
|
@@ -2631,13 +2641,13 @@ async function vn(e) {
|
|
|
2631
2641
|
d.vaultProvider.operationBtcPubkey !== s.vaultProvider.operationBtcPubkey && i.push(
|
|
2632
2642
|
`vault ${c}: vault provider key expected ${s.vaultProvider.operationBtcPubkey}, got ${d.vaultProvider.operationBtcPubkey}`
|
|
2633
2643
|
);
|
|
2634
|
-
const h =
|
|
2644
|
+
const h = ct(
|
|
2635
2645
|
`vault ${c}: vault keeper keys`,
|
|
2636
2646
|
s.vaultKeeperOperationKeysSorted,
|
|
2637
2647
|
d.vaultKeeperOperationKeysSorted
|
|
2638
2648
|
);
|
|
2639
2649
|
h && i.push(h);
|
|
2640
|
-
const g =
|
|
2650
|
+
const g = ct(
|
|
2641
2651
|
`vault ${c}: universal challenger keys`,
|
|
2642
2652
|
s.universalChallengerOperationKeysSorted,
|
|
2643
2653
|
d.universalChallengerOperationKeysSorted
|
|
@@ -2654,10 +2664,10 @@ class jt extends Error {
|
|
|
2654
2664
|
super(t), this.name = "RegisteredVaultVersionMismatchError";
|
|
2655
2665
|
}
|
|
2656
2666
|
}
|
|
2657
|
-
function
|
|
2667
|
+
function Pn(e) {
|
|
2658
2668
|
return e instanceof jt || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
|
|
2659
2669
|
}
|
|
2660
|
-
async function
|
|
2670
|
+
async function wn(e) {
|
|
2661
2671
|
const {
|
|
2662
2672
|
vaultRegistryReader: t,
|
|
2663
2673
|
vaultIds: r,
|
|
@@ -2682,7 +2692,7 @@ async function Pn(e) {
|
|
|
2682
2692
|
`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.`
|
|
2683
2693
|
);
|
|
2684
2694
|
}
|
|
2685
|
-
class
|
|
2695
|
+
class Es extends Error {
|
|
2686
2696
|
constructor(r, o) {
|
|
2687
2697
|
super(`Refund not yet mature (BIP68 not final): ${o.message}`);
|
|
2688
2698
|
z(this, "vaultId");
|
|
@@ -2690,30 +2700,30 @@ class xs extends Error {
|
|
|
2690
2700
|
this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = o;
|
|
2691
2701
|
}
|
|
2692
2702
|
}
|
|
2693
|
-
const
|
|
2694
|
-
function
|
|
2703
|
+
const $s = /^0x[0-9a-fA-F]{64}$/, ks = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, Wt = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, Yt = 160, lt = 2e3, dt = 10n, ht = 100n;
|
|
2704
|
+
function xn(e) {
|
|
2695
2705
|
if (!Number.isFinite(e) || e <= 0)
|
|
2696
2706
|
throw new Error(
|
|
2697
2707
|
`feeRateSatsVb must be a positive finite number, got ${e}`
|
|
2698
2708
|
);
|
|
2699
2709
|
return BigInt(Math.ceil(e * Yt));
|
|
2700
2710
|
}
|
|
2701
|
-
const
|
|
2711
|
+
const Ts = 1, Cs = /non-BIP68-final/i;
|
|
2702
2712
|
function Ae(e, t) {
|
|
2703
2713
|
if (e.length !== 66)
|
|
2704
2714
|
throw new Error(
|
|
2705
2715
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
2706
2716
|
);
|
|
2707
|
-
if (
|
|
2717
|
+
if (!$s.test(e))
|
|
2708
2718
|
throw new Error(
|
|
2709
2719
|
`${t} must contain only hex characters after the 0x prefix`
|
|
2710
2720
|
);
|
|
2711
2721
|
}
|
|
2712
|
-
function
|
|
2722
|
+
function Ce(e, t) {
|
|
2713
2723
|
if (!Number.isInteger(e) || e < 0)
|
|
2714
2724
|
throw new Error(`${t} must be a non-negative integer, got ${e}`);
|
|
2715
2725
|
}
|
|
2716
|
-
function
|
|
2726
|
+
function _s(e) {
|
|
2717
2727
|
if (Ae(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0)
|
|
2718
2728
|
throw new Error(
|
|
2719
2729
|
`htlcVout must be a non-negative integer, got ${e.htlcVout}`
|
|
@@ -2744,7 +2754,7 @@ function Ts(e) {
|
|
|
2744
2754
|
throw new Error(
|
|
2745
2755
|
`batch[${e.htlcVout}].amount (${t.amount}) does not match target amount (${e.amount})`
|
|
2746
2756
|
);
|
|
2747
|
-
if (
|
|
2757
|
+
if (Ce(e.offchainParamsVersion, "offchainParamsVersion"), Ce(e.appVaultKeepersVersion, "appVaultKeepersVersion"), Ce(
|
|
2748
2758
|
e.universalChallengersVersion,
|
|
2749
2759
|
"universalChallengersVersion"
|
|
2750
2760
|
), Ur(
|
|
@@ -2752,7 +2762,7 @@ function Ts(e) {
|
|
|
2752
2762
|
"VaultRefundData.vaultCoreVersion"
|
|
2753
2763
|
), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
|
|
2754
2764
|
throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
|
|
2755
|
-
if (
|
|
2765
|
+
if (!ks.test(e.unsignedPrePeginTxHex))
|
|
2756
2766
|
throw new Error(
|
|
2757
2767
|
"unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
|
|
2758
2768
|
);
|
|
@@ -2763,7 +2773,7 @@ function Ts(e) {
|
|
|
2763
2773
|
if (typeof e.amount != "bigint" || e.amount <= 0n)
|
|
2764
2774
|
throw new Error(`amount must be a positive bigint, got ${e.amount}`);
|
|
2765
2775
|
}
|
|
2766
|
-
function
|
|
2776
|
+
function Ss(e) {
|
|
2767
2777
|
if (!e.vaultProviderPubkey || !Wt.test(e.vaultProviderPubkey))
|
|
2768
2778
|
throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
|
|
2769
2779
|
if (e.vaultKeeperPubkeys.length === 0)
|
|
@@ -2789,7 +2799,7 @@ function _s(e) {
|
|
|
2789
2799
|
`councilQuorum (${e.councilQuorum}) must be in [1, councilSize=${e.councilSize}]`
|
|
2790
2800
|
);
|
|
2791
2801
|
}
|
|
2792
|
-
async function
|
|
2802
|
+
async function En(e) {
|
|
2793
2803
|
const {
|
|
2794
2804
|
vaultId: t,
|
|
2795
2805
|
readVault: r,
|
|
@@ -2801,18 +2811,18 @@ async function wn(e) {
|
|
|
2801
2811
|
} = e;
|
|
2802
2812
|
i == null || i.throwIfAborted(), Ae(t, "vaultId");
|
|
2803
2813
|
const u = await r();
|
|
2804
|
-
|
|
2814
|
+
_s(u), i == null || i.throwIfAborted();
|
|
2805
2815
|
const l = await o(u);
|
|
2806
|
-
if (
|
|
2816
|
+
if (Ss(l), i == null || i.throwIfAborted(), !Number.isFinite(s) || s <= 0)
|
|
2807
2817
|
throw new Error(`feeRate must be a positive number, got ${s}`);
|
|
2808
|
-
if (s >
|
|
2818
|
+
if (s > lt)
|
|
2809
2819
|
throw new Error(
|
|
2810
|
-
`feeRate ${s} sat/vB exceeds refund safety cap ${
|
|
2820
|
+
`feeRate ${s} sat/vB exceeds refund safety cap ${lt} sat/vB; refusing to sign refund.`
|
|
2811
2821
|
);
|
|
2812
|
-
const c = BigInt(Math.ceil(s * Yt)), d = u.amount *
|
|
2822
|
+
const c = BigInt(Math.ceil(s * Yt)), d = u.amount * dt / ht;
|
|
2813
2823
|
if (c > d)
|
|
2814
2824
|
throw new Error(
|
|
2815
|
-
`Refund fee ${c} sats exceeds the per-vault safety cap of ${d} sats (${
|
|
2825
|
+
`Refund fee ${c} sats exceeds the per-vault safety cap of ${d} sats (${dt}/${ht} of vault.amount=${u.amount}); refusing to sign refund.`
|
|
2816
2826
|
);
|
|
2817
2827
|
i == null || i.throwIfAborted();
|
|
2818
2828
|
const h = he(
|
|
@@ -2835,7 +2845,7 @@ async function wn(e) {
|
|
|
2835
2845
|
throw new Error(
|
|
2836
2846
|
`Funded Pre-PegIn tx has ${f.outs.length} outputs but batch requires at least ${u.batch.length} HTLC outputs. Refund refused — funded tx shape disagrees with sibling vector.`
|
|
2837
2847
|
);
|
|
2838
|
-
const { psbtHex:
|
|
2848
|
+
const { psbtHex: m } = await Mr({
|
|
2839
2849
|
prePeginParams: {
|
|
2840
2850
|
vaultCoreVersion: u.vaultCoreVersion,
|
|
2841
2851
|
depositorPubkey: h,
|
|
@@ -2871,10 +2881,10 @@ async function wn(e) {
|
|
|
2871
2881
|
i == null || i.throwIfAborted();
|
|
2872
2882
|
const k = ue(
|
|
2873
2883
|
u.depositorBtcPubkey,
|
|
2874
|
-
|
|
2875
|
-
), x = await n(
|
|
2884
|
+
Ts
|
|
2885
|
+
), x = await n(m, k);
|
|
2876
2886
|
ie({
|
|
2877
|
-
requestedPsbtHex:
|
|
2887
|
+
requestedPsbtHex: m,
|
|
2878
2888
|
returnedPsbtHex: x
|
|
2879
2889
|
});
|
|
2880
2890
|
const v = 0, E = ae(
|
|
@@ -2883,24 +2893,24 @@ async function wn(e) {
|
|
|
2883
2893
|
v
|
|
2884
2894
|
);
|
|
2885
2895
|
re({
|
|
2886
|
-
requestedPsbtHex:
|
|
2896
|
+
requestedPsbtHex: m,
|
|
2887
2897
|
signatureHex: E,
|
|
2888
2898
|
signerXOnlyPubkeyHex: h,
|
|
2889
2899
|
inputIndex: v
|
|
2890
2900
|
});
|
|
2891
|
-
const
|
|
2892
|
-
requestedPsbtHex:
|
|
2901
|
+
const T = Ct({
|
|
2902
|
+
requestedPsbtHex: m,
|
|
2893
2903
|
signaturesHex: [E],
|
|
2894
2904
|
signerXOnlyPubkeyHex: h
|
|
2895
2905
|
});
|
|
2896
2906
|
i == null || i.throwIfAborted();
|
|
2897
2907
|
try {
|
|
2898
|
-
return await a(
|
|
2908
|
+
return await a(T);
|
|
2899
2909
|
} catch (w) {
|
|
2900
|
-
throw w instanceof Error && Cs.test(w.message) ? new
|
|
2910
|
+
throw w instanceof Error && Cs.test(w.message) ? new Es(t, w) : w;
|
|
2901
2911
|
}
|
|
2902
2912
|
}
|
|
2903
|
-
class
|
|
2913
|
+
class pt extends Error {
|
|
2904
2914
|
constructor(r, o, s) {
|
|
2905
2915
|
super(r);
|
|
2906
2916
|
/** Fee the reclaim would have paid, in satoshis. */
|
|
@@ -2910,10 +2920,10 @@ class dt extends Error {
|
|
|
2910
2920
|
this.name = "ReclaimUneconomicalError", this.feeSats = o, this.sweptTotalSats = s;
|
|
2911
2921
|
}
|
|
2912
2922
|
}
|
|
2913
|
-
const
|
|
2914
|
-
async function
|
|
2923
|
+
const gt = 2e3, ft = 25n, yt = 100n, $n = 10n;
|
|
2924
|
+
async function As(e, t, r) {
|
|
2915
2925
|
for (let o = 0; o < e.length; o++) {
|
|
2916
|
-
const s = qr(e[o].depositorSignedPeginTxHex), n =
|
|
2926
|
+
const s = qr(e[o].depositorSignedPeginTxHex), n = Ie(
|
|
2917
2927
|
await yr(
|
|
2918
2928
|
b(s),
|
|
2919
2929
|
b(r)
|
|
@@ -2925,7 +2935,7 @@ async function Ss(e, t, r) {
|
|
|
2925
2935
|
);
|
|
2926
2936
|
}
|
|
2927
2937
|
}
|
|
2928
|
-
async function
|
|
2938
|
+
async function kn(e) {
|
|
2929
2939
|
const {
|
|
2930
2940
|
vaultIds: t,
|
|
2931
2941
|
depositorEthAddress: r,
|
|
@@ -2940,9 +2950,9 @@ async function En(e) {
|
|
|
2940
2950
|
throw new Error("Reclaim requires at least one vault id; got none.");
|
|
2941
2951
|
if (!Number.isFinite(n) || n <= 0)
|
|
2942
2952
|
throw new Error(`feeRate must be a positive number, got ${n}`);
|
|
2943
|
-
if (n >
|
|
2944
|
-
throw new
|
|
2945
|
-
`Fee rate ${n} sat/vB exceeds the reclaim safety cap of ${
|
|
2953
|
+
if (n > gt)
|
|
2954
|
+
throw new pt(
|
|
2955
|
+
`Fee rate ${n} sat/vB exceeds the reclaim safety cap of ${gt} sat/vB; refusing to sign.`,
|
|
2946
2956
|
0n,
|
|
2947
2957
|
0n
|
|
2948
2958
|
);
|
|
@@ -2951,15 +2961,15 @@ async function En(e) {
|
|
|
2951
2961
|
throw new Error(
|
|
2952
2962
|
`readVaults returned ${l.length} reserves for ${t.length} vault id(s); refusing to sweep a set that does not match the request.`
|
|
2953
2963
|
);
|
|
2954
|
-
await
|
|
2964
|
+
await As(l, t, r), u == null || u.throwIfAborted();
|
|
2955
2965
|
const c = he(o), d = l.map((v) => ({
|
|
2956
2966
|
depositorSignedPeginTxHex: v.depositorSignedPeginTxHex,
|
|
2957
2967
|
observed: v.observed,
|
|
2958
2968
|
expectedValue: v.expectedClaimValue
|
|
2959
|
-
})), h = Lr(n, d.length), g = d.reduce((v, E) => v + E.expectedValue, 0n), p = g *
|
|
2969
|
+
})), h = Lr(n, d.length), g = d.reduce((v, E) => v + E.expectedValue, 0n), p = g * ft / yt;
|
|
2960
2970
|
if (h > p)
|
|
2961
|
-
throw new
|
|
2962
|
-
`Reclaim fee ${h} sats exceeds ${
|
|
2971
|
+
throw new pt(
|
|
2972
|
+
`Reclaim fee ${h} sats exceeds ${ft}/${yt} of the swept total (${g} sats, cap ${p} sats). The reserve is not at risk — it stays where it is until fee rates fall.`,
|
|
2963
2973
|
h,
|
|
2964
2974
|
g
|
|
2965
2975
|
);
|
|
@@ -2973,23 +2983,23 @@ async function En(e) {
|
|
|
2973
2983
|
const f = ue(
|
|
2974
2984
|
o,
|
|
2975
2985
|
d.length
|
|
2976
|
-
),
|
|
2986
|
+
), m = await a(y, f);
|
|
2977
2987
|
ie({
|
|
2978
2988
|
requestedPsbtHex: y,
|
|
2979
|
-
returnedPsbtHex:
|
|
2989
|
+
returnedPsbtHex: m
|
|
2980
2990
|
});
|
|
2981
2991
|
const k = d.map((v, E) => {
|
|
2982
|
-
const
|
|
2983
|
-
|
|
2992
|
+
const T = ae(
|
|
2993
|
+
m,
|
|
2984
2994
|
c,
|
|
2985
2995
|
E
|
|
2986
2996
|
);
|
|
2987
2997
|
return re({
|
|
2988
2998
|
requestedPsbtHex: y,
|
|
2989
|
-
signatureHex:
|
|
2999
|
+
signatureHex: T,
|
|
2990
3000
|
signerXOnlyPubkeyHex: c,
|
|
2991
3001
|
inputIndex: E
|
|
2992
|
-
}),
|
|
3002
|
+
}), T;
|
|
2993
3003
|
}), x = Ct({
|
|
2994
3004
|
requestedPsbtHex: y,
|
|
2995
3005
|
signaturesHex: k,
|
|
@@ -2998,80 +3008,80 @@ async function En(e) {
|
|
|
2998
3008
|
return u == null || u.throwIfAborted(), i(x);
|
|
2999
3009
|
}
|
|
3000
3010
|
export {
|
|
3001
|
-
|
|
3011
|
+
wn as $,
|
|
3002
3012
|
K as A,
|
|
3003
|
-
|
|
3013
|
+
an as B,
|
|
3004
3014
|
eo as C,
|
|
3005
3015
|
U as D,
|
|
3006
3016
|
Qo as E,
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3017
|
+
un as F,
|
|
3018
|
+
P as G,
|
|
3019
|
+
is as H,
|
|
3020
|
+
cn as I,
|
|
3011
3021
|
Se as J,
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3022
|
+
dn as K,
|
|
3023
|
+
hn as L,
|
|
3024
|
+
pn as M,
|
|
3025
|
+
gn as N,
|
|
3026
|
+
vn as O,
|
|
3017
3027
|
ro as P,
|
|
3018
|
-
|
|
3019
|
-
|
|
3028
|
+
yn as Q,
|
|
3029
|
+
fn as R,
|
|
3020
3030
|
j as S,
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3031
|
+
bs as T,
|
|
3032
|
+
ms as U,
|
|
3033
|
+
io as V,
|
|
3024
3034
|
zt as W,
|
|
3025
|
-
|
|
3026
|
-
|
|
3035
|
+
bn as X,
|
|
3036
|
+
mn as Y,
|
|
3027
3037
|
jt as Z,
|
|
3028
|
-
|
|
3029
|
-
|
|
3038
|
+
Pn as _,
|
|
3039
|
+
Js as a,
|
|
3030
3040
|
Xt as a0,
|
|
3031
|
-
|
|
3041
|
+
ln as a1,
|
|
3032
3042
|
ke as a2,
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3043
|
+
ys as a3,
|
|
3044
|
+
it as a4,
|
|
3045
|
+
Ho as a5,
|
|
3046
|
+
Ko as a6,
|
|
3047
|
+
Ot as a7,
|
|
3048
|
+
Es as a8,
|
|
3049
|
+
En as a9,
|
|
3050
|
+
xn as aa,
|
|
3051
|
+
ht as ab,
|
|
3052
|
+
dt as ac,
|
|
3053
|
+
lt as ad,
|
|
3044
3054
|
Yt as ae,
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3055
|
+
pt as af,
|
|
3056
|
+
kn as ag,
|
|
3057
|
+
yt as ah,
|
|
3058
|
+
ft as ai,
|
|
3059
|
+
gt as aj,
|
|
3060
|
+
$n as ak,
|
|
3051
3061
|
Qs as b,
|
|
3052
3062
|
Zs as c,
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3063
|
+
tn as d,
|
|
3064
|
+
wo as e,
|
|
3065
|
+
Qr as f,
|
|
3066
|
+
to as g,
|
|
3067
|
+
rn as h,
|
|
3068
|
+
oo as i,
|
|
3069
|
+
se as j,
|
|
3070
|
+
no as k,
|
|
3071
|
+
co as l,
|
|
3072
|
+
en as m,
|
|
3073
|
+
Eo as n,
|
|
3074
|
+
So as o,
|
|
3075
|
+
bo as p,
|
|
3076
|
+
ko as q,
|
|
3077
|
+
on as r,
|
|
3068
3078
|
po as s,
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3079
|
+
St as t,
|
|
3080
|
+
No as u,
|
|
3081
|
+
Dt as v,
|
|
3082
|
+
Mt as w,
|
|
3083
|
+
Lo as x,
|
|
3084
|
+
sn as y,
|
|
3085
|
+
nn as z
|
|
3076
3086
|
};
|
|
3077
|
-
//# sourceMappingURL=buildAndBroadcastReclaim-
|
|
3087
|
+
//# sourceMappingURL=buildAndBroadcastReclaim-CcQ0b1be.js.map
|