@babylonlabs-io/ts-sdk 0.57.1 → 0.58.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/{PeginManager-CnX3uFb0.js → PeginManager-C8ixWlUM.js} +319 -298
- package/dist/PeginManager-C8ixWlUM.js.map +1 -0
- package/dist/PeginManager-CogqZaa2.cjs +2 -0
- package/dist/PeginManager-CogqZaa2.cjs.map +1 -0
- package/dist/{batchPoll-DTYXoTEc.js → batchPoll-B0VxT62K.js} +4 -4
- package/dist/{batchPoll-DTYXoTEc.js.map → batchPoll-B0VxT62K.js.map} +1 -1
- package/dist/{batchPoll-BXIy3R7h.cjs → batchPoll-D5IDDOa8.cjs} +2 -2
- package/dist/{batchPoll-BXIy3R7h.cjs.map → batchPoll-D5IDDOa8.cjs.map} +1 -1
- package/dist/{bitcoin-B5aNKtsk.js → bitcoin-d9eaaZB_.js} +49 -46
- package/dist/bitcoin-d9eaaZB_.js.map +1 -0
- package/dist/bitcoin-m84N5a8o.cjs +2 -0
- package/dist/bitcoin-m84N5a8o.cjs.map +1 -0
- package/dist/buildAndBroadcastRefund-BL8u-Ti4.cjs +2 -0
- package/dist/buildAndBroadcastRefund-BL8u-Ti4.cjs.map +1 -0
- package/dist/{buildAndBroadcastRefund-Bo3AlqCk.js → buildAndBroadcastRefund-DBA-Mp4I.js} +557 -484
- package/dist/buildAndBroadcastRefund-DBA-Mp4I.js.map +1 -0
- package/dist/{challengeAssert-Cu-PtJ1g.cjs → challengeAssert-BFRE2DM-.cjs} +2 -2
- package/dist/{challengeAssert-Cu-PtJ1g.cjs.map → challengeAssert-BFRE2DM-.cjs.map} +1 -1
- package/dist/{challengeAssert-BVQq50su.js → challengeAssert-C7PzyJ7g.js} +2 -2
- package/dist/{challengeAssert-BVQq50su.js.map → challengeAssert-C7PzyJ7g.js.map} +1 -1
- package/dist/constants-DU5CGcqO.cjs +2 -0
- package/dist/{constants-BqU1Uz15.cjs.map → constants-DU5CGcqO.cjs.map} +1 -1
- package/dist/constants-GjWXdaqV.js +23 -0
- package/dist/{constants-CDQE812z.js.map → constants-GjWXdaqV.js.map} +1 -1
- package/dist/{deriveVaultRoot-B_gEOTD6.js → deriveVaultRoot-D0RY5GJc.js} +2 -2
- package/dist/{deriveVaultRoot-B_gEOTD6.js.map → deriveVaultRoot-D0RY5GJc.js.map} +1 -1
- package/dist/{deriveVaultRoot-CebLadyJ.cjs → deriveVaultRoot-p4uGsM7w.cjs} +2 -2
- package/dist/{deriveVaultRoot-CebLadyJ.cjs.map → deriveVaultRoot-p4uGsM7w.cjs.map} +1 -1
- package/dist/errors-2aF9oRwM.cjs +2 -0
- package/dist/errors-2aF9oRwM.cjs.map +1 -0
- package/dist/errors-kXGQXKxZ.js +28 -0
- package/dist/errors-kXGQXKxZ.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +188 -180
- package/dist/{mempoolApi-C0olk43O.js → mempoolApi-CMHEz4ez.js} +3 -3
- package/dist/{mempoolApi-C0olk43O.js.map → mempoolApi-CMHEz4ez.js.map} +1 -1
- package/dist/{mempoolApi-Dsm2VPXp.cjs → mempoolApi-DfD3_Y6v.cjs} +2 -2
- package/dist/{mempoolApi-Dsm2VPXp.cjs.map → mempoolApi-DfD3_Y6v.cjs.map} +1 -1
- package/dist/{noPayout-CI4l1qu2.js → noPayout-DuE-UyhQ.js} +5 -5
- package/dist/{noPayout-CI4l1qu2.js.map → noPayout-DuE-UyhQ.js.map} +1 -1
- package/dist/{noPayout-Djrv31V5.cjs → noPayout-qUEtRKc_.cjs} +2 -2
- package/dist/{noPayout-Djrv31V5.cjs.map → noPayout-qUEtRKc_.cjs.map} +1 -1
- package/dist/{onChainBtcPubkey-Cd9kpz-S.cjs → onChainBtcPubkey-C_a2L3kL.cjs} +2 -2
- package/dist/{onChainBtcPubkey-Cd9kpz-S.cjs.map → onChainBtcPubkey-C_a2L3kL.cjs.map} +1 -1
- package/dist/{onChainBtcPubkey-aPY5ib3Q.js → onChainBtcPubkey-DeF4cKoO.js} +2 -2
- package/dist/{onChainBtcPubkey-aPY5ib3Q.js.map → onChainBtcPubkey-DeF4cKoO.js.map} +1 -1
- package/dist/peginInput-Ci921gTl.cjs +2 -0
- package/dist/peginInput-Ci921gTl.cjs.map +1 -0
- package/dist/peginInput-HQPWZfly.js +123 -0
- package/dist/peginInput-HQPWZfly.js.map +1 -0
- package/dist/{reservation-cHDRn4DA.js → reservation-CbAXa7VG.js} +2 -2
- package/dist/{reservation-cHDRn4DA.js.map → reservation-CbAXa7VG.js.map} +1 -1
- package/dist/{reservation-ClEs2X0H.cjs → reservation-RGKvg2x6.cjs} +2 -2
- package/dist/{reservation-ClEs2X0H.cjs.map → reservation-RGKvg2x6.cjs.map} +1 -1
- package/dist/signPsbtsWithFallback-Xs4jZw5z.cjs +2 -0
- package/dist/signPsbtsWithFallback-Xs4jZw5z.cjs.map +1 -0
- package/dist/{signPsbtsWithFallback-CzZFZf0I.js → signPsbtsWithFallback-eY1YgV13.js} +69 -67
- package/dist/signPsbtsWithFallback-eY1YgV13.js.map +1 -0
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +3 -3
- package/dist/tbv/core/deposit-terms/__tests__/depositTermsErrors.test.d.ts +2 -0
- package/dist/tbv/core/deposit-terms/__tests__/depositTermsErrors.test.d.ts.map +1 -0
- package/dist/tbv/core/deposit-terms/buildDepositTerms.d.ts.map +1 -1
- package/dist/tbv/core/deposit-terms/depositTerms.d.ts +72 -25
- package/dist/tbv/core/deposit-terms/depositTerms.d.ts.map +1 -1
- package/dist/tbv/core/deposit-terms/depositTermsErrors.d.ts +24 -0
- package/dist/tbv/core/deposit-terms/depositTermsErrors.d.ts.map +1 -0
- package/dist/tbv/core/deposit-terms/index.d.ts +2 -1
- package/dist/tbv/core/deposit-terms/index.d.ts.map +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +179 -171
- package/dist/tbv/core/managers/PayoutManager.d.ts +2 -0
- package/dist/tbv/core/managers/PayoutManager.d.ts.map +1 -1
- package/dist/tbv/core/managers/PeginManager.d.ts +16 -3
- package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
- 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.d.ts +1 -1
- package/dist/tbv/core/primitives/index.d.ts.map +1 -1
- package/dist/tbv/core/primitives/index.js +16 -15
- package/dist/tbv/core/primitives/psbt/assertPayoutFeeBand.d.ts +14 -32
- package/dist/tbv/core/primitives/psbt/assertPayoutFeeBand.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/constants.d.ts +10 -1
- package/dist/tbv/core/primitives/psbt/constants.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/payout.d.ts +8 -2
- package/dist/tbv/core/primitives/psbt/payout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/peginInput.d.ts.map +1 -1
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts +25 -1
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts +1 -1
- package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts +1 -1
- package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/validateOnChainParticipantKeys.d.ts.map +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +35 -31
- package/dist/tbv/core/services/participants/__tests__/indexerKeyHint.test.d.ts +9 -0
- package/dist/tbv/core/services/participants/__tests__/indexerKeyHint.test.d.ts.map +1 -0
- package/dist/tbv/core/services/participants/index.d.ts +2 -0
- package/dist/tbv/core/services/participants/index.d.ts.map +1 -1
- package/dist/tbv/core/services/participants/indexerKeyHint.d.ts +61 -0
- package/dist/tbv/core/services/participants/indexerKeyHint.d.ts.map +1 -0
- package/dist/tbv/core/utils/index.cjs +1 -1
- package/dist/tbv/core/utils/index.js +3 -3
- package/dist/tbv/core/vault-secrets/index.cjs +1 -1
- package/dist/tbv/core/vault-secrets/index.js +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +179 -171
- package/dist/testing/index.cjs +1 -1
- package/dist/testing/index.js +1 -1
- package/dist/{verifyScriptPathSchnorrSignature-Xoo9DOHW.js → verifyScriptPathSchnorrSignature-Bav08_7R.js} +268 -240
- package/dist/verifyScriptPathSchnorrSignature-Bav08_7R.js.map +1 -0
- package/dist/verifyScriptPathSchnorrSignature-CYjK4IP_.cjs +2 -0
- package/dist/verifyScriptPathSchnorrSignature-CYjK4IP_.cjs.map +1 -0
- package/package.json +1 -1
- package/dist/PeginManager-CnX3uFb0.js.map +0 -1
- package/dist/PeginManager-iDbqXsKD.cjs +0 -2
- package/dist/PeginManager-iDbqXsKD.cjs.map +0 -1
- package/dist/bitcoin-B5aNKtsk.js.map +0 -1
- package/dist/bitcoin-CHfKAhcI.cjs +0 -2
- package/dist/bitcoin-CHfKAhcI.cjs.map +0 -1
- package/dist/buildAndBroadcastRefund-4uAl7OIk.cjs +0 -2
- package/dist/buildAndBroadcastRefund-4uAl7OIk.cjs.map +0 -1
- package/dist/buildAndBroadcastRefund-Bo3AlqCk.js.map +0 -1
- package/dist/constants-BqU1Uz15.cjs +0 -2
- package/dist/constants-CDQE812z.js +0 -21
- package/dist/errors-B-H0seUG.js +0 -8
- package/dist/errors-B-H0seUG.js.map +0 -1
- package/dist/errors-Bfjxg_iJ.cjs +0 -2
- package/dist/errors-Bfjxg_iJ.cjs.map +0 -1
- package/dist/peginInput-BKD_b3gq.js +0 -105
- package/dist/peginInput-BKD_b3gq.js.map +0 -1
- package/dist/peginInput-CAiiDZeO.cjs +0 -2
- package/dist/peginInput-CAiiDZeO.cjs.map +0 -1
- package/dist/signPsbtsWithFallback-C01N6Kdo.cjs +0 -2
- package/dist/signPsbtsWithFallback-C01N6Kdo.cjs.map +0 -1
- package/dist/signPsbtsWithFallback-CzZFZf0I.js.map +0 -1
- package/dist/verifyScriptPathSchnorrSignature-C-84KJ6U.cjs +0 -2
- package/dist/verifyScriptPathSchnorrSignature-C-84KJ6U.cjs.map +0 -1
- package/dist/verifyScriptPathSchnorrSignature-Xoo9DOHW.js.map +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { computeMinClaimValue as
|
|
1
|
+
import { computeMinClaimValue as J, peginP2aAnchorOutput as ee, computeMinPeginFee as re, buildPeginTxFromPrePegin as ie, createPrePeginTransaction as se, validatePeginP2aAnchor as ue, tapInternalPubkey as te, createPayoutConnector as ce, computePayoutFeeFloor as ae } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
2
2
|
import { Buffer as p } from "buffer";
|
|
3
|
-
import { Transaction as
|
|
4
|
-
import { c as V, d as
|
|
5
|
-
import { s as g, u as _, h as y,
|
|
6
|
-
import { D as
|
|
7
|
-
import * as
|
|
3
|
+
import { Transaction as x, script as le, opcodes as he, payments as de, Psbt as C, crypto as pe } from "bitcoinjs-lib";
|
|
4
|
+
import { c as V, d as Pe } from "./fundPeginTransaction-B2wyjqp0.js";
|
|
5
|
+
import { s as g, u as _, h as y, j as ge, T as b, d as fe, S as T, X as H } from "./bitcoin-d9eaaZB_.js";
|
|
6
|
+
import { D as O, P as L, b as R, c as U, M as K, d as N, e as we, A as ve, B as $e, V as Se, N as F } from "./constants-GjWXdaqV.js";
|
|
7
|
+
import * as me from "@bitcoin-js/tiny-secp256k1-asmjs";
|
|
8
8
|
async function xe(e, t) {
|
|
9
9
|
const n = t.pegInAmounts.length;
|
|
10
10
|
if (e.htlcValues.length !== n)
|
|
@@ -19,7 +19,7 @@ async function xe(e, t) {
|
|
|
19
19
|
throw new Error(
|
|
20
20
|
`WASM Pre-PegIn returned non-positive depositorClaimValue ${e.depositorClaimValue}; expected > 0.`
|
|
21
21
|
);
|
|
22
|
-
const
|
|
22
|
+
const o = await J(
|
|
23
23
|
// Must price the same graph version the builder constructed.
|
|
24
24
|
t.vaultCoreVersion,
|
|
25
25
|
t.numLocalChallengers,
|
|
@@ -28,11 +28,11 @@ async function xe(e, t) {
|
|
|
28
28
|
t.councilSize,
|
|
29
29
|
t.feeRate
|
|
30
30
|
);
|
|
31
|
-
if (e.depositorClaimValue !==
|
|
31
|
+
if (e.depositorClaimValue !== o)
|
|
32
32
|
throw new Error(
|
|
33
|
-
`WASM Pre-PegIn depositorClaimValue ${e.depositorClaimValue} does not match the independently computed minimum claim value ${
|
|
33
|
+
`WASM Pre-PegIn depositorClaimValue ${e.depositorClaimValue} does not match the independently computed minimum claim value ${o} (vaultCoreVersion=${t.vaultCoreVersion}, numLocalChallengers=${t.numLocalChallengers}, numUniversalChallengers=${t.universalChallengerPubkeys.length}, councilQuorum=${t.councilQuorum}, councilSize=${t.councilSize}, feeRate=${t.feeRate}).`
|
|
34
34
|
);
|
|
35
|
-
const
|
|
35
|
+
const r = await ee(t.vaultCoreVersion), i = (r == null ? void 0 : r.value) ?? 0n, s = await re(
|
|
36
36
|
t.vaultCoreVersion,
|
|
37
37
|
t.vaultKeeperPubkeys.length,
|
|
38
38
|
t.universalChallengerPubkeys.length,
|
|
@@ -68,27 +68,27 @@ async function xe(e, t) {
|
|
|
68
68
|
}
|
|
69
69
|
return s;
|
|
70
70
|
}
|
|
71
|
-
function
|
|
71
|
+
function ye(e, t, n) {
|
|
72
72
|
if (e.length < t.length)
|
|
73
73
|
throw new Error(
|
|
74
74
|
`Encoded Pre-PegIn tx has ${e.length} output(s), fewer than the ${t.length} HTLC output(s) the cross-check validated.`
|
|
75
75
|
);
|
|
76
|
-
for (let
|
|
77
|
-
const
|
|
78
|
-
if (
|
|
76
|
+
for (let o = 0; o < t.length; o++) {
|
|
77
|
+
const r = BigInt(e[o].value);
|
|
78
|
+
if (r !== t[o])
|
|
79
79
|
throw new Error(
|
|
80
|
-
`Encoded Pre-PegIn HTLC output[${
|
|
80
|
+
`Encoded Pre-PegIn HTLC output[${o}] value ${r} does not match the cross-checked htlcValue ${t[o]}; the funded/signed tx would not pay the validated amount.`
|
|
81
81
|
);
|
|
82
|
-
const i = e[
|
|
82
|
+
const i = e[o].script.toString("hex").toLowerCase(), s = n[o].toLowerCase();
|
|
83
83
|
if (i !== s)
|
|
84
84
|
throw new Error(
|
|
85
|
-
`Encoded Pre-PegIn HTLC output[${
|
|
85
|
+
`Encoded Pre-PegIn HTLC output[${o}] scriptPubKey ${i} does not match the cross-checked htlcScriptPubKey ${s}.`
|
|
86
86
|
);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
const
|
|
90
|
-
async function
|
|
91
|
-
const t =
|
|
89
|
+
const q = 64, Ee = /^[0-9a-fA-F]+$/;
|
|
90
|
+
async function at(e) {
|
|
91
|
+
const t = ne(e.authAnchorHash), n = await se({
|
|
92
92
|
txGraphVersion: e.vaultCoreVersion,
|
|
93
93
|
depositorPubkey: e.depositorPubkey,
|
|
94
94
|
vaultProviderPubkey: e.vaultProviderPubkey,
|
|
@@ -104,13 +104,13 @@ async function it(e) {
|
|
|
104
104
|
councilSize: e.councilSize,
|
|
105
105
|
network: e.network,
|
|
106
106
|
authAnchorHash: t
|
|
107
|
-
}),
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
}), o = await xe(n, e), r = Pe(n.txHex);
|
|
108
|
+
ye(
|
|
109
|
+
r.outputs,
|
|
110
110
|
n.htlcValues,
|
|
111
111
|
n.htlcScriptPubKeys
|
|
112
112
|
);
|
|
113
|
-
const i =
|
|
113
|
+
const i = r.outputs.reduce(
|
|
114
114
|
(u, h) => u + BigInt(h.value),
|
|
115
115
|
0n
|
|
116
116
|
), s = t !== void 0 ? n.htlcValues.length : null;
|
|
@@ -123,20 +123,20 @@ async function it(e) {
|
|
|
123
123
|
peginAmounts: n.peginAmounts,
|
|
124
124
|
depositorClaimValue: n.depositorClaimValue,
|
|
125
125
|
authAnchorVout: s,
|
|
126
|
-
minPeginFee:
|
|
126
|
+
minPeginFee: o
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
|
-
function
|
|
129
|
+
function ne(e) {
|
|
130
130
|
if (e === void 0) return;
|
|
131
131
|
const t = e.startsWith("0x") || e.startsWith("0X") ? e.slice(2) : e;
|
|
132
|
-
if (t.length !==
|
|
132
|
+
if (t.length !== q || !Ee.test(t))
|
|
133
133
|
throw new Error(
|
|
134
|
-
`authAnchorHash must be 32-byte hex (${
|
|
134
|
+
`authAnchorHash must be 32-byte hex (${q} chars, no 0x prefix); got length ${t.length}`
|
|
135
135
|
);
|
|
136
136
|
return t.toLowerCase();
|
|
137
137
|
}
|
|
138
|
-
async function
|
|
139
|
-
const t = await
|
|
138
|
+
async function lt(e) {
|
|
139
|
+
const t = await ie(
|
|
140
140
|
{
|
|
141
141
|
txGraphVersion: e.prePeginParams.vaultCoreVersion,
|
|
142
142
|
depositorPubkey: e.prePeginParams.depositorPubkey,
|
|
@@ -152,7 +152,7 @@ async function st(e) {
|
|
|
152
152
|
councilQuorum: e.prePeginParams.councilQuorum,
|
|
153
153
|
councilSize: e.prePeginParams.councilSize,
|
|
154
154
|
network: e.prePeginParams.network,
|
|
155
|
-
authAnchorHash:
|
|
155
|
+
authAnchorHash: ne(
|
|
156
156
|
e.prePeginParams.authAnchorHash
|
|
157
157
|
)
|
|
158
158
|
},
|
|
@@ -160,23 +160,23 @@ async function st(e) {
|
|
|
160
160
|
e.fundedPrePeginTxHex,
|
|
161
161
|
e.htlcVout
|
|
162
162
|
);
|
|
163
|
-
return await
|
|
163
|
+
return await be(t, e), {
|
|
164
164
|
txHex: t.txHex,
|
|
165
165
|
txid: t.txid,
|
|
166
166
|
vaultScriptPubKey: t.vaultScriptPubKey,
|
|
167
167
|
vaultValue: t.vaultValue
|
|
168
168
|
};
|
|
169
169
|
}
|
|
170
|
-
const
|
|
171
|
-
async function
|
|
170
|
+
const Ce = 2, Ae = 1;
|
|
171
|
+
async function be(e, t) {
|
|
172
172
|
const n = t.prePeginParams.vaultCoreVersion;
|
|
173
|
-
await
|
|
174
|
-
const
|
|
173
|
+
await ue(n, e.txHex);
|
|
174
|
+
const o = await ee(n), r = Ce + (o ? 1 : 0), i = x.fromHex(g(e.txHex));
|
|
175
175
|
if (i.ins.length !== 1)
|
|
176
176
|
throw new Error(
|
|
177
177
|
`PegIn tx has ${i.ins.length} input(s), expected exactly 1 (the Pre-PegIn HTLC outpoint).`
|
|
178
178
|
);
|
|
179
|
-
const s =
|
|
179
|
+
const s = x.fromHex(
|
|
180
180
|
g(t.fundedPrePeginTxHex)
|
|
181
181
|
).getId(), u = _(
|
|
182
182
|
new Uint8Array(i.ins[0].hash).slice().reverse()
|
|
@@ -189,9 +189,9 @@ async function Ce(e, t) {
|
|
|
189
189
|
throw new Error(
|
|
190
190
|
`PegIn input spends Pre-PegIn output ${i.ins[0].index}, expected the requested HTLC vout ${t.htlcVout}.`
|
|
191
191
|
);
|
|
192
|
-
if (i.outs.length !==
|
|
192
|
+
if (i.outs.length !== r)
|
|
193
193
|
throw new Error(
|
|
194
|
-
`PegIn tx has ${i.outs.length} output(s), expected exactly ${
|
|
194
|
+
`PegIn tx has ${i.outs.length} output(s), expected exactly ${r} for vaultCoreVersion ${n} (vault + depositor claim${o ? " + P2A anchor" : ""}).`
|
|
195
195
|
);
|
|
196
196
|
const h = t.prePeginParams.pegInAmounts[t.htlcVout];
|
|
197
197
|
if (e.vaultValue !== h)
|
|
@@ -215,32 +215,32 @@ async function Ce(e, t) {
|
|
|
215
215
|
throw new Error(
|
|
216
216
|
`Encoded PegIn txid ${f} does not match the WASM-reported txid ${e.txid}.`
|
|
217
217
|
);
|
|
218
|
-
const d = await
|
|
218
|
+
const d = await J(
|
|
219
219
|
n,
|
|
220
220
|
t.prePeginParams.numLocalChallengers,
|
|
221
221
|
t.prePeginParams.universalChallengerPubkeys.length,
|
|
222
222
|
t.prePeginParams.councilQuorum,
|
|
223
223
|
t.prePeginParams.councilSize,
|
|
224
224
|
t.prePeginParams.feeRate
|
|
225
|
-
),
|
|
226
|
-
if (BigInt(
|
|
225
|
+
), S = i.outs[Ae];
|
|
226
|
+
if (BigInt(S.value) !== d)
|
|
227
227
|
throw new Error(
|
|
228
|
-
`Encoded PegIn depositor-claim output value ${
|
|
228
|
+
`Encoded PegIn depositor-claim output value ${S.value} does not match the independently computed claim value ${d} for vaultCoreVersion ${n}.`
|
|
229
229
|
);
|
|
230
|
-
const
|
|
230
|
+
const w = Ie(
|
|
231
231
|
t.prePeginParams.depositorPubkey
|
|
232
232
|
);
|
|
233
|
-
if (!
|
|
233
|
+
if (!S.script.equals(w))
|
|
234
234
|
throw new Error(
|
|
235
|
-
`Encoded PegIn depositor-claim output scriptPubKey ${
|
|
235
|
+
`Encoded PegIn depositor-claim output scriptPubKey ${S.script.toString("hex")} does not pay to the depositor's claim script (expected ${w.toString("hex")}).`
|
|
236
236
|
);
|
|
237
237
|
}
|
|
238
|
-
function
|
|
239
|
-
const t =
|
|
238
|
+
function Ie(e) {
|
|
239
|
+
const t = le.compile([
|
|
240
240
|
p.from(y(e)),
|
|
241
|
-
|
|
242
|
-
]), { output: n } =
|
|
243
|
-
internalPubkey: p.from(
|
|
241
|
+
he.OP_CHECKSIG
|
|
242
|
+
]), { output: n } = de.p2tr({
|
|
243
|
+
internalPubkey: p.from(te),
|
|
244
244
|
scriptTree: { output: t }
|
|
245
245
|
});
|
|
246
246
|
if (!n)
|
|
@@ -249,8 +249,8 @@ function be(e) {
|
|
|
249
249
|
);
|
|
250
250
|
return n;
|
|
251
251
|
}
|
|
252
|
-
async function
|
|
253
|
-
const t = await
|
|
252
|
+
async function _e(e) {
|
|
253
|
+
const t = await ce(
|
|
254
254
|
{
|
|
255
255
|
txGraphVersion: e.vaultCoreVersion,
|
|
256
256
|
depositor: e.depositor,
|
|
@@ -269,39 +269,49 @@ async function Ae(e) {
|
|
|
269
269
|
payoutControlBlock: t.payoutControlBlock
|
|
270
270
|
};
|
|
271
271
|
}
|
|
272
|
-
const
|
|
273
|
-
function
|
|
274
|
-
if (typeof e.protocolFeeRate != "bigint" || e.protocolFeeRate <= 0n || e.protocolFeeRate >
|
|
272
|
+
const ke = 256, Ve = 1500, B = 256, M = 0xffffffffn, Te = 500, He = 55, Oe = 34;
|
|
273
|
+
function Le(e) {
|
|
274
|
+
if (typeof e.protocolFeeRate != "bigint" || e.protocolFeeRate <= 0n || e.protocolFeeRate > M)
|
|
275
275
|
throw new Error(
|
|
276
|
-
`protocolFeeRate must be in [1, ${
|
|
276
|
+
`protocolFeeRate must be in [1, ${M}] sat/vB, got ${e.protocolFeeRate}`
|
|
277
277
|
);
|
|
278
|
-
for (const [t, n] of [
|
|
279
|
-
[
|
|
280
|
-
|
|
278
|
+
for (const [t, n, o, r] of [
|
|
279
|
+
[
|
|
280
|
+
"keepers",
|
|
281
|
+
e.numVaultKeepers,
|
|
282
|
+
ke,
|
|
283
|
+
"fee-floor model limit"
|
|
284
|
+
],
|
|
285
|
+
[
|
|
286
|
+
"challengers",
|
|
287
|
+
e.numUniversalChallengers,
|
|
288
|
+
Ve,
|
|
289
|
+
"protocol maximum"
|
|
290
|
+
]
|
|
281
291
|
])
|
|
282
|
-
if (!Number.isInteger(n) || n < 1 || n >
|
|
292
|
+
if (!Number.isInteger(n) || n < 1 || n > o)
|
|
283
293
|
throw new Error(
|
|
284
|
-
`Participant count for ${t} (${n}) is outside the
|
|
294
|
+
`Participant count for ${t} (${n}) is outside the supported range [1, ${o}]${n > o ? ` (${r})` : ""}.`
|
|
285
295
|
);
|
|
286
|
-
if (!Number.isInteger(e.councilSize) || e.councilSize < 1)
|
|
296
|
+
if (!Number.isInteger(e.councilSize) || e.councilSize < 1 || e.councilSize > B)
|
|
287
297
|
throw new Error(
|
|
288
|
-
`councilSize must be an integer
|
|
298
|
+
`councilSize must be an integer in [1, ${B}], got ${e.councilSize}`
|
|
289
299
|
);
|
|
290
300
|
}
|
|
291
|
-
async function
|
|
292
|
-
const { implicitFeeSats: n, out0Len:
|
|
301
|
+
async function Re(e, t) {
|
|
302
|
+
const { implicitFeeSats: n, out0Len: o, out1Len: r } = t, i = e.numVaultKeepers + e.numUniversalChallengers, s = BigInt(n), u = Math.max(0, o - Oe), h = Te + He * i + u, c = e.protocolFeeRate * BigInt(h);
|
|
293
303
|
if (s > c)
|
|
294
304
|
throw new Error(
|
|
295
305
|
`Payout implicit fee ${n} sats exceeds the safety cap of ${c} sats (${e.protocolFeeRate} sat/vB x ${h} vB for ${i} participants); refusing to sign payout.`
|
|
296
306
|
);
|
|
297
|
-
const l = await
|
|
307
|
+
const l = await ae(
|
|
298
308
|
e.vaultCoreVersion,
|
|
299
309
|
e.numVaultKeepers,
|
|
300
310
|
e.numUniversalChallengers,
|
|
301
311
|
e.numVaultKeepers,
|
|
302
312
|
e.councilSize,
|
|
303
|
-
r,
|
|
304
313
|
o,
|
|
314
|
+
r,
|
|
305
315
|
e.protocolFeeRate
|
|
306
316
|
);
|
|
307
317
|
if (s < l)
|
|
@@ -309,23 +319,23 @@ async function ke(e, t) {
|
|
|
309
319
|
`Payout implicit fee ${n} sats is below the floor of ${l} sats (the smallest fee any known vault-provider build produces for this shape); refusing to sign payout.`
|
|
310
320
|
);
|
|
311
321
|
}
|
|
312
|
-
const
|
|
313
|
-
function
|
|
314
|
-
return e.length ===
|
|
322
|
+
const Ue = 22, Ke = 34, Ne = 34, Fe = 25, qe = 23;
|
|
323
|
+
function Be(e) {
|
|
324
|
+
return e.length === Ue * 2 && e.startsWith("0014");
|
|
315
325
|
}
|
|
316
|
-
function
|
|
317
|
-
return e.length ===
|
|
326
|
+
function Me(e) {
|
|
327
|
+
return e.length === Ke * 2 && e.startsWith("0020");
|
|
318
328
|
}
|
|
319
|
-
function
|
|
320
|
-
return e.length ===
|
|
329
|
+
function We(e) {
|
|
330
|
+
return e.length === Ne * 2 && e.startsWith("5120");
|
|
321
331
|
}
|
|
322
|
-
function
|
|
323
|
-
return e.length ===
|
|
332
|
+
function Xe(e) {
|
|
333
|
+
return e.length === Fe * 2 && e.startsWith("76a914") && e.endsWith("88ac");
|
|
324
334
|
}
|
|
325
|
-
function
|
|
326
|
-
return e.length ===
|
|
335
|
+
function ze(e) {
|
|
336
|
+
return e.length === qe * 2 && e.startsWith("a914") && e.endsWith("87");
|
|
327
337
|
}
|
|
328
|
-
function
|
|
338
|
+
function W(e, t) {
|
|
329
339
|
const n = g(e).toLowerCase();
|
|
330
340
|
if (n.length === 0)
|
|
331
341
|
throw new Error(`${t} is empty`);
|
|
@@ -335,13 +345,13 @@ function M(e, t) {
|
|
|
335
345
|
throw new Error(
|
|
336
346
|
`${t} is an OP_RETURN output, which is provably unspendable`
|
|
337
347
|
);
|
|
338
|
-
if (!
|
|
348
|
+
if (!We(n) && !Be(n) && !Me(n) && !Xe(n) && !ze(n))
|
|
339
349
|
throw new Error(
|
|
340
350
|
`${t} is not a standard scriptPubKey (expected P2TR, P2WPKH, P2WSH, P2PKH, or P2SH; got ${n.length / 2} bytes: ${n})`
|
|
341
351
|
);
|
|
342
352
|
}
|
|
343
|
-
const
|
|
344
|
-
async function
|
|
353
|
+
const X = 3;
|
|
354
|
+
async function ht(e) {
|
|
345
355
|
const t = {
|
|
346
356
|
vaultCoreVersion: e.vaultCoreVersion,
|
|
347
357
|
numVaultKeepers: e.vaultKeeperBtcPubkeys.length,
|
|
@@ -349,25 +359,43 @@ async function ut(e) {
|
|
|
349
359
|
councilSize: e.councilSize,
|
|
350
360
|
protocolFeeRate: e.protocolFeeRate
|
|
351
361
|
};
|
|
352
|
-
|
|
353
|
-
const n =
|
|
354
|
-
if (n.ins.length !==
|
|
362
|
+
Le(t);
|
|
363
|
+
const n = x.fromHex(g(e.payoutTxHex)), o = x.fromHex(g(e.peginTxHex)), r = x.fromHex(g(e.assertTxHex));
|
|
364
|
+
if (n.ins.length !== O)
|
|
355
365
|
throw new Error(
|
|
356
|
-
`Payout transaction must have exactly ${
|
|
366
|
+
`Payout transaction must have exactly ${O} inputs, got ${n.ins.length}`
|
|
357
367
|
);
|
|
358
|
-
|
|
368
|
+
if (n.version !== L)
|
|
369
|
+
throw new Error(
|
|
370
|
+
`Payout transaction version ${n.version} must be ${L}; refusing to sign payout.`
|
|
371
|
+
);
|
|
372
|
+
if (n.locktime !== R)
|
|
373
|
+
throw new Error(
|
|
374
|
+
`Payout transaction locktime ${n.locktime} must be ${R}; refusing to sign payout.`
|
|
375
|
+
);
|
|
376
|
+
const i = z(
|
|
359
377
|
n.ins[0],
|
|
360
378
|
0,
|
|
361
|
-
|
|
379
|
+
o,
|
|
362
380
|
"PegIn",
|
|
363
|
-
|
|
364
|
-
)
|
|
381
|
+
we
|
|
382
|
+
);
|
|
383
|
+
if (n.ins[0].sequence !== e.timelockPegin)
|
|
384
|
+
throw new Error(
|
|
385
|
+
`Payout input 0 sequence ${n.ins[0].sequence} must equal the PegIn CSV timelock ${e.timelockPegin}; refusing to sign payout.`
|
|
386
|
+
);
|
|
387
|
+
const s = z(
|
|
365
388
|
n.ins[1],
|
|
366
389
|
1,
|
|
367
|
-
|
|
390
|
+
r,
|
|
368
391
|
"Assert",
|
|
369
|
-
|
|
370
|
-
)
|
|
392
|
+
ve
|
|
393
|
+
);
|
|
394
|
+
if (n.ins[1].sequence !== e.timelockAssert)
|
|
395
|
+
throw new Error(
|
|
396
|
+
`Payout input 1 sequence ${n.ins[1].sequence} must equal the Assert CSV timelock ${e.timelockAssert}; refusing to sign payout.`
|
|
397
|
+
);
|
|
398
|
+
const { out0Len: u, out1Len: h } = Ge(
|
|
371
399
|
n,
|
|
372
400
|
i.value,
|
|
373
401
|
e
|
|
@@ -379,12 +407,12 @@ async function ut(e) {
|
|
|
379
407
|
`Payout outputs (${l} sats) exceed inputs (${c} sats); invalid transaction.`
|
|
380
408
|
);
|
|
381
409
|
const a = c - l;
|
|
382
|
-
await
|
|
410
|
+
await Re(t, {
|
|
383
411
|
implicitFeeSats: a,
|
|
384
412
|
out0Len: u,
|
|
385
413
|
out1Len: h
|
|
386
414
|
});
|
|
387
|
-
const f = await
|
|
415
|
+
const f = await _e({
|
|
388
416
|
vaultCoreVersion: e.vaultCoreVersion,
|
|
389
417
|
depositor: e.depositorBtcPubkey,
|
|
390
418
|
vaultProvider: e.vaultProviderBtcPubkey,
|
|
@@ -394,7 +422,7 @@ async function ut(e) {
|
|
|
394
422
|
network: e.network
|
|
395
423
|
});
|
|
396
424
|
return {
|
|
397
|
-
psbtHex:
|
|
425
|
+
psbtHex: De(
|
|
398
426
|
n,
|
|
399
427
|
i,
|
|
400
428
|
s,
|
|
@@ -402,13 +430,13 @@ async function ut(e) {
|
|
|
402
430
|
)
|
|
403
431
|
};
|
|
404
432
|
}
|
|
405
|
-
function
|
|
433
|
+
function z(e, t, n, o, r) {
|
|
406
434
|
const i = _(
|
|
407
435
|
new Uint8Array(e.hash).slice().reverse()
|
|
408
436
|
), s = n.getId();
|
|
409
|
-
if (i !== s || e.index !==
|
|
437
|
+
if (i !== s || e.index !== r)
|
|
410
438
|
throw new Error(
|
|
411
|
-
`Input ${t} must spend ${
|
|
439
|
+
`Input ${t} must spend ${o}:${r}. Expected ${s}:${r}, got ${i}:${e.index}`
|
|
412
440
|
);
|
|
413
441
|
const u = n.outs[e.index];
|
|
414
442
|
if (!u)
|
|
@@ -417,11 +445,11 @@ function W(e, t, n, r, o) {
|
|
|
417
445
|
);
|
|
418
446
|
return u;
|
|
419
447
|
}
|
|
420
|
-
function
|
|
421
|
-
const
|
|
422
|
-
|
|
448
|
+
function De(e, t, n, o) {
|
|
449
|
+
const r = new C();
|
|
450
|
+
r.setVersion(e.version), r.setLocktime(e.locktime);
|
|
423
451
|
const [i, s] = e.ins;
|
|
424
|
-
|
|
452
|
+
r.addInput({
|
|
425
453
|
hash: i.hash,
|
|
426
454
|
index: i.index,
|
|
427
455
|
sequence: i.sequence,
|
|
@@ -431,16 +459,16 @@ function qe(e, t, n, r) {
|
|
|
431
459
|
},
|
|
432
460
|
tapLeafScript: [
|
|
433
461
|
{
|
|
434
|
-
leafVersion:
|
|
435
|
-
script: p.from(y(
|
|
462
|
+
leafVersion: b,
|
|
463
|
+
script: p.from(y(o.payoutScript)),
|
|
436
464
|
controlBlock: p.from(
|
|
437
|
-
y(
|
|
465
|
+
y(o.payoutControlBlock)
|
|
438
466
|
)
|
|
439
467
|
}
|
|
440
468
|
],
|
|
441
|
-
tapInternalKey: p.from(
|
|
469
|
+
tapInternalKey: p.from(te)
|
|
442
470
|
// sighashType omitted - defaults to SIGHASH_DEFAULT (0x00) for Taproot
|
|
443
|
-
}),
|
|
471
|
+
}), r.addInput({
|
|
444
472
|
hash: s.hash,
|
|
445
473
|
index: s.index,
|
|
446
474
|
sequence: s.sequence,
|
|
@@ -450,25 +478,25 @@ function qe(e, t, n, r) {
|
|
|
450
478
|
}
|
|
451
479
|
});
|
|
452
480
|
for (const u of e.outs)
|
|
453
|
-
|
|
481
|
+
r.addOutput({
|
|
454
482
|
script: u.script,
|
|
455
483
|
value: u.value
|
|
456
484
|
});
|
|
457
|
-
return
|
|
485
|
+
return r.toHex();
|
|
458
486
|
}
|
|
459
|
-
function
|
|
460
|
-
const n = g(e).toLowerCase(),
|
|
461
|
-
|
|
487
|
+
function D(e, t) {
|
|
488
|
+
const n = g(e).toLowerCase(), o = g(
|
|
489
|
+
fe(t)
|
|
462
490
|
).toLowerCase();
|
|
463
|
-
return n ===
|
|
491
|
+
return n === o ? [n] : [n, o];
|
|
464
492
|
}
|
|
465
|
-
function
|
|
493
|
+
function G(e, t) {
|
|
466
494
|
return t.some((n) => e.equals(p.from(n, "hex")));
|
|
467
495
|
}
|
|
468
|
-
function
|
|
496
|
+
function Ge(e, t, n) {
|
|
469
497
|
const {
|
|
470
|
-
claimerBtcPubkey:
|
|
471
|
-
vaultProviderBtcPubkey:
|
|
498
|
+
claimerBtcPubkey: o,
|
|
499
|
+
vaultProviderBtcPubkey: r,
|
|
472
500
|
depositorBtcPubkey: i,
|
|
473
501
|
vaultKeeperBtcPubkeys: s,
|
|
474
502
|
registeredPayoutScriptPubKey: u,
|
|
@@ -476,106 +504,106 @@ function We(e, t, n) {
|
|
|
476
504
|
vkClaimerPayoutScriptPubKeys: c,
|
|
477
505
|
vpCommissionScriptPubKey: l
|
|
478
506
|
} = n;
|
|
479
|
-
if (!
|
|
507
|
+
if (!ge(u))
|
|
480
508
|
throw new Error("Invalid registeredPayoutScriptPubKey: not valid hex");
|
|
481
|
-
const a = g(
|
|
482
|
-
(
|
|
509
|
+
const a = g(o).toLowerCase(), f = g(r).toLowerCase(), d = g(i).toLowerCase(), S = s.map(
|
|
510
|
+
(m) => g(m).toLowerCase()
|
|
483
511
|
);
|
|
484
|
-
let
|
|
512
|
+
let w, P, v;
|
|
485
513
|
if (a === f)
|
|
486
|
-
|
|
514
|
+
w = "vp-claimer", P = Se, v = [g(u)];
|
|
487
515
|
else if (a === d)
|
|
488
|
-
|
|
489
|
-
else if (
|
|
490
|
-
|
|
491
|
-
const
|
|
492
|
-
if (
|
|
516
|
+
w = "depositor-as-claimer", P = F, v = [g(u)];
|
|
517
|
+
else if (S.includes(a)) {
|
|
518
|
+
w = "vk-claimer", P = F;
|
|
519
|
+
const m = c[a];
|
|
520
|
+
if (m === void 0)
|
|
493
521
|
throw new Error(
|
|
494
522
|
`No registered payout script resolved for vault keeper claimer ${a}`
|
|
495
523
|
);
|
|
496
|
-
|
|
497
|
-
|
|
524
|
+
W(
|
|
525
|
+
m,
|
|
498
526
|
`Vault keeper payout script for claimer ${a}`
|
|
499
|
-
),
|
|
527
|
+
), v = D(m, a);
|
|
500
528
|
} else
|
|
501
529
|
throw new Error(
|
|
502
530
|
`Unknown claimer pubkey ${a}: not VP, depositor, or a registered vault keeper`
|
|
503
531
|
);
|
|
504
532
|
if (e.outs.length !== P)
|
|
505
533
|
throw new Error(
|
|
506
|
-
`Payout transaction has ${e.outs.length} output(s), expected exactly ${P} for role ${
|
|
534
|
+
`Payout transaction has ${e.outs.length} output(s), expected exactly ${P} for role ${w}.`
|
|
507
535
|
);
|
|
508
|
-
if (!
|
|
536
|
+
if (!G(e.outs[0].script, v))
|
|
509
537
|
throw new Error(
|
|
510
|
-
`Payout transaction output 0 does not pay the expected scriptPubKey for role ${
|
|
538
|
+
`Payout transaction output 0 does not pay the expected scriptPubKey for role ${w}. Accepted: ${v.join(" or ")}; got ${e.outs[0].script.toString("hex")}`
|
|
511
539
|
);
|
|
512
|
-
const
|
|
513
|
-
if (e.outs[
|
|
540
|
+
const A = P - 1;
|
|
541
|
+
if (e.outs[A].value !== U)
|
|
514
542
|
throw new Error(
|
|
515
|
-
`Payout CPFP anchor (out ${
|
|
543
|
+
`Payout CPFP anchor (out ${A}) value ${e.outs[A].value} sats must equal ${U} sats`
|
|
516
544
|
);
|
|
517
|
-
if (
|
|
518
|
-
|
|
545
|
+
if (w === "vp-claimer") {
|
|
546
|
+
W(
|
|
519
547
|
l,
|
|
520
548
|
"Vault provider commission payout script"
|
|
521
549
|
);
|
|
522
|
-
const
|
|
550
|
+
const m = D(
|
|
523
551
|
l,
|
|
524
552
|
f
|
|
525
553
|
);
|
|
526
|
-
if (!
|
|
554
|
+
if (!G(e.outs[1].script, m))
|
|
527
555
|
throw new Error(
|
|
528
|
-
`Payout transaction output 1 does not pay the vault provider's commission scriptPubKey. Accepted: ${
|
|
556
|
+
`Payout transaction output 1 does not pay the vault provider's commission scriptPubKey. Accepted: ${m.join(" or ")}; got ${e.outs[1].script.toString("hex")}`
|
|
529
557
|
);
|
|
530
|
-
if (!Number.isInteger(h) || h < 0 || h >=
|
|
558
|
+
if (!Number.isInteger(h) || h < 0 || h >= K)
|
|
531
559
|
throw new Error(
|
|
532
|
-
`commissionBps must be an integer in [0, ${
|
|
560
|
+
`commissionBps must be an integer in [0, ${K}), got ${h}`
|
|
533
561
|
);
|
|
534
|
-
const
|
|
535
|
-
t * h /
|
|
562
|
+
const k = Math.floor(
|
|
563
|
+
t * h / $e
|
|
536
564
|
);
|
|
537
|
-
if (e.outs[1].value >
|
|
565
|
+
if (e.outs[1].value > k)
|
|
538
566
|
throw new Error(
|
|
539
|
-
`Payout VP commission (out 1) value ${e.outs[1].value} sats exceeds cap ${
|
|
567
|
+
`Payout VP commission (out 1) value ${e.outs[1].value} sats exceeds cap ${k} sats (${h} bps of peginValue=${t})`
|
|
540
568
|
);
|
|
541
569
|
}
|
|
542
570
|
const E = e.outs[0].script.length;
|
|
543
|
-
if (E === 0 || E >
|
|
571
|
+
if (E === 0 || E > N)
|
|
544
572
|
throw new Error(
|
|
545
|
-
`Payout receiver scriptPubKey length ${E} is outside the contract's registration cap [1, ${
|
|
573
|
+
`Payout receiver scriptPubKey length ${E} is outside the contract's registration cap [1, ${N}]; refusing to sign payout.`
|
|
546
574
|
);
|
|
547
|
-
const
|
|
548
|
-
return { out0Len: E, out1Len:
|
|
575
|
+
const oe = w === "vp-claimer" ? e.outs[1].script.length : void 0;
|
|
576
|
+
return { out0Len: E, out1Len: oe };
|
|
549
577
|
}
|
|
550
|
-
function
|
|
551
|
-
const
|
|
552
|
-
if (n >=
|
|
578
|
+
function dt(e, t, n = 0) {
|
|
579
|
+
const o = C.fromHex(e);
|
|
580
|
+
if (n >= o.data.inputs.length)
|
|
553
581
|
throw new Error(
|
|
554
|
-
`Input index ${n} out of range (${
|
|
582
|
+
`Input index ${n} out of range (${o.data.inputs.length} inputs)`
|
|
555
583
|
);
|
|
556
|
-
const
|
|
557
|
-
if (
|
|
584
|
+
const r = o.data.inputs[n];
|
|
585
|
+
if (r.tapScriptSig && r.tapScriptSig.length > 0) {
|
|
558
586
|
const i = y(t);
|
|
559
|
-
for (const s of
|
|
587
|
+
for (const s of r.tapScriptSig)
|
|
560
588
|
if (s.pubkey.equals(p.from(i)))
|
|
561
|
-
return
|
|
589
|
+
return Y(s.signature, n);
|
|
562
590
|
throw new Error(
|
|
563
591
|
`No signature found for depositor pubkey: ${t} at input ${n}`
|
|
564
592
|
);
|
|
565
593
|
}
|
|
566
|
-
if (
|
|
567
|
-
const i =
|
|
568
|
-
if (i.length !==
|
|
594
|
+
if (r.finalScriptWitness && r.finalScriptWitness.length > 0) {
|
|
595
|
+
const i = Ye(r.finalScriptWitness);
|
|
596
|
+
if (i.length !== X)
|
|
569
597
|
throw new Error(
|
|
570
|
-
`Unexpected finalized witness stack size at input ${n}: expected ${
|
|
598
|
+
`Unexpected finalized witness stack size at input ${n}: expected ${X} items (signature, script, controlBlock), got ${i.length}`
|
|
571
599
|
);
|
|
572
|
-
return
|
|
600
|
+
return Y(i[0], n);
|
|
573
601
|
}
|
|
574
602
|
throw new Error(
|
|
575
603
|
`No tapScriptSig or finalScriptWitness found in signed PSBT at input ${n}`
|
|
576
604
|
);
|
|
577
605
|
}
|
|
578
|
-
function
|
|
606
|
+
function Y(e, t) {
|
|
579
607
|
if (e.length === 64)
|
|
580
608
|
return _(new Uint8Array(e));
|
|
581
609
|
throw e.length === 65 ? new Error(
|
|
@@ -584,35 +612,35 @@ function D(e, t) {
|
|
|
584
612
|
`Unexpected signature length at input ${t}: ${e.length}`
|
|
585
613
|
);
|
|
586
614
|
}
|
|
587
|
-
function
|
|
615
|
+
function Ye(e) {
|
|
588
616
|
const t = [];
|
|
589
617
|
let n = 0;
|
|
590
|
-
const
|
|
618
|
+
const o = (s) => {
|
|
591
619
|
if (n + s > e.length)
|
|
592
620
|
throw new Error(
|
|
593
621
|
`Malformed witness data: need ${s} byte(s) at offset ${n}, only ${e.length - n} remaining`
|
|
594
622
|
);
|
|
595
|
-
},
|
|
596
|
-
|
|
623
|
+
}, r = () => {
|
|
624
|
+
o(1);
|
|
597
625
|
const s = e[n++];
|
|
598
626
|
if (s < 253) return s;
|
|
599
627
|
if (s === 253) {
|
|
600
|
-
|
|
628
|
+
o(2);
|
|
601
629
|
const u = (e[n] | e[n + 1] << 8) >>> 0;
|
|
602
630
|
return n += 2, u;
|
|
603
631
|
}
|
|
604
632
|
if (s === 254) {
|
|
605
|
-
|
|
633
|
+
o(4);
|
|
606
634
|
const u = (e[n] | e[n + 1] << 8 | e[n + 2] << 16 | e[n + 3] << 24) >>> 0;
|
|
607
635
|
return n += 4, u;
|
|
608
636
|
}
|
|
609
637
|
throw new Error(
|
|
610
638
|
`Malformed witness data: 8-byte varint (0xff) not supported at offset ${n - 1}`
|
|
611
639
|
);
|
|
612
|
-
}, i =
|
|
640
|
+
}, i = r();
|
|
613
641
|
for (let s = 0; s < i; s++) {
|
|
614
|
-
const u =
|
|
615
|
-
|
|
642
|
+
const u = r();
|
|
643
|
+
o(u), t.push(p.from(e.subarray(n, n + u))), n += u;
|
|
616
644
|
}
|
|
617
645
|
if (n !== e.length)
|
|
618
646
|
throw new Error(
|
|
@@ -627,24 +655,24 @@ class $ extends Error {
|
|
|
627
655
|
), this.name = "PsbtSubstitutionError";
|
|
628
656
|
}
|
|
629
657
|
}
|
|
630
|
-
function
|
|
658
|
+
function Q(e, t) {
|
|
631
659
|
try {
|
|
632
660
|
return C.fromHex(t);
|
|
633
661
|
} catch (n) {
|
|
634
|
-
const
|
|
635
|
-
throw new Error(`Failed to parse ${e} PSBT: ${
|
|
662
|
+
const o = n instanceof Error ? n.message : String(n);
|
|
663
|
+
throw new Error(`Failed to parse ${e} PSBT: ${o}`);
|
|
636
664
|
}
|
|
637
665
|
}
|
|
638
|
-
const
|
|
666
|
+
const Qe = 8;
|
|
639
667
|
function I(e) {
|
|
640
|
-
return `${e.toString("hex").slice(0,
|
|
668
|
+
return `${e.toString("hex").slice(0, Qe)}…`;
|
|
641
669
|
}
|
|
642
|
-
function
|
|
670
|
+
function Z(e) {
|
|
643
671
|
const t = p.from(e).reverse();
|
|
644
672
|
return I(t);
|
|
645
673
|
}
|
|
646
|
-
function
|
|
647
|
-
const t =
|
|
674
|
+
function pt(e) {
|
|
675
|
+
const t = Q("requested", e.requestedPsbtHex), n = Q("returned", e.returnedPsbtHex);
|
|
648
676
|
if (t.version !== n.version)
|
|
649
677
|
throw new $(
|
|
650
678
|
`tx version differs (requested=${t.version}, returned=${n.version})`
|
|
@@ -661,122 +689,122 @@ function at(e) {
|
|
|
661
689
|
throw new $(
|
|
662
690
|
`output count differs (requested=${t.txOutputs.length}, returned=${n.txOutputs.length})`
|
|
663
691
|
);
|
|
664
|
-
for (let
|
|
665
|
-
const
|
|
666
|
-
if (!
|
|
692
|
+
for (let o = 0; o < t.txInputs.length; o++) {
|
|
693
|
+
const r = t.txInputs[o], i = n.txInputs[o];
|
|
694
|
+
if (!r.hash.equals(i.hash))
|
|
667
695
|
throw new $(
|
|
668
|
-
`input ${
|
|
696
|
+
`input ${o} prevout txid differs (requested=${Z(r.hash)}, returned=${Z(i.hash)})`
|
|
669
697
|
);
|
|
670
|
-
if (
|
|
698
|
+
if (r.index !== i.index)
|
|
671
699
|
throw new $(
|
|
672
|
-
`input ${
|
|
700
|
+
`input ${o} prevout vout differs (requested=${r.index}, returned=${i.index})`
|
|
673
701
|
);
|
|
674
|
-
if (
|
|
702
|
+
if (r.sequence !== i.sequence)
|
|
675
703
|
throw new $(
|
|
676
|
-
`input ${
|
|
704
|
+
`input ${o} sequence differs (requested=${r.sequence}, returned=${i.sequence})`
|
|
677
705
|
);
|
|
678
706
|
}
|
|
679
|
-
for (let
|
|
680
|
-
const
|
|
681
|
-
if (!
|
|
707
|
+
for (let o = 0; o < t.txOutputs.length; o++) {
|
|
708
|
+
const r = t.txOutputs[o], i = n.txOutputs[o];
|
|
709
|
+
if (!r.script.equals(i.script))
|
|
682
710
|
throw new $(
|
|
683
|
-
`output ${
|
|
711
|
+
`output ${o} scriptPubKey differs (requested=${I(r.script)}, returned=${I(i.script)})`
|
|
684
712
|
);
|
|
685
|
-
if (
|
|
713
|
+
if (r.value !== i.value)
|
|
686
714
|
throw new $(
|
|
687
|
-
`output ${
|
|
715
|
+
`output ${o} value differs (requested=${r.value}, returned=${i.value})`
|
|
688
716
|
);
|
|
689
717
|
}
|
|
690
718
|
}
|
|
691
|
-
const
|
|
692
|
-
function
|
|
693
|
-
if (e <
|
|
719
|
+
const j = 253, Ze = 254, je = 65535, Je = 4294967295;
|
|
720
|
+
function et(e) {
|
|
721
|
+
if (e < j)
|
|
694
722
|
return p.from([e]);
|
|
695
|
-
if (e <=
|
|
723
|
+
if (e <= je) {
|
|
696
724
|
const t = p.alloc(2);
|
|
697
|
-
return t.writeUInt16LE(e), p.concat([p.from([
|
|
725
|
+
return t.writeUInt16LE(e), p.concat([p.from([j]), t]);
|
|
698
726
|
}
|
|
699
|
-
if (e <=
|
|
727
|
+
if (e <= Je) {
|
|
700
728
|
const t = p.alloc(4);
|
|
701
|
-
return t.writeUInt32LE(e), p.concat([p.from([
|
|
729
|
+
return t.writeUInt32LE(e), p.concat([p.from([Ze]), t]);
|
|
702
730
|
}
|
|
703
731
|
throw new Error(`Script too large to encode as CompactSize: ${e} bytes`);
|
|
704
732
|
}
|
|
705
|
-
const
|
|
706
|
-
function
|
|
733
|
+
const tt = "TapLeaf";
|
|
734
|
+
function nt(e, t) {
|
|
707
735
|
const n = p.concat([
|
|
708
736
|
p.from([e]),
|
|
709
|
-
|
|
737
|
+
et(t.length),
|
|
710
738
|
p.from(t)
|
|
711
739
|
]);
|
|
712
|
-
return
|
|
740
|
+
return pe.taggedHash(tt, n);
|
|
713
741
|
}
|
|
714
|
-
function
|
|
715
|
-
const { requestedPsbtHex: t, signatureHex: n, signerXOnlyPubkeyHex:
|
|
716
|
-
if (i.length !==
|
|
742
|
+
function Pt(e) {
|
|
743
|
+
const { requestedPsbtHex: t, signatureHex: n, signerXOnlyPubkeyHex: o, inputIndex: r } = e, i = g(n);
|
|
744
|
+
if (i.length !== T)
|
|
717
745
|
throw new Error(
|
|
718
|
-
`Schnorr signature for input ${
|
|
746
|
+
`Schnorr signature for input ${r} must be ${T} hex chars (64 bytes), got ${i.length}.`
|
|
719
747
|
);
|
|
720
|
-
const s = g(
|
|
748
|
+
const s = g(o);
|
|
721
749
|
if (s.length !== H)
|
|
722
750
|
throw new Error(
|
|
723
|
-
`Signer x-only pubkey for input ${
|
|
751
|
+
`Signer x-only pubkey for input ${r} must be ${H} hex chars (32 bytes), got ${s.length}.`
|
|
724
752
|
);
|
|
725
753
|
const u = C.fromHex(t);
|
|
726
|
-
if (
|
|
754
|
+
if (r < 0 || r >= u.data.inputs.length)
|
|
727
755
|
throw new Error(
|
|
728
|
-
`Input index ${
|
|
756
|
+
`Input index ${r} out of range (${u.data.inputs.length} inputs).`
|
|
729
757
|
);
|
|
730
758
|
const h = [], c = [];
|
|
731
759
|
for (let P = 0; P < u.data.inputs.length; P++) {
|
|
732
|
-
const
|
|
733
|
-
if (!
|
|
760
|
+
const v = u.data.inputs[P].witnessUtxo;
|
|
761
|
+
if (!v)
|
|
734
762
|
throw new Error(
|
|
735
763
|
`Cannot verify signature: input ${P} of the requested PSBT has no witnessUtxo (required to recompute the Taproot sighash).`
|
|
736
764
|
);
|
|
737
|
-
h.push(
|
|
765
|
+
h.push(v.script), c.push(v.value);
|
|
738
766
|
}
|
|
739
|
-
const l = u.data.inputs[
|
|
767
|
+
const l = u.data.inputs[r].tapLeafScript;
|
|
740
768
|
if (!l || l.length !== 1)
|
|
741
769
|
throw new Error(
|
|
742
|
-
`Cannot verify signature: input ${
|
|
770
|
+
`Cannot verify signature: input ${r} of the requested PSBT must have exactly one tapLeafScript, got ${(l == null ? void 0 : l.length) ?? 0}.`
|
|
743
771
|
);
|
|
744
772
|
const a = l[0];
|
|
745
|
-
if (a.leafVersion !==
|
|
773
|
+
if (a.leafVersion !== b)
|
|
746
774
|
throw new Error(
|
|
747
|
-
`Cannot verify signature: input ${
|
|
775
|
+
`Cannot verify signature: input ${r} tapLeafScript has leaf version 0x${a.leafVersion.toString(16)}, expected 0x${b.toString(16)}.`
|
|
748
776
|
);
|
|
749
|
-
const f =
|
|
777
|
+
const f = nt(a.leafVersion, a.script), d = new x();
|
|
750
778
|
d.version = u.version, d.locktime = u.locktime;
|
|
751
779
|
for (const P of u.txInputs)
|
|
752
780
|
d.addInput(P.hash, P.index, P.sequence);
|
|
753
781
|
for (const P of u.txOutputs)
|
|
754
782
|
d.addOutput(P.script, P.value);
|
|
755
|
-
const
|
|
756
|
-
|
|
783
|
+
const S = d.hashForWitnessV1(
|
|
784
|
+
r,
|
|
757
785
|
h,
|
|
758
786
|
c,
|
|
759
|
-
|
|
787
|
+
x.SIGHASH_DEFAULT,
|
|
760
788
|
f
|
|
761
789
|
);
|
|
762
|
-
if (
|
|
763
|
-
|
|
790
|
+
if (!me.verifySchnorr(
|
|
791
|
+
S,
|
|
764
792
|
y(s),
|
|
765
793
|
y(i)
|
|
766
794
|
))
|
|
767
795
|
throw new Error(
|
|
768
|
-
`Schnorr signature for input ${
|
|
796
|
+
`Schnorr signature for input ${r} (signer ${s}) does not verify against the expected Taproot script-path sighash. The wallet may have signed with the tweaked key, signed a different transaction, or returned an invalid signature.`
|
|
769
797
|
);
|
|
770
798
|
}
|
|
771
799
|
export {
|
|
772
800
|
$ as P,
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
801
|
+
at as a,
|
|
802
|
+
lt as b,
|
|
803
|
+
ht as c,
|
|
804
|
+
pt as d,
|
|
805
|
+
dt as e,
|
|
806
|
+
Pt as f,
|
|
807
|
+
_e as g,
|
|
808
|
+
ne as n
|
|
781
809
|
};
|
|
782
|
-
//# sourceMappingURL=verifyScriptPathSchnorrSignature-
|
|
810
|
+
//# sourceMappingURL=verifyScriptPathSchnorrSignature-Bav08_7R.js.map
|