@babylonlabs-io/ts-sdk 0.52.0 → 0.53.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/ApplicationRegistry.abi-CLaa6E99.cjs +2 -0
- package/dist/ApplicationRegistry.abi-CLaa6E99.cjs.map +1 -0
- package/dist/{ApplicationRegistry.abi-Dn2qk6JG.js → ApplicationRegistry.abi-w5prf7Ig.js} +14 -1
- package/dist/ApplicationRegistry.abi-w5prf7Ig.js.map +1 -0
- package/dist/PayoutManager-1GWmbvI9.cjs +2 -0
- package/dist/PayoutManager-1GWmbvI9.cjs.map +1 -0
- package/dist/{PayoutManager-BwrV3xFW.js → PayoutManager-Ddo9_Ozc.js} +34 -32
- package/dist/PayoutManager-Ddo9_Ozc.js.map +1 -0
- package/dist/{PeginManager-BGWNJYPk.js → PeginManager-CTU0wgkJ.js} +37 -34
- package/dist/PeginManager-CTU0wgkJ.js.map +1 -0
- package/dist/PeginManager-De-eHl3v.cjs +2 -0
- package/dist/PeginManager-De-eHl3v.cjs.map +1 -0
- package/dist/buildAndBroadcastRefund-BnD2qUDW.cjs +2 -0
- package/dist/buildAndBroadcastRefund-BnD2qUDW.cjs.map +1 -0
- package/dist/{buildAndBroadcastRefund-BAT5A6MP.js → buildAndBroadcastRefund-DjS9nf87.js} +188 -177
- package/dist/buildAndBroadcastRefund-DjS9nf87.js.map +1 -0
- package/dist/{challengeAssert-HNbugpqL.cjs → challengeAssert-DLQfNcfU.cjs} +2 -2
- package/dist/{challengeAssert-HNbugpqL.cjs.map → challengeAssert-DLQfNcfU.cjs.map} +1 -1
- package/dist/{challengeAssert-csvYXBJB.js → challengeAssert-DvdbpEDY.js} +2 -2
- package/dist/{challengeAssert-csvYXBJB.js.map → challengeAssert-DvdbpEDY.js.map} +1 -1
- package/dist/constants-BhclpREj.js +19 -0
- package/dist/constants-BhclpREj.js.map +1 -0
- package/dist/constants-CvbARMl-.cjs +2 -0
- package/dist/constants-CvbARMl-.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +182 -181
- package/dist/index.js.map +1 -1
- package/dist/{mempoolApi-Dc1KSVNI.js → mempoolApi-CB7bHuwi.js} +106 -101
- package/dist/mempoolApi-CB7bHuwi.js.map +1 -0
- package/dist/mempoolApi-DqJByvqR.cjs +2 -0
- package/dist/mempoolApi-DqJByvqR.cjs.map +1 -0
- package/dist/noPayout-8dDKwi6n.cjs +2 -0
- package/dist/noPayout-8dDKwi6n.cjs.map +1 -0
- package/dist/{noPayout-DVx3zxUz.js → noPayout-tZFoNun3.js} +30 -30
- package/dist/noPayout-tZFoNun3.js.map +1 -0
- package/dist/{peginInput-B5XDDHpy.js → peginInput-BKD_b3gq.js} +10 -11
- package/dist/peginInput-BKD_b3gq.js.map +1 -0
- package/dist/{peginInput-De0C6aSj.cjs → peginInput-CAiiDZeO.cjs} +2 -2
- package/dist/peginInput-CAiiDZeO.cjs.map +1 -0
- package/dist/primeVpAuth-CF4cH5_e.cjs +2 -0
- package/dist/primeVpAuth-CF4cH5_e.cjs.map +1 -0
- package/dist/{primeVpAuth-DxMuWQCi.js → primeVpAuth-l-5x_2UV.js} +91 -85
- package/dist/{primeVpAuth-yTddDmGy.cjs.map → primeVpAuth-l-5x_2UV.js.map} +1 -1
- package/dist/tbv/core/clients/eth/protocol-params-reader.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/protocol-params-validation.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/types.d.ts +8 -0
- package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +2 -2
- package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts +10 -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.js +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +177 -176
- package/dist/tbv/core/index.js.map +1 -1
- package/dist/tbv/core/managers/PayoutManager.d.ts +6 -0
- package/dist/tbv/core/managers/PayoutManager.d.ts.map +1 -1
- package/dist/tbv/core/managers/PeginManager.d.ts +7 -0
- 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 +8 -0
- package/dist/tbv/core/primitives/__tests__/vaultCoreVersion.test.d.ts.map +1 -0
- package/dist/tbv/core/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.d.ts +1 -1
- package/dist/tbv/core/primitives/index.d.ts.map +1 -1
- package/dist/tbv/core/primitives/index.js +37 -36
- package/dist/tbv/core/primitives/index.js.map +1 -1
- package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/payout.d.ts +6 -0
- package/dist/tbv/core/primitives/psbt/payout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/pegin.d.ts +7 -0
- package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/peginInput.d.ts +6 -0
- package/dist/tbv/core/primitives/psbt/peginInput.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/refund.d.ts.map +1 -1
- package/dist/tbv/core/primitives/scripts/payout.d.ts +6 -0
- package/dist/tbv/core/primitives/scripts/payout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/vaultCoreVersion.d.ts +26 -0
- package/dist/tbv/core/primitives/vaultCoreVersion.d.ts.map +1 -0
- package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts +7 -0
- package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts +6 -0
- package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/verifyRegisteredVaultVersions.d.ts +8 -0
- package/dist/tbv/core/services/deposit/verifyRegisteredVaultVersions.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/services/refund/buildAndBroadcastRefund.d.ts +6 -0
- package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +177 -176
- package/dist/tbv/index.js.map +1 -1
- package/dist/{verifyScriptPathSchnorrSignature-BKECXOpa.js → verifyScriptPathSchnorrSignature-DpWZx5J0.js} +125 -130
- package/dist/verifyScriptPathSchnorrSignature-DpWZx5J0.js.map +1 -0
- package/dist/verifyScriptPathSchnorrSignature-a4Us7D3e.cjs +2 -0
- package/dist/verifyScriptPathSchnorrSignature-a4Us7D3e.cjs.map +1 -0
- package/package.json +3 -3
- package/dist/ApplicationRegistry.abi-BAPhJch3.cjs +0 -2
- package/dist/ApplicationRegistry.abi-BAPhJch3.cjs.map +0 -1
- package/dist/ApplicationRegistry.abi-Dn2qk6JG.js.map +0 -1
- package/dist/PayoutManager-BwrV3xFW.js.map +0 -1
- package/dist/PayoutManager-CBfHfLfz.cjs +0 -2
- package/dist/PayoutManager-CBfHfLfz.cjs.map +0 -1
- package/dist/PeginManager-BGWNJYPk.js.map +0 -1
- package/dist/PeginManager-DDp-ZRIa.cjs +0 -2
- package/dist/PeginManager-DDp-ZRIa.cjs.map +0 -1
- package/dist/buildAndBroadcastRefund-3MLyCOtv.cjs +0 -2
- package/dist/buildAndBroadcastRefund-3MLyCOtv.cjs.map +0 -1
- package/dist/buildAndBroadcastRefund-BAT5A6MP.js.map +0 -1
- package/dist/constants-CSG2XeD8.cjs +0 -2
- package/dist/constants-CSG2XeD8.cjs.map +0 -1
- package/dist/constants-Cd_fN8VT.js +0 -12
- package/dist/constants-Cd_fN8VT.js.map +0 -1
- package/dist/mempoolApi-Dc1KSVNI.js.map +0 -1
- package/dist/mempoolApi-NMiYQAXI.cjs +0 -2
- package/dist/mempoolApi-NMiYQAXI.cjs.map +0 -1
- package/dist/noPayout-ChPNKTbm.cjs +0 -2
- package/dist/noPayout-ChPNKTbm.cjs.map +0 -1
- package/dist/noPayout-DVx3zxUz.js.map +0 -1
- package/dist/peginInput-B5XDDHpy.js.map +0 -1
- package/dist/peginInput-De0C6aSj.cjs.map +0 -1
- package/dist/primeVpAuth-DxMuWQCi.js.map +0 -1
- package/dist/primeVpAuth-yTddDmGy.cjs +0 -2
- package/dist/tbv/core/primitives/__tests__/txGraphVersion.test.d.ts +0 -7
- package/dist/tbv/core/primitives/__tests__/txGraphVersion.test.d.ts.map +0 -1
- package/dist/tbv/core/primitives/txGraphVersion.d.ts +0 -11
- package/dist/tbv/core/primitives/txGraphVersion.d.ts.map +0 -1
- package/dist/verifyScriptPathSchnorrSignature-BKECXOpa.js.map +0 -1
- package/dist/verifyScriptPathSchnorrSignature-CVPh04ZI.cjs +0 -2
- package/dist/verifyScriptPathSchnorrSignature-CVPh04ZI.cjs.map +0 -1
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { computeMinClaimValue as
|
|
2
|
-
import { c as
|
|
1
|
+
import { computeMinClaimValue as Q, buildPeginTxFromPrePegin as Z, createPrePeginTransaction as j, createPayoutConnector as J, tapInternalPubkey as ee } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
2
|
+
import { c as L, d as te } from "./fundPeginTransaction-96FxwYYJ.js";
|
|
3
3
|
import { Buffer as c } from "buffer";
|
|
4
|
-
import { Transaction as S, Psbt as
|
|
5
|
-
import { s as x, h as E, u as
|
|
6
|
-
import { P as C, A as
|
|
7
|
-
import * as
|
|
8
|
-
|
|
9
|
-
async function ae(e, t) {
|
|
4
|
+
import { Transaction as S, Psbt as k, crypto as ne } from "bitcoinjs-lib";
|
|
5
|
+
import { s as x, h as E, u as _, T as V, c as re, d as oe, S as B, X as R } from "./bitcoin-B5aNKtsk.js";
|
|
6
|
+
import { P as C, A as T, b as q, M as I, V as ie, N } from "./constants-BhclpREj.js";
|
|
7
|
+
import * as se from "@bitcoin-js/tiny-secp256k1-asmjs";
|
|
8
|
+
async function ue(e, t) {
|
|
10
9
|
const n = t.pegInAmounts.length;
|
|
11
10
|
if (e.htlcValues.length !== n)
|
|
12
11
|
throw new Error(
|
|
@@ -20,10 +19,9 @@ async function ae(e, t) {
|
|
|
20
19
|
throw new Error(
|
|
21
20
|
`WASM Pre-PegIn returned non-positive depositorClaimValue ${e.depositorClaimValue}; expected > 0.`
|
|
22
21
|
);
|
|
23
|
-
const r = await
|
|
24
|
-
//
|
|
25
|
-
|
|
26
|
-
k,
|
|
22
|
+
const r = await Q(
|
|
23
|
+
// Must price the same graph version the builder constructed.
|
|
24
|
+
t.vaultCoreVersion,
|
|
27
25
|
t.numLocalChallengers,
|
|
28
26
|
t.universalChallengerPubkeys.length,
|
|
29
27
|
t.councilQuorum,
|
|
@@ -32,9 +30,9 @@ async function ae(e, t) {
|
|
|
32
30
|
);
|
|
33
31
|
if (e.depositorClaimValue !== r)
|
|
34
32
|
throw new Error(
|
|
35
|
-
`WASM Pre-PegIn depositorClaimValue ${e.depositorClaimValue} does not match the independently computed minimum claim value ${r} (numLocalChallengers=${t.numLocalChallengers}, numUniversalChallengers=${t.universalChallengerPubkeys.length}, councilQuorum=${t.councilQuorum}, councilSize=${t.councilSize}, feeRate=${t.feeRate}).`
|
|
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}).`
|
|
36
34
|
);
|
|
37
|
-
const o = t.minPeginFeeRate *
|
|
35
|
+
const o = t.minPeginFeeRate * L;
|
|
38
36
|
for (let i = 0; i < n; i++) {
|
|
39
37
|
const u = t.pegInAmounts[i], s = e.peginAmounts[i], a = e.htlcValues[i];
|
|
40
38
|
if (s !== u)
|
|
@@ -56,11 +54,11 @@ async function ae(e, t) {
|
|
|
56
54
|
);
|
|
57
55
|
if (l > o)
|
|
58
56
|
throw new Error(
|
|
59
|
-
`WASM Pre-PegIn implied PegIn fee for HTLC[${i}] (${l} sat) exceeds the plausibility cap ${o} sat (minPeginFeeRate=${t.minPeginFeeRate} × ${
|
|
57
|
+
`WASM Pre-PegIn implied PegIn fee for HTLC[${i}] (${l} sat) exceeds the plausibility cap ${o} sat (minPeginFeeRate=${t.minPeginFeeRate} × ${L} vbytes); htlcValue ${a} appears grossly inflated.`
|
|
60
58
|
);
|
|
61
59
|
}
|
|
62
60
|
}
|
|
63
|
-
function
|
|
61
|
+
function ae(e, t, n) {
|
|
64
62
|
if (e.length < t.length)
|
|
65
63
|
throw new Error(
|
|
66
64
|
`Encoded Pre-PegIn tx has ${e.length} output(s), fewer than the ${t.length} HTLC output(s) the cross-check validated.`
|
|
@@ -78,13 +76,10 @@ function ce(e, t, n) {
|
|
|
78
76
|
);
|
|
79
77
|
}
|
|
80
78
|
}
|
|
81
|
-
const
|
|
82
|
-
async function
|
|
83
|
-
const t =
|
|
84
|
-
|
|
85
|
-
// version resolution lands (fresh: activeVaultCoreVersion; resume: the
|
|
86
|
-
// vault's stamped vaultCoreVersion).
|
|
87
|
-
txGraphVersion: k,
|
|
79
|
+
const M = 64, ce = /^[0-9a-fA-F]+$/;
|
|
80
|
+
async function Ae(e) {
|
|
81
|
+
const t = D(e.authAnchorHash), n = await j({
|
|
82
|
+
txGraphVersion: e.vaultCoreVersion,
|
|
88
83
|
depositorPubkey: e.depositorPubkey,
|
|
89
84
|
vaultProviderPubkey: e.vaultProviderPubkey,
|
|
90
85
|
vaultKeeperPubkeys: e.vaultKeeperPubkeys,
|
|
@@ -100,9 +95,9 @@ async function Te(e) {
|
|
|
100
95
|
network: e.network,
|
|
101
96
|
authAnchorHash: t
|
|
102
97
|
});
|
|
103
|
-
await
|
|
104
|
-
const r =
|
|
105
|
-
|
|
98
|
+
await ue(n, e);
|
|
99
|
+
const r = te(n.txHex);
|
|
100
|
+
ae(
|
|
106
101
|
r.outputs,
|
|
107
102
|
n.htlcValues,
|
|
108
103
|
n.htlcScriptPubKeys
|
|
@@ -122,19 +117,19 @@ async function Te(e) {
|
|
|
122
117
|
authAnchorVout: i
|
|
123
118
|
};
|
|
124
119
|
}
|
|
125
|
-
function
|
|
120
|
+
function D(e) {
|
|
126
121
|
if (e === void 0) return;
|
|
127
122
|
const t = e.startsWith("0x") || e.startsWith("0X") ? e.slice(2) : e;
|
|
128
|
-
if (t.length !==
|
|
123
|
+
if (t.length !== M || !ce.test(t))
|
|
129
124
|
throw new Error(
|
|
130
|
-
`authAnchorHash must be 32-byte hex (${
|
|
125
|
+
`authAnchorHash must be 32-byte hex (${M} chars, no 0x prefix); got length ${t.length}`
|
|
131
126
|
);
|
|
132
127
|
return t.toLowerCase();
|
|
133
128
|
}
|
|
134
129
|
async function ke(e) {
|
|
135
|
-
const t = await
|
|
130
|
+
const t = await Z(
|
|
136
131
|
{
|
|
137
|
-
txGraphVersion:
|
|
132
|
+
txGraphVersion: e.prePeginParams.vaultCoreVersion,
|
|
138
133
|
depositorPubkey: e.prePeginParams.depositorPubkey,
|
|
139
134
|
vaultProviderPubkey: e.prePeginParams.vaultProviderPubkey,
|
|
140
135
|
vaultKeeperPubkeys: e.prePeginParams.vaultKeeperPubkeys,
|
|
@@ -148,7 +143,7 @@ async function ke(e) {
|
|
|
148
143
|
councilQuorum: e.prePeginParams.councilQuorum,
|
|
149
144
|
councilSize: e.prePeginParams.councilSize,
|
|
150
145
|
network: e.prePeginParams.network,
|
|
151
|
-
authAnchorHash:
|
|
146
|
+
authAnchorHash: D(
|
|
152
147
|
e.prePeginParams.authAnchorHash
|
|
153
148
|
)
|
|
154
149
|
},
|
|
@@ -163,10 +158,10 @@ async function ke(e) {
|
|
|
163
158
|
vaultValue: t.vaultValue
|
|
164
159
|
};
|
|
165
160
|
}
|
|
166
|
-
async function
|
|
167
|
-
const t = await
|
|
161
|
+
async function le(e) {
|
|
162
|
+
const t = await J(
|
|
168
163
|
{
|
|
169
|
-
txGraphVersion:
|
|
164
|
+
txGraphVersion: e.vaultCoreVersion,
|
|
170
165
|
depositor: e.depositor,
|
|
171
166
|
vaultProvider: e.vaultProvider,
|
|
172
167
|
vaultKeepers: e.vaultKeepers,
|
|
@@ -183,33 +178,34 @@ async function he(e) {
|
|
|
183
178
|
payoutControlBlock: t.payoutControlBlock
|
|
184
179
|
};
|
|
185
180
|
}
|
|
186
|
-
const
|
|
181
|
+
const K = 3, F = 10, X = 100;
|
|
187
182
|
async function Ce(e) {
|
|
188
|
-
const t = x(e.payoutTxHex), n = x(e.peginTxHex), r = x(e.assertTxHex), o = await
|
|
183
|
+
const t = x(e.payoutTxHex), n = x(e.peginTxHex), r = x(e.assertTxHex), o = await le({
|
|
184
|
+
vaultCoreVersion: e.vaultCoreVersion,
|
|
189
185
|
depositor: e.depositorBtcPubkey,
|
|
190
186
|
vaultProvider: e.vaultProviderBtcPubkey,
|
|
191
187
|
vaultKeepers: e.vaultKeeperBtcPubkeys,
|
|
192
188
|
universalChallengers: e.universalChallengerBtcPubkeys,
|
|
193
189
|
timelockPegin: e.timelockPegin,
|
|
194
190
|
network: e.network
|
|
195
|
-
}), i = E(o.payoutScript), u = E(o.payoutControlBlock), s = S.fromHex(t), a = S.fromHex(n), l = S.fromHex(r), p = new
|
|
191
|
+
}), i = E(o.payoutScript), u = E(o.payoutControlBlock), s = S.fromHex(t), a = S.fromHex(n), l = S.fromHex(r), p = new k();
|
|
196
192
|
if (p.setVersion(s.version), p.setLocktime(s.locktime), s.ins.length !== 2)
|
|
197
193
|
throw new Error(
|
|
198
194
|
`Payout transaction must have exactly 2 inputs, got ${s.ins.length}`
|
|
199
195
|
);
|
|
200
|
-
const f = s.ins[0], P = s.ins[1], h =
|
|
196
|
+
const f = s.ins[0], P = s.ins[1], h = _(
|
|
201
197
|
new Uint8Array(f.hash).slice().reverse()
|
|
202
|
-
),
|
|
203
|
-
if (h !==
|
|
198
|
+
), $ = a.getId();
|
|
199
|
+
if (h !== $ || f.index !== C)
|
|
204
200
|
throw new Error(
|
|
205
|
-
`Input 0 must spend PegIn:${C}. Expected ${
|
|
201
|
+
`Input 0 must spend PegIn:${C}. Expected ${$}:${C}, got ${h}:${f.index}`
|
|
206
202
|
);
|
|
207
|
-
const
|
|
203
|
+
const w = _(
|
|
208
204
|
new Uint8Array(P.hash).slice().reverse()
|
|
209
205
|
), d = l.getId();
|
|
210
|
-
if (
|
|
206
|
+
if (w !== d || P.index !== T)
|
|
211
207
|
throw new Error(
|
|
212
|
-
`Input 1 must spend Assert:${
|
|
208
|
+
`Input 1 must spend Assert:${T}. Expected ${d}:${T}, got ${w}:${P.index}`
|
|
213
209
|
);
|
|
214
210
|
const g = a.outs[f.index];
|
|
215
211
|
if (!g)
|
|
@@ -219,9 +215,9 @@ async function Ce(e) {
|
|
|
219
215
|
const y = l.outs[P.index];
|
|
220
216
|
if (!y)
|
|
221
217
|
throw new Error(
|
|
222
|
-
`Previous output not found for input 1 (txid: ${
|
|
218
|
+
`Previous output not found for input 1 (txid: ${w}, index: ${P.index})`
|
|
223
219
|
);
|
|
224
|
-
|
|
220
|
+
he({
|
|
225
221
|
payoutTx: s,
|
|
226
222
|
peginValueSats: g.value,
|
|
227
223
|
claimerBtcPubkey: e.claimerBtcPubkey,
|
|
@@ -231,19 +227,19 @@ async function Ce(e) {
|
|
|
231
227
|
registeredPayoutScriptPubKey: e.registeredPayoutScriptPubKey,
|
|
232
228
|
commissionBps: e.commissionBps
|
|
233
229
|
});
|
|
234
|
-
const
|
|
230
|
+
const m = g.value + y.value;
|
|
235
231
|
let b = 0;
|
|
236
232
|
for (const A of s.outs) b += A.value;
|
|
237
|
-
if (b >
|
|
233
|
+
if (b > m)
|
|
238
234
|
throw new Error(
|
|
239
|
-
`Payout outputs (${b} sats) exceed inputs (${
|
|
235
|
+
`Payout outputs (${b} sats) exceed inputs (${m} sats); invalid transaction.`
|
|
240
236
|
);
|
|
241
|
-
const
|
|
242
|
-
|
|
237
|
+
const O = m - b, U = Math.floor(
|
|
238
|
+
m * F / X
|
|
243
239
|
);
|
|
244
|
-
if (
|
|
240
|
+
if (O > U)
|
|
245
241
|
throw new Error(
|
|
246
|
-
`Payout implicit fee ${
|
|
242
|
+
`Payout implicit fee ${O} sats exceeds the safety cap of ${U} sats (${F}/${X} of inputs=${m}); refusing to sign payout.`
|
|
247
243
|
);
|
|
248
244
|
p.addInput({
|
|
249
245
|
hash: f.hash,
|
|
@@ -260,7 +256,7 @@ async function Ce(e) {
|
|
|
260
256
|
controlBlock: c.from(u)
|
|
261
257
|
}
|
|
262
258
|
],
|
|
263
|
-
tapInternalKey: c.from(
|
|
259
|
+
tapInternalKey: c.from(ee)
|
|
264
260
|
// sighashType omitted - defaults to SIGHASH_DEFAULT (0x00) for Taproot
|
|
265
261
|
}), p.addInput({
|
|
266
262
|
hash: P.hash,
|
|
@@ -281,7 +277,7 @@ async function Ce(e) {
|
|
|
281
277
|
psbtHex: p.toHex()
|
|
282
278
|
};
|
|
283
279
|
}
|
|
284
|
-
function
|
|
280
|
+
function he(e) {
|
|
285
281
|
const {
|
|
286
282
|
payoutTx: t,
|
|
287
283
|
peginValueSats: n,
|
|
@@ -292,43 +288,43 @@ function de(e) {
|
|
|
292
288
|
registeredPayoutScriptPubKey: s,
|
|
293
289
|
commissionBps: a
|
|
294
290
|
} = e;
|
|
295
|
-
if (!
|
|
291
|
+
if (!re(s))
|
|
296
292
|
throw new Error("Invalid registeredPayoutScriptPubKey: not valid hex");
|
|
297
293
|
const l = x(r).toLowerCase(), p = x(o).toLowerCase(), f = x(i).toLowerCase(), P = u.map(
|
|
298
294
|
(y) => x(y).toLowerCase()
|
|
299
295
|
);
|
|
300
|
-
let h, w
|
|
296
|
+
let h, $, w;
|
|
301
297
|
if (l === p)
|
|
302
|
-
h = "vp-claimer",
|
|
298
|
+
h = "vp-claimer", $ = ie, w = x(s);
|
|
303
299
|
else if (l === f)
|
|
304
|
-
h = "depositor-as-claimer",
|
|
300
|
+
h = "depositor-as-claimer", $ = N, w = x(s);
|
|
305
301
|
else if (P.includes(l))
|
|
306
|
-
h = "vk-claimer",
|
|
302
|
+
h = "vk-claimer", $ = N, w = x(oe(l));
|
|
307
303
|
else
|
|
308
304
|
throw new Error(
|
|
309
305
|
`Unknown claimer pubkey ${l}: not VP, depositor, or a registered vault keeper`
|
|
310
306
|
);
|
|
311
|
-
if (t.outs.length !==
|
|
307
|
+
if (t.outs.length !== $)
|
|
312
308
|
throw new Error(
|
|
313
|
-
`Payout transaction has ${t.outs.length} output(s), expected exactly ${
|
|
309
|
+
`Payout transaction has ${t.outs.length} output(s), expected exactly ${$} for role ${h}.`
|
|
314
310
|
);
|
|
315
|
-
const d = c.from(
|
|
311
|
+
const d = c.from(w, "hex");
|
|
316
312
|
if (!t.outs[0].script.equals(d))
|
|
317
313
|
throw new Error(
|
|
318
314
|
`Payout transaction output 0 does not pay the expected scriptPubKey for role ${h}`
|
|
319
315
|
);
|
|
320
|
-
const g =
|
|
321
|
-
if (t.outs[g].value !==
|
|
316
|
+
const g = $ - 1;
|
|
317
|
+
if (t.outs[g].value !== q)
|
|
322
318
|
throw new Error(
|
|
323
|
-
`Payout CPFP anchor (out ${g}) value ${t.outs[g].value} sats must equal ${
|
|
319
|
+
`Payout CPFP anchor (out ${g}) value ${t.outs[g].value} sats must equal ${q} sats`
|
|
324
320
|
);
|
|
325
321
|
if (h === "vp-claimer") {
|
|
326
|
-
if (!Number.isInteger(a) || a < 0 || a >=
|
|
322
|
+
if (!Number.isInteger(a) || a < 0 || a >= I)
|
|
327
323
|
throw new Error(
|
|
328
|
-
`commissionBps must be an integer in [0, ${
|
|
324
|
+
`commissionBps must be an integer in [0, ${I}), got ${a}`
|
|
329
325
|
);
|
|
330
326
|
const y = Math.floor(
|
|
331
|
-
n * a /
|
|
327
|
+
n * a / I
|
|
332
328
|
);
|
|
333
329
|
if (t.outs[1].value > y)
|
|
334
330
|
throw new Error(
|
|
@@ -336,8 +332,8 @@ function de(e) {
|
|
|
336
332
|
);
|
|
337
333
|
}
|
|
338
334
|
}
|
|
339
|
-
function
|
|
340
|
-
const r =
|
|
335
|
+
function Te(e, t, n = 0) {
|
|
336
|
+
const r = k.fromHex(e);
|
|
341
337
|
if (n >= r.data.inputs.length)
|
|
342
338
|
throw new Error(
|
|
343
339
|
`Input index ${n} out of range (${r.data.inputs.length} inputs)`
|
|
@@ -347,33 +343,33 @@ function Ie(e, t, n = 0) {
|
|
|
347
343
|
const i = E(t);
|
|
348
344
|
for (const u of o.tapScriptSig)
|
|
349
345
|
if (u.pubkey.equals(c.from(i)))
|
|
350
|
-
return
|
|
346
|
+
return W(u.signature, n);
|
|
351
347
|
throw new Error(
|
|
352
348
|
`No signature found for depositor pubkey: ${t} at input ${n}`
|
|
353
349
|
);
|
|
354
350
|
}
|
|
355
351
|
if (o.finalScriptWitness && o.finalScriptWitness.length > 0) {
|
|
356
|
-
const i =
|
|
357
|
-
if (i.length !==
|
|
352
|
+
const i = de(o.finalScriptWitness);
|
|
353
|
+
if (i.length !== K)
|
|
358
354
|
throw new Error(
|
|
359
|
-
`Unexpected finalized witness stack size at input ${n}: expected ${
|
|
355
|
+
`Unexpected finalized witness stack size at input ${n}: expected ${K} items (signature, script, controlBlock), got ${i.length}`
|
|
360
356
|
);
|
|
361
|
-
return
|
|
357
|
+
return W(i[0], n);
|
|
362
358
|
}
|
|
363
359
|
throw new Error(
|
|
364
360
|
`No tapScriptSig or finalScriptWitness found in signed PSBT at input ${n}`
|
|
365
361
|
);
|
|
366
362
|
}
|
|
367
|
-
function
|
|
363
|
+
function W(e, t) {
|
|
368
364
|
if (e.length === 64)
|
|
369
|
-
return
|
|
365
|
+
return _(new Uint8Array(e));
|
|
370
366
|
throw e.length === 65 ? new Error(
|
|
371
367
|
`Unexpected sighash byte 0x${e[64].toString(16).padStart(2, "0")} at input ${t}. Expected implicit SIGHASH_DEFAULT as a 64-byte signature.`
|
|
372
368
|
) : new Error(
|
|
373
369
|
`Unexpected signature length at input ${t}: ${e.length}`
|
|
374
370
|
);
|
|
375
371
|
}
|
|
376
|
-
function
|
|
372
|
+
function de(e) {
|
|
377
373
|
const t = [];
|
|
378
374
|
let n = 0;
|
|
379
375
|
const r = (u) => {
|
|
@@ -409,109 +405,109 @@ function pe(e) {
|
|
|
409
405
|
);
|
|
410
406
|
return t;
|
|
411
407
|
}
|
|
412
|
-
class
|
|
408
|
+
class v extends Error {
|
|
413
409
|
constructor(t) {
|
|
414
410
|
super(
|
|
415
411
|
`Wallet returned a PSBT for a different transaction: ${t}`
|
|
416
412
|
), this.name = "PsbtSubstitutionError";
|
|
417
413
|
}
|
|
418
414
|
}
|
|
419
|
-
function
|
|
415
|
+
function z(e, t) {
|
|
420
416
|
try {
|
|
421
|
-
return
|
|
417
|
+
return k.fromHex(t);
|
|
422
418
|
} catch (n) {
|
|
423
419
|
const r = n instanceof Error ? n.message : String(n);
|
|
424
420
|
throw new Error(`Failed to parse ${e} PSBT: ${r}`);
|
|
425
421
|
}
|
|
426
422
|
}
|
|
427
|
-
const
|
|
428
|
-
function
|
|
429
|
-
return `${e.toString("hex").slice(0,
|
|
423
|
+
const pe = 8;
|
|
424
|
+
function H(e) {
|
|
425
|
+
return `${e.toString("hex").slice(0, pe)}…`;
|
|
430
426
|
}
|
|
431
|
-
function
|
|
427
|
+
function G(e) {
|
|
432
428
|
const t = c.from(e).reverse();
|
|
433
|
-
return
|
|
429
|
+
return H(t);
|
|
434
430
|
}
|
|
435
|
-
function
|
|
436
|
-
const t =
|
|
431
|
+
function Ie(e) {
|
|
432
|
+
const t = z("requested", e.requestedPsbtHex), n = z("returned", e.returnedPsbtHex);
|
|
437
433
|
if (t.version !== n.version)
|
|
438
|
-
throw new
|
|
434
|
+
throw new v(
|
|
439
435
|
`tx version differs (requested=${t.version}, returned=${n.version})`
|
|
440
436
|
);
|
|
441
437
|
if (t.locktime !== n.locktime)
|
|
442
|
-
throw new
|
|
438
|
+
throw new v(
|
|
443
439
|
`tx locktime differs (requested=${t.locktime}, returned=${n.locktime})`
|
|
444
440
|
);
|
|
445
441
|
if (t.txInputs.length !== n.txInputs.length)
|
|
446
|
-
throw new
|
|
442
|
+
throw new v(
|
|
447
443
|
`input count differs (requested=${t.txInputs.length}, returned=${n.txInputs.length})`
|
|
448
444
|
);
|
|
449
445
|
if (t.txOutputs.length !== n.txOutputs.length)
|
|
450
|
-
throw new
|
|
446
|
+
throw new v(
|
|
451
447
|
`output count differs (requested=${t.txOutputs.length}, returned=${n.txOutputs.length})`
|
|
452
448
|
);
|
|
453
449
|
for (let r = 0; r < t.txInputs.length; r++) {
|
|
454
450
|
const o = t.txInputs[r], i = n.txInputs[r];
|
|
455
451
|
if (!o.hash.equals(i.hash))
|
|
456
|
-
throw new
|
|
457
|
-
`input ${r} prevout txid differs (requested=${
|
|
452
|
+
throw new v(
|
|
453
|
+
`input ${r} prevout txid differs (requested=${G(o.hash)}, returned=${G(i.hash)})`
|
|
458
454
|
);
|
|
459
455
|
if (o.index !== i.index)
|
|
460
|
-
throw new
|
|
456
|
+
throw new v(
|
|
461
457
|
`input ${r} prevout vout differs (requested=${o.index}, returned=${i.index})`
|
|
462
458
|
);
|
|
463
459
|
if (o.sequence !== i.sequence)
|
|
464
|
-
throw new
|
|
460
|
+
throw new v(
|
|
465
461
|
`input ${r} sequence differs (requested=${o.sequence}, returned=${i.sequence})`
|
|
466
462
|
);
|
|
467
463
|
}
|
|
468
464
|
for (let r = 0; r < t.txOutputs.length; r++) {
|
|
469
465
|
const o = t.txOutputs[r], i = n.txOutputs[r];
|
|
470
466
|
if (!o.script.equals(i.script))
|
|
471
|
-
throw new
|
|
472
|
-
`output ${r} scriptPubKey differs (requested=${
|
|
467
|
+
throw new v(
|
|
468
|
+
`output ${r} scriptPubKey differs (requested=${H(o.script)}, returned=${H(i.script)})`
|
|
473
469
|
);
|
|
474
470
|
if (o.value !== i.value)
|
|
475
|
-
throw new
|
|
471
|
+
throw new v(
|
|
476
472
|
`output ${r} value differs (requested=${o.value}, returned=${i.value})`
|
|
477
473
|
);
|
|
478
474
|
}
|
|
479
475
|
}
|
|
480
|
-
const
|
|
481
|
-
function
|
|
482
|
-
if (e <
|
|
476
|
+
const Y = 253, fe = 254, ge = 65535, Pe = 4294967295;
|
|
477
|
+
function xe(e) {
|
|
478
|
+
if (e < Y)
|
|
483
479
|
return c.from([e]);
|
|
484
|
-
if (e <=
|
|
480
|
+
if (e <= ge) {
|
|
485
481
|
const t = c.alloc(2);
|
|
486
|
-
return t.writeUInt16LE(e), c.concat([c.from([
|
|
482
|
+
return t.writeUInt16LE(e), c.concat([c.from([Y]), t]);
|
|
487
483
|
}
|
|
488
|
-
if (e <=
|
|
484
|
+
if (e <= Pe) {
|
|
489
485
|
const t = c.alloc(4);
|
|
490
|
-
return t.writeUInt32LE(e), c.concat([c.from([
|
|
486
|
+
return t.writeUInt32LE(e), c.concat([c.from([fe]), t]);
|
|
491
487
|
}
|
|
492
488
|
throw new Error(`Script too large to encode as CompactSize: ${e} bytes`);
|
|
493
489
|
}
|
|
494
490
|
const $e = "TapLeaf";
|
|
495
|
-
function
|
|
491
|
+
function we(e, t) {
|
|
496
492
|
const n = c.concat([
|
|
497
493
|
c.from([e]),
|
|
498
|
-
|
|
494
|
+
xe(t.length),
|
|
499
495
|
c.from(t)
|
|
500
496
|
]);
|
|
501
|
-
return
|
|
497
|
+
return ne.taggedHash($e, n);
|
|
502
498
|
}
|
|
503
|
-
function
|
|
499
|
+
function _e(e) {
|
|
504
500
|
const { requestedPsbtHex: t, signatureHex: n, signerXOnlyPubkeyHex: r, inputIndex: o } = e, i = x(n);
|
|
505
|
-
if (i.length !==
|
|
501
|
+
if (i.length !== B)
|
|
506
502
|
throw new Error(
|
|
507
|
-
`Schnorr signature for input ${o} must be ${
|
|
503
|
+
`Schnorr signature for input ${o} must be ${B} hex chars (64 bytes), got ${i.length}.`
|
|
508
504
|
);
|
|
509
505
|
const u = x(r);
|
|
510
|
-
if (u.length !==
|
|
506
|
+
if (u.length !== R)
|
|
511
507
|
throw new Error(
|
|
512
|
-
`Signer x-only pubkey for input ${o} must be ${
|
|
508
|
+
`Signer x-only pubkey for input ${o} must be ${R} hex chars (32 bytes), got ${u.length}.`
|
|
513
509
|
);
|
|
514
|
-
const s =
|
|
510
|
+
const s = k.fromHex(t);
|
|
515
511
|
if (o < 0 || o >= s.data.inputs.length)
|
|
516
512
|
throw new Error(
|
|
517
513
|
`Input index ${o} out of range (${s.data.inputs.length} inputs).`
|
|
@@ -535,21 +531,21 @@ function He(e) {
|
|
|
535
531
|
throw new Error(
|
|
536
532
|
`Cannot verify signature: input ${o} tapLeafScript has leaf version 0x${f.leafVersion.toString(16)}, expected 0x${V.toString(16)}.`
|
|
537
533
|
);
|
|
538
|
-
const P =
|
|
534
|
+
const P = we(f.leafVersion, f.script), h = new S();
|
|
539
535
|
h.version = s.version, h.locktime = s.locktime;
|
|
540
536
|
for (const d of s.txInputs)
|
|
541
537
|
h.addInput(d.hash, d.index, d.sequence);
|
|
542
538
|
for (const d of s.txOutputs)
|
|
543
539
|
h.addOutput(d.script, d.value);
|
|
544
|
-
const
|
|
540
|
+
const $ = h.hashForWitnessV1(
|
|
545
541
|
o,
|
|
546
542
|
a,
|
|
547
543
|
l,
|
|
548
544
|
S.SIGHASH_DEFAULT,
|
|
549
545
|
P
|
|
550
546
|
);
|
|
551
|
-
if (!
|
|
552
|
-
|
|
547
|
+
if (!se.verifySchnorr(
|
|
548
|
+
$,
|
|
553
549
|
E(u),
|
|
554
550
|
E(i)
|
|
555
551
|
))
|
|
@@ -558,15 +554,14 @@ function He(e) {
|
|
|
558
554
|
);
|
|
559
555
|
}
|
|
560
556
|
export {
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
Te as a,
|
|
557
|
+
v as P,
|
|
558
|
+
Ae as a,
|
|
564
559
|
ke as b,
|
|
565
560
|
Ce as c,
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
561
|
+
Ie as d,
|
|
562
|
+
Te as e,
|
|
563
|
+
_e as f,
|
|
564
|
+
le as g,
|
|
565
|
+
D as n
|
|
571
566
|
};
|
|
572
|
-
//# sourceMappingURL=verifyScriptPathSchnorrSignature-
|
|
567
|
+
//# sourceMappingURL=verifyScriptPathSchnorrSignature-DpWZx5J0.js.map
|