@babylonlabs-io/ts-sdk 3.3.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{BTCVaultRegistry.abi-BzNTa_EU.js → BTCVaultRegistry.abi-DnP4UkB5.js} +9 -140
- package/dist/BTCVaultRegistry.abi-DnP4UkB5.js.map +1 -0
- package/dist/{BTCVaultRegistry.abi-BH2-LHxN.cjs → BTCVaultRegistry.abi-DzbfZ9_s.cjs} +2 -2
- package/dist/BTCVaultRegistry.abi-DzbfZ9_s.cjs.map +1 -0
- package/dist/{PayoutManager-xEGvTbhL.js → PayoutManager-BUWP-H-q.js} +3 -3
- package/dist/PayoutManager-BUWP-H-q.js.map +1 -0
- package/dist/{PayoutManager-B1Ev0r7o.cjs → PayoutManager-Dopxq_Jv.cjs} +2 -2
- package/dist/PayoutManager-Dopxq_Jv.cjs.map +1 -0
- package/dist/PeginManager-CMbRRTnr.cjs +2 -0
- package/dist/{PeginManager-Co43rW_x.cjs.map → PeginManager-CMbRRTnr.cjs.map} +1 -1
- package/dist/{PeginManager-BJnUgW8C.js → PeginManager-Cas6_j7t.js} +118 -107
- package/dist/{PeginManager-BJnUgW8C.js.map → PeginManager-Cas6_j7t.js.map} +1 -1
- package/dist/{ProtocolParams.abi-Cv77fsUe.js → ProtocolParams.abi-CuDl7AuC.js} +3 -3
- package/dist/{ProtocolParams.abi-Cv77fsUe.js.map → ProtocolParams.abi-CuDl7AuC.js.map} +1 -1
- package/dist/{ProtocolParams.abi-BgEZaQ2I.cjs → ProtocolParams.abi-DWfIh6VH.cjs} +2 -2
- package/dist/{ProtocolParams.abi-BgEZaQ2I.cjs.map → ProtocolParams.abi-DWfIh6VH.cjs.map} +1 -1
- package/dist/VaultErrors.abi-Dc3UnB_h.js +5 -0
- package/dist/{VaultErrors.abi-Boz4w97c.js.map → VaultErrors.abi-Dc3UnB_h.js.map} +1 -1
- package/dist/VaultErrors.abi-Hjn1CdLs.cjs +2 -0
- package/dist/{VaultErrors.abi-DQ18kM0L.cjs.map → VaultErrors.abi-Hjn1CdLs.cjs.map} +1 -1
- package/dist/buildAndBroadcastReclaim-CVmG3ldA.cjs +2 -0
- package/dist/buildAndBroadcastReclaim-CVmG3ldA.cjs.map +1 -0
- package/dist/{buildAndBroadcastReclaim-CQANDXVJ.js → buildAndBroadcastReclaim-XRWuJWVL.js} +48 -50
- package/dist/buildAndBroadcastReclaim-XRWuJWVL.js.map +1 -0
- package/dist/{challengeAssert-C3eMcM5Y.cjs → challengeAssert-BE6Wm4x1.cjs} +2 -2
- package/dist/challengeAssert-BE6Wm4x1.cjs.map +1 -0
- package/dist/{challengeAssert-B2otuf7y.js → challengeAssert-DUKSjirl.js} +3 -3
- package/dist/challengeAssert-DUKSjirl.js.map +1 -0
- package/dist/constants-BCg6O0PX.cjs +2 -0
- package/dist/constants-BCg6O0PX.cjs.map +1 -0
- package/dist/constants-CmDDuM3L.js +50 -0
- package/dist/constants-CmDDuM3L.js.map +1 -0
- package/dist/{index-BRsWXDlv.js → index-B-9aXMxk.js} +6 -6
- package/dist/{index-BRsWXDlv.js.map → index-B-9aXMxk.js.map} +1 -1
- package/dist/{index-C6avwx1s.cjs → index-Dn7RlsKK.cjs} +2 -2
- package/dist/{index-C6avwx1s.cjs.map → index-Dn7RlsKK.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +16 -16
- package/dist/pegin-registration-client-DLlaZbsZ.cjs +2 -0
- package/dist/pegin-registration-client-DLlaZbsZ.cjs.map +1 -0
- package/dist/{pegin-registration-client-Cvjk4ILq.js → pegin-registration-client-ZI0k10_3.js} +90 -96
- package/dist/pegin-registration-client-ZI0k10_3.js.map +1 -0
- package/dist/{primeVpAuth-D4UWXQ76.js → primeVpAuth-C-ET0XF4.js} +2 -2
- package/dist/{primeVpAuth-D4UWXQ76.js.map → primeVpAuth-C-ET0XF4.js.map} +1 -1
- package/dist/{primeVpAuth-CXNXYKrh.cjs → primeVpAuth-Ch-ig2My.cjs} +2 -2
- package/dist/{primeVpAuth-CXNXYKrh.cjs.map → primeVpAuth-Ch-ig2My.cjs.map} +1 -1
- package/dist/registration-records-CKc0OVuK.cjs +2 -0
- package/dist/registration-records-CKc0OVuK.cjs.map +1 -0
- package/dist/{registration-records-DJJC2NiO.js → registration-records-D39ApuHS.js} +141 -141
- package/dist/registration-records-D39ApuHS.js.map +1 -0
- package/dist/shared/index.cjs.map +1 -1
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/wallets/interfaces/BitcoinWallet.d.ts +5 -0
- package/dist/shared/wallets/interfaces/BitcoinWallet.d.ts.map +1 -1
- package/dist/{signer-set-reader-GrFe_rsW.cjs → signer-set-reader-CJfV-GDz.cjs} +2 -2
- package/dist/{signer-set-reader-GrFe_rsW.cjs.map → signer-set-reader-CJfV-GDz.cjs.map} +1 -1
- package/dist/{signer-set-reader-CSUe92zE.js → signer-set-reader-DiwLeqik.js} +3 -3
- package/dist/{signer-set-reader-CSUe92zE.js.map → signer-set-reader-DiwLeqik.js.map} +1 -1
- package/dist/tbv/core/clients/eth/index.cjs +1 -1
- package/dist/tbv/core/clients/eth/index.js +4 -4
- package/dist/tbv/core/clients/eth/protocol-params-validation.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/registration-logs-error.d.ts +6 -6
- package/dist/tbv/core/clients/eth/registration-records.d.ts +1 -1
- package/dist/tbv/core/clients/eth/types.d.ts +12 -13
- package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts +1 -1
- package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts.map +1 -1
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +6 -6
- package/dist/tbv/core/clients/vault-provider/status/index.cjs +1 -1
- package/dist/tbv/core/clients/vault-provider/status/index.js +1 -1
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts +5 -111
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts.map +1 -1
- package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts +2 -2
- package/dist/tbv/core/contracts/abis/vaultErrors.abi.json.d.ts +1 -1
- package/dist/tbv/core/contracts/index.cjs +1 -1
- package/dist/tbv/core/contracts/index.js +3 -3
- package/dist/tbv/core/deposit-terms/__tests__/rebuildDepositTermsCore.test.d.ts +1 -1
- package/dist/tbv/core/deposit-terms/commissionCeiling.d.ts +1 -1
- package/dist/tbv/core/deposit-terms/depositTerms.d.ts +5 -5
- package/dist/tbv/core/deposit-terms/rebuildDepositTermsCore.d.ts.map +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +16 -16
- package/dist/tbv/core/managers/PeginManager.d.ts +2 -1
- 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/__tests__/vaultCoreVersion.test.d.ts +1 -1
- package/dist/tbv/core/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.js +3 -3
- package/dist/tbv/core/primitives/psbt/__tests__/deriveExpectedPeginPayoutScriptPubKey.test.d.ts +1 -1
- package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/constants.d.ts +38 -13
- package/dist/tbv/core/primitives/psbt/constants.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/depositorClaim.d.ts +3 -6
- package/dist/tbv/core/primitives/psbt/depositorClaim.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/pegin.d.ts +3 -5
- package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
- package/dist/tbv/core/recovery/peginParamsCandidates.d.ts +1 -1
- package/dist/tbv/core/recovery/reconstructPeginParams.d.ts.map +1 -1
- package/dist/tbv/core/services/delegated-claim/__tests__/realWasmWatchtowerArtifacts.test.d.ts +2 -2
- package/dist/tbv/core/services/delegated-claim/assembleWatchtowerArtifacts.d.ts +2 -1
- package/dist/tbv/core/services/delegated-claim/assembleWatchtowerArtifacts.d.ts.map +1 -1
- package/dist/tbv/core/services/delegated-claim/deriveClaimerWotsKeypair.d.ts +1 -1
- package/dist/tbv/core/services/delegated-claim/deriveClaimerWotsKeypair.d.ts.map +1 -1
- package/dist/tbv/core/services/delegated-claim/planDelegatedClaimSigning.d.ts +2 -1
- package/dist/tbv/core/services/delegated-claim/planDelegatedClaimSigning.d.ts.map +1 -1
- package/dist/tbv/core/services/delegated-claim/readDelegatedClaimVaultContext.d.ts +1 -1
- package/dist/tbv/core/services/delegated-claim/readDelegatedClaimVaultContext.d.ts.map +1 -1
- package/dist/tbv/core/services/delegated-claim/readWatchtowerArtifacts.d.ts +3 -3
- package/dist/tbv/core/services/delegated-claim/readWatchtowerArtifacts.d.ts.map +1 -1
- package/dist/tbv/core/services/delegated-claim/types.d.ts +5 -6
- package/dist/tbv/core/services/delegated-claim/types.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/__tests__/signDepositorGraph.realGraph.test.d.ts +3 -3
- package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts.map +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +2 -2
- package/dist/tbv/core/wasm/index.cjs.map +1 -1
- package/dist/tbv/core/wasm/index.d.ts +8 -11
- package/dist/tbv/core/wasm/index.d.ts.map +1 -1
- package/dist/tbv/core/wasm/index.js.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +16 -16
- package/dist/toRefundInputs-BSQjDOK9.cjs +2 -0
- package/dist/toRefundInputs-BSQjDOK9.cjs.map +1 -0
- package/dist/{toRefundInputs-Dzw1cteD.js → toRefundInputs-BbbvPb2A.js} +175 -173
- package/dist/toRefundInputs-BbbvPb2A.js.map +1 -0
- package/dist/{types-BC2TGzcp.cjs → types-BnZIbDHb.cjs} +2 -2
- package/dist/types-BnZIbDHb.cjs.map +1 -0
- package/dist/{types-24A9Qoxb.js → types-K_aM5GZO.js} +39 -39
- package/dist/types-K_aM5GZO.js.map +1 -0
- package/dist/{verifyKeyPathSchnorrSignature-IIj3Z2se.js → verifyKeyPathSchnorrSignature-DPXOFOol.js} +2 -2
- package/dist/{verifyKeyPathSchnorrSignature-IIj3Z2se.js.map → verifyKeyPathSchnorrSignature-DPXOFOol.js.map} +1 -1
- package/dist/{verifyKeyPathSchnorrSignature-BRTpEH9X.cjs → verifyKeyPathSchnorrSignature-DcxCojp0.cjs} +2 -2
- package/dist/{verifyKeyPathSchnorrSignature-BRTpEH9X.cjs.map → verifyKeyPathSchnorrSignature-DcxCojp0.cjs.map} +1 -1
- package/dist/verifyScriptPathSchnorrSignature-CgDa9Rcg.cjs +2 -0
- package/dist/verifyScriptPathSchnorrSignature-CgDa9Rcg.cjs.map +1 -0
- package/dist/{verifyScriptPathSchnorrSignature-owu3BfyT.js → verifyScriptPathSchnorrSignature-D-fdi-sG.js} +462 -459
- package/dist/verifyScriptPathSchnorrSignature-D-fdi-sG.js.map +1 -0
- package/package.json +3 -3
- package/dist/BTCVaultRegistry.abi-BH2-LHxN.cjs.map +0 -1
- package/dist/BTCVaultRegistry.abi-BzNTa_EU.js.map +0 -1
- package/dist/PayoutManager-B1Ev0r7o.cjs.map +0 -1
- package/dist/PayoutManager-xEGvTbhL.js.map +0 -1
- package/dist/PeginManager-Co43rW_x.cjs +0 -2
- package/dist/VaultErrors.abi-Boz4w97c.js +0 -5
- package/dist/VaultErrors.abi-DQ18kM0L.cjs +0 -2
- package/dist/buildAndBroadcastReclaim-CQANDXVJ.js.map +0 -1
- package/dist/buildAndBroadcastReclaim-DPk36Uhp.cjs +0 -2
- package/dist/buildAndBroadcastReclaim-DPk36Uhp.cjs.map +0 -1
- package/dist/challengeAssert-B2otuf7y.js.map +0 -1
- package/dist/challengeAssert-C3eMcM5Y.cjs.map +0 -1
- package/dist/constants-CAm10Qwp.cjs +0 -2
- package/dist/constants-CAm10Qwp.cjs.map +0 -1
- package/dist/constants-CvQZuxKv.js +0 -48
- package/dist/constants-CvQZuxKv.js.map +0 -1
- package/dist/pegin-registration-client-CdRyXP3j.cjs +0 -2
- package/dist/pegin-registration-client-CdRyXP3j.cjs.map +0 -1
- package/dist/pegin-registration-client-Cvjk4ILq.js.map +0 -1
- package/dist/registration-records-DJJC2NiO.js.map +0 -1
- package/dist/registration-records-XQMIKjGV.cjs +0 -2
- package/dist/registration-records-XQMIKjGV.cjs.map +0 -1
- package/dist/toRefundInputs-DTuWi--u.cjs +0 -2
- package/dist/toRefundInputs-DTuWi--u.cjs.map +0 -1
- package/dist/toRefundInputs-Dzw1cteD.js.map +0 -1
- package/dist/types-24A9Qoxb.js.map +0 -1
- package/dist/types-BC2TGzcp.cjs.map +0 -1
- package/dist/verifyScriptPathSchnorrSignature-CahYx5Td.cjs +0 -2
- package/dist/verifyScriptPathSchnorrSignature-CahYx5Td.cjs.map +0 -1
- package/dist/verifyScriptPathSchnorrSignature-owu3BfyT.js.map +0 -1
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import { script as x, opcodes as
|
|
2
|
-
import { computeMinClaimValue as
|
|
3
|
-
import { c as q, p as
|
|
4
|
-
import { p as
|
|
5
|
-
import { b as
|
|
6
|
-
import { Buffer as
|
|
7
|
-
import { P as X,
|
|
8
|
-
import * as
|
|
9
|
-
import { X as
|
|
1
|
+
import { script as x, opcodes as w, payments as L, Transaction as k, crypto as U, Psbt as H } from "bitcoinjs-lib";
|
|
2
|
+
import { computeMinClaimValue as Se, peginP2aAnchorOutput as Te, computeMinPeginFee as Oe, tapInternalPubkey as I, buildPeginTxFromPrePegin as Ve, createPrePeginTransaction as Le, validatePeginP2aAnchor as Re, createPayoutConnector as Ke, computePayoutFeeFloor as He, getAssertPayoutScriptInfo as Ne } from "./tbv/core/wasm/index.js";
|
|
3
|
+
import { c as q, p as Ue, d as Be } from "./fundPeginTransaction-CwhRbCQC.js";
|
|
4
|
+
import { p as Me, s as f, d as xe, m as Ce, T as y, h as C, u as M, j as Fe, S as W } from "./bitcoin-C-TuHb-v.js";
|
|
5
|
+
import { b as qe } from "./secp256k1-BuxBFUHm.js";
|
|
6
|
+
import { Buffer as a } from "buffer";
|
|
7
|
+
import { P as X, l as G, m as z, n as Y, o as We, p as D, q as Q, r as Z, s as j, t as J, u as ee, v as te, w as oe, x as ne, y as re, M as ie, j as se, z as Xe, A as be, B as Ge, V as ze, E as ue } from "./constants-CmDDuM3L.js";
|
|
8
|
+
import * as ke from "@bitcoin-js/tiny-secp256k1-asmjs";
|
|
9
|
+
import { X as ce } from "./validation-OSC0xTHB.js";
|
|
10
10
|
function b(e) {
|
|
11
|
-
return
|
|
11
|
+
return Me(e).toLowerCase();
|
|
12
12
|
}
|
|
13
13
|
function Qt(e, t, o) {
|
|
14
14
|
const n = /* @__PURE__ */ new Set();
|
|
15
15
|
n.add(b(e));
|
|
16
|
-
for (const
|
|
17
|
-
n.add(b(
|
|
16
|
+
for (const r of t)
|
|
17
|
+
n.add(b(r));
|
|
18
18
|
return n.delete(b(o)), n.size;
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function Ye(e) {
|
|
21
21
|
const t = b(e.claimerBtcPubkey), o = b(e.depositorBtcPubkey), n = e.vaultKeeperBtcPubkeys.map(b);
|
|
22
22
|
if (t === o) {
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
23
|
+
const s = n.filter((u) => u !== o);
|
|
24
|
+
if (s.length === 0)
|
|
25
25
|
throw new Error(
|
|
26
26
|
"Cannot derive localChallengers: vault keeper set is empty (or contains only the depositor)"
|
|
27
27
|
);
|
|
28
|
-
if (new Set(
|
|
28
|
+
if (new Set(s).size !== s.length)
|
|
29
29
|
throw new Error(
|
|
30
30
|
"Cannot derive localChallengers: duplicate vaultKeeper key — signing context is misconfigured"
|
|
31
31
|
);
|
|
32
|
-
return
|
|
32
|
+
return s;
|
|
33
33
|
}
|
|
34
|
-
const
|
|
34
|
+
const i = [
|
|
35
35
|
.../* @__PURE__ */ new Set([b(e.vaultProviderBtcPubkey), ...n])
|
|
36
|
-
].sort().filter((
|
|
37
|
-
if (
|
|
36
|
+
].sort().filter((s) => s !== t);
|
|
37
|
+
if (i.length === 0)
|
|
38
38
|
throw new Error(
|
|
39
39
|
`Cannot derive localChallengers: no vault provider or vault keeper remains after excluding claimer ${t}`
|
|
40
40
|
);
|
|
41
|
-
return
|
|
41
|
+
return i;
|
|
42
42
|
}
|
|
43
|
-
const
|
|
44
|
-
function
|
|
43
|
+
const De = 32, Qe = 65535, Ze = 2;
|
|
44
|
+
function _(e, t) {
|
|
45
45
|
const o = f(e).toLowerCase();
|
|
46
46
|
if (!/^[0-9a-f]{64}$/.test(o))
|
|
47
47
|
throw new Error(`${t} must be a 32-byte x-only public key.`);
|
|
48
48
|
try {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
qe.Point.fromBytes(
|
|
50
|
+
a.concat([
|
|
51
|
+
a.from([Ze]),
|
|
52
|
+
a.from(o, "hex")
|
|
53
53
|
])
|
|
54
54
|
);
|
|
55
55
|
} catch {
|
|
@@ -60,122 +60,122 @@ function I(e, t) {
|
|
|
60
60
|
function R(e, t) {
|
|
61
61
|
if (e.length === 0)
|
|
62
62
|
throw new Error(`${t} must not be empty.`);
|
|
63
|
-
const o = e.map((n,
|
|
63
|
+
const o = e.map((n, r) => _(n, `${t}[${r}]`)).sort();
|
|
64
64
|
if (new Set(o).size !== o.length)
|
|
65
65
|
throw new Error(`${t} must not contain duplicate keys.`);
|
|
66
66
|
return o;
|
|
67
67
|
}
|
|
68
68
|
function K(e, t) {
|
|
69
69
|
const o = [];
|
|
70
|
-
return e.forEach((n,
|
|
70
|
+
return e.forEach((n, r) => {
|
|
71
71
|
o.push(
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
a.from(n, "hex"),
|
|
73
|
+
r === 0 ? w.OP_CHECKSIG : w.OP_CHECKSIGADD
|
|
74
74
|
);
|
|
75
75
|
}), o.push(
|
|
76
76
|
x.number.encode(e.length),
|
|
77
|
-
t ?
|
|
77
|
+
t ? w.OP_NUMEQUALVERIFY : w.OP_NUMEQUAL
|
|
78
78
|
), o;
|
|
79
79
|
}
|
|
80
|
-
function
|
|
80
|
+
function je(e, t) {
|
|
81
81
|
var g;
|
|
82
|
-
|
|
83
|
-
const o =
|
|
82
|
+
Ce();
|
|
83
|
+
const o = _(
|
|
84
84
|
e.depositorPubkey,
|
|
85
85
|
"depositorPubkey"
|
|
86
|
-
), n =
|
|
86
|
+
), n = _(
|
|
87
87
|
e.vaultProviderPubkey,
|
|
88
88
|
"vaultProviderPubkey"
|
|
89
|
-
),
|
|
89
|
+
), r = R(
|
|
90
90
|
e.vaultKeeperPubkeys,
|
|
91
91
|
"vaultKeeperPubkeys"
|
|
92
|
-
),
|
|
92
|
+
), i = R(
|
|
93
93
|
e.universalChallengerPubkeys,
|
|
94
94
|
"universalChallengerPubkeys"
|
|
95
|
-
),
|
|
96
|
-
if (!/^[0-9a-f]{64}$/.test(
|
|
95
|
+
), s = f(t).toLowerCase();
|
|
96
|
+
if (!/^[0-9a-f]{64}$/.test(s))
|
|
97
97
|
throw new Error("hashlock must be 32 bytes.");
|
|
98
|
-
if (!Number.isInteger(e.timelockRefund) || e.timelockRefund < 1 || e.timelockRefund >
|
|
98
|
+
if (!Number.isInteger(e.timelockRefund) || e.timelockRefund < 1 || e.timelockRefund > Qe)
|
|
99
99
|
throw new Error("timelockRefund must be an integer from 1 to 65535.");
|
|
100
100
|
const u = x.compile([
|
|
101
|
-
|
|
102
|
-
x.number.encode(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
...K(
|
|
112
|
-
...K(
|
|
113
|
-
]),
|
|
114
|
-
|
|
115
|
-
|
|
101
|
+
w.OP_SIZE,
|
|
102
|
+
x.number.encode(De),
|
|
103
|
+
w.OP_EQUALVERIFY,
|
|
104
|
+
w.OP_SHA256,
|
|
105
|
+
a.from(s, "hex"),
|
|
106
|
+
w.OP_EQUALVERIFY,
|
|
107
|
+
a.from(o, "hex"),
|
|
108
|
+
w.OP_CHECKSIGVERIFY,
|
|
109
|
+
a.from(n, "hex"),
|
|
110
|
+
w.OP_CHECKSIGVERIFY,
|
|
111
|
+
...K(r, !0),
|
|
112
|
+
...K(i, !1)
|
|
113
|
+
]), c = x.compile([
|
|
114
|
+
a.from(o, "hex"),
|
|
115
|
+
w.OP_CHECKSIGVERIFY,
|
|
116
116
|
x.number.encode(e.timelockRefund),
|
|
117
|
-
|
|
118
|
-
]),
|
|
117
|
+
w.OP_CHECKSEQUENCEVERIFY
|
|
118
|
+
]), p = [
|
|
119
119
|
{ output: u, version: y },
|
|
120
|
-
{ output:
|
|
121
|
-
], { hash:
|
|
122
|
-
internalPubkey:
|
|
123
|
-
scriptTree:
|
|
120
|
+
{ output: c, version: y }
|
|
121
|
+
], { hash: l, output: h, witness: d } = L.p2tr({
|
|
122
|
+
internalPubkey: a.from(I),
|
|
123
|
+
scriptTree: p,
|
|
124
124
|
redeem: {
|
|
125
125
|
output: u,
|
|
126
126
|
redeemVersion: y
|
|
127
127
|
}
|
|
128
|
-
}),
|
|
129
|
-
internalPubkey:
|
|
130
|
-
scriptTree:
|
|
128
|
+
}), P = d == null ? void 0 : d[d.length - 1], E = L.p2tr({
|
|
129
|
+
internalPubkey: a.from(I),
|
|
130
|
+
scriptTree: p,
|
|
131
131
|
redeem: {
|
|
132
|
-
output:
|
|
132
|
+
output: c,
|
|
133
133
|
redeemVersion: y
|
|
134
134
|
}
|
|
135
|
-
}),
|
|
136
|
-
if (!
|
|
135
|
+
}), v = (g = E.witness) == null ? void 0 : g[E.witness.length - 1];
|
|
136
|
+
if (!l || !h || !P || !v)
|
|
137
137
|
throw new Error("Failed to derive the expected Pre-PegIn HTLC output.");
|
|
138
138
|
return {
|
|
139
139
|
hashlockScript: u,
|
|
140
|
-
hashlockControlBlock:
|
|
141
|
-
refundScript:
|
|
142
|
-
refundControlBlock:
|
|
143
|
-
scriptPubKey:
|
|
144
|
-
tapMerkleRoot:
|
|
140
|
+
hashlockControlBlock: P,
|
|
141
|
+
refundScript: c,
|
|
142
|
+
refundControlBlock: v,
|
|
143
|
+
scriptPubKey: h,
|
|
144
|
+
tapMerkleRoot: l
|
|
145
145
|
};
|
|
146
146
|
}
|
|
147
|
-
function
|
|
148
|
-
|
|
149
|
-
const o =
|
|
147
|
+
function Je(e, t) {
|
|
148
|
+
Ce();
|
|
149
|
+
const o = _(
|
|
150
150
|
e.depositorPubkey,
|
|
151
151
|
"depositorPubkey"
|
|
152
|
-
), n =
|
|
152
|
+
), n = _(
|
|
153
153
|
e.vaultProviderPubkey,
|
|
154
154
|
"vaultProviderPubkey"
|
|
155
|
-
),
|
|
155
|
+
), r = R(
|
|
156
156
|
e.vaultKeeperPubkeys,
|
|
157
157
|
"vaultKeeperPubkeys"
|
|
158
|
-
),
|
|
158
|
+
), i = R(
|
|
159
159
|
e.universalChallengerPubkeys,
|
|
160
160
|
"universalChallengerPubkeys"
|
|
161
|
-
),
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
161
|
+
), s = x.compile([
|
|
162
|
+
a.from(o, "hex"),
|
|
163
|
+
w.OP_CHECKSIGVERIFY,
|
|
164
|
+
a.from(n, "hex"),
|
|
165
|
+
w.OP_CHECKSIGVERIFY,
|
|
166
|
+
...K(r, !0),
|
|
166
167
|
...K(i, !0),
|
|
167
|
-
...K(s, !0),
|
|
168
168
|
x.number.encode(t),
|
|
169
|
-
|
|
169
|
+
w.OP_CHECKSEQUENCEVERIFY
|
|
170
170
|
]), { output: u } = L.p2tr({
|
|
171
|
-
internalPubkey:
|
|
172
|
-
scriptTree: { output:
|
|
171
|
+
internalPubkey: a.from(I),
|
|
172
|
+
scriptTree: { output: s, version: y }
|
|
173
173
|
});
|
|
174
174
|
if (!u)
|
|
175
175
|
throw new Error("Failed to derive the expected PegIn payout output.");
|
|
176
176
|
return u;
|
|
177
177
|
}
|
|
178
|
-
async function
|
|
178
|
+
async function et(e, t) {
|
|
179
179
|
const o = t.pegInAmounts.length;
|
|
180
180
|
if (t.hashlocks.length !== o)
|
|
181
181
|
throw new Error(
|
|
@@ -193,7 +193,7 @@ async function Je(e, t) {
|
|
|
193
193
|
throw new Error(
|
|
194
194
|
`WASM Pre-PegIn returned non-positive depositorClaimValue ${e.depositorClaimValue}; expected > 0.`
|
|
195
195
|
);
|
|
196
|
-
const n = await
|
|
196
|
+
const n = await Se(
|
|
197
197
|
// Must price the same graph version the builder constructed.
|
|
198
198
|
t.vaultCoreVersion,
|
|
199
199
|
t.numLocalChallengers,
|
|
@@ -206,154 +206,156 @@ async function Je(e, t) {
|
|
|
206
206
|
throw new Error(
|
|
207
207
|
`WASM Pre-PegIn depositorClaimValue ${e.depositorClaimValue} does not match the independently computed minimum claim value ${n} (vaultCoreVersion=${t.vaultCoreVersion}, numLocalChallengers=${t.numLocalChallengers}, numUniversalChallengers=${t.universalChallengerPubkeys.length}, councilQuorum=${t.councilQuorum}, councilSize=${t.councilSize}, feeRate=${t.feeRate}).`
|
|
208
208
|
);
|
|
209
|
-
const
|
|
209
|
+
const { value: r } = await Te(
|
|
210
|
+
t.vaultCoreVersion
|
|
211
|
+
), i = await Oe(
|
|
210
212
|
t.vaultCoreVersion,
|
|
211
213
|
t.vaultKeeperPubkeys.length,
|
|
212
214
|
t.universalChallengerPubkeys.length,
|
|
213
215
|
t.minPeginFeeRate
|
|
214
|
-
),
|
|
215
|
-
for (let
|
|
216
|
-
const
|
|
217
|
-
if (
|
|
216
|
+
), s = i + r, u = t.minPeginFeeRate * q;
|
|
217
|
+
for (let c = 0; c < o; c++) {
|
|
218
|
+
const p = t.pegInAmounts[c], l = e.peginAmounts[c], h = e.htlcValues[c];
|
|
219
|
+
if (l !== p)
|
|
218
220
|
throw new Error(
|
|
219
|
-
`WASM Pre-PegIn peginAmount[${
|
|
221
|
+
`WASM Pre-PegIn peginAmount[${c}] ${l} does not match the requested amount ${p}; refusing to build a tx whose recorded amount differs from the depositor's request.`
|
|
220
222
|
);
|
|
221
|
-
if (
|
|
223
|
+
if (l <= 0n)
|
|
222
224
|
throw new Error(
|
|
223
|
-
`WASM Pre-PegIn peginAmount[${
|
|
225
|
+
`WASM Pre-PegIn peginAmount[${c}] is non-positive (${l}); expected > 0.`
|
|
224
226
|
);
|
|
225
|
-
if (
|
|
227
|
+
if (h <= 0n)
|
|
226
228
|
throw new Error(
|
|
227
|
-
`WASM Pre-PegIn htlcValue[${
|
|
229
|
+
`WASM Pre-PegIn htlcValue[${c}] is non-positive (${h}); expected > 0.`
|
|
228
230
|
);
|
|
229
|
-
const
|
|
230
|
-
if (
|
|
231
|
+
const d = h - l - e.depositorClaimValue;
|
|
232
|
+
if (d <= 0n)
|
|
231
233
|
throw new Error(
|
|
232
|
-
`WASM Pre-PegIn htlcValue[${
|
|
234
|
+
`WASM Pre-PegIn htlcValue[${c}] ${h} does not strictly cover peginAmount ${l} + depositorClaimValue ${e.depositorClaimValue} + a PegIn reserve (implied reserve ${d}).`
|
|
233
235
|
);
|
|
234
|
-
if (
|
|
236
|
+
if (d > u)
|
|
235
237
|
throw new Error(
|
|
236
|
-
`WASM Pre-PegIn implied reserve for HTLC[${
|
|
238
|
+
`WASM Pre-PegIn implied reserve for HTLC[${c}] (${d} sat) exceeds the plausibility cap ${u} sat (minPeginFeeRate=${t.minPeginFeeRate} × ${q} vbytes); htlcValue ${h} appears grossly inflated.`
|
|
237
239
|
);
|
|
238
|
-
if (
|
|
240
|
+
if (d !== s)
|
|
239
241
|
throw new Error(
|
|
240
|
-
`WASM Pre-PegIn htlcValue[${
|
|
242
|
+
`WASM Pre-PegIn htlcValue[${c}] ${h} implies a PegIn fee+anchor reserve of ${d} sat, expected exactly ${s} sat (minPeginFee ${i} + p2aAnchor ${r} for vaultCoreVersion ${t.vaultCoreVersion}, vaultKeepers=${t.vaultKeeperPubkeys.length}, universalChallengers=${t.universalChallengerPubkeys.length}, minPeginFeeRate=${t.minPeginFeeRate}).`
|
|
241
243
|
);
|
|
242
244
|
}
|
|
243
|
-
return
|
|
245
|
+
return i;
|
|
244
246
|
}
|
|
245
247
|
class V extends Error {
|
|
246
248
|
constructor(t) {
|
|
247
249
|
super(t), this.name = "HtlcOutputMismatchError";
|
|
248
250
|
}
|
|
249
251
|
}
|
|
250
|
-
function
|
|
252
|
+
function tt(e, t, o) {
|
|
251
253
|
if (e.length < t.length)
|
|
252
254
|
throw new V(
|
|
253
255
|
`Encoded Pre-PegIn tx has ${e.length} output(s), fewer than the ${t.length} HTLC output(s) the cross-check validated.`
|
|
254
256
|
);
|
|
255
257
|
for (let n = 0; n < t.length; n++) {
|
|
256
|
-
const
|
|
257
|
-
if (
|
|
258
|
+
const r = BigInt(e[n].value);
|
|
259
|
+
if (r !== t[n])
|
|
258
260
|
throw new V(
|
|
259
|
-
`Encoded Pre-PegIn HTLC output[${n}] value ${
|
|
261
|
+
`Encoded Pre-PegIn HTLC output[${n}] value ${r} does not match the cross-checked htlcValue ${t[n]}; the funded/signed tx would not pay the validated amount.`
|
|
260
262
|
);
|
|
261
|
-
const
|
|
262
|
-
if (
|
|
263
|
+
const i = e[n].script.toString("hex").toLowerCase(), s = o[n].toLowerCase();
|
|
264
|
+
if (i !== s)
|
|
263
265
|
throw new V(
|
|
264
|
-
`Encoded Pre-PegIn HTLC output[${n}] scriptPubKey ${
|
|
266
|
+
`Encoded Pre-PegIn HTLC output[${n}] scriptPubKey ${i} does not match the cross-checked htlcScriptPubKey ${s}.`
|
|
265
267
|
);
|
|
266
268
|
}
|
|
267
269
|
}
|
|
268
|
-
function
|
|
269
|
-
if (
|
|
270
|
+
function ot(e, t, o, n, r, i, s) {
|
|
271
|
+
if (i !== X)
|
|
270
272
|
throw new Error(
|
|
271
|
-
`WASM Pre-PegIn transaction version ${
|
|
273
|
+
`WASM Pre-PegIn transaction version ${i}; expected ${X}.`
|
|
272
274
|
);
|
|
273
|
-
if (
|
|
275
|
+
if (s !== G)
|
|
274
276
|
throw new Error(
|
|
275
|
-
`WASM Pre-PegIn transaction locktime ${
|
|
277
|
+
`WASM Pre-PegIn transaction locktime ${s}; expected ${G}.`
|
|
276
278
|
);
|
|
277
279
|
if (t.length < z)
|
|
278
280
|
throw new Error(
|
|
279
281
|
`WASM Pre-PegIn output layout has ${t.length} HTLC output(s); expected at least ${z}.`
|
|
280
282
|
);
|
|
281
|
-
const u = t.length,
|
|
283
|
+
const u = t.length, c = u + +(r !== void 0), p = Ue(
|
|
282
284
|
t.length,
|
|
283
|
-
|
|
285
|
+
r !== void 0
|
|
284
286
|
);
|
|
285
|
-
if (e.length !==
|
|
287
|
+
if (e.length !== p)
|
|
286
288
|
throw new Error(
|
|
287
|
-
`WASM Pre-PegIn output layout has ${e.length} output(s); expected exactly ${
|
|
289
|
+
`WASM Pre-PegIn output layout has ${e.length} output(s); expected exactly ${p}.`
|
|
288
290
|
);
|
|
289
|
-
|
|
290
|
-
for (let
|
|
291
|
-
const
|
|
291
|
+
tt(e, t, o);
|
|
292
|
+
for (let P = 0; P < t.length; P++) {
|
|
293
|
+
const E = je(
|
|
292
294
|
n,
|
|
293
|
-
n.hashlocks[
|
|
295
|
+
n.hashlocks[P]
|
|
294
296
|
).scriptPubKey;
|
|
295
|
-
if (!e[
|
|
297
|
+
if (!e[P].script.equals(E))
|
|
296
298
|
throw new V(
|
|
297
|
-
`Pre-PegIn HTLC output[${
|
|
299
|
+
`Pre-PegIn HTLC output[${P}] does not match the independently derived scriptPubKey.`
|
|
298
300
|
);
|
|
299
301
|
}
|
|
300
|
-
if (
|
|
301
|
-
const
|
|
302
|
-
if (
|
|
302
|
+
if (r !== void 0) {
|
|
303
|
+
const P = e[u];
|
|
304
|
+
if (P.value !== Y)
|
|
303
305
|
throw new Error(
|
|
304
|
-
`WASM Pre-PegIn auth output[${u}] value ${
|
|
306
|
+
`WASM Pre-PegIn auth output[${u}] value ${P.value} sat; expected exactly ${Y} sat.`
|
|
305
307
|
);
|
|
306
|
-
const
|
|
307
|
-
if (
|
|
308
|
+
const E = P.script.toString("hex").toLowerCase(), v = We + r.toLowerCase();
|
|
309
|
+
if (E !== v)
|
|
308
310
|
throw new Error(
|
|
309
|
-
`WASM Pre-PegIn auth output[${u}] scriptPubKey ${
|
|
311
|
+
`WASM Pre-PegIn auth output[${u}] scriptPubKey ${E}; expected ${v}.`
|
|
310
312
|
);
|
|
311
313
|
}
|
|
312
|
-
const
|
|
313
|
-
if (
|
|
314
|
+
const l = e[c];
|
|
315
|
+
if (l.value !== D)
|
|
314
316
|
throw new Error(
|
|
315
|
-
`WASM Pre-PegIn CPFP output[${
|
|
317
|
+
`WASM Pre-PegIn CPFP output[${c}] value ${l.value} sat; expected exactly ${D} sat.`
|
|
316
318
|
);
|
|
317
|
-
const
|
|
318
|
-
|
|
319
|
+
const h = l.script.toString("hex").toLowerCase(), d = f(
|
|
320
|
+
xe(n.depositorPubkey)
|
|
319
321
|
).toLowerCase();
|
|
320
|
-
if (
|
|
322
|
+
if (h !== d)
|
|
321
323
|
throw new Error(
|
|
322
|
-
`WASM Pre-PegIn CPFP output[${
|
|
324
|
+
`WASM Pre-PegIn CPFP output[${c}] scriptPubKey ${h}; expected depositor BIP-86 script ${d}.`
|
|
323
325
|
);
|
|
324
326
|
}
|
|
325
|
-
const
|
|
326
|
-
function
|
|
327
|
+
const nt = 1;
|
|
328
|
+
function rt(e) {
|
|
327
329
|
const t = f(e);
|
|
328
330
|
if (!/^[0-9a-fA-F]{64}$/.test(t))
|
|
329
331
|
throw new Error(
|
|
330
332
|
"Invalid depositor pubkey for the depositor-claim script: must be an x-only key of 64 hex characters (32 bytes)."
|
|
331
333
|
);
|
|
332
334
|
const o = x.compile([
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
]), n =
|
|
335
|
+
a.from(C(t)),
|
|
336
|
+
w.OP_CHECKSIG
|
|
337
|
+
]), n = a.from(I), r = { output: o, redeemVersion: y }, { output: i, witness: s } = L.p2tr({
|
|
336
338
|
internalPubkey: n,
|
|
337
339
|
scriptTree: { output: o },
|
|
338
|
-
redeem:
|
|
340
|
+
redeem: r
|
|
339
341
|
});
|
|
340
|
-
if (!
|
|
342
|
+
if (!i)
|
|
341
343
|
throw new Error(
|
|
342
344
|
"Failed to derive the depositor-claim P2TR scriptPubKey for PegIn output validation"
|
|
343
345
|
);
|
|
344
|
-
const u =
|
|
346
|
+
const u = s == null ? void 0 : s[s.length - 1];
|
|
345
347
|
if (!u)
|
|
346
348
|
throw new Error(
|
|
347
349
|
"Failed to derive the depositor-claim tapleaf control block; refusing to build an unspendable input"
|
|
348
350
|
);
|
|
349
|
-
return { scriptPubKey:
|
|
351
|
+
return { scriptPubKey: i, leafScript: o, controlBlock: u, internalKey: n };
|
|
350
352
|
}
|
|
351
|
-
function
|
|
352
|
-
return
|
|
353
|
+
function it(e) {
|
|
354
|
+
return rt(e).scriptPubKey;
|
|
353
355
|
}
|
|
354
|
-
const
|
|
356
|
+
const ae = 64, st = /^[0-9a-fA-F]+$/, le = 65535;
|
|
355
357
|
async function Zt(e) {
|
|
356
|
-
const t =
|
|
358
|
+
const t = Ie(e.authAnchorHash), o = await Le({
|
|
357
359
|
txGraphVersion: e.vaultCoreVersion,
|
|
358
360
|
depositorPubkey: e.depositorPubkey,
|
|
359
361
|
vaultProviderPubkey: e.vaultProviderPubkey,
|
|
@@ -369,47 +371,47 @@ async function Zt(e) {
|
|
|
369
371
|
councilSize: e.councilSize,
|
|
370
372
|
network: e.network,
|
|
371
373
|
authAnchorHash: t
|
|
372
|
-
}), n = await
|
|
373
|
-
|
|
374
|
-
|
|
374
|
+
}), n = await et(o, e), r = Be(o.txHex);
|
|
375
|
+
ot(
|
|
376
|
+
r.outputs,
|
|
375
377
|
o.htlcValues,
|
|
376
378
|
o.htlcScriptPubKeys,
|
|
377
379
|
e,
|
|
378
380
|
t,
|
|
379
|
-
|
|
380
|
-
|
|
381
|
+
r.version,
|
|
382
|
+
r.locktime
|
|
381
383
|
);
|
|
382
|
-
const
|
|
383
|
-
(u,
|
|
384
|
+
const i = r.outputs.reduce(
|
|
385
|
+
(u, c) => u + BigInt(c.value),
|
|
384
386
|
0n
|
|
385
|
-
),
|
|
387
|
+
), s = t !== void 0 ? o.htlcValues.length : null;
|
|
386
388
|
return {
|
|
387
389
|
psbtHex: o.txHex,
|
|
388
|
-
totalOutputValue:
|
|
390
|
+
totalOutputValue: i,
|
|
389
391
|
htlcValues: o.htlcValues,
|
|
390
392
|
htlcScriptPubKeys: o.htlcScriptPubKeys,
|
|
391
393
|
htlcAddresses: o.htlcAddresses,
|
|
392
394
|
peginAmounts: o.peginAmounts,
|
|
393
395
|
depositorClaimValue: o.depositorClaimValue,
|
|
394
|
-
authAnchorVout:
|
|
396
|
+
authAnchorVout: s,
|
|
395
397
|
minPeginFee: n
|
|
396
398
|
};
|
|
397
399
|
}
|
|
398
|
-
function
|
|
400
|
+
function Ie(e) {
|
|
399
401
|
if (e === void 0) return;
|
|
400
402
|
const t = e.startsWith("0x") || e.startsWith("0X") ? e.slice(2) : e;
|
|
401
|
-
if (t.length !==
|
|
403
|
+
if (t.length !== ae || !st.test(t))
|
|
402
404
|
throw new Error(
|
|
403
|
-
`authAnchorHash must be 32-byte hex (${
|
|
405
|
+
`authAnchorHash must be 32-byte hex (${ae} chars, no 0x prefix); got length ${t.length}`
|
|
404
406
|
);
|
|
405
407
|
return t.toLowerCase();
|
|
406
408
|
}
|
|
407
409
|
async function jt(e) {
|
|
408
|
-
if (!Number.isInteger(e.timelockPegin) || e.timelockPegin < 1 || e.timelockPegin >
|
|
410
|
+
if (!Number.isInteger(e.timelockPegin) || e.timelockPegin < 1 || e.timelockPegin > le)
|
|
409
411
|
throw new Error(
|
|
410
|
-
`PegIn timelock ${e.timelockPegin} must be a whole number of blocks from 1 to ${
|
|
412
|
+
`PegIn timelock ${e.timelockPegin} must be a whole number of blocks from 1 to ${le}.`
|
|
411
413
|
);
|
|
412
|
-
const t = await
|
|
414
|
+
const t = await Ve(
|
|
413
415
|
{
|
|
414
416
|
txGraphVersion: e.prePeginParams.vaultCoreVersion,
|
|
415
417
|
depositorPubkey: e.prePeginParams.depositorPubkey,
|
|
@@ -425,7 +427,7 @@ async function jt(e) {
|
|
|
425
427
|
councilQuorum: e.prePeginParams.councilQuorum,
|
|
426
428
|
councilSize: e.prePeginParams.councilSize,
|
|
427
429
|
network: e.prePeginParams.network,
|
|
428
|
-
authAnchorHash:
|
|
430
|
+
authAnchorHash: Ie(
|
|
429
431
|
e.prePeginParams.authAnchorHash
|
|
430
432
|
)
|
|
431
433
|
},
|
|
@@ -440,100 +442,101 @@ async function jt(e) {
|
|
|
440
442
|
vaultValue: t.vaultValue
|
|
441
443
|
};
|
|
442
444
|
}
|
|
443
|
-
const st = 2;
|
|
444
445
|
async function ut(e, t) {
|
|
445
|
-
const o = t.prePeginParams.vaultCoreVersion
|
|
446
|
-
if (
|
|
447
|
-
throw new Error(
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
446
|
+
const o = t.prePeginParams.vaultCoreVersion;
|
|
447
|
+
if (o !== Q)
|
|
448
|
+
throw new Error(
|
|
449
|
+
`Unsupported vaultCoreVersion ${o} for PegIn tx; only ${Q} has a PegIn shape.`
|
|
450
|
+
);
|
|
451
|
+
await Re(o, e.txHex);
|
|
452
|
+
const n = k.fromHex(f(e.txHex));
|
|
453
|
+
if (n.version !== Z)
|
|
451
454
|
throw new Error(
|
|
452
|
-
`PegIn tx version ${
|
|
455
|
+
`PegIn tx version ${n.version} does not match vaultCoreVersion ${o}; expected ${Z}.`
|
|
453
456
|
);
|
|
454
|
-
if (
|
|
457
|
+
if (n.locktime !== j)
|
|
455
458
|
throw new Error(
|
|
456
|
-
`PegIn tx locktime ${
|
|
459
|
+
`PegIn tx locktime ${n.locktime} does not match the canonical locktime ${j}.`
|
|
457
460
|
);
|
|
458
|
-
if (
|
|
461
|
+
if (n.ins.length !== 1)
|
|
459
462
|
throw new Error(
|
|
460
|
-
`PegIn tx has ${
|
|
463
|
+
`PegIn tx has ${n.ins.length} input(s), expected exactly 1 (the Pre-PegIn HTLC outpoint).`
|
|
461
464
|
);
|
|
462
|
-
const
|
|
465
|
+
const r = k.fromHex(
|
|
463
466
|
f(t.fundedPrePeginTxHex)
|
|
464
|
-
).getId(),
|
|
465
|
-
new Uint8Array(
|
|
467
|
+
).getId(), i = M(
|
|
468
|
+
new Uint8Array(n.ins[0].hash).slice().reverse()
|
|
466
469
|
);
|
|
467
|
-
if (
|
|
470
|
+
if (i !== r)
|
|
468
471
|
throw new Error(
|
|
469
|
-
`PegIn input spends txid ${
|
|
472
|
+
`PegIn input spends txid ${i}, expected the funded Pre-PegIn ${r}.`
|
|
470
473
|
);
|
|
471
|
-
if (
|
|
474
|
+
if (n.ins[0].index !== t.htlcVout)
|
|
472
475
|
throw new Error(
|
|
473
|
-
`PegIn input spends Pre-PegIn output ${
|
|
476
|
+
`PegIn input spends Pre-PegIn output ${n.ins[0].index}, expected the requested HTLC vout ${t.htlcVout}.`
|
|
474
477
|
);
|
|
475
|
-
if (
|
|
478
|
+
if (n.ins[0].sequence !== J)
|
|
476
479
|
throw new Error(
|
|
477
|
-
`PegIn input sequence ${
|
|
480
|
+
`PegIn input sequence ${n.ins[0].sequence} does not match the canonical sequence ${J}.`
|
|
478
481
|
);
|
|
479
|
-
if (
|
|
482
|
+
if (n.ins[0].script.length !== 0)
|
|
480
483
|
throw new Error("PegIn input scriptSig must be empty.");
|
|
481
|
-
if (
|
|
484
|
+
if (n.ins[0].witness.length !== 0)
|
|
482
485
|
throw new Error("PegIn input witness must be empty before signing.");
|
|
483
|
-
if (
|
|
486
|
+
if (n.outs.length !== ee)
|
|
484
487
|
throw new Error(
|
|
485
|
-
`PegIn tx has ${
|
|
488
|
+
`PegIn tx has ${n.outs.length} output(s), expected exactly ${ee} for vaultCoreVersion ${o} (vault + depositor claim + P2A anchor).`
|
|
486
489
|
);
|
|
487
|
-
const
|
|
488
|
-
if (e.vaultValue !==
|
|
490
|
+
const s = t.prePeginParams.pegInAmounts[t.htlcVout];
|
|
491
|
+
if (e.vaultValue !== s)
|
|
489
492
|
throw new Error(
|
|
490
|
-
`PegIn vault output value ${e.vaultValue} does not match the requested peg-in amount ${
|
|
493
|
+
`PegIn vault output value ${e.vaultValue} does not match the requested peg-in amount ${s} for HTLC ${t.htlcVout}; refusing to sign a vault that locks a different amount than requested.`
|
|
491
494
|
);
|
|
492
|
-
const
|
|
493
|
-
if (BigInt(
|
|
495
|
+
const u = n.outs[0];
|
|
496
|
+
if (BigInt(u.value) !== e.vaultValue)
|
|
494
497
|
throw new Error(
|
|
495
|
-
`Encoded PegIn vault output value ${
|
|
498
|
+
`Encoded PegIn vault output value ${u.value} does not match the WASM-reported vaultValue ${e.vaultValue}.`
|
|
496
499
|
);
|
|
497
|
-
const
|
|
500
|
+
const c = Je(
|
|
498
501
|
t.prePeginParams,
|
|
499
502
|
t.timelockPegin
|
|
500
503
|
).toString("hex");
|
|
501
|
-
if (f(e.vaultScriptPubKey).toLowerCase() !==
|
|
504
|
+
if (f(e.vaultScriptPubKey).toLowerCase() !== c)
|
|
502
505
|
throw new Error(
|
|
503
|
-
`WASM-reported PegIn vaultScriptPubKey ${e.vaultScriptPubKey} does not match the independently derived payout scriptPubKey ${
|
|
506
|
+
`WASM-reported PegIn vaultScriptPubKey ${e.vaultScriptPubKey} does not match the independently derived payout scriptPubKey ${c}.`
|
|
504
507
|
);
|
|
505
|
-
const
|
|
506
|
-
if (
|
|
508
|
+
const p = u.script.toString("hex");
|
|
509
|
+
if (p !== c)
|
|
507
510
|
throw new Error(
|
|
508
|
-
`Encoded PegIn vault output scriptPubKey ${
|
|
511
|
+
`Encoded PegIn vault output scriptPubKey ${p} does not match the independently derived payout scriptPubKey ${c}.`
|
|
509
512
|
);
|
|
510
|
-
const
|
|
511
|
-
if (
|
|
513
|
+
const l = n.getId();
|
|
514
|
+
if (l !== f(e.txid).toLowerCase())
|
|
512
515
|
throw new Error(
|
|
513
|
-
`Encoded PegIn txid ${
|
|
516
|
+
`Encoded PegIn txid ${l} does not match the WASM-reported txid ${e.txid}.`
|
|
514
517
|
);
|
|
515
|
-
const
|
|
518
|
+
const h = await Se(
|
|
516
519
|
o,
|
|
517
520
|
t.prePeginParams.numLocalChallengers,
|
|
518
521
|
t.prePeginParams.universalChallengerPubkeys.length,
|
|
519
522
|
t.prePeginParams.councilQuorum,
|
|
520
523
|
t.prePeginParams.councilSize,
|
|
521
524
|
t.prePeginParams.feeRate
|
|
522
|
-
),
|
|
523
|
-
if (BigInt(
|
|
525
|
+
), d = n.outs[nt];
|
|
526
|
+
if (BigInt(d.value) !== h)
|
|
524
527
|
throw new Error(
|
|
525
|
-
`Encoded PegIn depositor-claim output value ${
|
|
528
|
+
`Encoded PegIn depositor-claim output value ${d.value} does not match the independently computed claim value ${h} for vaultCoreVersion ${o}.`
|
|
526
529
|
);
|
|
527
|
-
const
|
|
530
|
+
const P = it(
|
|
528
531
|
t.prePeginParams.depositorPubkey
|
|
529
532
|
);
|
|
530
|
-
if (!
|
|
533
|
+
if (!d.script.equals(P))
|
|
531
534
|
throw new Error(
|
|
532
|
-
`Encoded PegIn depositor-claim output scriptPubKey ${
|
|
535
|
+
`Encoded PegIn depositor-claim output scriptPubKey ${d.script.toString("hex")} does not pay to the depositor's claim script (expected ${P.toString("hex")}).`
|
|
533
536
|
);
|
|
534
537
|
}
|
|
535
538
|
async function ct(e) {
|
|
536
|
-
const t = await
|
|
539
|
+
const t = await Ke(
|
|
537
540
|
{
|
|
538
541
|
txGraphVersion: e.vaultCoreVersion,
|
|
539
542
|
depositor: e.depositor,
|
|
@@ -552,77 +555,77 @@ async function ct(e) {
|
|
|
552
555
|
payoutControlBlock: t.payoutControlBlock
|
|
553
556
|
};
|
|
554
557
|
}
|
|
555
|
-
const
|
|
558
|
+
const he = 253, at = 254, lt = 65535, ht = 4294967295, dt = "TapLeaf", pt = "TapBranch", Pt = "TapTweak", T = 33, O = 32, de = 128, ft = 1, gt = 254, wt = a.from([81, 32]);
|
|
556
559
|
function vt(e) {
|
|
557
|
-
if (e <
|
|
558
|
-
return
|
|
560
|
+
if (e < he)
|
|
561
|
+
return a.from([e]);
|
|
559
562
|
if (e <= lt) {
|
|
560
|
-
const t =
|
|
561
|
-
return t.writeUInt16LE(e),
|
|
563
|
+
const t = a.alloc(2);
|
|
564
|
+
return t.writeUInt16LE(e), a.concat([a.from([he]), t]);
|
|
562
565
|
}
|
|
563
566
|
if (e <= ht) {
|
|
564
|
-
const t =
|
|
565
|
-
return t.writeUInt32LE(e),
|
|
567
|
+
const t = a.alloc(4);
|
|
568
|
+
return t.writeUInt32LE(e), a.concat([a.from([at]), t]);
|
|
566
569
|
}
|
|
567
570
|
throw new Error(`Script too large to encode as CompactSize: ${e} bytes`);
|
|
568
571
|
}
|
|
569
|
-
function
|
|
570
|
-
const o =
|
|
571
|
-
|
|
572
|
+
function _e(e, t) {
|
|
573
|
+
const o = a.concat([
|
|
574
|
+
a.from([e]),
|
|
572
575
|
vt(t.length),
|
|
573
|
-
|
|
576
|
+
a.from(t)
|
|
574
577
|
]);
|
|
575
578
|
return U.taggedHash(dt, o);
|
|
576
579
|
}
|
|
577
580
|
function Et(e) {
|
|
578
|
-
const { leafVersion: t, script: o, controlBlock: n } = e,
|
|
579
|
-
if (
|
|
581
|
+
const { leafVersion: t, script: o, controlBlock: n } = e, r = n.length - T;
|
|
582
|
+
if (r < 0 || r % O !== 0 || r / O > de)
|
|
580
583
|
throw new Error(
|
|
581
|
-
`Malformed Taproot control block: length ${n.length} must be ${T} + 32*m with 0 <= m <= ${
|
|
584
|
+
`Malformed Taproot control block: length ${n.length} must be ${T} + 32*m with 0 <= m <= ${de}`
|
|
582
585
|
);
|
|
583
|
-
const
|
|
584
|
-
if (
|
|
586
|
+
const i = n[0] & gt;
|
|
587
|
+
if (i !== t)
|
|
585
588
|
throw new Error(
|
|
586
|
-
`Taproot control block leaf version 0x${
|
|
589
|
+
`Taproot control block leaf version 0x${i.toString(16)} does not match the tapLeafScript leaf version 0x${t.toString(16)}`
|
|
587
590
|
);
|
|
588
|
-
const
|
|
591
|
+
const s = a.from(
|
|
589
592
|
n.subarray(1, T)
|
|
590
593
|
);
|
|
591
|
-
let u =
|
|
592
|
-
for (let
|
|
593
|
-
const
|
|
594
|
-
n.subarray(
|
|
594
|
+
let u = _e(t, o);
|
|
595
|
+
for (let h = T; h < n.length; h += O) {
|
|
596
|
+
const d = a.from(
|
|
597
|
+
n.subarray(h, h + O)
|
|
595
598
|
);
|
|
596
599
|
u = U.taggedHash(
|
|
597
600
|
pt,
|
|
598
|
-
|
|
601
|
+
a.compare(u, d) <= 0 ? a.concat([u, d]) : a.concat([d, u])
|
|
599
602
|
);
|
|
600
603
|
}
|
|
601
|
-
const
|
|
604
|
+
const c = U.taggedHash(
|
|
602
605
|
Pt,
|
|
603
|
-
|
|
604
|
-
),
|
|
605
|
-
if (
|
|
606
|
+
a.concat([s, u])
|
|
607
|
+
), p = ke.xOnlyPointAddTweak(s, c);
|
|
608
|
+
if (p === null)
|
|
606
609
|
throw new Error(
|
|
607
610
|
"Taproot control block does not yield a valid output key (tweak is off-curve)"
|
|
608
611
|
);
|
|
609
|
-
const
|
|
610
|
-
if (
|
|
612
|
+
const l = n[0] & ft;
|
|
613
|
+
if (p.parity !== l)
|
|
611
614
|
throw new Error(
|
|
612
|
-
`Taproot output key parity ${
|
|
615
|
+
`Taproot output key parity ${p.parity} contradicts the control block's parity bit ${l}`
|
|
613
616
|
);
|
|
614
|
-
return
|
|
617
|
+
return a.concat([
|
|
615
618
|
wt,
|
|
616
|
-
|
|
619
|
+
a.from(p.xOnlyPubkey)
|
|
617
620
|
]);
|
|
618
621
|
}
|
|
619
|
-
const yt = 256, mt = 1500,
|
|
622
|
+
const yt = 256, mt = 1500, pe = 256, Pe = 0xffffffffn, $t = 500, St = 55, xt = 34;
|
|
620
623
|
function Ct(e) {
|
|
621
|
-
if (typeof e.protocolFeeRate != "bigint" || e.protocolFeeRate <= 0n || e.protocolFeeRate >
|
|
624
|
+
if (typeof e.protocolFeeRate != "bigint" || e.protocolFeeRate <= 0n || e.protocolFeeRate > Pe)
|
|
622
625
|
throw new Error(
|
|
623
|
-
`protocolFeeRate must be in [1, ${
|
|
626
|
+
`protocolFeeRate must be in [1, ${Pe}] sat/vB, got ${e.protocolFeeRate}`
|
|
624
627
|
);
|
|
625
|
-
for (const [t, o, n,
|
|
628
|
+
for (const [t, o, n, r] of [
|
|
626
629
|
[
|
|
627
630
|
"keepers",
|
|
628
631
|
e.numVaultKeepers,
|
|
@@ -638,43 +641,43 @@ function Ct(e) {
|
|
|
638
641
|
])
|
|
639
642
|
if (!Number.isInteger(o) || o < 1 || o > n)
|
|
640
643
|
throw new Error(
|
|
641
|
-
`Participant count for ${t} (${o}) is outside the supported range [1, ${n}]${o > n ? ` (${
|
|
644
|
+
`Participant count for ${t} (${o}) is outside the supported range [1, ${n}]${o > n ? ` (${r})` : ""}.`
|
|
642
645
|
);
|
|
643
|
-
if (!Number.isInteger(e.councilSize) || e.councilSize < 1 || e.councilSize >
|
|
646
|
+
if (!Number.isInteger(e.councilSize) || e.councilSize < 1 || e.councilSize > pe)
|
|
644
647
|
throw new Error(
|
|
645
|
-
`councilSize must be an integer in [1, ${
|
|
648
|
+
`councilSize must be an integer in [1, ${pe}], got ${e.councilSize}`
|
|
646
649
|
);
|
|
647
650
|
}
|
|
648
651
|
async function bt(e, t) {
|
|
649
|
-
const { implicitFeeSats: o, out0Len: n, out1Len:
|
|
650
|
-
if (
|
|
652
|
+
const { implicitFeeSats: o, out0Len: n, out1Len: r } = t, i = e.numVaultKeepers + e.numUniversalChallengers, s = BigInt(o), u = Math.max(0, n - xt), c = $t + St * i + u, p = e.protocolFeeRate * BigInt(c);
|
|
653
|
+
if (s > p)
|
|
651
654
|
throw new Error(
|
|
652
|
-
`Payout implicit fee ${o} sats exceeds the safety cap of ${
|
|
655
|
+
`Payout implicit fee ${o} sats exceeds the safety cap of ${p} sats (${e.protocolFeeRate} sat/vB x ${c} vB for ${i} participants); refusing to sign payout.`
|
|
653
656
|
);
|
|
654
|
-
const
|
|
657
|
+
const l = await He(
|
|
655
658
|
e.vaultCoreVersion,
|
|
656
659
|
e.numVaultKeepers,
|
|
657
660
|
e.numUniversalChallengers,
|
|
658
661
|
e.numVaultKeepers,
|
|
659
662
|
e.councilSize,
|
|
660
663
|
n,
|
|
661
|
-
|
|
664
|
+
r,
|
|
662
665
|
e.protocolFeeRate
|
|
663
666
|
);
|
|
664
|
-
if (
|
|
667
|
+
if (s < l)
|
|
665
668
|
throw new Error(
|
|
666
|
-
`Payout implicit fee ${o} sats is below the floor of ${
|
|
669
|
+
`Payout implicit fee ${o} sats is below the floor of ${l} sats (the smallest fee any known vault-provider build produces for this shape); refusing to sign payout.`
|
|
667
670
|
);
|
|
668
671
|
}
|
|
669
|
-
const kt = 22,
|
|
672
|
+
const kt = 22, It = 34, _t = 34, At = 25, Tt = 23;
|
|
670
673
|
function Ot(e) {
|
|
671
674
|
return e.length === kt * 2 && e.startsWith("0014");
|
|
672
675
|
}
|
|
673
676
|
function Vt(e) {
|
|
674
|
-
return e.length ===
|
|
677
|
+
return e.length === It * 2 && e.startsWith("0020");
|
|
675
678
|
}
|
|
676
679
|
function Lt(e) {
|
|
677
|
-
return e.length ===
|
|
680
|
+
return e.length === _t * 2 && e.startsWith("5120");
|
|
678
681
|
}
|
|
679
682
|
function Rt(e) {
|
|
680
683
|
return e.length === At * 2 && e.startsWith("76a914") && e.endsWith("88ac");
|
|
@@ -682,7 +685,7 @@ function Rt(e) {
|
|
|
682
685
|
function Kt(e) {
|
|
683
686
|
return e.length === Tt * 2 && e.startsWith("a914") && e.endsWith("87");
|
|
684
687
|
}
|
|
685
|
-
function
|
|
688
|
+
function fe(e, t) {
|
|
686
689
|
const o = f(e).toLowerCase();
|
|
687
690
|
if (o.length === 0)
|
|
688
691
|
throw new Error(`${t} is empty`);
|
|
@@ -697,7 +700,7 @@ function de(e, t) {
|
|
|
697
700
|
`${t} is not a standard scriptPubKey (expected P2TR, P2WPKH, P2WSH, P2PKH, or P2SH; got ${o.length / 2} bytes: ${o})`
|
|
698
701
|
);
|
|
699
702
|
}
|
|
700
|
-
const
|
|
703
|
+
const ge = 3;
|
|
701
704
|
async function Jt(e) {
|
|
702
705
|
const t = {
|
|
703
706
|
vaultCoreVersion: e.vaultCoreVersion,
|
|
@@ -707,59 +710,59 @@ async function Jt(e) {
|
|
|
707
710
|
protocolFeeRate: e.protocolFeeRate
|
|
708
711
|
};
|
|
709
712
|
Ct(t);
|
|
710
|
-
const o = k.fromHex(f(e.payoutTxHex)), n = k.fromHex(f(e.peginTxHex)),
|
|
711
|
-
if (o.ins.length !==
|
|
713
|
+
const o = k.fromHex(f(e.payoutTxHex)), n = k.fromHex(f(e.peginTxHex)), r = k.fromHex(f(e.assertTxHex));
|
|
714
|
+
if (o.ins.length !== te)
|
|
712
715
|
throw new Error(
|
|
713
|
-
`Payout transaction must have exactly ${
|
|
716
|
+
`Payout transaction must have exactly ${te} inputs, got ${o.ins.length}`
|
|
714
717
|
);
|
|
715
|
-
if (o.version !==
|
|
718
|
+
if (o.version !== oe)
|
|
716
719
|
throw new Error(
|
|
717
|
-
`Payout transaction version ${o.version} must be ${
|
|
720
|
+
`Payout transaction version ${o.version} must be ${oe}; refusing to sign payout.`
|
|
718
721
|
);
|
|
719
|
-
if (o.locktime !==
|
|
722
|
+
if (o.locktime !== ne)
|
|
720
723
|
throw new Error(
|
|
721
|
-
`Payout transaction locktime ${o.locktime} must be ${
|
|
724
|
+
`Payout transaction locktime ${o.locktime} must be ${ne}; refusing to sign payout.`
|
|
722
725
|
);
|
|
723
|
-
const
|
|
726
|
+
const i = we(
|
|
724
727
|
o.ins[0],
|
|
725
728
|
0,
|
|
726
729
|
n,
|
|
727
730
|
"PegIn",
|
|
728
|
-
|
|
731
|
+
Xe
|
|
729
732
|
);
|
|
730
733
|
if (o.ins[0].sequence !== e.timelockPegin)
|
|
731
734
|
throw new Error(
|
|
732
735
|
`Payout input 0 sequence ${o.ins[0].sequence} must equal the PegIn CSV timelock ${e.timelockPegin}; refusing to sign payout.`
|
|
733
736
|
);
|
|
734
|
-
const
|
|
737
|
+
const s = we(
|
|
735
738
|
o.ins[1],
|
|
736
739
|
1,
|
|
737
|
-
|
|
740
|
+
r,
|
|
738
741
|
"Assert",
|
|
739
|
-
|
|
742
|
+
be
|
|
740
743
|
);
|
|
741
744
|
if (o.ins[1].sequence !== e.timelockAssert)
|
|
742
745
|
throw new Error(
|
|
743
746
|
`Payout input 1 sequence ${o.ins[1].sequence} must equal the Assert CSV timelock ${e.timelockAssert}; refusing to sign payout.`
|
|
744
747
|
);
|
|
745
|
-
const { out0Len: u, out1Len:
|
|
748
|
+
const { out0Len: u, out1Len: c } = Ut(
|
|
746
749
|
o,
|
|
747
|
-
|
|
750
|
+
i.value,
|
|
748
751
|
e
|
|
749
|
-
),
|
|
750
|
-
let
|
|
751
|
-
for (const
|
|
752
|
-
if (
|
|
752
|
+
), p = i.value + s.value;
|
|
753
|
+
let l = 0;
|
|
754
|
+
for (const E of o.outs) l += E.value;
|
|
755
|
+
if (l > p)
|
|
753
756
|
throw new Error(
|
|
754
|
-
`Payout outputs (${
|
|
757
|
+
`Payout outputs (${l} sats) exceed inputs (${p} sats); invalid transaction.`
|
|
755
758
|
);
|
|
756
|
-
const
|
|
759
|
+
const h = p - l;
|
|
757
760
|
await bt(t, {
|
|
758
|
-
implicitFeeSats:
|
|
761
|
+
implicitFeeSats: h,
|
|
759
762
|
out0Len: u,
|
|
760
|
-
out1Len:
|
|
763
|
+
out1Len: c
|
|
761
764
|
});
|
|
762
|
-
const
|
|
765
|
+
const d = await ct({
|
|
763
766
|
vaultCoreVersion: e.vaultCoreVersion,
|
|
764
767
|
depositor: e.depositorBtcPubkey,
|
|
765
768
|
vaultProvider: e.vaultProviderBtcPubkey,
|
|
@@ -767,22 +770,22 @@ async function Jt(e) {
|
|
|
767
770
|
universalChallengers: e.universalChallengerBtcPubkeys,
|
|
768
771
|
timelockPegin: e.timelockPegin,
|
|
769
772
|
network: e.network
|
|
770
|
-
}),
|
|
773
|
+
}), P = await Ht(e, s);
|
|
771
774
|
return {
|
|
772
775
|
psbtHex: Nt(
|
|
773
776
|
o,
|
|
777
|
+
i,
|
|
774
778
|
s,
|
|
775
|
-
|
|
776
|
-
P
|
|
777
|
-
p
|
|
779
|
+
d,
|
|
780
|
+
P
|
|
778
781
|
)
|
|
779
782
|
};
|
|
780
783
|
}
|
|
781
784
|
async function Ht(e, t) {
|
|
782
|
-
const { payoutScript: o, payoutControlBlock: n } = await
|
|
785
|
+
const { payoutScript: o, payoutControlBlock: n } = await Ne({
|
|
783
786
|
txGraphVersion: e.vaultCoreVersion,
|
|
784
787
|
claimer: f(e.claimerBtcPubkey).toLowerCase(),
|
|
785
|
-
localChallengers:
|
|
788
|
+
localChallengers: Ye({
|
|
786
789
|
claimerBtcPubkey: e.claimerBtcPubkey,
|
|
787
790
|
depositorBtcPubkey: e.depositorBtcPubkey,
|
|
788
791
|
vaultProviderBtcPubkey: e.vaultProviderBtcPubkey,
|
|
@@ -796,40 +799,40 @@ async function Ht(e, t) {
|
|
|
796
799
|
(u) => f(u).toLowerCase()
|
|
797
800
|
),
|
|
798
801
|
councilQuorum: e.councilQuorum
|
|
799
|
-
}),
|
|
802
|
+
}), r = C(o), i = C(n), s = Et({
|
|
800
803
|
leafVersion: y,
|
|
801
|
-
script:
|
|
802
|
-
controlBlock:
|
|
804
|
+
script: r,
|
|
805
|
+
controlBlock: i
|
|
803
806
|
});
|
|
804
|
-
if (!t.script.equals(
|
|
807
|
+
if (!t.script.equals(s))
|
|
805
808
|
throw new Error(
|
|
806
|
-
`Rebuilt Assert:0 payout leaf does not spend the Assert output being referenced: leaf binds to ${
|
|
809
|
+
`Rebuilt Assert:0 payout leaf does not spend the Assert output being referenced: leaf binds to ${s.toString("hex")}, Assert:${be} pays ${t.script.toString("hex")}; refusing to sign payout.`
|
|
807
810
|
);
|
|
808
|
-
return { script:
|
|
811
|
+
return { script: r, controlBlock: i };
|
|
809
812
|
}
|
|
810
|
-
function
|
|
811
|
-
const
|
|
813
|
+
function we(e, t, o, n, r) {
|
|
814
|
+
const i = M(
|
|
812
815
|
new Uint8Array(e.hash).slice().reverse()
|
|
813
|
-
),
|
|
814
|
-
if (
|
|
816
|
+
), s = o.getId();
|
|
817
|
+
if (i !== s || e.index !== r)
|
|
815
818
|
throw new Error(
|
|
816
|
-
`Input ${t} must spend ${n}:${
|
|
819
|
+
`Input ${t} must spend ${n}:${r}. Expected ${s}:${r}, got ${i}:${e.index}`
|
|
817
820
|
);
|
|
818
821
|
const u = o.outs[e.index];
|
|
819
822
|
if (!u)
|
|
820
823
|
throw new Error(
|
|
821
|
-
`Previous output not found for input ${t} (txid: ${
|
|
824
|
+
`Previous output not found for input ${t} (txid: ${i}, index: ${e.index})`
|
|
822
825
|
);
|
|
823
826
|
return u;
|
|
824
827
|
}
|
|
825
|
-
function Nt(e, t, o, n,
|
|
826
|
-
const
|
|
827
|
-
|
|
828
|
-
const [
|
|
829
|
-
|
|
830
|
-
hash:
|
|
831
|
-
index:
|
|
832
|
-
sequence:
|
|
828
|
+
function Nt(e, t, o, n, r) {
|
|
829
|
+
const i = new H();
|
|
830
|
+
i.setVersion(e.version), i.setLocktime(e.locktime);
|
|
831
|
+
const [s, u] = e.ins;
|
|
832
|
+
i.addInput({
|
|
833
|
+
hash: s.hash,
|
|
834
|
+
index: s.index,
|
|
835
|
+
sequence: s.sequence,
|
|
833
836
|
witnessUtxo: {
|
|
834
837
|
script: t.script,
|
|
835
838
|
value: t.value
|
|
@@ -837,15 +840,15 @@ function Nt(e, t, o, n, i) {
|
|
|
837
840
|
tapLeafScript: [
|
|
838
841
|
{
|
|
839
842
|
leafVersion: y,
|
|
840
|
-
script:
|
|
841
|
-
controlBlock:
|
|
843
|
+
script: a.from(C(n.payoutScript)),
|
|
844
|
+
controlBlock: a.from(
|
|
842
845
|
C(n.payoutControlBlock)
|
|
843
846
|
)
|
|
844
847
|
}
|
|
845
848
|
],
|
|
846
|
-
tapInternalKey:
|
|
849
|
+
tapInternalKey: a.from(I)
|
|
847
850
|
// sighashType omitted - defaults to SIGHASH_DEFAULT (0x00) for Taproot
|
|
848
|
-
}),
|
|
851
|
+
}), i.addInput({
|
|
849
852
|
hash: u.hash,
|
|
850
853
|
index: u.index,
|
|
851
854
|
sequence: u.sequence,
|
|
@@ -856,109 +859,109 @@ function Nt(e, t, o, n, i) {
|
|
|
856
859
|
tapLeafScript: [
|
|
857
860
|
{
|
|
858
861
|
leafVersion: y,
|
|
859
|
-
script:
|
|
860
|
-
controlBlock:
|
|
862
|
+
script: a.from(r.script),
|
|
863
|
+
controlBlock: a.from(r.controlBlock)
|
|
861
864
|
}
|
|
862
865
|
],
|
|
863
|
-
tapInternalKey:
|
|
866
|
+
tapInternalKey: a.from(I)
|
|
864
867
|
});
|
|
865
|
-
for (const
|
|
866
|
-
|
|
867
|
-
script:
|
|
868
|
-
value:
|
|
868
|
+
for (const c of e.outs)
|
|
869
|
+
i.addOutput({
|
|
870
|
+
script: c.script,
|
|
871
|
+
value: c.value
|
|
869
872
|
});
|
|
870
|
-
return
|
|
873
|
+
return i.toHex();
|
|
871
874
|
}
|
|
872
|
-
function
|
|
875
|
+
function ve(e, t) {
|
|
873
876
|
const o = f(e).toLowerCase(), n = f(
|
|
874
|
-
|
|
877
|
+
xe(t)
|
|
875
878
|
).toLowerCase();
|
|
876
879
|
return o === n ? [o] : [o, n];
|
|
877
880
|
}
|
|
878
|
-
function
|
|
879
|
-
return t.some((o) => e.equals(
|
|
881
|
+
function Ee(e, t) {
|
|
882
|
+
return t.some((o) => e.equals(a.from(o, "hex")));
|
|
880
883
|
}
|
|
881
884
|
function Ut(e, t, o) {
|
|
882
885
|
const {
|
|
883
886
|
claimerBtcPubkey: n,
|
|
884
|
-
vaultProviderBtcPubkey:
|
|
885
|
-
depositorBtcPubkey:
|
|
886
|
-
vaultKeeperBtcPubkeys:
|
|
887
|
+
vaultProviderBtcPubkey: r,
|
|
888
|
+
depositorBtcPubkey: i,
|
|
889
|
+
vaultKeeperBtcPubkeys: s,
|
|
887
890
|
registeredPayoutScriptPubKey: u,
|
|
888
|
-
commissionBps:
|
|
889
|
-
vkClaimerPayoutScriptPubKeys:
|
|
890
|
-
vpCommissionScriptPubKey:
|
|
891
|
+
commissionBps: c,
|
|
892
|
+
vkClaimerPayoutScriptPubKeys: p,
|
|
893
|
+
vpCommissionScriptPubKey: l
|
|
891
894
|
} = o;
|
|
892
|
-
if (!
|
|
895
|
+
if (!Fe(u))
|
|
893
896
|
throw new Error("Invalid registeredPayoutScriptPubKey: not valid hex");
|
|
894
|
-
const
|
|
897
|
+
const h = f(n).toLowerCase(), d = f(r).toLowerCase(), P = f(i).toLowerCase(), E = s.map(
|
|
895
898
|
(S) => f(S).toLowerCase()
|
|
896
899
|
);
|
|
897
|
-
let
|
|
898
|
-
if (
|
|
899
|
-
|
|
900
|
-
else if (
|
|
901
|
-
|
|
902
|
-
else if (
|
|
903
|
-
|
|
904
|
-
const S =
|
|
900
|
+
let v, g, m;
|
|
901
|
+
if (h === d)
|
|
902
|
+
v = "vp-claimer", g = ze, m = [f(u)];
|
|
903
|
+
else if (h === P)
|
|
904
|
+
v = "depositor-as-claimer", g = ue, m = [f(u)];
|
|
905
|
+
else if (E.includes(h)) {
|
|
906
|
+
v = "vk-claimer", g = ue;
|
|
907
|
+
const S = p[h];
|
|
905
908
|
if (S === void 0)
|
|
906
909
|
throw new Error(
|
|
907
|
-
`No registered payout script resolved for vault keeper claimer ${
|
|
910
|
+
`No registered payout script resolved for vault keeper claimer ${h}`
|
|
908
911
|
);
|
|
909
|
-
|
|
912
|
+
fe(
|
|
910
913
|
S,
|
|
911
|
-
`Vault keeper payout script for claimer ${
|
|
912
|
-
), m =
|
|
914
|
+
`Vault keeper payout script for claimer ${h}`
|
|
915
|
+
), m = ve(S, h);
|
|
913
916
|
} else
|
|
914
917
|
throw new Error(
|
|
915
|
-
`Unknown claimer pubkey ${
|
|
918
|
+
`Unknown claimer pubkey ${h}: not VP, depositor, or a registered vault keeper`
|
|
916
919
|
);
|
|
917
920
|
if (e.outs.length !== g)
|
|
918
921
|
throw new Error(
|
|
919
|
-
`Payout transaction has ${e.outs.length} output(s), expected exactly ${g} for role ${
|
|
922
|
+
`Payout transaction has ${e.outs.length} output(s), expected exactly ${g} for role ${v}.`
|
|
920
923
|
);
|
|
921
|
-
if (!
|
|
924
|
+
if (!Ee(e.outs[0].script, m))
|
|
922
925
|
throw new Error(
|
|
923
|
-
`Payout transaction output 0 does not pay the expected scriptPubKey for role ${
|
|
926
|
+
`Payout transaction output 0 does not pay the expected scriptPubKey for role ${v}. Accepted: ${m.join(" or ")}; got ${e.outs[0].script.toString("hex")}`
|
|
924
927
|
);
|
|
925
928
|
const N = g - 1;
|
|
926
|
-
if (e.outs[N].value !==
|
|
929
|
+
if (e.outs[N].value !== re)
|
|
927
930
|
throw new Error(
|
|
928
|
-
`Payout CPFP anchor (out ${N}) value ${e.outs[N].value} sats must equal ${
|
|
931
|
+
`Payout CPFP anchor (out ${N}) value ${e.outs[N].value} sats must equal ${re} sats`
|
|
929
932
|
);
|
|
930
|
-
if (
|
|
931
|
-
|
|
932
|
-
|
|
933
|
+
if (v === "vp-claimer") {
|
|
934
|
+
fe(
|
|
935
|
+
l,
|
|
933
936
|
"Vault provider commission payout script"
|
|
934
937
|
);
|
|
935
|
-
const S =
|
|
936
|
-
|
|
937
|
-
|
|
938
|
+
const S = ve(
|
|
939
|
+
l,
|
|
940
|
+
d
|
|
938
941
|
);
|
|
939
|
-
if (!
|
|
942
|
+
if (!Ee(e.outs[1].script, S))
|
|
940
943
|
throw new Error(
|
|
941
944
|
`Payout transaction output 1 does not pay the vault provider's commission scriptPubKey. Accepted: ${S.join(" or ")}; got ${e.outs[1].script.toString("hex")}`
|
|
942
945
|
);
|
|
943
|
-
if (!Number.isInteger(
|
|
946
|
+
if (!Number.isInteger(c) || c < 0 || c >= ie)
|
|
944
947
|
throw new Error(
|
|
945
|
-
`commissionBps must be an integer in [0, ${
|
|
948
|
+
`commissionBps must be an integer in [0, ${ie}), got ${c}`
|
|
946
949
|
);
|
|
947
950
|
const F = Math.floor(
|
|
948
|
-
t *
|
|
951
|
+
t * c / Ge
|
|
949
952
|
);
|
|
950
953
|
if (e.outs[1].value > F)
|
|
951
954
|
throw new Error(
|
|
952
|
-
`Payout VP commission (out 1) value ${e.outs[1].value} sats exceeds cap ${F} sats (${
|
|
955
|
+
`Payout VP commission (out 1) value ${e.outs[1].value} sats exceeds cap ${F} sats (${c} bps of peginValue=${t})`
|
|
953
956
|
);
|
|
954
957
|
}
|
|
955
958
|
const A = e.outs[0].script.length;
|
|
956
|
-
if (A === 0 || A >
|
|
959
|
+
if (A === 0 || A > se)
|
|
957
960
|
throw new Error(
|
|
958
|
-
`Payout receiver scriptPubKey length ${A} is outside the contract's registration cap [1, ${
|
|
961
|
+
`Payout receiver scriptPubKey length ${A} is outside the contract's registration cap [1, ${se}]; refusing to sign payout.`
|
|
959
962
|
);
|
|
960
|
-
const
|
|
961
|
-
return { out0Len: A, out1Len:
|
|
963
|
+
const Ae = v === "vp-claimer" ? e.outs[1].script.length : void 0;
|
|
964
|
+
return { out0Len: A, out1Len: Ae };
|
|
962
965
|
}
|
|
963
966
|
function eo(e, t, o = 0) {
|
|
964
967
|
const n = H.fromHex(e);
|
|
@@ -966,29 +969,29 @@ function eo(e, t, o = 0) {
|
|
|
966
969
|
throw new Error(
|
|
967
970
|
`Input index ${o} out of range (${n.data.inputs.length} inputs)`
|
|
968
971
|
);
|
|
969
|
-
const
|
|
970
|
-
if (
|
|
971
|
-
const
|
|
972
|
-
for (const
|
|
973
|
-
if (
|
|
974
|
-
return
|
|
972
|
+
const r = n.data.inputs[o];
|
|
973
|
+
if (r.tapScriptSig && r.tapScriptSig.length > 0) {
|
|
974
|
+
const i = C(t);
|
|
975
|
+
for (const s of r.tapScriptSig)
|
|
976
|
+
if (s.pubkey.equals(a.from(i)))
|
|
977
|
+
return ye(s.signature, o);
|
|
975
978
|
throw new Error(
|
|
976
979
|
`No signature found for depositor pubkey: ${t} at input ${o}`
|
|
977
980
|
);
|
|
978
981
|
}
|
|
979
|
-
if (
|
|
980
|
-
const
|
|
981
|
-
if (
|
|
982
|
+
if (r.finalScriptWitness && r.finalScriptWitness.length > 0) {
|
|
983
|
+
const i = Bt(r.finalScriptWitness);
|
|
984
|
+
if (i.length !== ge)
|
|
982
985
|
throw new Error(
|
|
983
|
-
`Unexpected finalized witness stack size at input ${o}: expected ${
|
|
986
|
+
`Unexpected finalized witness stack size at input ${o}: expected ${ge} items (signature, script, controlBlock), got ${i.length}`
|
|
984
987
|
);
|
|
985
|
-
return
|
|
988
|
+
return ye(i[0], o);
|
|
986
989
|
}
|
|
987
990
|
throw new Error(
|
|
988
991
|
`No tapScriptSig or finalScriptWitness found in signed PSBT at input ${o}`
|
|
989
992
|
);
|
|
990
993
|
}
|
|
991
|
-
function
|
|
994
|
+
function ye(e, t) {
|
|
992
995
|
if (e.length === 64)
|
|
993
996
|
return M(new Uint8Array(e));
|
|
994
997
|
throw e.length === 65 ? new Error(
|
|
@@ -1000,21 +1003,21 @@ function we(e, t) {
|
|
|
1000
1003
|
function Bt(e) {
|
|
1001
1004
|
const t = [];
|
|
1002
1005
|
let o = 0;
|
|
1003
|
-
const n = (
|
|
1004
|
-
if (o +
|
|
1006
|
+
const n = (s) => {
|
|
1007
|
+
if (o + s > e.length)
|
|
1005
1008
|
throw new Error(
|
|
1006
|
-
`Malformed witness data: need ${
|
|
1009
|
+
`Malformed witness data: need ${s} byte(s) at offset ${o}, only ${e.length - o} remaining`
|
|
1007
1010
|
);
|
|
1008
|
-
},
|
|
1011
|
+
}, r = () => {
|
|
1009
1012
|
n(1);
|
|
1010
|
-
const
|
|
1011
|
-
if (
|
|
1012
|
-
if (
|
|
1013
|
+
const s = e[o++];
|
|
1014
|
+
if (s < 253) return s;
|
|
1015
|
+
if (s === 253) {
|
|
1013
1016
|
n(2);
|
|
1014
1017
|
const u = (e[o] | e[o + 1] << 8) >>> 0;
|
|
1015
1018
|
return o += 2, u;
|
|
1016
1019
|
}
|
|
1017
|
-
if (
|
|
1020
|
+
if (s === 254) {
|
|
1018
1021
|
n(4);
|
|
1019
1022
|
const u = (e[o] | e[o + 1] << 8 | e[o + 2] << 16 | e[o + 3] << 24) >>> 0;
|
|
1020
1023
|
return o += 4, u;
|
|
@@ -1022,14 +1025,14 @@ function Bt(e) {
|
|
|
1022
1025
|
throw new Error(
|
|
1023
1026
|
`Malformed witness data: 8-byte varint (0xff) not supported at offset ${o - 1}`
|
|
1024
1027
|
);
|
|
1025
|
-
},
|
|
1026
|
-
for (let
|
|
1027
|
-
const u =
|
|
1028
|
-
n(u), t.push(
|
|
1028
|
+
}, i = r();
|
|
1029
|
+
for (let s = 0; s < i; s++) {
|
|
1030
|
+
const u = r();
|
|
1031
|
+
n(u), t.push(a.from(e.subarray(o, o + u))), o += u;
|
|
1029
1032
|
}
|
|
1030
1033
|
if (o !== e.length)
|
|
1031
1034
|
throw new Error(
|
|
1032
|
-
`Malformed witness data: ${e.length - o} trailing byte(s) after parsing ${
|
|
1035
|
+
`Malformed witness data: ${e.length - o} trailing byte(s) after parsing ${i} item(s)`
|
|
1033
1036
|
);
|
|
1034
1037
|
return t;
|
|
1035
1038
|
}
|
|
@@ -1040,7 +1043,7 @@ class $ extends Error {
|
|
|
1040
1043
|
), this.name = "PsbtSubstitutionError";
|
|
1041
1044
|
}
|
|
1042
1045
|
}
|
|
1043
|
-
function
|
|
1046
|
+
function me(e, t) {
|
|
1044
1047
|
try {
|
|
1045
1048
|
return H.fromHex(t);
|
|
1046
1049
|
} catch (o) {
|
|
@@ -1052,12 +1055,12 @@ const Mt = 8;
|
|
|
1052
1055
|
function B(e) {
|
|
1053
1056
|
return `${e.toString("hex").slice(0, Mt)}…`;
|
|
1054
1057
|
}
|
|
1055
|
-
function
|
|
1056
|
-
const t =
|
|
1058
|
+
function $e(e) {
|
|
1059
|
+
const t = a.from(e).reverse();
|
|
1057
1060
|
return B(t);
|
|
1058
1061
|
}
|
|
1059
1062
|
function to(e) {
|
|
1060
|
-
const t =
|
|
1063
|
+
const t = me("requested", e.requestedPsbtHex), o = me("returned", e.returnedPsbtHex);
|
|
1061
1064
|
if (t.version !== o.version)
|
|
1062
1065
|
throw new $(
|
|
1063
1066
|
`tx version differs (requested=${t.version}, returned=${o.version})`
|
|
@@ -1075,109 +1078,109 @@ function to(e) {
|
|
|
1075
1078
|
`output count differs (requested=${t.txOutputs.length}, returned=${o.txOutputs.length})`
|
|
1076
1079
|
);
|
|
1077
1080
|
for (let n = 0; n < t.txInputs.length; n++) {
|
|
1078
|
-
const
|
|
1079
|
-
if (!
|
|
1081
|
+
const r = t.txInputs[n], i = o.txInputs[n];
|
|
1082
|
+
if (!r.hash.equals(i.hash))
|
|
1080
1083
|
throw new $(
|
|
1081
|
-
`input ${n} prevout txid differs (requested=${
|
|
1084
|
+
`input ${n} prevout txid differs (requested=${$e(r.hash)}, returned=${$e(i.hash)})`
|
|
1082
1085
|
);
|
|
1083
|
-
if (
|
|
1086
|
+
if (r.index !== i.index)
|
|
1084
1087
|
throw new $(
|
|
1085
|
-
`input ${n} prevout vout differs (requested=${
|
|
1088
|
+
`input ${n} prevout vout differs (requested=${r.index}, returned=${i.index})`
|
|
1086
1089
|
);
|
|
1087
|
-
if (
|
|
1090
|
+
if (r.sequence !== i.sequence)
|
|
1088
1091
|
throw new $(
|
|
1089
|
-
`input ${n} sequence differs (requested=${
|
|
1092
|
+
`input ${n} sequence differs (requested=${r.sequence}, returned=${i.sequence})`
|
|
1090
1093
|
);
|
|
1091
1094
|
}
|
|
1092
1095
|
for (let n = 0; n < t.txOutputs.length; n++) {
|
|
1093
|
-
const
|
|
1094
|
-
if (!
|
|
1096
|
+
const r = t.txOutputs[n], i = o.txOutputs[n];
|
|
1097
|
+
if (!r.script.equals(i.script))
|
|
1095
1098
|
throw new $(
|
|
1096
|
-
`output ${n} scriptPubKey differs (requested=${B(
|
|
1099
|
+
`output ${n} scriptPubKey differs (requested=${B(r.script)}, returned=${B(i.script)})`
|
|
1097
1100
|
);
|
|
1098
|
-
if (
|
|
1101
|
+
if (r.value !== i.value)
|
|
1099
1102
|
throw new $(
|
|
1100
|
-
`output ${n} value differs (requested=${
|
|
1103
|
+
`output ${n} value differs (requested=${r.value}, returned=${i.value})`
|
|
1101
1104
|
);
|
|
1102
1105
|
}
|
|
1103
1106
|
}
|
|
1104
1107
|
function oo(e) {
|
|
1105
|
-
const { requestedPsbtHex: t, signatureHex: o, signerXOnlyPubkeyHex: n, inputIndex:
|
|
1106
|
-
if (
|
|
1108
|
+
const { requestedPsbtHex: t, signatureHex: o, signerXOnlyPubkeyHex: n, inputIndex: r } = e, i = f(o);
|
|
1109
|
+
if (i.length !== W)
|
|
1107
1110
|
throw new Error(
|
|
1108
|
-
`Schnorr signature for input ${
|
|
1111
|
+
`Schnorr signature for input ${r} must be ${W} hex chars (64 bytes), got ${i.length}.`
|
|
1109
1112
|
);
|
|
1110
|
-
const
|
|
1111
|
-
if (
|
|
1113
|
+
const s = f(n);
|
|
1114
|
+
if (s.length !== ce)
|
|
1112
1115
|
throw new Error(
|
|
1113
|
-
`Signer x-only pubkey for input ${
|
|
1116
|
+
`Signer x-only pubkey for input ${r} must be ${ce} hex chars (32 bytes), got ${s.length}.`
|
|
1114
1117
|
);
|
|
1115
1118
|
const u = H.fromHex(t);
|
|
1116
|
-
if (
|
|
1119
|
+
if (r < 0 || r >= u.data.inputs.length)
|
|
1117
1120
|
throw new Error(
|
|
1118
|
-
`Input index ${
|
|
1121
|
+
`Input index ${r} out of range (${u.data.inputs.length} inputs).`
|
|
1119
1122
|
);
|
|
1120
|
-
const
|
|
1123
|
+
const c = [], p = [];
|
|
1121
1124
|
for (let g = 0; g < u.data.inputs.length; g++) {
|
|
1122
1125
|
const m = u.data.inputs[g].witnessUtxo;
|
|
1123
1126
|
if (!m)
|
|
1124
1127
|
throw new Error(
|
|
1125
1128
|
`Cannot verify signature: input ${g} of the requested PSBT has no witnessUtxo (required to recompute the Taproot sighash).`
|
|
1126
1129
|
);
|
|
1127
|
-
|
|
1130
|
+
c.push(m.script), p.push(m.value);
|
|
1128
1131
|
}
|
|
1129
|
-
const
|
|
1130
|
-
if (!
|
|
1132
|
+
const l = u.data.inputs[r].tapLeafScript;
|
|
1133
|
+
if (!l || l.length !== 1)
|
|
1131
1134
|
throw new Error(
|
|
1132
|
-
`Cannot verify signature: input ${
|
|
1135
|
+
`Cannot verify signature: input ${r} of the requested PSBT must have exactly one tapLeafScript, got ${(l == null ? void 0 : l.length) ?? 0}.`
|
|
1133
1136
|
);
|
|
1134
|
-
const
|
|
1135
|
-
if (
|
|
1137
|
+
const h = l[0];
|
|
1138
|
+
if (h.leafVersion !== y)
|
|
1136
1139
|
throw new Error(
|
|
1137
|
-
`Cannot verify signature: input ${
|
|
1140
|
+
`Cannot verify signature: input ${r} tapLeafScript has leaf version 0x${h.leafVersion.toString(16)}, expected 0x${y.toString(16)}.`
|
|
1138
1141
|
);
|
|
1139
|
-
const
|
|
1140
|
-
|
|
1142
|
+
const d = _e(h.leafVersion, h.script), P = new k();
|
|
1143
|
+
P.version = u.version, P.locktime = u.locktime;
|
|
1141
1144
|
for (const g of u.txInputs)
|
|
1142
|
-
|
|
1145
|
+
P.addInput(g.hash, g.index, g.sequence);
|
|
1143
1146
|
for (const g of u.txOutputs)
|
|
1144
|
-
|
|
1145
|
-
const
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1147
|
+
P.addOutput(g.script, g.value);
|
|
1148
|
+
const E = P.hashForWitnessV1(
|
|
1149
|
+
r,
|
|
1150
|
+
c,
|
|
1151
|
+
p,
|
|
1149
1152
|
k.SIGHASH_DEFAULT,
|
|
1150
|
-
|
|
1153
|
+
d
|
|
1151
1154
|
);
|
|
1152
|
-
if (!
|
|
1153
|
-
|
|
1154
|
-
C(
|
|
1155
|
-
C(
|
|
1155
|
+
if (!ke.verifySchnorr(
|
|
1156
|
+
E,
|
|
1157
|
+
C(s),
|
|
1158
|
+
C(i)
|
|
1156
1159
|
))
|
|
1157
1160
|
throw new Error(
|
|
1158
|
-
`Schnorr signature for input ${
|
|
1161
|
+
`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.`
|
|
1159
1162
|
);
|
|
1160
1163
|
}
|
|
1161
1164
|
export {
|
|
1162
1165
|
V as H,
|
|
1163
|
-
|
|
1166
|
+
nt as P,
|
|
1164
1167
|
Zt as a,
|
|
1165
1168
|
jt as b,
|
|
1166
1169
|
Qt as c,
|
|
1167
|
-
|
|
1168
|
-
|
|
1170
|
+
rt as d,
|
|
1171
|
+
it as e,
|
|
1169
1172
|
Jt as f,
|
|
1170
1173
|
eo as g,
|
|
1171
1174
|
$ as h,
|
|
1172
1175
|
to as i,
|
|
1173
1176
|
oo as j,
|
|
1174
1177
|
ct as k,
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1178
|
+
je as l,
|
|
1179
|
+
_e as m,
|
|
1180
|
+
Ie as n,
|
|
1181
|
+
tt as o,
|
|
1179
1182
|
Ct as p,
|
|
1180
1183
|
bt as q,
|
|
1181
|
-
|
|
1184
|
+
Ye as r
|
|
1182
1185
|
};
|
|
1183
|
-
//# sourceMappingURL=verifyScriptPathSchnorrSignature-
|
|
1186
|
+
//# sourceMappingURL=verifyScriptPathSchnorrSignature-D-fdi-sG.js.map
|