@babylonlabs-io/ts-sdk 5.1.0 → 6.0.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/{buildAndBroadcastReclaim-Acz637Vf.js → buildAndBroadcastReclaim-Bs_zdDGN.js} +793 -772
- package/dist/{buildAndBroadcastReclaim-Acz637Vf.js.map → buildAndBroadcastReclaim-Bs_zdDGN.js.map} +1 -1
- package/dist/{buildAndBroadcastReclaim-Cf05JFP-.cjs → buildAndBroadcastReclaim-CXOMHHgK.cjs} +2 -2
- package/dist/{buildAndBroadcastReclaim-Cf05JFP-.cjs.map → buildAndBroadcastReclaim-CXOMHHgK.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +95 -94
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +77 -76
- package/dist/tbv/core/recovery/reconstructPeginParams.d.ts +6 -0
- package/dist/tbv/core/recovery/reconstructPeginParams.d.ts.map +1 -1
- package/dist/tbv/core/recovery/toRefundInputs.d.ts +0 -2
- package/dist/tbv/core/recovery/toRefundInputs.d.ts.map +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +73 -72
- package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts +6 -2
- package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts.map +1 -1
- package/dist/tbv/core/services/refund/errors.d.ts +15 -0
- package/dist/tbv/core/services/refund/errors.d.ts.map +1 -1
- package/dist/tbv/core/services/refund/index.d.ts +1 -1
- package/dist/tbv/core/services/refund/index.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +77 -76
- package/dist/{toRefundInputs-DwXpKQxN.js → toRefundInputs-Cl4KgzIc.js} +149 -149
- package/dist/{toRefundInputs-DwXpKQxN.js.map → toRefundInputs-Cl4KgzIc.js.map} +1 -1
- package/dist/{toRefundInputs-BzyN0zvj.cjs → toRefundInputs-DyIgmGJq.cjs} +2 -2
- package/dist/{toRefundInputs-BzyN0zvj.cjs.map → toRefundInputs-DyIgmGJq.cjs.map} +1 -1
- package/package.json +1 -1
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
1
|
+
var rr = Object.defineProperty;
|
|
2
|
+
var or = (e, t, r) => t in e ? rr(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var B = (e, t, r) => or(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
4
|
import { B as Be } from "./BTCVaultRegistry.abi-DnP4UkB5.js";
|
|
5
|
-
import { e as Ie, s as P, i as
|
|
6
|
-
import { v as
|
|
7
|
-
import { verifyWatchtowerArtifacts as
|
|
8
|
-
import { m as
|
|
9
|
-
import { Psbt as
|
|
10
|
-
import { F
|
|
11
|
-
import { p as
|
|
12
|
-
import { Buffer as
|
|
13
|
-
import { C as
|
|
5
|
+
import { e as Ie, s as P, i as sr, u as vt, c as _, v as nr, g as ir, p as he, f as D } from "./bitcoin-C-TuHb-v.js";
|
|
6
|
+
import { v as ar, s as Pt, b as mt, P as ur, d as cr } from "./PayoutManager-BHeiLQ1j.js";
|
|
7
|
+
import { verifyWatchtowerArtifacts as lr, buildClaimPsbt as dr, buildAssertClaimerPsbt as pr, buildPayoutClaimerPsbt as hr, buildWronglyChallengedPsbts as gr, buildPayoutDepositorPsbt as fr, finalizeClaimTx as yr, buildWatchtowerArtifacts as vr, extractTapScriptSig as bt, expandWotsSeed as Pr, wotsKeypairFromSeed as mr, validateWotsKeypairAgainstGraph as br, getChallengeAssertOutputScriptPubKey as wr, deriveVaultId as xr } from "./tbv/core/wasm/index.js";
|
|
8
|
+
import { m as Er, d as wt, k as $r, a as _e, V as Le, i as kr, g as Cr, f as Tr, r as _r, h as Sr } from "./registration-records-D39ApuHS.js";
|
|
9
|
+
import { Psbt as G, Transaction as S } from "bitcoinjs-lib";
|
|
10
|
+
import { F, G as A, H as re, I as J, A as X, z as Z, J as ge, v as Me, E as ee, K as Ve, w as Ue, x as Fe, y as qe, W as Ar, D as Ge, C as Xe, L as Br, O as Ir, Q as Vr } from "./constants-CmDDuM3L.js";
|
|
11
|
+
import { p as Rr, q as Kr, r as xt, P as z, j as oe, f as Hr, i as ae, g as ue, s as Or } from "./verifyScriptPathSchnorrSignature-DLNGgm4j.js";
|
|
12
|
+
import { Buffer as O } from "buffer";
|
|
13
|
+
import { C as Et, X as $t } from "./validation-OSC0xTHB.js";
|
|
14
14
|
import { a as kt, c as ce } from "./signing-C1rR4tqs.js";
|
|
15
|
-
import { d as
|
|
16
|
-
import { O as ze, d as
|
|
17
|
-
import { zeroAddress as
|
|
18
|
-
import { v as je, D as
|
|
19
|
-
import { h as We, b as
|
|
20
|
-
import { c as
|
|
21
|
-
import { a as
|
|
22
|
-
import { c as
|
|
23
|
-
const
|
|
15
|
+
import { d as Ct } from "./deriveVaultRoot-BcvmER1E.js";
|
|
16
|
+
import { O as ze, d as Nr } from "./types-K_aM5GZO.js";
|
|
17
|
+
import { zeroAddress as Dr, isAddress as Lr, isAddressEqual as Mr } from "viem";
|
|
18
|
+
import { v as je, D as K, c as Ur, b as Fr, R as qr, d as Tt } from "./state-CFn1rT74.js";
|
|
19
|
+
import { h as We, b as Gr, s as Xr, j as zr } from "./sha2-YqVHJiFj.js";
|
|
20
|
+
import { c as jr, g as Wr, h as Yr, i as Qr, b as Jr, f as _t, e as Zr, a as eo } from "./challengeAssert-D_lRvsO0.js";
|
|
21
|
+
import { a as to } from "./secp256k1-BuxBFUHm.js";
|
|
22
|
+
import { c as ro } from "./btcTxHash-BRZ8_EZq.js";
|
|
23
|
+
const oo = /^0x[0-9a-fA-F]{64}$/, so = /^0x[0-9a-fA-F]{40}$/, no = /^0x([0-9a-fA-F]{2})*$/;
|
|
24
24
|
function ye(e, t) {
|
|
25
25
|
if (e.length !== 66)
|
|
26
26
|
throw new Error(
|
|
27
27
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
28
28
|
);
|
|
29
|
-
if (!
|
|
29
|
+
if (!oo.test(e))
|
|
30
30
|
throw new Error(
|
|
31
31
|
`${t} must contain only hex characters after the 0x prefix`
|
|
32
32
|
);
|
|
33
33
|
}
|
|
34
|
-
function
|
|
35
|
-
if (!
|
|
34
|
+
function io(e, t) {
|
|
35
|
+
if (!so.test(e))
|
|
36
36
|
throw new Error(
|
|
37
37
|
`${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
|
|
38
38
|
);
|
|
39
39
|
}
|
|
40
|
-
function
|
|
41
|
-
if (!
|
|
40
|
+
function ao(e, t) {
|
|
41
|
+
if (!no.test(e))
|
|
42
42
|
throw new Error(
|
|
43
43
|
`${t} must be a 0x-prefixed hex string with an even number of hex chars`
|
|
44
44
|
);
|
|
45
45
|
}
|
|
46
46
|
function Re(e) {
|
|
47
|
-
|
|
47
|
+
io(e.btcVaultRegistryAddress, "btcVaultRegistryAddress"), ye(e.vaultId, "vaultId");
|
|
48
48
|
const t = Ie(e.secret);
|
|
49
|
-
if (ye(t, "secret"), e.hashlock !== void 0 && (ye(e.hashlock, "hashlock"), !
|
|
49
|
+
if (ye(t, "secret"), e.hashlock !== void 0 && (ye(e.hashlock, "hashlock"), !ar(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 pn(e) {
|
|
56
56
|
const {
|
|
57
57
|
btcVaultRegistryAddress: t,
|
|
58
58
|
vaultId: r,
|
|
@@ -68,14 +68,14 @@ async function cn(e) {
|
|
|
68
68
|
secret: e.secret,
|
|
69
69
|
hashlock: o
|
|
70
70
|
});
|
|
71
|
-
return
|
|
71
|
+
return ao(s, "activationMetadata"), n({
|
|
72
72
|
address: t,
|
|
73
73
|
abi: Be,
|
|
74
74
|
functionName: "activateVaultWithSecret",
|
|
75
75
|
args: [r, i, s]
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
|
-
async function
|
|
78
|
+
async function hn(e) {
|
|
79
79
|
const { btcVaultRegistryAddress: t, vaultId: r, hashlock: o, writeContract: s, signal: n } = e;
|
|
80
80
|
n == null || n.throwIfAborted();
|
|
81
81
|
const a = Re({
|
|
@@ -91,7 +91,7 @@ async function ln(e) {
|
|
|
91
91
|
args: [r, a]
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
|
-
async function
|
|
94
|
+
async function gn(e) {
|
|
95
95
|
const { btcVaultRegistryAddress: t, vaultId: r, hashlock: o, writeContract: s, signal: n } = e;
|
|
96
96
|
if (n == null || n.throwIfAborted(), typeof o != "string")
|
|
97
97
|
throw new Error("hashlock is required to claim an expired vault");
|
|
@@ -108,22 +108,22 @@ async function pn(e) {
|
|
|
108
108
|
args: [r, a]
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
|
-
class
|
|
111
|
+
class H extends Error {
|
|
112
112
|
constructor(t, r) {
|
|
113
113
|
super(t, r), this.name = "AssertBindingError";
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
function ve(e, t) {
|
|
117
117
|
try {
|
|
118
|
-
return
|
|
118
|
+
return G.fromBase64(t);
|
|
119
119
|
} catch (r) {
|
|
120
|
-
throw new
|
|
120
|
+
throw new H(`${e} PSBT cannot be parsed.`, { cause: r });
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
-
function
|
|
123
|
+
function uo(e, t, r) {
|
|
124
124
|
const o = t.txInputs[r];
|
|
125
125
|
if (!o)
|
|
126
|
-
throw new
|
|
126
|
+
throw new H(`${e} PSBT has no input ${r}.`);
|
|
127
127
|
return o.hash;
|
|
128
128
|
}
|
|
129
129
|
function Ye(e) {
|
|
@@ -134,61 +134,61 @@ function Ye(e) {
|
|
|
134
134
|
function Pe(e, t, r, o, s, n) {
|
|
135
135
|
const a = t.txInputs[r];
|
|
136
136
|
if (!a)
|
|
137
|
-
throw new
|
|
137
|
+
throw new H(`${e} PSBT has no input ${r}.`);
|
|
138
138
|
if (!a.hash.equals(o) || a.index !== s)
|
|
139
|
-
throw new
|
|
139
|
+
throw new H(
|
|
140
140
|
`${e} input ${r} does not spend ${n}: the graph pairs this ${e} with a different transaction.`
|
|
141
141
|
);
|
|
142
142
|
}
|
|
143
|
-
function
|
|
143
|
+
function co(e, t) {
|
|
144
144
|
var s;
|
|
145
|
-
const r = (s = e.data.inputs[
|
|
145
|
+
const r = (s = e.data.inputs[F]) == null ? void 0 : s.witnessUtxo;
|
|
146
146
|
if (r === void 0)
|
|
147
|
-
throw new
|
|
148
|
-
`Assert input ${
|
|
147
|
+
throw new H(
|
|
148
|
+
`Assert input ${F} carries no witnessUtxo, so the amount and script its signature commits to cannot be checked; refusing to sign assert.`
|
|
149
149
|
);
|
|
150
150
|
const o = t.txOutputs[J];
|
|
151
151
|
if (!o)
|
|
152
|
-
throw new
|
|
152
|
+
throw new H(
|
|
153
153
|
`Claim PSBT has no output ${J} for the Assert to spend; refusing to sign assert.`
|
|
154
154
|
);
|
|
155
155
|
if (r.value !== o.value)
|
|
156
|
-
throw new
|
|
157
|
-
`Assert input ${
|
|
156
|
+
throw new H(
|
|
157
|
+
`Assert input ${F} declares a prevout of ${r.value} sats but the Claim's output ${J} is worth ${o.value}; refusing to sign assert.`
|
|
158
158
|
);
|
|
159
159
|
if (!r.script.equals(o.script))
|
|
160
|
-
throw new
|
|
161
|
-
`Assert input ${
|
|
160
|
+
throw new H(
|
|
161
|
+
`Assert input ${F} declares a prevout script that is not the Claim's output ${J} script; refusing to sign assert.`
|
|
162
162
|
);
|
|
163
163
|
}
|
|
164
|
-
function
|
|
164
|
+
function lo(e) {
|
|
165
165
|
const t = ve("Claim", e.claimPsbtBase64), r = ve("Assert", e.assertPsbtBase64), o = ve("Payout", e.payoutClaimerPsbtBase64);
|
|
166
166
|
Pe(
|
|
167
167
|
"Assert",
|
|
168
168
|
r,
|
|
169
|
-
|
|
169
|
+
F,
|
|
170
170
|
Ye(t),
|
|
171
171
|
J,
|
|
172
172
|
"Claim:0"
|
|
173
|
-
),
|
|
173
|
+
), co(r, t), Pe(
|
|
174
174
|
"Payout",
|
|
175
175
|
o,
|
|
176
176
|
A,
|
|
177
177
|
Ye(r),
|
|
178
|
-
|
|
178
|
+
X,
|
|
179
179
|
"Assert:0"
|
|
180
180
|
), Pe(
|
|
181
181
|
"Payout",
|
|
182
182
|
o,
|
|
183
183
|
re,
|
|
184
|
-
|
|
184
|
+
uo("Claim", t, ge),
|
|
185
185
|
Z,
|
|
186
186
|
"this vault's PegIn:0"
|
|
187
187
|
);
|
|
188
188
|
}
|
|
189
189
|
function me(e, t) {
|
|
190
190
|
try {
|
|
191
|
-
return
|
|
191
|
+
return G.fromBase64(t);
|
|
192
192
|
} catch (r) {
|
|
193
193
|
throw new Error(`${e} PSBT cannot be parsed.`, { cause: r });
|
|
194
194
|
}
|
|
@@ -204,7 +204,7 @@ function Qe(e, t, r, o) {
|
|
|
204
204
|
{
|
|
205
205
|
inputIndex: A,
|
|
206
206
|
expectedSats: o.value,
|
|
207
|
-
source: `the Assert's output ${
|
|
207
|
+
source: `the Assert's output ${X}`
|
|
208
208
|
}
|
|
209
209
|
];
|
|
210
210
|
for (const { inputIndex: i, expectedSats: u, source: l } of s) {
|
|
@@ -221,10 +221,10 @@ function Qe(e, t, r, o) {
|
|
|
221
221
|
const n = t.data.inputs[A].witnessUtxo;
|
|
222
222
|
if (!(n != null && n.script.equals(o.script)))
|
|
223
223
|
throw new Error(
|
|
224
|
-
`${e} Payout input ${A} declares a prevout script that is not the Assert's output ${
|
|
224
|
+
`${e} Payout input ${A} declares a prevout script that is not the Assert's output ${X} script; refusing to sign payout.`
|
|
225
225
|
);
|
|
226
226
|
}
|
|
227
|
-
async function
|
|
227
|
+
async function po(e) {
|
|
228
228
|
const { vault: t } = e, r = {
|
|
229
229
|
vaultCoreVersion: t.vaultCoreVersion,
|
|
230
230
|
numVaultKeepers: t.vaultKeeperBtcPubkeys.length,
|
|
@@ -232,7 +232,7 @@ async function lo(e) {
|
|
|
232
232
|
councilSize: t.councilSize,
|
|
233
233
|
protocolFeeRate: t.protocolFeeRate
|
|
234
234
|
};
|
|
235
|
-
|
|
235
|
+
Rr(r);
|
|
236
236
|
const o = me("Claimer Payout", e.payoutClaimerPsbtBase64), s = me(
|
|
237
237
|
"Depositor Payout",
|
|
238
238
|
e.payoutDepositorPsbtBase64
|
|
@@ -241,10 +241,10 @@ async function lo(e) {
|
|
|
241
241
|
throw new Error(
|
|
242
242
|
"Depositor and claimer Payout PSBTs describe different transactions; refusing to sign payout."
|
|
243
243
|
);
|
|
244
|
-
const a = n.txOutputs[
|
|
244
|
+
const a = n.txOutputs[X];
|
|
245
245
|
if (a === void 0)
|
|
246
246
|
throw new Error(
|
|
247
|
-
`Assert transaction has no output ${
|
|
247
|
+
`Assert transaction has no output ${X}; the Payout's implicit fee cannot be measured.`
|
|
248
248
|
);
|
|
249
249
|
if (o.txInputs.length !== Me)
|
|
250
250
|
throw new Error(
|
|
@@ -276,27 +276,27 @@ async function lo(e) {
|
|
|
276
276
|
throw new Error(
|
|
277
277
|
`Payout transaction has ${c.length} output(s), expected exactly ${ee} for a depositor-as-claimer payout.`
|
|
278
278
|
);
|
|
279
|
-
let
|
|
280
|
-
for (const
|
|
281
|
-
if (
|
|
279
|
+
let p = 0;
|
|
280
|
+
for (const d of c) p += d.value;
|
|
281
|
+
if (p > l)
|
|
282
282
|
throw new Error(
|
|
283
|
-
`Payout outputs (${
|
|
283
|
+
`Payout outputs (${p} sats) exceed inputs (${l} sats); invalid transaction.`
|
|
284
284
|
);
|
|
285
|
-
await
|
|
286
|
-
implicitFeeSats: l -
|
|
285
|
+
await Kr(r, {
|
|
286
|
+
implicitFeeSats: l - p,
|
|
287
287
|
out0Len: c[Ve].script.length,
|
|
288
288
|
out1Len: void 0
|
|
289
289
|
});
|
|
290
290
|
}
|
|
291
|
-
class
|
|
291
|
+
class ho extends Error {
|
|
292
292
|
constructor(t, r) {
|
|
293
293
|
super(
|
|
294
294
|
"Transaction graph's challenger set does not match the vault's (local ∪ universal)" + (t.length > 0 ? ` (missing: ${t.join(", ")})` : "") + (r.length > 0 ? ` (unexpected: ${r.join(", ")})` : "") + ". Refusing to sign an incomplete or padded challenger set."
|
|
295
295
|
), this.missing = t, this.unexpected = r, this.name = "ChallengerSetMismatchError";
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
|
-
function
|
|
299
|
-
const t =
|
|
298
|
+
function go(e) {
|
|
299
|
+
const t = xt({
|
|
300
300
|
claimerBtcPubkey: e.depositorBtcPubkey,
|
|
301
301
|
depositorBtcPubkey: e.depositorBtcPubkey,
|
|
302
302
|
vaultProviderBtcPubkey: e.vaultProviderBtcPubkey,
|
|
@@ -313,26 +313,26 @@ function ho(e) {
|
|
|
313
313
|
);
|
|
314
314
|
const a = [...t, ...r], i = new Set(a), u = a.filter((c) => !n.has(c)), l = s.filter((c) => !i.has(c));
|
|
315
315
|
if (u.length > 0 || l.length > 0)
|
|
316
|
-
throw new
|
|
316
|
+
throw new ho(u, l);
|
|
317
317
|
}
|
|
318
318
|
function Je(e) {
|
|
319
319
|
return P(e).toLowerCase();
|
|
320
320
|
}
|
|
321
|
-
class
|
|
321
|
+
class fo extends Error {
|
|
322
322
|
constructor(t, r) {
|
|
323
323
|
super(
|
|
324
324
|
`Payout transaction output ${Ve} pays ${r}, not the vault's registered payout script ${t}. Refusing to sign a payout to another destination.`
|
|
325
325
|
), this.expectedScriptHex = t, this.actualScriptHex = r, this.name = "PayoutDestinationError";
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
|
-
function
|
|
328
|
+
function yo(e) {
|
|
329
329
|
let t;
|
|
330
330
|
try {
|
|
331
|
-
t =
|
|
331
|
+
t = G.fromBase64(e.payoutPsbtBase64);
|
|
332
332
|
} catch (c) {
|
|
333
333
|
throw new Error("Payout PSBT cannot be parsed.", { cause: c });
|
|
334
334
|
}
|
|
335
|
-
const { version: r, locktime: o, outs: s } =
|
|
335
|
+
const { version: r, locktime: o, outs: s } = vo(t);
|
|
336
336
|
if (r !== Ue || o !== Fe)
|
|
337
337
|
throw new Error(
|
|
338
338
|
`Payout transaction has version ${r} and locktime ${o}, expected ${Ue} and ${Fe}.`
|
|
@@ -350,26 +350,26 @@ function fo(e) {
|
|
|
350
350
|
);
|
|
351
351
|
const a = s[Ve].script.toString("hex").toLowerCase();
|
|
352
352
|
if (a !== n)
|
|
353
|
-
throw new
|
|
353
|
+
throw new fo(n, a);
|
|
354
354
|
const i = s[ee - 1];
|
|
355
355
|
if (i.value !== qe)
|
|
356
356
|
throw new Error(
|
|
357
357
|
`Payout CPFP anchor value ${i.value} sats must equal ${qe} sats.`
|
|
358
358
|
);
|
|
359
359
|
const u = P(
|
|
360
|
-
|
|
360
|
+
Er(P(e.depositorBtcPubkey).toLowerCase())
|
|
361
361
|
), l = i.script.toString("hex").toLowerCase();
|
|
362
362
|
if (l !== u)
|
|
363
363
|
throw new Error(
|
|
364
364
|
`Payout CPFP anchor pays ${l}, not the depositor's BIP-86 P2TR ${u}. Refusing to sign a payout whose fee-bump output is spendable by somebody else.`
|
|
365
365
|
);
|
|
366
366
|
}
|
|
367
|
-
function
|
|
367
|
+
function vo(e) {
|
|
368
368
|
return {
|
|
369
369
|
version: e.version,
|
|
370
370
|
locktime: e.locktime,
|
|
371
371
|
outs: e.txOutputs.map((t) => ({
|
|
372
|
-
script:
|
|
372
|
+
script: O.from(t.script),
|
|
373
373
|
value: t.value
|
|
374
374
|
}))
|
|
375
375
|
};
|
|
@@ -379,8 +379,8 @@ class ne extends Error {
|
|
|
379
379
|
super(t), this.name = "PayoutInputLeafError";
|
|
380
380
|
}
|
|
381
381
|
}
|
|
382
|
-
function
|
|
383
|
-
const t =
|
|
382
|
+
function Po(e) {
|
|
383
|
+
const t = G.fromBase64(e.payoutDepositorPsbtBase64), r = G.fromBase64(e.payoutClaimerPsbtBase64), o = t.data.globalMap.unsignedTx.toBuffer(), s = r.data.globalMap.unsignedTx.toBuffer();
|
|
384
384
|
if (!o.equals(s))
|
|
385
385
|
throw new ne(
|
|
386
386
|
"Depositor and claimer Payout PSBTs describe different transactions; the graph is inconsistent."
|
|
@@ -404,59 +404,59 @@ function vo(e) {
|
|
|
404
404
|
...n.tapMerkleRoot ? { tapMerkleRoot: n.tapMerkleRoot } : {}
|
|
405
405
|
}), t.toBase64();
|
|
406
406
|
}
|
|
407
|
-
class
|
|
407
|
+
class mo extends Error {
|
|
408
408
|
constructor(t, r, o) {
|
|
409
409
|
super(
|
|
410
410
|
`Transaction graph does not belong to vault ${t}: its Claim spends PegIn ${o}, which derives vault ${r}. Refusing to sign for a graph served for another vault.`
|
|
411
411
|
), this.expectedVaultId = t, this.derivedVaultId = r, this.peginTxid = o, this.name = "VaultIdBindingError";
|
|
412
412
|
}
|
|
413
413
|
}
|
|
414
|
-
function
|
|
414
|
+
function bo(e) {
|
|
415
415
|
let t;
|
|
416
416
|
try {
|
|
417
|
-
t =
|
|
417
|
+
t = G.fromBase64(e);
|
|
418
418
|
} catch (o) {
|
|
419
419
|
throw new Error("Claim PSBT cannot be parsed.", { cause: o });
|
|
420
420
|
}
|
|
421
421
|
const r = t.txInputs[ge];
|
|
422
422
|
if (!r)
|
|
423
423
|
throw new Error("Claim PSBT carries no PegIn input to bind the vault to.");
|
|
424
|
-
return
|
|
424
|
+
return St(
|
|
425
425
|
"Claim PSBT",
|
|
426
426
|
t.txInputs.length,
|
|
427
427
|
r.index
|
|
428
428
|
), Ke(r.hash);
|
|
429
429
|
}
|
|
430
|
-
function
|
|
430
|
+
function wo(e) {
|
|
431
431
|
const t = e.ins[ge];
|
|
432
432
|
if (!t)
|
|
433
433
|
throw new Error(
|
|
434
434
|
"Artifacts file's claim_tx carries no PegIn input to bind the vault to."
|
|
435
435
|
);
|
|
436
|
-
return
|
|
436
|
+
return St(
|
|
437
437
|
"Artifacts file's claim_tx",
|
|
438
438
|
e.ins.length,
|
|
439
439
|
t.index
|
|
440
440
|
), Ke(t.hash);
|
|
441
441
|
}
|
|
442
|
-
function
|
|
443
|
-
if (t !== 1 || r !==
|
|
442
|
+
function St(e, t, r) {
|
|
443
|
+
if (t !== 1 || r !== z)
|
|
444
444
|
throw new Error(
|
|
445
|
-
`${e} must have exactly one input spending PegIn output ${
|
|
445
|
+
`${e} must have exactly one input spending PegIn output ${z}; it has ${t} input(s) and the first spends output ${r}.`
|
|
446
446
|
);
|
|
447
447
|
}
|
|
448
|
-
function
|
|
449
|
-
const t =
|
|
450
|
-
|
|
451
|
-
), r =
|
|
448
|
+
function At(e) {
|
|
449
|
+
const t = j(
|
|
450
|
+
wt(e.peginTxid, e.depositorEthAddress)
|
|
451
|
+
), r = j(e.expectedVaultId);
|
|
452
452
|
if (t !== r)
|
|
453
|
-
throw new
|
|
453
|
+
throw new mo(r, t, e.peginTxid);
|
|
454
454
|
}
|
|
455
|
-
function
|
|
455
|
+
function j(e) {
|
|
456
456
|
return `0x${(e.startsWith("0x") ? e.slice(2) : e).toLowerCase()}`;
|
|
457
457
|
}
|
|
458
458
|
function Ke(e) {
|
|
459
|
-
return
|
|
459
|
+
return O.from(e).reverse().toString("hex");
|
|
460
460
|
}
|
|
461
461
|
function le(e, t) {
|
|
462
462
|
const r = P(e);
|
|
@@ -464,7 +464,7 @@ function le(e, t) {
|
|
|
464
464
|
throw new Error(`${t} must be non-empty, even-length hex.`);
|
|
465
465
|
return r.toLowerCase();
|
|
466
466
|
}
|
|
467
|
-
function
|
|
467
|
+
function Bt(e) {
|
|
468
468
|
const t = le(
|
|
469
469
|
e.servedVerifyingKeyHex,
|
|
470
470
|
"source.verifyingKeyHex"
|
|
@@ -477,22 +477,22 @@ function At(e) {
|
|
|
477
477
|
`Vault provider served Groth16 verifying key ${t} but the trusted key for prover circuit version ${e.proverCircuitVersion} is ${r}; refusing to sign a claim whose proof would verify under a substituted key.`
|
|
478
478
|
);
|
|
479
479
|
}
|
|
480
|
-
const
|
|
481
|
-
class
|
|
480
|
+
const q = 1;
|
|
481
|
+
class xo extends Error {
|
|
482
482
|
constructor(t, r) {
|
|
483
483
|
super(
|
|
484
484
|
`Artifacts belong to vault ${r}, not ${t}. Select the artifacts file saved for this vault.`
|
|
485
485
|
), this.expectedVaultId = t, this.actualVaultId = r, this.name = "ArtifactsVaultMismatchError";
|
|
486
486
|
}
|
|
487
487
|
}
|
|
488
|
-
const
|
|
489
|
-
function
|
|
490
|
-
const t =
|
|
488
|
+
const Eo = /^(?:[0-9a-fA-F]{2})+$/;
|
|
489
|
+
function $o(e) {
|
|
490
|
+
const t = To(e, "babe_sessions"), r = Object.keys(t);
|
|
491
491
|
if (r.length === 0)
|
|
492
492
|
return { joined: !1 };
|
|
493
493
|
for (const [o, s] of Object.entries(t)) {
|
|
494
494
|
const n = typeof s == "object" && s !== null ? s.decryptor_artifacts_hex : void 0;
|
|
495
|
-
if (typeof n != "string" || !
|
|
495
|
+
if (typeof n != "string" || !Eo.test(n))
|
|
496
496
|
throw new Error(
|
|
497
497
|
`Artifacts file is missing a usable "babe_sessions": the entry for ${o} carries no non-empty hex "decryptor_artifacts_hex".`
|
|
498
498
|
);
|
|
@@ -506,7 +506,7 @@ function ko(e) {
|
|
|
506
506
|
} catch (a) {
|
|
507
507
|
throw new Error("Artifacts file is not valid JSON.", { cause: a });
|
|
508
508
|
}
|
|
509
|
-
const r = be(t.vault_id, "vault_id"), o =
|
|
509
|
+
const r = be(t.vault_id, "vault_id"), o = Co(be(t.claim_tx, "claim_tx")), s = we(
|
|
510
510
|
t.prover_circuit_version,
|
|
511
511
|
"prover_circuit_version"
|
|
512
512
|
), n = BigInt(
|
|
@@ -522,26 +522,26 @@ function ko(e) {
|
|
|
522
522
|
),
|
|
523
523
|
vaultId: r,
|
|
524
524
|
claimTxid: o.getId(),
|
|
525
|
-
peginTxid:
|
|
525
|
+
peginTxid: wo(o),
|
|
526
526
|
proverCircuitVersion: s,
|
|
527
527
|
claimableEventBlockNumber: n,
|
|
528
528
|
// Required: btc-vault's builder always writes it
|
|
529
529
|
// (`delegated_claim.rs:874` @ b534ff9e), so an absent one is not a file
|
|
530
530
|
// this SDK or the CLI produced.
|
|
531
531
|
verifyingKeyHex: be(t.verifying_key, "verifying_key"),
|
|
532
|
-
babeSessions:
|
|
532
|
+
babeSessions: $o(t.babe_sessions)
|
|
533
533
|
};
|
|
534
534
|
}
|
|
535
|
-
async function
|
|
536
|
-
const t = ko(e.artifactsJson), r =
|
|
535
|
+
async function fn(e) {
|
|
536
|
+
const t = ko(e.artifactsJson), r = j(e.expectedVaultId), o = j(t.vaultId);
|
|
537
537
|
if (r !== o)
|
|
538
|
-
throw new
|
|
539
|
-
|
|
538
|
+
throw new xo(r, o);
|
|
539
|
+
At({
|
|
540
540
|
peginTxid: t.peginTxid,
|
|
541
541
|
depositorEthAddress: e.depositorEthAddress,
|
|
542
542
|
expectedVaultId: r
|
|
543
543
|
});
|
|
544
|
-
const s = e.txGraphVersion ??
|
|
544
|
+
const s = e.txGraphVersion ?? q;
|
|
545
545
|
if (t.vaultCoreVersion !== s)
|
|
546
546
|
throw new Error(
|
|
547
547
|
`Artifacts record vault core version ${t.vaultCoreVersion}, but verification was asked for version ${s}.`
|
|
@@ -569,9 +569,9 @@ async function dn(e) {
|
|
|
569
569
|
throw new Error(
|
|
570
570
|
`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.`
|
|
571
571
|
);
|
|
572
|
-
return await
|
|
572
|
+
return await lr(s, e.artifactsJson), t;
|
|
573
573
|
}
|
|
574
|
-
function
|
|
574
|
+
function Co(e) {
|
|
575
575
|
try {
|
|
576
576
|
return S.fromHex(e);
|
|
577
577
|
} catch (t) {
|
|
@@ -590,15 +590,15 @@ function we(e, t) {
|
|
|
590
590
|
throw new Error(`Artifacts file is missing a usable "${t}".`);
|
|
591
591
|
return e;
|
|
592
592
|
}
|
|
593
|
-
function
|
|
593
|
+
function To(e, t) {
|
|
594
594
|
if (typeof e != "object" || e === null || Array.isArray(e))
|
|
595
595
|
throw new Error(`Artifacts file is missing a usable "${t}".`);
|
|
596
596
|
return e;
|
|
597
597
|
}
|
|
598
|
-
function
|
|
598
|
+
function It(e, t) {
|
|
599
599
|
return `wronglyChallenged:${e}:${t}`;
|
|
600
600
|
}
|
|
601
|
-
function
|
|
601
|
+
function Vt(e) {
|
|
602
602
|
const t = [
|
|
603
603
|
{
|
|
604
604
|
id: "claim",
|
|
@@ -610,7 +610,7 @@ function It(e) {
|
|
|
610
610
|
id: "assert",
|
|
611
611
|
kind: "assert",
|
|
612
612
|
psbtBase64: e.assert,
|
|
613
|
-
inputIndex:
|
|
613
|
+
inputIndex: F
|
|
614
614
|
},
|
|
615
615
|
{
|
|
616
616
|
id: "payoutClaimer",
|
|
@@ -628,95 +628,95 @@ function It(e) {
|
|
|
628
628
|
for (const r of Object.keys(e.wronglyChallenged))
|
|
629
629
|
e.wronglyChallenged[r].forEach((o, s) => {
|
|
630
630
|
t.push({
|
|
631
|
-
id:
|
|
631
|
+
id: It(r, s),
|
|
632
632
|
kind: "wronglyChallenged",
|
|
633
633
|
psbtBase64: o,
|
|
634
|
-
inputIndex:
|
|
634
|
+
inputIndex: Ar
|
|
635
635
|
});
|
|
636
636
|
});
|
|
637
637
|
return t;
|
|
638
638
|
}
|
|
639
|
-
const
|
|
640
|
-
function
|
|
639
|
+
const _o = "{}", So = Et - $t;
|
|
640
|
+
function R(e) {
|
|
641
641
|
const t = e.replace(/^0x/, "").toLowerCase();
|
|
642
|
-
if (t.length ===
|
|
643
|
-
return t.slice(
|
|
644
|
-
if (t.length ===
|
|
642
|
+
if (t.length === Et)
|
|
643
|
+
return t.slice(So);
|
|
644
|
+
if (t.length === $t) return t;
|
|
645
645
|
throw new Error(
|
|
646
646
|
`Public key must be 33-byte compressed or 32-byte x-only hex, got ${t.length / 2} bytes.`
|
|
647
647
|
);
|
|
648
648
|
}
|
|
649
649
|
async function Ze(e, t, r) {
|
|
650
650
|
const o = await e.getPublicKeyHex();
|
|
651
|
-
if (
|
|
651
|
+
if (R(o) !== R(t))
|
|
652
652
|
throw new Error(
|
|
653
653
|
"Connected wallet does not hold the vault's depositor key. Select the account that made the deposit, then try again."
|
|
654
654
|
);
|
|
655
655
|
const s = await e.getAddress();
|
|
656
|
-
if (!
|
|
656
|
+
if (!sr(s, o, r))
|
|
657
657
|
throw new Error(
|
|
658
658
|
`Connected wallet reports address "${s}", which is not derived from the vault's depositor key. Select the account that made the deposit, then try again.`
|
|
659
659
|
);
|
|
660
660
|
return s;
|
|
661
661
|
}
|
|
662
|
-
async function
|
|
663
|
-
const s =
|
|
662
|
+
async function Rt(e, t, r, o) {
|
|
663
|
+
const s = R(o);
|
|
664
664
|
if (s !== r.depositorBtcPubkey)
|
|
665
665
|
throw new Error(
|
|
666
666
|
`Depositor key ${s} is not the vault's registered depositor key ${r.depositorBtcPubkey}; refusing to plan a claim for another key.`
|
|
667
667
|
);
|
|
668
668
|
try {
|
|
669
|
-
|
|
669
|
+
$r(
|
|
670
670
|
Ie(r.registeredPayoutScriptPubKey),
|
|
671
671
|
r.depositorBtcPubkey,
|
|
672
672
|
o
|
|
673
673
|
);
|
|
674
|
-
} catch (
|
|
674
|
+
} catch (p) {
|
|
675
675
|
throw new Error(
|
|
676
|
-
`Registered payout script ${r.registeredPayoutScriptPubKey} failed the depositor-key derivation check: ${
|
|
677
|
-
{ cause:
|
|
676
|
+
`Registered payout script ${r.registeredPayoutScriptPubKey} failed the depositor-key derivation check: ${p instanceof Error ? p.message : String(p)}. This SDK registers only P2TR of the depositor's x-only key or P2WPKH of the compressed key (the contract bounds the script's length alone, PeginLogic.sol:237-240 @ c559f5c2); refusing to sign a claim that pays it.`,
|
|
677
|
+
{ cause: p }
|
|
678
678
|
);
|
|
679
679
|
}
|
|
680
|
-
if (e !==
|
|
680
|
+
if (e !== q)
|
|
681
681
|
throw new Error(
|
|
682
|
-
`Graph version ${e} is not the delegated-claim graph version ${
|
|
682
|
+
`Graph version ${e} is not the delegated-claim graph version ${q}; vaults on other graphs have no delegated-claim path.`
|
|
683
683
|
);
|
|
684
684
|
if (e !== r.vaultCoreVersion)
|
|
685
685
|
throw new Error(
|
|
686
686
|
`Graph version ${e} does not match the vault context's vault core version ${r.vaultCoreVersion}; they are one axis and must agree.`
|
|
687
687
|
);
|
|
688
688
|
const [n, a, i, u, l] = await Promise.all([
|
|
689
|
-
lr(e, t),
|
|
690
|
-
pr(e, t),
|
|
691
689
|
dr(e, t),
|
|
690
|
+
pr(e, t),
|
|
692
691
|
hr(e, t),
|
|
693
|
-
gr(e, t)
|
|
692
|
+
gr(e, t),
|
|
693
|
+
fr(e, t)
|
|
694
694
|
]);
|
|
695
|
-
|
|
696
|
-
peginTxid:
|
|
695
|
+
At({
|
|
696
|
+
peginTxid: bo(n),
|
|
697
697
|
depositorEthAddress: r.depositorEthAddress,
|
|
698
698
|
expectedVaultId: r.vaultId
|
|
699
|
-
}),
|
|
699
|
+
}), lo({
|
|
700
700
|
claimPsbtBase64: n,
|
|
701
701
|
assertPsbtBase64: a,
|
|
702
702
|
payoutClaimerPsbtBase64: i
|
|
703
703
|
});
|
|
704
|
-
for (const
|
|
705
|
-
|
|
706
|
-
payoutPsbtBase64:
|
|
704
|
+
for (const p of [i, l])
|
|
705
|
+
yo({
|
|
706
|
+
payoutPsbtBase64: p,
|
|
707
707
|
registeredPayoutScriptPubKey: r.registeredPayoutScriptPubKey,
|
|
708
708
|
depositorBtcPubkey: r.depositorBtcPubkey
|
|
709
709
|
});
|
|
710
|
-
const c =
|
|
710
|
+
const c = Po({
|
|
711
711
|
payoutDepositorPsbtBase64: l,
|
|
712
712
|
payoutClaimerPsbtBase64: i
|
|
713
713
|
});
|
|
714
|
-
return await
|
|
714
|
+
return await po({
|
|
715
715
|
payoutClaimerPsbtBase64: i,
|
|
716
716
|
payoutDepositorPsbtBase64: c,
|
|
717
717
|
assertPsbtBase64: a,
|
|
718
718
|
vault: r
|
|
719
|
-
}),
|
|
719
|
+
}), go({
|
|
720
720
|
graphChallengerPubkeys: Object.keys(u),
|
|
721
721
|
depositorBtcPubkey: o,
|
|
722
722
|
vaultProviderBtcPubkey: r.vaultProviderBtcPubkey,
|
|
@@ -724,13 +724,13 @@ async function Vt(e, t, r, o) {
|
|
|
724
724
|
universalChallengerBtcPubkeys: r.universalChallengerBtcPubkeys
|
|
725
725
|
}), { claim: n, assert: a, payoutClaimer: i, payoutDepositor: c, wronglyChallenged: u };
|
|
726
726
|
}
|
|
727
|
-
async function
|
|
728
|
-
|
|
727
|
+
async function Ao(e) {
|
|
728
|
+
Bt({
|
|
729
729
|
servedVerifyingKeyHex: e.source.verifyingKeyHex,
|
|
730
730
|
trustedVerifyingKeyHex: e.trustedVerifyingKeyHex,
|
|
731
731
|
proverCircuitVersion: e.vault.proverCircuitVersion
|
|
732
732
|
});
|
|
733
|
-
const t = await
|
|
733
|
+
const t = await Rt(
|
|
734
734
|
e.vault.txGraphVersion,
|
|
735
735
|
e.source.txGraphJson,
|
|
736
736
|
e.vault,
|
|
@@ -743,30 +743,30 @@ async function So(e) {
|
|
|
743
743
|
source: e.source,
|
|
744
744
|
vault: e.vault,
|
|
745
745
|
// Omitted means unjoined: the browser cannot hold the real sessions.
|
|
746
|
-
babeSessionsJson: e.babeSessionsJson === void 0 ?
|
|
747
|
-
requests:
|
|
746
|
+
babeSessionsJson: e.babeSessionsJson === void 0 ? _o : e.babeSessionsJson,
|
|
747
|
+
requests: Vt(t)
|
|
748
748
|
};
|
|
749
749
|
}
|
|
750
750
|
function fe(e, t, r) {
|
|
751
751
|
oe({
|
|
752
752
|
requestedPsbtHex: He(t.psbtBase64),
|
|
753
753
|
signatureHex: r,
|
|
754
|
-
signerXOnlyPubkeyHex:
|
|
754
|
+
signerXOnlyPubkeyHex: R(e.depositorPublicKey),
|
|
755
755
|
inputIndex: t.inputIndex
|
|
756
756
|
});
|
|
757
757
|
}
|
|
758
758
|
function He(e) {
|
|
759
|
-
return
|
|
759
|
+
return O.from(e, "base64").toString("hex");
|
|
760
760
|
}
|
|
761
|
-
function
|
|
762
|
-
return
|
|
761
|
+
function Kt(e) {
|
|
762
|
+
return O.from(e, "hex").toString("base64");
|
|
763
763
|
}
|
|
764
764
|
class Y extends Error {
|
|
765
765
|
constructor(t) {
|
|
766
766
|
super(t), this.name = "SigningPlanMismatchError";
|
|
767
767
|
}
|
|
768
768
|
}
|
|
769
|
-
function
|
|
769
|
+
function Bo(e, t) {
|
|
770
770
|
if (e.length !== t.length)
|
|
771
771
|
throw new Y(
|
|
772
772
|
`Plan has ${e.length} requests but the graph builds ${t.length}; the plan was altered after planning.`
|
|
@@ -791,7 +791,7 @@ function Ao(e, t) {
|
|
|
791
791
|
);
|
|
792
792
|
}
|
|
793
793
|
}
|
|
794
|
-
function
|
|
794
|
+
function Io(e, t) {
|
|
795
795
|
const r = new Set(e.map((a) => a.id)), o = [...r].filter((a) => !t.has(a)), s = [...t.keys()].filter((a) => !r.has(a));
|
|
796
796
|
if (o.length === 0 && s.length === 0) return;
|
|
797
797
|
const n = (a) => a.map((i) => `"${i}"`).join(", ");
|
|
@@ -799,7 +799,7 @@ function Bo(e, t) {
|
|
|
799
799
|
`Signatures do not cover the plan: ${t.size} signatures for ${e.length} requests` + (o.length > 0 ? `; missing ${n(o)}` : "") + (s.length > 0 ? `; extra ${n(s)}` : "") + "."
|
|
800
800
|
);
|
|
801
801
|
}
|
|
802
|
-
function
|
|
802
|
+
function M(e, t) {
|
|
803
803
|
const r = e.get(t);
|
|
804
804
|
if (r === void 0)
|
|
805
805
|
throw new Error(
|
|
@@ -807,45 +807,45 @@ function L(e, t) {
|
|
|
807
807
|
);
|
|
808
808
|
return r;
|
|
809
809
|
}
|
|
810
|
-
async function
|
|
811
|
-
const { plan: t, signatures: r } = e, { txGraphVersion: o } = t.vault, s = t.source.txGraphJson, n =
|
|
810
|
+
async function Vo(e) {
|
|
811
|
+
const { plan: t, signatures: r } = e, { txGraphVersion: o } = t.vault, s = t.source.txGraphJson, n = Bt({
|
|
812
812
|
servedVerifyingKeyHex: t.source.verifyingKeyHex,
|
|
813
813
|
trustedVerifyingKeyHex: t.trustedVerifyingKeyHex,
|
|
814
814
|
proverCircuitVersion: t.vault.proverCircuitVersion
|
|
815
|
-
}), a = await
|
|
815
|
+
}), a = await Rt(
|
|
816
816
|
o,
|
|
817
817
|
s,
|
|
818
818
|
t.vault,
|
|
819
819
|
t.depositorPublicKey
|
|
820
|
-
), i =
|
|
821
|
-
|
|
820
|
+
), i = Vt(a);
|
|
821
|
+
Bo(t.requests, i), Io(i, r);
|
|
822
822
|
for (const c of i)
|
|
823
823
|
fe(
|
|
824
824
|
t,
|
|
825
825
|
c,
|
|
826
|
-
|
|
826
|
+
M(r, c.id)
|
|
827
827
|
);
|
|
828
828
|
const u = {};
|
|
829
829
|
for (const c of Object.keys(a.wronglyChallenged))
|
|
830
830
|
u[c] = a.wronglyChallenged[c].map(
|
|
831
|
-
(
|
|
831
|
+
(p, d) => M(
|
|
832
832
|
r,
|
|
833
|
-
|
|
833
|
+
It(c, d)
|
|
834
834
|
)
|
|
835
835
|
);
|
|
836
|
-
const l = await
|
|
836
|
+
const l = await yr(
|
|
837
837
|
o,
|
|
838
838
|
s,
|
|
839
|
-
|
|
839
|
+
M(r, "claim")
|
|
840
840
|
);
|
|
841
|
-
return
|
|
841
|
+
return vr({
|
|
842
842
|
txGraphVersion: o,
|
|
843
843
|
graphJson: s,
|
|
844
844
|
signedClaimTxHex: l,
|
|
845
|
-
assertClaimerSigHex:
|
|
846
|
-
payoutClaimerSigHex:
|
|
845
|
+
assertClaimerSigHex: M(r, "assert"),
|
|
846
|
+
payoutClaimerSigHex: M(r, "payoutClaimer"),
|
|
847
847
|
wronglyChallengedSigs: u,
|
|
848
|
-
depositorPayoutSigHex:
|
|
848
|
+
depositorPayoutSigHex: M(r, "payoutDepositor"),
|
|
849
849
|
verifyingKeyHex: n,
|
|
850
850
|
claimableEventBlockNumber: t.vault.claimableEventBlockNumber,
|
|
851
851
|
proverCircuitVersion: t.vault.proverCircuitVersion,
|
|
@@ -854,44 +854,44 @@ async function Io(e) {
|
|
|
854
854
|
expectedVaultCoreVersion: t.vault.vaultCoreVersion
|
|
855
855
|
});
|
|
856
856
|
}
|
|
857
|
-
function
|
|
857
|
+
function Ro(e) {
|
|
858
858
|
return typeof e.signDelegatedClaimPsbt == "function";
|
|
859
859
|
}
|
|
860
|
-
class
|
|
860
|
+
class Ko extends Error {
|
|
861
861
|
constructor(t, r, o, s) {
|
|
862
862
|
super(t, s), this.signatures = r, this.failedRequestId = o, this.name = "DelegatedClaimSigningIncompleteError";
|
|
863
863
|
}
|
|
864
864
|
}
|
|
865
|
-
const
|
|
865
|
+
const Ht = {
|
|
866
866
|
assert: "intentBound",
|
|
867
867
|
payoutDepositor: "intentBound",
|
|
868
868
|
payoutClaimer: "standalone",
|
|
869
869
|
claim: "standalone",
|
|
870
870
|
wronglyChallenged: "standalone"
|
|
871
|
-
},
|
|
871
|
+
}, Ho = [
|
|
872
872
|
"payoutClaimer",
|
|
873
873
|
"claim",
|
|
874
874
|
"wronglyChallenged"
|
|
875
875
|
];
|
|
876
|
-
async function
|
|
876
|
+
async function Oo(e, t, r = {}) {
|
|
877
877
|
var s;
|
|
878
|
-
if ((s = r.signal) == null || s.throwIfAborted(),
|
|
878
|
+
if ((s = r.signal) == null || s.throwIfAborted(), No(e), R(e.depositorPublicKey) !== e.vault.depositorBtcPubkey)
|
|
879
879
|
throw new Error(
|
|
880
|
-
`Plan depositor key ${
|
|
880
|
+
`Plan depositor key ${R(e.depositorPublicKey)} is not the vault's registered depositor key ${e.vault.depositorBtcPubkey}; the plan was not built for this vault.`
|
|
881
881
|
);
|
|
882
|
-
if (
|
|
883
|
-
if (!
|
|
882
|
+
if (Pt(t)) {
|
|
883
|
+
if (!Ro(t))
|
|
884
884
|
throw new Error(
|
|
885
885
|
"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."
|
|
886
886
|
);
|
|
887
|
-
const n =
|
|
888
|
-
|
|
889
|
-
const a =
|
|
887
|
+
const n = Lo(r, e);
|
|
888
|
+
Mo(n.depositTerms, e.vault);
|
|
889
|
+
const a = Do(e), i = await Ze(
|
|
890
890
|
t,
|
|
891
891
|
e.depositorPublicKey,
|
|
892
892
|
e.btcNetwork
|
|
893
893
|
);
|
|
894
|
-
return
|
|
894
|
+
return Uo(
|
|
895
895
|
e,
|
|
896
896
|
t,
|
|
897
897
|
i,
|
|
@@ -905,9 +905,9 @@ async function Ho(e, t, r = {}) {
|
|
|
905
905
|
e.depositorPublicKey,
|
|
906
906
|
e.btcNetwork
|
|
907
907
|
);
|
|
908
|
-
return
|
|
908
|
+
return qo(e, t, o, r.signal);
|
|
909
909
|
}
|
|
910
|
-
function
|
|
910
|
+
function No(e) {
|
|
911
911
|
const t = /* @__PURE__ */ new Set();
|
|
912
912
|
for (const r of e.requests) {
|
|
913
913
|
if (t.has(r.id))
|
|
@@ -917,10 +917,10 @@ function Oo(e) {
|
|
|
917
917
|
t.add(r.id);
|
|
918
918
|
}
|
|
919
919
|
}
|
|
920
|
-
function
|
|
920
|
+
function Do(e) {
|
|
921
921
|
const t = e.requests.filter(
|
|
922
|
-
(s) =>
|
|
923
|
-
), r =
|
|
922
|
+
(s) => Ht[s.kind] === "intentBound"
|
|
923
|
+
), r = Ho.flatMap(
|
|
924
924
|
(s) => e.requests.filter((n) => n.kind === s)
|
|
925
925
|
), o = t.length + r.length;
|
|
926
926
|
if (o !== e.requests.length)
|
|
@@ -929,13 +929,13 @@ function No(e) {
|
|
|
929
929
|
);
|
|
930
930
|
return { intentBound: t, standalone: r };
|
|
931
931
|
}
|
|
932
|
-
function
|
|
932
|
+
function Ot(e, t) {
|
|
933
933
|
if (t.size !== e.requests.length)
|
|
934
934
|
throw new Error(
|
|
935
935
|
`Delegated-claim signing ended with ${t.size} signatures for ${e.requests.length} requests; the set is incomplete and must not be treated as signed.`
|
|
936
936
|
);
|
|
937
937
|
}
|
|
938
|
-
function
|
|
938
|
+
function Lo(e, t) {
|
|
939
939
|
if (e.depositTerms === void 0)
|
|
940
940
|
throw new Error(
|
|
941
941
|
"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."
|
|
@@ -944,15 +944,15 @@ function Do(e, t) {
|
|
|
944
944
|
throw new Error(
|
|
945
945
|
"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."
|
|
946
946
|
);
|
|
947
|
-
const r =
|
|
947
|
+
const r = vt(e.vaultContext.depositorBtcPubkey);
|
|
948
948
|
if (r !== t.vault.depositorBtcPubkey)
|
|
949
949
|
throw new Error(
|
|
950
950
|
`vaultContext derives from depositor key ${r} but this plan's vault is registered to ${t.vault.depositorBtcPubkey}; the device would derive for another depositor.`
|
|
951
951
|
);
|
|
952
952
|
return { depositTerms: e.depositTerms, vaultContext: e.vaultContext };
|
|
953
953
|
}
|
|
954
|
-
function
|
|
955
|
-
const r = (s) => s.map((n) =>
|
|
954
|
+
function Mo(e, t) {
|
|
955
|
+
const r = (s) => s.map((n) => R(n)).sort().join(",");
|
|
956
956
|
if (r(e.vaultKeeperBtcPubkeys) !== r(t.vaultKeeperBtcPubkeys) || r(e.universalChallengerBtcPubkeys) !== r(t.universalChallengerBtcPubkeys))
|
|
957
957
|
throw new Error(
|
|
958
958
|
"Deposit terms carry different keeper or challenger rosters than the vault context this claim signs for; the device would bind the Assert to the wrong intent."
|
|
@@ -977,22 +977,22 @@ function Lo(e, t) {
|
|
|
977
977
|
throw new Error(
|
|
978
978
|
"Deposit terms describe no vault group, so they cannot name the vault context's vault provider; the device would bind the Assert to the wrong intent."
|
|
979
979
|
);
|
|
980
|
-
const o =
|
|
980
|
+
const o = R(t.vaultProviderBtcPubkey);
|
|
981
981
|
for (const s of e.vaults)
|
|
982
|
-
if (
|
|
982
|
+
if (R(s.vaultProviderBtcPubkey) !== o)
|
|
983
983
|
throw new Error(
|
|
984
984
|
`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.`
|
|
985
985
|
);
|
|
986
986
|
}
|
|
987
|
-
async function
|
|
987
|
+
async function Uo(e, t, r, o, { intentBound: s, standalone: n }, a) {
|
|
988
988
|
var g;
|
|
989
|
-
const i =
|
|
989
|
+
const i = Fo(e, a.resume), u = [...s, ...n];
|
|
990
990
|
let l = 0;
|
|
991
991
|
const c = {
|
|
992
992
|
phase: "clearing any loaded intent"
|
|
993
|
-
},
|
|
994
|
-
var
|
|
995
|
-
c.phase = "signing", (
|
|
993
|
+
}, p = async (h) => {
|
|
994
|
+
var b;
|
|
995
|
+
c.phase = "signing", (b = a.signal) == null || b.throwIfAborted();
|
|
996
996
|
const y = await t.signDelegatedClaimPsbt(
|
|
997
997
|
He(h.psbtBase64),
|
|
998
998
|
kt(
|
|
@@ -1000,42 +1000,42 @@ async function Mo(e, t, r, o, { intentBound: s, standalone: n }, a) {
|
|
|
1000
1000
|
h.inputIndex,
|
|
1001
1001
|
r
|
|
1002
1002
|
)
|
|
1003
|
-
), f = await
|
|
1004
|
-
|
|
1003
|
+
), f = await bt(
|
|
1004
|
+
Kt(y),
|
|
1005
1005
|
h.inputIndex
|
|
1006
1006
|
);
|
|
1007
1007
|
fe(e, h, f), i.set(h.id, f);
|
|
1008
|
-
},
|
|
1008
|
+
}, d = async (h) => {
|
|
1009
1009
|
var f;
|
|
1010
|
-
c.phase = h, (f = a.signal) == null || f.throwIfAborted(), (await
|
|
1010
|
+
c.phase = h, (f = a.signal) == null || f.throwIfAborted(), (await Ct(t, o.vaultContext)).fill(0);
|
|
1011
1011
|
};
|
|
1012
1012
|
typeof t.validateDepositTerms == "function" && await t.validateDepositTerms(o.depositTerms);
|
|
1013
1013
|
try {
|
|
1014
|
-
await
|
|
1014
|
+
await d("clearing any loaded intent"), c.phase = "approving the deposit terms", (g = a.signal) == null || g.throwIfAborted(), await t.approveDepositTerms(o.depositTerms);
|
|
1015
1015
|
for (const h of s)
|
|
1016
|
-
await
|
|
1017
|
-
await
|
|
1016
|
+
await p(h), l++;
|
|
1017
|
+
await d("releasing the loaded intent");
|
|
1018
1018
|
for (const h of n)
|
|
1019
|
-
i.has(h.id) || await
|
|
1019
|
+
i.has(h.id) || await p(h), l++;
|
|
1020
1020
|
} catch (h) {
|
|
1021
1021
|
const y = u[l];
|
|
1022
1022
|
if (i.size === 0 || y === void 0) throw h;
|
|
1023
1023
|
const f = c.phase === "signing" ? `stopped at "${y.id}"` : `stopped before "${y.id}" while ${c.phase}`;
|
|
1024
|
-
throw new
|
|
1024
|
+
throw new Ko(
|
|
1025
1025
|
`Delegated-claim signing ${f}; ${i.size} of ${e.requests.length} signatures were collected.`,
|
|
1026
1026
|
i,
|
|
1027
1027
|
y.id,
|
|
1028
1028
|
{ cause: h }
|
|
1029
1029
|
);
|
|
1030
1030
|
}
|
|
1031
|
-
return
|
|
1031
|
+
return Ot(e, i), i;
|
|
1032
1032
|
}
|
|
1033
|
-
function
|
|
1033
|
+
function Fo(e, t) {
|
|
1034
1034
|
const r = /* @__PURE__ */ new Map();
|
|
1035
1035
|
if (!t) return r;
|
|
1036
1036
|
for (const o of e.requests) {
|
|
1037
1037
|
const s = t.get(o.id);
|
|
1038
|
-
if (!(s === void 0 ||
|
|
1038
|
+
if (!(s === void 0 || Ht[o.kind] === "intentBound")) {
|
|
1039
1039
|
try {
|
|
1040
1040
|
fe(e, o, s);
|
|
1041
1041
|
} catch {
|
|
@@ -1046,8 +1046,8 @@ function Uo(e, t) {
|
|
|
1046
1046
|
}
|
|
1047
1047
|
return r;
|
|
1048
1048
|
}
|
|
1049
|
-
async function
|
|
1050
|
-
const s = e.requests, n = await
|
|
1049
|
+
async function qo(e, t, r, o) {
|
|
1050
|
+
const s = e.requests, n = await mt(
|
|
1051
1051
|
t,
|
|
1052
1052
|
s.map((i) => He(i.psbtBase64)),
|
|
1053
1053
|
s.map(
|
|
@@ -1060,43 +1060,43 @@ async function Fo(e, t, r, o) {
|
|
|
1060
1060
|
o
|
|
1061
1061
|
), a = /* @__PURE__ */ new Map();
|
|
1062
1062
|
for (let i = 0; i < s.length; i++) {
|
|
1063
|
-
const u = await
|
|
1064
|
-
|
|
1063
|
+
const u = await bt(
|
|
1064
|
+
Kt(n[i]),
|
|
1065
1065
|
s[i].inputIndex
|
|
1066
1066
|
);
|
|
1067
1067
|
fe(e, s[i], u), a.set(s[i].id, u);
|
|
1068
1068
|
}
|
|
1069
|
-
return
|
|
1069
|
+
return Ot(e, a), a;
|
|
1070
1070
|
}
|
|
1071
|
-
async function
|
|
1072
|
-
const t = await
|
|
1071
|
+
async function yn(e) {
|
|
1072
|
+
const t = await Ao({
|
|
1073
1073
|
depositorPublicKey: e.depositorPublicKey,
|
|
1074
1074
|
btcNetwork: e.btcNetwork,
|
|
1075
1075
|
source: e.source,
|
|
1076
1076
|
trustedVerifyingKeyHex: e.trustedVerifyingKeyHex,
|
|
1077
1077
|
vault: e.vault,
|
|
1078
1078
|
babeSessionsJson: e.babeSessionsJson
|
|
1079
|
-
}), r = await
|
|
1079
|
+
}), r = await Oo(t, e.btcWallet, {
|
|
1080
1080
|
depositTerms: e.depositTerms,
|
|
1081
1081
|
vaultContext: e.vaultContext
|
|
1082
1082
|
});
|
|
1083
|
-
return
|
|
1083
|
+
return Vo({ plan: t, signatures: r });
|
|
1084
1084
|
}
|
|
1085
|
-
async function
|
|
1086
|
-
const t = await
|
|
1085
|
+
async function vn(e) {
|
|
1086
|
+
const t = await Ct(e.btcWallet, e.vaultContext);
|
|
1087
1087
|
let r;
|
|
1088
1088
|
try {
|
|
1089
|
-
r = await
|
|
1089
|
+
r = await Pr(t, e.htlcVout);
|
|
1090
1090
|
} finally {
|
|
1091
1091
|
t.fill(0);
|
|
1092
1092
|
}
|
|
1093
1093
|
let o;
|
|
1094
1094
|
try {
|
|
1095
|
-
o = await
|
|
1095
|
+
o = await mr(r);
|
|
1096
1096
|
} finally {
|
|
1097
1097
|
r.fill(0);
|
|
1098
1098
|
}
|
|
1099
|
-
return
|
|
1099
|
+
return Go(o.pk_hash, e.expectedWotsPkHash), await br(
|
|
1100
1100
|
e.txGraphVersion,
|
|
1101
1101
|
o.keypair,
|
|
1102
1102
|
e.txGraphJson
|
|
@@ -1105,7 +1105,7 @@ async function gn(e) {
|
|
|
1105
1105
|
pkHash: o.pk_hash
|
|
1106
1106
|
};
|
|
1107
1107
|
}
|
|
1108
|
-
function
|
|
1108
|
+
function Go(e, t) {
|
|
1109
1109
|
if (ie(e) !== ie(t))
|
|
1110
1110
|
throw new Error(
|
|
1111
1111
|
`Derived WOTS public-key hash ${ie(e)} does not match the vault's on-chain depositorWotsPkHash ${ie(t)}. The wallet, the HTLC output index, or the derivation itself is not the one this vault was created with.`
|
|
@@ -1126,7 +1126,7 @@ function xe(e, t, r) {
|
|
|
1126
1126
|
rotated: n !== s
|
|
1127
1127
|
};
|
|
1128
1128
|
}
|
|
1129
|
-
function
|
|
1129
|
+
function Xo(e) {
|
|
1130
1130
|
const t = /* @__PURE__ */ new Map();
|
|
1131
1131
|
for (const r of e) {
|
|
1132
1132
|
const o = t.get(r.operationBtcPubkey);
|
|
@@ -1137,7 +1137,7 @@ function Go(e) {
|
|
|
1137
1137
|
t.set(r.operationBtcPubkey, r.adminAddress);
|
|
1138
1138
|
}
|
|
1139
1139
|
}
|
|
1140
|
-
function
|
|
1140
|
+
function Nt(e, t, r) {
|
|
1141
1141
|
if (t.vaultKeepers.length !== e.vaultKeepers.length || t.universalChallengers.length !== e.universalChallengers.length)
|
|
1142
1142
|
throw new Error(
|
|
1143
1143
|
`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`
|
|
@@ -1154,7 +1154,7 @@ function Ot(e, t, r) {
|
|
|
1154
1154
|
), n = e.universalChallengers.map(
|
|
1155
1155
|
(a, i) => xe("universal challenger", a, t.universalChallengers[i])
|
|
1156
1156
|
);
|
|
1157
|
-
return
|
|
1157
|
+
return Xo([
|
|
1158
1158
|
o,
|
|
1159
1159
|
...s,
|
|
1160
1160
|
...n
|
|
@@ -1169,24 +1169,24 @@ function Ot(e, t, r) {
|
|
|
1169
1169
|
query: e
|
|
1170
1170
|
};
|
|
1171
1171
|
}
|
|
1172
|
-
async function
|
|
1172
|
+
async function zo(e) {
|
|
1173
1173
|
const t = await e.operationKeyReader.getCurrentOperationKeys(
|
|
1174
1174
|
e.query,
|
|
1175
1175
|
e.blockNumber
|
|
1176
1176
|
);
|
|
1177
|
-
return
|
|
1177
|
+
return Nt(e.query, t, { mode: "current" });
|
|
1178
1178
|
}
|
|
1179
|
-
async function
|
|
1179
|
+
async function Dt(e) {
|
|
1180
1180
|
const t = await e.operationKeyReader.getOperationKeysAtEpochs(
|
|
1181
1181
|
e.query,
|
|
1182
1182
|
e.epochs
|
|
1183
1183
|
);
|
|
1184
|
-
return
|
|
1184
|
+
return Nt(e.query, t, {
|
|
1185
1185
|
mode: "epochs",
|
|
1186
1186
|
epochs: e.epochs
|
|
1187
1187
|
});
|
|
1188
1188
|
}
|
|
1189
|
-
async function
|
|
1189
|
+
async function Lt(e) {
|
|
1190
1190
|
const { basic: t, protocol: r } = e.vault, {
|
|
1191
1191
|
registryReader: o,
|
|
1192
1192
|
vaultKeeperReader: s,
|
|
@@ -1216,7 +1216,7 @@ async function Dt(e) {
|
|
|
1216
1216
|
throw new Error(
|
|
1217
1217
|
`No universal challengers for version ${r.universalChallengersVersion}`
|
|
1218
1218
|
);
|
|
1219
|
-
return
|
|
1219
|
+
return Dt({
|
|
1220
1220
|
operationKeyReader: a,
|
|
1221
1221
|
query: {
|
|
1222
1222
|
vaultProviderEthAddress: t.vaultProvider,
|
|
@@ -1228,11 +1228,11 @@ async function Dt(e) {
|
|
|
1228
1228
|
epochs: c
|
|
1229
1229
|
});
|
|
1230
1230
|
}
|
|
1231
|
-
async function
|
|
1231
|
+
async function Pn(e) {
|
|
1232
1232
|
const { vaultId: t, readers: r } = e, o = await r.registryReader.getVaultData(t), { basic: s, protocol: n } = o;
|
|
1233
|
-
if (n.vaultCoreVersion !==
|
|
1233
|
+
if (n.vaultCoreVersion !== q)
|
|
1234
1234
|
throw new Error(
|
|
1235
|
-
`Vault ${t} is stamped vault core version ${n.vaultCoreVersion}; delegated claim requires ${
|
|
1235
|
+
`Vault ${t} is stamped vault core version ${n.vaultCoreVersion}; delegated claim requires ${q}.`
|
|
1236
1236
|
);
|
|
1237
1237
|
const a = _e(
|
|
1238
1238
|
s.depositorBtcPubKey,
|
|
@@ -1247,7 +1247,7 @@ async function fn(e) {
|
|
|
1247
1247
|
`the vault's status is ${s.status}, not Redeemed (${ze.REDEEMED}); no scan was made`
|
|
1248
1248
|
);
|
|
1249
1249
|
const [i, u, l, c] = await Promise.all([
|
|
1250
|
-
|
|
1250
|
+
Lt({ vaultId: t, vault: o, readers: r }),
|
|
1251
1251
|
r.registryReader.getRegistrationRecordsAtBlock(s.createdAt),
|
|
1252
1252
|
r.registryReader.getVaultClaimableBy(t, s.depositorBtcPubKey, s.createdAt).catch((v) => {
|
|
1253
1253
|
throw kr(v) ? new Le(
|
|
@@ -1262,54 +1262,54 @@ async function fn(e) {
|
|
|
1262
1262
|
r.protocolParamsReader.getOffchainParamsByVersion(
|
|
1263
1263
|
n.offchainParamsVersion
|
|
1264
1264
|
)
|
|
1265
|
-
]),
|
|
1266
|
-
|
|
1267
|
-
const g =
|
|
1265
|
+
]), p = Nr(c.timelockAssert), d = Cr(u, t, s.createdAt);
|
|
1266
|
+
Tr(d);
|
|
1267
|
+
const g = _r(d);
|
|
1268
1268
|
if (g.toLowerCase() !== n.prePeginTxHash.toLowerCase())
|
|
1269
1269
|
throw new Error(
|
|
1270
1270
|
`Registration log of vault ${t} records prePeginTxHash ${g} but the vault record says ${n.prePeginTxHash}; refusing an inconsistent node.`
|
|
1271
1271
|
);
|
|
1272
|
-
if (
|
|
1272
|
+
if (d.vaultCoreVersion !== n.vaultCoreVersion)
|
|
1273
1273
|
throw new Error(
|
|
1274
|
-
`Registration log of vault ${t} records vault core version ${
|
|
1274
|
+
`Registration log of vault ${t} records vault core version ${d.vaultCoreVersion} but the vault record says ${n.vaultCoreVersion}; refusing an inconsistent node.`
|
|
1275
1275
|
);
|
|
1276
|
-
if (
|
|
1276
|
+
if (d.amount !== s.amount)
|
|
1277
1277
|
throw new Error(
|
|
1278
|
-
`Registration log of vault ${t} records amount ${
|
|
1278
|
+
`Registration log of vault ${t} records amount ${d.amount} sats but the vault record says ${s.amount}; refusing an inconsistent node.`
|
|
1279
1279
|
);
|
|
1280
|
-
if (
|
|
1280
|
+
if (d.depositor.toLowerCase() !== s.depositor.toLowerCase())
|
|
1281
1281
|
throw new Error(
|
|
1282
|
-
`Registration log of vault ${t} records depositor ${
|
|
1282
|
+
`Registration log of vault ${t} records depositor ${d.depositor} but the vault record says ${s.depositor}; refusing an inconsistent node.`
|
|
1283
1283
|
);
|
|
1284
|
-
if (
|
|
1284
|
+
if (d.vaultProvider.toLowerCase() !== s.vaultProvider.toLowerCase())
|
|
1285
1285
|
throw new Error(
|
|
1286
|
-
`Registration log of vault ${t} records vaultProvider ${
|
|
1286
|
+
`Registration log of vault ${t} records vaultProvider ${d.vaultProvider} but the vault record says ${s.vaultProvider}; refusing an inconsistent node.`
|
|
1287
1287
|
);
|
|
1288
1288
|
if (l.vaultCoreVersion !== n.vaultCoreVersion)
|
|
1289
1289
|
throw new Error(
|
|
1290
1290
|
`Redemption log of vault ${t} records vault core version ${l.vaultCoreVersion} but the vault record says ${n.vaultCoreVersion}; refusing an inconsistent node.`
|
|
1291
1291
|
);
|
|
1292
|
-
if (l.proverCircuitVersion !==
|
|
1292
|
+
if (l.proverCircuitVersion !== d.proverCircuitVersion)
|
|
1293
1293
|
throw new Error(
|
|
1294
|
-
`Redemption log of vault ${t} records proverCircuitVersion ${l.proverCircuitVersion} but the registration log says ${
|
|
1294
|
+
`Redemption log of vault ${t} records proverCircuitVersion ${l.proverCircuitVersion} but the registration log says ${d.proverCircuitVersion}; refusing an inconsistent node.`
|
|
1295
1295
|
);
|
|
1296
|
-
if (
|
|
1296
|
+
if (d.proverCircuitVersion !== c.proverCircuitVersion)
|
|
1297
1297
|
throw new Error(
|
|
1298
|
-
`Registration log of vault ${t} records proverCircuitVersion ${
|
|
1298
|
+
`Registration log of vault ${t} records proverCircuitVersion ${d.proverCircuitVersion} but the stamped offchain params say ${c.proverCircuitVersion}; refusing an inconsistent node.`
|
|
1299
1299
|
);
|
|
1300
|
-
const h =
|
|
1300
|
+
const h = Sr(n.depositorSignedPeginTx);
|
|
1301
1301
|
for (const [v, E] of [
|
|
1302
|
-
["Registration",
|
|
1302
|
+
["Registration", d.peginTxHash],
|
|
1303
1303
|
["Redemption", l.peginTxHash]
|
|
1304
1304
|
])
|
|
1305
1305
|
if (E.toLowerCase() !== h.toLowerCase())
|
|
1306
1306
|
throw new Error(
|
|
1307
1307
|
`${v} log of vault ${t} records peginTxHash ${E} but the vault's depositor-signed PegIn hashes to ${h}; refusing an inconsistent node.`
|
|
1308
1308
|
);
|
|
1309
|
-
const y =
|
|
1310
|
-
|
|
1309
|
+
const y = j(
|
|
1310
|
+
wt(h, s.depositor)
|
|
1311
1311
|
);
|
|
1312
|
-
if (y !==
|
|
1312
|
+
if (y !== j(t))
|
|
1313
1313
|
throw new Error(
|
|
1314
1314
|
`Depositor-signed PegIn of vault ${t} derives vault id ${y} with depositor ${s.depositor}; refusing an inconsistent node.`
|
|
1315
1315
|
);
|
|
@@ -1318,9 +1318,9 @@ async function fn(e) {
|
|
|
1318
1318
|
"universalChallengersVersion",
|
|
1319
1319
|
"appVaultKeepersVersion"
|
|
1320
1320
|
]) {
|
|
1321
|
-
if (
|
|
1321
|
+
if (d[v] !== n[v])
|
|
1322
1322
|
throw new Error(
|
|
1323
|
-
`Registration log of vault ${t} records ${v} ${
|
|
1323
|
+
`Registration log of vault ${t} records ${v} ${d[v]} but the vault record says ${n[v]}; refusing an inconsistent node.`
|
|
1324
1324
|
);
|
|
1325
1325
|
if (l[v] !== n[v])
|
|
1326
1326
|
throw new Error(
|
|
@@ -1334,10 +1334,10 @@ async function fn(e) {
|
|
|
1334
1334
|
throw new Error(
|
|
1335
1335
|
`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.`
|
|
1336
1336
|
);
|
|
1337
|
-
const
|
|
1338
|
-
if (
|
|
1337
|
+
const b = Ke(f.ins[0].hash), k = f.ins[0].index;
|
|
1338
|
+
if (b !== P(n.prePeginTxHash).toLowerCase() || k !== n.htlcVout)
|
|
1339
1339
|
throw new Error(
|
|
1340
|
-
`Depositor-signed PegIn of vault ${t} spends ${
|
|
1340
|
+
`Depositor-signed PegIn of vault ${t} spends ${b}:${k} but the vault record says Pre-PegIn ${n.prePeginTxHash} output ${n.htlcVout}; refusing an inconsistent node.`
|
|
1341
1341
|
);
|
|
1342
1342
|
const x = f.outs[Z];
|
|
1343
1343
|
if (x === void 0)
|
|
@@ -1354,7 +1354,7 @@ async function fn(e) {
|
|
|
1354
1354
|
depositorEthAddress: s.depositor,
|
|
1355
1355
|
depositorBtcPubkey: a,
|
|
1356
1356
|
registeredPayoutScriptPubKey: P(
|
|
1357
|
-
|
|
1357
|
+
d.depositorPayoutScriptPubKey
|
|
1358
1358
|
),
|
|
1359
1359
|
vaultProviderBtcPubkey: i.vaultProvider.operationBtcPubkey,
|
|
1360
1360
|
vaultKeeperBtcPubkeys: [
|
|
@@ -1363,18 +1363,18 @@ async function fn(e) {
|
|
|
1363
1363
|
universalChallengerBtcPubkeys: [
|
|
1364
1364
|
...i.universalChallengerOperationKeysSorted
|
|
1365
1365
|
],
|
|
1366
|
-
txGraphVersion:
|
|
1366
|
+
txGraphVersion: q,
|
|
1367
1367
|
proverCircuitVersion: c.proverCircuitVersion,
|
|
1368
1368
|
vaultCoreVersion: n.vaultCoreVersion,
|
|
1369
1369
|
claimableEventBlockNumber: l.blockNumber,
|
|
1370
1370
|
peginVaultOutputValueSats: x.value,
|
|
1371
1371
|
protocolFeeRate: c.feeRate,
|
|
1372
1372
|
councilSize: c.securityCouncilKeys.length,
|
|
1373
|
-
timelockPegin:
|
|
1373
|
+
timelockPegin: p,
|
|
1374
1374
|
timelockAssert: Number(c.timelockAssert)
|
|
1375
1375
|
},
|
|
1376
1376
|
vault: o,
|
|
1377
|
-
registrationRecord:
|
|
1377
|
+
registrationRecord: d,
|
|
1378
1378
|
registrationRecords: u,
|
|
1379
1379
|
participantKeys: i,
|
|
1380
1380
|
offchainParams: c,
|
|
@@ -1386,35 +1386,35 @@ async function fn(e) {
|
|
|
1386
1386
|
htlcVout: n.htlcVout
|
|
1387
1387
|
};
|
|
1388
1388
|
}
|
|
1389
|
-
const
|
|
1390
|
-
class
|
|
1389
|
+
const jo = 8, Wo = 6e3, Yo = 10 * 6e4, Qo = 10;
|
|
1390
|
+
class Mt extends Error {
|
|
1391
1391
|
constructor(t) {
|
|
1392
1392
|
super(t), this.name = "PeginRegistrationMissingError";
|
|
1393
1393
|
}
|
|
1394
1394
|
}
|
|
1395
|
-
class
|
|
1395
|
+
class Ut extends Error {
|
|
1396
1396
|
constructor(t) {
|
|
1397
1397
|
super(t), this.name = "PeginRegistrationNotFinalError";
|
|
1398
1398
|
}
|
|
1399
1399
|
}
|
|
1400
|
-
function
|
|
1401
|
-
return e instanceof
|
|
1400
|
+
function Jo(e) {
|
|
1401
|
+
return e instanceof Mt || e instanceof Error && e.name === "PeginRegistrationMissingError";
|
|
1402
1402
|
}
|
|
1403
|
-
function
|
|
1404
|
-
return e instanceof
|
|
1403
|
+
function mn(e) {
|
|
1404
|
+
return e instanceof Ut || e instanceof Error && e.name === "PeginRegistrationNotFinalError";
|
|
1405
1405
|
}
|
|
1406
1406
|
function et(e) {
|
|
1407
1407
|
const { currentBlock: t, createdAtBlock: r } = e, o = t - r + 1n;
|
|
1408
1408
|
return o < 0n ? 0 : Number(o);
|
|
1409
1409
|
}
|
|
1410
|
-
async function
|
|
1410
|
+
async function bn(e) {
|
|
1411
1411
|
const {
|
|
1412
1412
|
vaultRegistryReader: t,
|
|
1413
1413
|
getBlockNumber: r,
|
|
1414
1414
|
vaultIds: o,
|
|
1415
|
-
required: s =
|
|
1416
|
-
pollIntervalMs: n =
|
|
1417
|
-
timeoutMs: a =
|
|
1415
|
+
required: s = jo,
|
|
1416
|
+
pollIntervalMs: n = Wo,
|
|
1417
|
+
timeoutMs: a = Yo,
|
|
1418
1418
|
signal: i,
|
|
1419
1419
|
onProgress: u
|
|
1420
1420
|
} = e;
|
|
@@ -1423,52 +1423,52 @@ async function vn(e) {
|
|
|
1423
1423
|
"waitForPeginRegistrationDepth requires at least one vault ID"
|
|
1424
1424
|
);
|
|
1425
1425
|
const l = Date.now();
|
|
1426
|
-
let c = !1,
|
|
1426
|
+
let c = !1, p = 0, d;
|
|
1427
1427
|
for (; ; ) {
|
|
1428
1428
|
if (i != null && i.aborted)
|
|
1429
1429
|
throw new Error(
|
|
1430
1430
|
`Aborted while waiting for peg-in registration depth (${o.length} vault(s))`
|
|
1431
1431
|
);
|
|
1432
1432
|
if (Date.now() - l >= a)
|
|
1433
|
-
throw new
|
|
1434
|
-
`Peg-in registration did not reach ${s} Ethereum confirmations within ${a}ms. The registration transaction was submitted but is not yet final, so the Pre-PegIn Bitcoin transaction was never sent and no funds are at risk. Resume this deposit from the dashboard once the network settles.` + (
|
|
1433
|
+
throw new Ut(
|
|
1434
|
+
`Peg-in registration did not reach ${s} Ethereum confirmations within ${a}ms. The registration transaction was submitted but is not yet final, so the Pre-PegIn Bitcoin transaction was never sent and no funds are at risk. Resume this deposit from the dashboard once the network settles.` + (d instanceof Error ? ` Last read error: ${d.message}` : "")
|
|
1435
1435
|
);
|
|
1436
1436
|
try {
|
|
1437
1437
|
const g = await r(), h = await Promise.all(
|
|
1438
1438
|
o.map((f) => t.getVaultBasicInfo(f))
|
|
1439
1439
|
), y = h.findIndex(
|
|
1440
|
-
(f) => f.depositor ===
|
|
1440
|
+
(f) => f.depositor === Dr || f.createdAt === 0n
|
|
1441
1441
|
);
|
|
1442
1442
|
if (y !== -1) {
|
|
1443
|
-
if (
|
|
1444
|
-
throw new
|
|
1445
|
-
`Vault ${o[y]} is still not visible on-chain after ${
|
|
1443
|
+
if (p += 1, !c && p > Qo)
|
|
1444
|
+
throw new Mt(
|
|
1445
|
+
`Vault ${o[y]} is still not visible on-chain after ${p} reads — the registration does not exist.`
|
|
1446
1446
|
);
|
|
1447
1447
|
console.warn(
|
|
1448
1448
|
`Peg-in registration for vault ${o[y]} is not visible in chain state at block ${g} — a lagging RPC backend or an Ethereum reorg. Still polling.`
|
|
1449
1449
|
), u == null || u({ confirmations: 0, required: s });
|
|
1450
1450
|
} else {
|
|
1451
|
-
c = !0,
|
|
1452
|
-
let f = h[0],
|
|
1451
|
+
c = !0, p = 0, d = void 0;
|
|
1452
|
+
let f = h[0], b = et({
|
|
1453
1453
|
currentBlock: g,
|
|
1454
1454
|
createdAtBlock: h[0].createdAt
|
|
1455
1455
|
});
|
|
1456
|
-
for (const
|
|
1456
|
+
for (const k of h.slice(1)) {
|
|
1457
1457
|
const x = et({
|
|
1458
1458
|
currentBlock: g,
|
|
1459
|
-
createdAtBlock:
|
|
1459
|
+
createdAtBlock: k.createdAt
|
|
1460
1460
|
});
|
|
1461
|
-
x <
|
|
1461
|
+
x < b && (b = x, f = k);
|
|
1462
1462
|
}
|
|
1463
|
-
if (u == null || u({ confirmations:
|
|
1464
|
-
return { confirmations:
|
|
1463
|
+
if (u == null || u({ confirmations: b, required: s }), b >= s)
|
|
1464
|
+
return { confirmations: b, basicInfo: f };
|
|
1465
1465
|
}
|
|
1466
1466
|
} catch (g) {
|
|
1467
|
-
if (
|
|
1467
|
+
if (Jo(g))
|
|
1468
1468
|
throw g;
|
|
1469
1469
|
console.warn(
|
|
1470
1470
|
`Registration-depth read failed (retrying in ${n}ms): ` + (g instanceof Error ? g.message : String(g))
|
|
1471
|
-
),
|
|
1471
|
+
), d = g;
|
|
1472
1472
|
}
|
|
1473
1473
|
await new Promise((g, h) => {
|
|
1474
1474
|
const y = () => {
|
|
@@ -1484,307 +1484,307 @@ async function vn(e) {
|
|
|
1484
1484
|
});
|
|
1485
1485
|
}
|
|
1486
1486
|
}
|
|
1487
|
-
const
|
|
1488
|
-
class
|
|
1487
|
+
const Zo = /^(?:[0-9a-f]{2})*$/, es = /^[0-9a-f]{64}$/, ts = /^([0-9a-f]{64}):(0|[1-9][0-9]*)$/, rs = -2147483648, os = 2147483647, Ee = 4294967295, tt = 2, rt = 2, de = 0;
|
|
1488
|
+
class w extends Error {
|
|
1489
1489
|
constructor(t) {
|
|
1490
1490
|
super(t), this.name = "GraphFingerprintError";
|
|
1491
1491
|
}
|
|
1492
1492
|
}
|
|
1493
|
-
function
|
|
1493
|
+
function $(e, t, r) {
|
|
1494
1494
|
const o = e[t];
|
|
1495
1495
|
if (o === void 0)
|
|
1496
|
-
throw new
|
|
1496
|
+
throw new w(`Graph tx ${r} is missing "${t}"`);
|
|
1497
1497
|
return o;
|
|
1498
1498
|
}
|
|
1499
1499
|
function te(e, t) {
|
|
1500
1500
|
if (!Array.isArray(e))
|
|
1501
|
-
throw new
|
|
1501
|
+
throw new w(`Graph tx ${t} is not an array`);
|
|
1502
1502
|
return e;
|
|
1503
1503
|
}
|
|
1504
|
-
function
|
|
1504
|
+
function I(e, t) {
|
|
1505
1505
|
if (e === null || typeof e != "object" || Array.isArray(e))
|
|
1506
|
-
throw new
|
|
1506
|
+
throw new w(`Graph tx ${t} is not an object`);
|
|
1507
1507
|
return e;
|
|
1508
1508
|
}
|
|
1509
1509
|
function Q(e, t, r, o) {
|
|
1510
1510
|
if (typeof e != "number" || !Number.isSafeInteger(e) || e < r || e > o)
|
|
1511
|
-
throw new
|
|
1511
|
+
throw new w(
|
|
1512
1512
|
`Graph tx ${t} is not an integer in [${r}, ${o}]`
|
|
1513
1513
|
);
|
|
1514
1514
|
return e;
|
|
1515
1515
|
}
|
|
1516
|
-
function
|
|
1517
|
-
if (typeof e != "string" || !
|
|
1518
|
-
throw new
|
|
1516
|
+
function $e(e, t) {
|
|
1517
|
+
if (typeof e != "string" || !Zo.test(e))
|
|
1518
|
+
throw new w(
|
|
1519
1519
|
`Graph tx ${t} is not lowercase hex without a prefix`
|
|
1520
1520
|
);
|
|
1521
|
-
return
|
|
1521
|
+
return O.from(e, "hex");
|
|
1522
1522
|
}
|
|
1523
|
-
function
|
|
1524
|
-
if (typeof e != "string" || !
|
|
1525
|
-
throw new
|
|
1523
|
+
function pe(e, t) {
|
|
1524
|
+
if (typeof e != "string" || !es.test(e))
|
|
1525
|
+
throw new w(
|
|
1526
1526
|
`Graph ${t} is not 32 bytes of lowercase hex`
|
|
1527
1527
|
);
|
|
1528
1528
|
return e;
|
|
1529
1529
|
}
|
|
1530
1530
|
function ot(e, t) {
|
|
1531
|
-
const r =
|
|
1531
|
+
const r = I(e, t), o = new S();
|
|
1532
1532
|
return o.version = Q(
|
|
1533
|
-
|
|
1533
|
+
$(r, "version", t),
|
|
1534
1534
|
`${t}.version`,
|
|
1535
|
-
|
|
1536
|
-
|
|
1535
|
+
rs,
|
|
1536
|
+
os
|
|
1537
1537
|
), o.locktime = Q(
|
|
1538
|
-
|
|
1538
|
+
$(r, "lock_time", t),
|
|
1539
1539
|
`${t}.lock_time`,
|
|
1540
1540
|
0,
|
|
1541
1541
|
Ee
|
|
1542
|
-
), te(
|
|
1543
|
-
const a = `${t}.input[${n}]`, i =
|
|
1542
|
+
), te($(r, "input", t), `${t}.input`).forEach((s, n) => {
|
|
1543
|
+
const a = `${t}.input[${n}]`, i = I(s, a), u = $(i, "previous_output", a), l = typeof u == "string" && ts.exec(u);
|
|
1544
1544
|
if (!l)
|
|
1545
|
-
throw new
|
|
1545
|
+
throw new w(
|
|
1546
1546
|
`Graph tx ${a}.previous_output is not "<txid>:<vout>"`
|
|
1547
1547
|
);
|
|
1548
1548
|
const c = Q(Number(l[2]), `${a}.previous_output vout`, 0, Ee);
|
|
1549
1549
|
o.addInput(
|
|
1550
|
-
|
|
1550
|
+
O.from(l[1], "hex").reverse(),
|
|
1551
1551
|
c,
|
|
1552
|
-
Q(
|
|
1553
|
-
|
|
1552
|
+
Q($(i, "sequence", a), `${a}.sequence`, 0, Ee),
|
|
1553
|
+
$e($(i, "script_sig", a), `${a}.script_sig`)
|
|
1554
1554
|
), o.ins[n].witness = te(
|
|
1555
|
-
|
|
1555
|
+
$(i, "witness", a),
|
|
1556
1556
|
`${a}.witness`
|
|
1557
|
-
).map((
|
|
1558
|
-
}), te(
|
|
1559
|
-
const a = `${t}.output[${n}]`, i =
|
|
1557
|
+
).map((p, d) => $e(p, `${a}.witness[${d}]`));
|
|
1558
|
+
}), te($(r, "output", t), `${t}.output`).forEach((s, n) => {
|
|
1559
|
+
const a = `${t}.output[${n}]`, i = I(s, a);
|
|
1560
1560
|
o.addOutput(
|
|
1561
|
-
|
|
1562
|
-
Q(
|
|
1561
|
+
$e($(i, "script_pubkey", a), `${a}.script_pubkey`),
|
|
1562
|
+
Q($(i, "value", a), `${a}.value`, 0, Number.MAX_SAFE_INTEGER)
|
|
1563
1563
|
);
|
|
1564
1564
|
}), new Uint8Array(o.toBuffer());
|
|
1565
1565
|
}
|
|
1566
|
-
function
|
|
1566
|
+
function L(e, t) {
|
|
1567
1567
|
const r = P(e).toLowerCase();
|
|
1568
1568
|
let o;
|
|
1569
1569
|
try {
|
|
1570
1570
|
o = S.fromHex(r);
|
|
1571
1571
|
} catch (s) {
|
|
1572
|
-
throw new
|
|
1572
|
+
throw new w(
|
|
1573
1573
|
`Presign ${t} is not one transaction: ${s instanceof Error ? s.message : String(s)}`
|
|
1574
1574
|
);
|
|
1575
1575
|
}
|
|
1576
1576
|
if (o.toHex() !== r)
|
|
1577
|
-
throw new
|
|
1577
|
+
throw new w(
|
|
1578
1578
|
`Presign ${t} is not a canonical transaction encoding`
|
|
1579
1579
|
);
|
|
1580
1580
|
return o;
|
|
1581
1581
|
}
|
|
1582
|
-
function
|
|
1582
|
+
function Ft(e, t) {
|
|
1583
1583
|
const r = e.ins[t];
|
|
1584
1584
|
if (r)
|
|
1585
1585
|
return {
|
|
1586
|
-
txid:
|
|
1586
|
+
txid: O.from(r.hash).reverse().toString("hex"),
|
|
1587
1587
|
vout: r.index
|
|
1588
1588
|
};
|
|
1589
1589
|
}
|
|
1590
|
-
function
|
|
1591
|
-
if (!e.outs[
|
|
1592
|
-
throw new
|
|
1593
|
-
`Presign ${t}.claim_tx must have output ${
|
|
1590
|
+
function qt(e, t) {
|
|
1591
|
+
if (!e.outs[de])
|
|
1592
|
+
throw new w(
|
|
1593
|
+
`Presign ${t}.claim_tx must have output ${de}`
|
|
1594
1594
|
);
|
|
1595
1595
|
}
|
|
1596
|
-
function
|
|
1596
|
+
function ss(e, t, r) {
|
|
1597
1597
|
if (e.ins.length !== 1)
|
|
1598
|
-
throw new
|
|
1598
|
+
throw new w(
|
|
1599
1599
|
`Presign ${r}.claim_tx must have exactly one input, got ${e.ins.length}`
|
|
1600
1600
|
);
|
|
1601
|
-
|
|
1602
|
-
const o =
|
|
1603
|
-
if ((o == null ? void 0 : o.txid) !== t || o.vout !==
|
|
1601
|
+
qt(e, r);
|
|
1602
|
+
const o = Ft(e, 0);
|
|
1603
|
+
if ((o == null ? void 0 : o.txid) !== t || o.vout !== z) {
|
|
1604
1604
|
const s = o ? `${o.txid}:${o.vout}` : "no input";
|
|
1605
|
-
throw new
|
|
1606
|
-
`Presign ${r}.claim_tx must spend ${t}:${
|
|
1605
|
+
throw new w(
|
|
1606
|
+
`Presign ${r}.claim_tx must spend ${t}:${z}, got ${s}`
|
|
1607
1607
|
);
|
|
1608
1608
|
}
|
|
1609
1609
|
}
|
|
1610
1610
|
function Oe(e, t, r) {
|
|
1611
|
-
const o =
|
|
1612
|
-
if ((o == null ? void 0 : o.txid) !== t || o.vout !==
|
|
1611
|
+
const o = Ft(e, 0);
|
|
1612
|
+
if ((o == null ? void 0 : o.txid) !== t || o.vout !== de) {
|
|
1613
1613
|
const s = o ? `${o.txid}:${o.vout}` : "no input";
|
|
1614
|
-
throw new
|
|
1615
|
-
`Presign ${r}.assert_tx input 0 must spend ${t}:${
|
|
1614
|
+
throw new w(
|
|
1615
|
+
`Presign ${r}.assert_tx input 0 must spend ${t}:${de}, got ${s}`
|
|
1616
1616
|
);
|
|
1617
1617
|
}
|
|
1618
1618
|
}
|
|
1619
|
-
function
|
|
1620
|
-
const t =
|
|
1619
|
+
function Gt(e) {
|
|
1620
|
+
const t = L(e.peginTxHex, `${e.path}.pegin_tx`), r = L(e.claimTxHex, `${e.path}.claim_tx`), o = L(e.assertTxHex, `${e.path}.assert_tx`);
|
|
1621
1621
|
return { peginTx: t, claimTx: r, assertTx: o };
|
|
1622
1622
|
}
|
|
1623
|
-
function ss(e) {
|
|
1624
|
-
const t = D(e.claimTxHex, `${e.path}.claim_tx`), r = D(e.assertTxHex, `${e.path}.assert_tx`);
|
|
1625
|
-
Ft(t, e.path), Oe(r, t.getId(), e.path);
|
|
1626
|
-
}
|
|
1627
1623
|
function ns(e) {
|
|
1628
|
-
const
|
|
1629
|
-
|
|
1624
|
+
const t = L(e.claimTxHex, `${e.path}.claim_tx`), r = L(e.assertTxHex, `${e.path}.assert_tx`);
|
|
1625
|
+
qt(t, e.path), Oe(r, t.getId(), e.path);
|
|
1626
|
+
}
|
|
1627
|
+
function is(e) {
|
|
1628
|
+
const { peginTx: t, claimTx: r, assertTx: o } = Gt(e);
|
|
1629
|
+
ss(r, t.getId(), e.path), Oe(o, r.getId(), e.path);
|
|
1630
1630
|
}
|
|
1631
|
-
function
|
|
1631
|
+
function as(e, t) {
|
|
1632
1632
|
const [r, ...o] = e.ins;
|
|
1633
1633
|
if (!r || o.length > 0)
|
|
1634
|
-
throw new
|
|
1634
|
+
throw new w(
|
|
1635
1635
|
`Presign claim_tx must have exactly one input, got ${e.ins.length}`
|
|
1636
1636
|
);
|
|
1637
|
-
const s =
|
|
1638
|
-
if (s !== t || r.index !==
|
|
1639
|
-
throw new
|
|
1640
|
-
`Presign claim_tx must spend ${t}:${
|
|
1637
|
+
const s = O.from(r.hash).reverse().toString("hex");
|
|
1638
|
+
if (s !== t || r.index !== z)
|
|
1639
|
+
throw new w(
|
|
1640
|
+
`Presign claim_tx must spend ${t}:${z}, got ${s}:${r.index}`
|
|
1641
1641
|
);
|
|
1642
1642
|
if (e.version !== tt)
|
|
1643
|
-
throw new
|
|
1643
|
+
throw new w(
|
|
1644
1644
|
`Presign claim_tx version must be ${tt}, got ${e.version}`
|
|
1645
1645
|
);
|
|
1646
1646
|
if (r.witness.length > 0)
|
|
1647
|
-
throw new
|
|
1647
|
+
throw new w(
|
|
1648
1648
|
`Presign claim_tx input must have an empty witness, got ${r.witness.length} item(s)`
|
|
1649
1649
|
);
|
|
1650
1650
|
if (e.outs.length !== rt)
|
|
1651
|
-
throw new
|
|
1651
|
+
throw new w(
|
|
1652
1652
|
`Presign claim_tx must have exactly ${rt} outputs, got ${e.outs.length}`
|
|
1653
1653
|
);
|
|
1654
1654
|
}
|
|
1655
|
-
function
|
|
1655
|
+
function Xt(e) {
|
|
1656
1656
|
const t = [...e.challengers].sort(
|
|
1657
1657
|
(o, s) => o.pubkey < s.pubkey ? -1 : o.pubkey > s.pubkey ? 1 : 0
|
|
1658
1658
|
), r = [e.peginTx, e.claimTx, e.assertTx, e.payoutTx];
|
|
1659
1659
|
return t.forEach((o, s) => {
|
|
1660
|
-
const n =
|
|
1660
|
+
const n = pe(o.pubkey, "challenger pubkey");
|
|
1661
1661
|
if (s > 0 && t[s - 1].pubkey === n)
|
|
1662
|
-
throw new
|
|
1662
|
+
throw new w(`Graph lists challenger ${n} twice`);
|
|
1663
1663
|
r.push(We(n), o.nopayoutTx);
|
|
1664
1664
|
for (const a of o.outputLabelHashes)
|
|
1665
|
-
r.push(We(
|
|
1666
|
-
}),
|
|
1665
|
+
r.push(We(pe(a, "output_label_hashes entry")));
|
|
1666
|
+
}), Gr(Xr(zr(...r)));
|
|
1667
1667
|
}
|
|
1668
|
-
function
|
|
1669
|
-
const t = P(e.peginTxid).toLowerCase(), { peginTx: r, claimTx: o, assertTx: s } =
|
|
1668
|
+
function us(e) {
|
|
1669
|
+
const t = P(e.peginTxid).toLowerCase(), { peginTx: r, claimTx: o, assertTx: s } = Gt({
|
|
1670
1670
|
peginTxHex: e.peginTxHex,
|
|
1671
1671
|
claimTxHex: e.claimTxHex,
|
|
1672
1672
|
assertTxHex: e.assertTxHex,
|
|
1673
1673
|
path: "depositor_graph"
|
|
1674
1674
|
});
|
|
1675
1675
|
if (r.getId() !== t)
|
|
1676
|
-
throw new
|
|
1676
|
+
throw new w(
|
|
1677
1677
|
`Presign pegin_tx hashes to ${r.getId()}, expected ${t}`
|
|
1678
1678
|
);
|
|
1679
|
-
|
|
1679
|
+
as(o, t), Oe(s, o.getId(), "depositor_graph");
|
|
1680
1680
|
const n = (a) => new Uint8Array(a.toBuffer());
|
|
1681
|
-
return
|
|
1681
|
+
return Xt({
|
|
1682
1682
|
peginTx: n(r),
|
|
1683
1683
|
claimTx: n(o),
|
|
1684
1684
|
assertTx: n(s),
|
|
1685
|
-
payoutTx: n(
|
|
1685
|
+
payoutTx: n(L(e.payoutTxHex, "payout_tx")),
|
|
1686
1686
|
challengers: e.challengers.map((a) => ({
|
|
1687
1687
|
pubkey: _(a.challenger_pubkey),
|
|
1688
|
-
nopayoutTx: n(
|
|
1688
|
+
nopayoutTx: n(L(a.nopayout_tx.tx_hex, "nopayout_tx")),
|
|
1689
1689
|
outputLabelHashes: a.output_label_hashes.map(
|
|
1690
1690
|
(i) => P(i).toLowerCase()
|
|
1691
1691
|
)
|
|
1692
1692
|
}))
|
|
1693
1693
|
});
|
|
1694
1694
|
}
|
|
1695
|
-
function
|
|
1696
|
-
const t = (o) => ot(
|
|
1697
|
-
|
|
1695
|
+
function cs(e) {
|
|
1696
|
+
const t = (o) => ot(I($(e, o, "graph"), o).tx, o), r = I(
|
|
1697
|
+
$(e, "challenger_subgraphs", "graph"),
|
|
1698
1698
|
"challenger_subgraphs"
|
|
1699
1699
|
);
|
|
1700
|
-
return
|
|
1700
|
+
return Xt({
|
|
1701
1701
|
peginTx: t("pegin_tx"),
|
|
1702
1702
|
claimTx: t("claim_tx"),
|
|
1703
1703
|
assertTx: t("assert_tx"),
|
|
1704
1704
|
payoutTx: t("payout_tx"),
|
|
1705
1705
|
challengers: Object.entries(r).map(([o, s]) => {
|
|
1706
|
-
const n = `challenger_subgraphs[${o}]`, a =
|
|
1706
|
+
const n = `challenger_subgraphs[${o}]`, a = I(s, n);
|
|
1707
1707
|
return {
|
|
1708
1708
|
pubkey: o,
|
|
1709
1709
|
nopayoutTx: ot(
|
|
1710
|
-
|
|
1710
|
+
I($(a, "nopayout_tx", n), `${n}.nopayout_tx`).tx,
|
|
1711
1711
|
`${n}.nopayout_tx`
|
|
1712
1712
|
),
|
|
1713
1713
|
outputLabelHashes: te(
|
|
1714
|
-
|
|
1714
|
+
$(a, "output_label_hashes", n),
|
|
1715
1715
|
`${n}.output_label_hashes`
|
|
1716
1716
|
).map(
|
|
1717
|
-
(i, u) =>
|
|
1717
|
+
(i, u) => pe(i, `${n}.output_label_hashes[${u}]`)
|
|
1718
1718
|
)
|
|
1719
1719
|
};
|
|
1720
1720
|
})
|
|
1721
1721
|
});
|
|
1722
1722
|
}
|
|
1723
|
-
function
|
|
1724
|
-
const t =
|
|
1725
|
-
|
|
1723
|
+
function ls(e) {
|
|
1724
|
+
const t = I(
|
|
1725
|
+
$(e, "challenger_pubkeys", "graph"),
|
|
1726
1726
|
"challenger_pubkeys"
|
|
1727
1727
|
), r = /* @__PURE__ */ new Set();
|
|
1728
1728
|
for (const o of ["local", "universal"])
|
|
1729
1729
|
te(
|
|
1730
|
-
|
|
1730
|
+
$(t, o, "challenger_pubkeys"),
|
|
1731
1731
|
`challenger_pubkeys.${o}`
|
|
1732
1732
|
).forEach((s, n) => {
|
|
1733
|
-
const a =
|
|
1733
|
+
const a = pe(s, `challenger_pubkeys.${o}[${n}]`);
|
|
1734
1734
|
if (r.has(a))
|
|
1735
|
-
throw new
|
|
1735
|
+
throw new w(
|
|
1736
1736
|
`Graph declares challenger ${a} more than once`
|
|
1737
1737
|
);
|
|
1738
1738
|
r.add(a);
|
|
1739
1739
|
});
|
|
1740
1740
|
return r;
|
|
1741
1741
|
}
|
|
1742
|
-
function
|
|
1743
|
-
const r =
|
|
1742
|
+
function wn(e, t) {
|
|
1743
|
+
const r = cs(e);
|
|
1744
1744
|
if (r !== t)
|
|
1745
|
-
throw new
|
|
1745
|
+
throw new w(
|
|
1746
1746
|
`Graph fingerprint ${r} does not match the presign fingerprint ${t}`
|
|
1747
1747
|
);
|
|
1748
1748
|
const o = Object.keys(
|
|
1749
|
-
|
|
1750
|
-
), s =
|
|
1749
|
+
I(e.challenger_subgraphs, "challenger_subgraphs")
|
|
1750
|
+
), s = ls(e);
|
|
1751
1751
|
if (o.length !== s.size || o.some((n) => !s.has(n)))
|
|
1752
|
-
throw new
|
|
1752
|
+
throw new w(
|
|
1753
1753
|
`Graph challenger_subgraphs keys ${o.join(", ")} do not match challenger_pubkeys ${[...s].join(", ")}`
|
|
1754
1754
|
);
|
|
1755
1755
|
}
|
|
1756
|
-
const
|
|
1756
|
+
const ds = 1;
|
|
1757
1757
|
function ps(e, t, r) {
|
|
1758
1758
|
const o = r.map(
|
|
1759
|
-
(
|
|
1760
|
-
), s = t.filter((
|
|
1759
|
+
(p) => P(p).toLowerCase()
|
|
1760
|
+
), s = t.filter((p) => o.includes(p));
|
|
1761
1761
|
if (s.length > 0)
|
|
1762
1762
|
throw new Error(
|
|
1763
1763
|
`Cannot validate challenger set: vault keepers and universal challengers overlap (${s.join(", ")})`
|
|
1764
1764
|
);
|
|
1765
1765
|
const n = [...t, ...o], a = e.map(
|
|
1766
|
-
(
|
|
1766
|
+
(p) => P(p.challenger_pubkey).toLowerCase()
|
|
1767
1767
|
), i = new Set(a);
|
|
1768
1768
|
if (i.size !== a.length)
|
|
1769
1769
|
throw new Error(
|
|
1770
1770
|
"Depositor graph contains duplicate challenger entries in challenger_presign_data"
|
|
1771
1771
|
);
|
|
1772
|
-
const u = new Set(n), l = n.filter((
|
|
1772
|
+
const u = new Set(n), l = n.filter((p) => !i.has(p)), c = a.filter((p) => !u.has(p));
|
|
1773
1773
|
if (l.length > 0 || c.length > 0)
|
|
1774
1774
|
throw new Error(
|
|
1775
1775
|
"Depositor graph challenger set does not match expected (local ∪ universal)" + (l.length > 0 ? ` (missing: ${l.join(", ")})` : "") + (c.length > 0 ? ` (unexpected: ${c.join(", ")})` : "")
|
|
1776
1776
|
);
|
|
1777
|
-
return
|
|
1777
|
+
return ir(n);
|
|
1778
1778
|
}
|
|
1779
|
-
function
|
|
1780
|
-
const r =
|
|
1779
|
+
function hs(e, t) {
|
|
1780
|
+
const r = Br + Ir * t + Vr;
|
|
1781
1781
|
if (e.outs.length !== r)
|
|
1782
1782
|
throw new Error(
|
|
1783
1783
|
`Assert must have ${r} outputs for ${t} challengers, got ${e.outs.length}`
|
|
1784
1784
|
);
|
|
1785
1785
|
}
|
|
1786
|
-
async function
|
|
1787
|
-
const r =
|
|
1786
|
+
async function zt(e, t) {
|
|
1787
|
+
const r = xt({
|
|
1788
1788
|
claimerBtcPubkey: t.depositorBtcPubkey,
|
|
1789
1789
|
depositorBtcPubkey: t.depositorBtcPubkey,
|
|
1790
1790
|
vaultProviderBtcPubkey: t.vaultProviderBtcPubkey,
|
|
@@ -1796,12 +1796,12 @@ async function Xt(e, t) {
|
|
|
1796
1796
|
), s = P(t.depositorBtcPubkey), n = S.fromHex(
|
|
1797
1797
|
P(e.assert_tx.tx_hex)
|
|
1798
1798
|
);
|
|
1799
|
-
|
|
1799
|
+
hs(n, o.length);
|
|
1800
1800
|
const a = [];
|
|
1801
1801
|
for (const i of e.challenger_presign_data) {
|
|
1802
1802
|
const u = P(i.challenger_pubkey), l = o.indexOf(
|
|
1803
1803
|
u.toLowerCase()
|
|
1804
|
-
), c = await
|
|
1804
|
+
), c = await gs({
|
|
1805
1805
|
challenger: i,
|
|
1806
1806
|
challengerPubkey: u,
|
|
1807
1807
|
challengerIndex: l,
|
|
@@ -1814,7 +1814,7 @@ async function Xt(e, t) {
|
|
|
1814
1814
|
}
|
|
1815
1815
|
return { localChallengers: r, noPayouts: a };
|
|
1816
1816
|
}
|
|
1817
|
-
async function
|
|
1817
|
+
async function gs(e) {
|
|
1818
1818
|
const {
|
|
1819
1819
|
challenger: t,
|
|
1820
1820
|
challengerPubkey: r,
|
|
@@ -1824,7 +1824,7 @@ async function hs(e) {
|
|
|
1824
1824
|
assertTx: a,
|
|
1825
1825
|
ctx: i
|
|
1826
1826
|
} = e;
|
|
1827
|
-
|
|
1827
|
+
Wr(
|
|
1828
1828
|
t.nopayout_tx.tx_hex,
|
|
1829
1829
|
r,
|
|
1830
1830
|
i.network
|
|
@@ -1835,7 +1835,7 @@ async function hs(e) {
|
|
|
1835
1835
|
P(t.challenge_assert_x_tx.tx_hex)
|
|
1836
1836
|
), c = S.fromHex(
|
|
1837
1837
|
P(t.challenge_assert_y_tx.tx_hex)
|
|
1838
|
-
),
|
|
1838
|
+
), p = await wr({
|
|
1839
1839
|
txGraphVersion: i.vaultCoreVersion,
|
|
1840
1840
|
claimer: n,
|
|
1841
1841
|
challenger: r,
|
|
@@ -1849,38 +1849,38 @@ async function hs(e) {
|
|
|
1849
1849
|
["X", l],
|
|
1850
1850
|
["Y", c]
|
|
1851
1851
|
])
|
|
1852
|
-
|
|
1852
|
+
Yr({
|
|
1853
1853
|
challengeAssertTx: h,
|
|
1854
1854
|
assertTx: a,
|
|
1855
1855
|
half: g,
|
|
1856
1856
|
challengerIndex: o,
|
|
1857
1857
|
challengerCount: s,
|
|
1858
1858
|
challengerPubkey: r,
|
|
1859
|
-
outputConnectorScriptPubKey:
|
|
1859
|
+
outputConnectorScriptPubKey: p
|
|
1860
1860
|
});
|
|
1861
|
-
const
|
|
1862
|
-
a.outs[
|
|
1861
|
+
const d = [
|
|
1862
|
+
a.outs[X],
|
|
1863
1863
|
l.outs[Xe],
|
|
1864
1864
|
c.outs[Xe]
|
|
1865
1865
|
];
|
|
1866
|
-
return
|
|
1866
|
+
return Qr({
|
|
1867
1867
|
noPayoutTx: u,
|
|
1868
1868
|
assertTxid: a.getId(),
|
|
1869
1869
|
challengeAssertXTxid: l.getId(),
|
|
1870
1870
|
challengeAssertYTxid: c.getId(),
|
|
1871
1871
|
timelockChallengeAssert: i.timelockChallengeAssert,
|
|
1872
1872
|
prevoutValues: [
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1873
|
+
d[0].value,
|
|
1874
|
+
d[1].value,
|
|
1875
|
+
d[2].value
|
|
1876
1876
|
]
|
|
1877
|
-
}),
|
|
1878
|
-
script_pubkey:
|
|
1877
|
+
}), d.map((g) => ({
|
|
1878
|
+
script_pubkey: vt(new Uint8Array(g.script)),
|
|
1879
1879
|
value: g.value
|
|
1880
1880
|
}));
|
|
1881
1881
|
}
|
|
1882
|
-
async function
|
|
1883
|
-
const o = [], s = [], n = [], { localChallengers: a, noPayouts: i } = await
|
|
1882
|
+
async function fs(e, t, r) {
|
|
1883
|
+
const o = [], s = [], n = [], { localChallengers: a, noPayouts: i } = await zt(e, r), u = await Hr({
|
|
1884
1884
|
vaultCoreVersion: r.vaultCoreVersion,
|
|
1885
1885
|
vkClaimerPayoutScriptPubKeys: r.vkClaimerPayoutScriptPubKeys,
|
|
1886
1886
|
vpCommissionScriptPubKey: r.vpCommissionScriptPubKey,
|
|
@@ -1896,7 +1896,7 @@ async function gs(e, t, r) {
|
|
|
1896
1896
|
network: r.network,
|
|
1897
1897
|
claimerBtcPubkey: r.depositorBtcPubkey,
|
|
1898
1898
|
registeredPayoutScriptPubKey: r.registeredPayoutScriptPubKey,
|
|
1899
|
-
commissionBps:
|
|
1899
|
+
commissionBps: ds,
|
|
1900
1900
|
protocolFeeRate: r.protocolFeeRate,
|
|
1901
1901
|
councilMembers: r.councilMembers,
|
|
1902
1902
|
councilQuorum: r.councilQuorum
|
|
@@ -1908,11 +1908,11 @@ async function gs(e, t, r) {
|
|
|
1908
1908
|
)
|
|
1909
1909
|
);
|
|
1910
1910
|
const l = P(r.depositorBtcPubkey);
|
|
1911
|
-
for (const { challenger: c, challengerPubkey:
|
|
1912
|
-
const g = o.length, h = await
|
|
1911
|
+
for (const { challenger: c, challengerPubkey: p, prevouts: d } of i) {
|
|
1912
|
+
const g = o.length, h = await jr({
|
|
1913
1913
|
noPayoutTxHex: c.nopayout_tx.tx_hex,
|
|
1914
|
-
challengerPubkey:
|
|
1915
|
-
prevouts:
|
|
1914
|
+
challengerPubkey: p,
|
|
1915
|
+
prevouts: d,
|
|
1916
1916
|
connectorParams: {
|
|
1917
1917
|
txGraphVersion: r.vaultCoreVersion,
|
|
1918
1918
|
claimer: l,
|
|
@@ -1929,13 +1929,13 @@ async function gs(e, t, r) {
|
|
|
1929
1929
|
Ge
|
|
1930
1930
|
)
|
|
1931
1931
|
), n.push({
|
|
1932
|
-
challengerPubkey:
|
|
1932
|
+
challengerPubkey: p,
|
|
1933
1933
|
noPayoutIdx: g
|
|
1934
1934
|
});
|
|
1935
1935
|
}
|
|
1936
1936
|
return { psbtHexes: o, signOptions: s, challengerEntries: n };
|
|
1937
1937
|
}
|
|
1938
|
-
function
|
|
1938
|
+
function ys(e, t, r) {
|
|
1939
1939
|
ae(e[0]);
|
|
1940
1940
|
const s = ue(
|
|
1941
1941
|
e[0].returnedPsbtHex,
|
|
@@ -1970,54 +1970,54 @@ function fs(e, t, r) {
|
|
|
1970
1970
|
per_challenger: n
|
|
1971
1971
|
};
|
|
1972
1972
|
}
|
|
1973
|
-
async function
|
|
1973
|
+
async function vs(e) {
|
|
1974
1974
|
const { depositorGraph: t, btcWallet: r, signingContext: o } = e;
|
|
1975
|
-
|
|
1975
|
+
is({
|
|
1976
1976
|
peginTxHex: o.peginTxHex,
|
|
1977
1977
|
claimTxHex: t.claim_tx.tx_hex,
|
|
1978
1978
|
assertTxHex: t.assert_tx.tx_hex,
|
|
1979
1979
|
path: "depositor_graph"
|
|
1980
1980
|
});
|
|
1981
|
-
const s = await r.getPublicKeyHex(), { depositorPubkey: n } =
|
|
1981
|
+
const s = await r.getPublicKeyHex(), { depositorPubkey: n } = nr(
|
|
1982
1982
|
s,
|
|
1983
1983
|
P(o.depositorBtcPubkey)
|
|
1984
|
-
), { psbtHexes: a, signOptions: i, challengerEntries: u } = await
|
|
1984
|
+
), { psbtHexes: a, signOptions: i, challengerEntries: u } = await fs(
|
|
1985
1985
|
t,
|
|
1986
1986
|
s,
|
|
1987
1987
|
o
|
|
1988
|
-
), l = await
|
|
1988
|
+
), l = await mt(
|
|
1989
1989
|
r,
|
|
1990
1990
|
a,
|
|
1991
1991
|
i
|
|
1992
|
-
), c = a.map((
|
|
1993
|
-
requestedPsbtHex:
|
|
1994
|
-
returnedPsbtHex: l[
|
|
1992
|
+
), c = a.map((p, d) => ({
|
|
1993
|
+
requestedPsbtHex: p,
|
|
1994
|
+
returnedPsbtHex: l[d]
|
|
1995
1995
|
}));
|
|
1996
|
-
return
|
|
1996
|
+
return ys(
|
|
1997
1997
|
c,
|
|
1998
1998
|
u,
|
|
1999
1999
|
n
|
|
2000
2000
|
);
|
|
2001
2001
|
}
|
|
2002
|
-
const
|
|
2003
|
-
async function
|
|
2002
|
+
const Ps = 1e4, U = 10;
|
|
2003
|
+
async function jt(e) {
|
|
2004
2004
|
const {
|
|
2005
2005
|
statusReader: t,
|
|
2006
2006
|
vaultId: r,
|
|
2007
2007
|
peginTxid: o,
|
|
2008
2008
|
targetStatuses: s,
|
|
2009
2009
|
timeoutMs: n,
|
|
2010
|
-
pollIntervalMs: a =
|
|
2010
|
+
pollIntervalMs: a = Ps,
|
|
2011
2011
|
signal: i
|
|
2012
2012
|
} = e, u = Date.now();
|
|
2013
2013
|
for (; ; ) {
|
|
2014
2014
|
if (i != null && i.aborted)
|
|
2015
2015
|
throw new Error(
|
|
2016
|
-
`Polling aborted for vault ${r.slice(0,
|
|
2016
|
+
`Polling aborted for vault ${r.slice(0, U)}… (target: ${[...s].join(", ")})`
|
|
2017
2017
|
);
|
|
2018
2018
|
if (Date.now() - u >= n)
|
|
2019
2019
|
throw new Error(
|
|
2020
|
-
`Polling timeout after ${n}ms for vault ${r.slice(0,
|
|
2020
|
+
`Polling timeout after ${n}ms for vault ${r.slice(0, U)}… (target: ${[...s].join(", ")})`
|
|
2021
2021
|
);
|
|
2022
2022
|
try {
|
|
2023
2023
|
const l = await t.getPeginStatusByVaultId(
|
|
@@ -2026,57 +2026,57 @@ async function zt(e) {
|
|
|
2026
2026
|
);
|
|
2027
2027
|
if (je(l.vault_id) !== je(r))
|
|
2028
2028
|
throw new Error(
|
|
2029
|
-
`getPeginStatusByVaultId returned status for vault ${l.vault_id.slice(0,
|
|
2029
|
+
`getPeginStatusByVaultId returned status for vault ${l.vault_id.slice(0, U)}…, requested ${r.slice(0, U)}…`
|
|
2030
2030
|
);
|
|
2031
2031
|
if (l.pegin_txid.toLowerCase() !== o.toLowerCase())
|
|
2032
2032
|
throw new Error(
|
|
2033
2033
|
`getPeginStatusByVaultId returned status for pegin ${l.pegin_txid.slice(0, 8)}…, requested ${o.slice(0, 8)}…`
|
|
2034
2034
|
);
|
|
2035
2035
|
const c = l.status;
|
|
2036
|
-
if (s.has(c) || c ===
|
|
2036
|
+
if (s.has(c) || c === K.ACTIVATED)
|
|
2037
2037
|
return c;
|
|
2038
|
-
if (c ===
|
|
2038
|
+
if (c === K.EXPIRED || Ur.has(c))
|
|
2039
2039
|
throw new Error(
|
|
2040
|
-
`Vault ${r.slice(0,
|
|
2040
|
+
`Vault ${r.slice(0, U)}… reached terminal status "${c}" while waiting for ${[...s].join(", ")}`
|
|
2041
2041
|
);
|
|
2042
2042
|
} catch (l) {
|
|
2043
|
-
if (!(l instanceof
|
|
2043
|
+
if (!(l instanceof Fr && l.code === qr.PEGIN_NOT_FOUND))
|
|
2044
2044
|
throw l;
|
|
2045
2045
|
}
|
|
2046
2046
|
await new Promise((l, c) => {
|
|
2047
|
-
const
|
|
2048
|
-
clearTimeout(
|
|
2047
|
+
const p = () => {
|
|
2048
|
+
clearTimeout(d), c(
|
|
2049
2049
|
new Error(
|
|
2050
|
-
`Polling aborted for vault ${r.slice(0,
|
|
2050
|
+
`Polling aborted for vault ${r.slice(0, U)}… (target: ${[...s].join(", ")})`
|
|
2051
2051
|
)
|
|
2052
2052
|
);
|
|
2053
|
-
},
|
|
2054
|
-
i == null || i.removeEventListener("abort",
|
|
2053
|
+
}, d = setTimeout(() => {
|
|
2054
|
+
i == null || i.removeEventListener("abort", p), l();
|
|
2055
2055
|
}, a);
|
|
2056
|
-
i == null || i.addEventListener("abort",
|
|
2056
|
+
i == null || i.addEventListener("abort", p, { once: !0 });
|
|
2057
2057
|
});
|
|
2058
2058
|
}
|
|
2059
2059
|
}
|
|
2060
|
-
const
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
]),
|
|
2066
|
-
|
|
2067
|
-
...
|
|
2060
|
+
const ms = 1200 * 1e3, Wt = /* @__PURE__ */ new Set([
|
|
2061
|
+
K.PENDING_ACKS,
|
|
2062
|
+
K.PENDING_ACTIVATION,
|
|
2063
|
+
K.ACTIVATED_PENDING_BROADCAST,
|
|
2064
|
+
K.ACTIVATED
|
|
2065
|
+
]), bs = /* @__PURE__ */ new Set([
|
|
2066
|
+
K.PENDING_DEPOSITOR_SIGNATURES,
|
|
2067
|
+
...Wt
|
|
2068
2068
|
]);
|
|
2069
|
-
function
|
|
2069
|
+
function ws(e) {
|
|
2070
2070
|
return e.map((t) => ({
|
|
2071
2071
|
claimerPubkeyXOnly: he(t.claimer_pubkey),
|
|
2072
2072
|
payoutTxHex: t.payout_tx.tx_hex,
|
|
2073
2073
|
assertTxHex: t.assert_tx.tx_hex
|
|
2074
2074
|
}));
|
|
2075
2075
|
}
|
|
2076
|
-
function
|
|
2076
|
+
function V(e) {
|
|
2077
2077
|
return he(e).toLowerCase();
|
|
2078
2078
|
}
|
|
2079
|
-
function
|
|
2079
|
+
function xs(e, t) {
|
|
2080
2080
|
const r = (u, l, c) => {
|
|
2081
2081
|
throw new Error(
|
|
2082
2082
|
`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.`
|
|
@@ -2089,9 +2089,9 @@ function ws(e, t) {
|
|
|
2089
2089
|
];
|
|
2090
2090
|
for (const [u, l, c] of o)
|
|
2091
2091
|
l !== c && r(u, l, c);
|
|
2092
|
-
const s = (u) => u.map(
|
|
2093
|
-
const c = s(u),
|
|
2094
|
-
return c.length ===
|
|
2092
|
+
const s = (u) => u.map(V).sort(), n = (u, l) => {
|
|
2093
|
+
const c = s(u), p = s(l);
|
|
2094
|
+
return c.length === p.length && c.every((d, g) => d === p[g]);
|
|
2095
2095
|
};
|
|
2096
2096
|
n(e.vaultKeeperBtcPubkeys, t.vaultKeeperBtcPubkeys) || r(
|
|
2097
2097
|
"vaultKeeperBtcPubkeys",
|
|
@@ -2105,8 +2105,8 @@ function ws(e, t) {
|
|
|
2105
2105
|
e.universalChallengerBtcPubkeys.join(","),
|
|
2106
2106
|
t.universalChallengerBtcPubkeys.join(",")
|
|
2107
2107
|
);
|
|
2108
|
-
const a =
|
|
2109
|
-
(u) =>
|
|
2108
|
+
const a = V(t.vaultProviderBtcPubkey), i = e.vaults.map(
|
|
2109
|
+
(u) => V(u.vaultProviderBtcPubkey)
|
|
2110
2110
|
);
|
|
2111
2111
|
i.includes(a) || r(
|
|
2112
2112
|
"vaults[].vaultProviderBtcPubkey",
|
|
@@ -2114,10 +2114,10 @@ function ws(e, t) {
|
|
|
2114
2114
|
t.vaultProviderBtcPubkey
|
|
2115
2115
|
);
|
|
2116
2116
|
}
|
|
2117
|
-
function
|
|
2118
|
-
const s =
|
|
2119
|
-
|
|
2120
|
-
...r.map(
|
|
2117
|
+
function Es(e, t, r, o) {
|
|
2118
|
+
const s = V(o), n = [
|
|
2119
|
+
V(t),
|
|
2120
|
+
...r.map(V)
|
|
2121
2121
|
], a = new Set(n);
|
|
2122
2122
|
if (a.size !== n.length)
|
|
2123
2123
|
throw new Error(
|
|
@@ -2128,14 +2128,14 @@ function xs(e, t, r, o) {
|
|
|
2128
2128
|
"Cannot validate claimer set: depositor key overlaps with vault provider or vault keeper set"
|
|
2129
2129
|
);
|
|
2130
2130
|
const i = e.map(
|
|
2131
|
-
(
|
|
2131
|
+
(d) => V(d.claimer_pubkey)
|
|
2132
2132
|
);
|
|
2133
2133
|
if (new Set(i).size !== i.length)
|
|
2134
2134
|
throw new Error("Presign response contains duplicate claimer entries");
|
|
2135
|
-
const u = i.filter((
|
|
2136
|
-
if (c.length > 0 ||
|
|
2135
|
+
const u = i.filter((d) => d !== s), l = new Set(u), c = n.filter((d) => !l.has(d)), p = u.filter((d) => !a.has(d));
|
|
2136
|
+
if (c.length > 0 || p.length > 0)
|
|
2137
2137
|
throw new Error(
|
|
2138
|
-
"Presign response claimer set does not match expected (vault provider ∪ vault keepers)" + (c.length > 0 ? ` (missing: ${c.join(", ")})` : "") + (
|
|
2138
|
+
"Presign response claimer set does not match expected (vault provider ∪ vault keepers)" + (c.length > 0 ? ` (missing: ${c.join(", ")})` : "") + (p.length > 0 ? ` (unexpected: ${p.join(", ")})` : "")
|
|
2139
2139
|
);
|
|
2140
2140
|
}
|
|
2141
2141
|
function st(e, t) {
|
|
@@ -2160,8 +2160,8 @@ function st(e, t) {
|
|
|
2160
2160
|
vpCommissionScriptPubKey: t.vpCommissionScriptPubKey
|
|
2161
2161
|
};
|
|
2162
2162
|
}
|
|
2163
|
-
async function
|
|
2164
|
-
const s = new
|
|
2163
|
+
async function $s(e, t, r, o) {
|
|
2164
|
+
const s = new ur({
|
|
2165
2165
|
network: t.network,
|
|
2166
2166
|
btcWallet: e
|
|
2167
2167
|
}), n = r.length;
|
|
@@ -2188,7 +2188,7 @@ async function Es(e, t, r, o) {
|
|
|
2188
2188
|
};
|
|
2189
2189
|
return o == null || o(n, n), i;
|
|
2190
2190
|
}
|
|
2191
|
-
async function
|
|
2191
|
+
async function xn(e) {
|
|
2192
2192
|
const {
|
|
2193
2193
|
statusReader: t,
|
|
2194
2194
|
presignClient: r,
|
|
@@ -2198,22 +2198,22 @@ async function mn(e) {
|
|
|
2198
2198
|
depositorPk: a,
|
|
2199
2199
|
signingContext: i,
|
|
2200
2200
|
depositTerms: u,
|
|
2201
|
-
timeoutMs: l =
|
|
2201
|
+
timeoutMs: l = ms,
|
|
2202
2202
|
signal: c,
|
|
2203
|
-
onProgress:
|
|
2204
|
-
recordGraphFingerprint:
|
|
2205
|
-
} = e, g = await
|
|
2203
|
+
onProgress: p,
|
|
2204
|
+
recordGraphFingerprint: d
|
|
2205
|
+
} = e, g = await jt({
|
|
2206
2206
|
statusReader: t,
|
|
2207
2207
|
vaultId: s,
|
|
2208
2208
|
peginTxid: n,
|
|
2209
|
-
targetStatuses:
|
|
2209
|
+
targetStatuses: bs,
|
|
2210
2210
|
timeoutMs: l,
|
|
2211
2211
|
signal: c
|
|
2212
2212
|
});
|
|
2213
|
-
if (
|
|
2213
|
+
if (Wt.has(g))
|
|
2214
2214
|
return;
|
|
2215
|
-
c == null || c.throwIfAborted(), u !== void 0 &&
|
|
2216
|
-
const h =
|
|
2215
|
+
c == null || c.throwIfAborted(), u !== void 0 && xs(u, i);
|
|
2216
|
+
const h = Pt(o) ? o : void 0;
|
|
2217
2217
|
let y;
|
|
2218
2218
|
if (h) {
|
|
2219
2219
|
if (!u)
|
|
@@ -2229,21 +2229,21 @@ async function mn(e) {
|
|
|
2229
2229
|
},
|
|
2230
2230
|
c
|
|
2231
2231
|
);
|
|
2232
|
-
c == null || c.throwIfAborted(), f.txs.forEach((
|
|
2233
|
-
|
|
2234
|
-
claimTxHex:
|
|
2235
|
-
assertTxHex:
|
|
2232
|
+
c == null || c.throwIfAborted(), f.txs.forEach((N, se) => {
|
|
2233
|
+
ns({
|
|
2234
|
+
claimTxHex: N.claim_tx.tx_hex,
|
|
2235
|
+
assertTxHex: N.assert_tx.tx_hex,
|
|
2236
2236
|
path: `txs[${se}]`
|
|
2237
2237
|
});
|
|
2238
2238
|
});
|
|
2239
|
-
const
|
|
2239
|
+
const b = us({
|
|
2240
2240
|
peginTxid: n,
|
|
2241
2241
|
peginTxHex: i.peginTxHex,
|
|
2242
2242
|
claimTxHex: f.depositor_graph.claim_tx.tx_hex,
|
|
2243
2243
|
assertTxHex: f.depositor_graph.assert_tx.tx_hex,
|
|
2244
2244
|
payoutTxHex: f.depositor_graph.payout_tx.tx_hex,
|
|
2245
2245
|
challengers: f.depositor_graph.challenger_presign_data
|
|
2246
|
-
}),
|
|
2246
|
+
}), k = {
|
|
2247
2247
|
vaultCoreVersion: i.vaultCoreVersion,
|
|
2248
2248
|
peginTxHex: i.peginTxHex,
|
|
2249
2249
|
depositorBtcPubkey: a,
|
|
@@ -2261,50 +2261,50 @@ async function mn(e) {
|
|
|
2261
2261
|
vkClaimerPayoutScriptPubKeys: i.vkClaimerPayoutScriptPubKeys,
|
|
2262
2262
|
vpCommissionScriptPubKey: i.vpCommissionScriptPubKey
|
|
2263
2263
|
};
|
|
2264
|
-
await
|
|
2264
|
+
await zt(
|
|
2265
2265
|
f.depositor_graph,
|
|
2266
|
-
|
|
2266
|
+
k
|
|
2267
2267
|
), c == null || c.throwIfAborted();
|
|
2268
|
-
const x =
|
|
2269
|
-
|
|
2268
|
+
const x = V(a);
|
|
2269
|
+
Es(
|
|
2270
2270
|
f.txs,
|
|
2271
2271
|
i.vaultProviderBtcPubkey,
|
|
2272
2272
|
i.vaultKeeperBtcPubkeys,
|
|
2273
2273
|
a
|
|
2274
2274
|
);
|
|
2275
2275
|
const v = f.txs.filter(
|
|
2276
|
-
(
|
|
2277
|
-
), E =
|
|
2276
|
+
(N) => V(N.claimer_pubkey) !== x
|
|
2277
|
+
), E = ws(v);
|
|
2278
2278
|
h && y && (typeof h.validateDepositTerms == "function" && await h.validateDepositTerms(y), await h.approveDepositTerms(y)), c == null || c.throwIfAborted();
|
|
2279
|
-
const
|
|
2279
|
+
const C = await $s(
|
|
2280
2280
|
o,
|
|
2281
2281
|
i,
|
|
2282
2282
|
E,
|
|
2283
|
-
|
|
2283
|
+
p
|
|
2284
2284
|
);
|
|
2285
2285
|
c == null || c.throwIfAborted();
|
|
2286
|
-
const
|
|
2286
|
+
const m = await vs({
|
|
2287
2287
|
depositorGraph: f.depositor_graph,
|
|
2288
2288
|
btcWallet: o,
|
|
2289
|
-
signingContext:
|
|
2289
|
+
signingContext: k
|
|
2290
2290
|
});
|
|
2291
|
-
c == null || c.throwIfAborted(), await
|
|
2292
|
-
const
|
|
2293
|
-
|
|
2291
|
+
c == null || c.throwIfAborted(), await d(b), c == null || c.throwIfAborted();
|
|
2292
|
+
const W = { ...C };
|
|
2293
|
+
W[P(a)] = m.payout_signatures, await r.submitDepositorPresignatures(
|
|
2294
2294
|
{
|
|
2295
2295
|
pegin_txid: n,
|
|
2296
2296
|
depositor_pk: a,
|
|
2297
|
-
signatures:
|
|
2298
|
-
depositor_claimer_presignatures:
|
|
2297
|
+
signatures: W,
|
|
2298
|
+
depositor_claimer_presignatures: m
|
|
2299
2299
|
},
|
|
2300
2300
|
c
|
|
2301
2301
|
);
|
|
2302
2302
|
}
|
|
2303
|
-
const ks = 300 * 1e3,
|
|
2304
|
-
|
|
2305
|
-
...
|
|
2303
|
+
const ks = 300 * 1e3, Cs = /* @__PURE__ */ new Set([
|
|
2304
|
+
K.PENDING_DEPOSITOR_WOTS_PK,
|
|
2305
|
+
...Tt
|
|
2306
2306
|
]);
|
|
2307
|
-
async function
|
|
2307
|
+
async function En(e) {
|
|
2308
2308
|
const {
|
|
2309
2309
|
statusReader: t,
|
|
2310
2310
|
wotsSubmitter: r,
|
|
@@ -2316,15 +2316,15 @@ async function bn(e) {
|
|
|
2316
2316
|
signal: u
|
|
2317
2317
|
} = e;
|
|
2318
2318
|
u == null || u.throwIfAborted();
|
|
2319
|
-
const l = await
|
|
2319
|
+
const l = await jt({
|
|
2320
2320
|
statusReader: t,
|
|
2321
2321
|
vaultId: o,
|
|
2322
2322
|
peginTxid: s,
|
|
2323
|
-
targetStatuses:
|
|
2323
|
+
targetStatuses: Cs,
|
|
2324
2324
|
timeoutMs: i,
|
|
2325
2325
|
signal: u
|
|
2326
2326
|
});
|
|
2327
|
-
|
|
2327
|
+
Tt.has(l) || (u == null || u.throwIfAborted(), await r.submitDepositorWotsKey(
|
|
2328
2328
|
{
|
|
2329
2329
|
pegin_txid: s,
|
|
2330
2330
|
depositor_pk: n,
|
|
@@ -2333,10 +2333,10 @@ async function bn(e) {
|
|
|
2333
2333
|
u
|
|
2334
2334
|
));
|
|
2335
2335
|
}
|
|
2336
|
-
function
|
|
2336
|
+
function ke(e) {
|
|
2337
2337
|
return e.registration || e.operation;
|
|
2338
2338
|
}
|
|
2339
|
-
function
|
|
2339
|
+
function Ts(e, t, r) {
|
|
2340
2340
|
const o = _(e);
|
|
2341
2341
|
return {
|
|
2342
2342
|
registration: o === _(t),
|
|
@@ -2356,7 +2356,7 @@ function Ce(e) {
|
|
|
2356
2356
|
function it(e, t) {
|
|
2357
2357
|
return e.length === t.length && e.every((r, o) => r === t[o]);
|
|
2358
2358
|
}
|
|
2359
|
-
async function
|
|
2359
|
+
async function $n(e) {
|
|
2360
2360
|
const {
|
|
2361
2361
|
vaultProviderEthAddress: t,
|
|
2362
2362
|
hintBtcPubkey: r,
|
|
@@ -2380,11 +2380,11 @@ class Se extends Error {
|
|
|
2380
2380
|
super(t), this.name = "ApplicationEntryPointMismatchError";
|
|
2381
2381
|
}
|
|
2382
2382
|
}
|
|
2383
|
-
function
|
|
2383
|
+
function kn(e) {
|
|
2384
2384
|
return e instanceof Se || e instanceof Error && e.name === "ApplicationEntryPointMismatchError";
|
|
2385
2385
|
}
|
|
2386
2386
|
const at = (e) => e.map(_).sort();
|
|
2387
|
-
async function
|
|
2387
|
+
async function Cn(e) {
|
|
2388
2388
|
const {
|
|
2389
2389
|
vaultRegistryReader: t,
|
|
2390
2390
|
vaultKeeperReader: r,
|
|
@@ -2396,8 +2396,8 @@ async function En(e) {
|
|
|
2396
2396
|
expectedUniversalChallengerBtcPubkeys: u,
|
|
2397
2397
|
operationKeyReader: l,
|
|
2398
2398
|
onIndexerServingOperationKeys: c,
|
|
2399
|
-
onIndexerHintsInconsistent:
|
|
2400
|
-
blockNumber:
|
|
2399
|
+
onIndexerHintsInconsistent: p,
|
|
2400
|
+
blockNumber: d
|
|
2401
2401
|
} = e, [
|
|
2402
2402
|
g,
|
|
2403
2403
|
h,
|
|
@@ -2406,49 +2406,49 @@ async function En(e) {
|
|
|
2406
2406
|
] = await Promise.all([
|
|
2407
2407
|
t.getVaultProviderApplication(
|
|
2408
2408
|
s,
|
|
2409
|
-
|
|
2409
|
+
d
|
|
2410
2410
|
),
|
|
2411
2411
|
t.getVaultProviderGenesisBtcPubKey(
|
|
2412
2412
|
s,
|
|
2413
|
-
|
|
2413
|
+
d
|
|
2414
2414
|
),
|
|
2415
|
-
o.getLatestUniversalChallengersVersion(
|
|
2416
|
-
o.getCurrentUcKeyEpoch(
|
|
2415
|
+
o.getLatestUniversalChallengersVersion(d),
|
|
2416
|
+
o.getCurrentUcKeyEpoch(d)
|
|
2417
2417
|
]);
|
|
2418
|
-
if (!
|
|
2418
|
+
if (!Lr(n, { strict: !1 }))
|
|
2419
2419
|
throw new Se(
|
|
2420
2420
|
`The application entry point this deposit was prepared for is not a valid address: ${n}`
|
|
2421
2421
|
);
|
|
2422
|
-
if (!
|
|
2422
|
+
if (!Mr(g, n))
|
|
2423
2423
|
throw new Se(
|
|
2424
2424
|
`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.`
|
|
2425
2425
|
);
|
|
2426
|
-
const [
|
|
2426
|
+
const [b, k] = await Promise.all(
|
|
2427
2427
|
[
|
|
2428
2428
|
r.getCurrentVaultKeepersVersion(
|
|
2429
2429
|
g,
|
|
2430
|
-
|
|
2430
|
+
d
|
|
2431
2431
|
),
|
|
2432
2432
|
r.getCurrentAppKeeperKeyEpoch(
|
|
2433
2433
|
g,
|
|
2434
|
-
|
|
2434
|
+
d
|
|
2435
2435
|
)
|
|
2436
2436
|
]
|
|
2437
2437
|
), [x, v] = await Promise.all([
|
|
2438
2438
|
r.getVaultKeepersByVersion(
|
|
2439
2439
|
g,
|
|
2440
|
-
|
|
2441
|
-
|
|
2440
|
+
b,
|
|
2441
|
+
d
|
|
2442
2442
|
),
|
|
2443
2443
|
o.getUniversalChallengersByVersion(
|
|
2444
2444
|
y,
|
|
2445
|
-
|
|
2445
|
+
d
|
|
2446
2446
|
)
|
|
2447
2447
|
]), E = {
|
|
2448
2448
|
vaultProvider: _(h),
|
|
2449
|
-
vaultKeepers: at(x.map((
|
|
2450
|
-
universalChallengers: at(v.map((
|
|
2451
|
-
},
|
|
2449
|
+
vaultKeepers: at(x.map((T) => T.btcPubKey)),
|
|
2450
|
+
universalChallengers: at(v.map((T) => T.btcPubKey))
|
|
2451
|
+
}, C = await zo({
|
|
2452
2452
|
operationKeyReader: l,
|
|
2453
2453
|
query: {
|
|
2454
2454
|
vaultProviderEthAddress: s,
|
|
@@ -2457,61 +2457,61 @@ async function En(e) {
|
|
|
2457
2457
|
vaultKeepers: x,
|
|
2458
2458
|
universalChallengers: v
|
|
2459
2459
|
},
|
|
2460
|
-
blockNumber:
|
|
2461
|
-
}),
|
|
2462
|
-
vaultProvider:
|
|
2463
|
-
vaultKeepers: [...
|
|
2460
|
+
blockNumber: d
|
|
2461
|
+
}), m = {
|
|
2462
|
+
vaultProvider: C.vaultProvider.operationBtcPubkey,
|
|
2463
|
+
vaultKeepers: [...C.vaultKeeperOperationKeysSorted],
|
|
2464
2464
|
universalChallengers: [
|
|
2465
|
-
...
|
|
2465
|
+
...C.universalChallengerOperationKeysSorted
|
|
2466
2466
|
]
|
|
2467
|
-
},
|
|
2467
|
+
}, W = Ts(
|
|
2468
2468
|
a,
|
|
2469
2469
|
E.vaultProvider,
|
|
2470
|
-
|
|
2471
|
-
),
|
|
2470
|
+
m.vaultProvider
|
|
2471
|
+
), N = nt(
|
|
2472
2472
|
i,
|
|
2473
2473
|
E.vaultKeepers,
|
|
2474
|
-
|
|
2474
|
+
m.vaultKeepers
|
|
2475
2475
|
), se = nt(
|
|
2476
2476
|
u,
|
|
2477
2477
|
E.universalChallengers,
|
|
2478
|
-
|
|
2478
|
+
m.universalChallengers
|
|
2479
2479
|
);
|
|
2480
|
-
if (
|
|
2480
|
+
if (!ke(W))
|
|
2481
2481
|
throw new Error(
|
|
2482
2482
|
`Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${s}. Refresh and try again.`
|
|
2483
2483
|
);
|
|
2484
|
-
if (
|
|
2484
|
+
if (!ke(N))
|
|
2485
2485
|
throw new Error(
|
|
2486
|
-
`Vault keeper BTC pubkeys (v${
|
|
2486
|
+
`Vault keeper BTC pubkeys (v${b}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
|
|
2487
2487
|
);
|
|
2488
|
-
if (
|
|
2488
|
+
if (!ke(se))
|
|
2489
2489
|
throw new Error(
|
|
2490
2490
|
`Universal challenger BTC pubkeys (v${y}) indexer set does not match ProtocolParams on-chain set. Refresh and try again.`
|
|
2491
2491
|
);
|
|
2492
|
-
const Ne = [
|
|
2493
|
-
if (
|
|
2494
|
-
const
|
|
2495
|
-
throw
|
|
2492
|
+
const Ne = [W, N, se], tr = Ne.some((T) => T.registration && !T.operation), De = Ne.some((T) => T.operation && !T.registration);
|
|
2493
|
+
if (tr && De) {
|
|
2494
|
+
const T = `Indexer participant hints are internally inconsistent for vault provider ${s}: some roles match the registration keys while others match the rotated operation keys.`;
|
|
2495
|
+
throw p == null || p(T), new Error(`${T} Refresh and try again.`);
|
|
2496
2496
|
}
|
|
2497
2497
|
return De && (c == null || c(
|
|
2498
2498
|
`Indexer is serving rotated operation keys for vault provider ${s}`
|
|
2499
2499
|
)), {
|
|
2500
|
-
vaultProviderBtcPubkeyXOnly:
|
|
2501
|
-
vaultKeeperBtcPubkeysSorted:
|
|
2502
|
-
universalChallengerBtcPubkeysSorted:
|
|
2503
|
-
expectedAppVaultKeepersVersion:
|
|
2500
|
+
vaultProviderBtcPubkeyXOnly: m.vaultProvider,
|
|
2501
|
+
vaultKeeperBtcPubkeysSorted: m.vaultKeepers,
|
|
2502
|
+
universalChallengerBtcPubkeysSorted: m.universalChallengers,
|
|
2503
|
+
expectedAppVaultKeepersVersion: b,
|
|
2504
2504
|
expectedUniversalChallengersVersion: y,
|
|
2505
|
-
appKeeperKeyEpoch:
|
|
2505
|
+
appKeeperKeyEpoch: k,
|
|
2506
2506
|
ucKeyEpoch: f,
|
|
2507
2507
|
registrationKeys: E,
|
|
2508
|
-
participantKeys:
|
|
2508
|
+
participantKeys: C
|
|
2509
2509
|
};
|
|
2510
2510
|
}
|
|
2511
|
-
function
|
|
2511
|
+
function _s(e) {
|
|
2512
2512
|
return /^[0-9a-fA-F]{64}$/.test(e);
|
|
2513
2513
|
}
|
|
2514
|
-
function
|
|
2514
|
+
function Tn(e) {
|
|
2515
2515
|
const {
|
|
2516
2516
|
amountSats: t,
|
|
2517
2517
|
minDeposit: r,
|
|
@@ -2522,29 +2522,29 @@ function kn(e) {
|
|
|
2522
2522
|
} = e;
|
|
2523
2523
|
return !(t <= 0n || t < r || o && o > 0n && t > o || n == null || a == null || t + n + a > s);
|
|
2524
2524
|
}
|
|
2525
|
-
function
|
|
2525
|
+
function _n(e, t, r) {
|
|
2526
2526
|
return e <= 0n ? {
|
|
2527
2527
|
valid: !1,
|
|
2528
2528
|
error: "Deposit amount must be greater than zero"
|
|
2529
2529
|
} : e < t ? {
|
|
2530
2530
|
valid: !1,
|
|
2531
|
-
error: `Minimum deposit is ${
|
|
2531
|
+
error: `Minimum deposit is ${D(t)} BTC`
|
|
2532
2532
|
} : r && r > 0n && e > r ? {
|
|
2533
2533
|
valid: !1,
|
|
2534
|
-
error: `Maximum deposit is ${
|
|
2534
|
+
error: `Maximum deposit is ${D(r)} BTC`
|
|
2535
2535
|
} : { valid: !0 };
|
|
2536
2536
|
}
|
|
2537
|
-
function
|
|
2537
|
+
function Sn(e) {
|
|
2538
2538
|
const { amount: t, effectiveRemaining: r } = e;
|
|
2539
2539
|
return r === null ? { valid: !0 } : r === 0n ? {
|
|
2540
2540
|
valid: !1,
|
|
2541
2541
|
error: "Supply cap reached — deposits temporarily paused"
|
|
2542
2542
|
} : t > r ? {
|
|
2543
2543
|
valid: !1,
|
|
2544
|
-
error: `Vault size exceeds remaining capacity (${
|
|
2544
|
+
error: `Vault size exceeds remaining capacity (${D(r)} BTC)`
|
|
2545
2545
|
} : { valid: !0 };
|
|
2546
2546
|
}
|
|
2547
|
-
function
|
|
2547
|
+
function An(e, t) {
|
|
2548
2548
|
if (!e || e.length === 0)
|
|
2549
2549
|
return {
|
|
2550
2550
|
valid: !1,
|
|
@@ -2560,7 +2560,7 @@ function Tn(e, t) {
|
|
|
2560
2560
|
error: "Invalid vault provider selected"
|
|
2561
2561
|
} : { valid: !0 };
|
|
2562
2562
|
}
|
|
2563
|
-
function
|
|
2563
|
+
function Ss(e, t, r) {
|
|
2564
2564
|
if (!e || e.length === 0)
|
|
2565
2565
|
return {
|
|
2566
2566
|
valid: !1,
|
|
@@ -2576,40 +2576,40 @@ function _s(e, t, r) {
|
|
|
2576
2576
|
if (t && s < t)
|
|
2577
2577
|
return {
|
|
2578
2578
|
valid: !1,
|
|
2579
|
-
error: `Vault ${o + 1} amount ${
|
|
2579
|
+
error: `Vault ${o + 1} amount ${D(s)} BTC is below minimum deposit ${D(t)} BTC`
|
|
2580
2580
|
};
|
|
2581
2581
|
if (r && s > r)
|
|
2582
2582
|
return {
|
|
2583
2583
|
valid: !1,
|
|
2584
|
-
error: `Vault ${o + 1} amount ${
|
|
2584
|
+
error: `Vault ${o + 1} amount ${D(s)} BTC exceeds maximum deposit ${D(r)} BTC`
|
|
2585
2585
|
};
|
|
2586
2586
|
}
|
|
2587
2587
|
return { valid: !0 };
|
|
2588
2588
|
}
|
|
2589
|
-
function
|
|
2589
|
+
function As(e) {
|
|
2590
2590
|
const t = P(e);
|
|
2591
|
-
return
|
|
2591
|
+
return _s(t) ? { valid: !0 } : {
|
|
2592
2592
|
valid: !1,
|
|
2593
2593
|
error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
|
|
2594
2594
|
};
|
|
2595
2595
|
}
|
|
2596
|
-
function
|
|
2596
|
+
function Bs(e) {
|
|
2597
2597
|
if (!e || e.length === 0)
|
|
2598
2598
|
throw new Error(
|
|
2599
2599
|
"No vault keepers available. The system requires at least one vault keeper to create a deposit."
|
|
2600
2600
|
);
|
|
2601
2601
|
}
|
|
2602
|
-
function
|
|
2602
|
+
function Is(e) {
|
|
2603
2603
|
if (!e || e.length === 0)
|
|
2604
2604
|
throw new Error(
|
|
2605
2605
|
"No universal challengers available. The system requires at least one universal challenger to create a deposit."
|
|
2606
2606
|
);
|
|
2607
2607
|
}
|
|
2608
|
-
function
|
|
2608
|
+
function Vs(e) {
|
|
2609
2609
|
if (e.length === 0)
|
|
2610
2610
|
throw new Error("No spendable UTXOs available");
|
|
2611
2611
|
}
|
|
2612
|
-
function
|
|
2612
|
+
function Bn(e) {
|
|
2613
2613
|
const {
|
|
2614
2614
|
vaultAmounts: t,
|
|
2615
2615
|
confirmedUTXOs: r,
|
|
@@ -2618,38 +2618,38 @@ function _n(e) {
|
|
|
2618
2618
|
universalChallengerBtcPubkeys: n,
|
|
2619
2619
|
minDeposit: a,
|
|
2620
2620
|
maxDeposit: i
|
|
2621
|
-
} = e, u =
|
|
2621
|
+
} = e, u = Ss(
|
|
2622
2622
|
t,
|
|
2623
2623
|
a,
|
|
2624
2624
|
i
|
|
2625
2625
|
);
|
|
2626
2626
|
if (!u.valid)
|
|
2627
2627
|
throw new Error(u.error);
|
|
2628
|
-
const l =
|
|
2628
|
+
const l = As(o);
|
|
2629
2629
|
if (!l.valid)
|
|
2630
2630
|
throw new Error(l.error);
|
|
2631
|
-
|
|
2631
|
+
Bs(s), Is(n), Vs(r);
|
|
2632
2632
|
}
|
|
2633
|
-
class
|
|
2633
|
+
class Yt extends Error {
|
|
2634
2634
|
constructor(t) {
|
|
2635
2635
|
super(t), this.name = "ParticipantKeyDriftError";
|
|
2636
2636
|
}
|
|
2637
2637
|
}
|
|
2638
|
-
function
|
|
2639
|
-
return e instanceof
|
|
2638
|
+
function In(e) {
|
|
2639
|
+
return e instanceof Yt || e instanceof Error && e.name === "ParticipantKeyDriftError";
|
|
2640
2640
|
}
|
|
2641
|
-
class
|
|
2641
|
+
class Qt extends Error {
|
|
2642
2642
|
constructor(t) {
|
|
2643
2643
|
super(t), this.name = "UnsupportedPayoutScriptError";
|
|
2644
2644
|
}
|
|
2645
2645
|
}
|
|
2646
|
-
function
|
|
2647
|
-
return e instanceof
|
|
2646
|
+
function Vn(e) {
|
|
2647
|
+
return e instanceof Qt || e instanceof Error && e.name === "UnsupportedPayoutScriptError";
|
|
2648
2648
|
}
|
|
2649
2649
|
function ut(e, t, r) {
|
|
2650
2650
|
return t.length === r.length && t.every((o, s) => o === r[s]) ? null : `${e} expected [${t.join(", ")}], got [${r.join(", ")}]`;
|
|
2651
2651
|
}
|
|
2652
|
-
async function
|
|
2652
|
+
async function Rs(e) {
|
|
2653
2653
|
const { operationKeyReader: t, query: r, epochs: o, vaultIds: s } = e, n = await t.getPayoutScriptsAtEpochs(
|
|
2654
2654
|
r,
|
|
2655
2655
|
o
|
|
@@ -2660,7 +2660,7 @@ async function Vs(e) {
|
|
|
2660
2660
|
);
|
|
2661
2661
|
const a = [], i = (u, l) => {
|
|
2662
2662
|
try {
|
|
2663
|
-
|
|
2663
|
+
Or(u, l);
|
|
2664
2664
|
} catch (c) {
|
|
2665
2665
|
a.push(
|
|
2666
2666
|
`vaults ${s.join(", ")}: ${c.message}`
|
|
@@ -2677,57 +2677,57 @@ async function Vs(e) {
|
|
|
2677
2677
|
`Vault keeper ${l.ethAddress} payout script`
|
|
2678
2678
|
);
|
|
2679
2679
|
if (a.length > 0)
|
|
2680
|
-
throw new
|
|
2680
|
+
throw new Qt(
|
|
2681
2681
|
`Aborting Pre-PegIn broadcast: an operator payout script registered for this vault is not a standard output type this app can verify (${a.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
|
|
2682
2682
|
);
|
|
2683
2683
|
}
|
|
2684
|
-
async function
|
|
2684
|
+
async function Rn(e) {
|
|
2685
2685
|
const { vaultRegistryReader: t, operationKeyReader: r, vaultIds: o, expected: s } = e, n = s.query;
|
|
2686
2686
|
if (o.length === 0) return;
|
|
2687
2687
|
const a = await t.getVaultKeyEpochsBatch(o), i = [];
|
|
2688
2688
|
for (const [l, c] of a.entries()) {
|
|
2689
|
-
const
|
|
2690
|
-
let
|
|
2689
|
+
const p = o[l];
|
|
2690
|
+
let d;
|
|
2691
2691
|
try {
|
|
2692
|
-
|
|
2692
|
+
d = await Dt({
|
|
2693
2693
|
operationKeyReader: r,
|
|
2694
2694
|
query: n,
|
|
2695
2695
|
epochs: c
|
|
2696
2696
|
});
|
|
2697
2697
|
} catch (y) {
|
|
2698
2698
|
i.push(
|
|
2699
|
-
`vault ${
|
|
2699
|
+
`vault ${p}: could not resolve participants at frozen epochs (vp=${c.vpKeyEpoch}, keeper=${c.appKeeperKeyEpoch}, uc=${c.ucKeyEpoch}): ${y.message}`
|
|
2700
2700
|
);
|
|
2701
2701
|
continue;
|
|
2702
2702
|
}
|
|
2703
|
-
|
|
2704
|
-
`vault ${
|
|
2703
|
+
d.vaultProvider.operationBtcPubkey !== s.vaultProvider.operationBtcPubkey && i.push(
|
|
2704
|
+
`vault ${p}: vault provider key expected ${s.vaultProvider.operationBtcPubkey}, got ${d.vaultProvider.operationBtcPubkey}`
|
|
2705
2705
|
);
|
|
2706
2706
|
const g = ut(
|
|
2707
|
-
`vault ${
|
|
2707
|
+
`vault ${p}: vault keeper keys`,
|
|
2708
2708
|
s.vaultKeeperOperationKeysSorted,
|
|
2709
|
-
|
|
2709
|
+
d.vaultKeeperOperationKeysSorted
|
|
2710
2710
|
);
|
|
2711
2711
|
g && i.push(g);
|
|
2712
2712
|
const h = ut(
|
|
2713
|
-
`vault ${
|
|
2713
|
+
`vault ${p}: universal challenger keys`,
|
|
2714
2714
|
s.universalChallengerOperationKeysSorted,
|
|
2715
|
-
|
|
2715
|
+
d.universalChallengerOperationKeysSorted
|
|
2716
2716
|
);
|
|
2717
2717
|
h && i.push(h);
|
|
2718
2718
|
}
|
|
2719
2719
|
if (i.length > 0)
|
|
2720
|
-
throw new
|
|
2720
|
+
throw new Yt(
|
|
2721
2721
|
`Aborting BTC broadcast: participant operation keys changed during registration (${i.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
|
|
2722
2722
|
);
|
|
2723
2723
|
const u = /* @__PURE__ */ new Map();
|
|
2724
2724
|
for (const [l, c] of a.entries()) {
|
|
2725
|
-
const
|
|
2726
|
-
|
|
2725
|
+
const p = `${c.vpKeyEpoch}:${c.appKeeperKeyEpoch}:${c.ucKeyEpoch}`, d = u.get(p);
|
|
2726
|
+
d ? d.vaultIds.push(o[l]) : u.set(p, { epochs: c, vaultIds: [o[l]] });
|
|
2727
2727
|
}
|
|
2728
2728
|
await Promise.all(
|
|
2729
2729
|
[...u.values()].map(
|
|
2730
|
-
({ epochs: l, vaultIds: c }) =>
|
|
2730
|
+
({ epochs: l, vaultIds: c }) => Rs({
|
|
2731
2731
|
operationKeyReader: r,
|
|
2732
2732
|
query: n,
|
|
2733
2733
|
epochs: l,
|
|
@@ -2736,15 +2736,15 @@ async function Bn(e) {
|
|
|
2736
2736
|
)
|
|
2737
2737
|
);
|
|
2738
2738
|
}
|
|
2739
|
-
class
|
|
2739
|
+
class Jt extends Error {
|
|
2740
2740
|
constructor(t) {
|
|
2741
2741
|
super(t), this.name = "RegisteredVaultVersionMismatchError";
|
|
2742
2742
|
}
|
|
2743
2743
|
}
|
|
2744
|
-
function
|
|
2745
|
-
return e instanceof
|
|
2744
|
+
function Kn(e) {
|
|
2745
|
+
return e instanceof Jt || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
|
|
2746
2746
|
}
|
|
2747
|
-
async function
|
|
2747
|
+
async function Hn(e) {
|
|
2748
2748
|
const {
|
|
2749
2749
|
vaultRegistryReader: t,
|
|
2750
2750
|
vaultIds: r,
|
|
@@ -2754,44 +2754,56 @@ async function Vn(e) {
|
|
|
2754
2754
|
expectedVaultCoreVersion: a
|
|
2755
2755
|
} = e, i = await t.getProtocolInfoBatch(r), u = [];
|
|
2756
2756
|
if (i.forEach((l, c) => {
|
|
2757
|
-
const
|
|
2757
|
+
const p = r[c];
|
|
2758
2758
|
l.offchainParamsVersion !== o && u.push(
|
|
2759
|
-
`vault ${
|
|
2759
|
+
`vault ${p}: offchainParams expected v${o}, got v${l.offchainParamsVersion}`
|
|
2760
2760
|
), l.appVaultKeepersVersion !== s && u.push(
|
|
2761
|
-
`vault ${
|
|
2761
|
+
`vault ${p}: appVaultKeepers expected v${s}, got v${l.appVaultKeepersVersion}`
|
|
2762
2762
|
), l.universalChallengersVersion !== n && u.push(
|
|
2763
|
-
`vault ${
|
|
2763
|
+
`vault ${p}: universalChallengers expected v${n}, got v${l.universalChallengersVersion}`
|
|
2764
2764
|
), l.vaultCoreVersion !== a && u.push(
|
|
2765
|
-
`vault ${
|
|
2765
|
+
`vault ${p}: vaultCoreVersion expected v${a} (build-time active), got v${l.vaultCoreVersion}`
|
|
2766
2766
|
);
|
|
2767
2767
|
}), u.length > 0)
|
|
2768
|
-
throw new
|
|
2768
|
+
throw new Jt(
|
|
2769
2769
|
`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.`
|
|
2770
2770
|
);
|
|
2771
2771
|
}
|
|
2772
|
-
class
|
|
2772
|
+
class Ks extends Error {
|
|
2773
2773
|
constructor(r, o) {
|
|
2774
2774
|
super(`Refund not yet mature (BIP68 not final): ${o.message}`);
|
|
2775
|
-
|
|
2776
|
-
|
|
2775
|
+
B(this, "vaultId");
|
|
2776
|
+
B(this, "cause");
|
|
2777
2777
|
this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = o;
|
|
2778
2778
|
}
|
|
2779
2779
|
}
|
|
2780
|
-
|
|
2781
|
-
|
|
2780
|
+
class ct extends Error {
|
|
2781
|
+
constructor(r, o, s, n) {
|
|
2782
|
+
super(
|
|
2783
|
+
`Refund broadcast rejected (bitcoind code ${r}): ${n.message}`
|
|
2784
|
+
);
|
|
2785
|
+
B(this, "code");
|
|
2786
|
+
B(this, "vaultId");
|
|
2787
|
+
B(this, "signedTxHex");
|
|
2788
|
+
B(this, "cause");
|
|
2789
|
+
this.name = "RefundBroadcastRejectedError", this.code = r, this.vaultId = o, this.signedTxHex = s, this.cause = n;
|
|
2790
|
+
}
|
|
2791
|
+
}
|
|
2792
|
+
const Hs = /^0x[0-9a-fA-F]{64}$/, Os = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, Zt = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, er = 160, lt = 2e3, dt = 10n, pt = 100n;
|
|
2793
|
+
function On(e) {
|
|
2782
2794
|
if (!Number.isFinite(e) || e <= 0)
|
|
2783
2795
|
throw new Error(
|
|
2784
2796
|
`feeRateSatsVb must be a positive finite number, got ${e}`
|
|
2785
2797
|
);
|
|
2786
|
-
return BigInt(Math.ceil(e *
|
|
2798
|
+
return BigInt(Math.ceil(e * er));
|
|
2787
2799
|
}
|
|
2788
|
-
const
|
|
2800
|
+
const Ns = 1, Ds = /non-BIP68-final/i, Ls = /"code"\s*:\s*-27\b/, Ms = /"code"\s*:\s*-25\b/;
|
|
2789
2801
|
function Ae(e, t) {
|
|
2790
2802
|
if (e.length !== 66)
|
|
2791
2803
|
throw new Error(
|
|
2792
2804
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
2793
2805
|
);
|
|
2794
|
-
if (!
|
|
2806
|
+
if (!Hs.test(e))
|
|
2795
2807
|
throw new Error(
|
|
2796
2808
|
`${t} must contain only hex characters after the 0x prefix`
|
|
2797
2809
|
);
|
|
@@ -2800,7 +2812,7 @@ function Te(e, t) {
|
|
|
2800
2812
|
if (!Number.isInteger(e) || e < 0)
|
|
2801
2813
|
throw new Error(`${t} must be a non-negative integer, got ${e}`);
|
|
2802
2814
|
}
|
|
2803
|
-
function
|
|
2815
|
+
function Us(e) {
|
|
2804
2816
|
if (Ae(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0)
|
|
2805
2817
|
throw new Error(
|
|
2806
2818
|
`htlcVout must be a non-negative integer, got ${e.htlcVout}`
|
|
@@ -2834,24 +2846,24 @@ function Ds(e) {
|
|
|
2834
2846
|
if (Te(e.offchainParamsVersion, "offchainParamsVersion"), Te(e.appVaultKeepersVersion, "appVaultKeepersVersion"), Te(
|
|
2835
2847
|
e.universalChallengersVersion,
|
|
2836
2848
|
"universalChallengersVersion"
|
|
2837
|
-
),
|
|
2849
|
+
), to(
|
|
2838
2850
|
e.vaultCoreVersion,
|
|
2839
2851
|
"VaultRefundData.vaultCoreVersion"
|
|
2840
2852
|
), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
|
|
2841
2853
|
throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
|
|
2842
|
-
if (!
|
|
2854
|
+
if (!Os.test(e.unsignedPrePeginTxHex))
|
|
2843
2855
|
throw new Error(
|
|
2844
2856
|
"unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
|
|
2845
2857
|
);
|
|
2846
|
-
if (!e.depositorBtcPubkey || !
|
|
2858
|
+
if (!e.depositorBtcPubkey || !Zt.test(e.depositorBtcPubkey))
|
|
2847
2859
|
throw new Error(
|
|
2848
2860
|
"depositorBtcPubkey must be 32 or 33 bytes of hex (optional 0x prefix)"
|
|
2849
2861
|
);
|
|
2850
2862
|
if (typeof e.amount != "bigint" || e.amount <= 0n)
|
|
2851
2863
|
throw new Error(`amount must be a positive bigint, got ${e.amount}`);
|
|
2852
2864
|
}
|
|
2853
|
-
function
|
|
2854
|
-
if (!e.vaultProviderPubkey || !
|
|
2865
|
+
function Fs(e) {
|
|
2866
|
+
if (!e.vaultProviderPubkey || !Zt.test(e.vaultProviderPubkey))
|
|
2855
2867
|
throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
|
|
2856
2868
|
if (e.vaultKeeperPubkeys.length === 0)
|
|
2857
2869
|
throw new Error("vaultKeeperPubkeys must be non-empty");
|
|
@@ -2876,7 +2888,7 @@ function Ls(e) {
|
|
|
2876
2888
|
`councilQuorum (${e.councilQuorum}) must be in [1, councilSize=${e.councilSize}]`
|
|
2877
2889
|
);
|
|
2878
2890
|
}
|
|
2879
|
-
async function
|
|
2891
|
+
async function Nn(e) {
|
|
2880
2892
|
const {
|
|
2881
2893
|
vaultId: t,
|
|
2882
2894
|
readVault: r,
|
|
@@ -2888,23 +2900,23 @@ async function Kn(e) {
|
|
|
2888
2900
|
} = e;
|
|
2889
2901
|
i == null || i.throwIfAborted(), Ae(t, "vaultId");
|
|
2890
2902
|
const u = await r();
|
|
2891
|
-
|
|
2903
|
+
Us(u), i == null || i.throwIfAborted();
|
|
2892
2904
|
const l = await o(u);
|
|
2893
|
-
if (
|
|
2905
|
+
if (Fs(l), i == null || i.throwIfAborted(), !Number.isFinite(s) || s <= 0)
|
|
2894
2906
|
throw new Error(`feeRate must be a positive number, got ${s}`);
|
|
2895
|
-
if (s >
|
|
2907
|
+
if (s > lt)
|
|
2896
2908
|
throw new Error(
|
|
2897
|
-
`feeRate ${s} sat/vB exceeds refund safety cap ${
|
|
2909
|
+
`feeRate ${s} sat/vB exceeds refund safety cap ${lt} sat/vB; refusing to sign refund.`
|
|
2898
2910
|
);
|
|
2899
|
-
const c = BigInt(Math.ceil(s *
|
|
2900
|
-
if (c >
|
|
2911
|
+
const c = BigInt(Math.ceil(s * er)), p = u.amount * dt / pt;
|
|
2912
|
+
if (c > p)
|
|
2901
2913
|
throw new Error(
|
|
2902
|
-
`Refund fee ${c} sats exceeds the per-vault safety cap of ${
|
|
2914
|
+
`Refund fee ${c} sats exceeds the per-vault safety cap of ${p} sats (${dt}/${pt} of vault.amount=${u.amount}); refusing to sign refund.`
|
|
2903
2915
|
);
|
|
2904
2916
|
i == null || i.throwIfAborted();
|
|
2905
|
-
const
|
|
2917
|
+
const d = he(
|
|
2906
2918
|
u.depositorBtcPubkey
|
|
2907
|
-
), g = P(u.unsignedPrePeginTxHex), h =
|
|
2919
|
+
), g = P(u.unsignedPrePeginTxHex), h = cr(g);
|
|
2908
2920
|
if (h !== void 0 && h.vout !== u.batch.length)
|
|
2909
2921
|
throw new Error(
|
|
2910
2922
|
`Auth-anchor OP_RETURN at vout ${h.vout} does not match batch size (${u.batch.length} HTLC outputs expect the anchor at vout ${u.batch.length}). Refund refused — sibling HTLC vector is incomplete.`
|
|
@@ -2913,23 +2925,23 @@ async function Kn(e) {
|
|
|
2913
2925
|
let f;
|
|
2914
2926
|
try {
|
|
2915
2927
|
f = S.fromHex(g);
|
|
2916
|
-
} catch (
|
|
2928
|
+
} catch (m) {
|
|
2917
2929
|
throw new Error(
|
|
2918
|
-
`Failed to parse funded Pre-PegIn transaction hex: ${
|
|
2930
|
+
`Failed to parse funded Pre-PegIn transaction hex: ${m instanceof Error ? m.message : String(m)}`
|
|
2919
2931
|
);
|
|
2920
2932
|
}
|
|
2921
2933
|
if (f.outs.length < u.batch.length)
|
|
2922
2934
|
throw new Error(
|
|
2923
2935
|
`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.`
|
|
2924
2936
|
);
|
|
2925
|
-
const { psbtHex:
|
|
2937
|
+
const { psbtHex: b } = await Jr({
|
|
2926
2938
|
prePeginParams: {
|
|
2927
2939
|
vaultCoreVersion: u.vaultCoreVersion,
|
|
2928
|
-
depositorPubkey:
|
|
2940
|
+
depositorPubkey: d,
|
|
2929
2941
|
vaultProviderPubkey: P(l.vaultProviderPubkey),
|
|
2930
2942
|
vaultKeeperPubkeys: l.vaultKeeperPubkeys.map(P),
|
|
2931
2943
|
universalChallengerPubkeys: l.universalChallengerPubkeys.map(P),
|
|
2932
|
-
hashlocks: u.batch.map((
|
|
2944
|
+
hashlocks: u.batch.map((m) => P(m.hashlock)),
|
|
2933
2945
|
timelockRefund: l.timelockRefund,
|
|
2934
2946
|
// `batch[i].amount` is the on-chain vault deposit (peg-in) amount, which
|
|
2935
2947
|
// is exactly what WASM's `pegInAmounts` expects — it re-adds the protocol
|
|
@@ -2937,7 +2949,7 @@ async function Kn(e) {
|
|
|
2937
2949
|
// HTLC output. `buildRefundPsbt`'s value cross-check then binds the result
|
|
2938
2950
|
// to the funded tx bytes, refusing the refund if the template's HTLC value
|
|
2939
2951
|
// disagrees with the on-chain commitment.
|
|
2940
|
-
pegInAmounts: u.batch.map((
|
|
2952
|
+
pegInAmounts: u.batch.map((m) => m.amount),
|
|
2941
2953
|
feeRate: l.feeRate,
|
|
2942
2954
|
minPeginFeeRate: l.minPeginFeeRate,
|
|
2943
2955
|
numLocalChallengers: l.numLocalChallengers,
|
|
@@ -2956,40 +2968,48 @@ async function Kn(e) {
|
|
|
2956
2968
|
hashlock: P(u.hashlock)
|
|
2957
2969
|
});
|
|
2958
2970
|
i == null || i.throwIfAborted();
|
|
2959
|
-
const
|
|
2971
|
+
const k = ce(
|
|
2960
2972
|
u.depositorBtcPubkey,
|
|
2961
|
-
|
|
2962
|
-
), x = await n(
|
|
2973
|
+
Ns
|
|
2974
|
+
), x = await n(b, k);
|
|
2963
2975
|
ae({
|
|
2964
|
-
requestedPsbtHex:
|
|
2976
|
+
requestedPsbtHex: b,
|
|
2965
2977
|
returnedPsbtHex: x
|
|
2966
2978
|
});
|
|
2967
2979
|
const v = 0, E = ue(
|
|
2968
2980
|
x,
|
|
2969
|
-
|
|
2981
|
+
d,
|
|
2970
2982
|
v
|
|
2971
2983
|
);
|
|
2972
2984
|
oe({
|
|
2973
|
-
requestedPsbtHex:
|
|
2985
|
+
requestedPsbtHex: b,
|
|
2974
2986
|
signatureHex: E,
|
|
2975
|
-
signerXOnlyPubkeyHex:
|
|
2987
|
+
signerXOnlyPubkeyHex: d,
|
|
2976
2988
|
inputIndex: v
|
|
2977
2989
|
});
|
|
2978
|
-
const
|
|
2979
|
-
requestedPsbtHex:
|
|
2990
|
+
const C = _t({
|
|
2991
|
+
requestedPsbtHex: b,
|
|
2980
2992
|
signaturesHex: [E],
|
|
2981
|
-
signerXOnlyPubkeyHex:
|
|
2993
|
+
signerXOnlyPubkeyHex: d
|
|
2982
2994
|
});
|
|
2983
2995
|
i == null || i.throwIfAborted();
|
|
2984
2996
|
try {
|
|
2985
|
-
return await a(
|
|
2986
|
-
} catch (
|
|
2987
|
-
|
|
2997
|
+
return await a(C);
|
|
2998
|
+
} catch (m) {
|
|
2999
|
+
if (m instanceof Error) {
|
|
3000
|
+
if (Ds.test(m.message))
|
|
3001
|
+
throw new Ks(t, m);
|
|
3002
|
+
if (Ls.test(m.message))
|
|
3003
|
+
throw new ct(-27, t, C, m);
|
|
3004
|
+
if (Ms.test(m.message))
|
|
3005
|
+
throw new ct(-25, t, C, m);
|
|
3006
|
+
}
|
|
3007
|
+
throw m;
|
|
2988
3008
|
}
|
|
2989
3009
|
}
|
|
2990
|
-
async function
|
|
3010
|
+
async function Dn(e) {
|
|
2991
3011
|
const { vaultId: t, vault: r, readers: o, network: s } = e, [n, a] = await Promise.all([
|
|
2992
|
-
|
|
3012
|
+
Lt({
|
|
2993
3013
|
vaultId: t,
|
|
2994
3014
|
vault: {
|
|
2995
3015
|
basic: {
|
|
@@ -3023,21 +3043,21 @@ async function Hn(e) {
|
|
|
3023
3043
|
network: s
|
|
3024
3044
|
};
|
|
3025
3045
|
}
|
|
3026
|
-
class
|
|
3046
|
+
class ht extends Error {
|
|
3027
3047
|
constructor(r, o, s) {
|
|
3028
3048
|
super(r);
|
|
3029
3049
|
/** Fee the reclaim would have paid, in satoshis. */
|
|
3030
|
-
|
|
3050
|
+
B(this, "feeSats");
|
|
3031
3051
|
/** Sum of the reserves the reclaim would have swept, in satoshis. */
|
|
3032
|
-
|
|
3052
|
+
B(this, "sweptTotalSats");
|
|
3033
3053
|
this.name = "ReclaimUneconomicalError", this.feeSats = o, this.sweptTotalSats = s;
|
|
3034
3054
|
}
|
|
3035
3055
|
}
|
|
3036
|
-
const
|
|
3037
|
-
async function
|
|
3056
|
+
const gt = 2e3, ft = 25n, yt = 100n, Ln = 10n;
|
|
3057
|
+
async function qs(e, t, r) {
|
|
3038
3058
|
for (let o = 0; o < e.length; o++) {
|
|
3039
|
-
const s =
|
|
3040
|
-
await
|
|
3059
|
+
const s = ro(e[o].depositorSignedPeginTxHex), n = Ie(
|
|
3060
|
+
await xr(
|
|
3041
3061
|
P(s),
|
|
3042
3062
|
P(r)
|
|
3043
3063
|
)
|
|
@@ -3048,7 +3068,7 @@ async function Ms(e, t, r) {
|
|
|
3048
3068
|
);
|
|
3049
3069
|
}
|
|
3050
3070
|
}
|
|
3051
|
-
async function
|
|
3071
|
+
async function Mn(e) {
|
|
3052
3072
|
const {
|
|
3053
3073
|
vaultIds: t,
|
|
3054
3074
|
depositorEthAddress: r,
|
|
@@ -3063,9 +3083,9 @@ async function Nn(e) {
|
|
|
3063
3083
|
throw new Error("Reclaim requires at least one vault id; got none.");
|
|
3064
3084
|
if (!Number.isFinite(n) || n <= 0)
|
|
3065
3085
|
throw new Error(`feeRate must be a positive number, got ${n}`);
|
|
3066
|
-
if (n >
|
|
3067
|
-
throw new
|
|
3068
|
-
`Fee rate ${n} sat/vB exceeds the reclaim safety cap of ${
|
|
3086
|
+
if (n > gt)
|
|
3087
|
+
throw new ht(
|
|
3088
|
+
`Fee rate ${n} sat/vB exceeds the reclaim safety cap of ${gt} sat/vB; refusing to sign.`,
|
|
3069
3089
|
0n,
|
|
3070
3090
|
0n
|
|
3071
3091
|
);
|
|
@@ -3074,131 +3094,132 @@ async function Nn(e) {
|
|
|
3074
3094
|
throw new Error(
|
|
3075
3095
|
`readVaults returned ${l.length} reserves for ${t.length} vault id(s); refusing to sweep a set that does not match the request.`
|
|
3076
3096
|
);
|
|
3077
|
-
await
|
|
3078
|
-
const c = he(o),
|
|
3097
|
+
await qs(l, t, r), u == null || u.throwIfAborted();
|
|
3098
|
+
const c = he(o), p = l.map((v) => ({
|
|
3079
3099
|
depositorSignedPeginTxHex: v.depositorSignedPeginTxHex,
|
|
3080
3100
|
observed: v.observed,
|
|
3081
3101
|
expectedValue: v.expectedClaimValue
|
|
3082
|
-
})),
|
|
3083
|
-
if (
|
|
3084
|
-
throw new
|
|
3085
|
-
`Reclaim fee ${
|
|
3086
|
-
|
|
3102
|
+
})), d = Zr(n, p.length), g = p.reduce((v, E) => v + E.expectedValue, 0n), h = g * ft / yt;
|
|
3103
|
+
if (d > h)
|
|
3104
|
+
throw new ht(
|
|
3105
|
+
`Reclaim fee ${d} sats exceeds ${ft}/${yt} of the swept total (${g} sats, cap ${h} sats). The reserve is not at risk — it stays where it is until fee rates fall.`,
|
|
3106
|
+
d,
|
|
3087
3107
|
g
|
|
3088
3108
|
);
|
|
3089
3109
|
u == null || u.throwIfAborted();
|
|
3090
|
-
const { psbtHex: y } =
|
|
3110
|
+
const { psbtHex: y } = eo({
|
|
3091
3111
|
depositorPubkey: c,
|
|
3092
|
-
inputs:
|
|
3093
|
-
feeSats:
|
|
3112
|
+
inputs: p,
|
|
3113
|
+
feeSats: d
|
|
3094
3114
|
});
|
|
3095
3115
|
u == null || u.throwIfAborted();
|
|
3096
3116
|
const f = ce(
|
|
3097
3117
|
o,
|
|
3098
|
-
|
|
3099
|
-
),
|
|
3118
|
+
p.length
|
|
3119
|
+
), b = await a(y, f);
|
|
3100
3120
|
ae({
|
|
3101
3121
|
requestedPsbtHex: y,
|
|
3102
|
-
returnedPsbtHex:
|
|
3122
|
+
returnedPsbtHex: b
|
|
3103
3123
|
});
|
|
3104
|
-
const
|
|
3105
|
-
const
|
|
3106
|
-
|
|
3124
|
+
const k = p.map((v, E) => {
|
|
3125
|
+
const C = ue(
|
|
3126
|
+
b,
|
|
3107
3127
|
c,
|
|
3108
3128
|
E
|
|
3109
3129
|
);
|
|
3110
3130
|
return oe({
|
|
3111
3131
|
requestedPsbtHex: y,
|
|
3112
|
-
signatureHex:
|
|
3132
|
+
signatureHex: C,
|
|
3113
3133
|
signerXOnlyPubkeyHex: c,
|
|
3114
3134
|
inputIndex: E
|
|
3115
|
-
}),
|
|
3116
|
-
}), x =
|
|
3135
|
+
}), C;
|
|
3136
|
+
}), x = _t({
|
|
3117
3137
|
requestedPsbtHex: y,
|
|
3118
|
-
signaturesHex:
|
|
3138
|
+
signaturesHex: k,
|
|
3119
3139
|
signerXOnlyPubkeyHex: c
|
|
3120
3140
|
});
|
|
3121
3141
|
return u == null || u.throwIfAborted(), i(x);
|
|
3122
3142
|
}
|
|
3123
3143
|
export {
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3144
|
+
Rn as $,
|
|
3145
|
+
H as A,
|
|
3146
|
+
wn as B,
|
|
3147
|
+
ho as C,
|
|
3148
|
+
q as D,
|
|
3149
|
+
cs as E,
|
|
3150
|
+
xn as F,
|
|
3151
|
+
w as G,
|
|
3152
|
+
vs as H,
|
|
3153
|
+
En as I,
|
|
3134
3154
|
Se as J,
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3155
|
+
kn as K,
|
|
3156
|
+
Cn as L,
|
|
3157
|
+
Tn as M,
|
|
3158
|
+
_n as N,
|
|
3159
|
+
Bn as O,
|
|
3160
|
+
fo as P,
|
|
3161
|
+
An as Q,
|
|
3162
|
+
Sn as R,
|
|
3143
3163
|
Y as S,
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3164
|
+
Ss as T,
|
|
3165
|
+
As as U,
|
|
3166
|
+
mo as V,
|
|
3167
|
+
Yt as W,
|
|
3168
|
+
Qt as X,
|
|
3169
|
+
Rs as Y,
|
|
3170
|
+
In as Z,
|
|
3171
|
+
Vn as _,
|
|
3172
|
+
pn as a,
|
|
3173
|
+
Jt as a0,
|
|
3174
|
+
Kn as a1,
|
|
3175
|
+
Hn as a2,
|
|
3176
|
+
jt as a3,
|
|
3177
|
+
$n as a4,
|
|
3178
|
+
ke as a5,
|
|
3179
|
+
Ts as a6,
|
|
3160
3180
|
nt as a7,
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3181
|
+
Lt as a8,
|
|
3182
|
+
zo as a9,
|
|
3183
|
+
Dt as aa,
|
|
3184
|
+
Ks as ab,
|
|
3185
|
+
ct as ac,
|
|
3186
|
+
Nn as ad,
|
|
3187
|
+
On as ae,
|
|
3188
|
+
pt as af,
|
|
3189
|
+
dt as ag,
|
|
3190
|
+
lt as ah,
|
|
3191
|
+
er as ai,
|
|
3192
|
+
Dn as aj,
|
|
3193
|
+
ht as ak,
|
|
3194
|
+
Mn as al,
|
|
3195
|
+
yt as am,
|
|
3196
|
+
ft as an,
|
|
3197
|
+
gt as ao,
|
|
3198
|
+
Ln as ap,
|
|
3199
|
+
hn as b,
|
|
3200
|
+
gn as c,
|
|
3201
|
+
yn as d,
|
|
3202
|
+
Vo as e,
|
|
3203
|
+
lo as f,
|
|
3204
|
+
go as g,
|
|
3205
|
+
vn as h,
|
|
3206
|
+
yo as i,
|
|
3186
3207
|
ne as j,
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3208
|
+
Po as k,
|
|
3209
|
+
xo as l,
|
|
3210
|
+
fn as m,
|
|
3211
|
+
Ko as n,
|
|
3212
|
+
Mo as o,
|
|
3213
|
+
Ao as p,
|
|
3214
|
+
Oo as q,
|
|
3215
|
+
Pn as r,
|
|
3195
3216
|
ko as s,
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3217
|
+
At as t,
|
|
3218
|
+
jo as u,
|
|
3219
|
+
Mt as v,
|
|
3220
|
+
Ut as w,
|
|
3221
|
+
Jo as x,
|
|
3222
|
+
mn as y,
|
|
3223
|
+
bn as z
|
|
3203
3224
|
};
|
|
3204
|
-
//# sourceMappingURL=buildAndBroadcastReclaim-
|
|
3225
|
+
//# sourceMappingURL=buildAndBroadcastReclaim-Bs_zdDGN.js.map
|