@babylonlabs-io/ts-sdk 3.0.2 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ApplicationRegistry.abi-s8cQ1ooR.js +160 -0
- package/dist/ApplicationRegistry.abi-s8cQ1ooR.js.map +1 -0
- package/dist/ApplicationRegistry.abi-sMiTWmnL.cjs +2 -0
- package/dist/ApplicationRegistry.abi-sMiTWmnL.cjs.map +1 -0
- package/dist/{BTCVaultRegistry.abi-BQ5tFNSu.cjs → BTCVaultRegistry.abi-CohlJX7c.cjs} +2 -2
- package/dist/{BTCVaultRegistry.abi-BQ5tFNSu.cjs.map → BTCVaultRegistry.abi-CohlJX7c.cjs.map} +1 -1
- package/dist/{BTCVaultRegistry.abi-B0x9_Bza.js → BTCVaultRegistry.abi-DBW0dyqH.js} +63 -1
- package/dist/{BTCVaultRegistry.abi-B0x9_Bza.js.map → BTCVaultRegistry.abi-DBW0dyqH.js.map} +1 -1
- package/dist/{PayoutManager-BSwbUQeF.js → PayoutManager-BZ212yml.js} +124 -123
- package/dist/PayoutManager-BZ212yml.js.map +1 -0
- package/dist/PayoutManager-DOdsgcUR.cjs +2 -0
- package/dist/PayoutManager-DOdsgcUR.cjs.map +1 -0
- package/dist/PeginManager-8EUlm10F.cjs +2 -0
- package/dist/{PeginManager-IgDHy_eU.cjs.map → PeginManager-8EUlm10F.cjs.map} +1 -1
- package/dist/{PeginManager-D8WGB8eN.js → PeginManager-QRwMUxZg.js} +45 -43
- package/dist/{PeginManager-D8WGB8eN.js.map → PeginManager-QRwMUxZg.js.map} +1 -1
- package/dist/{ProtocolParams.abi-q0AidvYX.js → ProtocolParams.abi-CKOVqFJP.js} +2 -158
- package/dist/ProtocolParams.abi-CKOVqFJP.js.map +1 -0
- package/dist/ProtocolParams.abi-CjrT0545.cjs +2 -0
- package/dist/ProtocolParams.abi-CjrT0545.cjs.map +1 -0
- package/dist/btcTxHash-BRZ8_EZq.js +9 -0
- package/dist/btcTxHash-BRZ8_EZq.js.map +1 -0
- package/dist/btcTxHash-CGb5BqFL.cjs +2 -0
- package/dist/btcTxHash-CGb5BqFL.cjs.map +1 -0
- package/dist/buildAndBroadcastReclaim-DjX7wVb2.cjs +2 -0
- package/dist/buildAndBroadcastReclaim-DjX7wVb2.cjs.map +1 -0
- package/dist/buildAndBroadcastReclaim-DoprHX7o.js +3077 -0
- package/dist/buildAndBroadcastReclaim-DoprHX7o.js.map +1 -0
- package/dist/buildVaultContextInputForClaim-9XZaqIiw.cjs +2 -0
- package/dist/buildVaultContextInputForClaim-9XZaqIiw.cjs.map +1 -0
- package/dist/buildVaultContextInputForClaim-DhBoQKyN.js +25 -0
- package/dist/buildVaultContextInputForClaim-DhBoQKyN.js.map +1 -0
- package/dist/constants-BeYquVd-.js +36 -0
- package/dist/constants-BeYquVd-.js.map +1 -0
- package/dist/constants-BwCg5K6R.cjs +2 -0
- package/dist/constants-BwCg5K6R.cjs.map +1 -0
- package/dist/{index-D2mybjXD.js → index-CVBtBjQ5.js} +2 -2
- package/dist/{index-D2mybjXD.js.map → index-CVBtBjQ5.js.map} +1 -1
- package/dist/{index-MRdle0fs.cjs → index-DpjYs5yr.cjs} +2 -2
- package/dist/{index-MRdle0fs.cjs.map → index-DpjYs5yr.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +288 -260
- package/dist/index.js.map +1 -1
- package/dist/{noPayout-qBXWKwav.js → noPayout-B-vGXJ-V.js} +3 -3
- package/dist/{noPayout-qBXWKwav.js.map → noPayout-B-vGXJ-V.js.map} +1 -1
- package/dist/{noPayout-DAWBQ0eG.cjs → noPayout-DOHak0ui.cjs} +2 -2
- package/dist/{noPayout-DAWBQ0eG.cjs.map → noPayout-DOHak0ui.cjs.map} +1 -1
- package/dist/pegin-registration-client-BWMwxtr8.js +718 -0
- package/dist/pegin-registration-client-BWMwxtr8.js.map +1 -0
- package/dist/pegin-registration-client-D4EguWaz.cjs +2 -0
- package/dist/pegin-registration-client-D4EguWaz.cjs.map +1 -0
- package/dist/{primeVpAuth-BDWBKYhv.cjs → primeVpAuth-BPj2TPdD.cjs} +2 -2
- package/dist/{primeVpAuth-BDWBKYhv.cjs.map → primeVpAuth-BPj2TPdD.cjs.map} +1 -1
- package/dist/{primeVpAuth-D0ZnsjRi.js → primeVpAuth-CiCdRNGf.js} +2 -2
- package/dist/{primeVpAuth-D0ZnsjRi.js.map → primeVpAuth-CiCdRNGf.js.map} +1 -1
- package/dist/registration-records-CKLAv3gw.js +447 -0
- package/dist/registration-records-CKLAv3gw.js.map +1 -0
- package/dist/registration-records-DFQgBaYi.cjs +2 -0
- package/dist/registration-records-DFQgBaYi.cjs.map +1 -0
- package/dist/{secp256k1-D-H9jmd7.js → secp256k1-BuxBFUHm.js} +3 -3
- package/dist/{secp256k1-D-H9jmd7.js.map → secp256k1-BuxBFUHm.js.map} +1 -1
- package/dist/signer-set-reader-C1VmC9_U.js +264 -0
- package/dist/signer-set-reader-C1VmC9_U.js.map +1 -0
- package/dist/signer-set-reader-C6g47hdk.cjs +2 -0
- package/dist/signer-set-reader-C6g47hdk.cjs.map +1 -0
- package/dist/{signing-Dhr2t0Z6.js → signing-C1rR4tqs.js} +9 -15
- package/dist/signing-C1rR4tqs.js.map +1 -0
- package/dist/signing-DvISftFk.cjs +2 -0
- package/dist/signing-DvISftFk.cjs.map +1 -0
- package/dist/tbv/core/clients/eth/__tests__/registration-records.test.d.ts +2 -0
- package/dist/tbv/core/clients/eth/__tests__/registration-records.test.d.ts.map +1 -0
- package/dist/tbv/core/clients/eth/claimable-event-error.d.ts +14 -0
- package/dist/tbv/core/clients/eth/claimable-event-error.d.ts.map +1 -0
- package/dist/tbv/core/clients/eth/index.cjs +1 -1
- package/dist/tbv/core/clients/eth/index.d.ts +3 -1
- package/dist/tbv/core/clients/eth/index.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/index.js +27 -21
- package/dist/tbv/core/clients/eth/index.js.map +1 -1
- package/dist/tbv/core/clients/eth/payout-script.d.ts +8 -0
- package/dist/tbv/core/clients/eth/payout-script.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/protocol-params-reader.d.ts +13 -0
- package/dist/tbv/core/clients/eth/protocol-params-reader.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/registration-logs-error.d.ts +11 -1
- package/dist/tbv/core/clients/eth/registration-logs-error.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/registration-records.d.ts +29 -0
- package/dist/tbv/core/clients/eth/registration-records.d.ts.map +1 -0
- package/dist/tbv/core/clients/eth/types.d.ts +120 -3
- package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts +9 -10
- 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 +56 -50
- package/dist/tbv/core/clients/index.js.map +1 -1
- 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 +45 -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 +16 -15
- package/dist/tbv/core/contracts/index.js.map +1 -1
- package/dist/tbv/core/deposit-terms/__tests__/claimSiblings.test.d.ts +2 -0
- package/dist/tbv/core/deposit-terms/__tests__/claimSiblings.test.d.ts.map +1 -0
- package/dist/tbv/core/deposit-terms/__tests__/fixtures/realFundedPrePegin.d.ts +29 -0
- package/dist/tbv/core/deposit-terms/__tests__/fixtures/realFundedPrePegin.d.ts.map +1 -0
- package/dist/tbv/core/deposit-terms/__tests__/fundedPrePeginFee.test.d.ts +2 -0
- package/dist/tbv/core/deposit-terms/__tests__/fundedPrePeginFee.test.d.ts.map +1 -0
- package/dist/tbv/core/deposit-terms/__tests__/rebuildDepositTermsForClaim.golden.test.d.ts +2 -0
- package/dist/tbv/core/deposit-terms/__tests__/rebuildDepositTermsForClaim.golden.test.d.ts.map +1 -0
- package/dist/tbv/core/deposit-terms/__tests__/rebuildDepositTermsForClaim.test.d.ts +2 -0
- package/dist/tbv/core/deposit-terms/__tests__/rebuildDepositTermsForClaim.test.d.ts.map +1 -0
- package/dist/tbv/core/deposit-terms/claimSiblings.d.ts +23 -0
- package/dist/tbv/core/deposit-terms/claimSiblings.d.ts.map +1 -0
- package/dist/tbv/core/deposit-terms/fundedPrePeginFee.d.ts +15 -0
- package/dist/tbv/core/deposit-terms/fundedPrePeginFee.d.ts.map +1 -0
- package/dist/tbv/core/deposit-terms/index.d.ts +3 -0
- package/dist/tbv/core/deposit-terms/index.d.ts.map +1 -1
- package/dist/tbv/core/deposit-terms/rebuildDepositTermsForClaim.d.ts +40 -0
- package/dist/tbv/core/deposit-terms/rebuildDepositTermsForClaim.d.ts.map +1 -0
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +287 -259
- 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/managers/pegin/signPsbtsWithFallback.d.ts +6 -2
- package/dist/tbv/core/managers/pegin/signPsbtsWithFallback.d.ts.map +1 -1
- package/dist/tbv/core/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.js +4 -4
- package/dist/tbv/core/primitives/psbt/constants.d.ts +54 -6
- package/dist/tbv/core/primitives/psbt/constants.d.ts.map +1 -1
- package/dist/tbv/core/services/delegated-claim/__tests__/assembleWatchtowerArtifactsFromSignatures.test.d.ts +2 -0
- package/dist/tbv/core/services/delegated-claim/__tests__/assembleWatchtowerArtifactsFromSignatures.test.d.ts.map +1 -0
- package/dist/tbv/core/services/delegated-claim/__tests__/assertBinding.test.d.ts +2 -0
- package/dist/tbv/core/services/delegated-claim/__tests__/assertBinding.test.d.ts.map +1 -0
- package/dist/tbv/core/services/delegated-claim/__tests__/assertPayoutFeeAndTimelocks.test.d.ts +2 -0
- package/dist/tbv/core/services/delegated-claim/__tests__/assertPayoutFeeAndTimelocks.test.d.ts.map +1 -0
- package/dist/tbv/core/services/delegated-claim/__tests__/fixtures/delegatedClaimPsbts.d.ts +49 -0
- package/dist/tbv/core/services/delegated-claim/__tests__/fixtures/delegatedClaimPsbts.d.ts.map +1 -0
- package/dist/tbv/core/services/delegated-claim/__tests__/payoutBinding.test.d.ts +2 -0
- package/dist/tbv/core/services/delegated-claim/__tests__/payoutBinding.test.d.ts.map +1 -0
- package/dist/tbv/core/services/delegated-claim/__tests__/payoutInputLeaf.test.d.ts +2 -0
- package/dist/tbv/core/services/delegated-claim/__tests__/payoutInputLeaf.test.d.ts.map +1 -0
- package/dist/tbv/core/services/delegated-claim/__tests__/planDelegatedClaimSigning.test.d.ts +2 -0
- package/dist/tbv/core/services/delegated-claim/__tests__/planDelegatedClaimSigning.test.d.ts.map +1 -0
- package/dist/tbv/core/services/delegated-claim/__tests__/readDelegatedClaimVaultContext.test.d.ts +2 -0
- package/dist/tbv/core/services/delegated-claim/__tests__/readDelegatedClaimVaultContext.test.d.ts.map +1 -0
- package/dist/tbv/core/services/delegated-claim/__tests__/realSchnorrVerification.test.d.ts +2 -0
- package/dist/tbv/core/services/delegated-claim/__tests__/realSchnorrVerification.test.d.ts.map +1 -0
- package/dist/tbv/core/services/delegated-claim/__tests__/signDelegatedClaimPlan.test.d.ts +2 -0
- package/dist/tbv/core/services/delegated-claim/__tests__/signDelegatedClaimPlan.test.d.ts.map +1 -0
- package/dist/tbv/core/services/delegated-claim/__tests__/signingRequests.test.d.ts +2 -0
- package/dist/tbv/core/services/delegated-claim/__tests__/signingRequests.test.d.ts.map +1 -0
- package/dist/tbv/core/services/delegated-claim/assembleWatchtowerArtifacts.d.ts +34 -9
- package/dist/tbv/core/services/delegated-claim/assembleWatchtowerArtifacts.d.ts.map +1 -1
- package/dist/tbv/core/services/delegated-claim/assembleWatchtowerArtifactsFromSignatures.d.ts +36 -0
- package/dist/tbv/core/services/delegated-claim/assembleWatchtowerArtifactsFromSignatures.d.ts.map +1 -0
- package/dist/tbv/core/services/delegated-claim/assertBinding.d.ts +37 -0
- package/dist/tbv/core/services/delegated-claim/assertBinding.d.ts.map +1 -0
- package/dist/tbv/core/services/delegated-claim/assertPayoutFeeAndTimelocks.d.ts +35 -0
- package/dist/tbv/core/services/delegated-claim/assertPayoutFeeAndTimelocks.d.ts.map +1 -0
- package/dist/tbv/core/services/delegated-claim/index.d.ts +22 -4
- package/dist/tbv/core/services/delegated-claim/index.d.ts.map +1 -1
- package/dist/tbv/core/services/delegated-claim/payoutBinding.d.ts +10 -4
- package/dist/tbv/core/services/delegated-claim/payoutBinding.d.ts.map +1 -1
- package/dist/tbv/core/services/delegated-claim/payoutInputLeaf.d.ts +34 -0
- package/dist/tbv/core/services/delegated-claim/payoutInputLeaf.d.ts.map +1 -0
- package/dist/tbv/core/services/delegated-claim/planDelegatedClaimSigning.d.ts +43 -0
- package/dist/tbv/core/services/delegated-claim/planDelegatedClaimSigning.d.ts.map +1 -0
- package/dist/tbv/core/services/delegated-claim/readDelegatedClaimVaultContext.d.ts +70 -0
- package/dist/tbv/core/services/delegated-claim/readDelegatedClaimVaultContext.d.ts.map +1 -0
- package/dist/tbv/core/services/delegated-claim/readWatchtowerArtifacts.d.ts +31 -2
- package/dist/tbv/core/services/delegated-claim/readWatchtowerArtifacts.d.ts.map +1 -1
- package/dist/tbv/core/services/delegated-claim/signDelegatedClaimPlan.d.ts +110 -0
- package/dist/tbv/core/services/delegated-claim/signDelegatedClaimPlan.d.ts.map +1 -0
- package/dist/tbv/core/services/delegated-claim/signingRequests.d.ts +24 -0
- package/dist/tbv/core/services/delegated-claim/signingRequests.d.ts.map +1 -0
- package/dist/tbv/core/services/delegated-claim/types.d.ts +110 -9
- package/dist/tbv/core/services/delegated-claim/types.d.ts.map +1 -1
- package/dist/tbv/core/services/delegated-claim/vaultIdBinding.d.ts +16 -1
- package/dist/tbv/core/services/delegated-claim/vaultIdBinding.d.ts.map +1 -1
- package/dist/tbv/core/services/delegated-claim/verifySignatureForRequest.d.ts +19 -0
- package/dist/tbv/core/services/delegated-claim/verifySignatureForRequest.d.ts.map +1 -0
- package/dist/tbv/core/services/delegated-claim/verifyingKeyBinding.d.ts +40 -0
- package/dist/tbv/core/services/delegated-claim/verifyingKeyBinding.d.ts.map +1 -0
- package/dist/tbv/core/services/delegated-claim/walletIdentity.d.ts +23 -0
- package/dist/tbv/core/services/delegated-claim/walletIdentity.d.ts.map +1 -0
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +89 -76
- package/dist/tbv/core/services/participants/__tests__/readStampedParticipantKeys.test.d.ts +2 -0
- package/dist/tbv/core/services/participants/__tests__/readStampedParticipantKeys.test.d.ts.map +1 -0
- package/dist/tbv/core/services/participants/index.d.ts +1 -0
- package/dist/tbv/core/services/participants/index.d.ts.map +1 -1
- package/dist/tbv/core/services/participants/readStampedParticipantKeys.d.ts +29 -0
- package/dist/tbv/core/services/participants/readStampedParticipantKeys.d.ts.map +1 -0
- package/dist/tbv/core/services/participants/resolveParticipantKeys.d.ts +1 -1
- package/dist/tbv/core/services/participants/resolveParticipantKeys.d.ts.map +1 -1
- package/dist/tbv/core/utils/index.cjs +1 -1
- package/dist/tbv/core/utils/index.js +47 -46
- package/dist/tbv/core/utils/index.js.map +1 -1
- package/dist/tbv/core/vault-secrets/__tests__/buildVaultContextInputForClaim.test.d.ts +2 -0
- package/dist/tbv/core/vault-secrets/__tests__/buildVaultContextInputForClaim.test.d.ts.map +1 -0
- package/dist/tbv/core/vault-secrets/buildVaultContextInputForClaim.d.ts +18 -0
- package/dist/tbv/core/vault-secrets/buildVaultContextInputForClaim.d.ts.map +1 -0
- package/dist/tbv/core/vault-secrets/index.cjs +1 -1
- package/dist/tbv/core/vault-secrets/index.d.ts +1 -0
- package/dist/tbv/core/vault-secrets/index.d.ts.map +1 -1
- package/dist/tbv/core/vault-secrets/index.js +12 -10
- package/dist/tbv/core/vault-secrets/index.js.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +287 -259
- package/dist/tbv/index.js.map +1 -1
- package/dist/toRefundInputs-BZXvuOMY.cjs +2 -0
- package/dist/toRefundInputs-BZXvuOMY.cjs.map +1 -0
- package/dist/toRefundInputs-dKDSvpVI.js +698 -0
- package/dist/toRefundInputs-dKDSvpVI.js.map +1 -0
- package/dist/types-Bda75Od0.cjs +2 -0
- package/dist/types-Bda75Od0.cjs.map +1 -0
- package/dist/types-C5jj3Cc-.js +198 -0
- package/dist/types-C5jj3Cc-.js.map +1 -0
- package/dist/{verifyKeyPathSchnorrSignature-Gm9EmZkx.cjs → verifyKeyPathSchnorrSignature-CQUut2-O.cjs} +2 -2
- package/dist/{verifyKeyPathSchnorrSignature-Gm9EmZkx.cjs.map → verifyKeyPathSchnorrSignature-CQUut2-O.cjs.map} +1 -1
- package/dist/{verifyKeyPathSchnorrSignature-BQHNhRj6.js → verifyKeyPathSchnorrSignature-DxPbeSdQ.js} +2 -2
- package/dist/{verifyKeyPathSchnorrSignature-BQHNhRj6.js.map → verifyKeyPathSchnorrSignature-DxPbeSdQ.js.map} +1 -1
- package/dist/{verifyScriptPathSchnorrSignature-CpjSTfMj.js → verifyScriptPathSchnorrSignature-B3-VkvnK.js} +6 -4
- package/dist/{verifyScriptPathSchnorrSignature-CpjSTfMj.js.map → verifyScriptPathSchnorrSignature-B3-VkvnK.js.map} +1 -1
- package/dist/{verifyScriptPathSchnorrSignature-BKZihCjk.cjs → verifyScriptPathSchnorrSignature-D2t1yACC.cjs} +2 -2
- package/dist/{verifyScriptPathSchnorrSignature-BKZihCjk.cjs.map → verifyScriptPathSchnorrSignature-D2t1yACC.cjs.map} +1 -1
- package/package.json +4 -4
- package/dist/PayoutManager-B6GFbG3X.cjs +0 -2
- package/dist/PayoutManager-B6GFbG3X.cjs.map +0 -1
- package/dist/PayoutManager-BSwbUQeF.js.map +0 -1
- package/dist/PeginManager-IgDHy_eU.cjs +0 -2
- package/dist/ProtocolParams.abi-Db2USqQm.cjs +0 -2
- package/dist/ProtocolParams.abi-Db2USqQm.cjs.map +0 -1
- package/dist/ProtocolParams.abi-q0AidvYX.js.map +0 -1
- package/dist/buildAndBroadcastReclaim-B8aFMGf-.cjs +0 -2
- package/dist/buildAndBroadcastReclaim-B8aFMGf-.cjs.map +0 -1
- package/dist/buildAndBroadcastReclaim-D5520lbL.js +0 -2210
- package/dist/buildAndBroadcastReclaim-D5520lbL.js.map +0 -1
- package/dist/constants-BTZdyOuk.cjs +0 -2
- package/dist/constants-BTZdyOuk.cjs.map +0 -1
- package/dist/constants-D5vORbQE.js +0 -29
- package/dist/constants-D5vORbQE.js.map +0 -1
- package/dist/onChainBtcPubkey-BlzxYImF.cjs +0 -2
- package/dist/onChainBtcPubkey-BlzxYImF.cjs.map +0 -1
- package/dist/onChainBtcPubkey-CCTdl53s.js +0 -159
- package/dist/onChainBtcPubkey-CCTdl53s.js.map +0 -1
- package/dist/pegin-registration-client-B0j6ugt9.cjs +0 -2
- package/dist/pegin-registration-client-B0j6ugt9.cjs.map +0 -1
- package/dist/pegin-registration-client-ilkV1mLP.js +0 -878
- package/dist/pegin-registration-client-ilkV1mLP.js.map +0 -1
- package/dist/signing-3l5Aqd-H.cjs +0 -2
- package/dist/signing-3l5Aqd-H.cjs.map +0 -1
- package/dist/signing-Dhr2t0Z6.js.map +0 -1
- package/dist/toRefundInputs-10RYIfh1.js +0 -559
- package/dist/toRefundInputs-10RYIfh1.js.map +0 -1
- package/dist/toRefundInputs-a-0HRyrl.cjs +0 -2
- package/dist/toRefundInputs-a-0HRyrl.cjs.map +0 -1
- package/dist/types-BueQoMjO.cjs +0 -2
- package/dist/types-BueQoMjO.cjs.map +0 -1
- package/dist/types-DGkejGZH.js +0 -456
- package/dist/types-DGkejGZH.js.map +0 -1
|
@@ -0,0 +1,3077 @@
|
|
|
1
|
+
var Jt = Object.defineProperty;
|
|
2
|
+
var Zt = (e, t, r) => t in e ? Jt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var z = (e, t, r) => Zt(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { B as ft } from "./BTCVaultRegistry.abi-DBW0dyqH.js";
|
|
5
|
+
import { e as Be, s as b, i as er, u as Ie, c as _, v as tr, p as he, f as N } from "./bitcoin-C-TuHb-v.js";
|
|
6
|
+
import { v as rr, s as yt, b as vt, P as or, d as sr } from "./PayoutManager-BZ212yml.js";
|
|
7
|
+
import { verifyWatchtowerArtifacts as nr, buildClaimPsbt as ir, buildAssertClaimerPsbt as ar, buildPayoutClaimerPsbt as ur, buildWronglyChallengedPsbts as cr, buildPayoutDepositorPsbt as lr, finalizeClaimTx as dr, buildWatchtowerArtifacts as hr, extractTapScriptSig as bt, expandWotsSeed as pr, wotsKeypairFromSeed as gr, validateWotsKeypairAgainstGraph as fr, deriveVaultId as yr } from "./tbv/core/wasm/index.js";
|
|
8
|
+
import { m as vr, d as Pt, k as br, a as _e, V as Me, i as Pr, g as mr, f as wr, r as xr, h as Er } from "./registration-records-CKLAv3gw.js";
|
|
9
|
+
import { Psbt as q, Transaction as S } from "bitcoinjs-lib";
|
|
10
|
+
import { q as F, r as A, s as ee, C as Y, A as te, p as Q, t as pe, l as Le, N as J, u as Ve, m as Fe, n as Ue, o as qe, W as $r, D as Xe } from "./constants-BeYquVd-.js";
|
|
11
|
+
import { p as kr, q as Cr, r as mt, P as X, j as re, f as Tr, i as ie, g as ae } from "./verifyScriptPathSchnorrSignature-B3-VkvnK.js";
|
|
12
|
+
import { Buffer as H } from "buffer";
|
|
13
|
+
import { C as wt, X as xt } from "./validation-OSC0xTHB.js";
|
|
14
|
+
import { a as Et, c as ue } from "./signing-C1rR4tqs.js";
|
|
15
|
+
import { d as $t } from "./deriveVaultRoot-BcvmER1E.js";
|
|
16
|
+
import { O as Ge, d as _r } from "./types-C5jj3Cc-.js";
|
|
17
|
+
import { zeroAddress as Sr, isAddress as Ar, isAddressEqual as Br } from "viem";
|
|
18
|
+
import { v as ze, D as R, c as Ir, b as Vr, R as Rr, d as kt } from "./state-CFn1rT74.js";
|
|
19
|
+
import { h as je, b as Kr, s as Hr, j as Or } from "./sha2-YqVHJiFj.js";
|
|
20
|
+
import { d as Nr, c as Dr, b as Mr, f as Ct, e as Lr, a as Fr } from "./noPayout-B-vGXJ-V.js";
|
|
21
|
+
import { a as Ur } from "./secp256k1-BuxBFUHm.js";
|
|
22
|
+
import { c as qr } from "./btcTxHash-BRZ8_EZq.js";
|
|
23
|
+
const Xr = /^0x[0-9a-fA-F]{64}$/, Gr = /^0x[0-9a-fA-F]{40}$/, zr = /^0x([0-9a-fA-F]{2})*$/;
|
|
24
|
+
function fe(e, t) {
|
|
25
|
+
if (e.length !== 66)
|
|
26
|
+
throw new Error(
|
|
27
|
+
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
28
|
+
);
|
|
29
|
+
if (!Xr.test(e))
|
|
30
|
+
throw new Error(
|
|
31
|
+
`${t} must contain only hex characters after the 0x prefix`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
function jr(e, t) {
|
|
35
|
+
if (!Gr.test(e))
|
|
36
|
+
throw new Error(
|
|
37
|
+
`${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
function Wr(e, t) {
|
|
41
|
+
if (!zr.test(e))
|
|
42
|
+
throw new Error(
|
|
43
|
+
`${t} must be a 0x-prefixed hex string with an even number of hex chars`
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
function Tt(e) {
|
|
47
|
+
jr(e.btcVaultRegistryAddress, "btcVaultRegistryAddress"), fe(e.vaultId, "vaultId");
|
|
48
|
+
const t = Be(e.secret);
|
|
49
|
+
if (fe(t, "secret"), e.hashlock !== void 0 && (fe(e.hashlock, "hashlock"), !rr(t, e.hashlock)))
|
|
50
|
+
throw new Error(
|
|
51
|
+
"Invalid secret: SHA256(secret) does not match the provided hashlock"
|
|
52
|
+
);
|
|
53
|
+
return t;
|
|
54
|
+
}
|
|
55
|
+
async function Ys(e) {
|
|
56
|
+
const {
|
|
57
|
+
btcVaultRegistryAddress: t,
|
|
58
|
+
vaultId: r,
|
|
59
|
+
hashlock: o,
|
|
60
|
+
activationMetadata: s,
|
|
61
|
+
writeContract: n,
|
|
62
|
+
signal: a
|
|
63
|
+
} = e;
|
|
64
|
+
a == null || a.throwIfAborted();
|
|
65
|
+
const i = Tt({
|
|
66
|
+
btcVaultRegistryAddress: t,
|
|
67
|
+
vaultId: r,
|
|
68
|
+
secret: e.secret,
|
|
69
|
+
hashlock: o
|
|
70
|
+
});
|
|
71
|
+
return Wr(s, "activationMetadata"), n({
|
|
72
|
+
address: t,
|
|
73
|
+
abi: ft,
|
|
74
|
+
functionName: "activateVaultWithSecret",
|
|
75
|
+
args: [r, i, s]
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
async function Qs(e) {
|
|
79
|
+
const { btcVaultRegistryAddress: t, vaultId: r, hashlock: o, writeContract: s, signal: n } = e;
|
|
80
|
+
n == null || n.throwIfAborted();
|
|
81
|
+
const a = Tt({
|
|
82
|
+
btcVaultRegistryAddress: t,
|
|
83
|
+
vaultId: r,
|
|
84
|
+
secret: e.secret,
|
|
85
|
+
hashlock: o
|
|
86
|
+
});
|
|
87
|
+
return s({
|
|
88
|
+
address: t,
|
|
89
|
+
abi: ft,
|
|
90
|
+
functionName: "activateVaultWithSecretAndRedeem",
|
|
91
|
+
args: [r, a]
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
class K extends Error {
|
|
95
|
+
constructor(t, r) {
|
|
96
|
+
super(t, r), this.name = "AssertBindingError";
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function ye(e, t) {
|
|
100
|
+
try {
|
|
101
|
+
return q.fromBase64(t);
|
|
102
|
+
} catch (r) {
|
|
103
|
+
throw new K(`${e} PSBT cannot be parsed.`, { cause: r });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function Yr(e, t, r) {
|
|
107
|
+
const o = t.txInputs[r];
|
|
108
|
+
if (!o)
|
|
109
|
+
throw new K(`${e} PSBT has no input ${r}.`);
|
|
110
|
+
return o.hash;
|
|
111
|
+
}
|
|
112
|
+
function We(e) {
|
|
113
|
+
return S.fromBuffer(
|
|
114
|
+
e.data.globalMap.unsignedTx.toBuffer()
|
|
115
|
+
).getHash();
|
|
116
|
+
}
|
|
117
|
+
function ve(e, t, r, o, s, n) {
|
|
118
|
+
const a = t.txInputs[r];
|
|
119
|
+
if (!a)
|
|
120
|
+
throw new K(`${e} PSBT has no input ${r}.`);
|
|
121
|
+
if (!a.hash.equals(o) || a.index !== s)
|
|
122
|
+
throw new K(
|
|
123
|
+
`${e} input ${r} does not spend ${n}: the graph pairs this ${e} with a different transaction.`
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
function Qr(e, t) {
|
|
127
|
+
var s;
|
|
128
|
+
const r = (s = e.data.inputs[F]) == null ? void 0 : s.witnessUtxo;
|
|
129
|
+
if (r === void 0)
|
|
130
|
+
throw new K(
|
|
131
|
+
`Assert input ${F} carries no witnessUtxo, so the amount and script its signature commits to cannot be checked; refusing to sign assert.`
|
|
132
|
+
);
|
|
133
|
+
const o = t.txOutputs[Y];
|
|
134
|
+
if (!o)
|
|
135
|
+
throw new K(
|
|
136
|
+
`Claim PSBT has no output ${Y} for the Assert to spend; refusing to sign assert.`
|
|
137
|
+
);
|
|
138
|
+
if (r.value !== o.value)
|
|
139
|
+
throw new K(
|
|
140
|
+
`Assert input ${F} declares a prevout of ${r.value} sats but the Claim's output ${Y} is worth ${o.value}; refusing to sign assert.`
|
|
141
|
+
);
|
|
142
|
+
if (!r.script.equals(o.script))
|
|
143
|
+
throw new K(
|
|
144
|
+
`Assert input ${F} declares a prevout script that is not the Claim's output ${Y} script; refusing to sign assert.`
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
function Jr(e) {
|
|
148
|
+
const t = ye("Claim", e.claimPsbtBase64), r = ye("Assert", e.assertPsbtBase64), o = ye("Payout", e.payoutClaimerPsbtBase64);
|
|
149
|
+
ve(
|
|
150
|
+
"Assert",
|
|
151
|
+
r,
|
|
152
|
+
F,
|
|
153
|
+
We(t),
|
|
154
|
+
Y,
|
|
155
|
+
"Claim:0"
|
|
156
|
+
), Qr(r, t), ve(
|
|
157
|
+
"Payout",
|
|
158
|
+
o,
|
|
159
|
+
A,
|
|
160
|
+
We(r),
|
|
161
|
+
te,
|
|
162
|
+
"Assert:0"
|
|
163
|
+
), ve(
|
|
164
|
+
"Payout",
|
|
165
|
+
o,
|
|
166
|
+
ee,
|
|
167
|
+
Yr("Claim", t, pe),
|
|
168
|
+
Q,
|
|
169
|
+
"this vault's PegIn:0"
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
function be(e, t) {
|
|
173
|
+
try {
|
|
174
|
+
return q.fromBase64(t);
|
|
175
|
+
} catch (r) {
|
|
176
|
+
throw new Error(`${e} PSBT cannot be parsed.`, { cause: r });
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function Ye(e, t, r, o) {
|
|
180
|
+
var a;
|
|
181
|
+
const s = [
|
|
182
|
+
{
|
|
183
|
+
inputIndex: ee,
|
|
184
|
+
expectedSats: r,
|
|
185
|
+
source: `the vault's PegIn output ${Q}`
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
inputIndex: A,
|
|
189
|
+
expectedSats: o.value,
|
|
190
|
+
source: `the Assert's output ${te}`
|
|
191
|
+
}
|
|
192
|
+
];
|
|
193
|
+
for (const { inputIndex: i, expectedSats: u, source: l } of s) {
|
|
194
|
+
const c = (a = t.data.inputs[i]) == null ? void 0 : a.witnessUtxo;
|
|
195
|
+
if (c === void 0)
|
|
196
|
+
throw new Error(
|
|
197
|
+
`${e} Payout input ${i} carries no witnessUtxo, so the amount its signature commits to cannot be checked; refusing to sign payout.`
|
|
198
|
+
);
|
|
199
|
+
if (c.value !== u)
|
|
200
|
+
throw new Error(
|
|
201
|
+
`${e} Payout input ${i} declares a prevout of ${c.value} sats but ${l} is worth ${u}; refusing to sign payout.`
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
const n = t.data.inputs[A].witnessUtxo;
|
|
205
|
+
if (!(n != null && n.script.equals(o.script)))
|
|
206
|
+
throw new Error(
|
|
207
|
+
`${e} Payout input ${A} declares a prevout script that is not the Assert's output ${te} script; refusing to sign payout.`
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
async function Zr(e) {
|
|
211
|
+
const { vault: t } = e, r = {
|
|
212
|
+
vaultCoreVersion: t.vaultCoreVersion,
|
|
213
|
+
numVaultKeepers: t.vaultKeeperBtcPubkeys.length,
|
|
214
|
+
numUniversalChallengers: t.universalChallengerBtcPubkeys.length,
|
|
215
|
+
councilSize: t.councilSize,
|
|
216
|
+
protocolFeeRate: t.protocolFeeRate
|
|
217
|
+
};
|
|
218
|
+
kr(r);
|
|
219
|
+
const o = be("Claimer Payout", e.payoutClaimerPsbtBase64), s = be(
|
|
220
|
+
"Depositor Payout",
|
|
221
|
+
e.payoutDepositorPsbtBase64
|
|
222
|
+
), n = be("Assert", e.assertPsbtBase64);
|
|
223
|
+
if (!s.data.globalMap.unsignedTx.toBuffer().equals(o.data.globalMap.unsignedTx.toBuffer()))
|
|
224
|
+
throw new Error(
|
|
225
|
+
"Depositor and claimer Payout PSBTs describe different transactions; refusing to sign payout."
|
|
226
|
+
);
|
|
227
|
+
const a = n.txOutputs[te];
|
|
228
|
+
if (a === void 0)
|
|
229
|
+
throw new Error(
|
|
230
|
+
`Assert transaction has no output ${te}; the Payout's implicit fee cannot be measured.`
|
|
231
|
+
);
|
|
232
|
+
if (o.txInputs.length !== Le)
|
|
233
|
+
throw new Error(
|
|
234
|
+
`Payout transaction must have exactly ${Le} inputs, got ${o.txInputs.length}`
|
|
235
|
+
);
|
|
236
|
+
const i = o.txInputs[ee].sequence;
|
|
237
|
+
if (i !== t.timelockPegin)
|
|
238
|
+
throw new Error(
|
|
239
|
+
`Payout input ${ee} sequence ${i} must equal the PegIn CSV timelock ${t.timelockPegin}; refusing to sign payout.`
|
|
240
|
+
);
|
|
241
|
+
const u = o.txInputs[A].sequence;
|
|
242
|
+
if (u !== t.timelockAssert)
|
|
243
|
+
throw new Error(
|
|
244
|
+
`Payout input ${A} sequence ${u} must equal the Assert CSV timelock ${t.timelockAssert}; refusing to sign payout.`
|
|
245
|
+
);
|
|
246
|
+
Ye(
|
|
247
|
+
"Claimer",
|
|
248
|
+
o,
|
|
249
|
+
t.peginVaultOutputValueSats,
|
|
250
|
+
a
|
|
251
|
+
), Ye(
|
|
252
|
+
"Depositor",
|
|
253
|
+
s,
|
|
254
|
+
t.peginVaultOutputValueSats,
|
|
255
|
+
a
|
|
256
|
+
);
|
|
257
|
+
const l = t.peginVaultOutputValueSats + a.value, c = o.txOutputs;
|
|
258
|
+
if (c.length !== J)
|
|
259
|
+
throw new Error(
|
|
260
|
+
`Payout transaction has ${c.length} output(s), expected exactly ${J} for a depositor-as-claimer payout.`
|
|
261
|
+
);
|
|
262
|
+
let d = 0;
|
|
263
|
+
for (const h of c) d += h.value;
|
|
264
|
+
if (d > l)
|
|
265
|
+
throw new Error(
|
|
266
|
+
`Payout outputs (${d} sats) exceed inputs (${l} sats); invalid transaction.`
|
|
267
|
+
);
|
|
268
|
+
await Cr(r, {
|
|
269
|
+
implicitFeeSats: l - d,
|
|
270
|
+
out0Len: c[Ve].script.length,
|
|
271
|
+
out1Len: void 0
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
class eo extends Error {
|
|
275
|
+
constructor(t, r) {
|
|
276
|
+
super(
|
|
277
|
+
"Transaction graph's challenger set does not match the vault's (local ∪ universal)" + (t.length > 0 ? ` (missing: ${t.join(", ")})` : "") + (r.length > 0 ? ` (unexpected: ${r.join(", ")})` : "") + ". Refusing to sign an incomplete or padded challenger set."
|
|
278
|
+
), this.missing = t, this.unexpected = r, this.name = "ChallengerSetMismatchError";
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
function to(e) {
|
|
282
|
+
const t = mt({
|
|
283
|
+
claimerBtcPubkey: e.depositorBtcPubkey,
|
|
284
|
+
depositorBtcPubkey: e.depositorBtcPubkey,
|
|
285
|
+
vaultProviderBtcPubkey: e.vaultProviderBtcPubkey,
|
|
286
|
+
vaultKeeperBtcPubkeys: e.vaultKeeperBtcPubkeys
|
|
287
|
+
}), r = e.universalChallengerBtcPubkeys.map(Qe), o = t.filter((c) => r.includes(c));
|
|
288
|
+
if (o.length > 0)
|
|
289
|
+
throw new Error(
|
|
290
|
+
`Cannot check the challenger set: vault keepers and universal challengers overlap (${o.join(", ")}).`
|
|
291
|
+
);
|
|
292
|
+
const s = e.graphChallengerPubkeys.map(Qe), n = new Set(s);
|
|
293
|
+
if (n.size !== s.length)
|
|
294
|
+
throw new Error(
|
|
295
|
+
"Transaction graph lists the same challenger more than once."
|
|
296
|
+
);
|
|
297
|
+
const a = [...t, ...r], i = new Set(a), u = a.filter((c) => !n.has(c)), l = s.filter((c) => !i.has(c));
|
|
298
|
+
if (u.length > 0 || l.length > 0)
|
|
299
|
+
throw new eo(u, l);
|
|
300
|
+
}
|
|
301
|
+
function Qe(e) {
|
|
302
|
+
return b(e).toLowerCase();
|
|
303
|
+
}
|
|
304
|
+
class ro extends Error {
|
|
305
|
+
constructor(t, r) {
|
|
306
|
+
super(
|
|
307
|
+
`Payout transaction output ${Ve} pays ${r}, not the vault's registered payout script ${t}. Refusing to sign a payout to another destination.`
|
|
308
|
+
), this.expectedScriptHex = t, this.actualScriptHex = r, this.name = "PayoutDestinationError";
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
function oo(e) {
|
|
312
|
+
let t;
|
|
313
|
+
try {
|
|
314
|
+
t = q.fromBase64(e.payoutPsbtBase64);
|
|
315
|
+
} catch (c) {
|
|
316
|
+
throw new Error("Payout PSBT cannot be parsed.", { cause: c });
|
|
317
|
+
}
|
|
318
|
+
const { version: r, locktime: o, outs: s } = so(t);
|
|
319
|
+
if (r !== Fe || o !== Ue)
|
|
320
|
+
throw new Error(
|
|
321
|
+
`Payout transaction has version ${r} and locktime ${o}, expected ${Fe} and ${Ue}.`
|
|
322
|
+
);
|
|
323
|
+
if (s.length !== J)
|
|
324
|
+
throw new Error(
|
|
325
|
+
`Payout transaction has ${s.length} output(s), expected exactly ${J} for a depositor-as-claimer payout.`
|
|
326
|
+
);
|
|
327
|
+
const n = b(
|
|
328
|
+
e.registeredPayoutScriptPubKey
|
|
329
|
+
).toLowerCase();
|
|
330
|
+
if (n.length === 0)
|
|
331
|
+
throw new Error(
|
|
332
|
+
"registeredPayoutScriptPubKey is empty; the vault's on-chain payout script is required to check the Payout destination."
|
|
333
|
+
);
|
|
334
|
+
const a = s[Ve].script.toString("hex").toLowerCase();
|
|
335
|
+
if (a !== n)
|
|
336
|
+
throw new ro(n, a);
|
|
337
|
+
const i = s[J - 1];
|
|
338
|
+
if (i.value !== qe)
|
|
339
|
+
throw new Error(
|
|
340
|
+
`Payout CPFP anchor value ${i.value} sats must equal ${qe} sats.`
|
|
341
|
+
);
|
|
342
|
+
const u = b(
|
|
343
|
+
vr(b(e.depositorBtcPubkey).toLowerCase())
|
|
344
|
+
), l = i.script.toString("hex").toLowerCase();
|
|
345
|
+
if (l !== u)
|
|
346
|
+
throw new Error(
|
|
347
|
+
`Payout CPFP anchor pays ${l}, not the depositor's BIP-86 P2TR ${u}. Refusing to sign a payout whose fee-bump output is spendable by somebody else.`
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
function so(e) {
|
|
351
|
+
return {
|
|
352
|
+
version: e.version,
|
|
353
|
+
locktime: e.locktime,
|
|
354
|
+
outs: e.txOutputs.map((t) => ({
|
|
355
|
+
script: H.from(t.script),
|
|
356
|
+
value: t.value
|
|
357
|
+
}))
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
class se extends Error {
|
|
361
|
+
constructor(t) {
|
|
362
|
+
super(t), this.name = "PayoutInputLeafError";
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
function no(e) {
|
|
366
|
+
const t = q.fromBase64(e.payoutDepositorPsbtBase64), r = q.fromBase64(e.payoutClaimerPsbtBase64), o = t.data.globalMap.unsignedTx.toBuffer(), s = r.data.globalMap.unsignedTx.toBuffer();
|
|
367
|
+
if (!o.equals(s))
|
|
368
|
+
throw new se(
|
|
369
|
+
"Depositor and claimer Payout PSBTs describe different transactions; the graph is inconsistent."
|
|
370
|
+
);
|
|
371
|
+
const n = r.data.inputs[A], a = t.data.inputs[A];
|
|
372
|
+
if (!n || !a)
|
|
373
|
+
throw new se(
|
|
374
|
+
"Payout PSBT has no Assert-connector input."
|
|
375
|
+
);
|
|
376
|
+
if (!n.tapLeafScript || n.tapLeafScript.length !== 1)
|
|
377
|
+
throw new se(
|
|
378
|
+
"Claimer Payout PSBT must carry exactly one leaf on the Assert-connector input."
|
|
379
|
+
);
|
|
380
|
+
if (a.tapLeafScript && a.tapLeafScript.length > 0)
|
|
381
|
+
throw new se(
|
|
382
|
+
"Depositor Payout PSBT already carries an Assert-connector leaf; refusing to overwrite it."
|
|
383
|
+
);
|
|
384
|
+
return t.updateInput(A, {
|
|
385
|
+
tapLeafScript: n.tapLeafScript,
|
|
386
|
+
...n.tapInternalKey ? { tapInternalKey: n.tapInternalKey } : {},
|
|
387
|
+
...n.tapMerkleRoot ? { tapMerkleRoot: n.tapMerkleRoot } : {}
|
|
388
|
+
}), t.toBase64();
|
|
389
|
+
}
|
|
390
|
+
const io = "00";
|
|
391
|
+
class ao extends Error {
|
|
392
|
+
constructor(t, r, o) {
|
|
393
|
+
super(
|
|
394
|
+
`Transaction graph does not belong to vault ${t}: its Claim spends PegIn ${o}, which derives vault ${r}. Refusing to sign for a graph served for another vault.`
|
|
395
|
+
), this.expectedVaultId = t, this.derivedVaultId = r, this.peginTxid = o, this.name = "VaultIdBindingError";
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
function uo(e) {
|
|
399
|
+
let t;
|
|
400
|
+
try {
|
|
401
|
+
t = q.fromBase64(e);
|
|
402
|
+
} catch (o) {
|
|
403
|
+
throw new Error("Claim PSBT cannot be parsed.", { cause: o });
|
|
404
|
+
}
|
|
405
|
+
const r = t.txInputs[pe];
|
|
406
|
+
if (!r)
|
|
407
|
+
throw new Error("Claim PSBT carries no PegIn input to bind the vault to.");
|
|
408
|
+
return _t(
|
|
409
|
+
"Claim PSBT",
|
|
410
|
+
t.txInputs.length,
|
|
411
|
+
r.index
|
|
412
|
+
), Re(r.hash);
|
|
413
|
+
}
|
|
414
|
+
function co(e) {
|
|
415
|
+
const t = e.ins[pe];
|
|
416
|
+
if (!t)
|
|
417
|
+
throw new Error(
|
|
418
|
+
"Artifacts file's claim_tx carries no PegIn input to bind the vault to."
|
|
419
|
+
);
|
|
420
|
+
return _t(
|
|
421
|
+
"Artifacts file's claim_tx",
|
|
422
|
+
e.ins.length,
|
|
423
|
+
t.index
|
|
424
|
+
), Re(t.hash);
|
|
425
|
+
}
|
|
426
|
+
function _t(e, t, r) {
|
|
427
|
+
if (t !== 1 || r !== X)
|
|
428
|
+
throw new Error(
|
|
429
|
+
`${e} must have exactly one input spending PegIn output ${X}; it has ${t} input(s) and the first spends output ${r}.`
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
function St(e) {
|
|
433
|
+
const t = G(
|
|
434
|
+
Pt(e.peginTxid, e.depositorEthAddress)
|
|
435
|
+
), r = G(e.expectedVaultId);
|
|
436
|
+
if (t !== r)
|
|
437
|
+
throw new ao(r, t, e.peginTxid);
|
|
438
|
+
}
|
|
439
|
+
function G(e) {
|
|
440
|
+
return `0x${(e.startsWith("0x") ? e.slice(2) : e).toLowerCase()}`;
|
|
441
|
+
}
|
|
442
|
+
function Re(e) {
|
|
443
|
+
return H.from(e).reverse().toString("hex");
|
|
444
|
+
}
|
|
445
|
+
function ce(e, t) {
|
|
446
|
+
const r = b(e);
|
|
447
|
+
if (!/^(?:[0-9a-fA-F]{2})+$/.test(r))
|
|
448
|
+
throw new Error(`${t} must be non-empty, even-length hex.`);
|
|
449
|
+
return r.toLowerCase();
|
|
450
|
+
}
|
|
451
|
+
function At(e) {
|
|
452
|
+
const t = ce(
|
|
453
|
+
e.servedVerifyingKeyHex,
|
|
454
|
+
"source.verifyingKeyHex"
|
|
455
|
+
), r = ce(
|
|
456
|
+
e.trustedVerifyingKeyHex,
|
|
457
|
+
"trustedVerifyingKeyHex"
|
|
458
|
+
);
|
|
459
|
+
if (t === r) return r;
|
|
460
|
+
throw new Error(
|
|
461
|
+
`Vault provider served Groth16 verifying key ${t} but the trusted key for prover circuit version ${e.proverCircuitVersion} is ${r}; refusing to sign a claim whose proof would verify under a substituted key.`
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
const U = 3;
|
|
465
|
+
class lo extends Error {
|
|
466
|
+
constructor(t, r) {
|
|
467
|
+
super(
|
|
468
|
+
`Artifacts belong to vault ${r}, not ${t}. Select the artifacts file saved for this vault.`
|
|
469
|
+
), this.expectedVaultId = t, this.actualVaultId = r, this.name = "ArtifactsVaultMismatchError";
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
function ho(e) {
|
|
473
|
+
const t = fo(e, "babe_sessions"), r = [];
|
|
474
|
+
for (const [o, s] of Object.entries(t)) {
|
|
475
|
+
const n = typeof s == "object" && s !== null ? s.decryptor_artifacts_hex : void 0;
|
|
476
|
+
if (typeof n != "string" || n.length === 0)
|
|
477
|
+
throw new Error(
|
|
478
|
+
`Artifacts file is missing a usable "babe_sessions": the entry for ${o} carries no "decryptor_artifacts_hex" string.`
|
|
479
|
+
);
|
|
480
|
+
n === io && r.push(o);
|
|
481
|
+
}
|
|
482
|
+
return {
|
|
483
|
+
challengerPubkeys: Object.keys(t),
|
|
484
|
+
placeholderChallengerPubkeys: r
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
function po(e) {
|
|
488
|
+
let t;
|
|
489
|
+
try {
|
|
490
|
+
t = JSON.parse(e);
|
|
491
|
+
} catch (i) {
|
|
492
|
+
throw new Error("Artifacts file is not valid JSON.", { cause: i });
|
|
493
|
+
}
|
|
494
|
+
const r = Pe(t.vault_id, "vault_id"), o = go(Pe(t.claim_tx, "claim_tx")), s = me(
|
|
495
|
+
t.prover_circuit_version,
|
|
496
|
+
"prover_circuit_version"
|
|
497
|
+
), n = t.claimable_event_block_number === void 0 ? 0n : BigInt(
|
|
498
|
+
me(
|
|
499
|
+
t.claimable_event_block_number,
|
|
500
|
+
"claimable_event_block_number"
|
|
501
|
+
)
|
|
502
|
+
), a = ho(t.babe_sessions);
|
|
503
|
+
return {
|
|
504
|
+
vaultCoreVersion: t.vault_core_version === void 0 ? void 0 : me(t.vault_core_version, "vault_core_version"),
|
|
505
|
+
vaultId: r,
|
|
506
|
+
claimTxid: o.getId(),
|
|
507
|
+
peginTxid: co(o),
|
|
508
|
+
proverCircuitVersion: s,
|
|
509
|
+
claimableEventBlockNumber: n,
|
|
510
|
+
// Required: btc-vault's builder always writes it
|
|
511
|
+
// (`delegated_claim.rs:514` @ ac4954e7), so an absent one is not a file
|
|
512
|
+
// this SDK or the CLI produced.
|
|
513
|
+
verifyingKeyHex: Pe(t.verifying_key, "verifying_key"),
|
|
514
|
+
babeSessionChallengerPubkeys: a.challengerPubkeys,
|
|
515
|
+
babeSessionPlaceholderChallengerPubkeys: a.placeholderChallengerPubkeys
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
async function Js(e) {
|
|
519
|
+
const t = po(e.artifactsJson), r = G(e.expectedVaultId), o = G(t.vaultId);
|
|
520
|
+
if (r !== o)
|
|
521
|
+
throw new lo(r, o);
|
|
522
|
+
St({
|
|
523
|
+
peginTxid: t.peginTxid,
|
|
524
|
+
depositorEthAddress: e.depositorEthAddress,
|
|
525
|
+
expectedVaultId: r
|
|
526
|
+
});
|
|
527
|
+
const s = e.txGraphVersion ?? U;
|
|
528
|
+
if (t.vaultCoreVersion !== void 0 && t.vaultCoreVersion !== s)
|
|
529
|
+
throw new Error(
|
|
530
|
+
`Artifacts record vault core version ${t.vaultCoreVersion}, but verification was asked for version ${s}.`
|
|
531
|
+
);
|
|
532
|
+
if (t.claimableEventBlockNumber === 0n)
|
|
533
|
+
throw new Error(
|
|
534
|
+
"Artifacts carry no claimable event block number. They were assembled before the Ethereum withdrawal was initiated; assemble them again."
|
|
535
|
+
);
|
|
536
|
+
if (t.claimableEventBlockNumber !== e.expectedClaimableEventBlockNumber)
|
|
537
|
+
throw new Error(
|
|
538
|
+
`Artifacts record claimable event block ${t.claimableEventBlockNumber} but the vault's finalized VaultClaimableBy event is at block ${e.expectedClaimableEventBlockNumber}; the prover would prove the wrong block, so refusing the file.`
|
|
539
|
+
);
|
|
540
|
+
if (t.proverCircuitVersion !== e.expectedProverCircuitVersion)
|
|
541
|
+
throw new Error(
|
|
542
|
+
`Artifacts record prover circuit version ${t.proverCircuitVersion} but the vault's stamped params say ${e.expectedProverCircuitVersion}; a proof for the wrong circuit fails at start-claim, so refusing the file.`
|
|
543
|
+
);
|
|
544
|
+
const n = ce(
|
|
545
|
+
t.verifyingKeyHex,
|
|
546
|
+
'Artifacts file "verifying_key"'
|
|
547
|
+
), a = ce(
|
|
548
|
+
e.trustedVerifyingKeyHex,
|
|
549
|
+
"trustedVerifyingKeyHex"
|
|
550
|
+
);
|
|
551
|
+
if (n !== a)
|
|
552
|
+
throw new Error(
|
|
553
|
+
`Artifacts carry Groth16 verifying key ${n} but the trusted key for prover circuit version ${e.expectedProverCircuitVersion} is ${a}; refusing a file whose proof would verify under a substituted key.`
|
|
554
|
+
);
|
|
555
|
+
const [i] = t.babeSessionPlaceholderChallengerPubkeys;
|
|
556
|
+
if (i !== void 0)
|
|
557
|
+
throw new Error(
|
|
558
|
+
`Artifacts carry a placeholder BaBe session for challenger ${i}; join the real sessions into the file before using it (#2598).`
|
|
559
|
+
);
|
|
560
|
+
return await nr(s, e.artifactsJson), t;
|
|
561
|
+
}
|
|
562
|
+
function go(e) {
|
|
563
|
+
try {
|
|
564
|
+
return S.fromHex(e);
|
|
565
|
+
} catch (t) {
|
|
566
|
+
throw new Error("Artifacts file carries an unparseable claim_tx.", {
|
|
567
|
+
cause: t
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
function Pe(e, t) {
|
|
572
|
+
if (typeof e != "string" || e.length === 0)
|
|
573
|
+
throw new Error(`Artifacts file is missing a usable "${t}".`);
|
|
574
|
+
return e;
|
|
575
|
+
}
|
|
576
|
+
function me(e, t) {
|
|
577
|
+
if (typeof e != "number" || !Number.isSafeInteger(e) || e < 0)
|
|
578
|
+
throw new Error(`Artifacts file is missing a usable "${t}".`);
|
|
579
|
+
return e;
|
|
580
|
+
}
|
|
581
|
+
function fo(e, t) {
|
|
582
|
+
if (e === void 0) return {};
|
|
583
|
+
if (typeof e != "object" || e === null || Array.isArray(e))
|
|
584
|
+
throw new Error(`Artifacts file is missing a usable "${t}".`);
|
|
585
|
+
return e;
|
|
586
|
+
}
|
|
587
|
+
function Bt(e, t) {
|
|
588
|
+
return `wronglyChallenged:${e}:${t}`;
|
|
589
|
+
}
|
|
590
|
+
function It(e) {
|
|
591
|
+
const t = [
|
|
592
|
+
{
|
|
593
|
+
id: "claim",
|
|
594
|
+
kind: "claim",
|
|
595
|
+
psbtBase64: e.claim,
|
|
596
|
+
inputIndex: pe
|
|
597
|
+
},
|
|
598
|
+
{
|
|
599
|
+
id: "assert",
|
|
600
|
+
kind: "assert",
|
|
601
|
+
psbtBase64: e.assert,
|
|
602
|
+
inputIndex: F
|
|
603
|
+
},
|
|
604
|
+
{
|
|
605
|
+
id: "payoutClaimer",
|
|
606
|
+
kind: "payoutClaimer",
|
|
607
|
+
psbtBase64: e.payoutClaimer,
|
|
608
|
+
inputIndex: A
|
|
609
|
+
},
|
|
610
|
+
{
|
|
611
|
+
id: "payoutDepositor",
|
|
612
|
+
kind: "payoutDepositor",
|
|
613
|
+
psbtBase64: e.payoutDepositor,
|
|
614
|
+
inputIndex: ee
|
|
615
|
+
}
|
|
616
|
+
];
|
|
617
|
+
for (const r of Object.keys(e.wronglyChallenged))
|
|
618
|
+
e.wronglyChallenged[r].forEach((o, s) => {
|
|
619
|
+
t.push({
|
|
620
|
+
id: Bt(r, s),
|
|
621
|
+
kind: "wronglyChallenged",
|
|
622
|
+
psbtBase64: o,
|
|
623
|
+
inputIndex: $r
|
|
624
|
+
});
|
|
625
|
+
});
|
|
626
|
+
return t;
|
|
627
|
+
}
|
|
628
|
+
const yo = wt - xt;
|
|
629
|
+
function V(e) {
|
|
630
|
+
const t = e.replace(/^0x/, "").toLowerCase();
|
|
631
|
+
if (t.length === wt)
|
|
632
|
+
return t.slice(yo);
|
|
633
|
+
if (t.length === xt) return t;
|
|
634
|
+
throw new Error(
|
|
635
|
+
`Public key must be 33-byte compressed or 32-byte x-only hex, got ${t.length / 2} bytes.`
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
async function Je(e, t, r) {
|
|
639
|
+
const o = await e.getPublicKeyHex();
|
|
640
|
+
if (V(o) !== V(t))
|
|
641
|
+
throw new Error(
|
|
642
|
+
"Connected wallet does not hold the vault's depositor key. Select the account that made the deposit, then try again."
|
|
643
|
+
);
|
|
644
|
+
const s = await e.getAddress();
|
|
645
|
+
if (!er(s, o, r))
|
|
646
|
+
throw new Error(
|
|
647
|
+
`Connected wallet reports address "${s}", which is not derived from the vault's depositor key. Select the account that made the deposit, then try again.`
|
|
648
|
+
);
|
|
649
|
+
return s;
|
|
650
|
+
}
|
|
651
|
+
async function Vt(e, t, r, o) {
|
|
652
|
+
const s = V(o);
|
|
653
|
+
if (s !== r.depositorBtcPubkey)
|
|
654
|
+
throw new Error(
|
|
655
|
+
`Depositor key ${s} is not the vault's registered depositor key ${r.depositorBtcPubkey}; refusing to plan a claim for another key.`
|
|
656
|
+
);
|
|
657
|
+
try {
|
|
658
|
+
br(
|
|
659
|
+
Be(r.registeredPayoutScriptPubKey),
|
|
660
|
+
r.depositorBtcPubkey,
|
|
661
|
+
o
|
|
662
|
+
);
|
|
663
|
+
} catch (d) {
|
|
664
|
+
throw new Error(
|
|
665
|
+
`Registered payout script ${r.registeredPayoutScriptPubKey} failed the depositor-key derivation check: ${d instanceof Error ? d.message : String(d)}. This SDK registers only P2TR of the depositor's x-only key or P2WPKH of the compressed key (the contract bounds the script's length alone, PeginLogic.sol:237-240 @ c559f5c2); refusing to sign a claim that pays it.`,
|
|
666
|
+
{ cause: d }
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
if (e !== U)
|
|
670
|
+
throw new Error(
|
|
671
|
+
`Graph version ${e} is not the delegated-claim graph version ${U}; vaults on earlier graphs have no delegated-claim path.`
|
|
672
|
+
);
|
|
673
|
+
if (e !== r.vaultCoreVersion)
|
|
674
|
+
throw new Error(
|
|
675
|
+
`Graph version ${e} does not match the vault context's vault core version ${r.vaultCoreVersion}; they are one axis and must agree.`
|
|
676
|
+
);
|
|
677
|
+
const [n, a, i, u, l] = await Promise.all([
|
|
678
|
+
ir(e, t),
|
|
679
|
+
ar(e, t),
|
|
680
|
+
ur(e, t),
|
|
681
|
+
cr(e, t),
|
|
682
|
+
lr(e, t)
|
|
683
|
+
]);
|
|
684
|
+
St({
|
|
685
|
+
peginTxid: uo(n),
|
|
686
|
+
depositorEthAddress: r.depositorEthAddress,
|
|
687
|
+
expectedVaultId: r.vaultId
|
|
688
|
+
}), Jr({
|
|
689
|
+
claimPsbtBase64: n,
|
|
690
|
+
assertPsbtBase64: a,
|
|
691
|
+
payoutClaimerPsbtBase64: i
|
|
692
|
+
});
|
|
693
|
+
for (const d of [i, l])
|
|
694
|
+
oo({
|
|
695
|
+
payoutPsbtBase64: d,
|
|
696
|
+
registeredPayoutScriptPubKey: r.registeredPayoutScriptPubKey,
|
|
697
|
+
depositorBtcPubkey: r.depositorBtcPubkey
|
|
698
|
+
});
|
|
699
|
+
const c = no({
|
|
700
|
+
payoutDepositorPsbtBase64: l,
|
|
701
|
+
payoutClaimerPsbtBase64: i
|
|
702
|
+
});
|
|
703
|
+
return await Zr({
|
|
704
|
+
payoutClaimerPsbtBase64: i,
|
|
705
|
+
payoutDepositorPsbtBase64: c,
|
|
706
|
+
assertPsbtBase64: a,
|
|
707
|
+
vault: r
|
|
708
|
+
}), to({
|
|
709
|
+
graphChallengerPubkeys: Object.keys(u),
|
|
710
|
+
depositorBtcPubkey: o,
|
|
711
|
+
vaultProviderBtcPubkey: r.vaultProviderBtcPubkey,
|
|
712
|
+
vaultKeeperBtcPubkeys: r.vaultKeeperBtcPubkeys,
|
|
713
|
+
universalChallengerBtcPubkeys: r.universalChallengerBtcPubkeys
|
|
714
|
+
}), { claim: n, assert: a, payoutClaimer: i, payoutDepositor: c, wronglyChallenged: u };
|
|
715
|
+
}
|
|
716
|
+
async function vo(e) {
|
|
717
|
+
At({
|
|
718
|
+
servedVerifyingKeyHex: e.source.verifyingKeyHex,
|
|
719
|
+
trustedVerifyingKeyHex: e.trustedVerifyingKeyHex,
|
|
720
|
+
proverCircuitVersion: e.vault.proverCircuitVersion
|
|
721
|
+
});
|
|
722
|
+
const t = await Vt(
|
|
723
|
+
e.vault.txGraphVersion,
|
|
724
|
+
e.source.txGraphJson,
|
|
725
|
+
e.vault,
|
|
726
|
+
e.depositorPublicKey
|
|
727
|
+
);
|
|
728
|
+
return {
|
|
729
|
+
depositorPublicKey: e.depositorPublicKey,
|
|
730
|
+
btcNetwork: e.btcNetwork,
|
|
731
|
+
trustedVerifyingKeyHex: e.trustedVerifyingKeyHex,
|
|
732
|
+
source: e.source,
|
|
733
|
+
vault: e.vault,
|
|
734
|
+
babeSessionsJson: e.babeSessionsJson,
|
|
735
|
+
requests: It(t)
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
function ge(e, t, r) {
|
|
739
|
+
re({
|
|
740
|
+
requestedPsbtHex: Ke(t.psbtBase64),
|
|
741
|
+
signatureHex: r,
|
|
742
|
+
signerXOnlyPubkeyHex: V(e.depositorPublicKey),
|
|
743
|
+
inputIndex: t.inputIndex
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
function Ke(e) {
|
|
747
|
+
return H.from(e, "base64").toString("hex");
|
|
748
|
+
}
|
|
749
|
+
function Rt(e) {
|
|
750
|
+
return H.from(e, "hex").toString("base64");
|
|
751
|
+
}
|
|
752
|
+
class j extends Error {
|
|
753
|
+
constructor(t) {
|
|
754
|
+
super(t), this.name = "SigningPlanMismatchError";
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
function bo(e, t) {
|
|
758
|
+
if (e.length !== t.length)
|
|
759
|
+
throw new j(
|
|
760
|
+
`Plan has ${e.length} requests but the graph builds ${t.length}; the plan was altered after planning.`
|
|
761
|
+
);
|
|
762
|
+
for (let r = 0; r < t.length; r++) {
|
|
763
|
+
const o = t[r], s = e[r];
|
|
764
|
+
if (s.id !== o.id)
|
|
765
|
+
throw new j(
|
|
766
|
+
`Plan request at position ${r} is "${s.id}" but the graph builds "${o.id}" there; the plan was altered after planning.`
|
|
767
|
+
);
|
|
768
|
+
if (s.kind !== o.kind)
|
|
769
|
+
throw new j(
|
|
770
|
+
`Plan request "${s.id}" has kind "${s.kind}" but the graph builds "${o.kind}"; the plan was altered after planning.`
|
|
771
|
+
);
|
|
772
|
+
if (s.inputIndex !== o.inputIndex)
|
|
773
|
+
throw new j(
|
|
774
|
+
`Plan request "${s.id}" signs inputIndex ${s.inputIndex} but the graph builds ${o.inputIndex}; the plan was altered after planning.`
|
|
775
|
+
);
|
|
776
|
+
if (s.psbtBase64 !== o.psbtBase64)
|
|
777
|
+
throw new j(
|
|
778
|
+
`Plan request "${s.id}" carries a psbt that differs from the one the graph builds; the plan was altered after planning.`
|
|
779
|
+
);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
function Po(e, t) {
|
|
783
|
+
const r = new Set(e.map((a) => a.id)), o = [...r].filter((a) => !t.has(a)), s = [...t.keys()].filter((a) => !r.has(a));
|
|
784
|
+
if (o.length === 0 && s.length === 0) return;
|
|
785
|
+
const n = (a) => a.map((i) => `"${i}"`).join(", ");
|
|
786
|
+
throw new Error(
|
|
787
|
+
`Signatures do not cover the plan: ${t.size} signatures for ${e.length} requests` + (o.length > 0 ? `; missing ${n(o)}` : "") + (s.length > 0 ? `; extra ${n(s)}` : "") + "."
|
|
788
|
+
);
|
|
789
|
+
}
|
|
790
|
+
function M(e, t) {
|
|
791
|
+
const r = e.get(t);
|
|
792
|
+
if (r === void 0)
|
|
793
|
+
throw new Error(
|
|
794
|
+
`No signature for request "${t}"; the plan was not fully signed.`
|
|
795
|
+
);
|
|
796
|
+
return r;
|
|
797
|
+
}
|
|
798
|
+
async function mo(e) {
|
|
799
|
+
const { plan: t, signatures: r } = e, { txGraphVersion: o } = t.vault, s = t.source.txGraphJson, n = At({
|
|
800
|
+
servedVerifyingKeyHex: t.source.verifyingKeyHex,
|
|
801
|
+
trustedVerifyingKeyHex: t.trustedVerifyingKeyHex,
|
|
802
|
+
proverCircuitVersion: t.vault.proverCircuitVersion
|
|
803
|
+
}), a = await Vt(
|
|
804
|
+
o,
|
|
805
|
+
s,
|
|
806
|
+
t.vault,
|
|
807
|
+
t.depositorPublicKey
|
|
808
|
+
), i = It(a);
|
|
809
|
+
bo(t.requests, i), Po(i, r);
|
|
810
|
+
for (const c of i)
|
|
811
|
+
ge(
|
|
812
|
+
t,
|
|
813
|
+
c,
|
|
814
|
+
M(r, c.id)
|
|
815
|
+
);
|
|
816
|
+
const u = {};
|
|
817
|
+
for (const c of Object.keys(a.wronglyChallenged))
|
|
818
|
+
u[c] = a.wronglyChallenged[c].map(
|
|
819
|
+
(d, h) => M(
|
|
820
|
+
r,
|
|
821
|
+
Bt(c, h)
|
|
822
|
+
)
|
|
823
|
+
);
|
|
824
|
+
const l = await dr(
|
|
825
|
+
o,
|
|
826
|
+
s,
|
|
827
|
+
M(r, "claim")
|
|
828
|
+
);
|
|
829
|
+
return hr({
|
|
830
|
+
txGraphVersion: o,
|
|
831
|
+
graphJson: s,
|
|
832
|
+
signedClaimTxHex: l,
|
|
833
|
+
assertClaimerSigHex: M(r, "assert"),
|
|
834
|
+
payoutClaimerSigHex: M(r, "payoutClaimer"),
|
|
835
|
+
wronglyChallengedSigs: u,
|
|
836
|
+
depositorPayoutSigHex: M(r, "payoutDepositor"),
|
|
837
|
+
verifyingKeyHex: n,
|
|
838
|
+
claimableEventBlockNumber: t.vault.claimableEventBlockNumber,
|
|
839
|
+
proverCircuitVersion: t.vault.proverCircuitVersion,
|
|
840
|
+
vaultIdHex: t.vault.vaultId,
|
|
841
|
+
babeSessionsJson: t.babeSessionsJson,
|
|
842
|
+
expectedVaultCoreVersion: t.vault.vaultCoreVersion
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
function wo(e) {
|
|
846
|
+
return typeof e.signDelegatedClaimPsbt == "function";
|
|
847
|
+
}
|
|
848
|
+
class xo extends Error {
|
|
849
|
+
constructor(t, r, o, s) {
|
|
850
|
+
super(t, s), this.signatures = r, this.failedRequestId = o, this.name = "DelegatedClaimSigningIncompleteError";
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
const Kt = {
|
|
854
|
+
assert: "intentBound",
|
|
855
|
+
payoutDepositor: "intentBound",
|
|
856
|
+
payoutClaimer: "standalone",
|
|
857
|
+
claim: "standalone",
|
|
858
|
+
wronglyChallenged: "standalone"
|
|
859
|
+
}, Eo = [
|
|
860
|
+
"payoutClaimer",
|
|
861
|
+
"claim",
|
|
862
|
+
"wronglyChallenged"
|
|
863
|
+
];
|
|
864
|
+
async function $o(e, t, r = {}) {
|
|
865
|
+
var s;
|
|
866
|
+
if ((s = r.signal) == null || s.throwIfAborted(), ko(e), V(e.depositorPublicKey) !== e.vault.depositorBtcPubkey)
|
|
867
|
+
throw new Error(
|
|
868
|
+
`Plan depositor key ${V(e.depositorPublicKey)} is not the vault's registered depositor key ${e.vault.depositorBtcPubkey}; the plan was not built for this vault.`
|
|
869
|
+
);
|
|
870
|
+
if (yt(t)) {
|
|
871
|
+
if (!wo(t))
|
|
872
|
+
throw new Error(
|
|
873
|
+
"Approval wallet does not implement signDelegatedClaimPsbt; the claim ceremony needs it because the device signs some claim PSBTs with no loaded intent and needs its own derivation fields on them."
|
|
874
|
+
);
|
|
875
|
+
const n = To(r, e);
|
|
876
|
+
_o(n.depositTerms, e.vault);
|
|
877
|
+
const a = Co(e), i = await Je(
|
|
878
|
+
t,
|
|
879
|
+
e.depositorPublicKey,
|
|
880
|
+
e.btcNetwork
|
|
881
|
+
);
|
|
882
|
+
return So(
|
|
883
|
+
e,
|
|
884
|
+
t,
|
|
885
|
+
i,
|
|
886
|
+
n,
|
|
887
|
+
a,
|
|
888
|
+
r
|
|
889
|
+
);
|
|
890
|
+
}
|
|
891
|
+
const o = await Je(
|
|
892
|
+
t,
|
|
893
|
+
e.depositorPublicKey,
|
|
894
|
+
e.btcNetwork
|
|
895
|
+
);
|
|
896
|
+
return Bo(e, t, o, r.signal);
|
|
897
|
+
}
|
|
898
|
+
function ko(e) {
|
|
899
|
+
const t = /* @__PURE__ */ new Set();
|
|
900
|
+
for (const r of e.requests) {
|
|
901
|
+
if (t.has(r.id))
|
|
902
|
+
throw new Error(
|
|
903
|
+
`Delegated-claim plan lists request "${r.id}" more than once; its signatures could not be keyed, so nothing is signed.`
|
|
904
|
+
);
|
|
905
|
+
t.add(r.id);
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
function Co(e) {
|
|
909
|
+
const t = e.requests.filter(
|
|
910
|
+
(s) => Kt[s.kind] === "intentBound"
|
|
911
|
+
), r = Eo.flatMap(
|
|
912
|
+
(s) => e.requests.filter((n) => n.kind === s)
|
|
913
|
+
), o = t.length + r.length;
|
|
914
|
+
if (o !== e.requests.length)
|
|
915
|
+
throw new Error(
|
|
916
|
+
`Delegated-claim plan has ${e.requests.length} signing requests but only ${o} are of a kind this signer can place in the device ceremony; the plan and the signer disagree on the request kinds.`
|
|
917
|
+
);
|
|
918
|
+
return { intentBound: t, standalone: r };
|
|
919
|
+
}
|
|
920
|
+
function Ht(e, t) {
|
|
921
|
+
if (t.size !== e.requests.length)
|
|
922
|
+
throw new Error(
|
|
923
|
+
`Delegated-claim signing ended with ${t.size} signatures for ${e.requests.length} requests; the set is incomplete and must not be treated as signed.`
|
|
924
|
+
);
|
|
925
|
+
}
|
|
926
|
+
function To(e, t) {
|
|
927
|
+
if (e.depositTerms === void 0)
|
|
928
|
+
throw new Error(
|
|
929
|
+
"An approval wallet signs Assert and the depositor Payout only under this vault's loaded intent; pass depositTerms (rebuilt from on-chain state) so it can be approved."
|
|
930
|
+
);
|
|
931
|
+
if (e.vaultContext === void 0)
|
|
932
|
+
throw new Error(
|
|
933
|
+
"An approval wallet releases a loaded intent only through the vault-root derivation; pass vaultContext so that derivation can run before and after the intent-bound signatures."
|
|
934
|
+
);
|
|
935
|
+
const r = Ie(e.vaultContext.depositorBtcPubkey);
|
|
936
|
+
if (r !== t.vault.depositorBtcPubkey)
|
|
937
|
+
throw new Error(
|
|
938
|
+
`vaultContext derives from depositor key ${r} but this plan's vault is registered to ${t.vault.depositorBtcPubkey}; the device would derive for another depositor.`
|
|
939
|
+
);
|
|
940
|
+
return { depositTerms: e.depositTerms, vaultContext: e.vaultContext };
|
|
941
|
+
}
|
|
942
|
+
function _o(e, t) {
|
|
943
|
+
const r = (s) => s.map((n) => V(n)).sort().join(",");
|
|
944
|
+
if (r(e.vaultKeeperBtcPubkeys) !== r(t.vaultKeeperBtcPubkeys) || r(e.universalChallengerBtcPubkeys) !== r(t.universalChallengerBtcPubkeys))
|
|
945
|
+
throw new Error(
|
|
946
|
+
"Deposit terms carry different keeper or challenger rosters than the vault context this claim signs for; the device would bind the Assert to the wrong intent."
|
|
947
|
+
);
|
|
948
|
+
if (e.vaultCoreVersion !== t.vaultCoreVersion)
|
|
949
|
+
throw new Error(
|
|
950
|
+
`Deposit terms describe vault core version ${e.vaultCoreVersion} but the vault context has version ${t.vaultCoreVersion}; the device would bind the Assert to the wrong intent.`
|
|
951
|
+
);
|
|
952
|
+
if (e.timelockPegin !== t.timelockPegin)
|
|
953
|
+
throw new Error(
|
|
954
|
+
`Deposit terms describe timelockPegin ${e.timelockPegin} but the vault context has ${t.timelockPegin}; the device would bind the Assert to the wrong intent.`
|
|
955
|
+
);
|
|
956
|
+
if (e.timelockAssert !== t.timelockAssert)
|
|
957
|
+
throw new Error(
|
|
958
|
+
`Deposit terms describe timelockAssert ${e.timelockAssert} but the vault context has ${t.timelockAssert}; the device would bind the Assert to the wrong intent.`
|
|
959
|
+
);
|
|
960
|
+
if (e.protocolFeeRate !== t.protocolFeeRate)
|
|
961
|
+
throw new Error(
|
|
962
|
+
`Deposit terms describe protocolFeeRate ${e.protocolFeeRate} but the vault context has ${t.protocolFeeRate}; the device would bind the Assert to the wrong intent.`
|
|
963
|
+
);
|
|
964
|
+
if (e.vaults.length === 0)
|
|
965
|
+
throw new Error(
|
|
966
|
+
"Deposit terms describe no vault group, so they cannot name the vault context's vault provider; the device would bind the Assert to the wrong intent."
|
|
967
|
+
);
|
|
968
|
+
const o = V(t.vaultProviderBtcPubkey);
|
|
969
|
+
for (const s of e.vaults)
|
|
970
|
+
if (V(s.vaultProviderBtcPubkey) !== o)
|
|
971
|
+
throw new Error(
|
|
972
|
+
`Deposit terms group at htlcVout ${s.htlcVout} names a different vault provider than the vault context this claim signs for; the device would bind the Assert to the wrong intent.`
|
|
973
|
+
);
|
|
974
|
+
}
|
|
975
|
+
async function So(e, t, r, o, { intentBound: s, standalone: n }, a) {
|
|
976
|
+
var g;
|
|
977
|
+
const i = Ao(e, a.resume), u = [...s, ...n];
|
|
978
|
+
let l = 0;
|
|
979
|
+
const c = {
|
|
980
|
+
phase: "clearing any loaded intent"
|
|
981
|
+
}, d = async (p) => {
|
|
982
|
+
var P;
|
|
983
|
+
c.phase = "signing", (P = a.signal) == null || P.throwIfAborted();
|
|
984
|
+
const y = await t.signDelegatedClaimPsbt(
|
|
985
|
+
Ke(p.psbtBase64),
|
|
986
|
+
Et(
|
|
987
|
+
e.depositorPublicKey,
|
|
988
|
+
p.inputIndex,
|
|
989
|
+
r
|
|
990
|
+
)
|
|
991
|
+
), f = await bt(
|
|
992
|
+
Rt(y),
|
|
993
|
+
p.inputIndex
|
|
994
|
+
);
|
|
995
|
+
ge(e, p, f), i.set(p.id, f);
|
|
996
|
+
}, h = async (p) => {
|
|
997
|
+
var f;
|
|
998
|
+
c.phase = p, (f = a.signal) == null || f.throwIfAborted(), (await $t(t, o.vaultContext)).fill(0);
|
|
999
|
+
};
|
|
1000
|
+
typeof t.validateDepositTerms == "function" && await t.validateDepositTerms(o.depositTerms);
|
|
1001
|
+
try {
|
|
1002
|
+
await h("clearing any loaded intent"), c.phase = "approving the deposit terms", (g = a.signal) == null || g.throwIfAborted(), await t.approveDepositTerms(o.depositTerms);
|
|
1003
|
+
for (const p of s)
|
|
1004
|
+
await d(p), l++;
|
|
1005
|
+
await h("releasing the loaded intent");
|
|
1006
|
+
for (const p of n)
|
|
1007
|
+
i.has(p.id) || await d(p), l++;
|
|
1008
|
+
} catch (p) {
|
|
1009
|
+
const y = u[l];
|
|
1010
|
+
if (i.size === 0 || y === void 0) throw p;
|
|
1011
|
+
const f = c.phase === "signing" ? `stopped at "${y.id}"` : `stopped before "${y.id}" while ${c.phase}`;
|
|
1012
|
+
throw new xo(
|
|
1013
|
+
`Delegated-claim signing ${f}; ${i.size} of ${e.requests.length} signatures were collected.`,
|
|
1014
|
+
i,
|
|
1015
|
+
y.id,
|
|
1016
|
+
{ cause: p }
|
|
1017
|
+
);
|
|
1018
|
+
}
|
|
1019
|
+
return Ht(e, i), i;
|
|
1020
|
+
}
|
|
1021
|
+
function Ao(e, t) {
|
|
1022
|
+
const r = /* @__PURE__ */ new Map();
|
|
1023
|
+
if (!t) return r;
|
|
1024
|
+
for (const o of e.requests) {
|
|
1025
|
+
const s = t.get(o.id);
|
|
1026
|
+
if (!(s === void 0 || Kt[o.kind] === "intentBound")) {
|
|
1027
|
+
try {
|
|
1028
|
+
ge(e, o, s);
|
|
1029
|
+
} catch {
|
|
1030
|
+
continue;
|
|
1031
|
+
}
|
|
1032
|
+
r.set(o.id, s);
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
return r;
|
|
1036
|
+
}
|
|
1037
|
+
async function Bo(e, t, r, o) {
|
|
1038
|
+
const s = e.requests, n = await vt(
|
|
1039
|
+
t,
|
|
1040
|
+
s.map((i) => Ke(i.psbtBase64)),
|
|
1041
|
+
s.map(
|
|
1042
|
+
(i) => Et(
|
|
1043
|
+
e.depositorPublicKey,
|
|
1044
|
+
i.inputIndex,
|
|
1045
|
+
r
|
|
1046
|
+
)
|
|
1047
|
+
),
|
|
1048
|
+
o
|
|
1049
|
+
), a = /* @__PURE__ */ new Map();
|
|
1050
|
+
for (let i = 0; i < s.length; i++) {
|
|
1051
|
+
const u = await bt(
|
|
1052
|
+
Rt(n[i]),
|
|
1053
|
+
s[i].inputIndex
|
|
1054
|
+
);
|
|
1055
|
+
ge(e, s[i], u), a.set(s[i].id, u);
|
|
1056
|
+
}
|
|
1057
|
+
return Ht(e, a), a;
|
|
1058
|
+
}
|
|
1059
|
+
async function Zs(e) {
|
|
1060
|
+
const t = await vo({
|
|
1061
|
+
depositorPublicKey: e.depositorPublicKey,
|
|
1062
|
+
btcNetwork: e.btcNetwork,
|
|
1063
|
+
source: e.source,
|
|
1064
|
+
trustedVerifyingKeyHex: e.trustedVerifyingKeyHex,
|
|
1065
|
+
vault: e.vault,
|
|
1066
|
+
babeSessionsJson: e.babeSessionsJson
|
|
1067
|
+
}), r = await $o(t, e.btcWallet, {
|
|
1068
|
+
depositTerms: e.depositTerms,
|
|
1069
|
+
vaultContext: e.vaultContext
|
|
1070
|
+
});
|
|
1071
|
+
return mo({ plan: t, signatures: r });
|
|
1072
|
+
}
|
|
1073
|
+
async function en(e) {
|
|
1074
|
+
const t = await $t(e.btcWallet, e.vaultContext);
|
|
1075
|
+
let r;
|
|
1076
|
+
try {
|
|
1077
|
+
r = await pr(t, e.htlcVout);
|
|
1078
|
+
} finally {
|
|
1079
|
+
t.fill(0);
|
|
1080
|
+
}
|
|
1081
|
+
let o;
|
|
1082
|
+
try {
|
|
1083
|
+
o = await gr(r);
|
|
1084
|
+
} finally {
|
|
1085
|
+
r.fill(0);
|
|
1086
|
+
}
|
|
1087
|
+
return Io(o.pk_hash, e.expectedWotsPkHash), await fr(
|
|
1088
|
+
e.txGraphVersion,
|
|
1089
|
+
o.keypair,
|
|
1090
|
+
e.txGraphJson
|
|
1091
|
+
), {
|
|
1092
|
+
wotsKeypairJson: JSON.stringify(o.keypair),
|
|
1093
|
+
pkHash: o.pk_hash
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
function Io(e, t) {
|
|
1097
|
+
if (ne(e) !== ne(t))
|
|
1098
|
+
throw new Error(
|
|
1099
|
+
`Derived WOTS public-key hash ${ne(e)} does not match the vault's on-chain depositorWotsPkHash ${ne(t)}. The wallet, the HTLC output index, or the derivation itself is not the one this vault was created with.`
|
|
1100
|
+
);
|
|
1101
|
+
}
|
|
1102
|
+
function ne(e) {
|
|
1103
|
+
return `0x${(e.startsWith("0x") ? e.slice(2) : e).toLowerCase()}`;
|
|
1104
|
+
}
|
|
1105
|
+
function we(e, t, r) {
|
|
1106
|
+
const o = `${e} operation key (admin=${t.ethAddress})`, s = _e(
|
|
1107
|
+
t.btcPubKey,
|
|
1108
|
+
`${e} roster key (admin=${t.ethAddress})`
|
|
1109
|
+
), n = _e(r, o);
|
|
1110
|
+
return {
|
|
1111
|
+
adminAddress: t.ethAddress,
|
|
1112
|
+
genesisBtcPubkey: s,
|
|
1113
|
+
operationBtcPubkey: n,
|
|
1114
|
+
rotated: n !== s
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
function Vo(e) {
|
|
1118
|
+
const t = /* @__PURE__ */ new Map();
|
|
1119
|
+
for (const r of e) {
|
|
1120
|
+
const o = t.get(r.operationBtcPubkey);
|
|
1121
|
+
if (o)
|
|
1122
|
+
throw new Error(
|
|
1123
|
+
`Participant operation key collision: ${o} and ${r.adminAddress} both resolve to operation key ${r.operationBtcPubkey}`
|
|
1124
|
+
);
|
|
1125
|
+
t.set(r.operationBtcPubkey, r.adminAddress);
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
function Ot(e, t, r) {
|
|
1129
|
+
if (t.vaultKeepers.length !== e.vaultKeepers.length || t.universalChallengers.length !== e.universalChallengers.length)
|
|
1130
|
+
throw new Error(
|
|
1131
|
+
`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`
|
|
1132
|
+
);
|
|
1133
|
+
const o = we(
|
|
1134
|
+
"vault provider",
|
|
1135
|
+
{
|
|
1136
|
+
ethAddress: e.vaultProviderEthAddress,
|
|
1137
|
+
btcPubKey: e.vaultProviderGenesisBtcPubkey
|
|
1138
|
+
},
|
|
1139
|
+
t.vaultProvider
|
|
1140
|
+
), s = e.vaultKeepers.map(
|
|
1141
|
+
(a, i) => we("vault keeper", a, t.vaultKeepers[i])
|
|
1142
|
+
), n = e.universalChallengers.map(
|
|
1143
|
+
(a, i) => we("universal challenger", a, t.universalChallengers[i])
|
|
1144
|
+
);
|
|
1145
|
+
return Vo([
|
|
1146
|
+
o,
|
|
1147
|
+
...s,
|
|
1148
|
+
...n
|
|
1149
|
+
]), {
|
|
1150
|
+
vaultProvider: o,
|
|
1151
|
+
vaultKeepers: s,
|
|
1152
|
+
universalChallengers: n,
|
|
1153
|
+
// Derived from the pairs, never the reverse — see ParticipantKeySet.
|
|
1154
|
+
vaultKeeperOperationKeysSorted: s.map((a) => a.operationBtcPubkey).sort(),
|
|
1155
|
+
universalChallengerOperationKeysSorted: n.map((a) => a.operationBtcPubkey).sort(),
|
|
1156
|
+
resolvedAt: r,
|
|
1157
|
+
query: e
|
|
1158
|
+
};
|
|
1159
|
+
}
|
|
1160
|
+
async function Ro(e) {
|
|
1161
|
+
const t = await e.operationKeyReader.getCurrentOperationKeys(
|
|
1162
|
+
e.query,
|
|
1163
|
+
e.blockNumber
|
|
1164
|
+
);
|
|
1165
|
+
return Ot(e.query, t, { mode: "current" });
|
|
1166
|
+
}
|
|
1167
|
+
async function Nt(e) {
|
|
1168
|
+
const t = await e.operationKeyReader.getOperationKeysAtEpochs(
|
|
1169
|
+
e.query,
|
|
1170
|
+
e.epochs
|
|
1171
|
+
);
|
|
1172
|
+
return Ot(e.query, t, {
|
|
1173
|
+
mode: "epochs",
|
|
1174
|
+
epochs: e.epochs
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
async function Ko(e) {
|
|
1178
|
+
const { basic: t, protocol: r } = e.vault, {
|
|
1179
|
+
registryReader: o,
|
|
1180
|
+
vaultKeeperReader: s,
|
|
1181
|
+
universalChallengerReader: n,
|
|
1182
|
+
operationKeyReader: a
|
|
1183
|
+
} = e.readers, [
|
|
1184
|
+
i,
|
|
1185
|
+
u,
|
|
1186
|
+
l,
|
|
1187
|
+
c
|
|
1188
|
+
] = await Promise.all([
|
|
1189
|
+
s.getVaultKeepersByVersion(
|
|
1190
|
+
t.applicationEntryPoint,
|
|
1191
|
+
r.appVaultKeepersVersion
|
|
1192
|
+
),
|
|
1193
|
+
n.getUniversalChallengersByVersion(
|
|
1194
|
+
r.universalChallengersVersion
|
|
1195
|
+
),
|
|
1196
|
+
o.getVaultProviderGenesisBtcPubKey(t.vaultProvider),
|
|
1197
|
+
o.getVaultKeyEpochs(e.vaultId)
|
|
1198
|
+
]);
|
|
1199
|
+
if (i.length === 0)
|
|
1200
|
+
throw new Error(
|
|
1201
|
+
`No vault keepers for version ${r.appVaultKeepersVersion}`
|
|
1202
|
+
);
|
|
1203
|
+
if (u.length === 0)
|
|
1204
|
+
throw new Error(
|
|
1205
|
+
`No universal challengers for version ${r.universalChallengersVersion}`
|
|
1206
|
+
);
|
|
1207
|
+
return Nt({
|
|
1208
|
+
operationKeyReader: a,
|
|
1209
|
+
query: {
|
|
1210
|
+
vaultProviderEthAddress: t.vaultProvider,
|
|
1211
|
+
vaultProviderGenesisBtcPubkey: `0x${l}`,
|
|
1212
|
+
applicationEntryPoint: t.applicationEntryPoint,
|
|
1213
|
+
vaultKeepers: i,
|
|
1214
|
+
universalChallengers: u
|
|
1215
|
+
},
|
|
1216
|
+
epochs: c
|
|
1217
|
+
});
|
|
1218
|
+
}
|
|
1219
|
+
async function tn(e) {
|
|
1220
|
+
const { vaultId: t, readers: r } = e, o = await r.registryReader.getVaultData(t), { basic: s, protocol: n } = o;
|
|
1221
|
+
if (n.vaultCoreVersion !== U)
|
|
1222
|
+
throw new Error(
|
|
1223
|
+
`Vault ${t} is stamped vault core version ${n.vaultCoreVersion}; delegated claim requires ${U}.`
|
|
1224
|
+
);
|
|
1225
|
+
const a = _e(
|
|
1226
|
+
s.depositorBtcPubKey,
|
|
1227
|
+
`getBtcVaultBasicInfo(${t}).depositorBtcPubKey`
|
|
1228
|
+
);
|
|
1229
|
+
if (s.status !== Ge.REDEEMED)
|
|
1230
|
+
throw new Me(
|
|
1231
|
+
t,
|
|
1232
|
+
s.depositorBtcPubKey,
|
|
1233
|
+
s.createdAt,
|
|
1234
|
+
s.createdAt,
|
|
1235
|
+
`the vault's status is ${s.status}, not Redeemed (${Ge.REDEEMED}); no scan was made`
|
|
1236
|
+
);
|
|
1237
|
+
const [i, u, l, c] = await Promise.all([
|
|
1238
|
+
Ko({ vaultId: t, vault: o, readers: r }),
|
|
1239
|
+
r.registryReader.getRegistrationRecordsAtBlock(s.createdAt),
|
|
1240
|
+
r.registryReader.getVaultClaimableBy(t, s.depositorBtcPubKey, s.createdAt).catch((v) => {
|
|
1241
|
+
throw Pr(v) ? new Me(
|
|
1242
|
+
t,
|
|
1243
|
+
s.depositorBtcPubKey,
|
|
1244
|
+
v.fromBlock,
|
|
1245
|
+
v.toBlock,
|
|
1246
|
+
"the vault is Redeemed but no VaultClaimableBy authorizes this depositor key in the finalized range. Either the redeem has not finalized yet (the scan stops about two epochs behind the tip), or the vault was redeemed for a vault keeper alone (redeemForAVK emits no depositor log), or the node did not serve every block scanned.",
|
|
1247
|
+
{ cause: v }
|
|
1248
|
+
) : v;
|
|
1249
|
+
}),
|
|
1250
|
+
r.protocolParamsReader.getOffchainParamsByVersion(
|
|
1251
|
+
n.offchainParamsVersion
|
|
1252
|
+
)
|
|
1253
|
+
]), d = _r(c.timelockAssert), h = mr(u, t, s.createdAt);
|
|
1254
|
+
wr(h);
|
|
1255
|
+
const g = xr(h);
|
|
1256
|
+
if (g.toLowerCase() !== n.prePeginTxHash.toLowerCase())
|
|
1257
|
+
throw new Error(
|
|
1258
|
+
`Registration log of vault ${t} records prePeginTxHash ${g} but the vault record says ${n.prePeginTxHash}; refusing an inconsistent node.`
|
|
1259
|
+
);
|
|
1260
|
+
if (h.vaultCoreVersion !== n.vaultCoreVersion)
|
|
1261
|
+
throw new Error(
|
|
1262
|
+
`Registration log of vault ${t} records vault core version ${h.vaultCoreVersion} but the vault record says ${n.vaultCoreVersion}; refusing an inconsistent node.`
|
|
1263
|
+
);
|
|
1264
|
+
if (h.amount !== s.amount)
|
|
1265
|
+
throw new Error(
|
|
1266
|
+
`Registration log of vault ${t} records amount ${h.amount} sats but the vault record says ${s.amount}; refusing an inconsistent node.`
|
|
1267
|
+
);
|
|
1268
|
+
if (h.depositor.toLowerCase() !== s.depositor.toLowerCase())
|
|
1269
|
+
throw new Error(
|
|
1270
|
+
`Registration log of vault ${t} records depositor ${h.depositor} but the vault record says ${s.depositor}; refusing an inconsistent node.`
|
|
1271
|
+
);
|
|
1272
|
+
if (h.vaultProvider.toLowerCase() !== s.vaultProvider.toLowerCase())
|
|
1273
|
+
throw new Error(
|
|
1274
|
+
`Registration log of vault ${t} records vaultProvider ${h.vaultProvider} but the vault record says ${s.vaultProvider}; refusing an inconsistent node.`
|
|
1275
|
+
);
|
|
1276
|
+
if (l.vaultCoreVersion !== n.vaultCoreVersion)
|
|
1277
|
+
throw new Error(
|
|
1278
|
+
`Redemption log of vault ${t} records vault core version ${l.vaultCoreVersion} but the vault record says ${n.vaultCoreVersion}; refusing an inconsistent node.`
|
|
1279
|
+
);
|
|
1280
|
+
if (l.proverCircuitVersion !== h.proverCircuitVersion)
|
|
1281
|
+
throw new Error(
|
|
1282
|
+
`Redemption log of vault ${t} records proverCircuitVersion ${l.proverCircuitVersion} but the registration log says ${h.proverCircuitVersion}; refusing an inconsistent node.`
|
|
1283
|
+
);
|
|
1284
|
+
if (h.proverCircuitVersion !== c.proverCircuitVersion)
|
|
1285
|
+
throw new Error(
|
|
1286
|
+
`Registration log of vault ${t} records proverCircuitVersion ${h.proverCircuitVersion} but the stamped offchain params say ${c.proverCircuitVersion}; refusing an inconsistent node.`
|
|
1287
|
+
);
|
|
1288
|
+
const p = Er(n.depositorSignedPeginTx);
|
|
1289
|
+
for (const [v, E] of [
|
|
1290
|
+
["Registration", h.peginTxHash],
|
|
1291
|
+
["Redemption", l.peginTxHash]
|
|
1292
|
+
])
|
|
1293
|
+
if (E.toLowerCase() !== p.toLowerCase())
|
|
1294
|
+
throw new Error(
|
|
1295
|
+
`${v} log of vault ${t} records peginTxHash ${E} but the vault's depositor-signed PegIn hashes to ${p}; refusing an inconsistent node.`
|
|
1296
|
+
);
|
|
1297
|
+
const y = G(
|
|
1298
|
+
Pt(p, s.depositor)
|
|
1299
|
+
);
|
|
1300
|
+
if (y !== G(t))
|
|
1301
|
+
throw new Error(
|
|
1302
|
+
`Depositor-signed PegIn of vault ${t} derives vault id ${y} with depositor ${s.depositor}; refusing an inconsistent node.`
|
|
1303
|
+
);
|
|
1304
|
+
for (const v of [
|
|
1305
|
+
"offchainParamsVersion",
|
|
1306
|
+
"universalChallengersVersion",
|
|
1307
|
+
"appVaultKeepersVersion"
|
|
1308
|
+
]) {
|
|
1309
|
+
if (h[v] !== n[v])
|
|
1310
|
+
throw new Error(
|
|
1311
|
+
`Registration log of vault ${t} records ${v} ${h[v]} but the vault record says ${n[v]}; refusing an inconsistent node.`
|
|
1312
|
+
);
|
|
1313
|
+
if (l[v] !== n[v])
|
|
1314
|
+
throw new Error(
|
|
1315
|
+
`Redemption log of vault ${t} records ${v} ${l[v]} but the vault record says ${n[v]}; refusing an inconsistent node.`
|
|
1316
|
+
);
|
|
1317
|
+
}
|
|
1318
|
+
const f = S.fromHex(
|
|
1319
|
+
b(n.depositorSignedPeginTx)
|
|
1320
|
+
);
|
|
1321
|
+
if (f.ins.length !== 1)
|
|
1322
|
+
throw new Error(
|
|
1323
|
+
`Depositor-signed PegIn of vault ${t} has ${f.ins.length} inputs; it spends Pre-PegIn ${n.prePeginTxHash} output ${n.htlcVout} with exactly one; refusing an inconsistent node.`
|
|
1324
|
+
);
|
|
1325
|
+
const P = Re(f.ins[0].hash), k = f.ins[0].index;
|
|
1326
|
+
if (P !== b(n.prePeginTxHash).toLowerCase() || k !== n.htlcVout)
|
|
1327
|
+
throw new Error(
|
|
1328
|
+
`Depositor-signed PegIn of vault ${t} spends ${P}:${k} but the vault record says Pre-PegIn ${n.prePeginTxHash} output ${n.htlcVout}; refusing an inconsistent node.`
|
|
1329
|
+
);
|
|
1330
|
+
const x = f.outs[Q];
|
|
1331
|
+
if (x === void 0)
|
|
1332
|
+
throw new Error(
|
|
1333
|
+
`Depositor-signed PegIn of vault ${t} has no output ${Q}; the Payout cannot spend the Vault UTXO.`
|
|
1334
|
+
);
|
|
1335
|
+
if (BigInt(x.value) !== s.amount)
|
|
1336
|
+
throw new Error(
|
|
1337
|
+
`Depositor-signed PegIn of vault ${t} pays ${x.value} sats to output ${Q} but the vault record says ${s.amount}; refusing an inconsistent node.`
|
|
1338
|
+
);
|
|
1339
|
+
return {
|
|
1340
|
+
context: {
|
|
1341
|
+
vaultId: t,
|
|
1342
|
+
depositorEthAddress: s.depositor,
|
|
1343
|
+
depositorBtcPubkey: a,
|
|
1344
|
+
registeredPayoutScriptPubKey: b(
|
|
1345
|
+
h.depositorPayoutScriptPubKey
|
|
1346
|
+
),
|
|
1347
|
+
vaultProviderBtcPubkey: i.vaultProvider.operationBtcPubkey,
|
|
1348
|
+
vaultKeeperBtcPubkeys: [
|
|
1349
|
+
...i.vaultKeeperOperationKeysSorted
|
|
1350
|
+
],
|
|
1351
|
+
universalChallengerBtcPubkeys: [
|
|
1352
|
+
...i.universalChallengerOperationKeysSorted
|
|
1353
|
+
],
|
|
1354
|
+
txGraphVersion: U,
|
|
1355
|
+
proverCircuitVersion: c.proverCircuitVersion,
|
|
1356
|
+
vaultCoreVersion: n.vaultCoreVersion,
|
|
1357
|
+
claimableEventBlockNumber: l.blockNumber,
|
|
1358
|
+
peginVaultOutputValueSats: x.value,
|
|
1359
|
+
protocolFeeRate: c.feeRate,
|
|
1360
|
+
councilSize: c.securityCouncilKeys.length,
|
|
1361
|
+
timelockPegin: d,
|
|
1362
|
+
timelockAssert: Number(c.timelockAssert)
|
|
1363
|
+
},
|
|
1364
|
+
vault: o,
|
|
1365
|
+
registrationRecord: h,
|
|
1366
|
+
registrationRecords: u,
|
|
1367
|
+
participantKeys: i,
|
|
1368
|
+
offchainParams: c,
|
|
1369
|
+
depositorBtcPubKeyBytes32: s.depositorBtcPubKey,
|
|
1370
|
+
depositorWotsPkHash: n.depositorWotsPkHash,
|
|
1371
|
+
prePeginTxHash: n.prePeginTxHash,
|
|
1372
|
+
peginTxHash: p,
|
|
1373
|
+
vaultProvider: s.vaultProvider,
|
|
1374
|
+
htlcVout: n.htlcVout
|
|
1375
|
+
};
|
|
1376
|
+
}
|
|
1377
|
+
const Ho = 8, Oo = 6e3, No = 10 * 6e4, Do = 10;
|
|
1378
|
+
class Dt extends Error {
|
|
1379
|
+
constructor(t) {
|
|
1380
|
+
super(t), this.name = "PeginRegistrationMissingError";
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
class Mt extends Error {
|
|
1384
|
+
constructor(t) {
|
|
1385
|
+
super(t), this.name = "PeginRegistrationNotFinalError";
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
function Mo(e) {
|
|
1389
|
+
return e instanceof Dt || e instanceof Error && e.name === "PeginRegistrationMissingError";
|
|
1390
|
+
}
|
|
1391
|
+
function rn(e) {
|
|
1392
|
+
return e instanceof Mt || e instanceof Error && e.name === "PeginRegistrationNotFinalError";
|
|
1393
|
+
}
|
|
1394
|
+
function Ze(e) {
|
|
1395
|
+
const { currentBlock: t, createdAtBlock: r } = e, o = t - r + 1n;
|
|
1396
|
+
return o < 0n ? 0 : Number(o);
|
|
1397
|
+
}
|
|
1398
|
+
async function on(e) {
|
|
1399
|
+
const {
|
|
1400
|
+
vaultRegistryReader: t,
|
|
1401
|
+
getBlockNumber: r,
|
|
1402
|
+
vaultIds: o,
|
|
1403
|
+
required: s = Ho,
|
|
1404
|
+
pollIntervalMs: n = Oo,
|
|
1405
|
+
timeoutMs: a = No,
|
|
1406
|
+
signal: i,
|
|
1407
|
+
onProgress: u
|
|
1408
|
+
} = e;
|
|
1409
|
+
if (o.length === 0)
|
|
1410
|
+
throw new Error(
|
|
1411
|
+
"waitForPeginRegistrationDepth requires at least one vault ID"
|
|
1412
|
+
);
|
|
1413
|
+
const l = Date.now();
|
|
1414
|
+
let c = !1, d = 0, h;
|
|
1415
|
+
for (; ; ) {
|
|
1416
|
+
if (i != null && i.aborted)
|
|
1417
|
+
throw new Error(
|
|
1418
|
+
`Aborted while waiting for peg-in registration depth (${o.length} vault(s))`
|
|
1419
|
+
);
|
|
1420
|
+
if (Date.now() - l >= a)
|
|
1421
|
+
throw new Mt(
|
|
1422
|
+
`Peg-in registration did not reach ${s} Ethereum confirmations within ${a}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.` + (h instanceof Error ? ` Last read error: ${h.message}` : "")
|
|
1423
|
+
);
|
|
1424
|
+
try {
|
|
1425
|
+
const g = await r(), p = await Promise.all(
|
|
1426
|
+
o.map((f) => t.getVaultBasicInfo(f))
|
|
1427
|
+
), y = p.findIndex(
|
|
1428
|
+
(f) => f.depositor === Sr || f.createdAt === 0n
|
|
1429
|
+
);
|
|
1430
|
+
if (y !== -1) {
|
|
1431
|
+
if (d += 1, !c && d > Do)
|
|
1432
|
+
throw new Dt(
|
|
1433
|
+
`Vault ${o[y]} is still not visible on-chain after ${d} reads — the registration does not exist.`
|
|
1434
|
+
);
|
|
1435
|
+
console.warn(
|
|
1436
|
+
`Peg-in registration for vault ${o[y]} is not visible in chain state at block ${g} — a lagging RPC backend or an Ethereum reorg. Still polling.`
|
|
1437
|
+
), u == null || u({ confirmations: 0, required: s });
|
|
1438
|
+
} else {
|
|
1439
|
+
c = !0, d = 0, h = void 0;
|
|
1440
|
+
let f = p[0], P = Ze({
|
|
1441
|
+
currentBlock: g,
|
|
1442
|
+
createdAtBlock: p[0].createdAt
|
|
1443
|
+
});
|
|
1444
|
+
for (const k of p.slice(1)) {
|
|
1445
|
+
const x = Ze({
|
|
1446
|
+
currentBlock: g,
|
|
1447
|
+
createdAtBlock: k.createdAt
|
|
1448
|
+
});
|
|
1449
|
+
x < P && (P = x, f = k);
|
|
1450
|
+
}
|
|
1451
|
+
if (u == null || u({ confirmations: P, required: s }), P >= s)
|
|
1452
|
+
return { confirmations: P, basicInfo: f };
|
|
1453
|
+
}
|
|
1454
|
+
} catch (g) {
|
|
1455
|
+
if (Mo(g))
|
|
1456
|
+
throw g;
|
|
1457
|
+
console.warn(
|
|
1458
|
+
`Registration-depth read failed (retrying in ${n}ms): ` + (g instanceof Error ? g.message : String(g))
|
|
1459
|
+
), h = g;
|
|
1460
|
+
}
|
|
1461
|
+
await new Promise((g, p) => {
|
|
1462
|
+
const y = () => {
|
|
1463
|
+
clearTimeout(f), p(
|
|
1464
|
+
new Error(
|
|
1465
|
+
`Aborted while waiting for peg-in registration depth (${o.length} vault(s))`
|
|
1466
|
+
)
|
|
1467
|
+
);
|
|
1468
|
+
}, f = setTimeout(() => {
|
|
1469
|
+
i == null || i.removeEventListener("abort", y), g();
|
|
1470
|
+
}, n);
|
|
1471
|
+
i == null || i.addEventListener("abort", y, { once: !0 });
|
|
1472
|
+
});
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
const Lo = /^(?:[0-9a-f]{2})*$/, Fo = /^[0-9a-f]{64}$/, Uo = /^([0-9a-f]{64}):(0|[1-9][0-9]*)$/, qo = -2147483648, Xo = 2147483647, xe = 4294967295, et = 2, tt = 2, le = 0;
|
|
1476
|
+
class m extends Error {
|
|
1477
|
+
constructor(t) {
|
|
1478
|
+
super(t), this.name = "GraphFingerprintError";
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
function $(e, t, r) {
|
|
1482
|
+
const o = e[t];
|
|
1483
|
+
if (o === void 0)
|
|
1484
|
+
throw new m(`Graph tx ${r} is missing "${t}"`);
|
|
1485
|
+
return o;
|
|
1486
|
+
}
|
|
1487
|
+
function Z(e, t) {
|
|
1488
|
+
if (!Array.isArray(e))
|
|
1489
|
+
throw new m(`Graph tx ${t} is not an array`);
|
|
1490
|
+
return e;
|
|
1491
|
+
}
|
|
1492
|
+
function B(e, t) {
|
|
1493
|
+
if (e === null || typeof e != "object" || Array.isArray(e))
|
|
1494
|
+
throw new m(`Graph tx ${t} is not an object`);
|
|
1495
|
+
return e;
|
|
1496
|
+
}
|
|
1497
|
+
function W(e, t, r, o) {
|
|
1498
|
+
if (typeof e != "number" || !Number.isSafeInteger(e) || e < r || e > o)
|
|
1499
|
+
throw new m(
|
|
1500
|
+
`Graph tx ${t} is not an integer in [${r}, ${o}]`
|
|
1501
|
+
);
|
|
1502
|
+
return e;
|
|
1503
|
+
}
|
|
1504
|
+
function Ee(e, t) {
|
|
1505
|
+
if (typeof e != "string" || !Lo.test(e))
|
|
1506
|
+
throw new m(
|
|
1507
|
+
`Graph tx ${t} is not lowercase hex without a prefix`
|
|
1508
|
+
);
|
|
1509
|
+
return H.from(e, "hex");
|
|
1510
|
+
}
|
|
1511
|
+
function de(e, t) {
|
|
1512
|
+
if (typeof e != "string" || !Fo.test(e))
|
|
1513
|
+
throw new m(
|
|
1514
|
+
`Graph ${t} is not 32 bytes of lowercase hex`
|
|
1515
|
+
);
|
|
1516
|
+
return e;
|
|
1517
|
+
}
|
|
1518
|
+
function rt(e, t) {
|
|
1519
|
+
const r = B(e, t), o = new S();
|
|
1520
|
+
return o.version = W(
|
|
1521
|
+
$(r, "version", t),
|
|
1522
|
+
`${t}.version`,
|
|
1523
|
+
qo,
|
|
1524
|
+
Xo
|
|
1525
|
+
), o.locktime = W(
|
|
1526
|
+
$(r, "lock_time", t),
|
|
1527
|
+
`${t}.lock_time`,
|
|
1528
|
+
0,
|
|
1529
|
+
xe
|
|
1530
|
+
), Z($(r, "input", t), `${t}.input`).forEach((s, n) => {
|
|
1531
|
+
const a = `${t}.input[${n}]`, i = B(s, a), u = $(i, "previous_output", a), l = typeof u == "string" && Uo.exec(u);
|
|
1532
|
+
if (!l)
|
|
1533
|
+
throw new m(
|
|
1534
|
+
`Graph tx ${a}.previous_output is not "<txid>:<vout>"`
|
|
1535
|
+
);
|
|
1536
|
+
const c = W(Number(l[2]), `${a}.previous_output vout`, 0, xe);
|
|
1537
|
+
o.addInput(
|
|
1538
|
+
H.from(l[1], "hex").reverse(),
|
|
1539
|
+
c,
|
|
1540
|
+
W($(i, "sequence", a), `${a}.sequence`, 0, xe),
|
|
1541
|
+
Ee($(i, "script_sig", a), `${a}.script_sig`)
|
|
1542
|
+
), o.ins[n].witness = Z(
|
|
1543
|
+
$(i, "witness", a),
|
|
1544
|
+
`${a}.witness`
|
|
1545
|
+
).map((d, h) => Ee(d, `${a}.witness[${h}]`));
|
|
1546
|
+
}), Z($(r, "output", t), `${t}.output`).forEach((s, n) => {
|
|
1547
|
+
const a = `${t}.output[${n}]`, i = B(s, a);
|
|
1548
|
+
o.addOutput(
|
|
1549
|
+
Ee($(i, "script_pubkey", a), `${a}.script_pubkey`),
|
|
1550
|
+
W($(i, "value", a), `${a}.value`, 0, Number.MAX_SAFE_INTEGER)
|
|
1551
|
+
);
|
|
1552
|
+
}), new Uint8Array(o.toBuffer());
|
|
1553
|
+
}
|
|
1554
|
+
function D(e, t) {
|
|
1555
|
+
const r = b(e).toLowerCase();
|
|
1556
|
+
let o;
|
|
1557
|
+
try {
|
|
1558
|
+
o = S.fromHex(r);
|
|
1559
|
+
} catch (s) {
|
|
1560
|
+
throw new m(
|
|
1561
|
+
`Presign ${t} is not one transaction: ${s instanceof Error ? s.message : String(s)}`
|
|
1562
|
+
);
|
|
1563
|
+
}
|
|
1564
|
+
if (o.toHex() !== r)
|
|
1565
|
+
throw new m(
|
|
1566
|
+
`Presign ${t} is not a canonical transaction encoding`
|
|
1567
|
+
);
|
|
1568
|
+
return o;
|
|
1569
|
+
}
|
|
1570
|
+
function Lt(e, t) {
|
|
1571
|
+
const r = e.ins[t];
|
|
1572
|
+
if (r)
|
|
1573
|
+
return {
|
|
1574
|
+
txid: H.from(r.hash).reverse().toString("hex"),
|
|
1575
|
+
vout: r.index
|
|
1576
|
+
};
|
|
1577
|
+
}
|
|
1578
|
+
function Ft(e, t) {
|
|
1579
|
+
if (!e.outs[le])
|
|
1580
|
+
throw new m(
|
|
1581
|
+
`Presign ${t}.claim_tx must have output ${le}`
|
|
1582
|
+
);
|
|
1583
|
+
}
|
|
1584
|
+
function Go(e, t, r) {
|
|
1585
|
+
if (e.ins.length !== 1)
|
|
1586
|
+
throw new m(
|
|
1587
|
+
`Presign ${r}.claim_tx must have exactly one input, got ${e.ins.length}`
|
|
1588
|
+
);
|
|
1589
|
+
Ft(e, r);
|
|
1590
|
+
const o = Lt(e, 0);
|
|
1591
|
+
if ((o == null ? void 0 : o.txid) !== t || o.vout !== X) {
|
|
1592
|
+
const s = o ? `${o.txid}:${o.vout}` : "no input";
|
|
1593
|
+
throw new m(
|
|
1594
|
+
`Presign ${r}.claim_tx must spend ${t}:${X}, got ${s}`
|
|
1595
|
+
);
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
function He(e, t, r) {
|
|
1599
|
+
const o = Lt(e, 0);
|
|
1600
|
+
if ((o == null ? void 0 : o.txid) !== t || o.vout !== le) {
|
|
1601
|
+
const s = o ? `${o.txid}:${o.vout}` : "no input";
|
|
1602
|
+
throw new m(
|
|
1603
|
+
`Presign ${r}.assert_tx input 0 must spend ${t}:${le}, got ${s}`
|
|
1604
|
+
);
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
function Ut(e) {
|
|
1608
|
+
const t = D(e.peginTxHex, `${e.path}.pegin_tx`), r = D(e.claimTxHex, `${e.path}.claim_tx`), o = D(e.assertTxHex, `${e.path}.assert_tx`);
|
|
1609
|
+
return { peginTx: t, claimTx: r, assertTx: o };
|
|
1610
|
+
}
|
|
1611
|
+
function zo(e) {
|
|
1612
|
+
const t = D(e.claimTxHex, `${e.path}.claim_tx`), r = D(e.assertTxHex, `${e.path}.assert_tx`);
|
|
1613
|
+
Ft(t, e.path), He(r, t.getId(), e.path);
|
|
1614
|
+
}
|
|
1615
|
+
function jo(e) {
|
|
1616
|
+
const { peginTx: t, claimTx: r, assertTx: o } = Ut(e);
|
|
1617
|
+
Go(r, t.getId(), e.path), He(o, r.getId(), e.path);
|
|
1618
|
+
}
|
|
1619
|
+
function Wo(e, t) {
|
|
1620
|
+
const [r, ...o] = e.ins;
|
|
1621
|
+
if (!r || o.length > 0)
|
|
1622
|
+
throw new m(
|
|
1623
|
+
`Presign claim_tx must have exactly one input, got ${e.ins.length}`
|
|
1624
|
+
);
|
|
1625
|
+
const s = H.from(r.hash).reverse().toString("hex");
|
|
1626
|
+
if (s !== t || r.index !== X)
|
|
1627
|
+
throw new m(
|
|
1628
|
+
`Presign claim_tx must spend ${t}:${X}, got ${s}:${r.index}`
|
|
1629
|
+
);
|
|
1630
|
+
if (e.version !== et)
|
|
1631
|
+
throw new m(
|
|
1632
|
+
`Presign claim_tx version must be ${et}, got ${e.version}`
|
|
1633
|
+
);
|
|
1634
|
+
if (r.witness.length > 0)
|
|
1635
|
+
throw new m(
|
|
1636
|
+
`Presign claim_tx input must have an empty witness, got ${r.witness.length} item(s)`
|
|
1637
|
+
);
|
|
1638
|
+
if (e.outs.length !== tt)
|
|
1639
|
+
throw new m(
|
|
1640
|
+
`Presign claim_tx must have exactly ${tt} outputs, got ${e.outs.length}`
|
|
1641
|
+
);
|
|
1642
|
+
}
|
|
1643
|
+
function qt(e) {
|
|
1644
|
+
const t = [...e.challengers].sort(
|
|
1645
|
+
(o, s) => o.pubkey < s.pubkey ? -1 : o.pubkey > s.pubkey ? 1 : 0
|
|
1646
|
+
), r = [e.peginTx, e.claimTx, e.assertTx, e.payoutTx];
|
|
1647
|
+
return t.forEach((o, s) => {
|
|
1648
|
+
const n = de(o.pubkey, "challenger pubkey");
|
|
1649
|
+
if (s > 0 && t[s - 1].pubkey === n)
|
|
1650
|
+
throw new m(`Graph lists challenger ${n} twice`);
|
|
1651
|
+
r.push(je(n), o.nopayoutTx);
|
|
1652
|
+
for (const a of o.outputLabelHashes)
|
|
1653
|
+
r.push(je(de(a, "output_label_hashes entry")));
|
|
1654
|
+
}), Kr(Hr(Or(...r)));
|
|
1655
|
+
}
|
|
1656
|
+
function Yo(e) {
|
|
1657
|
+
const t = b(e.peginTxid).toLowerCase(), { peginTx: r, claimTx: o, assertTx: s } = Ut({
|
|
1658
|
+
peginTxHex: e.peginTxHex,
|
|
1659
|
+
claimTxHex: e.claimTxHex,
|
|
1660
|
+
assertTxHex: e.assertTxHex,
|
|
1661
|
+
path: "depositor_graph"
|
|
1662
|
+
});
|
|
1663
|
+
if (r.getId() !== t)
|
|
1664
|
+
throw new m(
|
|
1665
|
+
`Presign pegin_tx hashes to ${r.getId()}, expected ${t}`
|
|
1666
|
+
);
|
|
1667
|
+
Wo(o, t), He(s, o.getId(), "depositor_graph");
|
|
1668
|
+
const n = (a) => new Uint8Array(a.toBuffer());
|
|
1669
|
+
return qt({
|
|
1670
|
+
peginTx: n(r),
|
|
1671
|
+
claimTx: n(o),
|
|
1672
|
+
assertTx: n(s),
|
|
1673
|
+
payoutTx: n(D(e.payoutTxHex, "payout_tx")),
|
|
1674
|
+
challengers: e.challengers.map((a) => ({
|
|
1675
|
+
pubkey: _(a.challenger_pubkey),
|
|
1676
|
+
nopayoutTx: n(D(a.nopayout_tx.tx_hex, "nopayout_tx")),
|
|
1677
|
+
outputLabelHashes: a.output_label_hashes.map(
|
|
1678
|
+
(i) => b(i).toLowerCase()
|
|
1679
|
+
)
|
|
1680
|
+
}))
|
|
1681
|
+
});
|
|
1682
|
+
}
|
|
1683
|
+
function Qo(e) {
|
|
1684
|
+
const t = (o) => rt(B($(e, o, "graph"), o).tx, o), r = B(
|
|
1685
|
+
$(e, "challenger_subgraphs", "graph"),
|
|
1686
|
+
"challenger_subgraphs"
|
|
1687
|
+
);
|
|
1688
|
+
return qt({
|
|
1689
|
+
peginTx: t("pegin_tx"),
|
|
1690
|
+
claimTx: t("claim_tx"),
|
|
1691
|
+
assertTx: t("assert_tx"),
|
|
1692
|
+
payoutTx: t("payout_tx"),
|
|
1693
|
+
challengers: Object.entries(r).map(([o, s]) => {
|
|
1694
|
+
const n = `challenger_subgraphs[${o}]`, a = B(s, n);
|
|
1695
|
+
return {
|
|
1696
|
+
pubkey: o,
|
|
1697
|
+
nopayoutTx: rt(
|
|
1698
|
+
B($(a, "nopayout_tx", n), `${n}.nopayout_tx`).tx,
|
|
1699
|
+
`${n}.nopayout_tx`
|
|
1700
|
+
),
|
|
1701
|
+
outputLabelHashes: Z(
|
|
1702
|
+
$(a, "output_label_hashes", n),
|
|
1703
|
+
`${n}.output_label_hashes`
|
|
1704
|
+
).map(
|
|
1705
|
+
(i, u) => de(i, `${n}.output_label_hashes[${u}]`)
|
|
1706
|
+
)
|
|
1707
|
+
};
|
|
1708
|
+
})
|
|
1709
|
+
});
|
|
1710
|
+
}
|
|
1711
|
+
function Jo(e) {
|
|
1712
|
+
const t = B(
|
|
1713
|
+
$(e, "challenger_pubkeys", "graph"),
|
|
1714
|
+
"challenger_pubkeys"
|
|
1715
|
+
), r = /* @__PURE__ */ new Set();
|
|
1716
|
+
for (const o of ["local", "universal"])
|
|
1717
|
+
Z(
|
|
1718
|
+
$(t, o, "challenger_pubkeys"),
|
|
1719
|
+
`challenger_pubkeys.${o}`
|
|
1720
|
+
).forEach((s, n) => {
|
|
1721
|
+
const a = de(s, `challenger_pubkeys.${o}[${n}]`);
|
|
1722
|
+
if (r.has(a))
|
|
1723
|
+
throw new m(
|
|
1724
|
+
`Graph declares challenger ${a} more than once`
|
|
1725
|
+
);
|
|
1726
|
+
r.add(a);
|
|
1727
|
+
});
|
|
1728
|
+
return r;
|
|
1729
|
+
}
|
|
1730
|
+
function sn(e, t) {
|
|
1731
|
+
const r = Qo(e);
|
|
1732
|
+
if (r !== t)
|
|
1733
|
+
throw new m(
|
|
1734
|
+
`Graph fingerprint ${r} does not match the presign fingerprint ${t}`
|
|
1735
|
+
);
|
|
1736
|
+
const o = Object.keys(
|
|
1737
|
+
B(e.challenger_subgraphs, "challenger_subgraphs")
|
|
1738
|
+
), s = Jo(e);
|
|
1739
|
+
if (o.length !== s.size || o.some((n) => !s.has(n)))
|
|
1740
|
+
throw new m(
|
|
1741
|
+
`Graph challenger_subgraphs keys ${o.join(", ")} do not match challenger_pubkeys ${[...s].join(", ")}`
|
|
1742
|
+
);
|
|
1743
|
+
}
|
|
1744
|
+
const Zo = 1;
|
|
1745
|
+
function es(e, t, r) {
|
|
1746
|
+
const o = r.map(
|
|
1747
|
+
(d) => b(d).toLowerCase()
|
|
1748
|
+
), s = t.filter((d) => o.includes(d));
|
|
1749
|
+
if (s.length > 0)
|
|
1750
|
+
throw new Error(
|
|
1751
|
+
`Cannot validate challenger set: vault keepers and universal challengers overlap (${s.join(", ")})`
|
|
1752
|
+
);
|
|
1753
|
+
const n = [...t, ...o], a = e.map(
|
|
1754
|
+
(d) => b(d.challenger_pubkey).toLowerCase()
|
|
1755
|
+
), i = new Set(a);
|
|
1756
|
+
if (i.size !== a.length)
|
|
1757
|
+
throw new Error(
|
|
1758
|
+
"Depositor graph contains duplicate challenger entries in challenger_presign_data"
|
|
1759
|
+
);
|
|
1760
|
+
const u = new Set(n), l = n.filter((d) => !i.has(d)), c = a.filter((d) => !u.has(d));
|
|
1761
|
+
if (l.length > 0 || c.length > 0)
|
|
1762
|
+
throw new Error(
|
|
1763
|
+
"Depositor graph challenger set does not match expected (local ∪ universal)" + (l.length > 0 ? ` (missing: ${l.join(", ")})` : "") + (c.length > 0 ? ` (unexpected: ${c.join(", ")})` : "")
|
|
1764
|
+
);
|
|
1765
|
+
}
|
|
1766
|
+
function ts(e, t) {
|
|
1767
|
+
const r = e.ins[t];
|
|
1768
|
+
return Ie(new Uint8Array(r.hash).slice().reverse());
|
|
1769
|
+
}
|
|
1770
|
+
function $e(e, t, r, o, s) {
|
|
1771
|
+
const n = e.ins[t];
|
|
1772
|
+
if (n.index !== 0)
|
|
1773
|
+
throw new Error(
|
|
1774
|
+
`NoPayout (challenger ${s}) input ${t} expected to spend ${o} vout 0, got vout ${n.index}`
|
|
1775
|
+
);
|
|
1776
|
+
const a = r.getId(), i = ts(e, t);
|
|
1777
|
+
if (i !== a)
|
|
1778
|
+
throw new Error(
|
|
1779
|
+
`NoPayout (challenger ${s}) input ${t} does not reference ${o} (expected txid ${a}, got ${i})`
|
|
1780
|
+
);
|
|
1781
|
+
}
|
|
1782
|
+
async function rs(e, t, r) {
|
|
1783
|
+
const o = [], s = [], n = [], a = mt({
|
|
1784
|
+
claimerBtcPubkey: r.depositorBtcPubkey,
|
|
1785
|
+
depositorBtcPubkey: r.depositorBtcPubkey,
|
|
1786
|
+
vaultProviderBtcPubkey: r.vaultProviderBtcPubkey,
|
|
1787
|
+
vaultKeeperBtcPubkeys: r.vaultKeeperBtcPubkeys
|
|
1788
|
+
});
|
|
1789
|
+
es(
|
|
1790
|
+
e.challenger_presign_data,
|
|
1791
|
+
a,
|
|
1792
|
+
r.universalChallengerBtcPubkeys
|
|
1793
|
+
);
|
|
1794
|
+
const i = await Tr({
|
|
1795
|
+
vaultCoreVersion: r.vaultCoreVersion,
|
|
1796
|
+
vkClaimerPayoutScriptPubKeys: r.vkClaimerPayoutScriptPubKeys,
|
|
1797
|
+
vpCommissionScriptPubKey: r.vpCommissionScriptPubKey,
|
|
1798
|
+
payoutTxHex: e.payout_tx.tx_hex,
|
|
1799
|
+
peginTxHex: r.peginTxHex,
|
|
1800
|
+
assertTxHex: e.assert_tx.tx_hex,
|
|
1801
|
+
timelockAssert: r.timelockAssert,
|
|
1802
|
+
depositorBtcPubkey: r.depositorBtcPubkey,
|
|
1803
|
+
vaultProviderBtcPubkey: r.vaultProviderBtcPubkey,
|
|
1804
|
+
vaultKeeperBtcPubkeys: r.vaultKeeperBtcPubkeys,
|
|
1805
|
+
universalChallengerBtcPubkeys: r.universalChallengerBtcPubkeys,
|
|
1806
|
+
timelockPegin: r.timelockPegin,
|
|
1807
|
+
network: r.network,
|
|
1808
|
+
claimerBtcPubkey: r.depositorBtcPubkey,
|
|
1809
|
+
registeredPayoutScriptPubKey: r.registeredPayoutScriptPubKey,
|
|
1810
|
+
commissionBps: Zo,
|
|
1811
|
+
protocolFeeRate: r.protocolFeeRate,
|
|
1812
|
+
councilMembers: r.councilMembers,
|
|
1813
|
+
councilQuorum: r.councilQuorum
|
|
1814
|
+
});
|
|
1815
|
+
o.push(i.psbtHex), s.push(
|
|
1816
|
+
ue(
|
|
1817
|
+
t,
|
|
1818
|
+
Xe
|
|
1819
|
+
)
|
|
1820
|
+
);
|
|
1821
|
+
const u = b(r.depositorBtcPubkey), l = S.fromHex(
|
|
1822
|
+
b(e.assert_tx.tx_hex)
|
|
1823
|
+
);
|
|
1824
|
+
for (const c of e.challenger_presign_data) {
|
|
1825
|
+
const d = b(c.challenger_pubkey), h = o.length, g = await os({
|
|
1826
|
+
challenger: c,
|
|
1827
|
+
challengerPubkey: d,
|
|
1828
|
+
claimerPubkey: u,
|
|
1829
|
+
localChallengers: a,
|
|
1830
|
+
assertTxParsed: l,
|
|
1831
|
+
ctx: r
|
|
1832
|
+
});
|
|
1833
|
+
o.push(g), s.push(
|
|
1834
|
+
ue(
|
|
1835
|
+
t,
|
|
1836
|
+
Xe
|
|
1837
|
+
)
|
|
1838
|
+
), n.push({
|
|
1839
|
+
challengerPubkey: d,
|
|
1840
|
+
noPayoutIdx: h
|
|
1841
|
+
});
|
|
1842
|
+
}
|
|
1843
|
+
return { psbtHexes: o, signOptions: s, challengerEntries: n };
|
|
1844
|
+
}
|
|
1845
|
+
async function os(e) {
|
|
1846
|
+
const {
|
|
1847
|
+
challenger: t,
|
|
1848
|
+
challengerPubkey: r,
|
|
1849
|
+
claimerPubkey: o,
|
|
1850
|
+
localChallengers: s,
|
|
1851
|
+
assertTxParsed: n,
|
|
1852
|
+
ctx: a
|
|
1853
|
+
} = e;
|
|
1854
|
+
Nr(
|
|
1855
|
+
t.nopayout_tx.tx_hex,
|
|
1856
|
+
r,
|
|
1857
|
+
a.network
|
|
1858
|
+
);
|
|
1859
|
+
const i = S.fromHex(
|
|
1860
|
+
b(t.nopayout_tx.tx_hex)
|
|
1861
|
+
), u = S.fromHex(
|
|
1862
|
+
b(t.challenge_assert_x_tx.tx_hex)
|
|
1863
|
+
), l = S.fromHex(
|
|
1864
|
+
b(t.challenge_assert_y_tx.tx_hex)
|
|
1865
|
+
);
|
|
1866
|
+
if (i.ins.length !== 3)
|
|
1867
|
+
throw new Error(
|
|
1868
|
+
`NoPayout (challenger ${r}) must have exactly 3 inputs, got ${i.ins.length}`
|
|
1869
|
+
);
|
|
1870
|
+
$e(
|
|
1871
|
+
i,
|
|
1872
|
+
0,
|
|
1873
|
+
n,
|
|
1874
|
+
"Assert",
|
|
1875
|
+
r
|
|
1876
|
+
), $e(
|
|
1877
|
+
i,
|
|
1878
|
+
1,
|
|
1879
|
+
u,
|
|
1880
|
+
"ChallengeAssertX",
|
|
1881
|
+
r
|
|
1882
|
+
), $e(
|
|
1883
|
+
i,
|
|
1884
|
+
2,
|
|
1885
|
+
l,
|
|
1886
|
+
"ChallengeAssertY",
|
|
1887
|
+
r
|
|
1888
|
+
);
|
|
1889
|
+
const c = [
|
|
1890
|
+
n.outs[0],
|
|
1891
|
+
u.outs[0],
|
|
1892
|
+
l.outs[0]
|
|
1893
|
+
].map((d) => ({
|
|
1894
|
+
script_pubkey: Ie(new Uint8Array(d.script)),
|
|
1895
|
+
value: d.value
|
|
1896
|
+
}));
|
|
1897
|
+
return Dr({
|
|
1898
|
+
noPayoutTxHex: t.nopayout_tx.tx_hex,
|
|
1899
|
+
challengerPubkey: r,
|
|
1900
|
+
prevouts: c,
|
|
1901
|
+
connectorParams: {
|
|
1902
|
+
txGraphVersion: a.vaultCoreVersion,
|
|
1903
|
+
claimer: o,
|
|
1904
|
+
localChallengers: s,
|
|
1905
|
+
universalChallengers: a.universalChallengerBtcPubkeys,
|
|
1906
|
+
timelockAssert: a.timelockAssert,
|
|
1907
|
+
councilMembers: a.councilMembers,
|
|
1908
|
+
councilQuorum: a.councilQuorum
|
|
1909
|
+
}
|
|
1910
|
+
});
|
|
1911
|
+
}
|
|
1912
|
+
function ss(e, t, r) {
|
|
1913
|
+
ie(e[0]);
|
|
1914
|
+
const s = ae(
|
|
1915
|
+
e[0].returnedPsbtHex,
|
|
1916
|
+
r
|
|
1917
|
+
);
|
|
1918
|
+
re({
|
|
1919
|
+
requestedPsbtHex: e[0].requestedPsbtHex,
|
|
1920
|
+
signatureHex: s,
|
|
1921
|
+
signerXOnlyPubkeyHex: r,
|
|
1922
|
+
inputIndex: 0
|
|
1923
|
+
});
|
|
1924
|
+
const n = {};
|
|
1925
|
+
for (const a of t) {
|
|
1926
|
+
ie(e[a.noPayoutIdx]);
|
|
1927
|
+
const i = ae(
|
|
1928
|
+
e[a.noPayoutIdx].returnedPsbtHex,
|
|
1929
|
+
r
|
|
1930
|
+
);
|
|
1931
|
+
re({
|
|
1932
|
+
requestedPsbtHex: e[a.noPayoutIdx].requestedPsbtHex,
|
|
1933
|
+
signatureHex: i,
|
|
1934
|
+
signerXOnlyPubkeyHex: r,
|
|
1935
|
+
inputIndex: 0
|
|
1936
|
+
}), n[a.challengerPubkey] = {
|
|
1937
|
+
nopayout_signature: i
|
|
1938
|
+
};
|
|
1939
|
+
}
|
|
1940
|
+
return {
|
|
1941
|
+
payout_signatures: {
|
|
1942
|
+
payout_signature: s
|
|
1943
|
+
},
|
|
1944
|
+
per_challenger: n
|
|
1945
|
+
};
|
|
1946
|
+
}
|
|
1947
|
+
async function ns(e) {
|
|
1948
|
+
const { depositorGraph: t, btcWallet: r, signingContext: o } = e;
|
|
1949
|
+
jo({
|
|
1950
|
+
peginTxHex: o.peginTxHex,
|
|
1951
|
+
claimTxHex: t.claim_tx.tx_hex,
|
|
1952
|
+
assertTxHex: t.assert_tx.tx_hex,
|
|
1953
|
+
path: "depositor_graph"
|
|
1954
|
+
});
|
|
1955
|
+
const s = await r.getPublicKeyHex(), { depositorPubkey: n } = tr(
|
|
1956
|
+
s,
|
|
1957
|
+
b(o.depositorBtcPubkey)
|
|
1958
|
+
), { psbtHexes: a, signOptions: i, challengerEntries: u } = await rs(
|
|
1959
|
+
t,
|
|
1960
|
+
s,
|
|
1961
|
+
o
|
|
1962
|
+
), l = await vt(
|
|
1963
|
+
r,
|
|
1964
|
+
a,
|
|
1965
|
+
i
|
|
1966
|
+
), c = a.map((d, h) => ({
|
|
1967
|
+
requestedPsbtHex: d,
|
|
1968
|
+
returnedPsbtHex: l[h]
|
|
1969
|
+
}));
|
|
1970
|
+
return ss(
|
|
1971
|
+
c,
|
|
1972
|
+
u,
|
|
1973
|
+
n
|
|
1974
|
+
);
|
|
1975
|
+
}
|
|
1976
|
+
const is = 1e4, L = 10;
|
|
1977
|
+
async function Xt(e) {
|
|
1978
|
+
const {
|
|
1979
|
+
statusReader: t,
|
|
1980
|
+
vaultId: r,
|
|
1981
|
+
peginTxid: o,
|
|
1982
|
+
targetStatuses: s,
|
|
1983
|
+
timeoutMs: n,
|
|
1984
|
+
pollIntervalMs: a = is,
|
|
1985
|
+
signal: i
|
|
1986
|
+
} = e, u = Date.now();
|
|
1987
|
+
for (; ; ) {
|
|
1988
|
+
if (i != null && i.aborted)
|
|
1989
|
+
throw new Error(
|
|
1990
|
+
`Polling aborted for vault ${r.slice(0, L)}… (target: ${[...s].join(", ")})`
|
|
1991
|
+
);
|
|
1992
|
+
if (Date.now() - u >= n)
|
|
1993
|
+
throw new Error(
|
|
1994
|
+
`Polling timeout after ${n}ms for vault ${r.slice(0, L)}… (target: ${[...s].join(", ")})`
|
|
1995
|
+
);
|
|
1996
|
+
try {
|
|
1997
|
+
const l = await t.getPeginStatusByVaultId(
|
|
1998
|
+
{ vault_id: r },
|
|
1999
|
+
i
|
|
2000
|
+
);
|
|
2001
|
+
if (ze(l.vault_id) !== ze(r))
|
|
2002
|
+
throw new Error(
|
|
2003
|
+
`getPeginStatusByVaultId returned status for vault ${l.vault_id.slice(0, L)}…, requested ${r.slice(0, L)}…`
|
|
2004
|
+
);
|
|
2005
|
+
if (l.pegin_txid.toLowerCase() !== o.toLowerCase())
|
|
2006
|
+
throw new Error(
|
|
2007
|
+
`getPeginStatusByVaultId returned status for pegin ${l.pegin_txid.slice(0, 8)}…, requested ${o.slice(0, 8)}…`
|
|
2008
|
+
);
|
|
2009
|
+
const c = l.status;
|
|
2010
|
+
if (s.has(c) || c === R.ACTIVATED)
|
|
2011
|
+
return c;
|
|
2012
|
+
if (c === R.EXPIRED || Ir.has(c))
|
|
2013
|
+
throw new Error(
|
|
2014
|
+
`Vault ${r.slice(0, L)}… reached terminal status "${c}" while waiting for ${[...s].join(", ")}`
|
|
2015
|
+
);
|
|
2016
|
+
} catch (l) {
|
|
2017
|
+
if (!(l instanceof Vr && l.code === Rr.PEGIN_NOT_FOUND))
|
|
2018
|
+
throw l;
|
|
2019
|
+
}
|
|
2020
|
+
await new Promise((l, c) => {
|
|
2021
|
+
const d = () => {
|
|
2022
|
+
clearTimeout(h), c(
|
|
2023
|
+
new Error(
|
|
2024
|
+
`Polling aborted for vault ${r.slice(0, L)}… (target: ${[...s].join(", ")})`
|
|
2025
|
+
)
|
|
2026
|
+
);
|
|
2027
|
+
}, h = setTimeout(() => {
|
|
2028
|
+
i == null || i.removeEventListener("abort", d), l();
|
|
2029
|
+
}, a);
|
|
2030
|
+
i == null || i.addEventListener("abort", d, { once: !0 });
|
|
2031
|
+
});
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
const as = 1200 * 1e3, Gt = /* @__PURE__ */ new Set([
|
|
2035
|
+
R.PENDING_ACKS,
|
|
2036
|
+
R.PENDING_ACTIVATION,
|
|
2037
|
+
R.ACTIVATED_PENDING_BROADCAST,
|
|
2038
|
+
R.ACTIVATED
|
|
2039
|
+
]), us = /* @__PURE__ */ new Set([
|
|
2040
|
+
R.PENDING_DEPOSITOR_SIGNATURES,
|
|
2041
|
+
...Gt
|
|
2042
|
+
]);
|
|
2043
|
+
function cs(e) {
|
|
2044
|
+
return e.map((t) => ({
|
|
2045
|
+
claimerPubkeyXOnly: he(t.claimer_pubkey),
|
|
2046
|
+
payoutTxHex: t.payout_tx.tx_hex,
|
|
2047
|
+
assertTxHex: t.assert_tx.tx_hex
|
|
2048
|
+
}));
|
|
2049
|
+
}
|
|
2050
|
+
function I(e) {
|
|
2051
|
+
return he(e).toLowerCase();
|
|
2052
|
+
}
|
|
2053
|
+
function ls(e, t) {
|
|
2054
|
+
const r = (u, l, c) => {
|
|
2055
|
+
throw new Error(
|
|
2056
|
+
`Deposit terms ${u} (${String(l)}) does not match the vault's version-locked signing context (${String(c)}); refusing to sign payouts against terms that describe a different graph.`
|
|
2057
|
+
);
|
|
2058
|
+
}, o = [
|
|
2059
|
+
["protocolFeeRate", e.protocolFeeRate, t.protocolFeeRate],
|
|
2060
|
+
["vaultCoreVersion", e.vaultCoreVersion, t.vaultCoreVersion],
|
|
2061
|
+
["timelockPegin", e.timelockPegin, t.timelockPegin],
|
|
2062
|
+
["timelockAssert", e.timelockAssert, t.timelockAssert]
|
|
2063
|
+
];
|
|
2064
|
+
for (const [u, l, c] of o)
|
|
2065
|
+
l !== c && r(u, l, c);
|
|
2066
|
+
const s = (u) => u.map(I).sort(), n = (u, l) => {
|
|
2067
|
+
const c = s(u), d = s(l);
|
|
2068
|
+
return c.length === d.length && c.every((h, g) => h === d[g]);
|
|
2069
|
+
};
|
|
2070
|
+
n(e.vaultKeeperBtcPubkeys, t.vaultKeeperBtcPubkeys) || r(
|
|
2071
|
+
"vaultKeeperBtcPubkeys",
|
|
2072
|
+
e.vaultKeeperBtcPubkeys.join(","),
|
|
2073
|
+
t.vaultKeeperBtcPubkeys.join(",")
|
|
2074
|
+
), n(
|
|
2075
|
+
e.universalChallengerBtcPubkeys,
|
|
2076
|
+
t.universalChallengerBtcPubkeys
|
|
2077
|
+
) || r(
|
|
2078
|
+
"universalChallengerBtcPubkeys",
|
|
2079
|
+
e.universalChallengerBtcPubkeys.join(","),
|
|
2080
|
+
t.universalChallengerBtcPubkeys.join(",")
|
|
2081
|
+
);
|
|
2082
|
+
const a = I(t.vaultProviderBtcPubkey), i = e.vaults.map(
|
|
2083
|
+
(u) => I(u.vaultProviderBtcPubkey)
|
|
2084
|
+
);
|
|
2085
|
+
i.includes(a) || r(
|
|
2086
|
+
"vaults[].vaultProviderBtcPubkey",
|
|
2087
|
+
i.join(",") || "<no vaults>",
|
|
2088
|
+
t.vaultProviderBtcPubkey
|
|
2089
|
+
);
|
|
2090
|
+
}
|
|
2091
|
+
function ds(e, t, r, o) {
|
|
2092
|
+
const s = I(o), n = [
|
|
2093
|
+
I(t),
|
|
2094
|
+
...r.map(I)
|
|
2095
|
+
], a = new Set(n);
|
|
2096
|
+
if (a.size !== n.length)
|
|
2097
|
+
throw new Error(
|
|
2098
|
+
"Cannot validate claimer set: signing context contains duplicate vault provider or vault keeper key"
|
|
2099
|
+
);
|
|
2100
|
+
if (a.has(s))
|
|
2101
|
+
throw new Error(
|
|
2102
|
+
"Cannot validate claimer set: depositor key overlaps with vault provider or vault keeper set"
|
|
2103
|
+
);
|
|
2104
|
+
const i = e.map(
|
|
2105
|
+
(h) => I(h.claimer_pubkey)
|
|
2106
|
+
);
|
|
2107
|
+
if (new Set(i).size !== i.length)
|
|
2108
|
+
throw new Error("Presign response contains duplicate claimer entries");
|
|
2109
|
+
const u = i.filter((h) => h !== s), l = new Set(u), c = n.filter((h) => !l.has(h)), d = u.filter((h) => !a.has(h));
|
|
2110
|
+
if (c.length > 0 || d.length > 0)
|
|
2111
|
+
throw new Error(
|
|
2112
|
+
"Presign response claimer set does not match expected (vault provider ∪ vault keepers)" + (c.length > 0 ? ` (missing: ${c.join(", ")})` : "") + (d.length > 0 ? ` (unexpected: ${d.join(", ")})` : "")
|
|
2113
|
+
);
|
|
2114
|
+
}
|
|
2115
|
+
function ot(e, t) {
|
|
2116
|
+
return {
|
|
2117
|
+
vaultCoreVersion: t.vaultCoreVersion,
|
|
2118
|
+
payoutTxHex: e.payoutTxHex,
|
|
2119
|
+
peginTxHex: t.peginTxHex,
|
|
2120
|
+
assertTxHex: e.assertTxHex,
|
|
2121
|
+
vaultProviderBtcPubkey: t.vaultProviderBtcPubkey,
|
|
2122
|
+
vaultKeeperBtcPubkeys: t.vaultKeeperBtcPubkeys,
|
|
2123
|
+
universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys,
|
|
2124
|
+
depositorBtcPubkey: t.depositorBtcPubkey,
|
|
2125
|
+
timelockPegin: t.timelockPegin,
|
|
2126
|
+
timelockAssert: t.timelockAssert,
|
|
2127
|
+
registeredPayoutScriptPubKey: t.registeredPayoutScriptPubKey,
|
|
2128
|
+
claimerBtcPubkey: e.claimerPubkeyXOnly,
|
|
2129
|
+
commissionBps: t.commissionBps,
|
|
2130
|
+
protocolFeeRate: t.protocolFeeRate,
|
|
2131
|
+
councilMembers: t.councilMembers,
|
|
2132
|
+
councilQuorum: t.councilQuorum,
|
|
2133
|
+
vkClaimerPayoutScriptPubKeys: t.vkClaimerPayoutScriptPubKeys,
|
|
2134
|
+
vpCommissionScriptPubKey: t.vpCommissionScriptPubKey
|
|
2135
|
+
};
|
|
2136
|
+
}
|
|
2137
|
+
async function hs(e, t, r, o) {
|
|
2138
|
+
const s = new or({
|
|
2139
|
+
network: t.network,
|
|
2140
|
+
btcWallet: e
|
|
2141
|
+
}), n = r.length;
|
|
2142
|
+
o == null || o(0, n);
|
|
2143
|
+
let a;
|
|
2144
|
+
if (s.supportsBatchSigning())
|
|
2145
|
+
a = (await s.signPayoutTransactionsBatch(
|
|
2146
|
+
r.map((l) => ot(l, t))
|
|
2147
|
+
)).map((l) => l.payoutSignature);
|
|
2148
|
+
else {
|
|
2149
|
+
a = [];
|
|
2150
|
+
for (let u = 0; u < r.length; u++) {
|
|
2151
|
+
o == null || o(u, n);
|
|
2152
|
+
const l = await s.signPayoutTransaction(
|
|
2153
|
+
ot(r[u], t)
|
|
2154
|
+
);
|
|
2155
|
+
a.push(l.signature);
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
const i = {};
|
|
2159
|
+
for (let u = 0; u < r.length; u++)
|
|
2160
|
+
i[r[u].claimerPubkeyXOnly] = {
|
|
2161
|
+
payout_signature: a[u]
|
|
2162
|
+
};
|
|
2163
|
+
return o == null || o(n, n), i;
|
|
2164
|
+
}
|
|
2165
|
+
async function nn(e) {
|
|
2166
|
+
const {
|
|
2167
|
+
statusReader: t,
|
|
2168
|
+
presignClient: r,
|
|
2169
|
+
btcWallet: o,
|
|
2170
|
+
vaultId: s,
|
|
2171
|
+
peginTxid: n,
|
|
2172
|
+
depositorPk: a,
|
|
2173
|
+
signingContext: i,
|
|
2174
|
+
depositTerms: u,
|
|
2175
|
+
timeoutMs: l = as,
|
|
2176
|
+
signal: c,
|
|
2177
|
+
onProgress: d,
|
|
2178
|
+
recordGraphFingerprint: h
|
|
2179
|
+
} = e, g = await Xt({
|
|
2180
|
+
statusReader: t,
|
|
2181
|
+
vaultId: s,
|
|
2182
|
+
peginTxid: n,
|
|
2183
|
+
targetStatuses: us,
|
|
2184
|
+
timeoutMs: l,
|
|
2185
|
+
signal: c
|
|
2186
|
+
});
|
|
2187
|
+
if (Gt.has(g))
|
|
2188
|
+
return;
|
|
2189
|
+
c == null || c.throwIfAborted(), u !== void 0 && ls(u, i);
|
|
2190
|
+
const p = yt(o) ? o : void 0;
|
|
2191
|
+
let y;
|
|
2192
|
+
if (p) {
|
|
2193
|
+
if (!u)
|
|
2194
|
+
throw new Error(
|
|
2195
|
+
"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)."
|
|
2196
|
+
);
|
|
2197
|
+
y = u;
|
|
2198
|
+
}
|
|
2199
|
+
const f = await r.requestDepositorPresignTransactions(
|
|
2200
|
+
{
|
|
2201
|
+
pegin_txid: n,
|
|
2202
|
+
depositor_pk: a
|
|
2203
|
+
},
|
|
2204
|
+
c
|
|
2205
|
+
);
|
|
2206
|
+
c == null || c.throwIfAborted(), f.txs.forEach((O, oe) => {
|
|
2207
|
+
zo({
|
|
2208
|
+
claimTxHex: O.claim_tx.tx_hex,
|
|
2209
|
+
assertTxHex: O.assert_tx.tx_hex,
|
|
2210
|
+
path: `txs[${oe}]`
|
|
2211
|
+
});
|
|
2212
|
+
});
|
|
2213
|
+
const P = Yo({
|
|
2214
|
+
peginTxid: n,
|
|
2215
|
+
peginTxHex: i.peginTxHex,
|
|
2216
|
+
claimTxHex: f.depositor_graph.claim_tx.tx_hex,
|
|
2217
|
+
assertTxHex: f.depositor_graph.assert_tx.tx_hex,
|
|
2218
|
+
payoutTxHex: f.depositor_graph.payout_tx.tx_hex,
|
|
2219
|
+
challengers: f.depositor_graph.challenger_presign_data
|
|
2220
|
+
}), k = I(a);
|
|
2221
|
+
ds(
|
|
2222
|
+
f.txs,
|
|
2223
|
+
i.vaultProviderBtcPubkey,
|
|
2224
|
+
i.vaultKeeperBtcPubkeys,
|
|
2225
|
+
a
|
|
2226
|
+
);
|
|
2227
|
+
const x = f.txs.filter(
|
|
2228
|
+
(O) => I(O.claimer_pubkey) !== k
|
|
2229
|
+
), v = cs(x);
|
|
2230
|
+
p && y && (typeof p.validateDepositTerms == "function" && await p.validateDepositTerms(y), await p.approveDepositTerms(y)), c == null || c.throwIfAborted();
|
|
2231
|
+
const E = await hs(
|
|
2232
|
+
o,
|
|
2233
|
+
i,
|
|
2234
|
+
v,
|
|
2235
|
+
d
|
|
2236
|
+
);
|
|
2237
|
+
c == null || c.throwIfAborted();
|
|
2238
|
+
const C = await ns({
|
|
2239
|
+
depositorGraph: f.depositor_graph,
|
|
2240
|
+
btcWallet: o,
|
|
2241
|
+
signingContext: {
|
|
2242
|
+
vaultCoreVersion: i.vaultCoreVersion,
|
|
2243
|
+
peginTxHex: i.peginTxHex,
|
|
2244
|
+
depositorBtcPubkey: a,
|
|
2245
|
+
vaultProviderBtcPubkey: i.vaultProviderBtcPubkey,
|
|
2246
|
+
vaultKeeperBtcPubkeys: i.vaultKeeperBtcPubkeys,
|
|
2247
|
+
universalChallengerBtcPubkeys: i.universalChallengerBtcPubkeys,
|
|
2248
|
+
timelockPegin: i.timelockPegin,
|
|
2249
|
+
timelockAssert: i.timelockAssert,
|
|
2250
|
+
councilMembers: i.councilMembers,
|
|
2251
|
+
councilQuorum: i.councilQuorum,
|
|
2252
|
+
network: i.network,
|
|
2253
|
+
registeredPayoutScriptPubKey: i.registeredPayoutScriptPubKey,
|
|
2254
|
+
protocolFeeRate: i.protocolFeeRate,
|
|
2255
|
+
vkClaimerPayoutScriptPubKeys: i.vkClaimerPayoutScriptPubKeys,
|
|
2256
|
+
vpCommissionScriptPubKey: i.vpCommissionScriptPubKey
|
|
2257
|
+
}
|
|
2258
|
+
});
|
|
2259
|
+
c == null || c.throwIfAborted(), await h(P), c == null || c.throwIfAborted();
|
|
2260
|
+
const w = { ...E };
|
|
2261
|
+
w[b(a)] = C.payout_signatures, await r.submitDepositorPresignatures(
|
|
2262
|
+
{
|
|
2263
|
+
pegin_txid: n,
|
|
2264
|
+
depositor_pk: a,
|
|
2265
|
+
signatures: w,
|
|
2266
|
+
depositor_claimer_presignatures: C
|
|
2267
|
+
},
|
|
2268
|
+
c
|
|
2269
|
+
);
|
|
2270
|
+
}
|
|
2271
|
+
const ps = 300 * 1e3, gs = /* @__PURE__ */ new Set([
|
|
2272
|
+
R.PENDING_DEPOSITOR_WOTS_PK,
|
|
2273
|
+
...kt
|
|
2274
|
+
]);
|
|
2275
|
+
async function an(e) {
|
|
2276
|
+
const {
|
|
2277
|
+
statusReader: t,
|
|
2278
|
+
wotsSubmitter: r,
|
|
2279
|
+
vaultId: o,
|
|
2280
|
+
peginTxid: s,
|
|
2281
|
+
depositorPk: n,
|
|
2282
|
+
wotsPublicKeys: a,
|
|
2283
|
+
timeoutMs: i = ps,
|
|
2284
|
+
signal: u
|
|
2285
|
+
} = e;
|
|
2286
|
+
u == null || u.throwIfAborted();
|
|
2287
|
+
const l = await Xt({
|
|
2288
|
+
statusReader: t,
|
|
2289
|
+
vaultId: o,
|
|
2290
|
+
peginTxid: s,
|
|
2291
|
+
targetStatuses: gs,
|
|
2292
|
+
timeoutMs: i,
|
|
2293
|
+
signal: u
|
|
2294
|
+
});
|
|
2295
|
+
kt.has(l) || (u == null || u.throwIfAborted(), await r.submitDepositorWotsKey(
|
|
2296
|
+
{
|
|
2297
|
+
pegin_txid: s,
|
|
2298
|
+
depositor_pk: n,
|
|
2299
|
+
wots_public_keys: a
|
|
2300
|
+
},
|
|
2301
|
+
u
|
|
2302
|
+
));
|
|
2303
|
+
}
|
|
2304
|
+
function ke(e) {
|
|
2305
|
+
return e.registration || e.operation;
|
|
2306
|
+
}
|
|
2307
|
+
function fs(e, t, r) {
|
|
2308
|
+
const o = _(e);
|
|
2309
|
+
return {
|
|
2310
|
+
registration: o === _(t),
|
|
2311
|
+
operation: o === _(r)
|
|
2312
|
+
};
|
|
2313
|
+
}
|
|
2314
|
+
function st(e, t, r) {
|
|
2315
|
+
const o = Ce(e);
|
|
2316
|
+
return {
|
|
2317
|
+
registration: nt(o, Ce(t)),
|
|
2318
|
+
operation: nt(o, Ce(r))
|
|
2319
|
+
};
|
|
2320
|
+
}
|
|
2321
|
+
function Ce(e) {
|
|
2322
|
+
return e.map(_).sort();
|
|
2323
|
+
}
|
|
2324
|
+
function nt(e, t) {
|
|
2325
|
+
return e.length === t.length && e.every((r, o) => r === t[o]);
|
|
2326
|
+
}
|
|
2327
|
+
async function un(e) {
|
|
2328
|
+
const {
|
|
2329
|
+
vaultProviderEthAddress: t,
|
|
2330
|
+
hintBtcPubkey: r,
|
|
2331
|
+
registrationBtcPubkey: o,
|
|
2332
|
+
readCurrentOperationBtcPubkey: s,
|
|
2333
|
+
context: n
|
|
2334
|
+
} = e;
|
|
2335
|
+
if (!r) return;
|
|
2336
|
+
const a = _(r);
|
|
2337
|
+
if (a === _(o)) return;
|
|
2338
|
+
const i = _(
|
|
2339
|
+
await s()
|
|
2340
|
+
);
|
|
2341
|
+
if (a !== i)
|
|
2342
|
+
throw new Error(
|
|
2343
|
+
`Vault provider BTC pubkey mismatch for ${t}: indexer hint matches neither the registration key nor the current operation key on-chain.${n ? ` ${n}` : ""}`
|
|
2344
|
+
);
|
|
2345
|
+
}
|
|
2346
|
+
class Se extends Error {
|
|
2347
|
+
constructor(t) {
|
|
2348
|
+
super(t), this.name = "ApplicationEntryPointMismatchError";
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
function cn(e) {
|
|
2352
|
+
return e instanceof Se || e instanceof Error && e.name === "ApplicationEntryPointMismatchError";
|
|
2353
|
+
}
|
|
2354
|
+
const it = (e) => e.map(_).sort();
|
|
2355
|
+
async function ln(e) {
|
|
2356
|
+
const {
|
|
2357
|
+
vaultRegistryReader: t,
|
|
2358
|
+
vaultKeeperReader: r,
|
|
2359
|
+
universalChallengerReader: o,
|
|
2360
|
+
vaultProviderEthAddress: s,
|
|
2361
|
+
applicationEntryPoint: n,
|
|
2362
|
+
expectedVaultProviderBtcPubkey: a,
|
|
2363
|
+
expectedVaultKeeperBtcPubkeys: i,
|
|
2364
|
+
expectedUniversalChallengerBtcPubkeys: u,
|
|
2365
|
+
operationKeyReader: l,
|
|
2366
|
+
onIndexerServingOperationKeys: c,
|
|
2367
|
+
onIndexerHintsInconsistent: d,
|
|
2368
|
+
blockNumber: h
|
|
2369
|
+
} = e, [
|
|
2370
|
+
g,
|
|
2371
|
+
p,
|
|
2372
|
+
y,
|
|
2373
|
+
f
|
|
2374
|
+
] = await Promise.all([
|
|
2375
|
+
t.getVaultProviderApplication(
|
|
2376
|
+
s,
|
|
2377
|
+
h
|
|
2378
|
+
),
|
|
2379
|
+
t.getVaultProviderGenesisBtcPubKey(
|
|
2380
|
+
s,
|
|
2381
|
+
h
|
|
2382
|
+
),
|
|
2383
|
+
o.getLatestUniversalChallengersVersion(h),
|
|
2384
|
+
o.getCurrentUcKeyEpoch(h)
|
|
2385
|
+
]);
|
|
2386
|
+
if (!Ar(n, { strict: !1 }))
|
|
2387
|
+
throw new Se(
|
|
2388
|
+
`The application entry point this deposit was prepared for is not a valid address: ${n}`
|
|
2389
|
+
);
|
|
2390
|
+
if (!Br(g, n))
|
|
2391
|
+
throw new Se(
|
|
2392
|
+
`Vault provider ${s} is registered to application ${g}, but this deposit was prepared for ${n}. Refusing to build: the vault keeper roster, its version, and the keeper key epoch would all resolve against a different application than the one selected.`
|
|
2393
|
+
);
|
|
2394
|
+
const [P, k] = await Promise.all(
|
|
2395
|
+
[
|
|
2396
|
+
r.getCurrentVaultKeepersVersion(
|
|
2397
|
+
g,
|
|
2398
|
+
h
|
|
2399
|
+
),
|
|
2400
|
+
r.getCurrentAppKeeperKeyEpoch(
|
|
2401
|
+
g,
|
|
2402
|
+
h
|
|
2403
|
+
)
|
|
2404
|
+
]
|
|
2405
|
+
), [x, v] = await Promise.all([
|
|
2406
|
+
r.getVaultKeepersByVersion(
|
|
2407
|
+
g,
|
|
2408
|
+
P,
|
|
2409
|
+
h
|
|
2410
|
+
),
|
|
2411
|
+
o.getUniversalChallengersByVersion(
|
|
2412
|
+
y,
|
|
2413
|
+
h
|
|
2414
|
+
)
|
|
2415
|
+
]), E = {
|
|
2416
|
+
vaultProvider: _(p),
|
|
2417
|
+
vaultKeepers: it(x.map((T) => T.btcPubKey)),
|
|
2418
|
+
universalChallengers: it(v.map((T) => T.btcPubKey))
|
|
2419
|
+
}, C = await Ro({
|
|
2420
|
+
operationKeyReader: l,
|
|
2421
|
+
query: {
|
|
2422
|
+
vaultProviderEthAddress: s,
|
|
2423
|
+
vaultProviderGenesisBtcPubkey: `0x${p}`,
|
|
2424
|
+
applicationEntryPoint: g,
|
|
2425
|
+
vaultKeepers: x,
|
|
2426
|
+
universalChallengers: v
|
|
2427
|
+
},
|
|
2428
|
+
blockNumber: h
|
|
2429
|
+
}), w = {
|
|
2430
|
+
vaultProvider: C.vaultProvider.operationBtcPubkey,
|
|
2431
|
+
vaultKeepers: [...C.vaultKeeperOperationKeysSorted],
|
|
2432
|
+
universalChallengers: [
|
|
2433
|
+
...C.universalChallengerOperationKeysSorted
|
|
2434
|
+
]
|
|
2435
|
+
}, O = fs(
|
|
2436
|
+
a,
|
|
2437
|
+
E.vaultProvider,
|
|
2438
|
+
w.vaultProvider
|
|
2439
|
+
), oe = st(
|
|
2440
|
+
i,
|
|
2441
|
+
E.vaultKeepers,
|
|
2442
|
+
w.vaultKeepers
|
|
2443
|
+
), Oe = st(
|
|
2444
|
+
u,
|
|
2445
|
+
E.universalChallengers,
|
|
2446
|
+
w.universalChallengers
|
|
2447
|
+
);
|
|
2448
|
+
if (!ke(O))
|
|
2449
|
+
throw new Error(
|
|
2450
|
+
`Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${s}. Refresh and try again.`
|
|
2451
|
+
);
|
|
2452
|
+
if (!ke(oe))
|
|
2453
|
+
throw new Error(
|
|
2454
|
+
`Vault keeper BTC pubkeys (v${P}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
|
|
2455
|
+
);
|
|
2456
|
+
if (!ke(Oe))
|
|
2457
|
+
throw new Error(
|
|
2458
|
+
`Universal challenger BTC pubkeys (v${y}) indexer set does not match ProtocolParams on-chain set. Refresh and try again.`
|
|
2459
|
+
);
|
|
2460
|
+
const Ne = [O, oe, Oe], Qt = Ne.some((T) => T.registration && !T.operation), De = Ne.some((T) => T.operation && !T.registration);
|
|
2461
|
+
if (Qt && De) {
|
|
2462
|
+
const T = `Indexer participant hints are internally inconsistent for vault provider ${s}: some roles match the registration keys while others match the rotated operation keys.`;
|
|
2463
|
+
throw d == null || d(T), new Error(`${T} Refresh and try again.`);
|
|
2464
|
+
}
|
|
2465
|
+
return De && (c == null || c(
|
|
2466
|
+
`Indexer is serving rotated operation keys for vault provider ${s}`
|
|
2467
|
+
)), {
|
|
2468
|
+
vaultProviderBtcPubkeyXOnly: w.vaultProvider,
|
|
2469
|
+
vaultKeeperBtcPubkeysSorted: w.vaultKeepers,
|
|
2470
|
+
universalChallengerBtcPubkeysSorted: w.universalChallengers,
|
|
2471
|
+
expectedAppVaultKeepersVersion: P,
|
|
2472
|
+
expectedUniversalChallengersVersion: y,
|
|
2473
|
+
appKeeperKeyEpoch: k,
|
|
2474
|
+
ucKeyEpoch: f,
|
|
2475
|
+
registrationKeys: E,
|
|
2476
|
+
participantKeys: C
|
|
2477
|
+
};
|
|
2478
|
+
}
|
|
2479
|
+
function ys(e) {
|
|
2480
|
+
return /^[0-9a-fA-F]{64}$/.test(e);
|
|
2481
|
+
}
|
|
2482
|
+
function dn(e) {
|
|
2483
|
+
const {
|
|
2484
|
+
amountSats: t,
|
|
2485
|
+
minDeposit: r,
|
|
2486
|
+
maxDeposit: o,
|
|
2487
|
+
btcBalance: s,
|
|
2488
|
+
estimatedFeeSats: n,
|
|
2489
|
+
depositorClaimValue: a
|
|
2490
|
+
} = e;
|
|
2491
|
+
return !(t <= 0n || t < r || o && o > 0n && t > o || n == null || a == null || t + n + a > s);
|
|
2492
|
+
}
|
|
2493
|
+
function hn(e, t, r) {
|
|
2494
|
+
return e <= 0n ? {
|
|
2495
|
+
valid: !1,
|
|
2496
|
+
error: "Deposit amount must be greater than zero"
|
|
2497
|
+
} : e < t ? {
|
|
2498
|
+
valid: !1,
|
|
2499
|
+
error: `Minimum deposit is ${N(t)} BTC`
|
|
2500
|
+
} : r && r > 0n && e > r ? {
|
|
2501
|
+
valid: !1,
|
|
2502
|
+
error: `Maximum deposit is ${N(r)} BTC`
|
|
2503
|
+
} : { valid: !0 };
|
|
2504
|
+
}
|
|
2505
|
+
function pn(e) {
|
|
2506
|
+
const { amount: t, effectiveRemaining: r } = e;
|
|
2507
|
+
return r === null ? { valid: !0 } : r === 0n ? {
|
|
2508
|
+
valid: !1,
|
|
2509
|
+
error: "Supply cap reached — deposits temporarily paused"
|
|
2510
|
+
} : t > r ? {
|
|
2511
|
+
valid: !1,
|
|
2512
|
+
error: `Vault size exceeds remaining capacity (${N(r)} BTC)`
|
|
2513
|
+
} : { valid: !0 };
|
|
2514
|
+
}
|
|
2515
|
+
function gn(e, t) {
|
|
2516
|
+
if (!e || e.length === 0)
|
|
2517
|
+
return {
|
|
2518
|
+
valid: !1,
|
|
2519
|
+
error: "At least one vault provider must be selected"
|
|
2520
|
+
};
|
|
2521
|
+
const r = t.map(
|
|
2522
|
+
(s) => s.toLowerCase()
|
|
2523
|
+
);
|
|
2524
|
+
return e.filter(
|
|
2525
|
+
(s) => !r.includes(s.toLowerCase())
|
|
2526
|
+
).length > 0 ? {
|
|
2527
|
+
valid: !1,
|
|
2528
|
+
error: "Invalid vault provider selected"
|
|
2529
|
+
} : { valid: !0 };
|
|
2530
|
+
}
|
|
2531
|
+
function vs(e, t, r) {
|
|
2532
|
+
if (!e || e.length === 0)
|
|
2533
|
+
return {
|
|
2534
|
+
valid: !1,
|
|
2535
|
+
error: "At least one vault amount required"
|
|
2536
|
+
};
|
|
2537
|
+
for (let o = 0; o < e.length; o++) {
|
|
2538
|
+
const s = e[o];
|
|
2539
|
+
if (s <= 0n)
|
|
2540
|
+
return {
|
|
2541
|
+
valid: !1,
|
|
2542
|
+
error: `Vault ${o + 1} amount must be positive`
|
|
2543
|
+
};
|
|
2544
|
+
if (t && s < t)
|
|
2545
|
+
return {
|
|
2546
|
+
valid: !1,
|
|
2547
|
+
error: `Vault ${o + 1} amount ${N(s)} BTC is below minimum deposit ${N(t)} BTC`
|
|
2548
|
+
};
|
|
2549
|
+
if (r && s > r)
|
|
2550
|
+
return {
|
|
2551
|
+
valid: !1,
|
|
2552
|
+
error: `Vault ${o + 1} amount ${N(s)} BTC exceeds maximum deposit ${N(r)} BTC`
|
|
2553
|
+
};
|
|
2554
|
+
}
|
|
2555
|
+
return { valid: !0 };
|
|
2556
|
+
}
|
|
2557
|
+
function bs(e) {
|
|
2558
|
+
const t = b(e);
|
|
2559
|
+
return ys(t) ? { valid: !0 } : {
|
|
2560
|
+
valid: !1,
|
|
2561
|
+
error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
|
|
2562
|
+
};
|
|
2563
|
+
}
|
|
2564
|
+
function Ps(e) {
|
|
2565
|
+
if (!e || e.length === 0)
|
|
2566
|
+
throw new Error(
|
|
2567
|
+
"No vault keepers available. The system requires at least one vault keeper to create a deposit."
|
|
2568
|
+
);
|
|
2569
|
+
}
|
|
2570
|
+
function ms(e) {
|
|
2571
|
+
if (!e || e.length === 0)
|
|
2572
|
+
throw new Error(
|
|
2573
|
+
"No universal challengers available. The system requires at least one universal challenger to create a deposit."
|
|
2574
|
+
);
|
|
2575
|
+
}
|
|
2576
|
+
function ws(e) {
|
|
2577
|
+
if (e.length === 0)
|
|
2578
|
+
throw new Error("No spendable UTXOs available");
|
|
2579
|
+
}
|
|
2580
|
+
function fn(e) {
|
|
2581
|
+
const {
|
|
2582
|
+
vaultAmounts: t,
|
|
2583
|
+
confirmedUTXOs: r,
|
|
2584
|
+
vaultProviderBtcPubkey: o,
|
|
2585
|
+
vaultKeeperBtcPubkeys: s,
|
|
2586
|
+
universalChallengerBtcPubkeys: n,
|
|
2587
|
+
minDeposit: a,
|
|
2588
|
+
maxDeposit: i
|
|
2589
|
+
} = e, u = vs(
|
|
2590
|
+
t,
|
|
2591
|
+
a,
|
|
2592
|
+
i
|
|
2593
|
+
);
|
|
2594
|
+
if (!u.valid)
|
|
2595
|
+
throw new Error(u.error);
|
|
2596
|
+
const l = bs(o);
|
|
2597
|
+
if (!l.valid)
|
|
2598
|
+
throw new Error(l.error);
|
|
2599
|
+
Ps(s), ms(n), ws(r);
|
|
2600
|
+
}
|
|
2601
|
+
class zt extends Error {
|
|
2602
|
+
constructor(t) {
|
|
2603
|
+
super(t), this.name = "ParticipantKeyDriftError";
|
|
2604
|
+
}
|
|
2605
|
+
}
|
|
2606
|
+
function yn(e) {
|
|
2607
|
+
return e instanceof zt || e instanceof Error && e.name === "ParticipantKeyDriftError";
|
|
2608
|
+
}
|
|
2609
|
+
function at(e, t, r) {
|
|
2610
|
+
return t.length === r.length && t.every((o, s) => o === r[s]) ? null : `${e} expected [${t.join(", ")}], got [${r.join(", ")}]`;
|
|
2611
|
+
}
|
|
2612
|
+
async function vn(e) {
|
|
2613
|
+
const { vaultRegistryReader: t, operationKeyReader: r, vaultIds: o, expected: s } = e, n = s.query;
|
|
2614
|
+
if (o.length === 0) return;
|
|
2615
|
+
const a = await t.getVaultKeyEpochsBatch(o), i = [];
|
|
2616
|
+
for (const [u, l] of a.entries()) {
|
|
2617
|
+
const c = o[u];
|
|
2618
|
+
let d;
|
|
2619
|
+
try {
|
|
2620
|
+
d = await Nt({
|
|
2621
|
+
operationKeyReader: r,
|
|
2622
|
+
query: n,
|
|
2623
|
+
epochs: l
|
|
2624
|
+
});
|
|
2625
|
+
} catch (p) {
|
|
2626
|
+
i.push(
|
|
2627
|
+
`vault ${c}: could not resolve participants at frozen epochs (vp=${l.vpKeyEpoch}, keeper=${l.appKeeperKeyEpoch}, uc=${l.ucKeyEpoch}): ${p.message}`
|
|
2628
|
+
);
|
|
2629
|
+
continue;
|
|
2630
|
+
}
|
|
2631
|
+
d.vaultProvider.operationBtcPubkey !== s.vaultProvider.operationBtcPubkey && i.push(
|
|
2632
|
+
`vault ${c}: vault provider key expected ${s.vaultProvider.operationBtcPubkey}, got ${d.vaultProvider.operationBtcPubkey}`
|
|
2633
|
+
);
|
|
2634
|
+
const h = at(
|
|
2635
|
+
`vault ${c}: vault keeper keys`,
|
|
2636
|
+
s.vaultKeeperOperationKeysSorted,
|
|
2637
|
+
d.vaultKeeperOperationKeysSorted
|
|
2638
|
+
);
|
|
2639
|
+
h && i.push(h);
|
|
2640
|
+
const g = at(
|
|
2641
|
+
`vault ${c}: universal challenger keys`,
|
|
2642
|
+
s.universalChallengerOperationKeysSorted,
|
|
2643
|
+
d.universalChallengerOperationKeysSorted
|
|
2644
|
+
);
|
|
2645
|
+
g && i.push(g);
|
|
2646
|
+
}
|
|
2647
|
+
if (i.length > 0)
|
|
2648
|
+
throw new zt(
|
|
2649
|
+
`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.`
|
|
2650
|
+
);
|
|
2651
|
+
}
|
|
2652
|
+
class jt extends Error {
|
|
2653
|
+
constructor(t) {
|
|
2654
|
+
super(t), this.name = "RegisteredVaultVersionMismatchError";
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2657
|
+
function bn(e) {
|
|
2658
|
+
return e instanceof jt || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
|
|
2659
|
+
}
|
|
2660
|
+
async function Pn(e) {
|
|
2661
|
+
const {
|
|
2662
|
+
vaultRegistryReader: t,
|
|
2663
|
+
vaultIds: r,
|
|
2664
|
+
expectedOffchainParamsVersion: o,
|
|
2665
|
+
expectedAppVaultKeepersVersion: s,
|
|
2666
|
+
expectedUniversalChallengersVersion: n,
|
|
2667
|
+
expectedVaultCoreVersion: a
|
|
2668
|
+
} = e, i = await t.getProtocolInfoBatch(r), u = [];
|
|
2669
|
+
if (i.forEach((l, c) => {
|
|
2670
|
+
const d = r[c];
|
|
2671
|
+
l.offchainParamsVersion !== o && u.push(
|
|
2672
|
+
`vault ${d}: offchainParams expected v${o}, got v${l.offchainParamsVersion}`
|
|
2673
|
+
), l.appVaultKeepersVersion !== s && u.push(
|
|
2674
|
+
`vault ${d}: appVaultKeepers expected v${s}, got v${l.appVaultKeepersVersion}`
|
|
2675
|
+
), l.universalChallengersVersion !== n && u.push(
|
|
2676
|
+
`vault ${d}: universalChallengers expected v${n}, got v${l.universalChallengersVersion}`
|
|
2677
|
+
), l.vaultCoreVersion !== a && u.push(
|
|
2678
|
+
`vault ${d}: vaultCoreVersion expected v${a} (build-time active), got v${l.vaultCoreVersion}`
|
|
2679
|
+
);
|
|
2680
|
+
}), u.length > 0)
|
|
2681
|
+
throw new jt(
|
|
2682
|
+
`Aborting BTC broadcast: signer-set or offchain-params versions changed during registration (${u.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
|
|
2683
|
+
);
|
|
2684
|
+
}
|
|
2685
|
+
class xs extends Error {
|
|
2686
|
+
constructor(r, o) {
|
|
2687
|
+
super(`Refund not yet mature (BIP68 not final): ${o.message}`);
|
|
2688
|
+
z(this, "vaultId");
|
|
2689
|
+
z(this, "cause");
|
|
2690
|
+
this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = o;
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
const Es = /^0x[0-9a-fA-F]{64}$/, $s = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, Wt = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, Yt = 160, ut = 2e3, ct = 10n, lt = 100n;
|
|
2694
|
+
function mn(e) {
|
|
2695
|
+
if (!Number.isFinite(e) || e <= 0)
|
|
2696
|
+
throw new Error(
|
|
2697
|
+
`feeRateSatsVb must be a positive finite number, got ${e}`
|
|
2698
|
+
);
|
|
2699
|
+
return BigInt(Math.ceil(e * Yt));
|
|
2700
|
+
}
|
|
2701
|
+
const ks = 1, Cs = /non-BIP68-final/i;
|
|
2702
|
+
function Ae(e, t) {
|
|
2703
|
+
if (e.length !== 66)
|
|
2704
|
+
throw new Error(
|
|
2705
|
+
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
2706
|
+
);
|
|
2707
|
+
if (!Es.test(e))
|
|
2708
|
+
throw new Error(
|
|
2709
|
+
`${t} must contain only hex characters after the 0x prefix`
|
|
2710
|
+
);
|
|
2711
|
+
}
|
|
2712
|
+
function Te(e, t) {
|
|
2713
|
+
if (!Number.isInteger(e) || e < 0)
|
|
2714
|
+
throw new Error(`${t} must be a non-negative integer, got ${e}`);
|
|
2715
|
+
}
|
|
2716
|
+
function Ts(e) {
|
|
2717
|
+
if (Ae(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0)
|
|
2718
|
+
throw new Error(
|
|
2719
|
+
`htlcVout must be a non-negative integer, got ${e.htlcVout}`
|
|
2720
|
+
);
|
|
2721
|
+
if (!Array.isArray(e.batch) || e.batch.length === 0)
|
|
2722
|
+
throw new Error("batch must be a non-empty array of HTLC entries");
|
|
2723
|
+
if (e.htlcVout >= e.batch.length)
|
|
2724
|
+
throw new Error(
|
|
2725
|
+
`htlcVout ${e.htlcVout} is out of range for batch of size ${e.batch.length}`
|
|
2726
|
+
);
|
|
2727
|
+
for (let r = 0; r < e.batch.length; r++) {
|
|
2728
|
+
const o = e.batch[r];
|
|
2729
|
+
if (Ae(o.hashlock, `batch[${r}].hashlock`), !Number.isInteger(o.htlcVout) || o.htlcVout !== r)
|
|
2730
|
+
throw new Error(
|
|
2731
|
+
`batch[${r}].htlcVout must equal ${r} (contiguous vout-ordered vector), got ${o.htlcVout}`
|
|
2732
|
+
);
|
|
2733
|
+
if (typeof o.amount != "bigint" || o.amount <= 0n)
|
|
2734
|
+
throw new Error(
|
|
2735
|
+
`batch[${r}].amount must be a positive bigint, got ${o.amount}`
|
|
2736
|
+
);
|
|
2737
|
+
}
|
|
2738
|
+
const t = e.batch[e.htlcVout];
|
|
2739
|
+
if (t.hashlock.toLowerCase() !== e.hashlock.toLowerCase())
|
|
2740
|
+
throw new Error(
|
|
2741
|
+
`batch[${e.htlcVout}].hashlock (${t.hashlock}) does not match target hashlock (${e.hashlock})`
|
|
2742
|
+
);
|
|
2743
|
+
if (t.amount !== e.amount)
|
|
2744
|
+
throw new Error(
|
|
2745
|
+
`batch[${e.htlcVout}].amount (${t.amount}) does not match target amount (${e.amount})`
|
|
2746
|
+
);
|
|
2747
|
+
if (Te(e.offchainParamsVersion, "offchainParamsVersion"), Te(e.appVaultKeepersVersion, "appVaultKeepersVersion"), Te(
|
|
2748
|
+
e.universalChallengersVersion,
|
|
2749
|
+
"universalChallengersVersion"
|
|
2750
|
+
), Ur(
|
|
2751
|
+
e.vaultCoreVersion,
|
|
2752
|
+
"VaultRefundData.vaultCoreVersion"
|
|
2753
|
+
), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
|
|
2754
|
+
throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
|
|
2755
|
+
if (!$s.test(e.unsignedPrePeginTxHex))
|
|
2756
|
+
throw new Error(
|
|
2757
|
+
"unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
|
|
2758
|
+
);
|
|
2759
|
+
if (!e.depositorBtcPubkey || !Wt.test(e.depositorBtcPubkey))
|
|
2760
|
+
throw new Error(
|
|
2761
|
+
"depositorBtcPubkey must be 32 or 33 bytes of hex (optional 0x prefix)"
|
|
2762
|
+
);
|
|
2763
|
+
if (typeof e.amount != "bigint" || e.amount <= 0n)
|
|
2764
|
+
throw new Error(`amount must be a positive bigint, got ${e.amount}`);
|
|
2765
|
+
}
|
|
2766
|
+
function _s(e) {
|
|
2767
|
+
if (!e.vaultProviderPubkey || !Wt.test(e.vaultProviderPubkey))
|
|
2768
|
+
throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
|
|
2769
|
+
if (e.vaultKeeperPubkeys.length === 0)
|
|
2770
|
+
throw new Error("vaultKeeperPubkeys must be non-empty");
|
|
2771
|
+
if (e.universalChallengerPubkeys.length === 0)
|
|
2772
|
+
throw new Error("universalChallengerPubkeys must be non-empty");
|
|
2773
|
+
if (!Number.isInteger(e.timelockRefund) || e.timelockRefund <= 0)
|
|
2774
|
+
throw new Error(
|
|
2775
|
+
`timelockRefund must be a positive integer, got ${e.timelockRefund}`
|
|
2776
|
+
);
|
|
2777
|
+
if (typeof e.feeRate != "bigint" || e.feeRate <= 0n)
|
|
2778
|
+
throw new Error(
|
|
2779
|
+
`protocol feeRate must be a positive bigint, got ${e.feeRate}`
|
|
2780
|
+
);
|
|
2781
|
+
if (typeof e.minPeginFeeRate != "bigint" || e.minPeginFeeRate <= 0n)
|
|
2782
|
+
throw new Error(
|
|
2783
|
+
`minPeginFeeRate must be a positive bigint, got ${e.minPeginFeeRate}`
|
|
2784
|
+
);
|
|
2785
|
+
if (!Number.isInteger(e.numLocalChallengers) || e.numLocalChallengers < 0)
|
|
2786
|
+
throw new Error("numLocalChallengers must be a non-negative integer");
|
|
2787
|
+
if (!Number.isInteger(e.councilQuorum) || !Number.isInteger(e.councilSize) || e.councilQuorum <= 0 || e.councilSize <= 0 || e.councilQuorum > e.councilSize)
|
|
2788
|
+
throw new Error(
|
|
2789
|
+
`councilQuorum (${e.councilQuorum}) must be in [1, councilSize=${e.councilSize}]`
|
|
2790
|
+
);
|
|
2791
|
+
}
|
|
2792
|
+
async function wn(e) {
|
|
2793
|
+
const {
|
|
2794
|
+
vaultId: t,
|
|
2795
|
+
readVault: r,
|
|
2796
|
+
readPrePeginContext: o,
|
|
2797
|
+
feeRate: s,
|
|
2798
|
+
signPsbt: n,
|
|
2799
|
+
broadcastTx: a,
|
|
2800
|
+
signal: i
|
|
2801
|
+
} = e;
|
|
2802
|
+
i == null || i.throwIfAborted(), Ae(t, "vaultId");
|
|
2803
|
+
const u = await r();
|
|
2804
|
+
Ts(u), i == null || i.throwIfAborted();
|
|
2805
|
+
const l = await o(u);
|
|
2806
|
+
if (_s(l), i == null || i.throwIfAborted(), !Number.isFinite(s) || s <= 0)
|
|
2807
|
+
throw new Error(`feeRate must be a positive number, got ${s}`);
|
|
2808
|
+
if (s > ut)
|
|
2809
|
+
throw new Error(
|
|
2810
|
+
`feeRate ${s} sat/vB exceeds refund safety cap ${ut} sat/vB; refusing to sign refund.`
|
|
2811
|
+
);
|
|
2812
|
+
const c = BigInt(Math.ceil(s * Yt)), d = u.amount * ct / lt;
|
|
2813
|
+
if (c > d)
|
|
2814
|
+
throw new Error(
|
|
2815
|
+
`Refund fee ${c} sats exceeds the per-vault safety cap of ${d} sats (${ct}/${lt} of vault.amount=${u.amount}); refusing to sign refund.`
|
|
2816
|
+
);
|
|
2817
|
+
i == null || i.throwIfAborted();
|
|
2818
|
+
const h = he(
|
|
2819
|
+
u.depositorBtcPubkey
|
|
2820
|
+
), g = b(u.unsignedPrePeginTxHex), p = sr(g);
|
|
2821
|
+
if (p !== void 0 && p.vout !== u.batch.length)
|
|
2822
|
+
throw new Error(
|
|
2823
|
+
`Auth-anchor OP_RETURN at vout ${p.vout} does not match batch size (${u.batch.length} HTLC outputs expect the anchor at vout ${u.batch.length}). Refund refused — sibling HTLC vector is incomplete.`
|
|
2824
|
+
);
|
|
2825
|
+
const y = p == null ? void 0 : p.hash;
|
|
2826
|
+
let f;
|
|
2827
|
+
try {
|
|
2828
|
+
f = S.fromHex(g);
|
|
2829
|
+
} catch (w) {
|
|
2830
|
+
throw new Error(
|
|
2831
|
+
`Failed to parse funded Pre-PegIn transaction hex: ${w instanceof Error ? w.message : String(w)}`
|
|
2832
|
+
);
|
|
2833
|
+
}
|
|
2834
|
+
if (f.outs.length < u.batch.length)
|
|
2835
|
+
throw new Error(
|
|
2836
|
+
`Funded Pre-PegIn tx has ${f.outs.length} outputs but batch requires at least ${u.batch.length} HTLC outputs. Refund refused — funded tx shape disagrees with sibling vector.`
|
|
2837
|
+
);
|
|
2838
|
+
const { psbtHex: P } = await Mr({
|
|
2839
|
+
prePeginParams: {
|
|
2840
|
+
vaultCoreVersion: u.vaultCoreVersion,
|
|
2841
|
+
depositorPubkey: h,
|
|
2842
|
+
vaultProviderPubkey: b(l.vaultProviderPubkey),
|
|
2843
|
+
vaultKeeperPubkeys: l.vaultKeeperPubkeys.map(b),
|
|
2844
|
+
universalChallengerPubkeys: l.universalChallengerPubkeys.map(b),
|
|
2845
|
+
hashlocks: u.batch.map((w) => b(w.hashlock)),
|
|
2846
|
+
timelockRefund: l.timelockRefund,
|
|
2847
|
+
// `batch[i].amount` is the on-chain vault deposit (peg-in) amount, which
|
|
2848
|
+
// is exactly what WASM's `pegInAmounts` expects — it re-adds the protocol
|
|
2849
|
+
// reserve (`depositorClaimValue + minPeginFee`) internally when sizing the
|
|
2850
|
+
// HTLC output. `buildRefundPsbt`'s value cross-check then binds the result
|
|
2851
|
+
// to the funded tx bytes, refusing the refund if the template's HTLC value
|
|
2852
|
+
// disagrees with the on-chain commitment.
|
|
2853
|
+
pegInAmounts: u.batch.map((w) => w.amount),
|
|
2854
|
+
feeRate: l.feeRate,
|
|
2855
|
+
minPeginFeeRate: l.minPeginFeeRate,
|
|
2856
|
+
numLocalChallengers: l.numLocalChallengers,
|
|
2857
|
+
councilQuorum: l.councilQuorum,
|
|
2858
|
+
councilSize: l.councilSize,
|
|
2859
|
+
network: l.network,
|
|
2860
|
+
authAnchorHash: y
|
|
2861
|
+
},
|
|
2862
|
+
fundedPrePeginTxHex: g,
|
|
2863
|
+
htlcVout: u.htlcVout,
|
|
2864
|
+
refundFee: c,
|
|
2865
|
+
// buildRefundPsbt's top-level `hashlock` param is documented as "no 0x
|
|
2866
|
+
// prefix" and flows into the WASM HTLC connector derivation; a prefixed
|
|
2867
|
+
// value would derive the wrong refund script leaf and yield an
|
|
2868
|
+
// unspendable PSBT. Match the `hashlocks` array handling above.
|
|
2869
|
+
hashlock: b(u.hashlock)
|
|
2870
|
+
});
|
|
2871
|
+
i == null || i.throwIfAborted();
|
|
2872
|
+
const k = ue(
|
|
2873
|
+
u.depositorBtcPubkey,
|
|
2874
|
+
ks
|
|
2875
|
+
), x = await n(P, k);
|
|
2876
|
+
ie({
|
|
2877
|
+
requestedPsbtHex: P,
|
|
2878
|
+
returnedPsbtHex: x
|
|
2879
|
+
});
|
|
2880
|
+
const v = 0, E = ae(
|
|
2881
|
+
x,
|
|
2882
|
+
h,
|
|
2883
|
+
v
|
|
2884
|
+
);
|
|
2885
|
+
re({
|
|
2886
|
+
requestedPsbtHex: P,
|
|
2887
|
+
signatureHex: E,
|
|
2888
|
+
signerXOnlyPubkeyHex: h,
|
|
2889
|
+
inputIndex: v
|
|
2890
|
+
});
|
|
2891
|
+
const C = Ct({
|
|
2892
|
+
requestedPsbtHex: P,
|
|
2893
|
+
signaturesHex: [E],
|
|
2894
|
+
signerXOnlyPubkeyHex: h
|
|
2895
|
+
});
|
|
2896
|
+
i == null || i.throwIfAborted();
|
|
2897
|
+
try {
|
|
2898
|
+
return await a(C);
|
|
2899
|
+
} catch (w) {
|
|
2900
|
+
throw w instanceof Error && Cs.test(w.message) ? new xs(t, w) : w;
|
|
2901
|
+
}
|
|
2902
|
+
}
|
|
2903
|
+
class dt extends Error {
|
|
2904
|
+
constructor(r, o, s) {
|
|
2905
|
+
super(r);
|
|
2906
|
+
/** Fee the reclaim would have paid, in satoshis. */
|
|
2907
|
+
z(this, "feeSats");
|
|
2908
|
+
/** Sum of the reserves the reclaim would have swept, in satoshis. */
|
|
2909
|
+
z(this, "sweptTotalSats");
|
|
2910
|
+
this.name = "ReclaimUneconomicalError", this.feeSats = o, this.sweptTotalSats = s;
|
|
2911
|
+
}
|
|
2912
|
+
}
|
|
2913
|
+
const ht = 2e3, pt = 25n, gt = 100n, xn = 10n;
|
|
2914
|
+
async function Ss(e, t, r) {
|
|
2915
|
+
for (let o = 0; o < e.length; o++) {
|
|
2916
|
+
const s = qr(e[o].depositorSignedPeginTxHex), n = Be(
|
|
2917
|
+
await yr(
|
|
2918
|
+
b(s),
|
|
2919
|
+
b(r)
|
|
2920
|
+
)
|
|
2921
|
+
).toLowerCase();
|
|
2922
|
+
if (n !== t[o].toLowerCase())
|
|
2923
|
+
throw new Error(
|
|
2924
|
+
`Reserve ${o} belongs to vault ${n}, 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.`
|
|
2925
|
+
);
|
|
2926
|
+
}
|
|
2927
|
+
}
|
|
2928
|
+
async function En(e) {
|
|
2929
|
+
const {
|
|
2930
|
+
vaultIds: t,
|
|
2931
|
+
depositorEthAddress: r,
|
|
2932
|
+
depositorBtcPubkey: o,
|
|
2933
|
+
readVaults: s,
|
|
2934
|
+
feeRate: n,
|
|
2935
|
+
signPsbt: a,
|
|
2936
|
+
broadcastTx: i,
|
|
2937
|
+
signal: u
|
|
2938
|
+
} = e;
|
|
2939
|
+
if (u == null || u.throwIfAborted(), t.length === 0)
|
|
2940
|
+
throw new Error("Reclaim requires at least one vault id; got none.");
|
|
2941
|
+
if (!Number.isFinite(n) || n <= 0)
|
|
2942
|
+
throw new Error(`feeRate must be a positive number, got ${n}`);
|
|
2943
|
+
if (n > ht)
|
|
2944
|
+
throw new dt(
|
|
2945
|
+
`Fee rate ${n} sat/vB exceeds the reclaim safety cap of ${ht} sat/vB; refusing to sign.`,
|
|
2946
|
+
0n,
|
|
2947
|
+
0n
|
|
2948
|
+
);
|
|
2949
|
+
const l = await s();
|
|
2950
|
+
if (u == null || u.throwIfAborted(), l.length !== t.length)
|
|
2951
|
+
throw new Error(
|
|
2952
|
+
`readVaults returned ${l.length} reserves for ${t.length} vault id(s); refusing to sweep a set that does not match the request.`
|
|
2953
|
+
);
|
|
2954
|
+
await Ss(l, t, r), u == null || u.throwIfAborted();
|
|
2955
|
+
const c = he(o), d = l.map((v) => ({
|
|
2956
|
+
depositorSignedPeginTxHex: v.depositorSignedPeginTxHex,
|
|
2957
|
+
observed: v.observed,
|
|
2958
|
+
expectedValue: v.expectedClaimValue
|
|
2959
|
+
})), h = Lr(n, d.length), g = d.reduce((v, E) => v + E.expectedValue, 0n), p = g * pt / gt;
|
|
2960
|
+
if (h > p)
|
|
2961
|
+
throw new dt(
|
|
2962
|
+
`Reclaim fee ${h} sats exceeds ${pt}/${gt} of the swept total (${g} sats, cap ${p} sats). The reserve is not at risk — it stays where it is until fee rates fall.`,
|
|
2963
|
+
h,
|
|
2964
|
+
g
|
|
2965
|
+
);
|
|
2966
|
+
u == null || u.throwIfAborted();
|
|
2967
|
+
const { psbtHex: y } = Fr({
|
|
2968
|
+
depositorPubkey: c,
|
|
2969
|
+
inputs: d,
|
|
2970
|
+
feeSats: h
|
|
2971
|
+
});
|
|
2972
|
+
u == null || u.throwIfAborted();
|
|
2973
|
+
const f = ue(
|
|
2974
|
+
o,
|
|
2975
|
+
d.length
|
|
2976
|
+
), P = await a(y, f);
|
|
2977
|
+
ie({
|
|
2978
|
+
requestedPsbtHex: y,
|
|
2979
|
+
returnedPsbtHex: P
|
|
2980
|
+
});
|
|
2981
|
+
const k = d.map((v, E) => {
|
|
2982
|
+
const C = ae(
|
|
2983
|
+
P,
|
|
2984
|
+
c,
|
|
2985
|
+
E
|
|
2986
|
+
);
|
|
2987
|
+
return re({
|
|
2988
|
+
requestedPsbtHex: y,
|
|
2989
|
+
signatureHex: C,
|
|
2990
|
+
signerXOnlyPubkeyHex: c,
|
|
2991
|
+
inputIndex: E
|
|
2992
|
+
}), C;
|
|
2993
|
+
}), x = Ct({
|
|
2994
|
+
requestedPsbtHex: y,
|
|
2995
|
+
signaturesHex: k,
|
|
2996
|
+
signerXOnlyPubkeyHex: c
|
|
2997
|
+
});
|
|
2998
|
+
return u == null || u.throwIfAborted(), i(x);
|
|
2999
|
+
}
|
|
3000
|
+
export {
|
|
3001
|
+
Pn as $,
|
|
3002
|
+
K as A,
|
|
3003
|
+
io as B,
|
|
3004
|
+
eo as C,
|
|
3005
|
+
U as D,
|
|
3006
|
+
Qo as E,
|
|
3007
|
+
nn as F,
|
|
3008
|
+
m as G,
|
|
3009
|
+
ns as H,
|
|
3010
|
+
an as I,
|
|
3011
|
+
Se as J,
|
|
3012
|
+
cn as K,
|
|
3013
|
+
ln as L,
|
|
3014
|
+
dn as M,
|
|
3015
|
+
hn as N,
|
|
3016
|
+
fn as O,
|
|
3017
|
+
ro as P,
|
|
3018
|
+
gn as Q,
|
|
3019
|
+
pn as R,
|
|
3020
|
+
j as S,
|
|
3021
|
+
vs as T,
|
|
3022
|
+
bs as U,
|
|
3023
|
+
ao as V,
|
|
3024
|
+
zt as W,
|
|
3025
|
+
yn as X,
|
|
3026
|
+
vn as Y,
|
|
3027
|
+
jt as Z,
|
|
3028
|
+
bn as _,
|
|
3029
|
+
Ys as a,
|
|
3030
|
+
Xt as a0,
|
|
3031
|
+
un as a1,
|
|
3032
|
+
ke as a2,
|
|
3033
|
+
fs as a3,
|
|
3034
|
+
st as a4,
|
|
3035
|
+
Ko as a5,
|
|
3036
|
+
Ro as a6,
|
|
3037
|
+
Nt as a7,
|
|
3038
|
+
xs as a8,
|
|
3039
|
+
wn as a9,
|
|
3040
|
+
mn as aa,
|
|
3041
|
+
lt as ab,
|
|
3042
|
+
ct as ac,
|
|
3043
|
+
ut as ad,
|
|
3044
|
+
Yt as ae,
|
|
3045
|
+
dt as af,
|
|
3046
|
+
En as ag,
|
|
3047
|
+
gt as ah,
|
|
3048
|
+
pt as ai,
|
|
3049
|
+
ht as aj,
|
|
3050
|
+
xn as ak,
|
|
3051
|
+
Qs as b,
|
|
3052
|
+
Zs as c,
|
|
3053
|
+
mo as d,
|
|
3054
|
+
Jr as e,
|
|
3055
|
+
to as f,
|
|
3056
|
+
en as g,
|
|
3057
|
+
oo as h,
|
|
3058
|
+
se as i,
|
|
3059
|
+
no as j,
|
|
3060
|
+
lo as k,
|
|
3061
|
+
Js as l,
|
|
3062
|
+
xo as m,
|
|
3063
|
+
_o as n,
|
|
3064
|
+
$o as o,
|
|
3065
|
+
vo as p,
|
|
3066
|
+
St as q,
|
|
3067
|
+
tn as r,
|
|
3068
|
+
po as s,
|
|
3069
|
+
Ho as t,
|
|
3070
|
+
Dt as u,
|
|
3071
|
+
Mt as v,
|
|
3072
|
+
Mo as w,
|
|
3073
|
+
rn as x,
|
|
3074
|
+
on as y,
|
|
3075
|
+
sn as z
|
|
3076
|
+
};
|
|
3077
|
+
//# sourceMappingURL=buildAndBroadcastReclaim-DoprHX7o.js.map
|