@babylonlabs-io/ts-sdk 3.1.2 → 3.2.1
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-BH2-LHxN.cjs +2 -0
- package/dist/BTCVaultRegistry.abi-BH2-LHxN.cjs.map +1 -0
- package/dist/{BTCVaultRegistry.abi-BmHpMUWD.js → BTCVaultRegistry.abi-BzNTa_EU.js} +19 -1
- package/dist/BTCVaultRegistry.abi-BzNTa_EU.js.map +1 -0
- package/dist/{PayoutManager-DOdsgcUR.cjs → PayoutManager-B1Ev0r7o.cjs} +2 -2
- package/dist/{PayoutManager-DOdsgcUR.cjs.map → PayoutManager-B1Ev0r7o.cjs.map} +1 -1
- package/dist/{PayoutManager-BZ212yml.js → PayoutManager-xEGvTbhL.js} +3 -3
- package/dist/{PayoutManager-BZ212yml.js.map → PayoutManager-xEGvTbhL.js.map} +1 -1
- package/dist/{PeginManager-PyKbfy5q.cjs → PeginManager-BCRtUqyX.cjs} +2 -2
- package/dist/{PeginManager-PyKbfy5q.cjs.map → PeginManager-BCRtUqyX.cjs.map} +1 -1
- package/dist/{PeginManager-Dfr5Qe1g.js → PeginManager-sizm3dlw.js} +7 -7
- package/dist/{PeginManager-Dfr5Qe1g.js.map → PeginManager-sizm3dlw.js.map} +1 -1
- package/dist/buildAndBroadcastReclaim-CE77jzTp.cjs +2 -0
- package/dist/buildAndBroadcastReclaim-CE77jzTp.cjs.map +1 -0
- package/dist/{buildAndBroadcastReclaim-R0HNpLMD.js → buildAndBroadcastReclaim-rQyAiAUS.js} +901 -867
- package/dist/buildAndBroadcastReclaim-rQyAiAUS.js.map +1 -0
- package/dist/challengeAssert-B2otuf7y.js +509 -0
- package/dist/challengeAssert-B2otuf7y.js.map +1 -0
- package/dist/challengeAssert-C3eMcM5Y.cjs +2 -0
- package/dist/challengeAssert-C3eMcM5Y.cjs.map +1 -0
- package/dist/constants-CAm10Qwp.cjs +2 -0
- package/dist/constants-CAm10Qwp.cjs.map +1 -0
- package/dist/constants-CvQZuxKv.js +48 -0
- package/dist/constants-CvQZuxKv.js.map +1 -0
- package/dist/{index-CVBtBjQ5.js → index-BRsWXDlv.js} +6 -6
- package/dist/{index-CVBtBjQ5.js.map → index-BRsWXDlv.js.map} +1 -1
- package/dist/{index-DpjYs5yr.cjs → index-C6avwx1s.cjs} +2 -2
- package/dist/{index-DpjYs5yr.cjs.map → index-C6avwx1s.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +297 -298
- package/dist/index.js.map +1 -1
- package/dist/{pegin-registration-client-kdz4fT5_.js → pegin-registration-client-8tzSRDaq.js} +46 -45
- package/dist/pegin-registration-client-8tzSRDaq.js.map +1 -0
- package/dist/pegin-registration-client-Bmkh1OZ9.cjs +2 -0
- package/dist/pegin-registration-client-Bmkh1OZ9.cjs.map +1 -0
- package/dist/peginState-CIibG9S_.js +75 -0
- package/dist/peginState-CIibG9S_.js.map +1 -0
- package/dist/peginState-IyE22wWh.cjs +2 -0
- package/dist/peginState-IyE22wWh.cjs.map +1 -0
- package/dist/{primeVpAuth-BPj2TPdD.cjs → primeVpAuth-CXNXYKrh.cjs} +2 -2
- package/dist/{primeVpAuth-BPj2TPdD.cjs.map → primeVpAuth-CXNXYKrh.cjs.map} +1 -1
- package/dist/{primeVpAuth-CiCdRNGf.js → primeVpAuth-D4UWXQ76.js} +2 -2
- package/dist/{primeVpAuth-CiCdRNGf.js.map → primeVpAuth-D4UWXQ76.js.map} +1 -1
- package/dist/{registration-records-CKLAv3gw.js → registration-records-BBOz21Dm.js} +15 -15
- package/dist/{registration-records-CKLAv3gw.js.map → registration-records-BBOz21Dm.js.map} +1 -1
- package/dist/{registration-records-DFQgBaYi.cjs → registration-records-DaBufozs.cjs} +2 -2
- package/dist/{registration-records-DFQgBaYi.cjs.map → registration-records-DaBufozs.cjs.map} +1 -1
- package/dist/{reservation-DOAHVT3B.js → reservation-BZQABu4g.js} +2 -2
- package/dist/{reservation-DOAHVT3B.js.map → reservation-BZQABu4g.js.map} +1 -1
- package/dist/{reservation-ECxjZi5t.cjs → reservation-CA5knoQ0.cjs} +2 -2
- package/dist/{reservation-ECxjZi5t.cjs.map → reservation-CA5knoQ0.cjs.map} +1 -1
- package/dist/{signer-set-reader-DFAu6I-v.cjs → signer-set-reader-D-CyIYR5.cjs} +2 -2
- package/dist/{signer-set-reader-DFAu6I-v.cjs.map → signer-set-reader-D-CyIYR5.cjs.map} +1 -1
- package/dist/{signer-set-reader-BCtmSKUM.js → signer-set-reader-DFF9MgQN.js} +2 -2
- package/dist/{signer-set-reader-BCtmSKUM.js.map → signer-set-reader-DFF9MgQN.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/types.d.ts +8 -0
- package/dist/tbv/core/clients/eth/types.d.ts.map +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 +14 -0
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.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 +293 -294
- package/dist/tbv/core/index.js.map +1 -1
- package/dist/tbv/core/managers/index.cjs +1 -1
- package/dist/tbv/core/managers/index.js +2 -2
- package/dist/tbv/core/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.js +29 -30
- package/dist/tbv/core/primitives/index.js.map +1 -1
- package/dist/tbv/core/primitives/psbt/__tests__/challengeAssert.test.d.ts +2 -0
- package/dist/tbv/core/primitives/psbt/__tests__/challengeAssert.test.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/__tests__/noPayout.test.d.ts +2 -0
- package/dist/tbv/core/primitives/psbt/__tests__/noPayout.test.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/challengeAssert.d.ts +43 -0
- package/dist/tbv/core/primitives/psbt/challengeAssert.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/constants.d.ts +50 -2
- package/dist/tbv/core/primitives/psbt/constants.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/noPayout.d.ts +42 -0
- package/dist/tbv/core/primitives/psbt/noPayout.d.ts.map +1 -1
- package/dist/tbv/core/services/activation/activateVault.d.ts +50 -0
- package/dist/tbv/core/services/activation/activateVault.d.ts.map +1 -1
- package/dist/tbv/core/services/activation/index.d.ts +1 -1
- package/dist/tbv/core/services/activation/index.d.ts.map +1 -1
- package/dist/tbv/core/services/delegated-claim/__tests__/realWasmWatchtowerArtifacts.test.d.ts +9 -0
- package/dist/tbv/core/services/delegated-claim/__tests__/realWasmWatchtowerArtifacts.test.d.ts.map +1 -0
- package/dist/tbv/core/services/delegated-claim/assembleWatchtowerArtifacts.d.ts +5 -7
- package/dist/tbv/core/services/delegated-claim/assembleWatchtowerArtifacts.d.ts.map +1 -1
- package/dist/tbv/core/services/delegated-claim/index.d.ts +3 -4
- package/dist/tbv/core/services/delegated-claim/index.d.ts.map +1 -1
- package/dist/tbv/core/services/delegated-claim/planDelegatedClaimSigning.d.ts.map +1 -1
- package/dist/tbv/core/services/delegated-claim/readWatchtowerArtifacts.d.ts +14 -8
- package/dist/tbv/core/services/delegated-claim/readWatchtowerArtifacts.d.ts.map +1 -1
- package/dist/tbv/core/services/delegated-claim/types.d.ts +32 -19
- 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 +12 -0
- package/dist/tbv/core/services/deposit/__tests__/signDepositorGraph.realGraph.test.d.ts.map +1 -0
- package/dist/tbv/core/services/deposit/peginState.d.ts +20 -1
- package/dist/tbv/core/services/deposit/peginState.d.ts.map +1 -1
- 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 +46 -1
- 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 +59 -59
- package/dist/tbv/core/utils/index.cjs +1 -1
- package/dist/tbv/core/utils/index.js +1 -1
- package/dist/tbv/core/wasm/__tests__/challengeAssertOutputConnector.test.d.ts +2 -0
- package/dist/tbv/core/wasm/__tests__/challengeAssertOutputConnector.test.d.ts.map +1 -0
- package/dist/tbv/core/wasm/index.cjs +1 -1
- package/dist/tbv/core/wasm/index.cjs.map +1 -1
- package/dist/tbv/core/wasm/index.d.ts +14 -2
- package/dist/tbv/core/wasm/index.d.ts.map +1 -1
- package/dist/tbv/core/wasm/index.js +81 -77
- package/dist/tbv/core/wasm/index.js.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +293 -294
- package/dist/tbv/index.js.map +1 -1
- package/dist/{toRefundInputs-BbAOOUg6.cjs → toRefundInputs-DOCLxqC1.cjs} +2 -2
- package/dist/{toRefundInputs-BbAOOUg6.cjs.map → toRefundInputs-DOCLxqC1.cjs.map} +1 -1
- package/dist/{toRefundInputs-DW14g6wH.js → toRefundInputs-Dso_QEr-.js} +5 -5
- package/dist/{toRefundInputs-DW14g6wH.js.map → toRefundInputs-Dso_QEr-.js.map} +1 -1
- package/dist/{types-Bda75Od0.cjs → types-DGr5HWwD.cjs} +2 -2
- package/dist/types-DGr5HWwD.cjs.map +1 -0
- package/dist/{types-C5jj3Cc-.js → types-Dbs--c2M.js} +2 -2
- package/dist/types-Dbs--c2M.js.map +1 -0
- package/dist/{verifyKeyPathSchnorrSignature-CQUut2-O.cjs → verifyKeyPathSchnorrSignature-BRTpEH9X.cjs} +2 -2
- package/dist/{verifyKeyPathSchnorrSignature-CQUut2-O.cjs.map → verifyKeyPathSchnorrSignature-BRTpEH9X.cjs.map} +1 -1
- package/dist/{verifyKeyPathSchnorrSignature-DxPbeSdQ.js → verifyKeyPathSchnorrSignature-IIj3Z2se.js} +2 -2
- package/dist/{verifyKeyPathSchnorrSignature-DxPbeSdQ.js.map → verifyKeyPathSchnorrSignature-IIj3Z2se.js.map} +1 -1
- package/dist/{verifyScriptPathSchnorrSignature-D2t1yACC.cjs → verifyScriptPathSchnorrSignature-CahYx5Td.cjs} +2 -2
- package/dist/{verifyScriptPathSchnorrSignature-D2t1yACC.cjs.map → verifyScriptPathSchnorrSignature-CahYx5Td.cjs.map} +1 -1
- package/dist/{verifyScriptPathSchnorrSignature-B3-VkvnK.js → verifyScriptPathSchnorrSignature-owu3BfyT.js} +2 -2
- package/dist/{verifyScriptPathSchnorrSignature-B3-VkvnK.js.map → verifyScriptPathSchnorrSignature-owu3BfyT.js.map} +1 -1
- package/package.json +3 -3
- package/dist/BTCVaultRegistry.abi-BmHpMUWD.js.map +0 -1
- package/dist/BTCVaultRegistry.abi-DffWFdpA.cjs +0 -2
- package/dist/BTCVaultRegistry.abi-DffWFdpA.cjs.map +0 -1
- package/dist/buildAndBroadcastReclaim-Da8rD5Z7.cjs +0 -2
- package/dist/buildAndBroadcastReclaim-Da8rD5Z7.cjs.map +0 -1
- package/dist/buildAndBroadcastReclaim-R0HNpLMD.js.map +0 -1
- package/dist/challengeAssert-Cp_GeRg8.js +0 -64
- package/dist/challengeAssert-Cp_GeRg8.js.map +0 -1
- package/dist/challengeAssert-Z7_YULBb.cjs +0 -2
- package/dist/challengeAssert-Z7_YULBb.cjs.map +0 -1
- package/dist/constants-BeYquVd-.js +0 -36
- package/dist/constants-BeYquVd-.js.map +0 -1
- package/dist/constants-BwCg5K6R.cjs +0 -2
- package/dist/constants-BwCg5K6R.cjs.map +0 -1
- package/dist/noPayout-B-vGXJ-V.js +0 -361
- package/dist/noPayout-B-vGXJ-V.js.map +0 -1
- package/dist/noPayout-DOHak0ui.cjs +0 -2
- package/dist/noPayout-DOHak0ui.cjs.map +0 -1
- package/dist/pegin-registration-client-C-abxMWq.cjs +0 -2
- package/dist/pegin-registration-client-C-abxMWq.cjs.map +0 -1
- package/dist/pegin-registration-client-kdz4fT5_.js.map +0 -1
- package/dist/peginState-BU2ONFXF.js +0 -68
- package/dist/peginState-BU2ONFXF.js.map +0 -1
- package/dist/peginState-DUv10EJR.cjs +0 -2
- package/dist/peginState-DUv10EJR.cjs.map +0 -1
- package/dist/types-Bda75Od0.cjs.map +0 -1
- package/dist/types-C5jj3Cc-.js.map +0 -1
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
import { Transaction as b, Psbt as _, payments as j } from "bitcoinjs-lib";
|
|
2
|
+
import { Buffer as f } from "buffer";
|
|
3
|
+
import { loadTbvWasm as J, tapInternalPubkey as N, getAssertNoPayoutScriptInfo as Z, getChallengeAssertScriptInfo as tt } from "./tbv/core/wasm/index.js";
|
|
4
|
+
import { u as C, T as A, s as g, d as k, h as m, S as B, p as et, k as ot, l as Q } from "./bitcoin-C-TuHb-v.js";
|
|
5
|
+
import { n as rt, l as nt, d as st, P as E, m as it } from "./verifyScriptPathSchnorrSignature-owu3BfyT.js";
|
|
6
|
+
import { R as q, a as X, N as M, b as D, c as G, d as at, A as ut, C as Y, e as H, f as ct, g as lt, h as ht, i as pt } from "./constants-CvQZuxKv.js";
|
|
7
|
+
import { D as z } from "./fundPeginTransaction-CwhRbCQC.js";
|
|
8
|
+
import { X as F } from "./validation-OSC0xTHB.js";
|
|
9
|
+
const dt = (1n << 64n) - 1n;
|
|
10
|
+
function ft(e, n) {
|
|
11
|
+
if (!Array.isArray(e))
|
|
12
|
+
throw new Error(
|
|
13
|
+
`${n} must be an array of positive bigints (got ${typeof e}).`
|
|
14
|
+
);
|
|
15
|
+
if (e.length === 0)
|
|
16
|
+
throw new Error(`${n} must not be empty.`);
|
|
17
|
+
return e.forEach((t, i) => {
|
|
18
|
+
if (typeof t != "bigint")
|
|
19
|
+
throw new Error(
|
|
20
|
+
`${n}[${i}] must be a bigint (got ${typeof t}); refusing to feed it into satoshi math.`
|
|
21
|
+
);
|
|
22
|
+
if (t <= 0n)
|
|
23
|
+
throw new Error(`${n}[${i}] must be > 0 (got ${t}).`);
|
|
24
|
+
if (t > dt)
|
|
25
|
+
throw new Error(
|
|
26
|
+
`${n}[${i}] must fit in a u64 (got ${t}); refusing to feed it into satoshi math.`
|
|
27
|
+
);
|
|
28
|
+
}), e;
|
|
29
|
+
}
|
|
30
|
+
async function Ct(e) {
|
|
31
|
+
const { WasmPrePeginTx: n } = await J(), { prePeginParams: t, fundedPrePeginTxHex: i, htlcVout: a, refundFee: c, hashlock: s } = e, r = rt(
|
|
32
|
+
t.authAnchorHash
|
|
33
|
+
), o = new n(
|
|
34
|
+
t.vaultCoreVersion,
|
|
35
|
+
t.depositorPubkey,
|
|
36
|
+
t.vaultProviderPubkey,
|
|
37
|
+
t.vaultKeeperPubkeys,
|
|
38
|
+
t.universalChallengerPubkeys,
|
|
39
|
+
[...t.hashlocks],
|
|
40
|
+
new BigUint64Array(
|
|
41
|
+
ft(t.pegInAmounts, "pegInAmounts")
|
|
42
|
+
),
|
|
43
|
+
t.timelockRefund,
|
|
44
|
+
t.feeRate,
|
|
45
|
+
t.minPeginFeeRate,
|
|
46
|
+
t.numLocalChallengers,
|
|
47
|
+
t.councilQuorum,
|
|
48
|
+
t.councilSize,
|
|
49
|
+
t.network,
|
|
50
|
+
r
|
|
51
|
+
);
|
|
52
|
+
let u = null;
|
|
53
|
+
try {
|
|
54
|
+
const p = o.getHtlcScriptPubKey(a).toLowerCase(), l = nt(t, s), d = l.scriptPubKey.toString("hex");
|
|
55
|
+
if (p !== d)
|
|
56
|
+
throw new Error(
|
|
57
|
+
`WASM HTLC scriptPubKey ${p} does not match the independently derived scriptPubKey ${d}.`
|
|
58
|
+
);
|
|
59
|
+
const x = o.getHtlcValue(a);
|
|
60
|
+
u = o.fromFundedTransaction(i);
|
|
61
|
+
const w = u.buildRefundTx(c, a), T = i.startsWith("0x") ? i.slice(2) : i, v = b.fromHex(T), P = v.outs[a];
|
|
62
|
+
if (!P)
|
|
63
|
+
throw new Error(
|
|
64
|
+
`HTLC output at vout ${a} not found in funded Pre-PegIn tx (tx has ${v.outs.length} outputs)`
|
|
65
|
+
);
|
|
66
|
+
const I = C(
|
|
67
|
+
new Uint8Array(P.script)
|
|
68
|
+
).toLowerCase();
|
|
69
|
+
if (I !== d)
|
|
70
|
+
throw new Error(
|
|
71
|
+
`HTLC scriptPubKey mismatch at vout ${a}: reconstructed template expects ${d}, funded tx carries ${I}. Refund refused — the (hashlocks, pegInAmounts) vector does not match the on-chain commitment.`
|
|
72
|
+
);
|
|
73
|
+
const $ = BigInt(P.value);
|
|
74
|
+
if ($ !== x)
|
|
75
|
+
throw new Error(
|
|
76
|
+
`HTLC value mismatch at vout ${a}: reconstructed template expects ${x} sat, funded tx carries ${$} sat. Refund refused — the pegInAmounts vector does not match the on-chain commitment.`
|
|
77
|
+
);
|
|
78
|
+
const h = b.fromHex(w);
|
|
79
|
+
if (h.version !== q)
|
|
80
|
+
throw new Error(
|
|
81
|
+
`Refund transaction version ${h.version} does not match protocol version ${q}.`
|
|
82
|
+
);
|
|
83
|
+
if (h.locktime !== X)
|
|
84
|
+
throw new Error(
|
|
85
|
+
`Refund transaction locktime ${h.locktime} does not match protocol locktime ${X}.`
|
|
86
|
+
);
|
|
87
|
+
if (h.ins.length !== 1)
|
|
88
|
+
throw new Error(
|
|
89
|
+
`Refund transaction must have exactly 1 input, got ${h.ins.length}`
|
|
90
|
+
);
|
|
91
|
+
const y = h.ins[0], O = v.getId(), L = C(
|
|
92
|
+
new Uint8Array(y.hash).slice().reverse()
|
|
93
|
+
);
|
|
94
|
+
if (L !== O)
|
|
95
|
+
throw new Error(
|
|
96
|
+
`Refund input does not reference the Pre-PegIn transaction. Expected ${O}, got ${L}`
|
|
97
|
+
);
|
|
98
|
+
if (y.index !== a)
|
|
99
|
+
throw new Error(
|
|
100
|
+
`Refund input index ${y.index} does not match expected htlcVout ${a}`
|
|
101
|
+
);
|
|
102
|
+
if (y.sequence !== t.timelockRefund)
|
|
103
|
+
throw new Error(
|
|
104
|
+
`Refund input sequence ${y.sequence} does not match timelockRefund ${t.timelockRefund}.`
|
|
105
|
+
);
|
|
106
|
+
const S = new _();
|
|
107
|
+
if (S.setVersion(h.version), S.setLocktime(h.locktime), S.addInput({
|
|
108
|
+
hash: y.hash,
|
|
109
|
+
index: y.index,
|
|
110
|
+
sequence: y.sequence,
|
|
111
|
+
witnessUtxo: {
|
|
112
|
+
script: P.script,
|
|
113
|
+
value: P.value
|
|
114
|
+
},
|
|
115
|
+
tapLeafScript: [
|
|
116
|
+
{
|
|
117
|
+
leafVersion: A,
|
|
118
|
+
script: l.refundScript,
|
|
119
|
+
controlBlock: l.refundControlBlock
|
|
120
|
+
}
|
|
121
|
+
],
|
|
122
|
+
tapInternalKey: f.from(N),
|
|
123
|
+
tapMerkleRoot: l.tapMerkleRoot
|
|
124
|
+
}), h.outs.length !== 1)
|
|
125
|
+
throw new Error(
|
|
126
|
+
`Refund transaction must have exactly 1 output, got ${h.outs.length}`
|
|
127
|
+
);
|
|
128
|
+
const R = h.outs[0], U = g(
|
|
129
|
+
k(t.depositorPubkey)
|
|
130
|
+
).toLowerCase(), V = C(
|
|
131
|
+
new Uint8Array(R.script)
|
|
132
|
+
).toLowerCase();
|
|
133
|
+
if (V !== U)
|
|
134
|
+
throw new Error(
|
|
135
|
+
`Refund output scriptPubKey ${V} does not match the depositor's BIP-86 address ${U}. Refund refused — the reclaimed funds would not return to the depositor.`
|
|
136
|
+
);
|
|
137
|
+
const K = $ - c;
|
|
138
|
+
if (BigInt(R.value) !== K)
|
|
139
|
+
throw new Error(
|
|
140
|
+
`Refund output value ${BigInt(R.value)} sat does not equal the HTLC value ${$} sat minus the requested fee ${c} sat (expected ${K} sat). Refund refused — the reclaimed amount would be burned as excess fee.`
|
|
141
|
+
);
|
|
142
|
+
return S.addOutput({
|
|
143
|
+
script: R.script,
|
|
144
|
+
value: R.value
|
|
145
|
+
}), { psbtHex: S.toHex() };
|
|
146
|
+
} finally {
|
|
147
|
+
u == null || u.free(), o.free();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const gt = 2, wt = 4294967293, mt = 214, $t = 299, Et = 4;
|
|
151
|
+
function xt(e) {
|
|
152
|
+
if (!Number.isInteger(e) || e < 1)
|
|
153
|
+
throw new Error(
|
|
154
|
+
`Reclaim input count must be a positive integer, got ${e}.`
|
|
155
|
+
);
|
|
156
|
+
return Math.ceil(
|
|
157
|
+
(mt + $t * e) / Et
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
function _t(e, n) {
|
|
161
|
+
if (!Number.isFinite(e) || e <= 0)
|
|
162
|
+
throw new Error(
|
|
163
|
+
`Reclaim fee rate must be a positive number, got ${e}.`
|
|
164
|
+
);
|
|
165
|
+
return BigInt(Math.ceil(e * xt(n)));
|
|
166
|
+
}
|
|
167
|
+
function Ht(e) {
|
|
168
|
+
const { depositorPubkey: n, inputs: t, feeSats: i } = e;
|
|
169
|
+
if (t.length === 0)
|
|
170
|
+
throw new Error("Reclaim requires at least one input; got none.");
|
|
171
|
+
if (i <= 0n)
|
|
172
|
+
throw new Error(
|
|
173
|
+
`Reclaim fee must be positive, got ${i} sat. Refusing to build a transaction that would not relay.`
|
|
174
|
+
);
|
|
175
|
+
const a = st(n), c = C(
|
|
176
|
+
new Uint8Array(a.scriptPubKey)
|
|
177
|
+
).toLowerCase(), s = new _();
|
|
178
|
+
s.setVersion(gt), s.setLocktime(0);
|
|
179
|
+
let r = 0n;
|
|
180
|
+
const o = /* @__PURE__ */ new Set();
|
|
181
|
+
if (t.forEach((l, d) => {
|
|
182
|
+
const x = b.fromHex(
|
|
183
|
+
g(l.depositorSignedPeginTxHex)
|
|
184
|
+
), w = x.getId(), T = x.outs[E];
|
|
185
|
+
if (!T)
|
|
186
|
+
throw new Error(
|
|
187
|
+
`PegIn ${w} has no output at vout ${E} (tx has ${x.outs.length}); there is no depositor-claim reserve to reclaim.`
|
|
188
|
+
);
|
|
189
|
+
const v = g(l.observed.txid).toLowerCase();
|
|
190
|
+
if (v !== w)
|
|
191
|
+
throw new Error(
|
|
192
|
+
`Input ${d}: the observation is of ${v}, but this input spends PegIn ${w}. Reclaim refused — the reserve that was looked up is not the one being swept.`
|
|
193
|
+
);
|
|
194
|
+
if (l.observed.vout !== E)
|
|
195
|
+
throw new Error(
|
|
196
|
+
`Input ${d}: the observation is of vout ${l.observed.vout}, but the depositor-claim reserve is at vout ${E}. Reclaim refused.`
|
|
197
|
+
);
|
|
198
|
+
const P = C(
|
|
199
|
+
new Uint8Array(T.script)
|
|
200
|
+
).toLowerCase();
|
|
201
|
+
if (P !== c)
|
|
202
|
+
throw new Error(
|
|
203
|
+
`Input ${d}: PegIn ${w} vout ${E} pays ${P}, but the connected wallet's depositor-claim script is ${c}. Reclaim refused — this reserve belongs to a different wallet.`
|
|
204
|
+
);
|
|
205
|
+
const I = g(
|
|
206
|
+
l.observed.scriptPubKey
|
|
207
|
+
).toLowerCase();
|
|
208
|
+
if (I !== c)
|
|
209
|
+
throw new Error(
|
|
210
|
+
`Input ${d}: the observed UTXO ${w}:${E} pays ${I}, expected ${c}. Reclaim refused — chain state disagrees with the contract's PegIn.`
|
|
211
|
+
);
|
|
212
|
+
const $ = BigInt(T.value);
|
|
213
|
+
if ($ !== l.observed.value)
|
|
214
|
+
throw new Error(
|
|
215
|
+
`Input ${d}: PegIn ${w} vout ${E} carries ${$} sat, but the observed UTXO carries ${l.observed.value} sat. Reclaim refused.`
|
|
216
|
+
);
|
|
217
|
+
if ($ !== l.expectedValue)
|
|
218
|
+
throw new Error(
|
|
219
|
+
`Input ${d}: PegIn ${w} vout ${E} carries ${$} sat, but this vault's parameters compute a depositor-claim value of ${l.expectedValue} sat. Reclaim refused.`
|
|
220
|
+
);
|
|
221
|
+
const h = `${w}:${E}`;
|
|
222
|
+
if (o.has(h))
|
|
223
|
+
throw new Error(
|
|
224
|
+
`Input ${d} repeats outpoint ${h}, which is already being swept by an earlier input. Reclaim refused.`
|
|
225
|
+
);
|
|
226
|
+
o.add(h), r += $, s.addInput({
|
|
227
|
+
hash: w,
|
|
228
|
+
index: E,
|
|
229
|
+
sequence: wt,
|
|
230
|
+
witnessUtxo: { script: T.script, value: T.value },
|
|
231
|
+
tapLeafScript: [
|
|
232
|
+
{
|
|
233
|
+
leafVersion: A,
|
|
234
|
+
script: a.leafScript,
|
|
235
|
+
controlBlock: a.controlBlock
|
|
236
|
+
}
|
|
237
|
+
],
|
|
238
|
+
tapInternalKey: a.internalKey
|
|
239
|
+
});
|
|
240
|
+
}), i >= r)
|
|
241
|
+
throw new Error(
|
|
242
|
+
`Reclaim fee ${i} sat is not less than the swept total ${r} sat. Refusing to build a transaction with no output.`
|
|
243
|
+
);
|
|
244
|
+
const u = r - i;
|
|
245
|
+
if (u <= z)
|
|
246
|
+
throw new Error(
|
|
247
|
+
`Reclaim output ${u} sat is at or below the dust threshold ${z} sat. The reserve is not at risk — it stays where it is until fee rates fall.`
|
|
248
|
+
);
|
|
249
|
+
const p = g(
|
|
250
|
+
k(n)
|
|
251
|
+
);
|
|
252
|
+
return s.addOutput({
|
|
253
|
+
script: f.from(m(p)),
|
|
254
|
+
value: Number(u)
|
|
255
|
+
}), { psbtHex: s.toHex(), outputValue: u, totalInputValue: r };
|
|
256
|
+
}
|
|
257
|
+
function Nt(e) {
|
|
258
|
+
const { requestedPsbtHex: n, signaturesHex: t, signerXOnlyPubkeyHex: i } = e, a = g(i);
|
|
259
|
+
if (a.length !== F)
|
|
260
|
+
throw new Error(
|
|
261
|
+
`Signer x-only pubkey must be ${F} hex chars (32 bytes), got ${a.length}.`
|
|
262
|
+
);
|
|
263
|
+
const c = f.from(m(a)), s = _.fromHex(n);
|
|
264
|
+
if (t.length !== s.data.inputs.length)
|
|
265
|
+
throw new Error(
|
|
266
|
+
`Cannot finalize: got ${t.length} signature(s) for ${s.data.inputs.length} input(s). Every input must be signed — refusing to broadcast a partially signed transaction.`
|
|
267
|
+
);
|
|
268
|
+
return s.data.inputs.forEach((r, o) => {
|
|
269
|
+
if (r.tapKeySig)
|
|
270
|
+
throw new Error(
|
|
271
|
+
`Cannot finalize: input ${o} of the locally built PSBT carries a key-path signature. These outputs are script-path only.`
|
|
272
|
+
);
|
|
273
|
+
const u = r.tapLeafScript;
|
|
274
|
+
if (!u || u.length !== 1)
|
|
275
|
+
throw new Error(
|
|
276
|
+
`Cannot finalize: input ${o} must have exactly one tapLeafScript, got ${(u == null ? void 0 : u.length) ?? 0}.`
|
|
277
|
+
);
|
|
278
|
+
const p = u[0];
|
|
279
|
+
if (p.leafVersion !== A)
|
|
280
|
+
throw new Error(
|
|
281
|
+
`Cannot finalize: input ${o} tapLeafScript has leaf version 0x${p.leafVersion.toString(16)}, expected 0x${A.toString(16)}.`
|
|
282
|
+
);
|
|
283
|
+
const l = g(t[o]);
|
|
284
|
+
if (l.length !== B)
|
|
285
|
+
throw new Error(
|
|
286
|
+
`Signature for input ${o} must be ${B} hex chars (64 bytes), got ${l.length}.`
|
|
287
|
+
);
|
|
288
|
+
s.updateInput(o, {
|
|
289
|
+
tapScriptSig: [
|
|
290
|
+
{
|
|
291
|
+
pubkey: c,
|
|
292
|
+
leafHash: it(p.leafVersion, p.script),
|
|
293
|
+
signature: f.from(m(l))
|
|
294
|
+
}
|
|
295
|
+
]
|
|
296
|
+
});
|
|
297
|
+
}), s.finalizeAllInputs(), s.extractTransaction().toHex();
|
|
298
|
+
}
|
|
299
|
+
const W = 65535;
|
|
300
|
+
async function kt(e) {
|
|
301
|
+
const n = g(e.noPayoutTxHex), t = b.fromHex(n), { noPayoutScript: i, noPayoutControlBlock: a } = await Z(
|
|
302
|
+
e.connectorParams,
|
|
303
|
+
e.challengerPubkey
|
|
304
|
+
), c = m(i), s = m(a), r = new _();
|
|
305
|
+
r.setVersion(t.version), r.setLocktime(t.locktime);
|
|
306
|
+
for (let o = 0; o < t.ins.length; o++) {
|
|
307
|
+
const u = t.ins[o], p = e.prevouts[o];
|
|
308
|
+
if (!p)
|
|
309
|
+
throw new Error(`Missing prevout data for input ${o}`);
|
|
310
|
+
const l = {
|
|
311
|
+
hash: u.hash,
|
|
312
|
+
index: u.index,
|
|
313
|
+
sequence: u.sequence,
|
|
314
|
+
witnessUtxo: {
|
|
315
|
+
script: f.from(m(g(p.script_pubkey))),
|
|
316
|
+
value: p.value
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
o === 0 && (l.tapLeafScript = [
|
|
320
|
+
{
|
|
321
|
+
leafVersion: A,
|
|
322
|
+
script: f.from(c),
|
|
323
|
+
controlBlock: f.from(s)
|
|
324
|
+
}
|
|
325
|
+
], l.tapInternalKey = f.from(N)), r.addInput(l);
|
|
326
|
+
}
|
|
327
|
+
for (const o of t.outs)
|
|
328
|
+
r.addOutput({
|
|
329
|
+
script: o.script,
|
|
330
|
+
value: o.value
|
|
331
|
+
});
|
|
332
|
+
return r.toHex();
|
|
333
|
+
}
|
|
334
|
+
function Ot(e, n, t) {
|
|
335
|
+
const i = b.fromHex(g(e));
|
|
336
|
+
if (i.outs.length !== 1)
|
|
337
|
+
throw new Error(
|
|
338
|
+
`NoPayout transaction must have exactly 1 output, got ${i.outs.length}`
|
|
339
|
+
);
|
|
340
|
+
const a = m(et(n)), { output: c } = j.p2tr({
|
|
341
|
+
internalPubkey: f.from(a),
|
|
342
|
+
network: ot(t)
|
|
343
|
+
});
|
|
344
|
+
if (!c)
|
|
345
|
+
throw new Error(
|
|
346
|
+
"Failed to derive challenger BIP-86 P2TR scriptPubKey for NoPayout output validation"
|
|
347
|
+
);
|
|
348
|
+
if (!i.outs[0].script.equals(c))
|
|
349
|
+
throw new Error(
|
|
350
|
+
"NoPayout transaction does not pay to the expected challenger BIP-86 P2TR address"
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
function Lt(e) {
|
|
354
|
+
const { noPayoutTx: n, timelockChallengeAssert: t } = e;
|
|
355
|
+
if (!Number.isInteger(t) || t < 1 || t > W)
|
|
356
|
+
throw new Error(
|
|
357
|
+
`timelockChallengeAssert must be an integer in 1..${W}, got ${t}`
|
|
358
|
+
);
|
|
359
|
+
if (n.version !== M)
|
|
360
|
+
throw new Error(
|
|
361
|
+
`NoPayout version must be ${M}, got ${n.version}`
|
|
362
|
+
);
|
|
363
|
+
if (n.locktime !== D)
|
|
364
|
+
throw new Error(
|
|
365
|
+
`NoPayout locktime must be ${D}, got ${n.locktime}`
|
|
366
|
+
);
|
|
367
|
+
if (n.ins.length !== G)
|
|
368
|
+
throw new Error(
|
|
369
|
+
`NoPayout must have exactly ${G} inputs, got ${n.ins.length}`
|
|
370
|
+
);
|
|
371
|
+
[
|
|
372
|
+
{
|
|
373
|
+
label: "Assert",
|
|
374
|
+
txid: e.assertTxid,
|
|
375
|
+
vout: ut,
|
|
376
|
+
sequence: at
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
label: "ChallengeAssertX",
|
|
380
|
+
txid: e.challengeAssertXTxid,
|
|
381
|
+
vout: Y,
|
|
382
|
+
sequence: t
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
label: "ChallengeAssertY",
|
|
386
|
+
txid: e.challengeAssertYTxid,
|
|
387
|
+
vout: Y,
|
|
388
|
+
sequence: t
|
|
389
|
+
}
|
|
390
|
+
].forEach((s, r) => {
|
|
391
|
+
const o = n.ins[r], u = Q(o);
|
|
392
|
+
if (u !== s.txid || o.index !== s.vout)
|
|
393
|
+
throw new Error(
|
|
394
|
+
`NoPayout input ${r} must spend ${s.label} ${s.txid}:${s.vout}, got ${u}:${o.index}`
|
|
395
|
+
);
|
|
396
|
+
if (o.sequence !== s.sequence)
|
|
397
|
+
throw new Error(
|
|
398
|
+
`NoPayout input ${r} (${s.label}) sequence must be ${s.sequence}, got ${o.sequence}`
|
|
399
|
+
);
|
|
400
|
+
});
|
|
401
|
+
const a = e.prevoutValues.reduce((s, r) => s + r, 0), c = n.outs.reduce((s, r) => s + r.value, 0);
|
|
402
|
+
if (c > a)
|
|
403
|
+
throw new Error(
|
|
404
|
+
`NoPayout output value ${c} exceeds its inputs (${a} sats)`
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
async function Ut(e) {
|
|
408
|
+
const n = b.fromHex(
|
|
409
|
+
g(e.challengeAssertTxHex)
|
|
410
|
+
), t = b.fromHex(g(e.assertTxHex)), i = t.getId();
|
|
411
|
+
if (e.connectorParamsPerInput.length !== n.ins.length)
|
|
412
|
+
throw new Error(
|
|
413
|
+
`Expected ${n.ins.length} connector params, got ${e.connectorParamsPerInput.length}`
|
|
414
|
+
);
|
|
415
|
+
const a = /* @__PURE__ */ new Set();
|
|
416
|
+
for (let r = 0; r < n.ins.length; r++) {
|
|
417
|
+
const o = n.ins[r], u = Q(o);
|
|
418
|
+
if (u !== i)
|
|
419
|
+
throw new Error(
|
|
420
|
+
`ChallengeAssert input ${r} must spend an Assert output. Expected txid ${i}, got ${u}`
|
|
421
|
+
);
|
|
422
|
+
if (!t.outs[o.index])
|
|
423
|
+
throw new Error(
|
|
424
|
+
`Assert output ${o.index} not found for ChallengeAssert input ${r} (txid: ${i})`
|
|
425
|
+
);
|
|
426
|
+
if (a.has(o.index))
|
|
427
|
+
throw new Error(
|
|
428
|
+
`ChallengeAssert input ${r} duplicates Assert output index ${o.index}`
|
|
429
|
+
);
|
|
430
|
+
a.add(o.index);
|
|
431
|
+
}
|
|
432
|
+
const c = await Promise.all(
|
|
433
|
+
e.connectorParamsPerInput.map((r) => tt(r))
|
|
434
|
+
), s = new _();
|
|
435
|
+
s.setVersion(n.version), s.setLocktime(n.locktime);
|
|
436
|
+
for (let r = 0; r < n.ins.length; r++) {
|
|
437
|
+
const o = n.ins[r], u = t.outs[o.index], { script: p, controlBlock: l } = c[r], d = m(p), x = m(l);
|
|
438
|
+
s.addInput({
|
|
439
|
+
hash: o.hash,
|
|
440
|
+
index: o.index,
|
|
441
|
+
sequence: o.sequence,
|
|
442
|
+
witnessUtxo: {
|
|
443
|
+
script: u.script,
|
|
444
|
+
value: u.value
|
|
445
|
+
},
|
|
446
|
+
tapLeafScript: [
|
|
447
|
+
{
|
|
448
|
+
leafVersion: A,
|
|
449
|
+
script: f.from(d),
|
|
450
|
+
controlBlock: f.from(x)
|
|
451
|
+
}
|
|
452
|
+
],
|
|
453
|
+
tapInternalKey: f.from(N)
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
for (const r of n.outs)
|
|
457
|
+
s.addOutput({
|
|
458
|
+
script: r.script,
|
|
459
|
+
value: r.value
|
|
460
|
+
});
|
|
461
|
+
return s.toHex();
|
|
462
|
+
}
|
|
463
|
+
function Vt(e) {
|
|
464
|
+
const n = Pt(e).getId(), t = e.challengeAssertTx.getId();
|
|
465
|
+
if (t !== n)
|
|
466
|
+
throw new Error(
|
|
467
|
+
`ChallengeAssert${e.half} (challenger ${e.challengerPubkey}) is not the canonical transaction for this Assert: expected txid ${n}, got ${t}`
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
function Pt(e) {
|
|
471
|
+
const { assertTx: n, half: t, challengerIndex: i, challengerCount: a } = e;
|
|
472
|
+
if (!Number.isInteger(i) || i < 0 || i >= a)
|
|
473
|
+
throw new Error(
|
|
474
|
+
`ChallengeAssert${t} challenger index ${i} is outside 0..${a - 1}`
|
|
475
|
+
);
|
|
476
|
+
const c = pt + (t === "Y" ? a : 0) + i, s = n.outs[c];
|
|
477
|
+
if (!s)
|
|
478
|
+
throw new Error(
|
|
479
|
+
`Assert has no output ${c} for the ChallengeAssert${t} of challenger index ${i}`
|
|
480
|
+
);
|
|
481
|
+
const r = s.value - H;
|
|
482
|
+
if (r < 0)
|
|
483
|
+
throw new Error(
|
|
484
|
+
`Assert output ${c} (${s.value} sats) cannot fund the ${H}-sat ChallengeAssert${t} anchor`
|
|
485
|
+
);
|
|
486
|
+
const o = new b();
|
|
487
|
+
return o.version = ct, o.locktime = lt, o.addInput(n.getHash(), c, ht), o.addOutput(
|
|
488
|
+
f.from(m(e.outputConnectorScriptPubKey)),
|
|
489
|
+
r
|
|
490
|
+
), o.addOutput(
|
|
491
|
+
f.from(
|
|
492
|
+
m(k(e.challengerPubkey))
|
|
493
|
+
),
|
|
494
|
+
H
|
|
495
|
+
), o;
|
|
496
|
+
}
|
|
497
|
+
export {
|
|
498
|
+
Ht as a,
|
|
499
|
+
Ct as b,
|
|
500
|
+
kt as c,
|
|
501
|
+
Ut as d,
|
|
502
|
+
_t as e,
|
|
503
|
+
Nt as f,
|
|
504
|
+
Ot as g,
|
|
505
|
+
Vt as h,
|
|
506
|
+
Lt as i,
|
|
507
|
+
xt as r
|
|
508
|
+
};
|
|
509
|
+
//# sourceMappingURL=challengeAssert-B2otuf7y.js.map
|