@babylonlabs-io/ts-sdk 5.0.0 → 5.1.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/{PayoutManager-BXzFIZK6.cjs → PayoutManager-B5nR0x1t.cjs} +2 -2
- package/dist/{PayoutManager-BXzFIZK6.cjs.map → PayoutManager-B5nR0x1t.cjs.map} +1 -1
- package/dist/{PayoutManager-Cjkozmnn.js → PayoutManager-BHeiLQ1j.js} +2 -2
- package/dist/{PayoutManager-Cjkozmnn.js.map → PayoutManager-BHeiLQ1j.js.map} +1 -1
- package/dist/{PeginManager-BipOU_e4.cjs → PeginManager-6ghglb4r.cjs} +2 -2
- package/dist/{PeginManager-BipOU_e4.cjs.map → PeginManager-6ghglb4r.cjs.map} +1 -1
- package/dist/{PeginManager-Cd5pHNTO.js → PeginManager-CXNqbgA4.js} +5 -5
- package/dist/{PeginManager-Cd5pHNTO.js.map → PeginManager-CXNqbgA4.js.map} +1 -1
- package/dist/{buildAndBroadcastReclaim-DU8iOtbn.js → buildAndBroadcastReclaim-Acz637Vf.js} +634 -576
- package/dist/{buildAndBroadcastReclaim-DU8iOtbn.js.map → buildAndBroadcastReclaim-Acz637Vf.js.map} +1 -1
- package/dist/{buildAndBroadcastReclaim-B00roO6R.cjs → buildAndBroadcastReclaim-Cf05JFP-.cjs} +2 -2
- package/dist/{buildAndBroadcastReclaim-B00roO6R.cjs.map → buildAndBroadcastReclaim-Cf05JFP-.cjs.map} +1 -1
- package/dist/{challengeAssert-eUMgmpMk.cjs → challengeAssert-CuX_8Twt.cjs} +2 -2
- package/dist/{challengeAssert-eUMgmpMk.cjs.map → challengeAssert-CuX_8Twt.cjs.map} +1 -1
- package/dist/{challengeAssert-pJP7MKhG.js → challengeAssert-D_lRvsO0.js} +2 -2
- package/dist/{challengeAssert-pJP7MKhG.js.map → challengeAssert-D_lRvsO0.js.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +90 -87
- package/dist/{pegin-registration-client-ZI0k10_3.js → pegin-registration-client-BlrXyZpF.js} +67 -70
- package/dist/pegin-registration-client-BlrXyZpF.js.map +1 -0
- package/dist/pegin-registration-client-DOb-Iznp.cjs +2 -0
- package/dist/pegin-registration-client-DOb-Iznp.cjs.map +1 -0
- package/dist/peginState-B4t_PDgj.cjs +2 -0
- package/dist/peginState-B4t_PDgj.cjs.map +1 -0
- package/dist/{peginState-CIibG9S_.js → peginState-CXdbSit3.js} +7 -7
- package/dist/peginState-CXdbSit3.js.map +1 -0
- package/dist/{reservation-BZQABu4g.js → reservation-BAj5n-H_.js} +2 -2
- package/dist/{reservation-BZQABu4g.js.map → reservation-BAj5n-H_.js.map} +1 -1
- package/dist/{reservation-CA5knoQ0.cjs → reservation-D9ftyiwP.cjs} +2 -2
- package/dist/{reservation-CA5knoQ0.cjs.map → reservation-D9ftyiwP.cjs.map} +1 -1
- package/dist/tbv/core/clients/eth/index.cjs +1 -1
- package/dist/tbv/core/clients/eth/index.js +1 -1
- package/dist/tbv/core/clients/eth/types.d.ts +1 -1
- package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts.map +1 -1
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +92 -89
- package/dist/tbv/core/managers/index.cjs +1 -1
- package/dist/tbv/core/managers/index.js +2 -2
- package/dist/tbv/core/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.js +3 -3
- package/dist/tbv/core/primitives/psbt/standardPayoutScript.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/index.d.ts +1 -1
- package/dist/tbv/core/services/deposit/index.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/peginState.d.ts +9 -2
- package/dist/tbv/core/services/deposit/peginState.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/verifyRegisteredParticipantKeys.d.ts +27 -1
- package/dist/tbv/core/services/deposit/verifyRegisteredParticipantKeys.d.ts.map +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +85 -82
- package/dist/tbv/core/utils/index.cjs +1 -1
- package/dist/tbv/core/utils/index.js +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +92 -89
- package/dist/{toRefundInputs-CR7vtHMa.cjs → toRefundInputs-BzyN0zvj.cjs} +2 -2
- package/dist/{toRefundInputs-CR7vtHMa.cjs.map → toRefundInputs-BzyN0zvj.cjs.map} +1 -1
- package/dist/{toRefundInputs-BrJrmOvY.js → toRefundInputs-DwXpKQxN.js} +4 -4
- package/dist/{toRefundInputs-BrJrmOvY.js.map → toRefundInputs-DwXpKQxN.js.map} +1 -1
- package/dist/types-BnZIbDHb.cjs.map +1 -1
- package/dist/types-K_aM5GZO.js.map +1 -1
- package/dist/{verifyKeyPathSchnorrSignature-DcxCojp0.cjs → verifyKeyPathSchnorrSignature-BVrAmVL3.cjs} +2 -2
- package/dist/{verifyKeyPathSchnorrSignature-DcxCojp0.cjs.map → verifyKeyPathSchnorrSignature-BVrAmVL3.cjs.map} +1 -1
- package/dist/{verifyKeyPathSchnorrSignature-DPXOFOol.js → verifyKeyPathSchnorrSignature-CIE3jlVt.js} +2 -2
- package/dist/{verifyKeyPathSchnorrSignature-DPXOFOol.js.map → verifyKeyPathSchnorrSignature-CIE3jlVt.js.map} +1 -1
- package/dist/verifyScriptPathSchnorrSignature-BHskbJJx.cjs +2 -0
- package/dist/verifyScriptPathSchnorrSignature-BHskbJJx.cjs.map +1 -0
- package/dist/{verifyScriptPathSchnorrSignature-D-fdi-sG.js → verifyScriptPathSchnorrSignature-DLNGgm4j.js} +181 -173
- package/dist/verifyScriptPathSchnorrSignature-DLNGgm4j.js.map +1 -0
- package/package.json +3 -3
- package/dist/pegin-registration-client-DLlaZbsZ.cjs +0 -2
- package/dist/pegin-registration-client-DLlaZbsZ.cjs.map +0 -1
- package/dist/pegin-registration-client-ZI0k10_3.js.map +0 -1
- package/dist/peginState-CIibG9S_.js.map +0 -1
- package/dist/peginState-IyE22wWh.cjs +0 -2
- package/dist/peginState-IyE22wWh.cjs.map +0 -1
- package/dist/verifyScriptPathSchnorrSignature-CgDa9Rcg.cjs +0 -2
- package/dist/verifyScriptPathSchnorrSignature-CgDa9Rcg.cjs.map +0 -1
- package/dist/verifyScriptPathSchnorrSignature-D-fdi-sG.js.map +0 -1
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { script as x, opcodes as w, payments as L, Transaction as k, crypto as U, Psbt as H } from "bitcoinjs-lib";
|
|
2
|
-
import { computeMinClaimValue as
|
|
3
|
-
import { c as q, p as
|
|
4
|
-
import { p as
|
|
5
|
-
import { b as
|
|
2
|
+
import { computeMinClaimValue as xe, peginP2aAnchorOutput as Oe, computeMinPeginFee as Ve, tapInternalPubkey as I, buildPeginTxFromPrePegin as Le, createPrePeginTransaction as Re, validatePeginP2aAnchor as Ke, createPayoutConnector as He, computePayoutFeeFloor as Ne, getAssertPayoutScriptInfo as Ue } from "./tbv/core/wasm/index.js";
|
|
3
|
+
import { c as q, p as Be, d as Me } from "./fundPeginTransaction-CwhRbCQC.js";
|
|
4
|
+
import { p as Fe, s as f, d as Ce, m as be, T as y, h as C, u as M, j as qe, S as W } from "./bitcoin-C-TuHb-v.js";
|
|
5
|
+
import { b as We, s as Xe } from "./secp256k1-BuxBFUHm.js";
|
|
6
6
|
import { Buffer as a } from "buffer";
|
|
7
|
-
import { P as X, l as G, m as z, n as Y, o as
|
|
8
|
-
import * as
|
|
7
|
+
import { P as X, l as G, m as z, n as Y, o as Ge, p as D, q as Q, r as Z, s as j, t as J, u as ee, v as te, w as oe, x as ne, y as re, M as ie, j as se, z as ze, A as ke, B as Ye, V as De, E as ue } from "./constants-CmDDuM3L.js";
|
|
8
|
+
import * as Ie from "@bitcoin-js/tiny-secp256k1-asmjs";
|
|
9
9
|
import { X as ce } from "./validation-OSC0xTHB.js";
|
|
10
10
|
function b(e) {
|
|
11
|
-
return
|
|
11
|
+
return Fe(e).toLowerCase();
|
|
12
12
|
}
|
|
13
|
-
function
|
|
13
|
+
function jt(e, t, o) {
|
|
14
14
|
const n = /* @__PURE__ */ new Set();
|
|
15
15
|
n.add(b(e));
|
|
16
16
|
for (const r of t)
|
|
17
17
|
n.add(b(r));
|
|
18
18
|
return n.delete(b(o)), n.size;
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function Qe(e) {
|
|
21
21
|
const t = b(e.claimerBtcPubkey), o = b(e.depositorBtcPubkey), n = e.vaultKeeperBtcPubkeys.map(b);
|
|
22
22
|
if (t === o) {
|
|
23
23
|
const s = n.filter((u) => u !== o);
|
|
@@ -40,15 +40,15 @@ function Ye(e) {
|
|
|
40
40
|
);
|
|
41
41
|
return i;
|
|
42
42
|
}
|
|
43
|
-
const
|
|
43
|
+
const Ze = 32, je = 65535, Je = 2;
|
|
44
44
|
function _(e, t) {
|
|
45
45
|
const o = f(e).toLowerCase();
|
|
46
46
|
if (!/^[0-9a-f]{64}$/.test(o))
|
|
47
47
|
throw new Error(`${t} must be a 32-byte x-only public key.`);
|
|
48
48
|
try {
|
|
49
|
-
|
|
49
|
+
We.Point.fromBytes(
|
|
50
50
|
a.concat([
|
|
51
|
-
a.from([
|
|
51
|
+
a.from([Je]),
|
|
52
52
|
a.from(o, "hex")
|
|
53
53
|
])
|
|
54
54
|
);
|
|
@@ -77,9 +77,9 @@ function K(e, t) {
|
|
|
77
77
|
t ? w.OP_NUMEQUALVERIFY : w.OP_NUMEQUAL
|
|
78
78
|
), o;
|
|
79
79
|
}
|
|
80
|
-
function
|
|
80
|
+
function et(e, t) {
|
|
81
81
|
var g;
|
|
82
|
-
|
|
82
|
+
be();
|
|
83
83
|
const o = _(
|
|
84
84
|
e.depositorPubkey,
|
|
85
85
|
"depositorPubkey"
|
|
@@ -95,11 +95,11 @@ function je(e, t) {
|
|
|
95
95
|
), s = f(t).toLowerCase();
|
|
96
96
|
if (!/^[0-9a-f]{64}$/.test(s))
|
|
97
97
|
throw new Error("hashlock must be 32 bytes.");
|
|
98
|
-
if (!Number.isInteger(e.timelockRefund) || e.timelockRefund < 1 || e.timelockRefund >
|
|
98
|
+
if (!Number.isInteger(e.timelockRefund) || e.timelockRefund < 1 || e.timelockRefund > je)
|
|
99
99
|
throw new Error("timelockRefund must be an integer from 1 to 65535.");
|
|
100
100
|
const u = x.compile([
|
|
101
101
|
w.OP_SIZE,
|
|
102
|
-
x.number.encode(
|
|
102
|
+
x.number.encode(Ze),
|
|
103
103
|
w.OP_EQUALVERIFY,
|
|
104
104
|
w.OP_SHA256,
|
|
105
105
|
a.from(s, "hex"),
|
|
@@ -144,8 +144,8 @@ function je(e, t) {
|
|
|
144
144
|
tapMerkleRoot: l
|
|
145
145
|
};
|
|
146
146
|
}
|
|
147
|
-
function
|
|
148
|
-
|
|
147
|
+
function tt(e, t) {
|
|
148
|
+
be();
|
|
149
149
|
const o = _(
|
|
150
150
|
e.depositorPubkey,
|
|
151
151
|
"depositorPubkey"
|
|
@@ -175,7 +175,7 @@ function Je(e, t) {
|
|
|
175
175
|
throw new Error("Failed to derive the expected PegIn payout output.");
|
|
176
176
|
return u;
|
|
177
177
|
}
|
|
178
|
-
async function
|
|
178
|
+
async function ot(e, t) {
|
|
179
179
|
const o = t.pegInAmounts.length;
|
|
180
180
|
if (t.hashlocks.length !== o)
|
|
181
181
|
throw new Error(
|
|
@@ -193,7 +193,7 @@ async function et(e, t) {
|
|
|
193
193
|
throw new Error(
|
|
194
194
|
`WASM Pre-PegIn returned non-positive depositorClaimValue ${e.depositorClaimValue}; expected > 0.`
|
|
195
195
|
);
|
|
196
|
-
const n = await
|
|
196
|
+
const n = await xe(
|
|
197
197
|
// Must price the same graph version the builder constructed.
|
|
198
198
|
t.vaultCoreVersion,
|
|
199
199
|
t.numLocalChallengers,
|
|
@@ -206,9 +206,9 @@ async function et(e, t) {
|
|
|
206
206
|
throw new Error(
|
|
207
207
|
`WASM Pre-PegIn depositorClaimValue ${e.depositorClaimValue} does not match the independently computed minimum claim value ${n} (vaultCoreVersion=${t.vaultCoreVersion}, numLocalChallengers=${t.numLocalChallengers}, numUniversalChallengers=${t.universalChallengerPubkeys.length}, councilQuorum=${t.councilQuorum}, councilSize=${t.councilSize}, feeRate=${t.feeRate}).`
|
|
208
208
|
);
|
|
209
|
-
const { value: r } = await
|
|
209
|
+
const { value: r } = await Oe(
|
|
210
210
|
t.vaultCoreVersion
|
|
211
|
-
), i = await
|
|
211
|
+
), i = await Ve(
|
|
212
212
|
t.vaultCoreVersion,
|
|
213
213
|
t.vaultKeeperPubkeys.length,
|
|
214
214
|
t.universalChallengerPubkeys.length,
|
|
@@ -249,7 +249,7 @@ class V extends Error {
|
|
|
249
249
|
super(t), this.name = "HtlcOutputMismatchError";
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
|
-
function
|
|
252
|
+
function nt(e, t, o) {
|
|
253
253
|
if (e.length < t.length)
|
|
254
254
|
throw new V(
|
|
255
255
|
`Encoded Pre-PegIn tx has ${e.length} output(s), fewer than the ${t.length} HTLC output(s) the cross-check validated.`
|
|
@@ -267,7 +267,7 @@ function tt(e, t, o) {
|
|
|
267
267
|
);
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
|
-
function
|
|
270
|
+
function rt(e, t, o, n, r, i, s) {
|
|
271
271
|
if (i !== X)
|
|
272
272
|
throw new Error(
|
|
273
273
|
`WASM Pre-PegIn transaction version ${i}; expected ${X}.`
|
|
@@ -280,7 +280,7 @@ function ot(e, t, o, n, r, i, s) {
|
|
|
280
280
|
throw new Error(
|
|
281
281
|
`WASM Pre-PegIn output layout has ${t.length} HTLC output(s); expected at least ${z}.`
|
|
282
282
|
);
|
|
283
|
-
const u = t.length, c = u + +(r !== void 0), p =
|
|
283
|
+
const u = t.length, c = u + +(r !== void 0), p = Be(
|
|
284
284
|
t.length,
|
|
285
285
|
r !== void 0
|
|
286
286
|
);
|
|
@@ -288,9 +288,9 @@ function ot(e, t, o, n, r, i, s) {
|
|
|
288
288
|
throw new Error(
|
|
289
289
|
`WASM Pre-PegIn output layout has ${e.length} output(s); expected exactly ${p}.`
|
|
290
290
|
);
|
|
291
|
-
|
|
291
|
+
nt(e, t, o);
|
|
292
292
|
for (let P = 0; P < t.length; P++) {
|
|
293
|
-
const E =
|
|
293
|
+
const E = et(
|
|
294
294
|
n,
|
|
295
295
|
n.hashlocks[P]
|
|
296
296
|
).scriptPubKey;
|
|
@@ -305,7 +305,7 @@ function ot(e, t, o, n, r, i, s) {
|
|
|
305
305
|
throw new Error(
|
|
306
306
|
`WASM Pre-PegIn auth output[${u}] value ${P.value} sat; expected exactly ${Y} sat.`
|
|
307
307
|
);
|
|
308
|
-
const E = P.script.toString("hex").toLowerCase(), v =
|
|
308
|
+
const E = P.script.toString("hex").toLowerCase(), v = Ge + r.toLowerCase();
|
|
309
309
|
if (E !== v)
|
|
310
310
|
throw new Error(
|
|
311
311
|
`WASM Pre-PegIn auth output[${u}] scriptPubKey ${E}; expected ${v}.`
|
|
@@ -317,15 +317,15 @@ function ot(e, t, o, n, r, i, s) {
|
|
|
317
317
|
`WASM Pre-PegIn CPFP output[${c}] value ${l.value} sat; expected exactly ${D} sat.`
|
|
318
318
|
);
|
|
319
319
|
const h = l.script.toString("hex").toLowerCase(), d = f(
|
|
320
|
-
|
|
320
|
+
Ce(n.depositorPubkey)
|
|
321
321
|
).toLowerCase();
|
|
322
322
|
if (h !== d)
|
|
323
323
|
throw new Error(
|
|
324
324
|
`WASM Pre-PegIn CPFP output[${c}] scriptPubKey ${h}; expected depositor BIP-86 script ${d}.`
|
|
325
325
|
);
|
|
326
326
|
}
|
|
327
|
-
const
|
|
328
|
-
function
|
|
327
|
+
const it = 1;
|
|
328
|
+
function st(e) {
|
|
329
329
|
const t = f(e);
|
|
330
330
|
if (!/^[0-9a-fA-F]{64}$/.test(t))
|
|
331
331
|
throw new Error(
|
|
@@ -350,12 +350,12 @@ function rt(e) {
|
|
|
350
350
|
);
|
|
351
351
|
return { scriptPubKey: i, leafScript: o, controlBlock: u, internalKey: n };
|
|
352
352
|
}
|
|
353
|
-
function
|
|
354
|
-
return
|
|
353
|
+
function ut(e) {
|
|
354
|
+
return st(e).scriptPubKey;
|
|
355
355
|
}
|
|
356
|
-
const ae = 64,
|
|
357
|
-
async function
|
|
358
|
-
const t =
|
|
356
|
+
const ae = 64, ct = /^[0-9a-fA-F]+$/, le = 65535;
|
|
357
|
+
async function Jt(e) {
|
|
358
|
+
const t = _e(e.authAnchorHash), o = await Re({
|
|
359
359
|
txGraphVersion: e.vaultCoreVersion,
|
|
360
360
|
depositorPubkey: e.depositorPubkey,
|
|
361
361
|
vaultProviderPubkey: e.vaultProviderPubkey,
|
|
@@ -371,8 +371,8 @@ async function Zt(e) {
|
|
|
371
371
|
councilSize: e.councilSize,
|
|
372
372
|
network: e.network,
|
|
373
373
|
authAnchorHash: t
|
|
374
|
-
}), n = await
|
|
375
|
-
|
|
374
|
+
}), n = await ot(o, e), r = Me(o.txHex);
|
|
375
|
+
rt(
|
|
376
376
|
r.outputs,
|
|
377
377
|
o.htlcValues,
|
|
378
378
|
o.htlcScriptPubKeys,
|
|
@@ -397,21 +397,21 @@ async function Zt(e) {
|
|
|
397
397
|
minPeginFee: n
|
|
398
398
|
};
|
|
399
399
|
}
|
|
400
|
-
function
|
|
400
|
+
function _e(e) {
|
|
401
401
|
if (e === void 0) return;
|
|
402
402
|
const t = e.startsWith("0x") || e.startsWith("0X") ? e.slice(2) : e;
|
|
403
|
-
if (t.length !== ae || !
|
|
403
|
+
if (t.length !== ae || !ct.test(t))
|
|
404
404
|
throw new Error(
|
|
405
405
|
`authAnchorHash must be 32-byte hex (${ae} chars, no 0x prefix); got length ${t.length}`
|
|
406
406
|
);
|
|
407
407
|
return t.toLowerCase();
|
|
408
408
|
}
|
|
409
|
-
async function
|
|
409
|
+
async function eo(e) {
|
|
410
410
|
if (!Number.isInteger(e.timelockPegin) || e.timelockPegin < 1 || e.timelockPegin > le)
|
|
411
411
|
throw new Error(
|
|
412
412
|
`PegIn timelock ${e.timelockPegin} must be a whole number of blocks from 1 to ${le}.`
|
|
413
413
|
);
|
|
414
|
-
const t = await
|
|
414
|
+
const t = await Le(
|
|
415
415
|
{
|
|
416
416
|
txGraphVersion: e.prePeginParams.vaultCoreVersion,
|
|
417
417
|
depositorPubkey: e.prePeginParams.depositorPubkey,
|
|
@@ -427,7 +427,7 @@ async function jt(e) {
|
|
|
427
427
|
councilQuorum: e.prePeginParams.councilQuorum,
|
|
428
428
|
councilSize: e.prePeginParams.councilSize,
|
|
429
429
|
network: e.prePeginParams.network,
|
|
430
|
-
authAnchorHash:
|
|
430
|
+
authAnchorHash: _e(
|
|
431
431
|
e.prePeginParams.authAnchorHash
|
|
432
432
|
)
|
|
433
433
|
},
|
|
@@ -435,20 +435,20 @@ async function jt(e) {
|
|
|
435
435
|
e.fundedPrePeginTxHex,
|
|
436
436
|
e.htlcVout
|
|
437
437
|
);
|
|
438
|
-
return await
|
|
438
|
+
return await at(t, e), {
|
|
439
439
|
txHex: t.txHex,
|
|
440
440
|
txid: t.txid,
|
|
441
441
|
vaultScriptPubKey: t.vaultScriptPubKey,
|
|
442
442
|
vaultValue: t.vaultValue
|
|
443
443
|
};
|
|
444
444
|
}
|
|
445
|
-
async function
|
|
445
|
+
async function at(e, t) {
|
|
446
446
|
const o = t.prePeginParams.vaultCoreVersion;
|
|
447
447
|
if (o !== Q)
|
|
448
448
|
throw new Error(
|
|
449
449
|
`Unsupported vaultCoreVersion ${o} for PegIn tx; only ${Q} has a PegIn shape.`
|
|
450
450
|
);
|
|
451
|
-
await
|
|
451
|
+
await Ke(o, e.txHex);
|
|
452
452
|
const n = k.fromHex(f(e.txHex));
|
|
453
453
|
if (n.version !== Z)
|
|
454
454
|
throw new Error(
|
|
@@ -497,7 +497,7 @@ async function ut(e, t) {
|
|
|
497
497
|
throw new Error(
|
|
498
498
|
`Encoded PegIn vault output value ${u.value} does not match the WASM-reported vaultValue ${e.vaultValue}.`
|
|
499
499
|
);
|
|
500
|
-
const c =
|
|
500
|
+
const c = tt(
|
|
501
501
|
t.prePeginParams,
|
|
502
502
|
t.timelockPegin
|
|
503
503
|
).toString("hex");
|
|
@@ -515,19 +515,19 @@ async function ut(e, t) {
|
|
|
515
515
|
throw new Error(
|
|
516
516
|
`Encoded PegIn txid ${l} does not match the WASM-reported txid ${e.txid}.`
|
|
517
517
|
);
|
|
518
|
-
const h = await
|
|
518
|
+
const h = await xe(
|
|
519
519
|
o,
|
|
520
520
|
t.prePeginParams.numLocalChallengers,
|
|
521
521
|
t.prePeginParams.universalChallengerPubkeys.length,
|
|
522
522
|
t.prePeginParams.councilQuorum,
|
|
523
523
|
t.prePeginParams.councilSize,
|
|
524
524
|
t.prePeginParams.feeRate
|
|
525
|
-
), d = n.outs[
|
|
525
|
+
), d = n.outs[it];
|
|
526
526
|
if (BigInt(d.value) !== h)
|
|
527
527
|
throw new Error(
|
|
528
528
|
`Encoded PegIn depositor-claim output value ${d.value} does not match the independently computed claim value ${h} for vaultCoreVersion ${o}.`
|
|
529
529
|
);
|
|
530
|
-
const P =
|
|
530
|
+
const P = ut(
|
|
531
531
|
t.prePeginParams.depositorPubkey
|
|
532
532
|
);
|
|
533
533
|
if (!d.script.equals(P))
|
|
@@ -535,8 +535,8 @@ async function ut(e, t) {
|
|
|
535
535
|
`Encoded PegIn depositor-claim output scriptPubKey ${d.script.toString("hex")} does not pay to the depositor's claim script (expected ${P.toString("hex")}).`
|
|
536
536
|
);
|
|
537
537
|
}
|
|
538
|
-
async function
|
|
539
|
-
const t = await
|
|
538
|
+
async function lt(e) {
|
|
539
|
+
const t = await He(
|
|
540
540
|
{
|
|
541
541
|
txGraphVersion: e.vaultCoreVersion,
|
|
542
542
|
depositor: e.depositor,
|
|
@@ -555,35 +555,35 @@ async function ct(e) {
|
|
|
555
555
|
payoutControlBlock: t.payoutControlBlock
|
|
556
556
|
};
|
|
557
557
|
}
|
|
558
|
-
const he = 253,
|
|
559
|
-
function
|
|
558
|
+
const he = 253, ht = 254, dt = 65535, pt = 4294967295, Pt = "TapLeaf", ft = "TapBranch", gt = "TapTweak", T = 33, O = 32, de = 128, wt = 1, vt = 254, Et = a.from([81, 32]);
|
|
559
|
+
function yt(e) {
|
|
560
560
|
if (e < he)
|
|
561
561
|
return a.from([e]);
|
|
562
|
-
if (e <=
|
|
562
|
+
if (e <= dt) {
|
|
563
563
|
const t = a.alloc(2);
|
|
564
564
|
return t.writeUInt16LE(e), a.concat([a.from([he]), t]);
|
|
565
565
|
}
|
|
566
|
-
if (e <=
|
|
566
|
+
if (e <= pt) {
|
|
567
567
|
const t = a.alloc(4);
|
|
568
|
-
return t.writeUInt32LE(e), a.concat([a.from([
|
|
568
|
+
return t.writeUInt32LE(e), a.concat([a.from([ht]), t]);
|
|
569
569
|
}
|
|
570
570
|
throw new Error(`Script too large to encode as CompactSize: ${e} bytes`);
|
|
571
571
|
}
|
|
572
|
-
function
|
|
572
|
+
function Ae(e, t) {
|
|
573
573
|
const o = a.concat([
|
|
574
574
|
a.from([e]),
|
|
575
|
-
|
|
575
|
+
yt(t.length),
|
|
576
576
|
a.from(t)
|
|
577
577
|
]);
|
|
578
|
-
return U.taggedHash(
|
|
578
|
+
return U.taggedHash(Pt, o);
|
|
579
579
|
}
|
|
580
|
-
function
|
|
580
|
+
function $t(e) {
|
|
581
581
|
const { leafVersion: t, script: o, controlBlock: n } = e, r = n.length - T;
|
|
582
582
|
if (r < 0 || r % O !== 0 || r / O > de)
|
|
583
583
|
throw new Error(
|
|
584
584
|
`Malformed Taproot control block: length ${n.length} must be ${T} + 32*m with 0 <= m <= ${de}`
|
|
585
585
|
);
|
|
586
|
-
const i = n[0] &
|
|
586
|
+
const i = n[0] & vt;
|
|
587
587
|
if (i !== t)
|
|
588
588
|
throw new Error(
|
|
589
589
|
`Taproot control block leaf version 0x${i.toString(16)} does not match the tapLeafScript leaf version 0x${t.toString(16)}`
|
|
@@ -591,36 +591,36 @@ function Et(e) {
|
|
|
591
591
|
const s = a.from(
|
|
592
592
|
n.subarray(1, T)
|
|
593
593
|
);
|
|
594
|
-
let u =
|
|
594
|
+
let u = Ae(t, o);
|
|
595
595
|
for (let h = T; h < n.length; h += O) {
|
|
596
596
|
const d = a.from(
|
|
597
597
|
n.subarray(h, h + O)
|
|
598
598
|
);
|
|
599
599
|
u = U.taggedHash(
|
|
600
|
-
|
|
600
|
+
ft,
|
|
601
601
|
a.compare(u, d) <= 0 ? a.concat([u, d]) : a.concat([d, u])
|
|
602
602
|
);
|
|
603
603
|
}
|
|
604
604
|
const c = U.taggedHash(
|
|
605
|
-
|
|
605
|
+
gt,
|
|
606
606
|
a.concat([s, u])
|
|
607
|
-
), p =
|
|
607
|
+
), p = Ie.xOnlyPointAddTweak(s, c);
|
|
608
608
|
if (p === null)
|
|
609
609
|
throw new Error(
|
|
610
610
|
"Taproot control block does not yield a valid output key (tweak is off-curve)"
|
|
611
611
|
);
|
|
612
|
-
const l = n[0] &
|
|
612
|
+
const l = n[0] & wt;
|
|
613
613
|
if (p.parity !== l)
|
|
614
614
|
throw new Error(
|
|
615
615
|
`Taproot output key parity ${p.parity} contradicts the control block's parity bit ${l}`
|
|
616
616
|
);
|
|
617
617
|
return a.concat([
|
|
618
|
-
|
|
618
|
+
Et,
|
|
619
619
|
a.from(p.xOnlyPubkey)
|
|
620
620
|
]);
|
|
621
621
|
}
|
|
622
|
-
const
|
|
623
|
-
function
|
|
622
|
+
const mt = 256, St = 1500, pe = 256, Pe = 0xffffffffn, xt = 500, Ct = 55, bt = 34;
|
|
623
|
+
function kt(e) {
|
|
624
624
|
if (typeof e.protocolFeeRate != "bigint" || e.protocolFeeRate <= 0n || e.protocolFeeRate > Pe)
|
|
625
625
|
throw new Error(
|
|
626
626
|
`protocolFeeRate must be in [1, ${Pe}] sat/vB, got ${e.protocolFeeRate}`
|
|
@@ -629,13 +629,13 @@ function Ct(e) {
|
|
|
629
629
|
[
|
|
630
630
|
"keepers",
|
|
631
631
|
e.numVaultKeepers,
|
|
632
|
-
|
|
632
|
+
mt,
|
|
633
633
|
"fee-floor model limit"
|
|
634
634
|
],
|
|
635
635
|
[
|
|
636
636
|
"challengers",
|
|
637
637
|
e.numUniversalChallengers,
|
|
638
|
-
|
|
638
|
+
St,
|
|
639
639
|
"protocol maximum"
|
|
640
640
|
]
|
|
641
641
|
])
|
|
@@ -648,13 +648,13 @@ function Ct(e) {
|
|
|
648
648
|
`councilSize must be an integer in [1, ${pe}], got ${e.councilSize}`
|
|
649
649
|
);
|
|
650
650
|
}
|
|
651
|
-
async function
|
|
652
|
-
const { implicitFeeSats: o, out0Len: n, out1Len: r } = t, i = e.numVaultKeepers + e.numUniversalChallengers, s = BigInt(o), u = Math.max(0, n -
|
|
651
|
+
async function It(e, t) {
|
|
652
|
+
const { implicitFeeSats: o, out0Len: n, out1Len: r } = t, i = e.numVaultKeepers + e.numUniversalChallengers, s = BigInt(o), u = Math.max(0, n - bt), c = xt + Ct * i + u, p = e.protocolFeeRate * BigInt(c);
|
|
653
653
|
if (s > p)
|
|
654
654
|
throw new Error(
|
|
655
655
|
`Payout implicit fee ${o} sats exceeds the safety cap of ${p} sats (${e.protocolFeeRate} sat/vB x ${c} vB for ${i} participants); refusing to sign payout.`
|
|
656
656
|
);
|
|
657
|
-
const l = await
|
|
657
|
+
const l = await Ne(
|
|
658
658
|
e.vaultCoreVersion,
|
|
659
659
|
e.numVaultKeepers,
|
|
660
660
|
e.numUniversalChallengers,
|
|
@@ -669,23 +669,30 @@ async function bt(e, t) {
|
|
|
669
669
|
`Payout implicit fee ${o} sats is below the floor of ${l} sats (the smallest fee any known vault-provider build produces for this shape); refusing to sign payout.`
|
|
670
670
|
);
|
|
671
671
|
}
|
|
672
|
-
const
|
|
673
|
-
function Ot(e) {
|
|
674
|
-
return e.length === kt * 2 && e.startsWith("0014");
|
|
675
|
-
}
|
|
676
|
-
function Vt(e) {
|
|
677
|
-
return e.length === It * 2 && e.startsWith("0020");
|
|
678
|
-
}
|
|
672
|
+
const _t = 22, At = 34, Tt = 34, fe = "5120", Ot = 25, Vt = 23;
|
|
679
673
|
function Lt(e) {
|
|
680
|
-
return e.length === _t * 2 && e.startsWith("
|
|
674
|
+
return e.length === _t * 2 && e.startsWith("0014");
|
|
681
675
|
}
|
|
682
676
|
function Rt(e) {
|
|
683
|
-
return e.length === At * 2 && e.startsWith("
|
|
677
|
+
return e.length === At * 2 && e.startsWith("0020");
|
|
684
678
|
}
|
|
685
679
|
function Kt(e) {
|
|
686
|
-
|
|
680
|
+
if (e.length !== Tt * 2 || !e.startsWith(fe))
|
|
681
|
+
return !1;
|
|
682
|
+
try {
|
|
683
|
+
Xe.utils.lift_x(BigInt(`0x${e.slice(fe.length)}`));
|
|
684
|
+
} catch {
|
|
685
|
+
return !1;
|
|
686
|
+
}
|
|
687
|
+
return !0;
|
|
687
688
|
}
|
|
688
|
-
function
|
|
689
|
+
function Ht(e) {
|
|
690
|
+
return e.length === Ot * 2 && e.startsWith("76a914") && e.endsWith("88ac");
|
|
691
|
+
}
|
|
692
|
+
function Nt(e) {
|
|
693
|
+
return e.length === Vt * 2 && e.startsWith("a914") && e.endsWith("87");
|
|
694
|
+
}
|
|
695
|
+
function ge(e, t) {
|
|
689
696
|
const o = f(e).toLowerCase();
|
|
690
697
|
if (o.length === 0)
|
|
691
698
|
throw new Error(`${t} is empty`);
|
|
@@ -695,13 +702,13 @@ function fe(e, t) {
|
|
|
695
702
|
throw new Error(
|
|
696
703
|
`${t} is an OP_RETURN output, which is provably unspendable`
|
|
697
704
|
);
|
|
698
|
-
if (!
|
|
705
|
+
if (!Kt(o) && !Lt(o) && !Rt(o) && !Ht(o) && !Nt(o))
|
|
699
706
|
throw new Error(
|
|
700
707
|
`${t} is not a standard scriptPubKey (expected P2TR, P2WPKH, P2WSH, P2PKH, or P2SH; got ${o.length / 2} bytes: ${o})`
|
|
701
708
|
);
|
|
702
709
|
}
|
|
703
|
-
const
|
|
704
|
-
async function
|
|
710
|
+
const we = 3;
|
|
711
|
+
async function to(e) {
|
|
705
712
|
const t = {
|
|
706
713
|
vaultCoreVersion: e.vaultCoreVersion,
|
|
707
714
|
numVaultKeepers: e.vaultKeeperBtcPubkeys.length,
|
|
@@ -709,7 +716,7 @@ async function Jt(e) {
|
|
|
709
716
|
councilSize: e.councilMembers.length,
|
|
710
717
|
protocolFeeRate: e.protocolFeeRate
|
|
711
718
|
};
|
|
712
|
-
|
|
719
|
+
kt(t);
|
|
713
720
|
const o = k.fromHex(f(e.payoutTxHex)), n = k.fromHex(f(e.peginTxHex)), r = k.fromHex(f(e.assertTxHex));
|
|
714
721
|
if (o.ins.length !== te)
|
|
715
722
|
throw new Error(
|
|
@@ -723,29 +730,29 @@ async function Jt(e) {
|
|
|
723
730
|
throw new Error(
|
|
724
731
|
`Payout transaction locktime ${o.locktime} must be ${ne}; refusing to sign payout.`
|
|
725
732
|
);
|
|
726
|
-
const i =
|
|
733
|
+
const i = ve(
|
|
727
734
|
o.ins[0],
|
|
728
735
|
0,
|
|
729
736
|
n,
|
|
730
737
|
"PegIn",
|
|
731
|
-
|
|
738
|
+
ze
|
|
732
739
|
);
|
|
733
740
|
if (o.ins[0].sequence !== e.timelockPegin)
|
|
734
741
|
throw new Error(
|
|
735
742
|
`Payout input 0 sequence ${o.ins[0].sequence} must equal the PegIn CSV timelock ${e.timelockPegin}; refusing to sign payout.`
|
|
736
743
|
);
|
|
737
|
-
const s =
|
|
744
|
+
const s = ve(
|
|
738
745
|
o.ins[1],
|
|
739
746
|
1,
|
|
740
747
|
r,
|
|
741
748
|
"Assert",
|
|
742
|
-
|
|
749
|
+
ke
|
|
743
750
|
);
|
|
744
751
|
if (o.ins[1].sequence !== e.timelockAssert)
|
|
745
752
|
throw new Error(
|
|
746
753
|
`Payout input 1 sequence ${o.ins[1].sequence} must equal the Assert CSV timelock ${e.timelockAssert}; refusing to sign payout.`
|
|
747
754
|
);
|
|
748
|
-
const { out0Len: u, out1Len: c } =
|
|
755
|
+
const { out0Len: u, out1Len: c } = Mt(
|
|
749
756
|
o,
|
|
750
757
|
i.value,
|
|
751
758
|
e
|
|
@@ -757,12 +764,12 @@ async function Jt(e) {
|
|
|
757
764
|
`Payout outputs (${l} sats) exceed inputs (${p} sats); invalid transaction.`
|
|
758
765
|
);
|
|
759
766
|
const h = p - l;
|
|
760
|
-
await
|
|
767
|
+
await It(t, {
|
|
761
768
|
implicitFeeSats: h,
|
|
762
769
|
out0Len: u,
|
|
763
770
|
out1Len: c
|
|
764
771
|
});
|
|
765
|
-
const d = await
|
|
772
|
+
const d = await lt({
|
|
766
773
|
vaultCoreVersion: e.vaultCoreVersion,
|
|
767
774
|
depositor: e.depositorBtcPubkey,
|
|
768
775
|
vaultProvider: e.vaultProviderBtcPubkey,
|
|
@@ -770,9 +777,9 @@ async function Jt(e) {
|
|
|
770
777
|
universalChallengers: e.universalChallengerBtcPubkeys,
|
|
771
778
|
timelockPegin: e.timelockPegin,
|
|
772
779
|
network: e.network
|
|
773
|
-
}), P = await
|
|
780
|
+
}), P = await Ut(e, s);
|
|
774
781
|
return {
|
|
775
|
-
psbtHex:
|
|
782
|
+
psbtHex: Bt(
|
|
776
783
|
o,
|
|
777
784
|
i,
|
|
778
785
|
s,
|
|
@@ -781,11 +788,11 @@ async function Jt(e) {
|
|
|
781
788
|
)
|
|
782
789
|
};
|
|
783
790
|
}
|
|
784
|
-
async function
|
|
785
|
-
const { payoutScript: o, payoutControlBlock: n } = await
|
|
791
|
+
async function Ut(e, t) {
|
|
792
|
+
const { payoutScript: o, payoutControlBlock: n } = await Ue({
|
|
786
793
|
txGraphVersion: e.vaultCoreVersion,
|
|
787
794
|
claimer: f(e.claimerBtcPubkey).toLowerCase(),
|
|
788
|
-
localChallengers:
|
|
795
|
+
localChallengers: Qe({
|
|
789
796
|
claimerBtcPubkey: e.claimerBtcPubkey,
|
|
790
797
|
depositorBtcPubkey: e.depositorBtcPubkey,
|
|
791
798
|
vaultProviderBtcPubkey: e.vaultProviderBtcPubkey,
|
|
@@ -799,18 +806,18 @@ async function Ht(e, t) {
|
|
|
799
806
|
(u) => f(u).toLowerCase()
|
|
800
807
|
),
|
|
801
808
|
councilQuorum: e.councilQuorum
|
|
802
|
-
}), r = C(o), i = C(n), s =
|
|
809
|
+
}), r = C(o), i = C(n), s = $t({
|
|
803
810
|
leafVersion: y,
|
|
804
811
|
script: r,
|
|
805
812
|
controlBlock: i
|
|
806
813
|
});
|
|
807
814
|
if (!t.script.equals(s))
|
|
808
815
|
throw new Error(
|
|
809
|
-
`Rebuilt Assert:0 payout leaf does not spend the Assert output being referenced: leaf binds to ${s.toString("hex")}, Assert:${
|
|
816
|
+
`Rebuilt Assert:0 payout leaf does not spend the Assert output being referenced: leaf binds to ${s.toString("hex")}, Assert:${ke} pays ${t.script.toString("hex")}; refusing to sign payout.`
|
|
810
817
|
);
|
|
811
818
|
return { script: r, controlBlock: i };
|
|
812
819
|
}
|
|
813
|
-
function
|
|
820
|
+
function ve(e, t, o, n, r) {
|
|
814
821
|
const i = M(
|
|
815
822
|
new Uint8Array(e.hash).slice().reverse()
|
|
816
823
|
), s = o.getId();
|
|
@@ -825,7 +832,7 @@ function we(e, t, o, n, r) {
|
|
|
825
832
|
);
|
|
826
833
|
return u;
|
|
827
834
|
}
|
|
828
|
-
function
|
|
835
|
+
function Bt(e, t, o, n, r) {
|
|
829
836
|
const i = new H();
|
|
830
837
|
i.setVersion(e.version), i.setLocktime(e.locktime);
|
|
831
838
|
const [s, u] = e.ins;
|
|
@@ -872,16 +879,16 @@ function Nt(e, t, o, n, r) {
|
|
|
872
879
|
});
|
|
873
880
|
return i.toHex();
|
|
874
881
|
}
|
|
875
|
-
function
|
|
882
|
+
function Ee(e, t) {
|
|
876
883
|
const o = f(e).toLowerCase(), n = f(
|
|
877
|
-
|
|
884
|
+
Ce(t)
|
|
878
885
|
).toLowerCase();
|
|
879
886
|
return o === n ? [o] : [o, n];
|
|
880
887
|
}
|
|
881
|
-
function
|
|
888
|
+
function ye(e, t) {
|
|
882
889
|
return t.some((o) => e.equals(a.from(o, "hex")));
|
|
883
890
|
}
|
|
884
|
-
function
|
|
891
|
+
function Mt(e, t, o) {
|
|
885
892
|
const {
|
|
886
893
|
claimerBtcPubkey: n,
|
|
887
894
|
vaultProviderBtcPubkey: r,
|
|
@@ -892,16 +899,16 @@ function Ut(e, t, o) {
|
|
|
892
899
|
vkClaimerPayoutScriptPubKeys: p,
|
|
893
900
|
vpCommissionScriptPubKey: l
|
|
894
901
|
} = o;
|
|
895
|
-
if (!
|
|
902
|
+
if (!qe(u))
|
|
896
903
|
throw new Error("Invalid registeredPayoutScriptPubKey: not valid hex");
|
|
897
904
|
const h = f(n).toLowerCase(), d = f(r).toLowerCase(), P = f(i).toLowerCase(), E = s.map(
|
|
898
905
|
(S) => f(S).toLowerCase()
|
|
899
906
|
);
|
|
900
|
-
let v, g,
|
|
907
|
+
let v, g, $;
|
|
901
908
|
if (h === d)
|
|
902
|
-
v = "vp-claimer", g =
|
|
909
|
+
v = "vp-claimer", g = De, $ = [f(u)];
|
|
903
910
|
else if (h === P)
|
|
904
|
-
v = "depositor-as-claimer", g = ue,
|
|
911
|
+
v = "depositor-as-claimer", g = ue, $ = [f(u)];
|
|
905
912
|
else if (E.includes(h)) {
|
|
906
913
|
v = "vk-claimer", g = ue;
|
|
907
914
|
const S = p[h];
|
|
@@ -909,10 +916,10 @@ function Ut(e, t, o) {
|
|
|
909
916
|
throw new Error(
|
|
910
917
|
`No registered payout script resolved for vault keeper claimer ${h}`
|
|
911
918
|
);
|
|
912
|
-
|
|
919
|
+
ge(
|
|
913
920
|
S,
|
|
914
921
|
`Vault keeper payout script for claimer ${h}`
|
|
915
|
-
),
|
|
922
|
+
), $ = Ee(S, h);
|
|
916
923
|
} else
|
|
917
924
|
throw new Error(
|
|
918
925
|
`Unknown claimer pubkey ${h}: not VP, depositor, or a registered vault keeper`
|
|
@@ -921,9 +928,9 @@ function Ut(e, t, o) {
|
|
|
921
928
|
throw new Error(
|
|
922
929
|
`Payout transaction has ${e.outs.length} output(s), expected exactly ${g} for role ${v}.`
|
|
923
930
|
);
|
|
924
|
-
if (!
|
|
931
|
+
if (!ye(e.outs[0].script, $))
|
|
925
932
|
throw new Error(
|
|
926
|
-
`Payout transaction output 0 does not pay the expected scriptPubKey for role ${v}. Accepted: ${
|
|
933
|
+
`Payout transaction output 0 does not pay the expected scriptPubKey for role ${v}. Accepted: ${$.join(" or ")}; got ${e.outs[0].script.toString("hex")}`
|
|
927
934
|
);
|
|
928
935
|
const N = g - 1;
|
|
929
936
|
if (e.outs[N].value !== re)
|
|
@@ -931,15 +938,15 @@ function Ut(e, t, o) {
|
|
|
931
938
|
`Payout CPFP anchor (out ${N}) value ${e.outs[N].value} sats must equal ${re} sats`
|
|
932
939
|
);
|
|
933
940
|
if (v === "vp-claimer") {
|
|
934
|
-
|
|
941
|
+
ge(
|
|
935
942
|
l,
|
|
936
943
|
"Vault provider commission payout script"
|
|
937
944
|
);
|
|
938
|
-
const S =
|
|
945
|
+
const S = Ee(
|
|
939
946
|
l,
|
|
940
947
|
d
|
|
941
948
|
);
|
|
942
|
-
if (!
|
|
949
|
+
if (!ye(e.outs[1].script, S))
|
|
943
950
|
throw new Error(
|
|
944
951
|
`Payout transaction output 1 does not pay the vault provider's commission scriptPubKey. Accepted: ${S.join(" or ")}; got ${e.outs[1].script.toString("hex")}`
|
|
945
952
|
);
|
|
@@ -948,7 +955,7 @@ function Ut(e, t, o) {
|
|
|
948
955
|
`commissionBps must be an integer in [0, ${ie}), got ${c}`
|
|
949
956
|
);
|
|
950
957
|
const F = Math.floor(
|
|
951
|
-
t * c /
|
|
958
|
+
t * c / Ye
|
|
952
959
|
);
|
|
953
960
|
if (e.outs[1].value > F)
|
|
954
961
|
throw new Error(
|
|
@@ -960,10 +967,10 @@ function Ut(e, t, o) {
|
|
|
960
967
|
throw new Error(
|
|
961
968
|
`Payout receiver scriptPubKey length ${A} is outside the contract's registration cap [1, ${se}]; refusing to sign payout.`
|
|
962
969
|
);
|
|
963
|
-
const
|
|
964
|
-
return { out0Len: A, out1Len:
|
|
970
|
+
const Te = v === "vp-claimer" ? e.outs[1].script.length : void 0;
|
|
971
|
+
return { out0Len: A, out1Len: Te };
|
|
965
972
|
}
|
|
966
|
-
function
|
|
973
|
+
function oo(e, t, o = 0) {
|
|
967
974
|
const n = H.fromHex(e);
|
|
968
975
|
if (o >= n.data.inputs.length)
|
|
969
976
|
throw new Error(
|
|
@@ -974,24 +981,24 @@ function eo(e, t, o = 0) {
|
|
|
974
981
|
const i = C(t);
|
|
975
982
|
for (const s of r.tapScriptSig)
|
|
976
983
|
if (s.pubkey.equals(a.from(i)))
|
|
977
|
-
return
|
|
984
|
+
return $e(s.signature, o);
|
|
978
985
|
throw new Error(
|
|
979
986
|
`No signature found for depositor pubkey: ${t} at input ${o}`
|
|
980
987
|
);
|
|
981
988
|
}
|
|
982
989
|
if (r.finalScriptWitness && r.finalScriptWitness.length > 0) {
|
|
983
|
-
const i =
|
|
984
|
-
if (i.length !==
|
|
990
|
+
const i = Ft(r.finalScriptWitness);
|
|
991
|
+
if (i.length !== we)
|
|
985
992
|
throw new Error(
|
|
986
|
-
`Unexpected finalized witness stack size at input ${o}: expected ${
|
|
993
|
+
`Unexpected finalized witness stack size at input ${o}: expected ${we} items (signature, script, controlBlock), got ${i.length}`
|
|
987
994
|
);
|
|
988
|
-
return
|
|
995
|
+
return $e(i[0], o);
|
|
989
996
|
}
|
|
990
997
|
throw new Error(
|
|
991
998
|
`No tapScriptSig or finalScriptWitness found in signed PSBT at input ${o}`
|
|
992
999
|
);
|
|
993
1000
|
}
|
|
994
|
-
function
|
|
1001
|
+
function $e(e, t) {
|
|
995
1002
|
if (e.length === 64)
|
|
996
1003
|
return M(new Uint8Array(e));
|
|
997
1004
|
throw e.length === 65 ? new Error(
|
|
@@ -1000,7 +1007,7 @@ function ye(e, t) {
|
|
|
1000
1007
|
`Unexpected signature length at input ${t}: ${e.length}`
|
|
1001
1008
|
);
|
|
1002
1009
|
}
|
|
1003
|
-
function
|
|
1010
|
+
function Ft(e) {
|
|
1004
1011
|
const t = [];
|
|
1005
1012
|
let o = 0;
|
|
1006
1013
|
const n = (s) => {
|
|
@@ -1036,7 +1043,7 @@ function Bt(e) {
|
|
|
1036
1043
|
);
|
|
1037
1044
|
return t;
|
|
1038
1045
|
}
|
|
1039
|
-
class
|
|
1046
|
+
class m extends Error {
|
|
1040
1047
|
constructor(t) {
|
|
1041
1048
|
super(
|
|
1042
1049
|
`Wallet returned a PSBT for a different transaction: ${t}`
|
|
@@ -1051,60 +1058,60 @@ function me(e, t) {
|
|
|
1051
1058
|
throw new Error(`Failed to parse ${e} PSBT: ${n}`);
|
|
1052
1059
|
}
|
|
1053
1060
|
}
|
|
1054
|
-
const
|
|
1061
|
+
const qt = 8;
|
|
1055
1062
|
function B(e) {
|
|
1056
|
-
return `${e.toString("hex").slice(0,
|
|
1063
|
+
return `${e.toString("hex").slice(0, qt)}…`;
|
|
1057
1064
|
}
|
|
1058
|
-
function
|
|
1065
|
+
function Se(e) {
|
|
1059
1066
|
const t = a.from(e).reverse();
|
|
1060
1067
|
return B(t);
|
|
1061
1068
|
}
|
|
1062
|
-
function
|
|
1069
|
+
function no(e) {
|
|
1063
1070
|
const t = me("requested", e.requestedPsbtHex), o = me("returned", e.returnedPsbtHex);
|
|
1064
1071
|
if (t.version !== o.version)
|
|
1065
|
-
throw new
|
|
1072
|
+
throw new m(
|
|
1066
1073
|
`tx version differs (requested=${t.version}, returned=${o.version})`
|
|
1067
1074
|
);
|
|
1068
1075
|
if (t.locktime !== o.locktime)
|
|
1069
|
-
throw new
|
|
1076
|
+
throw new m(
|
|
1070
1077
|
`tx locktime differs (requested=${t.locktime}, returned=${o.locktime})`
|
|
1071
1078
|
);
|
|
1072
1079
|
if (t.txInputs.length !== o.txInputs.length)
|
|
1073
|
-
throw new
|
|
1080
|
+
throw new m(
|
|
1074
1081
|
`input count differs (requested=${t.txInputs.length}, returned=${o.txInputs.length})`
|
|
1075
1082
|
);
|
|
1076
1083
|
if (t.txOutputs.length !== o.txOutputs.length)
|
|
1077
|
-
throw new
|
|
1084
|
+
throw new m(
|
|
1078
1085
|
`output count differs (requested=${t.txOutputs.length}, returned=${o.txOutputs.length})`
|
|
1079
1086
|
);
|
|
1080
1087
|
for (let n = 0; n < t.txInputs.length; n++) {
|
|
1081
1088
|
const r = t.txInputs[n], i = o.txInputs[n];
|
|
1082
1089
|
if (!r.hash.equals(i.hash))
|
|
1083
|
-
throw new
|
|
1084
|
-
`input ${n} prevout txid differs (requested=${
|
|
1090
|
+
throw new m(
|
|
1091
|
+
`input ${n} prevout txid differs (requested=${Se(r.hash)}, returned=${Se(i.hash)})`
|
|
1085
1092
|
);
|
|
1086
1093
|
if (r.index !== i.index)
|
|
1087
|
-
throw new
|
|
1094
|
+
throw new m(
|
|
1088
1095
|
`input ${n} prevout vout differs (requested=${r.index}, returned=${i.index})`
|
|
1089
1096
|
);
|
|
1090
1097
|
if (r.sequence !== i.sequence)
|
|
1091
|
-
throw new
|
|
1098
|
+
throw new m(
|
|
1092
1099
|
`input ${n} sequence differs (requested=${r.sequence}, returned=${i.sequence})`
|
|
1093
1100
|
);
|
|
1094
1101
|
}
|
|
1095
1102
|
for (let n = 0; n < t.txOutputs.length; n++) {
|
|
1096
1103
|
const r = t.txOutputs[n], i = o.txOutputs[n];
|
|
1097
1104
|
if (!r.script.equals(i.script))
|
|
1098
|
-
throw new
|
|
1105
|
+
throw new m(
|
|
1099
1106
|
`output ${n} scriptPubKey differs (requested=${B(r.script)}, returned=${B(i.script)})`
|
|
1100
1107
|
);
|
|
1101
1108
|
if (r.value !== i.value)
|
|
1102
|
-
throw new
|
|
1109
|
+
throw new m(
|
|
1103
1110
|
`output ${n} value differs (requested=${r.value}, returned=${i.value})`
|
|
1104
1111
|
);
|
|
1105
1112
|
}
|
|
1106
1113
|
}
|
|
1107
|
-
function
|
|
1114
|
+
function ro(e) {
|
|
1108
1115
|
const { requestedPsbtHex: t, signatureHex: o, signerXOnlyPubkeyHex: n, inputIndex: r } = e, i = f(o);
|
|
1109
1116
|
if (i.length !== W)
|
|
1110
1117
|
throw new Error(
|
|
@@ -1122,12 +1129,12 @@ function oo(e) {
|
|
|
1122
1129
|
);
|
|
1123
1130
|
const c = [], p = [];
|
|
1124
1131
|
for (let g = 0; g < u.data.inputs.length; g++) {
|
|
1125
|
-
const
|
|
1126
|
-
if (
|
|
1132
|
+
const $ = u.data.inputs[g].witnessUtxo;
|
|
1133
|
+
if (!$)
|
|
1127
1134
|
throw new Error(
|
|
1128
1135
|
`Cannot verify signature: input ${g} of the requested PSBT has no witnessUtxo (required to recompute the Taproot sighash).`
|
|
1129
1136
|
);
|
|
1130
|
-
c.push(
|
|
1137
|
+
c.push($.script), p.push($.value);
|
|
1131
1138
|
}
|
|
1132
1139
|
const l = u.data.inputs[r].tapLeafScript;
|
|
1133
1140
|
if (!l || l.length !== 1)
|
|
@@ -1139,7 +1146,7 @@ function oo(e) {
|
|
|
1139
1146
|
throw new Error(
|
|
1140
1147
|
`Cannot verify signature: input ${r} tapLeafScript has leaf version 0x${h.leafVersion.toString(16)}, expected 0x${y.toString(16)}.`
|
|
1141
1148
|
);
|
|
1142
|
-
const d =
|
|
1149
|
+
const d = Ae(h.leafVersion, h.script), P = new k();
|
|
1143
1150
|
P.version = u.version, P.locktime = u.locktime;
|
|
1144
1151
|
for (const g of u.txInputs)
|
|
1145
1152
|
P.addInput(g.hash, g.index, g.sequence);
|
|
@@ -1152,7 +1159,7 @@ function oo(e) {
|
|
|
1152
1159
|
k.SIGHASH_DEFAULT,
|
|
1153
1160
|
d
|
|
1154
1161
|
);
|
|
1155
|
-
if (!
|
|
1162
|
+
if (!Ie.verifySchnorr(
|
|
1156
1163
|
E,
|
|
1157
1164
|
C(s),
|
|
1158
1165
|
C(i)
|
|
@@ -1163,24 +1170,25 @@ function oo(e) {
|
|
|
1163
1170
|
}
|
|
1164
1171
|
export {
|
|
1165
1172
|
V as H,
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1173
|
+
it as P,
|
|
1174
|
+
Jt as a,
|
|
1175
|
+
eo as b,
|
|
1176
|
+
jt as c,
|
|
1177
|
+
st as d,
|
|
1178
|
+
ut as e,
|
|
1179
|
+
to as f,
|
|
1180
|
+
oo as g,
|
|
1181
|
+
m as h,
|
|
1182
|
+
no as i,
|
|
1183
|
+
ro as j,
|
|
1184
|
+
lt as k,
|
|
1185
|
+
et as l,
|
|
1186
|
+
Ae as m,
|
|
1187
|
+
_e as n,
|
|
1188
|
+
nt as o,
|
|
1189
|
+
kt as p,
|
|
1190
|
+
It as q,
|
|
1191
|
+
Qe as r,
|
|
1192
|
+
ge as s
|
|
1185
1193
|
};
|
|
1186
|
-
//# sourceMappingURL=verifyScriptPathSchnorrSignature-
|
|
1194
|
+
//# sourceMappingURL=verifyScriptPathSchnorrSignature-DLNGgm4j.js.map
|