@btc-vision/transaction 1.0.97 → 1.0.100
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/.babelrc +4 -7
- package/.prettierrc.json +11 -11
- package/CONTRIBUTING.md +71 -71
- package/LICENSE.md +62 -62
- package/README.md +76 -76
- package/browser/_version.d.ts +1 -1
- package/browser/bytecode/Compressor.d.ts +0 -1
- package/browser/crypto/crypto-browser.d.ts +1 -30
- package/browser/crypto/crypto.d.ts +0 -1
- package/browser/generators/AddressGenerator.d.ts +0 -1
- package/browser/generators/Generator.d.ts +2 -3
- package/browser/generators/builders/CalldataGenerator.d.ts +0 -1
- package/browser/generators/builders/CustomGenerator.d.ts +6 -0
- package/browser/generators/builders/DeploymentGenerator.d.ts +0 -1
- package/browser/generators/builders/MultiSignGenerator.d.ts +0 -1
- package/browser/index.js +1 -1
- package/browser/keypair/EcKeyPair.d.ts +0 -1
- package/browser/keypair/Wallet.d.ts +0 -1
- package/browser/opnet.d.ts +5 -3
- package/browser/signer/TweakedSigner.d.ts +0 -1
- package/browser/transaction/TransactionFactory.d.ts +2 -0
- package/browser/transaction/browser/BrowserSignerBase.d.ts +0 -1
- package/browser/transaction/browser/extensions/UnisatSigner.d.ts +0 -1
- package/{build/transaction/builders/DeploymentTransactionV2.d.ts → browser/transaction/builders/CustomScriptTransaction.d.ts} +16 -12
- package/browser/transaction/builders/DeploymentTransaction.d.ts +0 -1
- package/browser/transaction/builders/InteractionTransaction.d.ts +0 -1
- package/browser/transaction/builders/MultiSignTransaction.d.ts +0 -1
- package/browser/transaction/builders/SharedInteractionTransaction.d.ts +0 -1
- package/browser/transaction/builders/TransactionBuilder.d.ts +0 -1
- package/browser/transaction/builders/UnwrapSegwitTransaction.d.ts +0 -1
- package/browser/transaction/builders/UnwrapTransaction.d.ts +0 -1
- package/browser/transaction/builders/WrapTransaction.d.ts +0 -1
- package/browser/transaction/enums/TransactionType.d.ts +2 -1
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +0 -1
- package/browser/transaction/interfaces/Tap.d.ts +0 -1
- package/browser/transaction/shared/P2TR_MS.d.ts +0 -1
- package/browser/transaction/shared/TweakedTransaction.d.ts +0 -1
- package/browser/utils/BitcoinUtils.d.ts +0 -1
- package/browser/verification/TapscriptVerificator.d.ts +0 -1
- package/browser/wbtc/WrappedGenerationParameters.d.ts +0 -1
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/bytecode/Compressor.d.ts +0 -1
- package/build/bytecode/Compressor.js +4 -4
- package/build/crypto/crypto.d.ts +0 -1
- package/build/generators/AddressGenerator.d.ts +0 -1
- package/build/generators/Generator.d.ts +2 -3
- package/build/generators/Generator.js +3 -5
- package/build/generators/builders/CalldataGenerator.d.ts +0 -1
- package/build/generators/builders/CalldataGenerator.js +2 -0
- package/build/generators/builders/CustomGenerator.d.ts +6 -0
- package/build/generators/builders/CustomGenerator.js +16 -0
- package/build/generators/builders/DeploymentGenerator.d.ts +0 -1
- package/build/generators/builders/DeploymentGenerator.js +2 -0
- package/build/generators/builders/{MultisignGenerator.d.ts → MultiSignGenerator.d.ts} +0 -1
- package/build/generators/builders/{MultisignGenerator.js → MultiSignGenerator.js} +1 -1
- package/build/keypair/EcKeyPair.d.ts +0 -1
- package/build/keypair/EcKeyPair.js +2 -2
- package/build/keypair/Wallet.d.ts +0 -1
- package/build/keypair/Wallet.js +0 -5
- package/build/metadata/ContractBaseMetadata.js +0 -1
- package/build/metadata/contracts/wBTC.js +3 -5
- package/build/metadata/tokens.js +32 -30
- package/build/opnet.d.ts +5 -3
- package/build/opnet.js +5 -3
- package/build/signer/TweakedSigner.d.ts +0 -1
- package/build/transaction/TransactionFactory.d.ts +2 -0
- package/build/transaction/TransactionFactory.js +42 -3
- package/build/transaction/browser/BrowserSignerBase.d.ts +0 -1
- package/build/transaction/browser/extensions/UnisatSigner.d.ts +0 -1
- package/build/transaction/browser/extensions/UnisatSigner.js +1 -6
- package/build/transaction/builders/CustomScriptTransaction.d.ts +40 -0
- package/build/transaction/builders/{DeploymentTransactionV2.js → CustomScriptTransaction.js} +40 -67
- package/build/transaction/builders/DeploymentTransaction.d.ts +0 -1
- package/build/transaction/builders/DeploymentTransaction.js +25 -33
- package/build/transaction/builders/FundingTransaction.js +1 -3
- package/build/transaction/builders/InteractionTransaction.d.ts +0 -1
- package/build/transaction/builders/InteractionTransaction.js +2 -5
- package/build/transaction/builders/MultiSignTransaction.d.ts +0 -1
- package/build/transaction/builders/MultiSignTransaction.js +66 -73
- package/build/transaction/builders/SharedInteractionTransaction.d.ts +0 -1
- package/build/transaction/builders/SharedInteractionTransaction.js +20 -25
- package/build/transaction/builders/TransactionBuilder.d.ts +0 -1
- package/build/transaction/builders/TransactionBuilder.js +12 -21
- package/build/transaction/builders/UnwrapSegwitTransaction.d.ts +0 -1
- package/build/transaction/builders/UnwrapSegwitTransaction.js +4 -10
- package/build/transaction/builders/UnwrapTransaction.d.ts +0 -1
- package/build/transaction/builders/UnwrapTransaction.js +5 -11
- package/build/transaction/builders/WrapTransaction.d.ts +0 -1
- package/build/transaction/builders/WrapTransaction.js +5 -12
- package/build/transaction/enums/TransactionType.d.ts +2 -1
- package/build/transaction/enums/TransactionType.js +1 -0
- package/build/transaction/interfaces/ITransactionParameters.d.ts +0 -1
- package/build/transaction/interfaces/Tap.d.ts +0 -1
- package/build/transaction/processor/PsbtTransaction.js +3 -4
- package/build/transaction/shared/P2TR_MS.d.ts +0 -1
- package/build/transaction/shared/TweakedTransaction.d.ts +0 -1
- package/build/transaction/shared/TweakedTransaction.js +11 -16
- package/build/utils/BitcoinUtils.d.ts +0 -1
- package/build/utxo/OPNetLimitedProvider.js +2 -3
- package/build/verification/TapscriptVerificator.d.ts +0 -1
- package/build/verification/TapscriptVerificator.js +1 -1
- package/build/wbtc/UnwrapGeneration.js +0 -2
- package/build/wbtc/WrappedGenerationParameters.d.ts +0 -1
- package/build/wbtc/WrappedGenerationParameters.js +0 -6
- package/cjs/package.json +3 -0
- package/gulpfile.js +49 -133
- package/package.json +112 -113
- package/src/_version.ts +1 -1
- package/src/bytecode/Compressor.ts +27 -27
- package/src/consensus/metadata/RoswellConsensus.ts +26 -26
- package/src/crypto/crypto.ts +1 -1
- package/src/generators/Generator.ts +75 -75
- package/src/generators/builders/CalldataGenerator.ts +2 -0
- package/src/generators/builders/CustomGenerator.ts +30 -0
- package/src/generators/builders/DeploymentGenerator.ts +2 -0
- package/src/generators/builders/MultiSignGenerator.ts +73 -73
- package/src/metadata/contracts/wBTC.ts +60 -60
- package/src/metadata/tokens.ts +135 -135
- package/src/network/ChainId.ts +6 -6
- package/src/opnet.ts +82 -82
- package/src/signer/TweakedSigner.ts +56 -56
- package/src/transaction/TransactionFactory.ts +72 -14
- package/src/transaction/builders/CustomScriptTransaction.ts +337 -0
- package/src/transaction/builders/DeploymentTransaction.ts +356 -356
- package/src/transaction/builders/MultiSignTransaction.ts +659 -659
- package/src/transaction/builders/UnwrapSegwitTransaction.ts +365 -365
- package/src/transaction/builders/UnwrapTransaction.ts +507 -507
- package/src/transaction/enums/TransactionType.ts +10 -9
- package/src/transaction/processor/PsbtTransaction.ts +173 -173
- package/src/transaction/shared/P2TR_MS.ts +42 -42
- package/src/transaction/shared/TweakedTransaction.ts +539 -539
- package/src/utils/BitcoinUtils.ts +96 -96
- package/tsconfig.base.json +27 -43
- package/tsconfig.json +15 -8
- package/tsconfig.webpack.json +22 -22
- package/EPOCH.md +0 -250
- package/VAULT_TARGET_CONSOLIDATION.md +0 -111
- package/browser/network/NetworkInformation.d.ts +0 -6
- package/browser/transaction/browser/BrowserSigner.d.ts +0 -9
- package/browser/transaction/builders/TapUnwarpTransaction.d.ts +0 -40
- package/browser/transaction/builders/UnwarpTransaction.d.ts +0 -34
- package/browser/utxo/UTXOManager.d.ts +0 -7
- package/build/Utils.d.ts +0 -0
- package/build/Utils.js +0 -1
- package/build/consensus/metadata/RoswsellConsensus.d.ts +0 -2
- package/build/consensus/metadata/RoswsellConsensus.js +0 -4
- package/build/contracts/ContractMetadataManager.d.ts +0 -0
- package/build/contracts/ContractMetadataManager.js +0 -1
- package/build/generators/OPNetAddressGenerator.d.ts +0 -0
- package/build/generators/OPNetAddressGenerator.js +0 -1
- package/build/generators/builders/DeploymentGeneratorV2.d.ts +0 -13
- package/build/generators/builders/DeploymentGeneratorV2.js +0 -57
- package/build/generators/builders/UnwrapGenerator.d.ts +0 -8
- package/build/generators/builders/UnwrapGenerator.js +0 -79
- package/build/keypair/interfaces/GeneratedWallet.d.ts +0 -5
- package/build/keypair/interfaces/GeneratedWallet.js +0 -1
- package/build/metadata/CommonContracts.d.ts +0 -6
- package/build/metadata/CommonContracts.js +0 -5
- package/build/metadata/ContractMetadataManager.d.ts +0 -1
- package/build/metadata/ContractMetadataManager.js +0 -9
- package/build/metadata/contracts/ContractBase.d.ts +0 -9
- package/build/metadata/contracts/ContractBase.js +0 -13
- package/build/metadata/contracts/ContractBaseMetadata.d.ts +0 -9
- package/build/metadata/contracts/ContractBaseMetadata.js +0 -13
- package/build/metadata/contracts/ContractMetadataManager.d.ts +0 -0
- package/build/metadata/contracts/ContractMetadataManager.js +0 -1
- package/build/network/NetworkConverter.d.ts +0 -0
- package/build/network/NetworkConverter.js +0 -14
- package/build/network/NetworkInformation.d.ts +0 -6
- package/build/network/NetworkInformation.js +0 -1
- package/build/scripts/Regtest.d.ts +0 -2
- package/build/scripts/Regtest.js +0 -15
- package/build/scripts/test.d.ts +0 -1
- package/build/scripts/test.js +0 -74
- package/build/signer/Regtest.d.ts +0 -2
- package/build/signer/Regtest.js +0 -15
- package/build/tests/Regtest.d.ts +0 -3
- package/build/tests/Regtest.js +0 -29
- package/build/tests/adaptPSBT.d.ts +0 -1
- package/build/tests/adaptPSBT.js +0 -44
- package/build/tests/btc/send.d.ts +0 -1
- package/build/tests/btc/send.js +0 -35
- package/build/tests/btc/transfer.d.ts +0 -1
- package/build/tests/btc/transfer.js +0 -35
- package/build/tests/createPairReg.d.ts +0 -1
- package/build/tests/createPairReg.js +0 -73
- package/build/tests/deploy/deployMoto.d.ts +0 -4
- package/build/tests/deploy/deployMoto.js +0 -89
- package/build/tests/deploy/deployPool.d.ts +0 -1
- package/build/tests/deploy/deployPool.js +0 -5
- package/build/tests/deploy/deployStep1.d.ts +0 -1
- package/build/tests/deploy/deployStep1.js +0 -5
- package/build/tests/deploy/deployStep2.d.ts +0 -1
- package/build/tests/deploy/deployStep2.js +0 -5
- package/build/tests/deploy/deployStep3.d.ts +0 -1
- package/build/tests/deploy/deployStep3.js +0 -5
- package/build/tests/deploy.d.ts +0 -1
- package/build/tests/deploy.js +0 -41
- package/build/tests/deployMotoRegStep1.d.ts +0 -1
- package/build/tests/deployMotoRegStep1.js +0 -85
- package/build/tests/deployReg.d.ts +0 -1
- package/build/tests/deployReg.js +0 -85
- package/build/tests/factory/createPairReg.d.ts +0 -1
- package/build/tests/factory/createPairReg.js +0 -13
- package/build/tests/gen.d.ts +0 -1
- package/build/tests/gen.js +0 -19
- package/build/tests/interaction.d.ts +0 -5
- package/build/tests/interaction.js +0 -62
- package/build/tests/massWrapReg.d.ts +0 -1
- package/build/tests/massWrapReg.js +0 -105
- package/build/tests/mineReg.d.ts +0 -1
- package/build/tests/mineReg.js +0 -19
- package/build/tests/moto/airdropToken.d.ts +0 -1
- package/build/tests/moto/airdropToken.js +0 -21
- package/build/tests/moto/airdropTokens.d.ts +0 -1
- package/build/tests/moto/airdropTokens.js +0 -60
- package/build/tests/moto/allowance.d.ts +0 -1
- package/build/tests/moto/allowance.js +0 -6
- package/build/tests/moto/approve.d.ts +0 -1
- package/build/tests/moto/approve.js +0 -10
- package/build/tests/moto/approveWBTC.d.ts +0 -1
- package/build/tests/moto/approveWBTC.js +0 -12
- package/build/tests/moto/balanceOf.d.ts +0 -1
- package/build/tests/moto/balanceOf.js +0 -12
- package/build/tests/moto/transfer.d.ts +0 -1
- package/build/tests/moto/transfer.js +0 -16
- package/build/tests/motoswap/airdropToken.d.ts +0 -11
- package/build/tests/motoswap/airdropToken.js +0 -36
- package/build/tests/motoswap/deployMoto.d.ts +0 -4
- package/build/tests/motoswap/deployMoto.js +0 -89
- package/build/tests/motoswap/deployMotoRegStep1.d.ts +0 -1
- package/build/tests/motoswap/deployMotoRegStep1.js +0 -91
- package/build/tests/motoswap/deployMotoRegStep2.d.ts +0 -1
- package/build/tests/motoswap/deployMotoRegStep2.js +0 -91
- package/build/tests/motoswap/deployPool.d.ts +0 -1
- package/build/tests/motoswap/deployPool.js +0 -5
- package/build/tests/motoswap/deployStep1.d.ts +0 -1
- package/build/tests/motoswap/deployStep1.js +0 -5
- package/build/tests/motoswap/deployStep2.d.ts +0 -1
- package/build/tests/motoswap/deployStep2.js +0 -5
- package/build/tests/motoswap/deployStep3.d.ts +0 -1
- package/build/tests/motoswap/deployStep3.js +0 -5
- package/build/tests/motoswap/interaction.d.ts +0 -3
- package/build/tests/motoswap/interaction.js +0 -63
- package/build/tests/motoswap/routerAddLiquidity.d.ts +0 -11
- package/build/tests/motoswap/routerAddLiquidity.js +0 -35
- package/build/tests/motoswap-router/addLiquidity.d.ts +0 -11
- package/build/tests/motoswap-router/addLiquidity.js +0 -36
- package/build/tests/motoswap-router/deployMoto.d.ts +0 -4
- package/build/tests/motoswap-router/deployMoto.js +0 -89
- package/build/tests/motoswap-router/deployPool.d.ts +0 -1
- package/build/tests/motoswap-router/deployPool.js +0 -5
- package/build/tests/motoswap-router/deployStep1.d.ts +0 -1
- package/build/tests/motoswap-router/deployStep1.js +0 -5
- package/build/tests/motoswap-router/deployStep2.d.ts +0 -1
- package/build/tests/motoswap-router/deployStep2.js +0 -5
- package/build/tests/motoswap-router/deployStep3.d.ts +0 -1
- package/build/tests/motoswap-router/deployStep3.js +0 -5
- package/build/tests/motoswap-router/getAmountsOut.d.ts +0 -5
- package/build/tests/motoswap-router/getAmountsOut.js +0 -34
- package/build/tests/motoswap-router/routerAddLiquidity.d.ts +0 -11
- package/build/tests/motoswap-router/routerAddLiquidity.js +0 -35
- package/build/tests/motoswap-router/swap.d.ts +0 -8
- package/build/tests/motoswap-router/swap.js +0 -24
- package/build/tests/multisign.d.ts +0 -1
- package/build/tests/multisign.js +0 -47
- package/build/tests/multisign2.d.ts +0 -1
- package/build/tests/multisign2.js +0 -27
- package/build/tests/pool/DecodePoolAddress.d.ts +0 -6
- package/build/tests/pool/DecodePoolAddress.js +0 -12
- package/build/tests/pool/decodeReserves.d.ts +0 -5
- package/build/tests/pool/decodeReserves.js +0 -13
- package/build/tests/pool/reserves.d.ts +0 -1
- package/build/tests/pool/reserves.js +0 -18
- package/build/tests/shared/Utils.d.ts +0 -2
- package/build/tests/shared/Utils.js +0 -14
- package/build/tests/shared/interaction.d.ts +0 -7
- package/build/tests/shared/interaction.js +0 -85
- package/build/tests/shared/tokens.d.ts +0 -6
- package/build/tests/shared/tokens.js +0 -5
- package/build/tests/stakeReg.d.ts +0 -1
- package/build/tests/stakeReg.js +0 -73
- package/build/tests/stakedReg.d.ts +0 -1
- package/build/tests/stakedReg.js +0 -28
- package/build/tests/test.d.ts +0 -1
- package/build/tests/test.js +0 -51
- package/build/tests/test2.d.ts +0 -1
- package/build/tests/test2.js +0 -73
- package/build/tests/testReg.d.ts +0 -1
- package/build/tests/testReg.js +0 -91
- package/build/tests/tokens.d.ts +0 -6
- package/build/tests/tokens.js +0 -5
- package/build/tests/totalRewardReg.d.ts +0 -1
- package/build/tests/totalRewardReg.js +0 -28
- package/build/tests/transfer.d.ts +0 -1
- package/build/tests/transfer.js +0 -74
- package/build/tests/transferReg.d.ts +0 -1
- package/build/tests/transferReg.js +0 -74
- package/build/tests/unStakeReg.d.ts +0 -1
- package/build/tests/unStakeReg.js +0 -72
- package/build/tests/unwrapReg.d.ts +0 -1
- package/build/tests/unwrapReg.js +0 -61
- package/build/tests/unwrapReg2.d.ts +0 -1
- package/build/tests/unwrapReg2.js +0 -56
- package/build/tests/unwrapRegSegwit.d.ts +0 -1
- package/build/tests/unwrapRegSegwit.js +0 -83
- package/build/tests/wbtc/approve.d.ts +0 -1
- package/build/tests/wbtc/approve.js +0 -6
- package/build/tests/wbtc/approveWBTC.d.ts +0 -1
- package/build/tests/wbtc/approveWBTC.js +0 -12
- package/build/tests/wbtc/massWrapReg.d.ts +0 -1
- package/build/tests/wbtc/massWrapReg.js +0 -105
- package/build/tests/wbtc/transfer.d.ts +0 -1
- package/build/tests/wbtc/transfer.js +0 -16
- package/build/tests/wbtc/transferReg.d.ts +0 -1
- package/build/tests/wbtc/transferReg.js +0 -16
- package/build/tests/wbtc/unStakeReg.d.ts +0 -1
- package/build/tests/wbtc/unStakeReg.js +0 -72
- package/build/tests/wbtc/unwrapReg.d.ts +0 -1
- package/build/tests/wbtc/unwrapReg.js +0 -60
- package/build/tests/wbtc/unwrapRegSegwit.d.ts +0 -1
- package/build/tests/wbtc/unwrapRegSegwit.js +0 -83
- package/build/tests/wbtc/withdrawalRequestReg.d.ts +0 -1
- package/build/tests/wbtc/withdrawalRequestReg.js +0 -71
- package/build/tests/wbtc/wrapReg.d.ts +0 -1
- package/build/tests/wbtc/wrapReg.js +0 -65
- package/build/tests/wbtc/wrapTest.d.ts +0 -1
- package/build/tests/wbtc/wrapTest.js +0 -66
- package/build/tests/withdrawalRequestReg.d.ts +0 -1
- package/build/tests/withdrawalRequestReg.js +0 -71
- package/build/tests/wrap.d.ts +0 -1
- package/build/tests/wrap.js +0 -65
- package/build/tests/wrapReg.d.ts +0 -1
- package/build/tests/wrapReg.js +0 -68
- package/build/tests/wrapTest.d.ts +0 -1
- package/build/tests/wrapTest.js +0 -66
- package/build/tests/wrapTestg.d.ts +0 -1
- package/build/tests/wrapTestg.js +0 -66
- package/build/tests/writers/allowance.d.ts +0 -3
- package/build/tests/writers/allowance.js +0 -10
- package/build/tests/writers/approve.d.ts +0 -4
- package/build/tests/writers/approve.js +0 -11
- package/build/transaction/TransactionBuilder.d.ts +0 -60
- package/build/transaction/TransactionBuilder.js +0 -244
- package/build/transaction/browser/BrowserSigner.d.ts +0 -11
- package/build/transaction/browser/BrowserSigner.js +0 -10
- package/build/transaction/browser/extensions/Unisat.d.ts +0 -54
- package/build/transaction/browser/extensions/Unisat.js +0 -11
- package/build/transaction/builders/GenericTransaction.d.ts +0 -11
- package/build/transaction/builders/GenericTransaction.js +0 -23
- package/build/transaction/builders/TapUnwarpTransaction.d.ts +0 -37
- package/build/transaction/builders/TapUnwarpTransaction.js +0 -201
- package/build/transaction/builders/UnwarpSegwitTransaction.d.ts +0 -34
- package/build/transaction/builders/UnwarpSegwitTransaction.js +0 -184
- package/build/transaction/builders/UnwarpTransaction.d.ts +0 -35
- package/build/transaction/builders/UnwarpTransaction.js +0 -199
- package/build/transaction/interfaces/ITransactions.d.ts +0 -32
- package/build/transaction/interfaces/ITransactions.js +0 -1
- package/build/utxo/IUTXO.d.ts +0 -0
- package/build/utxo/IUTXO.js +0 -1
- package/build/utxo/OPNetUtils.d.ts +0 -7
- package/build/utxo/OPNetUtils.js +0 -47
- package/build/utxo/UTXOManager.d.ts +0 -7
- package/build/utxo/UTXOManager.js +0 -47
- package/build/wbtc/BroadcastResponse.d.ts +0 -0
- package/build/wbtc/BroadcastResponse.js +0 -1
- package/examples/Deploy.md +0 -188
- package/examples/Unwrap.md +0 -165
- package/examples/Wrap.md +0 -194
- package/tsconfig.cjs.json +0 -13
- /package/build/generators/{features.d.ts → Features.d.ts} +0 -0
- /package/build/generators/{features.js → Features.js} +0 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import { Taptree } from 'bitcoinjs-lib/src/types.js';
|
|
2
|
+
import { TransactionType } from '../enums/TransactionType.js';
|
|
3
|
+
import { TapLeafScript } from '../interfaces/Tap.js';
|
|
4
|
+
import { SharedInteractionParameters } from '../interfaces/ITransactionParameters.js';
|
|
5
|
+
import { Address } from '@btc-vision/bsi-binary';
|
|
6
|
+
import { crypto as bitCrypto, Payment, Psbt, Signer, Stack } from 'bitcoinjs-lib';
|
|
7
|
+
import { TransactionBuilder } from './TransactionBuilder';
|
|
8
|
+
import { CustomGenerator } from '../../generators/builders/CustomGenerator';
|
|
9
|
+
import { BitcoinUtils } from '../../utils/BitcoinUtils';
|
|
10
|
+
import { EcKeyPair } from '../../keypair/EcKeyPair';
|
|
11
|
+
import { AddressGenerator } from '../../generators/AddressGenerator';
|
|
12
|
+
import { toXOnly } from 'bitcoinjs-lib/src/psbt/bip371.js';
|
|
13
|
+
import { PsbtInput } from 'bip174/src/lib/interfaces.js';
|
|
14
|
+
|
|
15
|
+
export interface ICustomTransactionParameters extends SharedInteractionParameters {
|
|
16
|
+
readonly script: (Buffer | Stack)[];
|
|
17
|
+
readonly witnesses: Buffer[];
|
|
18
|
+
|
|
19
|
+
readonly to: Address;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Class for interaction transactions
|
|
24
|
+
* @class CustomScriptTransaction
|
|
25
|
+
*/
|
|
26
|
+
export class CustomScriptTransaction extends TransactionBuilder<TransactionType.CUSTOM_CODE> {
|
|
27
|
+
public type: TransactionType.CUSTOM_CODE = TransactionType.CUSTOM_CODE;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The contract address
|
|
31
|
+
* @protected
|
|
32
|
+
*/
|
|
33
|
+
protected readonly _scriptAddress: Address;
|
|
34
|
+
/**
|
|
35
|
+
* The tap leaf script
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
protected tapLeafScript: TapLeafScript | null = null;
|
|
39
|
+
/**
|
|
40
|
+
* The target script redeem
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
private targetScriptRedeem: Payment | null = null;
|
|
44
|
+
/**
|
|
45
|
+
* The left over funds script redeem
|
|
46
|
+
* @private
|
|
47
|
+
*/
|
|
48
|
+
private leftOverFundsScriptRedeem: Payment | null = null;
|
|
49
|
+
/**
|
|
50
|
+
* The compiled target script
|
|
51
|
+
* @private
|
|
52
|
+
*/
|
|
53
|
+
private readonly compiledTargetScript: Buffer;
|
|
54
|
+
/**
|
|
55
|
+
* The script tree
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
private readonly scriptTree: Taptree;
|
|
59
|
+
/**
|
|
60
|
+
* The deployment bitcoin generator
|
|
61
|
+
* @private
|
|
62
|
+
*/
|
|
63
|
+
private generator: CustomGenerator;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The contract seed
|
|
67
|
+
* @private
|
|
68
|
+
*/
|
|
69
|
+
private readonly scriptSeed: Buffer;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The contract signer
|
|
73
|
+
* @private
|
|
74
|
+
*/
|
|
75
|
+
private readonly contractSigner: Signer;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The contract salt random bytes
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
81
|
+
private readonly randomBytes: Buffer;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The witnesses
|
|
85
|
+
* @private
|
|
86
|
+
*/
|
|
87
|
+
private readonly witnesses: Buffer[];
|
|
88
|
+
|
|
89
|
+
public constructor(parameters: ICustomTransactionParameters) {
|
|
90
|
+
super(parameters);
|
|
91
|
+
|
|
92
|
+
if (!parameters.script) throw new Error('Bitcoin script is required');
|
|
93
|
+
if (!parameters.witnesses) throw new Error('Witness(es) are required');
|
|
94
|
+
|
|
95
|
+
this.witnesses = parameters.witnesses;
|
|
96
|
+
this.randomBytes = parameters.randomBytes || BitcoinUtils.rndBytes();
|
|
97
|
+
|
|
98
|
+
this.scriptSeed = this.getContractSeed();
|
|
99
|
+
this.contractSigner = EcKeyPair.fromSeedKeyPair(this.scriptSeed, this.network);
|
|
100
|
+
|
|
101
|
+
this.generator = new CustomGenerator(this.internalPubKeyToXOnly(), this.network);
|
|
102
|
+
|
|
103
|
+
this.compiledTargetScript = this.generator.compile(parameters.script);
|
|
104
|
+
|
|
105
|
+
this.scriptTree = this.getScriptTree();
|
|
106
|
+
|
|
107
|
+
this.internalInit();
|
|
108
|
+
|
|
109
|
+
this._scriptAddress = AddressGenerator.generatePKSH(this.scriptSeed, this.network);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @description Get the contract address (PKSH)
|
|
114
|
+
*/
|
|
115
|
+
public get scriptAddress(): Address {
|
|
116
|
+
return this._scriptAddress;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @description Get the P2TR address
|
|
121
|
+
*/
|
|
122
|
+
public get p2trAddress(): Address {
|
|
123
|
+
return this.to || this.getScriptAddress();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Get the random bytes used for the interaction
|
|
128
|
+
* @returns {Buffer} The random bytes
|
|
129
|
+
*/
|
|
130
|
+
public getRndBytes(): Buffer {
|
|
131
|
+
return this.randomBytes;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Get the contract signer public key
|
|
136
|
+
* @protected
|
|
137
|
+
*/
|
|
138
|
+
protected contractSignerXOnlyPubKey(): Buffer {
|
|
139
|
+
return toXOnly(this.contractSigner.publicKey);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Build the transaction
|
|
144
|
+
* @protected
|
|
145
|
+
*/
|
|
146
|
+
protected override async buildTransaction(): Promise<void> {
|
|
147
|
+
if (!this.to) {
|
|
148
|
+
this.to = this.getScriptAddress();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const selectedRedeem = !!this.contractSigner
|
|
152
|
+
? this.targetScriptRedeem
|
|
153
|
+
: this.leftOverFundsScriptRedeem;
|
|
154
|
+
|
|
155
|
+
if (!selectedRedeem) {
|
|
156
|
+
throw new Error('Left over funds script redeem is required');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (!selectedRedeem.redeemVersion) {
|
|
160
|
+
throw new Error('Left over funds script redeem version is required');
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (!selectedRedeem.output) {
|
|
164
|
+
throw new Error('Left over funds script redeem output is required');
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
this.tapLeafScript = {
|
|
168
|
+
leafVersion: selectedRedeem.redeemVersion,
|
|
169
|
+
script: selectedRedeem.output,
|
|
170
|
+
controlBlock: this.getWitness(),
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
this.addInputsFromUTXO();
|
|
174
|
+
|
|
175
|
+
const amountSpent: bigint = this.getTransactionOPNetFee();
|
|
176
|
+
this.addOutput({
|
|
177
|
+
value: Number(amountSpent),
|
|
178
|
+
address: this.to,
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
await this.addRefundOutput(amountSpent);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Sign the inputs
|
|
186
|
+
* @param {Psbt} transaction The transaction to sign
|
|
187
|
+
* @protected
|
|
188
|
+
*/
|
|
189
|
+
protected async signInputs(transaction: Psbt): Promise<void> {
|
|
190
|
+
if (!this.contractSigner) {
|
|
191
|
+
await super.signInputs(transaction);
|
|
192
|
+
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
for (let i = 0; i < transaction.data.inputs.length; i++) {
|
|
197
|
+
if (i === 0) {
|
|
198
|
+
// multi sig input
|
|
199
|
+
transaction.signInput(0, this.contractSigner);
|
|
200
|
+
transaction.signInput(0, this.getSignerKey());
|
|
201
|
+
|
|
202
|
+
transaction.finalizeInput(0, this.customFinalizer);
|
|
203
|
+
} else {
|
|
204
|
+
transaction.signInput(i, this.getSignerKey());
|
|
205
|
+
transaction.finalizeInput(i);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Get the tap output
|
|
212
|
+
* @protected
|
|
213
|
+
*/
|
|
214
|
+
protected override generateScriptAddress(): Payment {
|
|
215
|
+
return {
|
|
216
|
+
internalPubkey: this.internalPubKeyToXOnly(),
|
|
217
|
+
network: this.network,
|
|
218
|
+
scriptTree: this.scriptTree,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Generate the tap data
|
|
224
|
+
* @protected
|
|
225
|
+
*/
|
|
226
|
+
protected override generateTapData(): Payment {
|
|
227
|
+
const selectedRedeem = !!this.contractSigner
|
|
228
|
+
? this.targetScriptRedeem
|
|
229
|
+
: this.leftOverFundsScriptRedeem;
|
|
230
|
+
|
|
231
|
+
if (!selectedRedeem) {
|
|
232
|
+
throw new Error('Left over funds script redeem is required');
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (!this.scriptTree) {
|
|
236
|
+
throw new Error('Script tree is required');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return {
|
|
240
|
+
internalPubkey: this.internalPubKeyToXOnly(),
|
|
241
|
+
network: this.network,
|
|
242
|
+
scriptTree: this.scriptTree,
|
|
243
|
+
redeem: selectedRedeem,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Generate the contract seed for the deployment
|
|
249
|
+
* @private
|
|
250
|
+
*/
|
|
251
|
+
private getContractSeed(): Buffer {
|
|
252
|
+
return bitCrypto.hash256(this.randomBytes);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Finalize the transaction
|
|
257
|
+
* @param _inputIndex
|
|
258
|
+
* @param input
|
|
259
|
+
*/
|
|
260
|
+
private customFinalizer = (_inputIndex: number, input: PsbtInput) => {
|
|
261
|
+
if (!this.tapLeafScript) {
|
|
262
|
+
throw new Error('Tap leaf script is required');
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (!input.tapScriptSig) {
|
|
266
|
+
throw new Error('Tap script signature is required');
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const scriptSolution = this.witnesses;
|
|
270
|
+
const witness = scriptSolution
|
|
271
|
+
.concat(this.tapLeafScript.script)
|
|
272
|
+
.concat(this.tapLeafScript.controlBlock);
|
|
273
|
+
|
|
274
|
+
return {
|
|
275
|
+
finalScriptWitness: TransactionBuilder.witnessStackToScriptWitness(witness),
|
|
276
|
+
};
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Get the public keys for the redeem scripts
|
|
281
|
+
* @private
|
|
282
|
+
*/
|
|
283
|
+
private getPubKeys(): Buffer[] {
|
|
284
|
+
const pubkeys = [this.signer.publicKey];
|
|
285
|
+
|
|
286
|
+
if (this.contractSigner) {
|
|
287
|
+
pubkeys.push(this.contractSigner.publicKey);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return pubkeys;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Generate the redeem scripts
|
|
295
|
+
* @private
|
|
296
|
+
*/
|
|
297
|
+
private generateRedeemScripts(): void {
|
|
298
|
+
this.targetScriptRedeem = {
|
|
299
|
+
pubkeys: this.getPubKeys(),
|
|
300
|
+
output: this.compiledTargetScript,
|
|
301
|
+
redeemVersion: 192,
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
this.leftOverFundsScriptRedeem = {
|
|
305
|
+
pubkeys: this.getPubKeys(),
|
|
306
|
+
output: this.getLeafScript(),
|
|
307
|
+
redeemVersion: 192,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Get the second leaf script
|
|
313
|
+
* @private
|
|
314
|
+
*/
|
|
315
|
+
private getLeafScript(): Buffer {
|
|
316
|
+
return TransactionBuilder.LOCK_LEAF_SCRIPT;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Get the script tree
|
|
321
|
+
* @private
|
|
322
|
+
*/
|
|
323
|
+
private getScriptTree(): Taptree {
|
|
324
|
+
this.generateRedeemScripts();
|
|
325
|
+
|
|
326
|
+
return [
|
|
327
|
+
{
|
|
328
|
+
output: this.compiledTargetScript,
|
|
329
|
+
version: 192,
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
output: this.getLeafScript(),
|
|
333
|
+
version: 192,
|
|
334
|
+
},
|
|
335
|
+
];
|
|
336
|
+
}
|
|
337
|
+
}
|