@babylonlabs-io/ts-sdk 0.56.1 → 0.57.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BTCVaultRegistry.abi-AUAyCHal.cjs +2 -0
- package/dist/BTCVaultRegistry.abi-AUAyCHal.cjs.map +1 -0
- package/dist/{BTCVaultRegistry.abi-Chs4AFBj.js → BTCVaultRegistry.abi-CixOlp3B.js} +73 -14
- package/dist/BTCVaultRegistry.abi-CixOlp3B.js.map +1 -0
- package/dist/BTCVaultRegistryKeyEpochs.abi-CXjhRZbm.js +111 -0
- package/dist/BTCVaultRegistryKeyEpochs.abi-CXjhRZbm.js.map +1 -0
- package/dist/BTCVaultRegistryKeyEpochs.abi-_NERAdc5.cjs +2 -0
- package/dist/BTCVaultRegistryKeyEpochs.abi-_NERAdc5.cjs.map +1 -0
- package/dist/{PeginManager-Ba7Cr51Z.js → PeginManager-CnX3uFb0.js} +5 -5
- package/dist/{PeginManager-Ba7Cr51Z.js.map → PeginManager-CnX3uFb0.js.map} +1 -1
- package/dist/PeginManager-iDbqXsKD.cjs +2 -0
- package/dist/{PeginManager-CcjGRo4O.cjs.map → PeginManager-iDbqXsKD.cjs.map} +1 -1
- package/dist/ProtocolParams.abi-C8U7BHCS.cjs +2 -0
- package/dist/ProtocolParams.abi-C8U7BHCS.cjs.map +1 -0
- package/dist/{ApplicationRegistry.abi-w5prf7Ig.js → ProtocolParams.abi-CV938AYZ.js} +150 -80
- package/dist/ProtocolParams.abi-CV938AYZ.js.map +1 -0
- package/dist/{buildAndBroadcastRefund-BtXUqBkb.js → buildAndBroadcastRefund-CCb1_z24.js} +627 -452
- package/dist/buildAndBroadcastRefund-CCb1_z24.js.map +1 -0
- package/dist/buildAndBroadcastRefund-CDzzTZ2U.cjs +2 -0
- package/dist/buildAndBroadcastRefund-CDzzTZ2U.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +163 -153
- package/dist/index.js.map +1 -1
- package/dist/{types-CQDRQvV-.js → json-rpc-client-Ehjthcd7.js} +61 -61
- package/dist/json-rpc-client-Ehjthcd7.js.map +1 -0
- package/dist/{types-WA0LrDk1.cjs → json-rpc-client-fUoK-TzT.cjs} +2 -2
- package/dist/json-rpc-client-fUoK-TzT.cjs.map +1 -0
- package/dist/mempoolApi-C0olk43O.js +536 -0
- package/dist/mempoolApi-C0olk43O.js.map +1 -0
- package/dist/mempoolApi-Dsm2VPXp.cjs +2 -0
- package/dist/mempoolApi-Dsm2VPXp.cjs.map +1 -0
- package/dist/{noPayout-CihCk1HE.js → noPayout-CI4l1qu2.js} +2 -2
- package/dist/{noPayout-CihCk1HE.js.map → noPayout-CI4l1qu2.js.map} +1 -1
- package/dist/{noPayout-Cb8vFrkY.cjs → noPayout-Djrv31V5.cjs} +2 -2
- package/dist/{noPayout-Cb8vFrkY.cjs.map → noPayout-Djrv31V5.cjs.map} +1 -1
- package/dist/onChainBtcPubkey-Cd9kpz-S.cjs +2 -0
- package/dist/onChainBtcPubkey-Cd9kpz-S.cjs.map +1 -0
- package/dist/onChainBtcPubkey-aPY5ib3Q.js +19 -0
- package/dist/onChainBtcPubkey-aPY5ib3Q.js.map +1 -0
- package/dist/primeVpAuth-BlxUcdBf.cjs +2 -0
- package/dist/primeVpAuth-BlxUcdBf.cjs.map +1 -0
- package/dist/{primeVpAuth-Caa5J_uv.js → primeVpAuth-DkJbvywo.js} +479 -367
- package/dist/primeVpAuth-DkJbvywo.js.map +1 -0
- package/dist/signPsbtsWithFallback-C01N6Kdo.cjs +2 -0
- package/dist/signPsbtsWithFallback-C01N6Kdo.cjs.map +1 -0
- package/dist/{PayoutManager-BVgmuKuK.js → signPsbtsWithFallback-CzZFZf0I.js} +105 -101
- package/dist/signPsbtsWithFallback-CzZFZf0I.js.map +1 -0
- package/dist/tbv/core/clients/eth/index.d.ts +5 -3
- package/dist/tbv/core/clients/eth/index.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/onChainBtcPubkey.d.ts +16 -0
- package/dist/tbv/core/clients/eth/onChainBtcPubkey.d.ts.map +1 -0
- package/dist/tbv/core/clients/eth/operation-key-reader.d.ts +33 -0
- package/dist/tbv/core/clients/eth/operation-key-reader.d.ts.map +1 -0
- package/dist/tbv/core/clients/eth/types.d.ts +122 -3
- package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts +25 -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 +35 -32
- package/dist/tbv/core/clients/index.js.map +1 -1
- package/dist/tbv/core/contracts/__tests__/BTCVaultRegistryKeyEpochs.abi.test.d.ts +2 -0
- package/dist/tbv/core/contracts/__tests__/BTCVaultRegistryKeyEpochs.abi.test.d.ts.map +1 -0
- package/dist/tbv/core/contracts/abis/ApplicationRegistry.abi.d.ts +66 -0
- package/dist/tbv/core/contracts/abis/ApplicationRegistry.abi.d.ts.map +1 -1
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts +50 -0
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts.map +1 -1
- package/dist/tbv/core/contracts/abis/BTCVaultRegistryKeyEpochs.abi.d.ts +111 -0
- package/dist/tbv/core/contracts/abis/BTCVaultRegistryKeyEpochs.abi.d.ts.map +1 -0
- package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts +36 -0
- package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts.map +1 -1
- package/dist/tbv/core/contracts/index.cjs +1 -1
- package/dist/tbv/core/contracts/index.d.ts +2 -1
- package/dist/tbv/core/contracts/index.d.ts.map +1 -1
- package/dist/tbv/core/contracts/index.js +8 -6
- package/dist/tbv/core/contracts/index.js.map +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +163 -153
- package/dist/tbv/core/index.js.map +1 -1
- package/dist/tbv/core/managers/PayoutManager.d.ts +8 -0
- package/dist/tbv/core/managers/PayoutManager.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.js +2 -2
- package/dist/tbv/core/primitives/psbt/__tests__/standardPayoutScript.test.d.ts +2 -0
- package/dist/tbv/core/primitives/psbt/__tests__/standardPayoutScript.test.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/assertPayoutFeeBand.d.ts +5 -5
- package/dist/tbv/core/primitives/psbt/assertPayoutFeeBand.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/payout.d.ts +23 -0
- package/dist/tbv/core/primitives/psbt/payout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/standardPayoutScript.d.ts +41 -0
- package/dist/tbv/core/primitives/psbt/standardPayoutScript.d.ts.map +1 -0
- package/dist/tbv/core/services/deposit/__tests__/verifyRegisteredParticipantKeys.test.d.ts +2 -0
- package/dist/tbv/core/services/deposit/__tests__/verifyRegisteredParticipantKeys.test.d.ts.map +1 -0
- package/dist/tbv/core/services/deposit/index.d.ts +7 -6
- package/dist/tbv/core/services/deposit/index.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts +10 -0
- package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts +9 -0
- package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/validateOnChainParticipantKeys.d.ts +38 -1
- package/dist/tbv/core/services/deposit/validateOnChainParticipantKeys.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/verifyRegisteredParticipantKeys.d.ts +42 -0
- package/dist/tbv/core/services/deposit/verifyRegisteredParticipantKeys.d.ts.map +1 -0
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.d.ts +1 -0
- package/dist/tbv/core/services/index.d.ts.map +1 -1
- package/dist/tbv/core/services/index.js +36 -31
- package/dist/tbv/core/services/participants/__tests__/fixtures/rotation.d.ts +55 -0
- package/dist/tbv/core/services/participants/__tests__/fixtures/rotation.d.ts.map +1 -0
- package/dist/tbv/core/services/participants/__tests__/resolveParticipantKeys.test.d.ts +2 -0
- package/dist/tbv/core/services/participants/__tests__/resolveParticipantKeys.test.d.ts.map +1 -0
- package/dist/tbv/core/services/participants/index.d.ts +8 -0
- package/dist/tbv/core/services/participants/index.d.ts.map +1 -0
- package/dist/tbv/core/services/participants/resolveParticipantKeys.d.ts +26 -0
- package/dist/tbv/core/services/participants/resolveParticipantKeys.d.ts.map +1 -0
- package/dist/tbv/core/services/participants/types.d.ts +62 -0
- package/dist/tbv/core/services/participants/types.d.ts.map +1 -0
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +163 -153
- package/dist/tbv/index.js.map +1 -1
- package/dist/verifyScriptPathSchnorrSignature-C-84KJ6U.cjs +2 -0
- package/dist/verifyScriptPathSchnorrSignature-C-84KJ6U.cjs.map +1 -0
- package/dist/{verifyScriptPathSchnorrSignature-CgrnAjMW.js → verifyScriptPathSchnorrSignature-Xoo9DOHW.js} +359 -301
- package/dist/verifyScriptPathSchnorrSignature-Xoo9DOHW.js.map +1 -0
- package/package.json +1 -1
- package/dist/ApplicationRegistry.abi-CLaa6E99.cjs +0 -2
- package/dist/ApplicationRegistry.abi-CLaa6E99.cjs.map +0 -1
- package/dist/ApplicationRegistry.abi-w5prf7Ig.js.map +0 -1
- package/dist/BTCVaultRegistry.abi-Chs4AFBj.js.map +0 -1
- package/dist/BTCVaultRegistry.abi-JdeqLz4x.cjs +0 -2
- package/dist/BTCVaultRegistry.abi-JdeqLz4x.cjs.map +0 -1
- package/dist/PayoutManager-BVgmuKuK.js.map +0 -1
- package/dist/PayoutManager-Cu4_l-_Y.cjs +0 -2
- package/dist/PayoutManager-Cu4_l-_Y.cjs.map +0 -1
- package/dist/PeginManager-CcjGRo4O.cjs +0 -2
- package/dist/buildAndBroadcastRefund-BtXUqBkb.js.map +0 -1
- package/dist/buildAndBroadcastRefund-Cq01wyZX.cjs +0 -2
- package/dist/buildAndBroadcastRefund-Cq01wyZX.cjs.map +0 -1
- package/dist/mempoolApi-DkyKmmgI.cjs +0 -2
- package/dist/mempoolApi-DkyKmmgI.cjs.map +0 -1
- package/dist/mempoolApi-lpJdvPkK.js +0 -483
- package/dist/mempoolApi-lpJdvPkK.js.map +0 -1
- package/dist/primeVpAuth-Caa5J_uv.js.map +0 -1
- package/dist/primeVpAuth-y-4A88ah.cjs +0 -2
- package/dist/primeVpAuth-y-4A88ah.cjs.map +0 -1
- package/dist/types-CQDRQvV-.js.map +0 -1
- package/dist/types-WA0LrDk1.cjs.map +0 -1
- package/dist/verifyScriptPathSchnorrSignature-BZhX-SOd.cjs +0 -2
- package/dist/verifyScriptPathSchnorrSignature-BZhX-SOd.cjs.map +0 -1
- package/dist/verifyScriptPathSchnorrSignature-CgrnAjMW.js.map +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { computeMinClaimValue as
|
|
2
|
-
import { Buffer as
|
|
3
|
-
import { Transaction as
|
|
4
|
-
import { c as V, d as
|
|
5
|
-
import { s as
|
|
6
|
-
import { D as
|
|
7
|
-
import * as
|
|
8
|
-
async function
|
|
1
|
+
import { computeMinClaimValue as Z, peginP2aAnchorOutput as j, computeMinPeginFee as ne, buildPeginTxFromPrePegin as oe, createPrePeginTransaction as re, validatePeginP2aAnchor as ie, tapInternalPubkey as J, createPayoutConnector as se, computePayoutFeeFloor as ue } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
2
|
+
import { Buffer as p } from "buffer";
|
|
3
|
+
import { Transaction as m, script as ce, opcodes as ae, payments as le, Psbt as C, crypto as he } from "bitcoinjs-lib";
|
|
4
|
+
import { c as V, d as de } from "./fundPeginTransaction-B2wyjqp0.js";
|
|
5
|
+
import { s as g, u as _, h as y, c as pe, T as A, d as Pe, S as k, X as H } from "./bitcoin-B5aNKtsk.js";
|
|
6
|
+
import { D as L, P as O, M as R, b as U, c as ge, A as fe, B as ve, V as we, N as K } from "./constants-CDQE812z.js";
|
|
7
|
+
import * as $e from "@bitcoin-js/tiny-secp256k1-asmjs";
|
|
8
|
+
async function xe(e, t) {
|
|
9
9
|
const n = t.pegInAmounts.length;
|
|
10
10
|
if (e.htlcValues.length !== n)
|
|
11
11
|
throw new Error(
|
|
@@ -19,7 +19,7 @@ async function ge(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 r = await Z(
|
|
23
23
|
// Must price the same graph version the builder constructed.
|
|
24
24
|
t.vaultCoreVersion,
|
|
25
25
|
t.numLocalChallengers,
|
|
@@ -28,67 +28,67 @@ async function ge(e, t) {
|
|
|
28
28
|
t.councilSize,
|
|
29
29
|
t.feeRate
|
|
30
30
|
);
|
|
31
|
-
if (e.depositorClaimValue !==
|
|
31
|
+
if (e.depositorClaimValue !== r)
|
|
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 ${r} (vaultCoreVersion=${t.vaultCoreVersion}, numLocalChallengers=${t.numLocalChallengers}, numUniversalChallengers=${t.universalChallengerPubkeys.length}, councilQuorum=${t.councilQuorum}, councilSize=${t.councilSize}, feeRate=${t.feeRate}).`
|
|
34
34
|
);
|
|
35
|
-
const o = await
|
|
35
|
+
const o = await j(t.vaultCoreVersion), i = (o == null ? void 0 : o.value) ?? 0n, s = await ne(
|
|
36
36
|
t.vaultCoreVersion,
|
|
37
37
|
t.vaultKeeperPubkeys.length,
|
|
38
38
|
t.universalChallengerPubkeys.length,
|
|
39
39
|
t.minPeginFeeRate
|
|
40
|
-
), u = s +
|
|
40
|
+
), u = s + i, h = t.minPeginFeeRate * V;
|
|
41
41
|
for (let c = 0; c < n; c++) {
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
42
|
+
const l = t.pegInAmounts[c], a = e.peginAmounts[c], f = e.htlcValues[c];
|
|
43
|
+
if (a !== l)
|
|
44
44
|
throw new Error(
|
|
45
|
-
`WASM Pre-PegIn peginAmount[${c}] ${
|
|
45
|
+
`WASM Pre-PegIn peginAmount[${c}] ${a} does not match the requested amount ${l}; refusing to build a tx whose recorded amount differs from the depositor's request.`
|
|
46
46
|
);
|
|
47
|
-
if (
|
|
47
|
+
if (a <= 0n)
|
|
48
48
|
throw new Error(
|
|
49
|
-
`WASM Pre-PegIn peginAmount[${c}] is non-positive (${
|
|
49
|
+
`WASM Pre-PegIn peginAmount[${c}] is non-positive (${a}); expected > 0.`
|
|
50
50
|
);
|
|
51
|
-
if (
|
|
51
|
+
if (f <= 0n)
|
|
52
52
|
throw new Error(
|
|
53
|
-
`WASM Pre-PegIn htlcValue[${c}] is non-positive (${
|
|
53
|
+
`WASM Pre-PegIn htlcValue[${c}] is non-positive (${f}); expected > 0.`
|
|
54
54
|
);
|
|
55
|
-
const
|
|
56
|
-
if (
|
|
55
|
+
const d = f - a - e.depositorClaimValue;
|
|
56
|
+
if (d <= 0n)
|
|
57
57
|
throw new Error(
|
|
58
|
-
`WASM Pre-PegIn htlcValue[${c}] ${
|
|
58
|
+
`WASM Pre-PegIn htlcValue[${c}] ${f} does not strictly cover peginAmount ${a} + depositorClaimValue ${e.depositorClaimValue} + a PegIn reserve (implied reserve ${d}).`
|
|
59
59
|
);
|
|
60
|
-
if (
|
|
60
|
+
if (d > h)
|
|
61
61
|
throw new Error(
|
|
62
|
-
`WASM Pre-PegIn implied reserve for HTLC[${c}] (${
|
|
62
|
+
`WASM Pre-PegIn implied reserve for HTLC[${c}] (${d} sat) exceeds the plausibility cap ${h} sat (minPeginFeeRate=${t.minPeginFeeRate} × ${V} vbytes); htlcValue ${f} appears grossly inflated.`
|
|
63
63
|
);
|
|
64
|
-
if (
|
|
64
|
+
if (d !== u)
|
|
65
65
|
throw new Error(
|
|
66
|
-
`WASM Pre-PegIn htlcValue[${c}] ${
|
|
66
|
+
`WASM Pre-PegIn htlcValue[${c}] ${f} implies a PegIn fee+anchor reserve of ${d} sat, expected exactly ${u} sat (minPeginFee ${s} + p2aAnchor ${i} for vaultCoreVersion ${t.vaultCoreVersion}, vaultKeepers=${t.vaultKeeperPubkeys.length}, universalChallengers=${t.universalChallengerPubkeys.length}, minPeginFeeRate=${t.minPeginFeeRate}).`
|
|
67
67
|
);
|
|
68
68
|
}
|
|
69
69
|
return s;
|
|
70
70
|
}
|
|
71
|
-
function
|
|
71
|
+
function Se(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 o = BigInt(e[
|
|
78
|
-
if (o !== t[
|
|
76
|
+
for (let r = 0; r < t.length; r++) {
|
|
77
|
+
const o = BigInt(e[r].value);
|
|
78
|
+
if (o !== t[r])
|
|
79
79
|
throw new Error(
|
|
80
|
-
`Encoded Pre-PegIn HTLC output[${
|
|
80
|
+
`Encoded Pre-PegIn HTLC output[${r}] value ${o} does not match the cross-checked htlcValue ${t[r]}; the funded/signed tx would not pay the validated amount.`
|
|
81
81
|
);
|
|
82
|
-
const
|
|
83
|
-
if (
|
|
82
|
+
const i = e[r].script.toString("hex").toLowerCase(), s = n[r].toLowerCase();
|
|
83
|
+
if (i !== s)
|
|
84
84
|
throw new Error(
|
|
85
|
-
`Encoded Pre-PegIn HTLC output[${
|
|
85
|
+
`Encoded Pre-PegIn HTLC output[${r}] 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 N = 64, me = /^[0-9a-fA-F]+$/;
|
|
90
|
+
async function it(e) {
|
|
91
|
+
const t = ee(e.authAnchorHash), n = await re({
|
|
92
92
|
txGraphVersion: e.vaultCoreVersion,
|
|
93
93
|
depositorPubkey: e.depositorPubkey,
|
|
94
94
|
vaultProviderPubkey: e.vaultProviderPubkey,
|
|
@@ -104,39 +104,39 @@ async function We(e) {
|
|
|
104
104
|
councilSize: e.councilSize,
|
|
105
105
|
network: e.network,
|
|
106
106
|
authAnchorHash: t
|
|
107
|
-
}),
|
|
108
|
-
|
|
107
|
+
}), r = await xe(n, e), o = de(n.txHex);
|
|
108
|
+
Se(
|
|
109
109
|
o.outputs,
|
|
110
110
|
n.htlcValues,
|
|
111
111
|
n.htlcScriptPubKeys
|
|
112
112
|
);
|
|
113
|
-
const
|
|
114
|
-
(u,
|
|
113
|
+
const i = o.outputs.reduce(
|
|
114
|
+
(u, h) => u + BigInt(h.value),
|
|
115
115
|
0n
|
|
116
116
|
), s = t !== void 0 ? n.htlcValues.length : null;
|
|
117
117
|
return {
|
|
118
118
|
psbtHex: n.txHex,
|
|
119
|
-
totalOutputValue:
|
|
119
|
+
totalOutputValue: i,
|
|
120
120
|
htlcValues: n.htlcValues,
|
|
121
121
|
htlcScriptPubKeys: n.htlcScriptPubKeys,
|
|
122
122
|
htlcAddresses: n.htlcAddresses,
|
|
123
123
|
peginAmounts: n.peginAmounts,
|
|
124
124
|
depositorClaimValue: n.depositorClaimValue,
|
|
125
125
|
authAnchorVout: s,
|
|
126
|
-
minPeginFee:
|
|
126
|
+
minPeginFee: r
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
|
-
function
|
|
129
|
+
function ee(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 !== N || !me.test(t))
|
|
133
133
|
throw new Error(
|
|
134
|
-
`authAnchorHash must be 32-byte hex (${
|
|
134
|
+
`authAnchorHash must be 32-byte hex (${N} 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 st(e) {
|
|
139
|
+
const t = await oe(
|
|
140
140
|
{
|
|
141
141
|
txGraphVersion: e.prePeginParams.vaultCoreVersion,
|
|
142
142
|
depositorPubkey: e.prePeginParams.depositorPubkey,
|
|
@@ -152,7 +152,7 @@ async function Xe(e) {
|
|
|
152
152
|
councilQuorum: e.prePeginParams.councilQuorum,
|
|
153
153
|
councilSize: e.prePeginParams.councilSize,
|
|
154
154
|
network: e.prePeginParams.network,
|
|
155
|
-
authAnchorHash:
|
|
155
|
+
authAnchorHash: ee(
|
|
156
156
|
e.prePeginParams.authAnchorHash
|
|
157
157
|
)
|
|
158
158
|
},
|
|
@@ -160,87 +160,87 @@ async function Xe(e) {
|
|
|
160
160
|
e.fundedPrePeginTxHex,
|
|
161
161
|
e.htlcVout
|
|
162
162
|
);
|
|
163
|
-
return await
|
|
163
|
+
return await Ce(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 ye = 2, Ee = 1;
|
|
171
|
+
async function Ce(e, t) {
|
|
172
172
|
const n = t.prePeginParams.vaultCoreVersion;
|
|
173
|
-
await
|
|
174
|
-
const
|
|
175
|
-
if (
|
|
173
|
+
await ie(n, e.txHex);
|
|
174
|
+
const r = await j(n), o = ye + (r ? 1 : 0), i = m.fromHex(g(e.txHex));
|
|
175
|
+
if (i.ins.length !== 1)
|
|
176
176
|
throw new Error(
|
|
177
|
-
`PegIn tx has ${
|
|
177
|
+
`PegIn tx has ${i.ins.length} input(s), expected exactly 1 (the Pre-PegIn HTLC outpoint).`
|
|
178
178
|
);
|
|
179
|
-
const s =
|
|
180
|
-
|
|
179
|
+
const s = m.fromHex(
|
|
180
|
+
g(t.fundedPrePeginTxHex)
|
|
181
181
|
).getId(), u = _(
|
|
182
|
-
new Uint8Array(
|
|
182
|
+
new Uint8Array(i.ins[0].hash).slice().reverse()
|
|
183
183
|
);
|
|
184
184
|
if (u !== s)
|
|
185
185
|
throw new Error(
|
|
186
186
|
`PegIn input spends txid ${u}, expected the funded Pre-PegIn ${s}.`
|
|
187
187
|
);
|
|
188
|
-
if (
|
|
188
|
+
if (i.ins[0].index !== t.htlcVout)
|
|
189
189
|
throw new Error(
|
|
190
|
-
`PegIn input spends Pre-PegIn output ${
|
|
190
|
+
`PegIn input spends Pre-PegIn output ${i.ins[0].index}, expected the requested HTLC vout ${t.htlcVout}.`
|
|
191
191
|
);
|
|
192
|
-
if (
|
|
192
|
+
if (i.outs.length !== o)
|
|
193
193
|
throw new Error(
|
|
194
|
-
`PegIn tx has ${
|
|
194
|
+
`PegIn tx has ${i.outs.length} output(s), expected exactly ${o} for vaultCoreVersion ${n} (vault + depositor claim${r ? " + P2A anchor" : ""}).`
|
|
195
195
|
);
|
|
196
|
-
const
|
|
197
|
-
if (e.vaultValue !==
|
|
196
|
+
const h = t.prePeginParams.pegInAmounts[t.htlcVout];
|
|
197
|
+
if (e.vaultValue !== h)
|
|
198
198
|
throw new Error(
|
|
199
|
-
`PegIn vault output value ${e.vaultValue} does not match the requested peg-in amount ${
|
|
199
|
+
`PegIn vault output value ${e.vaultValue} does not match the requested peg-in amount ${h} for HTLC ${t.htlcVout}; refusing to sign a vault that locks a different amount than requested.`
|
|
200
200
|
);
|
|
201
|
-
const c =
|
|
201
|
+
const c = i.outs[0];
|
|
202
202
|
if (BigInt(c.value) !== e.vaultValue)
|
|
203
203
|
throw new Error(
|
|
204
204
|
`Encoded PegIn vault output value ${c.value} does not match the WASM-reported vaultValue ${e.vaultValue}.`
|
|
205
205
|
);
|
|
206
|
-
const
|
|
206
|
+
const l = c.script.toString("hex"), a = g(
|
|
207
207
|
e.vaultScriptPubKey
|
|
208
208
|
).toLowerCase();
|
|
209
|
-
if (
|
|
209
|
+
if (l.toLowerCase() !== a)
|
|
210
210
|
throw new Error(
|
|
211
|
-
`Encoded PegIn vault output scriptPubKey ${
|
|
211
|
+
`Encoded PegIn vault output scriptPubKey ${l} does not match the WASM-reported vaultScriptPubKey ${e.vaultScriptPubKey}.`
|
|
212
212
|
);
|
|
213
|
-
const
|
|
214
|
-
if (
|
|
213
|
+
const f = i.getId();
|
|
214
|
+
if (f !== g(e.txid).toLowerCase())
|
|
215
215
|
throw new Error(
|
|
216
|
-
`Encoded PegIn txid ${
|
|
216
|
+
`Encoded PegIn txid ${f} does not match the WASM-reported txid ${e.txid}.`
|
|
217
217
|
);
|
|
218
|
-
const
|
|
218
|
+
const d = await Z(
|
|
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
|
+
), x = i.outs[Ee];
|
|
226
|
+
if (BigInt(x.value) !== d)
|
|
227
227
|
throw new Error(
|
|
228
|
-
`Encoded PegIn depositor-claim output value ${
|
|
228
|
+
`Encoded PegIn depositor-claim output value ${x.value} does not match the independently computed claim value ${d} for vaultCoreVersion ${n}.`
|
|
229
229
|
);
|
|
230
|
-
const
|
|
230
|
+
const v = be(
|
|
231
231
|
t.prePeginParams.depositorPubkey
|
|
232
232
|
);
|
|
233
|
-
if (!
|
|
233
|
+
if (!x.script.equals(v))
|
|
234
234
|
throw new Error(
|
|
235
|
-
`Encoded PegIn depositor-claim output scriptPubKey ${
|
|
235
|
+
`Encoded PegIn depositor-claim output scriptPubKey ${x.script.toString("hex")} does not pay to the depositor's claim script (expected ${v.toString("hex")}).`
|
|
236
236
|
);
|
|
237
237
|
}
|
|
238
|
-
function
|
|
239
|
-
const t =
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
]), { output: n } =
|
|
243
|
-
internalPubkey:
|
|
238
|
+
function be(e) {
|
|
239
|
+
const t = ce.compile([
|
|
240
|
+
p.from(y(e)),
|
|
241
|
+
ae.OP_CHECKSIG
|
|
242
|
+
]), { output: n } = le.p2tr({
|
|
243
|
+
internalPubkey: p.from(J),
|
|
244
244
|
scriptTree: { output: t }
|
|
245
245
|
});
|
|
246
246
|
if (!n)
|
|
@@ -249,8 +249,8 @@ function Se(e) {
|
|
|
249
249
|
);
|
|
250
250
|
return n;
|
|
251
251
|
}
|
|
252
|
-
async function
|
|
253
|
-
const t = await
|
|
252
|
+
async function Ae(e) {
|
|
253
|
+
const t = await se(
|
|
254
254
|
{
|
|
255
255
|
txGraphVersion: e.vaultCoreVersion,
|
|
256
256
|
depositor: e.depositor,
|
|
@@ -269,48 +269,79 @@ async function me(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 Ie = 500, _e = 55, B = 0xffffffffn, F = 32, Te = 34;
|
|
273
|
+
function Ve(e) {
|
|
274
|
+
if (typeof e.protocolFeeRate != "bigint" || e.protocolFeeRate <= 0n || e.protocolFeeRate > B)
|
|
275
275
|
throw new Error(
|
|
276
|
-
`protocolFeeRate must be in [1, ${
|
|
276
|
+
`protocolFeeRate must be in [1, ${B}] sat/vB, got ${e.protocolFeeRate}`
|
|
277
277
|
);
|
|
278
278
|
for (const [t, n] of [
|
|
279
279
|
["keepers", e.numVaultKeepers],
|
|
280
280
|
["challengers", e.numUniversalChallengers]
|
|
281
281
|
])
|
|
282
|
-
if (!Number.isInteger(n) || n < 1 || n >
|
|
282
|
+
if (!Number.isInteger(n) || n < 1 || n > F)
|
|
283
283
|
throw new Error(
|
|
284
|
-
`Participant count for ${t} (${n}) is outside the device range [1, ${
|
|
284
|
+
`Participant count for ${t} (${n}) is outside the device range [1, ${F}].`
|
|
285
285
|
);
|
|
286
286
|
if (!Number.isInteger(e.councilSize) || e.councilSize < 1)
|
|
287
287
|
throw new Error(
|
|
288
288
|
`councilSize must be an integer >= 1, got ${e.councilSize}`
|
|
289
289
|
);
|
|
290
290
|
}
|
|
291
|
-
async function
|
|
292
|
-
const { implicitFeeSats: n, out0Len:
|
|
291
|
+
async function ke(e, t) {
|
|
292
|
+
const { implicitFeeSats: n, out0Len: r, out1Len: o } = t, i = e.numVaultKeepers + e.numUniversalChallengers, s = BigInt(n), u = Math.max(0, r - Te), h = Ie + _e * i + u, c = e.protocolFeeRate * BigInt(h);
|
|
293
293
|
if (s > c)
|
|
294
294
|
throw new Error(
|
|
295
|
-
`Payout implicit fee ${n} sats exceeds the safety cap of ${c} sats (${e.protocolFeeRate} sat/vB x ${
|
|
295
|
+
`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
296
|
);
|
|
297
|
-
const
|
|
297
|
+
const l = await ue(
|
|
298
298
|
e.vaultCoreVersion,
|
|
299
299
|
e.numVaultKeepers,
|
|
300
300
|
e.numUniversalChallengers,
|
|
301
301
|
e.numVaultKeepers,
|
|
302
302
|
e.councilSize,
|
|
303
|
-
|
|
303
|
+
r,
|
|
304
304
|
o,
|
|
305
305
|
e.protocolFeeRate
|
|
306
306
|
);
|
|
307
|
-
if (s <
|
|
307
|
+
if (s < l)
|
|
308
308
|
throw new Error(
|
|
309
|
-
`Payout implicit fee ${n} sats is below the floor of ${
|
|
309
|
+
`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
310
|
);
|
|
311
311
|
}
|
|
312
|
-
const
|
|
313
|
-
|
|
312
|
+
const He = 22, Le = 34, Oe = 34, Re = 25, Ue = 23;
|
|
313
|
+
function Ke(e) {
|
|
314
|
+
return e.length === He * 2 && e.startsWith("0014");
|
|
315
|
+
}
|
|
316
|
+
function Ne(e) {
|
|
317
|
+
return e.length === Le * 2 && e.startsWith("0020");
|
|
318
|
+
}
|
|
319
|
+
function Be(e) {
|
|
320
|
+
return e.length === Oe * 2 && e.startsWith("5120");
|
|
321
|
+
}
|
|
322
|
+
function Fe(e) {
|
|
323
|
+
return e.length === Re * 2 && e.startsWith("76a914") && e.endsWith("88ac");
|
|
324
|
+
}
|
|
325
|
+
function Me(e) {
|
|
326
|
+
return e.length === Ue * 2 && e.startsWith("a914") && e.endsWith("87");
|
|
327
|
+
}
|
|
328
|
+
function M(e, t) {
|
|
329
|
+
const n = g(e).toLowerCase();
|
|
330
|
+
if (n.length === 0)
|
|
331
|
+
throw new Error(`${t} is empty`);
|
|
332
|
+
if (!/^[0-9a-f]+$/.test(n) || n.length % 2 !== 0)
|
|
333
|
+
throw new Error(`${t} is not valid hex`);
|
|
334
|
+
if (n.startsWith("6a"))
|
|
335
|
+
throw new Error(
|
|
336
|
+
`${t} is an OP_RETURN output, which is provably unspendable`
|
|
337
|
+
);
|
|
338
|
+
if (!Be(n) && !Ke(n) && !Ne(n) && !Fe(n) && !Me(n))
|
|
339
|
+
throw new Error(
|
|
340
|
+
`${t} is not a standard scriptPubKey (expected P2TR, P2WPKH, P2WSH, P2PKH, or P2SH; got ${n.length / 2} bytes: ${n})`
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
const q = 3;
|
|
344
|
+
async function ut(e) {
|
|
314
345
|
const t = {
|
|
315
346
|
vaultCoreVersion: e.vaultCoreVersion,
|
|
316
347
|
numVaultKeepers: e.vaultKeeperBtcPubkeys.length,
|
|
@@ -318,42 +349,42 @@ async function ze(e) {
|
|
|
318
349
|
councilSize: e.councilSize,
|
|
319
350
|
protocolFeeRate: e.protocolFeeRate
|
|
320
351
|
};
|
|
321
|
-
|
|
322
|
-
const n =
|
|
323
|
-
if (n.ins.length !==
|
|
352
|
+
Ve(t);
|
|
353
|
+
const n = m.fromHex(g(e.payoutTxHex)), r = m.fromHex(g(e.peginTxHex)), o = m.fromHex(g(e.assertTxHex));
|
|
354
|
+
if (n.ins.length !== L)
|
|
324
355
|
throw new Error(
|
|
325
|
-
`Payout transaction must have exactly ${
|
|
356
|
+
`Payout transaction must have exactly ${L} inputs, got ${n.ins.length}`
|
|
326
357
|
);
|
|
327
|
-
const
|
|
358
|
+
const i = W(
|
|
328
359
|
n.ins[0],
|
|
329
360
|
0,
|
|
330
|
-
|
|
361
|
+
r,
|
|
331
362
|
"PegIn",
|
|
332
|
-
|
|
333
|
-
), s =
|
|
363
|
+
ge
|
|
364
|
+
), s = W(
|
|
334
365
|
n.ins[1],
|
|
335
366
|
1,
|
|
336
367
|
o,
|
|
337
368
|
"Assert",
|
|
338
|
-
|
|
339
|
-
), { out0Len: u, out1Len:
|
|
369
|
+
fe
|
|
370
|
+
), { out0Len: u, out1Len: h } = We(
|
|
340
371
|
n,
|
|
341
|
-
|
|
372
|
+
i.value,
|
|
342
373
|
e
|
|
343
|
-
), c =
|
|
344
|
-
let
|
|
345
|
-
for (const
|
|
346
|
-
if (
|
|
374
|
+
), c = i.value + s.value;
|
|
375
|
+
let l = 0;
|
|
376
|
+
for (const d of n.outs) l += d.value;
|
|
377
|
+
if (l > c)
|
|
347
378
|
throw new Error(
|
|
348
|
-
`Payout outputs (${
|
|
379
|
+
`Payout outputs (${l} sats) exceed inputs (${c} sats); invalid transaction.`
|
|
349
380
|
);
|
|
350
|
-
const
|
|
351
|
-
await
|
|
352
|
-
implicitFeeSats:
|
|
381
|
+
const a = c - l;
|
|
382
|
+
await ke(t, {
|
|
383
|
+
implicitFeeSats: a,
|
|
353
384
|
out0Len: u,
|
|
354
|
-
out1Len:
|
|
385
|
+
out1Len: h
|
|
355
386
|
});
|
|
356
|
-
const
|
|
387
|
+
const f = await Ae({
|
|
357
388
|
vaultCoreVersion: e.vaultCoreVersion,
|
|
358
389
|
depositor: e.depositorBtcPubkey,
|
|
359
390
|
vaultProvider: e.vaultProviderBtcPubkey,
|
|
@@ -363,51 +394,51 @@ async function ze(e) {
|
|
|
363
394
|
network: e.network
|
|
364
395
|
});
|
|
365
396
|
return {
|
|
366
|
-
psbtHex:
|
|
397
|
+
psbtHex: qe(
|
|
367
398
|
n,
|
|
368
|
-
|
|
399
|
+
i,
|
|
369
400
|
s,
|
|
370
|
-
|
|
401
|
+
f
|
|
371
402
|
)
|
|
372
403
|
};
|
|
373
404
|
}
|
|
374
|
-
function
|
|
375
|
-
const
|
|
405
|
+
function W(e, t, n, r, o) {
|
|
406
|
+
const i = _(
|
|
376
407
|
new Uint8Array(e.hash).slice().reverse()
|
|
377
408
|
), s = n.getId();
|
|
378
|
-
if (
|
|
409
|
+
if (i !== s || e.index !== o)
|
|
379
410
|
throw new Error(
|
|
380
|
-
`Input ${t} must spend ${
|
|
411
|
+
`Input ${t} must spend ${r}:${o}. Expected ${s}:${o}, got ${i}:${e.index}`
|
|
381
412
|
);
|
|
382
413
|
const u = n.outs[e.index];
|
|
383
414
|
if (!u)
|
|
384
415
|
throw new Error(
|
|
385
|
-
`Previous output not found for input ${t} (txid: ${
|
|
416
|
+
`Previous output not found for input ${t} (txid: ${i}, index: ${e.index})`
|
|
386
417
|
);
|
|
387
418
|
return u;
|
|
388
419
|
}
|
|
389
|
-
function
|
|
390
|
-
const o = new
|
|
420
|
+
function qe(e, t, n, r) {
|
|
421
|
+
const o = new C();
|
|
391
422
|
o.setVersion(e.version), o.setLocktime(e.locktime);
|
|
392
|
-
const [
|
|
423
|
+
const [i, s] = e.ins;
|
|
393
424
|
o.addInput({
|
|
394
|
-
hash:
|
|
395
|
-
index:
|
|
396
|
-
sequence:
|
|
425
|
+
hash: i.hash,
|
|
426
|
+
index: i.index,
|
|
427
|
+
sequence: i.sequence,
|
|
397
428
|
witnessUtxo: {
|
|
398
429
|
script: t.script,
|
|
399
430
|
value: t.value
|
|
400
431
|
},
|
|
401
432
|
tapLeafScript: [
|
|
402
433
|
{
|
|
403
|
-
leafVersion:
|
|
404
|
-
script:
|
|
405
|
-
controlBlock:
|
|
406
|
-
|
|
434
|
+
leafVersion: A,
|
|
435
|
+
script: p.from(y(r.payoutScript)),
|
|
436
|
+
controlBlock: p.from(
|
|
437
|
+
y(r.payoutControlBlock)
|
|
407
438
|
)
|
|
408
439
|
}
|
|
409
440
|
],
|
|
410
|
-
tapInternalKey:
|
|
441
|
+
tapInternalKey: p.from(J)
|
|
411
442
|
// sighashType omitted - defaults to SIGHASH_DEFAULT (0x00) for Taproot
|
|
412
443
|
}), o.addInput({
|
|
413
444
|
hash: s.hash,
|
|
@@ -425,99 +456,126 @@ function Ie(e, t, n, i) {
|
|
|
425
456
|
});
|
|
426
457
|
return o.toHex();
|
|
427
458
|
}
|
|
428
|
-
function
|
|
459
|
+
function X(e, t) {
|
|
460
|
+
const n = g(e).toLowerCase(), r = g(
|
|
461
|
+
Pe(t)
|
|
462
|
+
).toLowerCase();
|
|
463
|
+
return n === r ? [n] : [n, r];
|
|
464
|
+
}
|
|
465
|
+
function z(e, t) {
|
|
466
|
+
return t.some((n) => e.equals(p.from(n, "hex")));
|
|
467
|
+
}
|
|
468
|
+
function We(e, t, n) {
|
|
429
469
|
const {
|
|
430
|
-
claimerBtcPubkey:
|
|
470
|
+
claimerBtcPubkey: r,
|
|
431
471
|
vaultProviderBtcPubkey: o,
|
|
432
|
-
depositorBtcPubkey:
|
|
472
|
+
depositorBtcPubkey: i,
|
|
433
473
|
vaultKeeperBtcPubkeys: s,
|
|
434
474
|
registeredPayoutScriptPubKey: u,
|
|
435
|
-
commissionBps:
|
|
475
|
+
commissionBps: h,
|
|
476
|
+
vkClaimerPayoutScriptPubKeys: c,
|
|
477
|
+
vpCommissionScriptPubKey: l
|
|
436
478
|
} = n;
|
|
437
|
-
if (!
|
|
479
|
+
if (!pe(u))
|
|
438
480
|
throw new Error("Invalid registeredPayoutScriptPubKey: not valid hex");
|
|
439
|
-
const
|
|
440
|
-
(
|
|
481
|
+
const a = g(r).toLowerCase(), f = g(o).toLowerCase(), d = g(i).toLowerCase(), x = s.map(
|
|
482
|
+
(S) => g(S).toLowerCase()
|
|
441
483
|
);
|
|
442
|
-
let
|
|
443
|
-
if (
|
|
444
|
-
|
|
445
|
-
else if (
|
|
446
|
-
|
|
447
|
-
else if (
|
|
448
|
-
|
|
449
|
-
|
|
484
|
+
let v, P, w;
|
|
485
|
+
if (a === f)
|
|
486
|
+
v = "vp-claimer", P = we, w = [g(u)];
|
|
487
|
+
else if (a === d)
|
|
488
|
+
v = "depositor-as-claimer", P = K, w = [g(u)];
|
|
489
|
+
else if (x.includes(a)) {
|
|
490
|
+
v = "vk-claimer", P = K;
|
|
491
|
+
const S = c[a];
|
|
492
|
+
if (S === void 0)
|
|
493
|
+
throw new Error(
|
|
494
|
+
`No registered payout script resolved for vault keeper claimer ${a}`
|
|
495
|
+
);
|
|
496
|
+
M(
|
|
497
|
+
S,
|
|
498
|
+
`Vault keeper payout script for claimer ${a}`
|
|
499
|
+
), w = X(S, a);
|
|
500
|
+
} else
|
|
450
501
|
throw new Error(
|
|
451
|
-
`Unknown claimer pubkey ${
|
|
502
|
+
`Unknown claimer pubkey ${a}: not VP, depositor, or a registered vault keeper`
|
|
452
503
|
);
|
|
453
|
-
if (e.outs.length !==
|
|
504
|
+
if (e.outs.length !== P)
|
|
454
505
|
throw new Error(
|
|
455
|
-
`Payout transaction has ${e.outs.length} output(s), expected exactly ${
|
|
506
|
+
`Payout transaction has ${e.outs.length} output(s), expected exactly ${P} for role ${v}.`
|
|
456
507
|
);
|
|
457
|
-
|
|
458
|
-
if (!e.outs[0].script.equals(f))
|
|
508
|
+
if (!z(e.outs[0].script, w))
|
|
459
509
|
throw new Error(
|
|
460
|
-
`Payout transaction output 0 does not pay the expected scriptPubKey for role ${
|
|
510
|
+
`Payout transaction output 0 does not pay the expected scriptPubKey for role ${v}. Accepted: ${w.join(" or ")}; got ${e.outs[0].script.toString("hex")}`
|
|
461
511
|
);
|
|
462
|
-
const
|
|
463
|
-
if (e.outs[
|
|
512
|
+
const b = P - 1;
|
|
513
|
+
if (e.outs[b].value !== O)
|
|
464
514
|
throw new Error(
|
|
465
|
-
`Payout CPFP anchor (out ${
|
|
515
|
+
`Payout CPFP anchor (out ${b}) value ${e.outs[b].value} sats must equal ${O} sats`
|
|
466
516
|
);
|
|
467
|
-
if (
|
|
468
|
-
|
|
517
|
+
if (v === "vp-claimer") {
|
|
518
|
+
M(
|
|
519
|
+
l,
|
|
520
|
+
"Vault provider commission payout script"
|
|
521
|
+
);
|
|
522
|
+
const S = X(
|
|
523
|
+
l,
|
|
524
|
+
f
|
|
525
|
+
);
|
|
526
|
+
if (!z(e.outs[1].script, S))
|
|
527
|
+
throw new Error(
|
|
528
|
+
`Payout transaction output 1 does not pay the vault provider's commission scriptPubKey. Accepted: ${S.join(" or ")}; got ${e.outs[1].script.toString("hex")}`
|
|
529
|
+
);
|
|
530
|
+
if (!Number.isInteger(h) || h < 0 || h >= R)
|
|
469
531
|
throw new Error(
|
|
470
|
-
`commissionBps must be an integer in [0, ${
|
|
532
|
+
`commissionBps must be an integer in [0, ${R}), got ${h}`
|
|
471
533
|
);
|
|
472
|
-
const
|
|
473
|
-
t *
|
|
534
|
+
const T = Math.floor(
|
|
535
|
+
t * h / ve
|
|
474
536
|
);
|
|
475
|
-
if (e.outs[1].value >
|
|
537
|
+
if (e.outs[1].value > T)
|
|
476
538
|
throw new Error(
|
|
477
|
-
`Payout VP commission (out 1) value ${e.outs[1].value} sats exceeds cap ${
|
|
539
|
+
`Payout VP commission (out 1) value ${e.outs[1].value} sats exceeds cap ${T} sats (${h} bps of peginValue=${t})`
|
|
478
540
|
);
|
|
479
541
|
}
|
|
480
|
-
const E =
|
|
481
|
-
if (E === 0 || E >
|
|
482
|
-
throw new Error(
|
|
483
|
-
`Payout receiver scriptPubKey length ${E} is outside the contract's registration cap [1, ${b}]; refusing to sign payout.`
|
|
484
|
-
);
|
|
485
|
-
const y = a === "vp-claimer" ? e.outs[1].script.length : void 0;
|
|
486
|
-
if (y !== void 0 && (y === 0 || y > b))
|
|
542
|
+
const E = e.outs[0].script.length;
|
|
543
|
+
if (E === 0 || E > U)
|
|
487
544
|
throw new Error(
|
|
488
|
-
`Payout
|
|
545
|
+
`Payout receiver scriptPubKey length ${E} is outside the contract's registration cap [1, ${U}]; refusing to sign payout.`
|
|
489
546
|
);
|
|
490
|
-
|
|
547
|
+
const te = v === "vp-claimer" ? e.outs[1].script.length : void 0;
|
|
548
|
+
return { out0Len: E, out1Len: te };
|
|
491
549
|
}
|
|
492
|
-
function
|
|
493
|
-
const
|
|
494
|
-
if (n >=
|
|
550
|
+
function ct(e, t, n = 0) {
|
|
551
|
+
const r = C.fromHex(e);
|
|
552
|
+
if (n >= r.data.inputs.length)
|
|
495
553
|
throw new Error(
|
|
496
|
-
`Input index ${n} out of range (${
|
|
554
|
+
`Input index ${n} out of range (${r.data.inputs.length} inputs)`
|
|
497
555
|
);
|
|
498
|
-
const o =
|
|
556
|
+
const o = r.data.inputs[n];
|
|
499
557
|
if (o.tapScriptSig && o.tapScriptSig.length > 0) {
|
|
500
|
-
const
|
|
558
|
+
const i = y(t);
|
|
501
559
|
for (const s of o.tapScriptSig)
|
|
502
|
-
if (s.pubkey.equals(
|
|
503
|
-
return
|
|
560
|
+
if (s.pubkey.equals(p.from(i)))
|
|
561
|
+
return D(s.signature, n);
|
|
504
562
|
throw new Error(
|
|
505
563
|
`No signature found for depositor pubkey: ${t} at input ${n}`
|
|
506
564
|
);
|
|
507
565
|
}
|
|
508
566
|
if (o.finalScriptWitness && o.finalScriptWitness.length > 0) {
|
|
509
|
-
const
|
|
510
|
-
if (
|
|
567
|
+
const i = Xe(o.finalScriptWitness);
|
|
568
|
+
if (i.length !== q)
|
|
511
569
|
throw new Error(
|
|
512
|
-
`Unexpected finalized witness stack size at input ${n}: expected ${
|
|
570
|
+
`Unexpected finalized witness stack size at input ${n}: expected ${q} items (signature, script, controlBlock), got ${i.length}`
|
|
513
571
|
);
|
|
514
|
-
return
|
|
572
|
+
return D(i[0], n);
|
|
515
573
|
}
|
|
516
574
|
throw new Error(
|
|
517
575
|
`No tapScriptSig or finalScriptWitness found in signed PSBT at input ${n}`
|
|
518
576
|
);
|
|
519
577
|
}
|
|
520
|
-
function
|
|
578
|
+
function D(e, t) {
|
|
521
579
|
if (e.length === 64)
|
|
522
580
|
return _(new Uint8Array(e));
|
|
523
581
|
throw e.length === 65 ? new Error(
|
|
@@ -526,199 +584,199 @@ function q(e, t) {
|
|
|
526
584
|
`Unexpected signature length at input ${t}: ${e.length}`
|
|
527
585
|
);
|
|
528
586
|
}
|
|
529
|
-
function
|
|
587
|
+
function Xe(e) {
|
|
530
588
|
const t = [];
|
|
531
589
|
let n = 0;
|
|
532
|
-
const
|
|
590
|
+
const r = (s) => {
|
|
533
591
|
if (n + s > e.length)
|
|
534
592
|
throw new Error(
|
|
535
593
|
`Malformed witness data: need ${s} byte(s) at offset ${n}, only ${e.length - n} remaining`
|
|
536
594
|
);
|
|
537
595
|
}, o = () => {
|
|
538
|
-
|
|
596
|
+
r(1);
|
|
539
597
|
const s = e[n++];
|
|
540
598
|
if (s < 253) return s;
|
|
541
599
|
if (s === 253) {
|
|
542
|
-
|
|
600
|
+
r(2);
|
|
543
601
|
const u = (e[n] | e[n + 1] << 8) >>> 0;
|
|
544
602
|
return n += 2, u;
|
|
545
603
|
}
|
|
546
604
|
if (s === 254) {
|
|
547
|
-
|
|
605
|
+
r(4);
|
|
548
606
|
const u = (e[n] | e[n + 1] << 8 | e[n + 2] << 16 | e[n + 3] << 24) >>> 0;
|
|
549
607
|
return n += 4, u;
|
|
550
608
|
}
|
|
551
609
|
throw new Error(
|
|
552
610
|
`Malformed witness data: 8-byte varint (0xff) not supported at offset ${n - 1}`
|
|
553
611
|
);
|
|
554
|
-
},
|
|
555
|
-
for (let s = 0; s <
|
|
612
|
+
}, i = o();
|
|
613
|
+
for (let s = 0; s < i; s++) {
|
|
556
614
|
const u = o();
|
|
557
|
-
|
|
615
|
+
r(u), t.push(p.from(e.subarray(n, n + u))), n += u;
|
|
558
616
|
}
|
|
559
617
|
if (n !== e.length)
|
|
560
618
|
throw new Error(
|
|
561
|
-
`Malformed witness data: ${e.length - n} trailing byte(s) after parsing ${
|
|
619
|
+
`Malformed witness data: ${e.length - n} trailing byte(s) after parsing ${i} item(s)`
|
|
562
620
|
);
|
|
563
621
|
return t;
|
|
564
622
|
}
|
|
565
|
-
class
|
|
623
|
+
class $ extends Error {
|
|
566
624
|
constructor(t) {
|
|
567
625
|
super(
|
|
568
626
|
`Wallet returned a PSBT for a different transaction: ${t}`
|
|
569
627
|
), this.name = "PsbtSubstitutionError";
|
|
570
628
|
}
|
|
571
629
|
}
|
|
572
|
-
function
|
|
630
|
+
function G(e, t) {
|
|
573
631
|
try {
|
|
574
|
-
return
|
|
632
|
+
return C.fromHex(t);
|
|
575
633
|
} catch (n) {
|
|
576
|
-
const
|
|
577
|
-
throw new Error(`Failed to parse ${e} PSBT: ${
|
|
634
|
+
const r = n instanceof Error ? n.message : String(n);
|
|
635
|
+
throw new Error(`Failed to parse ${e} PSBT: ${r}`);
|
|
578
636
|
}
|
|
579
637
|
}
|
|
580
|
-
const
|
|
581
|
-
function
|
|
582
|
-
return `${e.toString("hex").slice(0,
|
|
638
|
+
const ze = 8;
|
|
639
|
+
function I(e) {
|
|
640
|
+
return `${e.toString("hex").slice(0, ze)}…`;
|
|
583
641
|
}
|
|
584
|
-
function
|
|
585
|
-
const t =
|
|
586
|
-
return
|
|
642
|
+
function Y(e) {
|
|
643
|
+
const t = p.from(e).reverse();
|
|
644
|
+
return I(t);
|
|
587
645
|
}
|
|
588
|
-
function
|
|
589
|
-
const t =
|
|
646
|
+
function at(e) {
|
|
647
|
+
const t = G("requested", e.requestedPsbtHex), n = G("returned", e.returnedPsbtHex);
|
|
590
648
|
if (t.version !== n.version)
|
|
591
|
-
throw new
|
|
649
|
+
throw new $(
|
|
592
650
|
`tx version differs (requested=${t.version}, returned=${n.version})`
|
|
593
651
|
);
|
|
594
652
|
if (t.locktime !== n.locktime)
|
|
595
|
-
throw new
|
|
653
|
+
throw new $(
|
|
596
654
|
`tx locktime differs (requested=${t.locktime}, returned=${n.locktime})`
|
|
597
655
|
);
|
|
598
656
|
if (t.txInputs.length !== n.txInputs.length)
|
|
599
|
-
throw new
|
|
657
|
+
throw new $(
|
|
600
658
|
`input count differs (requested=${t.txInputs.length}, returned=${n.txInputs.length})`
|
|
601
659
|
);
|
|
602
660
|
if (t.txOutputs.length !== n.txOutputs.length)
|
|
603
|
-
throw new
|
|
661
|
+
throw new $(
|
|
604
662
|
`output count differs (requested=${t.txOutputs.length}, returned=${n.txOutputs.length})`
|
|
605
663
|
);
|
|
606
|
-
for (let
|
|
607
|
-
const o = t.txInputs[
|
|
608
|
-
if (!o.hash.equals(
|
|
609
|
-
throw new
|
|
610
|
-
`input ${
|
|
664
|
+
for (let r = 0; r < t.txInputs.length; r++) {
|
|
665
|
+
const o = t.txInputs[r], i = n.txInputs[r];
|
|
666
|
+
if (!o.hash.equals(i.hash))
|
|
667
|
+
throw new $(
|
|
668
|
+
`input ${r} prevout txid differs (requested=${Y(o.hash)}, returned=${Y(i.hash)})`
|
|
611
669
|
);
|
|
612
|
-
if (o.index !==
|
|
613
|
-
throw new
|
|
614
|
-
`input ${
|
|
670
|
+
if (o.index !== i.index)
|
|
671
|
+
throw new $(
|
|
672
|
+
`input ${r} prevout vout differs (requested=${o.index}, returned=${i.index})`
|
|
615
673
|
);
|
|
616
|
-
if (o.sequence !==
|
|
617
|
-
throw new
|
|
618
|
-
`input ${
|
|
674
|
+
if (o.sequence !== i.sequence)
|
|
675
|
+
throw new $(
|
|
676
|
+
`input ${r} sequence differs (requested=${o.sequence}, returned=${i.sequence})`
|
|
619
677
|
);
|
|
620
678
|
}
|
|
621
|
-
for (let
|
|
622
|
-
const o = t.txOutputs[
|
|
623
|
-
if (!o.script.equals(
|
|
624
|
-
throw new
|
|
625
|
-
`output ${
|
|
679
|
+
for (let r = 0; r < t.txOutputs.length; r++) {
|
|
680
|
+
const o = t.txOutputs[r], i = n.txOutputs[r];
|
|
681
|
+
if (!o.script.equals(i.script))
|
|
682
|
+
throw new $(
|
|
683
|
+
`output ${r} scriptPubKey differs (requested=${I(o.script)}, returned=${I(i.script)})`
|
|
626
684
|
);
|
|
627
|
-
if (o.value !==
|
|
628
|
-
throw new
|
|
629
|
-
`output ${
|
|
685
|
+
if (o.value !== i.value)
|
|
686
|
+
throw new $(
|
|
687
|
+
`output ${r} value differs (requested=${o.value}, returned=${i.value})`
|
|
630
688
|
);
|
|
631
689
|
}
|
|
632
690
|
}
|
|
633
|
-
const
|
|
634
|
-
function
|
|
635
|
-
if (e <
|
|
636
|
-
return
|
|
637
|
-
if (e <=
|
|
638
|
-
const t =
|
|
639
|
-
return t.writeUInt16LE(e),
|
|
691
|
+
const Q = 253, De = 254, Ge = 65535, Ye = 4294967295;
|
|
692
|
+
function Qe(e) {
|
|
693
|
+
if (e < Q)
|
|
694
|
+
return p.from([e]);
|
|
695
|
+
if (e <= Ge) {
|
|
696
|
+
const t = p.alloc(2);
|
|
697
|
+
return t.writeUInt16LE(e), p.concat([p.from([Q]), t]);
|
|
640
698
|
}
|
|
641
|
-
if (e <=
|
|
642
|
-
const t =
|
|
643
|
-
return t.writeUInt32LE(e),
|
|
699
|
+
if (e <= Ye) {
|
|
700
|
+
const t = p.alloc(4);
|
|
701
|
+
return t.writeUInt32LE(e), p.concat([p.from([De]), t]);
|
|
644
702
|
}
|
|
645
703
|
throw new Error(`Script too large to encode as CompactSize: ${e} bytes`);
|
|
646
704
|
}
|
|
647
|
-
const
|
|
648
|
-
function
|
|
649
|
-
const n =
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
705
|
+
const Ze = "TapLeaf";
|
|
706
|
+
function je(e, t) {
|
|
707
|
+
const n = p.concat([
|
|
708
|
+
p.from([e]),
|
|
709
|
+
Qe(t.length),
|
|
710
|
+
p.from(t)
|
|
653
711
|
]);
|
|
654
|
-
return
|
|
712
|
+
return he.taggedHash(Ze, n);
|
|
655
713
|
}
|
|
656
|
-
function
|
|
657
|
-
const { requestedPsbtHex: t, signatureHex: n, signerXOnlyPubkeyHex:
|
|
658
|
-
if (
|
|
714
|
+
function lt(e) {
|
|
715
|
+
const { requestedPsbtHex: t, signatureHex: n, signerXOnlyPubkeyHex: r, inputIndex: o } = e, i = g(n);
|
|
716
|
+
if (i.length !== k)
|
|
659
717
|
throw new Error(
|
|
660
|
-
`Schnorr signature for input ${o} must be ${k} hex chars (64 bytes), got ${
|
|
718
|
+
`Schnorr signature for input ${o} must be ${k} hex chars (64 bytes), got ${i.length}.`
|
|
661
719
|
);
|
|
662
|
-
const s =
|
|
720
|
+
const s = g(r);
|
|
663
721
|
if (s.length !== H)
|
|
664
722
|
throw new Error(
|
|
665
723
|
`Signer x-only pubkey for input ${o} must be ${H} hex chars (32 bytes), got ${s.length}.`
|
|
666
724
|
);
|
|
667
|
-
const u =
|
|
725
|
+
const u = C.fromHex(t);
|
|
668
726
|
if (o < 0 || o >= u.data.inputs.length)
|
|
669
727
|
throw new Error(
|
|
670
728
|
`Input index ${o} out of range (${u.data.inputs.length} inputs).`
|
|
671
729
|
);
|
|
672
|
-
const
|
|
673
|
-
for (let
|
|
674
|
-
const
|
|
675
|
-
if (!
|
|
730
|
+
const h = [], c = [];
|
|
731
|
+
for (let P = 0; P < u.data.inputs.length; P++) {
|
|
732
|
+
const w = u.data.inputs[P].witnessUtxo;
|
|
733
|
+
if (!w)
|
|
676
734
|
throw new Error(
|
|
677
|
-
`Cannot verify signature: input ${
|
|
735
|
+
`Cannot verify signature: input ${P} of the requested PSBT has no witnessUtxo (required to recompute the Taproot sighash).`
|
|
678
736
|
);
|
|
679
|
-
|
|
737
|
+
h.push(w.script), c.push(w.value);
|
|
680
738
|
}
|
|
681
|
-
const
|
|
682
|
-
if (!
|
|
739
|
+
const l = u.data.inputs[o].tapLeafScript;
|
|
740
|
+
if (!l || l.length !== 1)
|
|
683
741
|
throw new Error(
|
|
684
|
-
`Cannot verify signature: input ${o} of the requested PSBT must have exactly one tapLeafScript, got ${(
|
|
742
|
+
`Cannot verify signature: input ${o} of the requested PSBT must have exactly one tapLeafScript, got ${(l == null ? void 0 : l.length) ?? 0}.`
|
|
685
743
|
);
|
|
686
|
-
const
|
|
687
|
-
if (
|
|
744
|
+
const a = l[0];
|
|
745
|
+
if (a.leafVersion !== A)
|
|
688
746
|
throw new Error(
|
|
689
|
-
`Cannot verify signature: input ${o} tapLeafScript has leaf version 0x${
|
|
747
|
+
`Cannot verify signature: input ${o} tapLeafScript has leaf version 0x${a.leafVersion.toString(16)}, expected 0x${A.toString(16)}.`
|
|
690
748
|
);
|
|
691
|
-
const
|
|
692
|
-
|
|
693
|
-
for (const
|
|
694
|
-
|
|
695
|
-
for (const
|
|
696
|
-
|
|
697
|
-
const
|
|
749
|
+
const f = je(a.leafVersion, a.script), d = new m();
|
|
750
|
+
d.version = u.version, d.locktime = u.locktime;
|
|
751
|
+
for (const P of u.txInputs)
|
|
752
|
+
d.addInput(P.hash, P.index, P.sequence);
|
|
753
|
+
for (const P of u.txOutputs)
|
|
754
|
+
d.addOutput(P.script, P.value);
|
|
755
|
+
const x = d.hashForWitnessV1(
|
|
698
756
|
o,
|
|
699
|
-
|
|
757
|
+
h,
|
|
700
758
|
c,
|
|
701
|
-
|
|
702
|
-
|
|
759
|
+
m.SIGHASH_DEFAULT,
|
|
760
|
+
f
|
|
703
761
|
);
|
|
704
|
-
if (
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
762
|
+
if (!$e.verifySchnorr(
|
|
763
|
+
x,
|
|
764
|
+
y(s),
|
|
765
|
+
y(i)
|
|
708
766
|
))
|
|
709
767
|
throw new Error(
|
|
710
768
|
`Schnorr signature for input ${o} (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.`
|
|
711
769
|
);
|
|
712
770
|
}
|
|
713
771
|
export {
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
772
|
+
$ as P,
|
|
773
|
+
it as a,
|
|
774
|
+
st as b,
|
|
775
|
+
ut as c,
|
|
776
|
+
at as d,
|
|
777
|
+
ct as e,
|
|
778
|
+
lt as f,
|
|
779
|
+
Ae as g,
|
|
780
|
+
ee as n
|
|
723
781
|
};
|
|
724
|
-
//# sourceMappingURL=verifyScriptPathSchnorrSignature-
|
|
782
|
+
//# sourceMappingURL=verifyScriptPathSchnorrSignature-Xoo9DOHW.js.map
|