@babylonlabs-io/ts-sdk 0.70.1 → 0.71.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/PeginManager-Bn8FxM35.cjs +2 -0
- package/dist/PeginManager-Bn8FxM35.cjs.map +1 -0
- package/dist/{PeginManager-BNtg6jgY.js → PeginManager-C3ojNTlv.js} +12 -12
- package/dist/PeginManager-C3ojNTlv.js.map +1 -0
- package/dist/abortSignals-BPpAUL1Z.js +18 -0
- package/dist/abortSignals-BPpAUL1Z.js.map +1 -0
- package/dist/abortSignals-msbmbqFe.cjs +2 -0
- package/dist/abortSignals-msbmbqFe.cjs.map +1 -0
- package/dist/{bitcoin-Ch_jxnDa.js → bitcoin-C-TuHb-v.js} +21 -22
- package/dist/bitcoin-C-TuHb-v.js.map +1 -0
- package/dist/bitcoin-D-O2GjbC.cjs +2 -0
- package/dist/bitcoin-D-O2GjbC.cjs.map +1 -0
- package/dist/{buildAndBroadcastReclaim-kBHwOL02.js → buildAndBroadcastReclaim-YvWDRAN8.js} +493 -489
- package/dist/{buildAndBroadcastReclaim-kBHwOL02.js.map → buildAndBroadcastReclaim-YvWDRAN8.js.map} +1 -1
- package/dist/buildAndBroadcastReclaim-zfjDI5__.cjs +2 -0
- package/dist/{buildAndBroadcastReclaim-iNJfx0ZG.cjs.map → buildAndBroadcastReclaim-zfjDI5__.cjs.map} +1 -1
- package/dist/{challengeAssert-BNQ8sToz.js → challengeAssert-Cp_GeRg8.js} +3 -3
- package/dist/challengeAssert-Cp_GeRg8.js.map +1 -0
- package/dist/challengeAssert-Z7_YULBb.cjs +2 -0
- package/dist/challengeAssert-Z7_YULBb.cjs.map +1 -0
- package/dist/constants-Bh38W9mq.cjs +2 -0
- package/dist/constants-Bh38W9mq.cjs.map +1 -0
- package/dist/constants-CPzppOdq.js +17 -0
- package/dist/constants-CPzppOdq.js.map +1 -0
- package/dist/index-Cs7_Evtk.cjs +2 -0
- package/dist/index-Cs7_Evtk.cjs.map +1 -0
- package/dist/index-LgmJhdEN.js +505 -0
- package/dist/index-LgmJhdEN.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +244 -239
- package/dist/index.js.map +1 -1
- package/dist/{mempoolApi-CfOFmov6.js → mempoolApi-CKD_IbrM.js} +59 -59
- package/dist/mempoolApi-CKD_IbrM.js.map +1 -0
- package/dist/mempoolApi-DronQ5xn.cjs +2 -0
- package/dist/mempoolApi-DronQ5xn.cjs.map +1 -0
- package/dist/noPayout-DpGRzidi.js +353 -0
- package/dist/noPayout-DpGRzidi.js.map +1 -0
- package/dist/noPayout-zEifyecV.cjs +2 -0
- package/dist/noPayout-zEifyecV.cjs.map +1 -0
- package/dist/{onChainBtcPubkey-C_a2L3kL.cjs → onChainBtcPubkey-B5ZvWCCF.cjs} +2 -2
- package/dist/{onChainBtcPubkey-C_a2L3kL.cjs.map → onChainBtcPubkey-B5ZvWCCF.cjs.map} +1 -1
- package/dist/{onChainBtcPubkey-BAHZyKQL.js → onChainBtcPubkey-DATNfAAl.js} +2 -2
- package/dist/{onChainBtcPubkey-BAHZyKQL.js.map → onChainBtcPubkey-DATNfAAl.js.map} +1 -1
- package/dist/parseFundingOutpoints-BkgGihaY.cjs +2 -0
- package/dist/parseFundingOutpoints-BkgGihaY.cjs.map +1 -0
- package/dist/{parseFundingOutpoints-CO-f6IHK.js → parseFundingOutpoints-DlINgQ3X.js} +30 -29
- package/dist/parseFundingOutpoints-DlINgQ3X.js.map +1 -0
- package/dist/primeVpAuth-Cjq6qFHq.cjs +2 -0
- package/dist/primeVpAuth-Cjq6qFHq.cjs.map +1 -0
- package/dist/{batchPoll-BM4iQ9jT.js → primeVpAuth-tLRjdHwZ.js} +311 -803
- package/dist/primeVpAuth-tLRjdHwZ.js.map +1 -0
- package/dist/{reservation-CBAvoF3U.js → reservation-Cj9F0rP9.js} +2 -2
- package/dist/{reservation-CBAvoF3U.js.map → reservation-Cj9F0rP9.js.map} +1 -1
- package/dist/{reservation-CDbInVw0.cjs → reservation-Dr2HLCxx.cjs} +2 -2
- package/dist/{reservation-CDbInVw0.cjs.map → reservation-Dr2HLCxx.cjs.map} +1 -1
- package/dist/{signPsbtsWithFallback-X6ivsbh7.js → signPsbtsWithFallback-CCFTzE0o.js} +19 -20
- package/dist/{signPsbtsWithFallback-X6ivsbh7.js.map → signPsbtsWithFallback-CCFTzE0o.js.map} +1 -1
- package/dist/signPsbtsWithFallback-CrkvpSJz.cjs +2 -0
- package/dist/{signPsbtsWithFallback-Bo1PJX90.cjs.map → signPsbtsWithFallback-CrkvpSJz.cjs.map} +1 -1
- package/dist/signing-BJ3X66b-.cjs +2 -0
- package/dist/signing-BJ3X66b-.cjs.map +1 -0
- package/dist/signing-Cm-McVR2.js +22 -0
- package/dist/signing-Cm-McVR2.js.map +1 -0
- package/dist/tbv/core/clients/eth/types.d.ts +0 -2
- 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 +36 -35
- package/dist/tbv/core/clients/index.js.map +1 -1
- package/dist/tbv/core/clients/mempool/mempoolApi.d.ts +9 -1
- package/dist/tbv/core/clients/mempool/mempoolApi.d.ts.map +1 -1
- package/dist/tbv/core/clients/vault-provider/auth/serverIdentity.d.ts.map +1 -1
- package/dist/tbv/core/clients/vault-provider/auth/verifyDepositorCwt.d.ts.map +1 -1
- package/dist/tbv/core/clients/vault-provider/status/index.cjs +2 -0
- package/dist/tbv/core/clients/vault-provider/status/index.cjs.map +1 -0
- package/dist/tbv/core/clients/vault-provider/status/index.d.ts +18 -0
- package/dist/tbv/core/clients/vault-provider/status/index.d.ts.map +1 -0
- package/dist/tbv/core/clients/vault-provider/status/index.js +17 -0
- package/dist/tbv/core/clients/vault-provider/status/index.js.map +1 -0
- package/dist/tbv/core/clients/vault-provider/validators.d.ts.map +1 -1
- package/dist/tbv/core/deposit-terms/rebuildDepositTermsCore.d.ts +1 -1
- 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 +237 -232
- 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.d.ts +4 -2
- package/dist/tbv/core/primitives/index.d.ts.map +1 -1
- package/dist/tbv/core/primitives/index.js +26 -25
- package/dist/tbv/core/primitives/psbt/__tests__/finalizeScriptPathWithSignatures.test.d.ts +11 -0
- package/dist/tbv/core/primitives/psbt/__tests__/finalizeScriptPathWithSignatures.test.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts +1 -1
- package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/challengeAssert.d.ts +1 -1
- package/dist/tbv/core/primitives/psbt/challengeAssert.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/finalizeScriptPathWithSignatures.d.ts +52 -0
- package/dist/tbv/core/primitives/psbt/finalizeScriptPathWithSignatures.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/noPayout.d.ts +1 -1
- package/dist/tbv/core/primitives/psbt/noPayout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/payout.d.ts +1 -1
- package/dist/tbv/core/primitives/psbt/payout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/pegin.d.ts +1 -1
- package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/peginInput.d.ts +1 -1
- package/dist/tbv/core/primitives/psbt/peginInput.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/reclaim.d.ts +23 -1
- package/dist/tbv/core/primitives/psbt/reclaim.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 +1 -1
- package/dist/tbv/core/primitives/scripts/payout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts +0 -10
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts.map +1 -1
- package/dist/tbv/core/recovery/reconstructPeginParams.d.ts.map +1 -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 +2 -2
- package/dist/tbv/core/services/reclaim/__tests__/buildAndBroadcastReclaim.walletPsbt.test.d.ts +14 -0
- package/dist/tbv/core/services/reclaim/__tests__/buildAndBroadcastReclaim.walletPsbt.test.d.ts.map +1 -0
- package/dist/tbv/core/services/reclaim/buildAndBroadcastReclaim.d.ts +14 -2
- package/dist/tbv/core/services/reclaim/buildAndBroadcastReclaim.d.ts.map +1 -1
- package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts.map +1 -1
- package/dist/tbv/core/utils/index.cjs +1 -1
- package/dist/tbv/core/utils/index.js +47 -44
- package/dist/tbv/core/utils/index.js.map +1 -1
- package/dist/tbv/core/utils/utxo/reservation.d.ts.map +1 -1
- package/dist/tbv/core/utils/validation.d.ts +4 -0
- package/dist/tbv/core/utils/validation.d.ts.map +1 -1
- package/dist/tbv/core/vault-secrets/deriveVaultRoot.d.ts.map +1 -1
- package/dist/tbv/core/vault-secrets/index.cjs +1 -1
- package/dist/tbv/core/vault-secrets/index.d.ts +1 -1
- package/dist/tbv/core/vault-secrets/index.d.ts.map +1 -1
- package/dist/tbv/core/vault-secrets/index.js +2 -2
- package/dist/tbv/core/wasm/__tests__/constants.test.d.ts +2 -0
- package/dist/tbv/core/wasm/__tests__/constants.test.d.ts.map +1 -0
- package/dist/tbv/core/wasm/__tests__/loader.test.d.ts +2 -0
- package/dist/tbv/core/wasm/__tests__/loader.test.d.ts.map +1 -0
- package/dist/tbv/core/wasm/__tests__/value-guards.test.d.ts +2 -0
- package/dist/tbv/core/wasm/__tests__/value-guards.test.d.ts.map +1 -0
- package/dist/tbv/core/wasm/constants.d.ts +11 -0
- package/dist/tbv/core/wasm/constants.d.ts.map +1 -0
- package/dist/tbv/core/wasm/index.cjs +2 -0
- package/dist/tbv/core/wasm/index.cjs.map +1 -0
- package/dist/tbv/core/wasm/index.d.ts +191 -0
- package/dist/tbv/core/wasm/index.d.ts.map +1 -0
- package/dist/tbv/core/wasm/index.js +144 -0
- package/dist/tbv/core/wasm/index.js.map +1 -0
- package/dist/tbv/core/wasm/value-guards.d.ts +30 -0
- package/dist/tbv/core/wasm/value-guards.d.ts.map +1 -0
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +237 -232
- package/dist/tbv/index.js.map +1 -1
- package/dist/testing/index.cjs +1 -1
- package/dist/testing/index.js +1 -1
- package/dist/toRefundInputs-CY9u84U9.cjs +2 -0
- package/dist/toRefundInputs-CY9u84U9.cjs.map +1 -0
- package/dist/{toRefundInputs-DPNYBFkP.js → toRefundInputs-Df1vi23S.js} +8 -8
- package/dist/toRefundInputs-Df1vi23S.js.map +1 -0
- package/dist/validation-C6XTfZak.cjs +2 -0
- package/dist/validation-C6XTfZak.cjs.map +1 -0
- package/dist/validation-OSC0xTHB.js +17 -0
- package/dist/validation-OSC0xTHB.js.map +1 -0
- package/dist/vaultCoreVersion-DYfw3qed.cjs +2 -0
- package/dist/vaultCoreVersion-DYfw3qed.cjs.map +1 -0
- package/dist/vaultCoreVersion-D_fP9P3C.js +10 -0
- package/dist/vaultCoreVersion-D_fP9P3C.js.map +1 -0
- package/dist/verifyKeyPathSchnorrSignature-BedSbH2D.cjs +2 -0
- package/dist/verifyKeyPathSchnorrSignature-BedSbH2D.cjs.map +1 -0
- package/dist/{verifyKeyPathSchnorrSignature-C6Cmk0R1.js → verifyKeyPathSchnorrSignature-BrgUJmV0.js} +3 -3
- package/dist/verifyKeyPathSchnorrSignature-BrgUJmV0.js.map +1 -0
- package/dist/verifyScriptPathSchnorrSignature-BfNUSgA7.cjs +2 -0
- package/dist/verifyScriptPathSchnorrSignature-BfNUSgA7.cjs.map +1 -0
- package/dist/{verifyScriptPathSchnorrSignature-CQYucnJA.js → verifyScriptPathSchnorrSignature-Ciq_xZhw.js} +39 -37
- package/dist/verifyScriptPathSchnorrSignature-Ciq_xZhw.js.map +1 -0
- package/dist/waitForTransactionReceiptSmartAware-DpQ69ySe.cjs +2 -0
- package/dist/waitForTransactionReceiptSmartAware-DpQ69ySe.cjs.map +1 -0
- package/dist/{waitForTransactionReceiptSmartAware-B6oYRdFO.js → waitForTransactionReceiptSmartAware-z3Xfmo44.js} +42 -47
- package/dist/waitForTransactionReceiptSmartAware-z3Xfmo44.js.map +1 -0
- package/package.json +12 -2
- package/dist/PeginManager-BNtg6jgY.js.map +0 -1
- package/dist/PeginManager-CvI99Uhd.cjs +0 -2
- package/dist/PeginManager-CvI99Uhd.cjs.map +0 -1
- package/dist/batchPoll-BM4iQ9jT.js.map +0 -1
- package/dist/batchPoll-cqpEfBjr.cjs +0 -2
- package/dist/batchPoll-cqpEfBjr.cjs.map +0 -1
- package/dist/bitcoin-Ch_jxnDa.js.map +0 -1
- package/dist/bitcoin-m84N5a8o.cjs +0 -2
- package/dist/bitcoin-m84N5a8o.cjs.map +0 -1
- package/dist/buildAndBroadcastReclaim-iNJfx0ZG.cjs +0 -2
- package/dist/challengeAssert-BNQ8sToz.js.map +0 -1
- package/dist/challengeAssert-BrpC3-cQ.cjs +0 -2
- package/dist/challengeAssert-BrpC3-cQ.cjs.map +0 -1
- package/dist/constants-BCdDRd_Y.cjs +0 -2
- package/dist/constants-BCdDRd_Y.cjs.map +0 -1
- package/dist/constants-DRiWbItj.js +0 -24
- package/dist/constants-DRiWbItj.js.map +0 -1
- package/dist/mempoolApi-CfOFmov6.js.map +0 -1
- package/dist/mempoolApi-Q90mz17e.cjs +0 -2
- package/dist/mempoolApi-Q90mz17e.cjs.map +0 -1
- package/dist/noPayout-BKP3mRu3.cjs +0 -2
- package/dist/noPayout-BKP3mRu3.cjs.map +0 -1
- package/dist/noPayout-BdATUPjF.js +0 -280
- package/dist/noPayout-BdATUPjF.js.map +0 -1
- package/dist/parseFundingOutpoints-CIO9Ok1L.cjs +0 -2
- package/dist/parseFundingOutpoints-CIO9Ok1L.cjs.map +0 -1
- package/dist/parseFundingOutpoints-CO-f6IHK.js.map +0 -1
- package/dist/signPsbtsWithFallback-Bo1PJX90.cjs +0 -2
- package/dist/signing-Bnsro0hE.cjs +0 -2
- package/dist/signing-Bnsro0hE.cjs.map +0 -1
- package/dist/signing-DaLvGwQe.js +0 -16
- package/dist/signing-DaLvGwQe.js.map +0 -1
- package/dist/toRefundInputs-BJojfg3k.cjs +0 -2
- package/dist/toRefundInputs-BJojfg3k.cjs.map +0 -1
- package/dist/toRefundInputs-DPNYBFkP.js.map +0 -1
- package/dist/validation-CDbOaDj7.cjs +0 -2
- package/dist/validation-CDbOaDj7.cjs.map +0 -1
- package/dist/validation-Dj3dqYtl.js +0 -30
- package/dist/validation-Dj3dqYtl.js.map +0 -1
- package/dist/verifyKeyPathSchnorrSignature-C6Cmk0R1.js.map +0 -1
- package/dist/verifyKeyPathSchnorrSignature-Cr5T4Aym.cjs +0 -2
- package/dist/verifyKeyPathSchnorrSignature-Cr5T4Aym.cjs.map +0 -1
- package/dist/verifyScriptPathSchnorrSignature-CQYucnJA.js.map +0 -1
- package/dist/verifyScriptPathSchnorrSignature-D-ppKNjT.cjs +0 -2
- package/dist/verifyScriptPathSchnorrSignature-D-ppKNjT.cjs.map +0 -1
- package/dist/waitForTransactionReceiptSmartAware-B6oYRdFO.js.map +0 -1
- package/dist/waitForTransactionReceiptSmartAware-Ct7LPwPI.cjs +0 -2
- package/dist/waitForTransactionReceiptSmartAware-Ct7LPwPI.cjs.map +0 -1
|
@@ -1,50 +1,52 @@
|
|
|
1
1
|
var Ee = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var
|
|
2
|
+
var xe = (e, t, r) => t in e ? Ee(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var S = (e, t, r) => xe(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
4
|
import { B as ae } from "./BTCVaultRegistry.abi-CJwWI2EO.js";
|
|
5
|
-
import { e as
|
|
6
|
-
import { v as
|
|
5
|
+
import { e as ie, v as Te, s as v, u as ue, p as O, c as R, f as _ } from "./bitcoin-C-TuHb-v.js";
|
|
6
|
+
import { v as Re, d as Ce, s as Ae, P as _e, a as Se } from "./signPsbtsWithFallback-CCFTzE0o.js";
|
|
7
7
|
import { zeroAddress as $e } from "viem";
|
|
8
|
-
import { D as
|
|
9
|
-
import { Transaction as
|
|
10
|
-
import {
|
|
11
|
-
import { D as
|
|
12
|
-
import { d as He, c as
|
|
13
|
-
import {
|
|
14
|
-
import { a as
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
import { D as C, c as Be, b as Ie, R as Ve, d as le } from "./json-rpc-client-DuUARJvV.js";
|
|
9
|
+
import { Transaction as $ } from "bitcoinjs-lib";
|
|
10
|
+
import { o as Ke, f as Oe, i as B, g as I, j as V } from "./verifyScriptPathSchnorrSignature-Ciq_xZhw.js";
|
|
11
|
+
import { D as G } from "./constants-CPzppOdq.js";
|
|
12
|
+
import { d as He, c as Ne, b as De, f as ce, e as Fe, a as Me } from "./noPayout-DpGRzidi.js";
|
|
13
|
+
import { a as K, c as Le } from "./signing-Cm-McVR2.js";
|
|
14
|
+
import { a as q } from "./onChainBtcPubkey-DATNfAAl.js";
|
|
15
|
+
import { a as Ue } from "./vaultCoreVersion-D_fP9P3C.js";
|
|
16
|
+
import { deriveVaultId as Xe } from "./tbv/core/wasm/index.js";
|
|
17
|
+
const Ge = /^0x[0-9a-fA-F]{64}$/, qe = /^0x[0-9a-fA-F]{40}$/, ze = /^0x([0-9a-fA-F]{2})*$/;
|
|
18
|
+
function H(e, t) {
|
|
17
19
|
if (e.length !== 66)
|
|
18
20
|
throw new Error(
|
|
19
21
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
20
22
|
);
|
|
21
|
-
if (!
|
|
23
|
+
if (!Ge.test(e))
|
|
22
24
|
throw new Error(
|
|
23
25
|
`${t} must contain only hex characters after the 0x prefix`
|
|
24
26
|
);
|
|
25
27
|
}
|
|
26
|
-
function
|
|
27
|
-
if (!
|
|
28
|
+
function je(e, t) {
|
|
29
|
+
if (!qe.test(e))
|
|
28
30
|
throw new Error(
|
|
29
31
|
`${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
|
|
30
32
|
);
|
|
31
33
|
}
|
|
32
|
-
function
|
|
33
|
-
if (!
|
|
34
|
+
function Qe(e, t) {
|
|
35
|
+
if (!ze.test(e))
|
|
34
36
|
throw new Error(
|
|
35
37
|
`${t} must be a 0x-prefixed hex string with an even number of hex chars`
|
|
36
38
|
);
|
|
37
39
|
}
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
const t =
|
|
41
|
-
if (
|
|
40
|
+
function he(e) {
|
|
41
|
+
je(e.btcVaultRegistryAddress, "btcVaultRegistryAddress"), H(e.vaultId, "vaultId");
|
|
42
|
+
const t = ie(e.secret);
|
|
43
|
+
if (H(t, "secret"), e.hashlock !== void 0 && (H(e.hashlock, "hashlock"), !Re(t, e.hashlock)))
|
|
42
44
|
throw new Error(
|
|
43
45
|
"Invalid secret: SHA256(secret) does not match the provided hashlock"
|
|
44
46
|
);
|
|
45
47
|
return t;
|
|
46
48
|
}
|
|
47
|
-
async function
|
|
49
|
+
async function Wt(e) {
|
|
48
50
|
const {
|
|
49
51
|
btcVaultRegistryAddress: t,
|
|
50
52
|
vaultId: r,
|
|
@@ -54,23 +56,23 @@ async function qt(e) {
|
|
|
54
56
|
signal: s
|
|
55
57
|
} = e;
|
|
56
58
|
s == null || s.throwIfAborted();
|
|
57
|
-
const
|
|
59
|
+
const i = he({
|
|
58
60
|
btcVaultRegistryAddress: t,
|
|
59
61
|
vaultId: r,
|
|
60
62
|
secret: e.secret,
|
|
61
63
|
hashlock: o
|
|
62
64
|
});
|
|
63
|
-
return
|
|
65
|
+
return Qe(a, "activationMetadata"), l({
|
|
64
66
|
address: t,
|
|
65
67
|
abi: ae,
|
|
66
68
|
functionName: "activateVaultWithSecret",
|
|
67
|
-
args: [r,
|
|
69
|
+
args: [r, i, a]
|
|
68
70
|
});
|
|
69
71
|
}
|
|
70
|
-
async function
|
|
72
|
+
async function Yt(e) {
|
|
71
73
|
const { btcVaultRegistryAddress: t, vaultId: r, hashlock: o, writeContract: a, signal: l } = e;
|
|
72
74
|
l == null || l.throwIfAborted();
|
|
73
|
-
const s =
|
|
75
|
+
const s = he({
|
|
74
76
|
btcVaultRegistryAddress: t,
|
|
75
77
|
vaultId: r,
|
|
76
78
|
secret: e.secret,
|
|
@@ -83,37 +85,37 @@ async function jt(e) {
|
|
|
83
85
|
args: [r, s]
|
|
84
86
|
});
|
|
85
87
|
}
|
|
86
|
-
const
|
|
87
|
-
class
|
|
88
|
+
const We = 8, Ye = 6e3, Je = 10 * 6e4, Ze = 10;
|
|
89
|
+
class de extends Error {
|
|
88
90
|
constructor(t) {
|
|
89
91
|
super(t), this.name = "PeginRegistrationMissingError";
|
|
90
92
|
}
|
|
91
93
|
}
|
|
92
|
-
class
|
|
94
|
+
class pe extends Error {
|
|
93
95
|
constructor(t) {
|
|
94
96
|
super(t), this.name = "PeginRegistrationNotFinalError";
|
|
95
97
|
}
|
|
96
98
|
}
|
|
97
|
-
function
|
|
98
|
-
return e instanceof
|
|
99
|
+
function et(e) {
|
|
100
|
+
return e instanceof de || e instanceof Error && e.name === "PeginRegistrationMissingError";
|
|
99
101
|
}
|
|
100
|
-
function
|
|
101
|
-
return e instanceof
|
|
102
|
+
function Jt(e) {
|
|
103
|
+
return e instanceof pe || e instanceof Error && e.name === "PeginRegistrationNotFinalError";
|
|
102
104
|
}
|
|
103
|
-
function
|
|
105
|
+
function z(e) {
|
|
104
106
|
const { currentBlock: t, createdAtBlock: r } = e, o = t - r + 1n;
|
|
105
107
|
return o < 0n ? 0 : Number(o);
|
|
106
108
|
}
|
|
107
|
-
async function
|
|
109
|
+
async function Zt(e) {
|
|
108
110
|
const {
|
|
109
111
|
vaultRegistryReader: t,
|
|
110
112
|
getBlockNumber: r,
|
|
111
113
|
vaultIds: o,
|
|
112
|
-
required: a =
|
|
113
|
-
pollIntervalMs: l =
|
|
114
|
-
timeoutMs: s =
|
|
115
|
-
signal:
|
|
116
|
-
onProgress:
|
|
114
|
+
required: a = We,
|
|
115
|
+
pollIntervalMs: l = Ye,
|
|
116
|
+
timeoutMs: s = Je,
|
|
117
|
+
signal: i,
|
|
118
|
+
onProgress: n
|
|
117
119
|
} = e;
|
|
118
120
|
if (o.length === 0)
|
|
119
121
|
throw new Error(
|
|
@@ -122,116 +124,116 @@ async function Wt(e) {
|
|
|
122
124
|
const u = Date.now();
|
|
123
125
|
let h = !1, c = 0, d;
|
|
124
126
|
for (; ; ) {
|
|
125
|
-
if (
|
|
127
|
+
if (i != null && i.aborted)
|
|
126
128
|
throw new Error(
|
|
127
129
|
`Aborted while waiting for peg-in registration depth (${o.length} vault(s))`
|
|
128
130
|
);
|
|
129
131
|
if (Date.now() - u >= s)
|
|
130
|
-
throw new
|
|
132
|
+
throw new pe(
|
|
131
133
|
`Peg-in registration did not reach ${a} Ethereum confirmations within ${s}ms. The registration transaction was submitted but is not yet final, so the Pre-PegIn Bitcoin transaction was never sent and no funds are at risk. Resume this deposit from the dashboard once the network settles.` + (d instanceof Error ? ` Last read error: ${d.message}` : "")
|
|
132
134
|
);
|
|
133
135
|
try {
|
|
134
136
|
const p = await r(), g = await Promise.all(
|
|
135
|
-
o.map((
|
|
136
|
-
),
|
|
137
|
-
(
|
|
137
|
+
o.map((m) => t.getVaultBasicInfo(m))
|
|
138
|
+
), P = g.findIndex(
|
|
139
|
+
(m) => m.depositor === $e || m.createdAt === 0n
|
|
138
140
|
);
|
|
139
|
-
if (
|
|
140
|
-
if (c += 1, !h && c >
|
|
141
|
-
throw new
|
|
142
|
-
`Vault ${o[
|
|
141
|
+
if (P !== -1) {
|
|
142
|
+
if (c += 1, !h && c > Ze)
|
|
143
|
+
throw new de(
|
|
144
|
+
`Vault ${o[P]} is still not visible on-chain after ${c} reads — the registration does not exist.`
|
|
143
145
|
);
|
|
144
146
|
console.warn(
|
|
145
|
-
`Peg-in registration for vault ${o[
|
|
146
|
-
),
|
|
147
|
+
`Peg-in registration for vault ${o[P]} is not visible in chain state at block ${p} — a lagging RPC backend or an Ethereum reorg. Still polling.`
|
|
148
|
+
), n == null || n({ confirmations: 0, required: a });
|
|
147
149
|
} else {
|
|
148
150
|
h = !0, c = 0, d = void 0;
|
|
149
|
-
let
|
|
151
|
+
let m = g[0], f = z({
|
|
150
152
|
currentBlock: p,
|
|
151
153
|
createdAtBlock: g[0].createdAt
|
|
152
154
|
});
|
|
153
|
-
for (const
|
|
154
|
-
const
|
|
155
|
+
for (const w of g.slice(1)) {
|
|
156
|
+
const y = z({
|
|
155
157
|
currentBlock: p,
|
|
156
|
-
createdAtBlock:
|
|
158
|
+
createdAtBlock: w.createdAt
|
|
157
159
|
});
|
|
158
|
-
|
|
160
|
+
y < f && (f = y, m = w);
|
|
159
161
|
}
|
|
160
|
-
if (
|
|
161
|
-
return { confirmations:
|
|
162
|
+
if (n == null || n({ confirmations: f, required: a }), f >= a)
|
|
163
|
+
return { confirmations: f, basicInfo: m };
|
|
162
164
|
}
|
|
163
165
|
} catch (p) {
|
|
164
|
-
if (
|
|
166
|
+
if (et(p))
|
|
165
167
|
throw p;
|
|
166
168
|
console.warn(
|
|
167
169
|
`Registration-depth read failed (retrying in ${l}ms): ` + (p instanceof Error ? p.message : String(p))
|
|
168
170
|
), d = p;
|
|
169
171
|
}
|
|
170
172
|
await new Promise((p, g) => {
|
|
171
|
-
const
|
|
172
|
-
clearTimeout(
|
|
173
|
+
const P = () => {
|
|
174
|
+
clearTimeout(m), g(
|
|
173
175
|
new Error(
|
|
174
176
|
`Aborted while waiting for peg-in registration depth (${o.length} vault(s))`
|
|
175
177
|
)
|
|
176
178
|
);
|
|
177
|
-
},
|
|
178
|
-
|
|
179
|
+
}, m = setTimeout(() => {
|
|
180
|
+
i == null || i.removeEventListener("abort", P), p();
|
|
179
181
|
}, l);
|
|
180
|
-
|
|
182
|
+
i == null || i.addEventListener("abort", P, { once: !0 });
|
|
181
183
|
});
|
|
182
184
|
}
|
|
183
185
|
}
|
|
184
|
-
const
|
|
185
|
-
function
|
|
186
|
+
const tt = 1;
|
|
187
|
+
function rt(e, t, r) {
|
|
186
188
|
const o = r.map(
|
|
187
|
-
(c) =>
|
|
189
|
+
(c) => v(c).toLowerCase()
|
|
188
190
|
), a = t.filter((c) => o.includes(c));
|
|
189
191
|
if (a.length > 0)
|
|
190
192
|
throw new Error(
|
|
191
193
|
`Cannot validate challenger set: vault keepers and universal challengers overlap (${a.join(", ")})`
|
|
192
194
|
);
|
|
193
195
|
const l = [...t, ...o], s = e.map(
|
|
194
|
-
(c) =>
|
|
195
|
-
),
|
|
196
|
-
if (
|
|
196
|
+
(c) => v(c.challenger_pubkey).toLowerCase()
|
|
197
|
+
), i = new Set(s);
|
|
198
|
+
if (i.size !== s.length)
|
|
197
199
|
throw new Error(
|
|
198
200
|
"Depositor graph contains duplicate challenger entries in challenger_presign_data"
|
|
199
201
|
);
|
|
200
|
-
const
|
|
202
|
+
const n = new Set(l), u = l.filter((c) => !i.has(c)), h = s.filter((c) => !n.has(c));
|
|
201
203
|
if (u.length > 0 || h.length > 0)
|
|
202
204
|
throw new Error(
|
|
203
205
|
"Depositor graph challenger set does not match expected (local ∪ universal)" + (u.length > 0 ? ` (missing: ${u.join(", ")})` : "") + (h.length > 0 ? ` (unexpected: ${h.join(", ")})` : "")
|
|
204
206
|
);
|
|
205
207
|
}
|
|
206
|
-
function
|
|
208
|
+
function ot(e, t) {
|
|
207
209
|
const r = e.ins[t];
|
|
208
|
-
return
|
|
210
|
+
return ue(new Uint8Array(r.hash).slice().reverse());
|
|
209
211
|
}
|
|
210
|
-
function
|
|
212
|
+
function N(e, t, r, o, a) {
|
|
211
213
|
const l = e.ins[t];
|
|
212
214
|
if (l.index !== 0)
|
|
213
215
|
throw new Error(
|
|
214
216
|
`NoPayout (challenger ${a}) input ${t} expected to spend ${o} vout 0, got vout ${l.index}`
|
|
215
217
|
);
|
|
216
|
-
const s = r.getId(),
|
|
217
|
-
if (
|
|
218
|
+
const s = r.getId(), i = ot(e, t);
|
|
219
|
+
if (i !== s)
|
|
218
220
|
throw new Error(
|
|
219
|
-
`NoPayout (challenger ${a}) input ${t} does not reference ${o} (expected txid ${s}, got ${
|
|
221
|
+
`NoPayout (challenger ${a}) input ${t} does not reference ${o} (expected txid ${s}, got ${i})`
|
|
220
222
|
);
|
|
221
223
|
}
|
|
222
|
-
async function
|
|
224
|
+
async function nt(e, t, r) {
|
|
223
225
|
const o = [], a = [], l = [], s = Ke({
|
|
224
226
|
claimerBtcPubkey: r.depositorBtcPubkey,
|
|
225
227
|
depositorBtcPubkey: r.depositorBtcPubkey,
|
|
226
228
|
vaultProviderBtcPubkey: r.vaultProviderBtcPubkey,
|
|
227
229
|
vaultKeeperBtcPubkeys: r.vaultKeeperBtcPubkeys
|
|
228
230
|
});
|
|
229
|
-
|
|
231
|
+
rt(
|
|
230
232
|
e.challenger_presign_data,
|
|
231
233
|
s,
|
|
232
234
|
r.universalChallengerBtcPubkeys
|
|
233
235
|
);
|
|
234
|
-
const
|
|
236
|
+
const i = await Oe({
|
|
235
237
|
vaultCoreVersion: r.vaultCoreVersion,
|
|
236
238
|
vkClaimerPayoutScriptPubKeys: r.vkClaimerPayoutScriptPubKeys,
|
|
237
239
|
vpCommissionScriptPubKey: r.vpCommissionScriptPubKey,
|
|
@@ -247,25 +249,25 @@ async function rt(e, t, r) {
|
|
|
247
249
|
network: r.network,
|
|
248
250
|
claimerBtcPubkey: r.depositorBtcPubkey,
|
|
249
251
|
registeredPayoutScriptPubKey: r.registeredPayoutScriptPubKey,
|
|
250
|
-
commissionBps:
|
|
252
|
+
commissionBps: tt,
|
|
251
253
|
protocolFeeRate: r.protocolFeeRate,
|
|
252
254
|
councilMembers: r.councilMembers,
|
|
253
255
|
councilQuorum: r.councilQuorum
|
|
254
256
|
});
|
|
255
|
-
o.push(
|
|
257
|
+
o.push(i.psbtHex), a.push(
|
|
256
258
|
K(
|
|
257
259
|
t,
|
|
258
|
-
|
|
260
|
+
G
|
|
259
261
|
)
|
|
260
262
|
);
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
+
const n = v(r.depositorBtcPubkey), u = $.fromHex(
|
|
264
|
+
v(e.assert_tx.tx_hex)
|
|
263
265
|
);
|
|
264
266
|
for (const h of e.challenger_presign_data) {
|
|
265
|
-
const c =
|
|
267
|
+
const c = v(h.challenger_pubkey), d = o.length, p = await st({
|
|
266
268
|
challenger: h,
|
|
267
269
|
challengerPubkey: c,
|
|
268
|
-
claimerPubkey:
|
|
270
|
+
claimerPubkey: n,
|
|
269
271
|
localChallengers: s,
|
|
270
272
|
assertTxParsed: u,
|
|
271
273
|
ctx: r
|
|
@@ -273,7 +275,7 @@ async function rt(e, t, r) {
|
|
|
273
275
|
o.push(p), a.push(
|
|
274
276
|
K(
|
|
275
277
|
t,
|
|
276
|
-
|
|
278
|
+
G
|
|
277
279
|
)
|
|
278
280
|
), l.push({
|
|
279
281
|
challengerPubkey: c,
|
|
@@ -282,7 +284,7 @@ async function rt(e, t, r) {
|
|
|
282
284
|
}
|
|
283
285
|
return { psbtHexes: o, signOptions: a, challengerEntries: l };
|
|
284
286
|
}
|
|
285
|
-
async function
|
|
287
|
+
async function st(e) {
|
|
286
288
|
const {
|
|
287
289
|
challenger: t,
|
|
288
290
|
challengerPubkey: r,
|
|
@@ -296,31 +298,31 @@ async function ot(e) {
|
|
|
296
298
|
r,
|
|
297
299
|
s.network
|
|
298
300
|
);
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
),
|
|
302
|
-
|
|
303
|
-
), u =
|
|
304
|
-
|
|
301
|
+
const i = $.fromHex(
|
|
302
|
+
v(t.nopayout_tx.tx_hex)
|
|
303
|
+
), n = $.fromHex(
|
|
304
|
+
v(t.challenge_assert_x_tx.tx_hex)
|
|
305
|
+
), u = $.fromHex(
|
|
306
|
+
v(t.challenge_assert_y_tx.tx_hex)
|
|
305
307
|
);
|
|
306
|
-
if (
|
|
308
|
+
if (i.ins.length !== 3)
|
|
307
309
|
throw new Error(
|
|
308
|
-
`NoPayout (challenger ${r}) must have exactly 3 inputs, got ${
|
|
310
|
+
`NoPayout (challenger ${r}) must have exactly 3 inputs, got ${i.ins.length}`
|
|
309
311
|
);
|
|
310
|
-
|
|
311
|
-
|
|
312
|
+
N(
|
|
313
|
+
i,
|
|
312
314
|
0,
|
|
313
315
|
l,
|
|
314
316
|
"Assert",
|
|
315
317
|
r
|
|
316
|
-
),
|
|
317
|
-
n,
|
|
318
|
-
1,
|
|
318
|
+
), N(
|
|
319
319
|
i,
|
|
320
|
+
1,
|
|
321
|
+
n,
|
|
320
322
|
"ChallengeAssertX",
|
|
321
323
|
r
|
|
322
|
-
),
|
|
323
|
-
|
|
324
|
+
), N(
|
|
325
|
+
i,
|
|
324
326
|
2,
|
|
325
327
|
u,
|
|
326
328
|
"ChallengeAssertY",
|
|
@@ -328,13 +330,13 @@ async function ot(e) {
|
|
|
328
330
|
);
|
|
329
331
|
const h = [
|
|
330
332
|
l.outs[0],
|
|
331
|
-
|
|
333
|
+
n.outs[0],
|
|
332
334
|
u.outs[0]
|
|
333
335
|
].map((c) => ({
|
|
334
|
-
script_pubkey:
|
|
336
|
+
script_pubkey: ue(new Uint8Array(c.script)),
|
|
335
337
|
value: c.value
|
|
336
338
|
}));
|
|
337
|
-
return
|
|
339
|
+
return Ne({
|
|
338
340
|
noPayoutTxHex: t.nopayout_tx.tx_hex,
|
|
339
341
|
challengerPubkey: r,
|
|
340
342
|
prevouts: h,
|
|
@@ -349,7 +351,7 @@ async function ot(e) {
|
|
|
349
351
|
}
|
|
350
352
|
});
|
|
351
353
|
}
|
|
352
|
-
function
|
|
354
|
+
function at(e, t, r) {
|
|
353
355
|
B(e[0]);
|
|
354
356
|
const a = I(
|
|
355
357
|
e[0].returnedPsbtHex,
|
|
@@ -364,17 +366,17 @@ function nt(e, t, r) {
|
|
|
364
366
|
const l = {};
|
|
365
367
|
for (const s of t) {
|
|
366
368
|
B(e[s.noPayoutIdx]);
|
|
367
|
-
const
|
|
369
|
+
const i = I(
|
|
368
370
|
e[s.noPayoutIdx].returnedPsbtHex,
|
|
369
371
|
r
|
|
370
372
|
);
|
|
371
373
|
V({
|
|
372
374
|
requestedPsbtHex: e[s.noPayoutIdx].requestedPsbtHex,
|
|
373
|
-
signatureHex:
|
|
375
|
+
signatureHex: i,
|
|
374
376
|
signerXOnlyPubkeyHex: r,
|
|
375
377
|
inputIndex: 0
|
|
376
378
|
}), l[s.challengerPubkey] = {
|
|
377
|
-
nopayout_signature:
|
|
379
|
+
nopayout_signature: i
|
|
378
380
|
};
|
|
379
381
|
}
|
|
380
382
|
return {
|
|
@@ -384,68 +386,68 @@ function nt(e, t, r) {
|
|
|
384
386
|
per_challenger: l
|
|
385
387
|
};
|
|
386
388
|
}
|
|
387
|
-
async function
|
|
389
|
+
async function it(e) {
|
|
388
390
|
const { depositorGraph: t, btcWallet: r, signingContext: o } = e, a = await r.getPublicKeyHex(), { depositorPubkey: l } = Te(
|
|
389
391
|
a,
|
|
390
|
-
|
|
391
|
-
), { psbtHexes: s, signOptions:
|
|
392
|
+
v(o.depositorBtcPubkey)
|
|
393
|
+
), { psbtHexes: s, signOptions: i, challengerEntries: n } = await nt(
|
|
392
394
|
t,
|
|
393
395
|
a,
|
|
394
396
|
o
|
|
395
|
-
), u = await
|
|
397
|
+
), u = await Ce(
|
|
396
398
|
r,
|
|
397
399
|
s,
|
|
398
|
-
|
|
400
|
+
i
|
|
399
401
|
), h = s.map((c, d) => ({
|
|
400
402
|
requestedPsbtHex: c,
|
|
401
403
|
returnedPsbtHex: u[d]
|
|
402
404
|
}));
|
|
403
|
-
return
|
|
405
|
+
return at(
|
|
404
406
|
h,
|
|
405
|
-
|
|
407
|
+
n,
|
|
406
408
|
l
|
|
407
409
|
);
|
|
408
410
|
}
|
|
409
|
-
const
|
|
410
|
-
async function
|
|
411
|
+
const ut = 1e4;
|
|
412
|
+
async function ge(e) {
|
|
411
413
|
const {
|
|
412
414
|
statusReader: t,
|
|
413
415
|
peginTxid: r,
|
|
414
416
|
targetStatuses: o,
|
|
415
417
|
timeoutMs: a,
|
|
416
|
-
pollIntervalMs: l =
|
|
418
|
+
pollIntervalMs: l = ut,
|
|
417
419
|
signal: s
|
|
418
|
-
} = e,
|
|
420
|
+
} = e, i = Date.now();
|
|
419
421
|
for (; ; ) {
|
|
420
422
|
if (s != null && s.aborted)
|
|
421
423
|
throw new Error(
|
|
422
424
|
`Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
|
|
423
425
|
);
|
|
424
|
-
if (Date.now() -
|
|
426
|
+
if (Date.now() - i >= a)
|
|
425
427
|
throw new Error(
|
|
426
428
|
`Polling timeout after ${a}ms for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
|
|
427
429
|
);
|
|
428
430
|
try {
|
|
429
|
-
const
|
|
431
|
+
const n = await t.getPeginStatus(
|
|
430
432
|
{ pegin_txid: r },
|
|
431
433
|
s
|
|
432
434
|
);
|
|
433
|
-
if (
|
|
435
|
+
if (n.pegin_txid.toLowerCase() !== r.toLowerCase())
|
|
434
436
|
throw new Error(
|
|
435
|
-
`getPeginStatus returned status for pegin ${
|
|
437
|
+
`getPeginStatus returned status for pegin ${n.pegin_txid.slice(0, 8)}…, requested ${r.slice(0, 8)}…`
|
|
436
438
|
);
|
|
437
|
-
const u =
|
|
438
|
-
if (o.has(u) || u ===
|
|
439
|
+
const u = n.status;
|
|
440
|
+
if (o.has(u) || u === C.ACTIVATED)
|
|
439
441
|
return u;
|
|
440
|
-
if (u ===
|
|
442
|
+
if (u === C.EXPIRED || Be.has(u))
|
|
441
443
|
throw new Error(
|
|
442
444
|
`Pegin ${r.slice(0, 8)}… reached terminal status "${u}" while waiting for ${[...o].join(", ")}`
|
|
443
445
|
);
|
|
444
|
-
} catch (
|
|
445
|
-
if (!(
|
|
446
|
-
throw
|
|
446
|
+
} catch (n) {
|
|
447
|
+
if (!(n instanceof Ie && n.code === Ve.PEGIN_NOT_FOUND))
|
|
448
|
+
throw n;
|
|
447
449
|
}
|
|
448
|
-
await new Promise((
|
|
450
|
+
await new Promise((n, u) => {
|
|
449
451
|
const h = () => {
|
|
450
452
|
clearTimeout(c), u(
|
|
451
453
|
new Error(
|
|
@@ -453,35 +455,35 @@ async function pe(e) {
|
|
|
453
455
|
)
|
|
454
456
|
);
|
|
455
457
|
}, c = setTimeout(() => {
|
|
456
|
-
s == null || s.removeEventListener("abort", h),
|
|
458
|
+
s == null || s.removeEventListener("abort", h), n();
|
|
457
459
|
}, l);
|
|
458
460
|
s == null || s.addEventListener("abort", h, { once: !0 });
|
|
459
461
|
});
|
|
460
462
|
}
|
|
461
463
|
}
|
|
462
|
-
const
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
]),
|
|
468
|
-
|
|
469
|
-
...
|
|
464
|
+
const lt = 1200 * 1e3, fe = /* @__PURE__ */ new Set([
|
|
465
|
+
C.PENDING_ACKS,
|
|
466
|
+
C.PENDING_ACTIVATION,
|
|
467
|
+
C.ACTIVATED_PENDING_BROADCAST,
|
|
468
|
+
C.ACTIVATED
|
|
469
|
+
]), ct = /* @__PURE__ */ new Set([
|
|
470
|
+
C.PENDING_DEPOSITOR_SIGNATURES,
|
|
471
|
+
...fe
|
|
470
472
|
]);
|
|
471
|
-
function
|
|
473
|
+
function ht(e) {
|
|
472
474
|
return e.map((t) => ({
|
|
473
475
|
claimerPubkeyXOnly: O(t.claimer_pubkey),
|
|
474
476
|
payoutTxHex: t.payout_tx.tx_hex,
|
|
475
477
|
assertTxHex: t.assert_tx.tx_hex
|
|
476
478
|
}));
|
|
477
479
|
}
|
|
478
|
-
function
|
|
480
|
+
function T(e) {
|
|
479
481
|
return O(e).toLowerCase();
|
|
480
482
|
}
|
|
481
|
-
function
|
|
482
|
-
const r = (
|
|
483
|
+
function dt(e, t) {
|
|
484
|
+
const r = (n, u, h) => {
|
|
483
485
|
throw new Error(
|
|
484
|
-
`Deposit terms ${
|
|
486
|
+
`Deposit terms ${n} (${String(u)}) does not match the vault's version-locked signing context (${String(h)}); refusing to sign payouts against terms that describe a different graph.`
|
|
485
487
|
);
|
|
486
488
|
}, o = [
|
|
487
489
|
["protocolFeeRate", e.protocolFeeRate, t.protocolFeeRate],
|
|
@@ -489,10 +491,10 @@ function ct(e, t) {
|
|
|
489
491
|
["timelockPegin", e.timelockPegin, t.timelockPegin],
|
|
490
492
|
["timelockAssert", e.timelockAssert, t.timelockAssert]
|
|
491
493
|
];
|
|
492
|
-
for (const [
|
|
493
|
-
u !== h && r(
|
|
494
|
-
const a = (
|
|
495
|
-
const h = a(
|
|
494
|
+
for (const [n, u, h] of o)
|
|
495
|
+
u !== h && r(n, u, h);
|
|
496
|
+
const a = (n) => n.map(T).sort(), l = (n, u) => {
|
|
497
|
+
const h = a(n), c = a(u);
|
|
496
498
|
return h.length === c.length && h.every((d, p) => d === c[p]);
|
|
497
499
|
};
|
|
498
500
|
l(e.vaultKeeperBtcPubkeys, t.vaultKeeperBtcPubkeys) || r(
|
|
@@ -507,19 +509,19 @@ function ct(e, t) {
|
|
|
507
509
|
e.universalChallengerBtcPubkeys.join(","),
|
|
508
510
|
t.universalChallengerBtcPubkeys.join(",")
|
|
509
511
|
);
|
|
510
|
-
const s =
|
|
511
|
-
(
|
|
512
|
+
const s = T(t.vaultProviderBtcPubkey), i = e.vaults.map(
|
|
513
|
+
(n) => T(n.vaultProviderBtcPubkey)
|
|
512
514
|
);
|
|
513
|
-
|
|
515
|
+
i.includes(s) || r(
|
|
514
516
|
"vaults[].vaultProviderBtcPubkey",
|
|
515
|
-
|
|
517
|
+
i.join(",") || "<no vaults>",
|
|
516
518
|
t.vaultProviderBtcPubkey
|
|
517
519
|
);
|
|
518
520
|
}
|
|
519
|
-
function
|
|
520
|
-
const a =
|
|
521
|
-
|
|
522
|
-
...r.map(
|
|
521
|
+
function pt(e, t, r, o) {
|
|
522
|
+
const a = T(o), l = [
|
|
523
|
+
T(t),
|
|
524
|
+
...r.map(T)
|
|
523
525
|
], s = new Set(l);
|
|
524
526
|
if (s.size !== l.length)
|
|
525
527
|
throw new Error(
|
|
@@ -529,12 +531,12 @@ function ht(e, t, r, o) {
|
|
|
529
531
|
throw new Error(
|
|
530
532
|
"Cannot validate claimer set: depositor key overlaps with vault provider or vault keeper set"
|
|
531
533
|
);
|
|
532
|
-
const
|
|
533
|
-
(d) =>
|
|
534
|
+
const i = e.map(
|
|
535
|
+
(d) => T(d.claimer_pubkey)
|
|
534
536
|
);
|
|
535
|
-
if (new Set(
|
|
537
|
+
if (new Set(i).size !== i.length)
|
|
536
538
|
throw new Error("Presign response contains duplicate claimer entries");
|
|
537
|
-
const
|
|
539
|
+
const n = i.filter((d) => d !== a), u = new Set(n), h = l.filter((d) => !u.has(d)), c = n.filter((d) => !s.has(d));
|
|
538
540
|
if (h.length > 0 || c.length > 0)
|
|
539
541
|
throw new Error(
|
|
540
542
|
"Presign response claimer set does not match expected (vault provider ∪ vault keepers)" + (h.length > 0 ? ` (missing: ${h.join(", ")})` : "") + (c.length > 0 ? ` (unexpected: ${c.join(", ")})` : "")
|
|
@@ -562,7 +564,7 @@ function j(e, t) {
|
|
|
562
564
|
vpCommissionScriptPubKey: t.vpCommissionScriptPubKey
|
|
563
565
|
};
|
|
564
566
|
}
|
|
565
|
-
async function
|
|
567
|
+
async function gt(e, t, r, o) {
|
|
566
568
|
const a = new _e({
|
|
567
569
|
network: t.network,
|
|
568
570
|
btcWallet: e
|
|
@@ -575,22 +577,22 @@ async function dt(e, t, r, o) {
|
|
|
575
577
|
)).map((u) => u.payoutSignature);
|
|
576
578
|
else {
|
|
577
579
|
s = [];
|
|
578
|
-
for (let
|
|
579
|
-
o == null || o(
|
|
580
|
+
for (let n = 0; n < r.length; n++) {
|
|
581
|
+
o == null || o(n, l);
|
|
580
582
|
const u = await a.signPayoutTransaction(
|
|
581
|
-
j(r[
|
|
583
|
+
j(r[n], t)
|
|
582
584
|
);
|
|
583
585
|
s.push(u.signature);
|
|
584
586
|
}
|
|
585
587
|
}
|
|
586
|
-
const
|
|
587
|
-
for (let
|
|
588
|
-
|
|
589
|
-
payout_signature: s[
|
|
588
|
+
const i = {};
|
|
589
|
+
for (let n = 0; n < r.length; n++)
|
|
590
|
+
i[r[n].claimerPubkeyXOnly] = {
|
|
591
|
+
payout_signature: s[n]
|
|
590
592
|
};
|
|
591
|
-
return o == null || o(l, l),
|
|
593
|
+
return o == null || o(l, l), i;
|
|
592
594
|
}
|
|
593
|
-
async function
|
|
595
|
+
async function er(e) {
|
|
594
596
|
const {
|
|
595
597
|
statusReader: t,
|
|
596
598
|
presignClient: r,
|
|
@@ -598,25 +600,25 @@ async function Yt(e) {
|
|
|
598
600
|
peginTxid: a,
|
|
599
601
|
depositorPk: l,
|
|
600
602
|
signingContext: s,
|
|
601
|
-
depositTerms:
|
|
602
|
-
timeoutMs:
|
|
603
|
+
depositTerms: i,
|
|
604
|
+
timeoutMs: n = lt,
|
|
603
605
|
signal: u,
|
|
604
606
|
onProgress: h
|
|
605
|
-
} = e, c = await
|
|
607
|
+
} = e, c = await ge({
|
|
606
608
|
statusReader: t,
|
|
607
609
|
peginTxid: a,
|
|
608
|
-
targetStatuses:
|
|
609
|
-
timeoutMs:
|
|
610
|
+
targetStatuses: ct,
|
|
611
|
+
timeoutMs: n,
|
|
610
612
|
signal: u
|
|
611
613
|
});
|
|
612
|
-
if (
|
|
614
|
+
if (fe.has(c))
|
|
613
615
|
return;
|
|
614
|
-
if (u == null || u.throwIfAborted(),
|
|
615
|
-
if (!
|
|
616
|
+
if (u == null || u.throwIfAborted(), i !== void 0 && dt(i, s), Ae(o)) {
|
|
617
|
+
if (!i)
|
|
616
618
|
throw new Error(
|
|
617
619
|
"runDepositorPresignFlow: this wallet requires approved deposit terms but none were provided. Fresh deposits must pass PreparePeginResult.depositTerms; resume flows must rebuild them from on-chain state (the vault app's rebuildDepositTerms)."
|
|
618
620
|
);
|
|
619
|
-
typeof o.validateDepositTerms == "function" && await o.validateDepositTerms(
|
|
621
|
+
typeof o.validateDepositTerms == "function" && await o.validateDepositTerms(i), await o.approveDepositTerms(i);
|
|
620
622
|
}
|
|
621
623
|
const d = await r.requestDepositorPresignTransactions(
|
|
622
624
|
{
|
|
@@ -626,23 +628,23 @@ async function Yt(e) {
|
|
|
626
628
|
u
|
|
627
629
|
);
|
|
628
630
|
u == null || u.throwIfAborted();
|
|
629
|
-
const p =
|
|
630
|
-
|
|
631
|
+
const p = T(l);
|
|
632
|
+
pt(
|
|
631
633
|
d.txs,
|
|
632
634
|
s.vaultProviderBtcPubkey,
|
|
633
635
|
s.vaultKeeperBtcPubkeys,
|
|
634
636
|
l
|
|
635
637
|
);
|
|
636
638
|
const g = d.txs.filter(
|
|
637
|
-
(
|
|
638
|
-
),
|
|
639
|
+
(y) => T(y.claimer_pubkey) !== p
|
|
640
|
+
), P = ht(g), m = await gt(
|
|
639
641
|
o,
|
|
640
642
|
s,
|
|
641
|
-
|
|
643
|
+
P,
|
|
642
644
|
h
|
|
643
645
|
);
|
|
644
646
|
u == null || u.throwIfAborted();
|
|
645
|
-
const
|
|
647
|
+
const f = await it({
|
|
646
648
|
depositorGraph: d.depositor_graph,
|
|
647
649
|
btcWallet: o,
|
|
648
650
|
signingContext: {
|
|
@@ -664,56 +666,56 @@ async function Yt(e) {
|
|
|
664
666
|
}
|
|
665
667
|
});
|
|
666
668
|
u == null || u.throwIfAborted();
|
|
667
|
-
const
|
|
668
|
-
v
|
|
669
|
+
const w = { ...m };
|
|
670
|
+
w[v(l)] = f.payout_signatures, await r.submitDepositorPresignatures(
|
|
669
671
|
{
|
|
670
672
|
pegin_txid: a,
|
|
671
673
|
depositor_pk: l,
|
|
672
|
-
signatures:
|
|
673
|
-
depositor_claimer_presignatures:
|
|
674
|
+
signatures: w,
|
|
675
|
+
depositor_claimer_presignatures: f
|
|
674
676
|
},
|
|
675
677
|
u
|
|
676
678
|
);
|
|
677
679
|
}
|
|
678
|
-
const
|
|
679
|
-
|
|
680
|
-
...
|
|
680
|
+
const ft = 300 * 1e3, mt = /* @__PURE__ */ new Set([
|
|
681
|
+
C.PENDING_DEPOSITOR_WOTS_PK,
|
|
682
|
+
...le
|
|
681
683
|
]);
|
|
682
|
-
async function
|
|
684
|
+
async function tr(e) {
|
|
683
685
|
const {
|
|
684
686
|
statusReader: t,
|
|
685
687
|
wotsSubmitter: r,
|
|
686
688
|
peginTxid: o,
|
|
687
689
|
depositorPk: a,
|
|
688
690
|
wotsPublicKeys: l,
|
|
689
|
-
timeoutMs: s =
|
|
690
|
-
signal:
|
|
691
|
+
timeoutMs: s = ft,
|
|
692
|
+
signal: i
|
|
691
693
|
} = e;
|
|
692
|
-
|
|
693
|
-
const
|
|
694
|
+
i == null || i.throwIfAborted();
|
|
695
|
+
const n = await ge({
|
|
694
696
|
statusReader: t,
|
|
695
697
|
peginTxid: o,
|
|
696
|
-
targetStatuses:
|
|
698
|
+
targetStatuses: mt,
|
|
697
699
|
timeoutMs: s,
|
|
698
|
-
signal:
|
|
700
|
+
signal: i
|
|
699
701
|
});
|
|
700
|
-
|
|
702
|
+
le.has(n) || (i == null || i.throwIfAborted(), await r.submitDepositorWotsKey(
|
|
701
703
|
{
|
|
702
704
|
pegin_txid: o,
|
|
703
705
|
depositor_pk: a,
|
|
704
706
|
wots_public_keys: l
|
|
705
707
|
},
|
|
706
|
-
|
|
708
|
+
i
|
|
707
709
|
));
|
|
708
710
|
}
|
|
709
711
|
function D(e) {
|
|
710
712
|
return e.registration || e.operation;
|
|
711
713
|
}
|
|
712
|
-
function
|
|
713
|
-
const o =
|
|
714
|
+
function vt(e, t, r) {
|
|
715
|
+
const o = R(e);
|
|
714
716
|
return {
|
|
715
|
-
registration: o ===
|
|
716
|
-
operation: o ===
|
|
717
|
+
registration: o === R(t),
|
|
718
|
+
operation: o === R(r)
|
|
717
719
|
};
|
|
718
720
|
}
|
|
719
721
|
function Q(e, t, r) {
|
|
@@ -724,12 +726,12 @@ function Q(e, t, r) {
|
|
|
724
726
|
};
|
|
725
727
|
}
|
|
726
728
|
function F(e) {
|
|
727
|
-
return e.map(
|
|
729
|
+
return e.map(R).sort();
|
|
728
730
|
}
|
|
729
731
|
function W(e, t) {
|
|
730
732
|
return e.length === t.length && e.every((r, o) => r === t[o]);
|
|
731
733
|
}
|
|
732
|
-
async function
|
|
734
|
+
async function rr(e) {
|
|
733
735
|
const {
|
|
734
736
|
vaultProviderEthAddress: t,
|
|
735
737
|
hintBtcPubkey: r,
|
|
@@ -738,21 +740,21 @@ async function Zt(e) {
|
|
|
738
740
|
context: l
|
|
739
741
|
} = e;
|
|
740
742
|
if (!r) return;
|
|
741
|
-
const s =
|
|
742
|
-
if (s ===
|
|
743
|
-
const
|
|
743
|
+
const s = R(r);
|
|
744
|
+
if (s === R(o)) return;
|
|
745
|
+
const i = R(
|
|
744
746
|
await a()
|
|
745
747
|
);
|
|
746
|
-
if (s !==
|
|
748
|
+
if (s !== i)
|
|
747
749
|
throw new Error(
|
|
748
750
|
`Vault provider BTC pubkey mismatch for ${t}: indexer hint matches neither the registration key nor the current operation key on-chain.${l ? ` ${l}` : ""}`
|
|
749
751
|
);
|
|
750
752
|
}
|
|
751
753
|
function M(e, t, r) {
|
|
752
|
-
const o = `${e} operation key (admin=${t.ethAddress})`, a =
|
|
754
|
+
const o = `${e} operation key (admin=${t.ethAddress})`, a = q(
|
|
753
755
|
t.btcPubKey,
|
|
754
756
|
`${e} roster key (admin=${t.ethAddress})`
|
|
755
|
-
), l =
|
|
757
|
+
), l = q(r, o);
|
|
756
758
|
return {
|
|
757
759
|
adminAddress: t.ethAddress,
|
|
758
760
|
genesisBtcPubkey: a,
|
|
@@ -760,7 +762,7 @@ function M(e, t, r) {
|
|
|
760
762
|
rotated: l !== a
|
|
761
763
|
};
|
|
762
764
|
}
|
|
763
|
-
function
|
|
765
|
+
function Pt(e) {
|
|
764
766
|
const t = /* @__PURE__ */ new Map();
|
|
765
767
|
for (const r of e) {
|
|
766
768
|
const o = t.get(r.operationBtcPubkey);
|
|
@@ -771,7 +773,7 @@ function mt(e) {
|
|
|
771
773
|
t.set(r.operationBtcPubkey, r.adminAddress);
|
|
772
774
|
}
|
|
773
775
|
}
|
|
774
|
-
function
|
|
776
|
+
function me(e, t, r) {
|
|
775
777
|
if (t.vaultKeepers.length !== e.vaultKeepers.length || t.universalChallengers.length !== e.universalChallengers.length)
|
|
776
778
|
throw new Error(
|
|
777
779
|
`Operation-key resolution returned ${t.vaultKeepers.length} keeper and ${t.universalChallengers.length} challenger keys for a roster of ${e.vaultKeepers.length} keepers and ${e.universalChallengers.length} challengers`
|
|
@@ -784,11 +786,11 @@ function fe(e, t, r) {
|
|
|
784
786
|
},
|
|
785
787
|
t.vaultProvider
|
|
786
788
|
), a = e.vaultKeepers.map(
|
|
787
|
-
(s,
|
|
789
|
+
(s, i) => M("vault keeper", s, t.vaultKeepers[i])
|
|
788
790
|
), l = e.universalChallengers.map(
|
|
789
|
-
(s,
|
|
791
|
+
(s, i) => M("universal challenger", s, t.universalChallengers[i])
|
|
790
792
|
);
|
|
791
|
-
return
|
|
793
|
+
return Pt([
|
|
792
794
|
o,
|
|
793
795
|
...a,
|
|
794
796
|
...l
|
|
@@ -803,24 +805,24 @@ function fe(e, t, r) {
|
|
|
803
805
|
query: e
|
|
804
806
|
};
|
|
805
807
|
}
|
|
806
|
-
async function
|
|
808
|
+
async function yt(e) {
|
|
807
809
|
const t = await e.operationKeyReader.getCurrentOperationKeys(
|
|
808
810
|
e.query
|
|
809
811
|
);
|
|
810
|
-
return
|
|
812
|
+
return me(e.query, t, { mode: "current" });
|
|
811
813
|
}
|
|
812
|
-
async function
|
|
814
|
+
async function bt(e) {
|
|
813
815
|
const t = await e.operationKeyReader.getOperationKeysAtEpochs(
|
|
814
816
|
e.query,
|
|
815
817
|
e.epochs
|
|
816
818
|
);
|
|
817
|
-
return
|
|
819
|
+
return me(e.query, t, {
|
|
818
820
|
mode: "epochs",
|
|
819
821
|
epochs: e.epochs
|
|
820
822
|
});
|
|
821
823
|
}
|
|
822
|
-
const Y = (e) => e.map(
|
|
823
|
-
async function
|
|
824
|
+
const Y = (e) => e.map(R).sort();
|
|
825
|
+
async function or(e) {
|
|
824
826
|
const {
|
|
825
827
|
vaultRegistryReader: t,
|
|
826
828
|
vaultKeeperReader: r,
|
|
@@ -828,8 +830,8 @@ async function er(e) {
|
|
|
828
830
|
vaultProviderEthAddress: a,
|
|
829
831
|
applicationEntryPoint: l,
|
|
830
832
|
expectedVaultProviderBtcPubkey: s,
|
|
831
|
-
expectedVaultKeeperBtcPubkeys:
|
|
832
|
-
expectedUniversalChallengerBtcPubkeys:
|
|
833
|
+
expectedVaultKeeperBtcPubkeys: i,
|
|
834
|
+
expectedUniversalChallengerBtcPubkeys: n,
|
|
833
835
|
operationKeyReader: u,
|
|
834
836
|
onIndexerServingOperationKeys: h,
|
|
835
837
|
onIndexerHintsInconsistent: c
|
|
@@ -843,7 +845,7 @@ async function er(e) {
|
|
|
843
845
|
),
|
|
844
846
|
r.getCurrentVaultKeepersVersion(l),
|
|
845
847
|
o.getLatestUniversalChallengersVersion()
|
|
846
|
-
]), [
|
|
848
|
+
]), [P, m] = await Promise.all([
|
|
847
849
|
r.getVaultKeepersByVersion(
|
|
848
850
|
l,
|
|
849
851
|
p
|
|
@@ -851,71 +853,71 @@ async function er(e) {
|
|
|
851
853
|
o.getUniversalChallengersByVersion(
|
|
852
854
|
g
|
|
853
855
|
)
|
|
854
|
-
]),
|
|
855
|
-
vaultProvider:
|
|
856
|
-
vaultKeepers: Y(
|
|
857
|
-
universalChallengers: Y(
|
|
858
|
-
},
|
|
856
|
+
]), f = {
|
|
857
|
+
vaultProvider: R(d),
|
|
858
|
+
vaultKeepers: Y(P.map((E) => E.btcPubKey)),
|
|
859
|
+
universalChallengers: Y(m.map((E) => E.btcPubKey))
|
|
860
|
+
}, w = await yt({
|
|
859
861
|
operationKeyReader: u,
|
|
860
862
|
query: {
|
|
861
863
|
vaultProviderEthAddress: a,
|
|
862
864
|
vaultProviderGenesisBtcPubkey: `0x${d}`,
|
|
863
865
|
applicationEntryPoint: l,
|
|
864
|
-
vaultKeepers:
|
|
865
|
-
universalChallengers:
|
|
866
|
+
vaultKeepers: P,
|
|
867
|
+
universalChallengers: m
|
|
866
868
|
}
|
|
867
|
-
}),
|
|
868
|
-
vaultProvider:
|
|
869
|
-
vaultKeepers: [...
|
|
869
|
+
}), y = {
|
|
870
|
+
vaultProvider: w.vaultProvider.operationBtcPubkey,
|
|
871
|
+
vaultKeepers: [...w.vaultKeeperOperationKeysSorted],
|
|
870
872
|
universalChallengers: [
|
|
871
|
-
...
|
|
873
|
+
...w.universalChallengerOperationKeysSorted
|
|
872
874
|
]
|
|
873
|
-
},
|
|
875
|
+
}, k = vt(
|
|
874
876
|
s,
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
),
|
|
878
|
-
n,
|
|
879
|
-
P.vaultKeepers,
|
|
880
|
-
m.vaultKeepers
|
|
881
|
-
), $ = Q(
|
|
877
|
+
f.vaultProvider,
|
|
878
|
+
y.vaultProvider
|
|
879
|
+
), x = Q(
|
|
882
880
|
i,
|
|
883
|
-
|
|
884
|
-
|
|
881
|
+
f.vaultKeepers,
|
|
882
|
+
y.vaultKeepers
|
|
883
|
+
), A = Q(
|
|
884
|
+
n,
|
|
885
|
+
f.universalChallengers,
|
|
886
|
+
y.universalChallengers
|
|
885
887
|
);
|
|
886
|
-
if (!D(
|
|
888
|
+
if (!D(k))
|
|
887
889
|
throw new Error(
|
|
888
890
|
`Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${a}. Refresh and try again.`
|
|
889
891
|
);
|
|
890
|
-
if (!D(
|
|
892
|
+
if (!D(x))
|
|
891
893
|
throw new Error(
|
|
892
894
|
`Vault keeper BTC pubkeys (v${p}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
|
|
893
895
|
);
|
|
894
|
-
if (!D(
|
|
896
|
+
if (!D(A))
|
|
895
897
|
throw new Error(
|
|
896
898
|
`Universal challenger BTC pubkeys (v${g}) indexer set does not match ProtocolParams on-chain set. Refresh and try again.`
|
|
897
899
|
);
|
|
898
|
-
const
|
|
899
|
-
if (
|
|
900
|
+
const b = [k, x, A], ke = b.some((E) => E.registration && !E.operation), X = b.some((E) => E.operation && !E.registration);
|
|
901
|
+
if (ke && X) {
|
|
900
902
|
const E = `Indexer participant hints are internally inconsistent for vault provider ${a}: some roles match the registration keys while others match the rotated operation keys.`;
|
|
901
903
|
throw c == null || c(E), new Error(`${E} Refresh and try again.`);
|
|
902
904
|
}
|
|
903
|
-
return
|
|
905
|
+
return X && (h == null || h(
|
|
904
906
|
`Indexer is serving rotated operation keys for vault provider ${a}`
|
|
905
907
|
)), {
|
|
906
|
-
vaultProviderBtcPubkeyXOnly:
|
|
907
|
-
vaultKeeperBtcPubkeysSorted:
|
|
908
|
-
universalChallengerBtcPubkeysSorted:
|
|
908
|
+
vaultProviderBtcPubkeyXOnly: y.vaultProvider,
|
|
909
|
+
vaultKeeperBtcPubkeysSorted: y.vaultKeepers,
|
|
910
|
+
universalChallengerBtcPubkeysSorted: y.universalChallengers,
|
|
909
911
|
expectedAppVaultKeepersVersion: p,
|
|
910
912
|
expectedUniversalChallengersVersion: g,
|
|
911
|
-
registrationKeys:
|
|
912
|
-
participantKeys:
|
|
913
|
+
registrationKeys: f,
|
|
914
|
+
participantKeys: w
|
|
913
915
|
};
|
|
914
916
|
}
|
|
915
|
-
function
|
|
917
|
+
function wt(e) {
|
|
916
918
|
return /^[0-9a-fA-F]{64}$/.test(e);
|
|
917
919
|
}
|
|
918
|
-
function
|
|
920
|
+
function nr(e) {
|
|
919
921
|
const {
|
|
920
922
|
amountSats: t,
|
|
921
923
|
minDeposit: r,
|
|
@@ -926,29 +928,29 @@ function tr(e) {
|
|
|
926
928
|
} = e;
|
|
927
929
|
return !(t <= 0n || t < r || o && o > 0n && t > o || l == null || s == null || t + l + s > a);
|
|
928
930
|
}
|
|
929
|
-
function
|
|
931
|
+
function sr(e, t, r) {
|
|
930
932
|
return e <= 0n ? {
|
|
931
933
|
valid: !1,
|
|
932
934
|
error: "Deposit amount must be greater than zero"
|
|
933
935
|
} : e < t ? {
|
|
934
936
|
valid: !1,
|
|
935
|
-
error: `Minimum deposit is ${
|
|
937
|
+
error: `Minimum deposit is ${_(t)} BTC`
|
|
936
938
|
} : r && r > 0n && e > r ? {
|
|
937
939
|
valid: !1,
|
|
938
|
-
error: `Maximum deposit is ${
|
|
940
|
+
error: `Maximum deposit is ${_(r)} BTC`
|
|
939
941
|
} : { valid: !0 };
|
|
940
942
|
}
|
|
941
|
-
function
|
|
943
|
+
function ar(e) {
|
|
942
944
|
const { amount: t, effectiveRemaining: r } = e;
|
|
943
945
|
return r === null ? { valid: !0 } : r === 0n ? {
|
|
944
946
|
valid: !1,
|
|
945
947
|
error: "Supply cap reached — deposits temporarily paused"
|
|
946
948
|
} : t > r ? {
|
|
947
949
|
valid: !1,
|
|
948
|
-
error: `Vault size exceeds remaining capacity (${
|
|
950
|
+
error: `Vault size exceeds remaining capacity (${_(r)} BTC)`
|
|
949
951
|
} : { valid: !0 };
|
|
950
952
|
}
|
|
951
|
-
function
|
|
953
|
+
function ir(e, t) {
|
|
952
954
|
if (!e || e.length === 0)
|
|
953
955
|
return {
|
|
954
956
|
valid: !1,
|
|
@@ -964,7 +966,7 @@ function nr(e, t) {
|
|
|
964
966
|
error: "Invalid vault provider selected"
|
|
965
967
|
} : { valid: !0 };
|
|
966
968
|
}
|
|
967
|
-
function
|
|
969
|
+
function kt(e, t, r) {
|
|
968
970
|
if (!e || e.length === 0)
|
|
969
971
|
return {
|
|
970
972
|
valid: !1,
|
|
@@ -980,40 +982,40 @@ function bt(e, t, r) {
|
|
|
980
982
|
if (t && a < t)
|
|
981
983
|
return {
|
|
982
984
|
valid: !1,
|
|
983
|
-
error: `Vault ${o + 1} amount ${
|
|
985
|
+
error: `Vault ${o + 1} amount ${_(a)} BTC is below minimum deposit ${_(t)} BTC`
|
|
984
986
|
};
|
|
985
987
|
if (r && a > r)
|
|
986
988
|
return {
|
|
987
989
|
valid: !1,
|
|
988
|
-
error: `Vault ${o + 1} amount ${
|
|
990
|
+
error: `Vault ${o + 1} amount ${_(a)} BTC exceeds maximum deposit ${_(r)} BTC`
|
|
989
991
|
};
|
|
990
992
|
}
|
|
991
993
|
return { valid: !0 };
|
|
992
994
|
}
|
|
993
|
-
function
|
|
994
|
-
const t =
|
|
995
|
-
return
|
|
995
|
+
function Et(e) {
|
|
996
|
+
const t = v(e);
|
|
997
|
+
return wt(t) ? { valid: !0 } : {
|
|
996
998
|
valid: !1,
|
|
997
999
|
error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
|
|
998
1000
|
};
|
|
999
1001
|
}
|
|
1000
|
-
function
|
|
1002
|
+
function xt(e) {
|
|
1001
1003
|
if (!e || e.length === 0)
|
|
1002
1004
|
throw new Error(
|
|
1003
1005
|
"No vault keepers available. The system requires at least one vault keeper to create a deposit."
|
|
1004
1006
|
);
|
|
1005
1007
|
}
|
|
1006
|
-
function
|
|
1008
|
+
function Tt(e) {
|
|
1007
1009
|
if (!e || e.length === 0)
|
|
1008
1010
|
throw new Error(
|
|
1009
1011
|
"No universal challengers available. The system requires at least one universal challenger to create a deposit."
|
|
1010
1012
|
);
|
|
1011
1013
|
}
|
|
1012
|
-
function
|
|
1014
|
+
function Rt(e) {
|
|
1013
1015
|
if (e.length === 0)
|
|
1014
1016
|
throw new Error("No spendable UTXOs available");
|
|
1015
1017
|
}
|
|
1016
|
-
function
|
|
1018
|
+
function ur(e) {
|
|
1017
1019
|
const {
|
|
1018
1020
|
vaultAmounts: t,
|
|
1019
1021
|
confirmedUTXOs: r,
|
|
@@ -1021,50 +1023,50 @@ function sr(e) {
|
|
|
1021
1023
|
vaultKeeperBtcPubkeys: a,
|
|
1022
1024
|
universalChallengerBtcPubkeys: l,
|
|
1023
1025
|
minDeposit: s,
|
|
1024
|
-
maxDeposit:
|
|
1025
|
-
} = e,
|
|
1026
|
+
maxDeposit: i
|
|
1027
|
+
} = e, n = kt(
|
|
1026
1028
|
t,
|
|
1027
1029
|
s,
|
|
1028
|
-
|
|
1030
|
+
i
|
|
1029
1031
|
);
|
|
1030
|
-
if (!
|
|
1031
|
-
throw new Error(
|
|
1032
|
-
const u =
|
|
1032
|
+
if (!n.valid)
|
|
1033
|
+
throw new Error(n.error);
|
|
1034
|
+
const u = Et(o);
|
|
1033
1035
|
if (!u.valid)
|
|
1034
1036
|
throw new Error(u.error);
|
|
1035
|
-
|
|
1037
|
+
xt(a), Tt(l), Rt(r);
|
|
1036
1038
|
}
|
|
1037
|
-
class
|
|
1039
|
+
class ve extends Error {
|
|
1038
1040
|
constructor(t) {
|
|
1039
1041
|
super(t), this.name = "ParticipantKeyDriftError";
|
|
1040
1042
|
}
|
|
1041
1043
|
}
|
|
1042
|
-
function
|
|
1043
|
-
return e instanceof
|
|
1044
|
+
function lr(e) {
|
|
1045
|
+
return e instanceof ve || e instanceof Error && e.name === "ParticipantKeyDriftError";
|
|
1044
1046
|
}
|
|
1045
1047
|
function J(e, t, r) {
|
|
1046
1048
|
return t.length === r.length && t.every((o, a) => o === r[a]) ? null : `${e} expected [${t.join(", ")}], got [${r.join(", ")}]`;
|
|
1047
1049
|
}
|
|
1048
|
-
async function
|
|
1050
|
+
async function cr(e) {
|
|
1049
1051
|
const { vaultRegistryReader: t, operationKeyReader: r, vaultIds: o, expected: a } = e, l = a.query;
|
|
1050
1052
|
if (o.length === 0) return;
|
|
1051
|
-
const s = await t.getVaultKeyEpochsBatch(o),
|
|
1052
|
-
for (const [
|
|
1053
|
-
const h = o[
|
|
1053
|
+
const s = await t.getVaultKeyEpochsBatch(o), i = [];
|
|
1054
|
+
for (const [n, u] of s.entries()) {
|
|
1055
|
+
const h = o[n];
|
|
1054
1056
|
let c;
|
|
1055
1057
|
try {
|
|
1056
|
-
c = await
|
|
1058
|
+
c = await bt({
|
|
1057
1059
|
operationKeyReader: r,
|
|
1058
1060
|
query: l,
|
|
1059
1061
|
epochs: u
|
|
1060
1062
|
});
|
|
1061
1063
|
} catch (g) {
|
|
1062
|
-
|
|
1064
|
+
i.push(
|
|
1063
1065
|
`vault ${h}: could not resolve participants at frozen epochs (vp=${u.vpKeyEpoch}, keeper=${u.appKeeperKeyEpoch}, uc=${u.ucKeyEpoch}): ${g.message}`
|
|
1064
1066
|
);
|
|
1065
1067
|
continue;
|
|
1066
1068
|
}
|
|
1067
|
-
c.vaultProvider.operationBtcPubkey !== a.vaultProvider.operationBtcPubkey &&
|
|
1069
|
+
c.vaultProvider.operationBtcPubkey !== a.vaultProvider.operationBtcPubkey && i.push(
|
|
1068
1070
|
`vault ${h}: vault provider key expected ${a.vaultProvider.operationBtcPubkey}, got ${c.vaultProvider.operationBtcPubkey}`
|
|
1069
1071
|
);
|
|
1070
1072
|
const d = J(
|
|
@@ -1072,17 +1074,17 @@ async function ir(e) {
|
|
|
1072
1074
|
a.vaultKeeperOperationKeysSorted,
|
|
1073
1075
|
c.vaultKeeperOperationKeysSorted
|
|
1074
1076
|
);
|
|
1075
|
-
d &&
|
|
1077
|
+
d && i.push(d);
|
|
1076
1078
|
const p = J(
|
|
1077
1079
|
`vault ${h}: universal challenger keys`,
|
|
1078
1080
|
a.universalChallengerOperationKeysSorted,
|
|
1079
1081
|
c.universalChallengerOperationKeysSorted
|
|
1080
1082
|
);
|
|
1081
|
-
p &&
|
|
1083
|
+
p && i.push(p);
|
|
1082
1084
|
}
|
|
1083
|
-
if (
|
|
1084
|
-
throw new
|
|
1085
|
-
`Aborting BTC broadcast: participant operation keys changed during registration (${
|
|
1085
|
+
if (i.length > 0)
|
|
1086
|
+
throw new ve(
|
|
1087
|
+
`Aborting BTC broadcast: participant operation keys changed during registration (${i.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
|
|
1086
1088
|
);
|
|
1087
1089
|
}
|
|
1088
1090
|
class Pe extends Error {
|
|
@@ -1090,10 +1092,10 @@ class Pe extends Error {
|
|
|
1090
1092
|
super(t), this.name = "RegisteredVaultVersionMismatchError";
|
|
1091
1093
|
}
|
|
1092
1094
|
}
|
|
1093
|
-
function
|
|
1095
|
+
function hr(e) {
|
|
1094
1096
|
return e instanceof Pe || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
|
|
1095
1097
|
}
|
|
1096
|
-
async function
|
|
1098
|
+
async function dr(e) {
|
|
1097
1099
|
const {
|
|
1098
1100
|
vaultRegistryReader: t,
|
|
1099
1101
|
vaultIds: r,
|
|
@@ -1101,70 +1103,70 @@ async function lr(e) {
|
|
|
1101
1103
|
expectedAppVaultKeepersVersion: a,
|
|
1102
1104
|
expectedUniversalChallengersVersion: l,
|
|
1103
1105
|
expectedVaultCoreVersion: s
|
|
1104
|
-
} = e,
|
|
1105
|
-
if (
|
|
1106
|
+
} = e, i = await t.getProtocolInfoBatch(r), n = [];
|
|
1107
|
+
if (i.forEach((u, h) => {
|
|
1106
1108
|
const c = r[h];
|
|
1107
|
-
u.offchainParamsVersion !== o &&
|
|
1109
|
+
u.offchainParamsVersion !== o && n.push(
|
|
1108
1110
|
`vault ${c}: offchainParams expected v${o}, got v${u.offchainParamsVersion}`
|
|
1109
|
-
), u.appVaultKeepersVersion !== a &&
|
|
1111
|
+
), u.appVaultKeepersVersion !== a && n.push(
|
|
1110
1112
|
`vault ${c}: appVaultKeepers expected v${a}, got v${u.appVaultKeepersVersion}`
|
|
1111
|
-
), u.universalChallengersVersion !== l &&
|
|
1113
|
+
), u.universalChallengersVersion !== l && n.push(
|
|
1112
1114
|
`vault ${c}: universalChallengers expected v${l}, got v${u.universalChallengersVersion}`
|
|
1113
|
-
), u.vaultCoreVersion !== s &&
|
|
1115
|
+
), u.vaultCoreVersion !== s && n.push(
|
|
1114
1116
|
`vault ${c}: vaultCoreVersion expected v${s} (build-time active), got v${u.vaultCoreVersion}`
|
|
1115
1117
|
);
|
|
1116
|
-
}),
|
|
1118
|
+
}), n.length > 0)
|
|
1117
1119
|
throw new Pe(
|
|
1118
|
-
`Aborting BTC broadcast: signer-set or offchain-params versions changed during registration (${
|
|
1120
|
+
`Aborting BTC broadcast: signer-set or offchain-params versions changed during registration (${n.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
|
|
1119
1121
|
);
|
|
1120
1122
|
}
|
|
1121
|
-
var
|
|
1122
|
-
const
|
|
1123
|
+
var ye = /* @__PURE__ */ ((e) => (e.CLAIM_EVENT_RECEIVED = "ClaimEventReceived", e.CLAIM_BROADCAST = "ClaimBroadcast", e.ASSERT_BROADCAST = "AssertBroadcast", e.PAYOUT_BROADCAST = "PayoutBroadcast", e.PAYOUT_BLOCKED = "PayoutBlocked", e))(ye || {});
|
|
1124
|
+
const Ct = /* @__PURE__ */ new Set([
|
|
1123
1125
|
"PayoutBroadcast",
|
|
1124
1126
|
"PayoutBlocked"
|
|
1125
1127
|
/* PAYOUT_BLOCKED */
|
|
1126
1128
|
]);
|
|
1127
|
-
function
|
|
1128
|
-
return Object.values(
|
|
1129
|
+
function pr(e) {
|
|
1130
|
+
return Object.values(ye).includes(
|
|
1129
1131
|
e
|
|
1130
1132
|
);
|
|
1131
1133
|
}
|
|
1132
|
-
function
|
|
1133
|
-
return !!e &&
|
|
1134
|
+
function gr(e) {
|
|
1135
|
+
return !!e && Ct.has(e);
|
|
1134
1136
|
}
|
|
1135
1137
|
class At extends Error {
|
|
1136
1138
|
constructor(r, o) {
|
|
1137
1139
|
super(`Refund not yet mature (BIP68 not final): ${o.message}`);
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
+
S(this, "vaultId");
|
|
1141
|
+
S(this, "cause");
|
|
1140
1142
|
this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = o;
|
|
1141
1143
|
}
|
|
1142
1144
|
}
|
|
1143
|
-
const
|
|
1144
|
-
function
|
|
1145
|
+
const _t = /^0x[0-9a-fA-F]{64}$/, St = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, be = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, we = 160, Z = 2e3, ee = 10n, te = 100n;
|
|
1146
|
+
function fr(e) {
|
|
1145
1147
|
if (!Number.isFinite(e) || e <= 0)
|
|
1146
1148
|
throw new Error(
|
|
1147
1149
|
`feeRateSatsVb must be a positive finite number, got ${e}`
|
|
1148
1150
|
);
|
|
1149
|
-
return BigInt(Math.ceil(e *
|
|
1151
|
+
return BigInt(Math.ceil(e * we));
|
|
1150
1152
|
}
|
|
1151
|
-
const
|
|
1152
|
-
function
|
|
1153
|
+
const $t = 1, Bt = /non-BIP68-final/i;
|
|
1154
|
+
function U(e, t) {
|
|
1153
1155
|
if (e.length !== 66)
|
|
1154
1156
|
throw new Error(
|
|
1155
1157
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
1156
1158
|
);
|
|
1157
|
-
if (!
|
|
1159
|
+
if (!_t.test(e))
|
|
1158
1160
|
throw new Error(
|
|
1159
1161
|
`${t} must contain only hex characters after the 0x prefix`
|
|
1160
1162
|
);
|
|
1161
1163
|
}
|
|
1162
|
-
function
|
|
1164
|
+
function L(e, t) {
|
|
1163
1165
|
if (!Number.isInteger(e) || e < 0)
|
|
1164
1166
|
throw new Error(`${t} must be a non-negative integer, got ${e}`);
|
|
1165
1167
|
}
|
|
1166
|
-
function
|
|
1167
|
-
if (
|
|
1168
|
+
function It(e) {
|
|
1169
|
+
if (U(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0)
|
|
1168
1170
|
throw new Error(
|
|
1169
1171
|
`htlcVout must be a non-negative integer, got ${e.htlcVout}`
|
|
1170
1172
|
);
|
|
@@ -1176,7 +1178,7 @@ function $t(e) {
|
|
|
1176
1178
|
);
|
|
1177
1179
|
for (let r = 0; r < e.batch.length; r++) {
|
|
1178
1180
|
const o = e.batch[r];
|
|
1179
|
-
if (
|
|
1181
|
+
if (U(o.hashlock, `batch[${r}].hashlock`), !Number.isInteger(o.htlcVout) || o.htlcVout !== r)
|
|
1180
1182
|
throw new Error(
|
|
1181
1183
|
`batch[${r}].htlcVout must equal ${r} (contiguous vout-ordered vector), got ${o.htlcVout}`
|
|
1182
1184
|
);
|
|
@@ -1194,27 +1196,27 @@ function $t(e) {
|
|
|
1194
1196
|
throw new Error(
|
|
1195
1197
|
`batch[${e.htlcVout}].amount (${t.amount}) does not match target amount (${e.amount})`
|
|
1196
1198
|
);
|
|
1197
|
-
if (
|
|
1199
|
+
if (L(e.offchainParamsVersion, "offchainParamsVersion"), L(e.appVaultKeepersVersion, "appVaultKeepersVersion"), L(
|
|
1198
1200
|
e.universalChallengersVersion,
|
|
1199
1201
|
"universalChallengersVersion"
|
|
1200
|
-
),
|
|
1202
|
+
), Ue(
|
|
1201
1203
|
e.vaultCoreVersion,
|
|
1202
1204
|
"VaultRefundData.vaultCoreVersion"
|
|
1203
1205
|
), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
|
|
1204
1206
|
throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
|
|
1205
|
-
if (!
|
|
1207
|
+
if (!St.test(e.unsignedPrePeginTxHex))
|
|
1206
1208
|
throw new Error(
|
|
1207
1209
|
"unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
|
|
1208
1210
|
);
|
|
1209
|
-
if (!e.depositorBtcPubkey || !
|
|
1211
|
+
if (!e.depositorBtcPubkey || !be.test(e.depositorBtcPubkey))
|
|
1210
1212
|
throw new Error(
|
|
1211
1213
|
"depositorBtcPubkey must be 32 or 33 bytes of hex (optional 0x prefix)"
|
|
1212
1214
|
);
|
|
1213
1215
|
if (typeof e.amount != "bigint" || e.amount <= 0n)
|
|
1214
1216
|
throw new Error(`amount must be a positive bigint, got ${e.amount}`);
|
|
1215
1217
|
}
|
|
1216
|
-
function
|
|
1217
|
-
if (!e.vaultProviderPubkey || !
|
|
1218
|
+
function Vt(e) {
|
|
1219
|
+
if (!e.vaultProviderPubkey || !be.test(e.vaultProviderPubkey))
|
|
1218
1220
|
throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
|
|
1219
1221
|
if (e.vaultKeeperPubkeys.length === 0)
|
|
1220
1222
|
throw new Error("vaultKeeperPubkeys must be non-empty");
|
|
@@ -1239,18 +1241,7 @@ function Bt(e) {
|
|
|
1239
1241
|
`councilQuorum (${e.councilQuorum}) must be in [1, councilSize=${e.councilSize}]`
|
|
1240
1242
|
);
|
|
1241
1243
|
}
|
|
1242
|
-
function
|
|
1243
|
-
const t = le.fromHex(e);
|
|
1244
|
-
try {
|
|
1245
|
-
t.finalizeAllInputs();
|
|
1246
|
-
} catch (r) {
|
|
1247
|
-
const o = r instanceof Error ? r.message : String(r);
|
|
1248
|
-
if (!o.includes("already finalized"))
|
|
1249
|
-
throw new Error(`Failed to finalize refund PSBT: ${o}`);
|
|
1250
|
-
}
|
|
1251
|
-
return t.extractTransaction().toHex();
|
|
1252
|
-
}
|
|
1253
|
-
async function pr(e) {
|
|
1244
|
+
async function mr(e) {
|
|
1254
1245
|
const {
|
|
1255
1246
|
vaultId: t,
|
|
1256
1247
|
readVault: r,
|
|
@@ -1258,52 +1249,52 @@ async function pr(e) {
|
|
|
1258
1249
|
feeRate: a,
|
|
1259
1250
|
signPsbt: l,
|
|
1260
1251
|
broadcastTx: s,
|
|
1261
|
-
signal:
|
|
1252
|
+
signal: i
|
|
1262
1253
|
} = e;
|
|
1263
|
-
|
|
1264
|
-
const
|
|
1265
|
-
|
|
1266
|
-
const u = await o(
|
|
1267
|
-
if (
|
|
1254
|
+
i == null || i.throwIfAborted(), U(t, "vaultId");
|
|
1255
|
+
const n = await r();
|
|
1256
|
+
It(n), i == null || i.throwIfAborted();
|
|
1257
|
+
const u = await o(n);
|
|
1258
|
+
if (Vt(u), i == null || i.throwIfAborted(), !Number.isFinite(a) || a <= 0)
|
|
1268
1259
|
throw new Error(`feeRate must be a positive number, got ${a}`);
|
|
1269
1260
|
if (a > Z)
|
|
1270
1261
|
throw new Error(
|
|
1271
1262
|
`feeRate ${a} sat/vB exceeds refund safety cap ${Z} sat/vB; refusing to sign refund.`
|
|
1272
1263
|
);
|
|
1273
|
-
const h = BigInt(Math.ceil(a *
|
|
1264
|
+
const h = BigInt(Math.ceil(a * we)), c = n.amount * ee / te;
|
|
1274
1265
|
if (h > c)
|
|
1275
1266
|
throw new Error(
|
|
1276
|
-
`Refund fee ${h} sats exceeds the per-vault safety cap of ${c} sats (${ee}/${te} of vault.amount=${
|
|
1267
|
+
`Refund fee ${h} sats exceeds the per-vault safety cap of ${c} sats (${ee}/${te} of vault.amount=${n.amount}); refusing to sign refund.`
|
|
1277
1268
|
);
|
|
1278
|
-
|
|
1269
|
+
i == null || i.throwIfAborted();
|
|
1279
1270
|
const d = O(
|
|
1280
|
-
|
|
1281
|
-
), p =
|
|
1282
|
-
if (g !== void 0 && g.vout !==
|
|
1271
|
+
n.depositorBtcPubkey
|
|
1272
|
+
), p = v(n.unsignedPrePeginTxHex), g = Se(p);
|
|
1273
|
+
if (g !== void 0 && g.vout !== n.batch.length)
|
|
1283
1274
|
throw new Error(
|
|
1284
|
-
`Auth-anchor OP_RETURN at vout ${g.vout} does not match batch size (${
|
|
1275
|
+
`Auth-anchor OP_RETURN at vout ${g.vout} does not match batch size (${n.batch.length} HTLC outputs expect the anchor at vout ${n.batch.length}). Refund refused — sibling HTLC vector is incomplete.`
|
|
1285
1276
|
);
|
|
1286
|
-
const
|
|
1287
|
-
let
|
|
1277
|
+
const P = g == null ? void 0 : g.hash;
|
|
1278
|
+
let m;
|
|
1288
1279
|
try {
|
|
1289
|
-
|
|
1290
|
-
} catch (
|
|
1280
|
+
m = $.fromHex(p);
|
|
1281
|
+
} catch (b) {
|
|
1291
1282
|
throw new Error(
|
|
1292
|
-
`Failed to parse funded Pre-PegIn transaction hex: ${
|
|
1283
|
+
`Failed to parse funded Pre-PegIn transaction hex: ${b instanceof Error ? b.message : String(b)}`
|
|
1293
1284
|
);
|
|
1294
1285
|
}
|
|
1295
|
-
if (
|
|
1286
|
+
if (m.outs.length < n.batch.length)
|
|
1296
1287
|
throw new Error(
|
|
1297
|
-
`Funded Pre-PegIn tx has ${
|
|
1288
|
+
`Funded Pre-PegIn tx has ${m.outs.length} outputs but batch requires at least ${n.batch.length} HTLC outputs. Refund refused — funded tx shape disagrees with sibling vector.`
|
|
1298
1289
|
);
|
|
1299
|
-
const { psbtHex:
|
|
1290
|
+
const { psbtHex: f } = await De({
|
|
1300
1291
|
prePeginParams: {
|
|
1301
|
-
vaultCoreVersion:
|
|
1292
|
+
vaultCoreVersion: n.vaultCoreVersion,
|
|
1302
1293
|
depositorPubkey: d,
|
|
1303
|
-
vaultProviderPubkey:
|
|
1304
|
-
vaultKeeperPubkeys: u.vaultKeeperPubkeys.map(
|
|
1305
|
-
universalChallengerPubkeys: u.universalChallengerPubkeys.map(
|
|
1306
|
-
hashlocks:
|
|
1294
|
+
vaultProviderPubkey: v(u.vaultProviderPubkey),
|
|
1295
|
+
vaultKeeperPubkeys: u.vaultKeeperPubkeys.map(v),
|
|
1296
|
+
universalChallengerPubkeys: u.universalChallengerPubkeys.map(v),
|
|
1297
|
+
hashlocks: n.batch.map((b) => v(b.hashlock)),
|
|
1307
1298
|
timelockRefund: u.timelockRefund,
|
|
1308
1299
|
// `batch[i].amount` is the on-chain vault deposit (peg-in) amount, which
|
|
1309
1300
|
// is exactly what WASM's `pegInAmounts` expects — it re-adds the protocol
|
|
@@ -1311,188 +1302,201 @@ async function pr(e) {
|
|
|
1311
1302
|
// HTLC output. `buildRefundPsbt`'s value cross-check then binds the result
|
|
1312
1303
|
// to the funded tx bytes, refusing the refund if the template's HTLC value
|
|
1313
1304
|
// disagrees with the on-chain commitment.
|
|
1314
|
-
pegInAmounts:
|
|
1305
|
+
pegInAmounts: n.batch.map((b) => b.amount),
|
|
1315
1306
|
feeRate: u.feeRate,
|
|
1316
1307
|
minPeginFeeRate: u.minPeginFeeRate,
|
|
1317
1308
|
numLocalChallengers: u.numLocalChallengers,
|
|
1318
1309
|
councilQuorum: u.councilQuorum,
|
|
1319
1310
|
councilSize: u.councilSize,
|
|
1320
1311
|
network: u.network,
|
|
1321
|
-
authAnchorHash:
|
|
1312
|
+
authAnchorHash: P
|
|
1322
1313
|
},
|
|
1323
1314
|
fundedPrePeginTxHex: p,
|
|
1324
|
-
htlcVout:
|
|
1315
|
+
htlcVout: n.htlcVout,
|
|
1325
1316
|
refundFee: h,
|
|
1326
1317
|
// buildRefundPsbt's top-level `hashlock` param is documented as "no 0x
|
|
1327
1318
|
// prefix" and flows into the WASM HTLC connector derivation; a prefixed
|
|
1328
1319
|
// value would derive the wrong refund script leaf and yield an
|
|
1329
1320
|
// unspendable PSBT. Match the `hashlocks` array handling above.
|
|
1330
|
-
hashlock:
|
|
1321
|
+
hashlock: v(n.hashlock)
|
|
1331
1322
|
});
|
|
1332
|
-
|
|
1333
|
-
const
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
),
|
|
1323
|
+
i == null || i.throwIfAborted();
|
|
1324
|
+
const w = K(
|
|
1325
|
+
n.depositorBtcPubkey,
|
|
1326
|
+
$t
|
|
1327
|
+
), y = await l(f, w);
|
|
1337
1328
|
B({
|
|
1338
|
-
requestedPsbtHex:
|
|
1339
|
-
returnedPsbtHex:
|
|
1329
|
+
requestedPsbtHex: f,
|
|
1330
|
+
returnedPsbtHex: y
|
|
1340
1331
|
});
|
|
1341
|
-
const
|
|
1342
|
-
|
|
1332
|
+
const k = 0, x = I(
|
|
1333
|
+
y,
|
|
1343
1334
|
d,
|
|
1344
|
-
|
|
1335
|
+
k
|
|
1345
1336
|
);
|
|
1346
1337
|
V({
|
|
1347
|
-
requestedPsbtHex:
|
|
1348
|
-
signatureHex:
|
|
1338
|
+
requestedPsbtHex: f,
|
|
1339
|
+
signatureHex: x,
|
|
1349
1340
|
signerXOnlyPubkeyHex: d,
|
|
1350
|
-
inputIndex:
|
|
1341
|
+
inputIndex: k
|
|
1351
1342
|
});
|
|
1352
|
-
const
|
|
1353
|
-
|
|
1343
|
+
const A = ce({
|
|
1344
|
+
requestedPsbtHex: f,
|
|
1345
|
+
signaturesHex: [x],
|
|
1346
|
+
signerXOnlyPubkeyHex: d
|
|
1347
|
+
});
|
|
1348
|
+
i == null || i.throwIfAborted();
|
|
1354
1349
|
try {
|
|
1355
|
-
return await s(
|
|
1356
|
-
} catch (
|
|
1357
|
-
throw
|
|
1350
|
+
return await s(A);
|
|
1351
|
+
} catch (b) {
|
|
1352
|
+
throw b instanceof Error && Bt.test(b.message) ? new At(t, b) : b;
|
|
1358
1353
|
}
|
|
1359
1354
|
}
|
|
1360
1355
|
class re extends Error {
|
|
1361
1356
|
constructor(r, o, a) {
|
|
1362
1357
|
super(r);
|
|
1363
1358
|
/** Fee the reclaim would have paid, in satoshis. */
|
|
1364
|
-
|
|
1359
|
+
S(this, "feeSats");
|
|
1365
1360
|
/** Sum of the reserves the reclaim would have swept, in satoshis. */
|
|
1366
|
-
|
|
1361
|
+
S(this, "sweptTotalSats");
|
|
1367
1362
|
this.name = "ReclaimUneconomicalError", this.feeSats = o, this.sweptTotalSats = a;
|
|
1368
1363
|
}
|
|
1369
1364
|
}
|
|
1370
|
-
const oe = 2e3, ne = 25n, se = 100n,
|
|
1371
|
-
function
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1365
|
+
const oe = 2e3, ne = 25n, se = 100n, vr = 10n;
|
|
1366
|
+
async function Kt(e, t, r) {
|
|
1367
|
+
for (let o = 0; o < e.length; o++) {
|
|
1368
|
+
const a = Le(e[o].depositorSignedPeginTxHex), l = ie(
|
|
1369
|
+
await Xe(
|
|
1370
|
+
v(a),
|
|
1371
|
+
v(r)
|
|
1372
|
+
)
|
|
1373
|
+
).toLowerCase();
|
|
1374
|
+
if (l !== t[o].toLowerCase())
|
|
1375
|
+
throw new Error(
|
|
1376
|
+
`Reserve ${o} belongs to vault ${l}, not the requested ${t[o].toLowerCase()}. Refusing to sweep a reserve whose vault is not the one the caller asked for — the reserve funds that vault's claim transaction and cannot be replaced.`
|
|
1377
|
+
);
|
|
1379
1378
|
}
|
|
1380
|
-
return t.extractTransaction().toHex();
|
|
1381
1379
|
}
|
|
1382
|
-
async function
|
|
1380
|
+
async function Pr(e) {
|
|
1383
1381
|
const {
|
|
1384
1382
|
vaultIds: t,
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1383
|
+
depositorEthAddress: r,
|
|
1384
|
+
depositorBtcPubkey: o,
|
|
1385
|
+
readVaults: a,
|
|
1386
|
+
feeRate: l,
|
|
1387
|
+
signPsbt: s,
|
|
1388
|
+
broadcastTx: i,
|
|
1390
1389
|
signal: n
|
|
1391
1390
|
} = e;
|
|
1392
1391
|
if (n == null || n.throwIfAborted(), t.length === 0)
|
|
1393
1392
|
throw new Error("Reclaim requires at least one vault id; got none.");
|
|
1394
|
-
if (!Number.isFinite(
|
|
1395
|
-
throw new Error(`feeRate must be a positive number, got ${
|
|
1396
|
-
if (
|
|
1393
|
+
if (!Number.isFinite(l) || l <= 0)
|
|
1394
|
+
throw new Error(`feeRate must be a positive number, got ${l}`);
|
|
1395
|
+
if (l > oe)
|
|
1397
1396
|
throw new re(
|
|
1398
|
-
`Fee rate ${
|
|
1397
|
+
`Fee rate ${l} sat/vB exceeds the reclaim safety cap of ${oe} sat/vB; refusing to sign.`,
|
|
1399
1398
|
0n,
|
|
1400
1399
|
0n
|
|
1401
1400
|
);
|
|
1402
|
-
const
|
|
1403
|
-
if (n == null || n.throwIfAborted(),
|
|
1401
|
+
const u = await a();
|
|
1402
|
+
if (n == null || n.throwIfAborted(), u.length !== t.length)
|
|
1404
1403
|
throw new Error(
|
|
1405
|
-
`readVaults returned ${
|
|
1404
|
+
`readVaults returned ${u.length} reserves for ${t.length} vault id(s); refusing to sweep a set that does not match the request.`
|
|
1406
1405
|
);
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1406
|
+
await Kt(u, t, r), n == null || n.throwIfAborted();
|
|
1407
|
+
const h = O(o), c = u.map((k) => ({
|
|
1408
|
+
depositorSignedPeginTxHex: k.depositorSignedPeginTxHex,
|
|
1409
|
+
observed: k.observed,
|
|
1410
|
+
expectedValue: k.expectedClaimValue
|
|
1411
|
+
})), d = Fe(l, c.length), p = c.reduce((k, x) => k + x.expectedValue, 0n), g = p * ne / se;
|
|
1412
|
+
if (d > g)
|
|
1413
1413
|
throw new re(
|
|
1414
|
-
`Reclaim fee ${
|
|
1415
|
-
|
|
1416
|
-
|
|
1414
|
+
`Reclaim fee ${d} sats exceeds ${ne}/${se} of the swept total (${p} sats, cap ${g} sats). The reserve is not at risk — it stays where it is until fee rates fall.`,
|
|
1415
|
+
d,
|
|
1416
|
+
p
|
|
1417
1417
|
);
|
|
1418
1418
|
n == null || n.throwIfAborted();
|
|
1419
|
-
const { psbtHex:
|
|
1420
|
-
depositorPubkey:
|
|
1421
|
-
inputs:
|
|
1422
|
-
feeSats:
|
|
1419
|
+
const { psbtHex: P } = Me({
|
|
1420
|
+
depositorPubkey: h,
|
|
1421
|
+
inputs: c,
|
|
1422
|
+
feeSats: d
|
|
1423
1423
|
});
|
|
1424
1424
|
n == null || n.throwIfAborted();
|
|
1425
|
-
const
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
), f = await
|
|
1425
|
+
const m = K(
|
|
1426
|
+
o,
|
|
1427
|
+
c.length
|
|
1428
|
+
), f = await s(P, m);
|
|
1429
1429
|
B({
|
|
1430
|
-
requestedPsbtHex:
|
|
1430
|
+
requestedPsbtHex: P,
|
|
1431
1431
|
returnedPsbtHex: f
|
|
1432
|
-
})
|
|
1432
|
+
});
|
|
1433
|
+
const w = c.map((k, x) => {
|
|
1433
1434
|
const A = I(
|
|
1434
1435
|
f,
|
|
1435
|
-
|
|
1436
|
-
|
|
1436
|
+
h,
|
|
1437
|
+
x
|
|
1437
1438
|
);
|
|
1438
|
-
V({
|
|
1439
|
-
requestedPsbtHex:
|
|
1439
|
+
return V({
|
|
1440
|
+
requestedPsbtHex: P,
|
|
1440
1441
|
signatureHex: A,
|
|
1441
|
-
signerXOnlyPubkeyHex:
|
|
1442
|
-
inputIndex:
|
|
1443
|
-
});
|
|
1442
|
+
signerXOnlyPubkeyHex: h,
|
|
1443
|
+
inputIndex: x
|
|
1444
|
+
}), A;
|
|
1445
|
+
}), y = ce({
|
|
1446
|
+
requestedPsbtHex: P,
|
|
1447
|
+
signaturesHex: w,
|
|
1448
|
+
signerXOnlyPubkeyHex: h
|
|
1444
1449
|
});
|
|
1445
|
-
|
|
1446
|
-
return n == null || n.throwIfAborted(), s(P);
|
|
1450
|
+
return n == null || n.throwIfAborted(), i(y);
|
|
1447
1451
|
}
|
|
1448
1452
|
export {
|
|
1449
|
-
|
|
1453
|
+
vt as A,
|
|
1450
1454
|
Q as B,
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1455
|
+
yt as C,
|
|
1456
|
+
bt as D,
|
|
1457
|
+
ye as E,
|
|
1458
|
+
pr as F,
|
|
1459
|
+
gr as G,
|
|
1456
1460
|
At as H,
|
|
1457
|
-
|
|
1458
|
-
|
|
1461
|
+
mr as I,
|
|
1462
|
+
fr as J,
|
|
1459
1463
|
te as K,
|
|
1460
1464
|
ee as L,
|
|
1461
1465
|
Z as M,
|
|
1462
|
-
|
|
1466
|
+
we as N,
|
|
1463
1467
|
re as O,
|
|
1464
|
-
|
|
1465
|
-
|
|
1468
|
+
We as P,
|
|
1469
|
+
Pr as Q,
|
|
1466
1470
|
Pe as R,
|
|
1467
1471
|
se as S,
|
|
1468
1472
|
ne as T,
|
|
1469
1473
|
oe as U,
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1474
|
+
vr as V,
|
|
1475
|
+
Wt as a,
|
|
1476
|
+
Yt as b,
|
|
1477
|
+
de as c,
|
|
1478
|
+
pe as d,
|
|
1479
|
+
Jt as e,
|
|
1480
|
+
tr as f,
|
|
1481
|
+
nr as g,
|
|
1482
|
+
sr as h,
|
|
1483
|
+
et as i,
|
|
1484
|
+
ur as j,
|
|
1485
|
+
ir as k,
|
|
1486
|
+
ar as l,
|
|
1487
|
+
kt as m,
|
|
1488
|
+
Et as n,
|
|
1489
|
+
ve as o,
|
|
1490
|
+
lr as p,
|
|
1491
|
+
cr as q,
|
|
1492
|
+
er as r,
|
|
1493
|
+
it as s,
|
|
1494
|
+
hr as t,
|
|
1495
|
+
dr as u,
|
|
1496
|
+
or as v,
|
|
1497
|
+
Zt as w,
|
|
1498
|
+
ge as x,
|
|
1499
|
+
rr as y,
|
|
1496
1500
|
D as z
|
|
1497
1501
|
};
|
|
1498
|
-
//# sourceMappingURL=buildAndBroadcastReclaim-
|
|
1502
|
+
//# sourceMappingURL=buildAndBroadcastReclaim-YvWDRAN8.js.map
|