@btc-vision/bitcoin 6.5.6 → 7.0.0-alpha.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/HOW_TO_WRITE_GOOD_CODE.md +2436 -0
- package/benchmark/psbt-2000-inputs.bench.ts +178 -0
- package/benchmark/signing.bench.ts +147 -0
- package/browser/address.d.ts +56 -9
- package/browser/address.d.ts.map +1 -0
- package/browser/bech32utils.d.ts +9 -1
- package/browser/bech32utils.d.ts.map +1 -0
- package/browser/bip66.d.ts +11 -6
- package/browser/bip66.d.ts.map +1 -0
- package/browser/block.d.ts +117 -11
- package/browser/block.d.ts.map +1 -0
- package/browser/branded.d.ts +20 -0
- package/browser/branded.d.ts.map +1 -0
- package/browser/crypto/crypto.d.ts +1 -0
- package/browser/crypto/crypto.d.ts.map +1 -0
- package/browser/crypto.d.ts +46 -7
- package/browser/crypto.d.ts.map +1 -0
- package/browser/ecc/context.d.ts +129 -0
- package/browser/ecc/context.d.ts.map +1 -0
- package/browser/ecc/index.d.ts +11 -0
- package/browser/ecc/index.d.ts.map +1 -0
- package/browser/ecc/types.d.ts +128 -0
- package/browser/ecc/types.d.ts.map +1 -0
- package/browser/ecpair.d.ts +99 -0
- package/browser/errors.d.ts +124 -0
- package/browser/errors.d.ts.map +1 -0
- package/browser/index.d.ts +32 -5
- package/browser/index.d.ts.map +1 -0
- package/browser/index.js +12482 -101
- package/browser/io/BinaryReader.d.ts +276 -0
- package/browser/io/BinaryReader.d.ts.map +1 -0
- package/browser/io/BinaryWriter.d.ts +391 -0
- package/browser/io/BinaryWriter.d.ts.map +1 -0
- package/browser/io/MemoryPool.d.ts +220 -0
- package/browser/io/MemoryPool.d.ts.map +1 -0
- package/browser/io/base64.d.ts +13 -0
- package/browser/io/base64.d.ts.map +1 -0
- package/browser/io/hex.d.ts +67 -0
- package/browser/io/hex.d.ts.map +1 -0
- package/browser/io/index.d.ts +17 -0
- package/browser/io/index.d.ts.map +1 -0
- package/browser/io/utils.d.ts +199 -0
- package/browser/io/utils.d.ts.map +1 -0
- package/browser/merkle.d.ts +10 -1
- package/browser/merkle.d.ts.map +1 -0
- package/browser/networks.d.ts +70 -9
- package/browser/networks.d.ts.map +1 -0
- package/browser/opcodes.d.ts +1 -0
- package/browser/opcodes.d.ts.map +1 -0
- package/browser/payments/bip341.d.ts +35 -9
- package/browser/payments/bip341.d.ts.map +1 -0
- package/browser/payments/embed.d.ts +112 -1
- package/browser/payments/embed.d.ts.map +1 -0
- package/browser/payments/index.d.ts +17 -10
- package/browser/payments/index.d.ts.map +1 -0
- package/browser/payments/p2ms.d.ts +150 -0
- package/browser/payments/p2ms.d.ts.map +1 -0
- package/browser/payments/p2op.d.ts +150 -24
- package/browser/payments/p2op.d.ts.map +1 -0
- package/browser/payments/p2pk.d.ts +154 -1
- package/browser/payments/p2pk.d.ts.map +1 -0
- package/browser/payments/p2pkh.d.ts +176 -1
- package/browser/payments/p2pkh.d.ts.map +1 -0
- package/browser/payments/p2sh.d.ts +150 -1
- package/browser/payments/p2sh.d.ts.map +1 -0
- package/browser/payments/p2tr.d.ts +185 -1
- package/browser/payments/p2tr.d.ts.map +1 -0
- package/browser/payments/p2wpkh.d.ts +161 -1
- package/browser/payments/p2wpkh.d.ts.map +1 -0
- package/browser/payments/p2wsh.d.ts +146 -1
- package/browser/payments/p2wsh.d.ts.map +1 -0
- package/browser/payments/types.d.ts +94 -64
- package/browser/payments/types.d.ts.map +1 -0
- package/browser/psbt/bip371.d.ts +34 -8
- package/browser/psbt/bip371.d.ts.map +1 -0
- package/browser/psbt/psbtutils.d.ts +56 -16
- package/browser/psbt/psbtutils.d.ts.map +1 -0
- package/browser/psbt/types.d.ts +245 -0
- package/browser/psbt/types.d.ts.map +1 -0
- package/browser/psbt/utils.d.ts +64 -0
- package/browser/psbt/utils.d.ts.map +1 -0
- package/browser/psbt/validation.d.ts +84 -0
- package/browser/psbt/validation.d.ts.map +1 -0
- package/browser/psbt.d.ts +82 -118
- package/browser/psbt.d.ts.map +1 -0
- package/browser/pubkey.d.ts +27 -6
- package/browser/pubkey.d.ts.map +1 -0
- package/browser/push_data.d.ts +24 -2
- package/browser/push_data.d.ts.map +1 -0
- package/browser/script.d.ts +33 -8
- package/browser/script.d.ts.map +1 -0
- package/browser/script_number.d.ts +17 -0
- package/browser/script_number.d.ts.map +1 -0
- package/browser/script_signature.d.ts +23 -5
- package/browser/script_signature.d.ts.map +1 -0
- package/browser/transaction.d.ts +160 -18
- package/browser/transaction.d.ts.map +1 -0
- package/browser/types.d.ts +36 -38
- package/browser/types.d.ts.map +1 -0
- package/browser/workers/WorkerSigningPool.d.ts +143 -0
- package/browser/workers/WorkerSigningPool.d.ts.map +1 -0
- package/browser/workers/WorkerSigningPool.node.d.ts +116 -0
- package/browser/workers/WorkerSigningPool.node.d.ts.map +1 -0
- package/browser/workers/ecc-bundle.d.ts +25 -0
- package/browser/workers/ecc-bundle.d.ts.map +1 -0
- package/browser/workers/index.d.ts +91 -0
- package/browser/workers/index.d.ts.map +1 -0
- package/browser/workers/psbt-parallel.d.ts +88 -0
- package/browser/workers/psbt-parallel.d.ts.map +1 -0
- package/browser/workers/signing-worker.d.ts +37 -0
- package/browser/workers/signing-worker.d.ts.map +1 -0
- package/browser/workers/types.d.ts +365 -0
- package/browser/workers/types.d.ts.map +1 -0
- package/build/address.d.ts +57 -10
- package/build/address.d.ts.map +1 -0
- package/build/address.js +80 -24
- package/build/address.js.map +1 -0
- package/build/bech32utils.d.ts +9 -1
- package/build/bech32utils.d.ts.map +1 -0
- package/build/bech32utils.js +10 -2
- package/build/bech32utils.js.map +1 -0
- package/build/bip66.d.ts +11 -6
- package/build/bip66.d.ts.map +1 -0
- package/build/bip66.js +32 -3
- package/build/bip66.js.map +1 -0
- package/build/block.d.ts +117 -11
- package/build/block.d.ts.map +1 -0
- package/build/block.js +204 -72
- package/build/block.js.map +1 -0
- package/build/branded.d.ts +20 -0
- package/build/branded.d.ts.map +1 -0
- package/build/branded.js +7 -0
- package/build/branded.js.map +1 -0
- package/build/crypto/crypto.d.ts +1 -0
- package/build/crypto/crypto.d.ts.map +1 -0
- package/build/crypto/crypto.js +1 -0
- package/build/crypto/crypto.js.map +1 -0
- package/build/crypto.d.ts +46 -7
- package/build/crypto.d.ts.map +1 -0
- package/build/crypto.js +65 -20
- package/build/crypto.js.map +1 -0
- package/build/ecc/context.d.ts +135 -0
- package/build/ecc/context.d.ts.map +1 -0
- package/build/ecc/context.js +232 -0
- package/build/ecc/context.js.map +1 -0
- package/build/ecc/index.d.ts +11 -0
- package/build/ecc/index.d.ts.map +1 -0
- package/build/ecc/index.js +11 -0
- package/build/ecc/index.js.map +1 -0
- package/build/ecc/types.d.ts +134 -0
- package/build/ecc/types.d.ts.map +1 -0
- package/build/ecc/types.js +8 -0
- package/build/ecc/types.js.map +1 -0
- package/build/errors.d.ts +124 -0
- package/build/errors.d.ts.map +1 -0
- package/build/errors.js +155 -0
- package/build/errors.js.map +1 -0
- package/build/index.d.ts +32 -5
- package/build/index.d.ts.map +1 -0
- package/build/index.js +26 -3
- package/build/index.js.map +1 -0
- package/build/io/BinaryReader.d.ts +276 -0
- package/build/io/BinaryReader.d.ts.map +1 -0
- package/build/io/BinaryReader.js +425 -0
- package/build/io/BinaryReader.js.map +1 -0
- package/build/io/BinaryWriter.d.ts +391 -0
- package/build/io/BinaryWriter.d.ts.map +1 -0
- package/build/io/BinaryWriter.js +611 -0
- package/build/io/BinaryWriter.js.map +1 -0
- package/build/io/MemoryPool.d.ts +220 -0
- package/build/io/MemoryPool.d.ts.map +1 -0
- package/build/io/MemoryPool.js +309 -0
- package/build/io/MemoryPool.js.map +1 -0
- package/build/io/base64.d.ts +13 -0
- package/build/io/base64.d.ts.map +1 -0
- package/build/io/base64.js +20 -0
- package/build/io/base64.js.map +1 -0
- package/build/io/hex.d.ts +67 -0
- package/build/io/hex.d.ts.map +1 -0
- package/build/io/hex.js +138 -0
- package/build/io/hex.js.map +1 -0
- package/build/io/index.d.ts +17 -0
- package/build/io/index.d.ts.map +1 -0
- package/build/io/index.js +23 -0
- package/build/io/index.js.map +1 -0
- package/build/io/utils.d.ts +199 -0
- package/build/io/utils.d.ts.map +1 -0
- package/build/io/utils.js +271 -0
- package/build/io/utils.js.map +1 -0
- package/build/merkle.d.ts +10 -1
- package/build/merkle.d.ts.map +1 -0
- package/build/merkle.js +12 -1
- package/build/merkle.js.map +1 -0
- package/build/networks.d.ts +70 -9
- package/build/networks.d.ts.map +1 -0
- package/build/networks.js +90 -4
- package/build/networks.js.map +1 -0
- package/build/opcodes.d.ts +1 -0
- package/build/opcodes.d.ts.map +1 -0
- package/build/opcodes.js +1 -0
- package/build/opcodes.js.map +1 -0
- package/build/payments/bip341.d.ts +36 -9
- package/build/payments/bip341.d.ts.map +1 -0
- package/build/payments/bip341.js +35 -15
- package/build/payments/bip341.js.map +1 -0
- package/build/payments/embed.d.ts +120 -1
- package/build/payments/embed.d.ts.map +1 -0
- package/build/payments/embed.js +215 -34
- package/build/payments/embed.js.map +1 -0
- package/build/payments/index.d.ts +17 -10
- package/build/payments/index.d.ts.map +1 -0
- package/build/payments/index.js +20 -10
- package/build/payments/index.js.map +1 -0
- package/build/payments/p2ms.d.ts +159 -1
- package/build/payments/p2ms.d.ts.map +1 -0
- package/build/payments/p2ms.js +427 -108
- package/build/payments/p2ms.js.map +1 -0
- package/build/payments/p2op.d.ts +158 -24
- package/build/payments/p2op.d.ts.map +1 -0
- package/build/payments/p2op.js +379 -93
- package/build/payments/p2op.js.map +1 -0
- package/build/payments/p2pk.d.ts +162 -1
- package/build/payments/p2pk.d.ts.map +1 -0
- package/build/payments/p2pk.js +327 -58
- package/build/payments/p2pk.js.map +1 -0
- package/build/payments/p2pkh.d.ts +185 -1
- package/build/payments/p2pkh.d.ts.map +1 -0
- package/build/payments/p2pkh.js +467 -114
- package/build/payments/p2pkh.js.map +1 -0
- package/build/payments/p2sh.d.ts +159 -1
- package/build/payments/p2sh.d.ts.map +1 -0
- package/build/payments/p2sh.js +500 -152
- package/build/payments/p2sh.js.map +1 -0
- package/build/payments/p2tr.d.ts +193 -1
- package/build/payments/p2tr.d.ts.map +1 -0
- package/build/payments/p2tr.js +592 -174
- package/build/payments/p2tr.js.map +1 -0
- package/build/payments/p2wpkh.d.ts +170 -1
- package/build/payments/p2wpkh.d.ts.map +1 -0
- package/build/payments/p2wpkh.js +429 -104
- package/build/payments/p2wpkh.js.map +1 -0
- package/build/payments/p2wsh.d.ts +155 -1
- package/build/payments/p2wsh.d.ts.map +1 -0
- package/build/payments/p2wsh.js +466 -144
- package/build/payments/p2wsh.js.map +1 -0
- package/build/payments/types.d.ts +98 -64
- package/build/payments/types.d.ts.map +1 -0
- package/build/payments/types.js +17 -13
- package/build/payments/types.js.map +1 -0
- package/build/psbt/bip371.d.ts +35 -9
- package/build/psbt/bip371.d.ts.map +1 -0
- package/build/psbt/bip371.js +113 -28
- package/build/psbt/bip371.js.map +1 -0
- package/build/psbt/psbtutils.d.ts +56 -16
- package/build/psbt/psbtutils.d.ts.map +1 -0
- package/build/psbt/psbtutils.js +71 -16
- package/build/psbt/psbtutils.js.map +1 -0
- package/build/psbt/types.d.ts +249 -0
- package/build/psbt/types.d.ts.map +1 -0
- package/build/psbt/types.js +6 -0
- package/build/psbt/types.js.map +1 -0
- package/build/psbt/utils.d.ts +68 -0
- package/build/psbt/utils.d.ts.map +1 -0
- package/build/psbt/utils.js +171 -0
- package/build/psbt/utils.js.map +1 -0
- package/build/psbt/validation.d.ts +88 -0
- package/build/psbt/validation.d.ts.map +1 -0
- package/build/psbt/validation.js +149 -0
- package/build/psbt/validation.js.map +1 -0
- package/build/psbt.d.ts +84 -120
- package/build/psbt.d.ts.map +1 -0
- package/build/psbt.js +411 -412
- package/build/psbt.js.map +1 -0
- package/build/pubkey.d.ts +27 -6
- package/build/pubkey.d.ts.map +1 -0
- package/build/pubkey.js +36 -12
- package/build/pubkey.js.map +1 -0
- package/build/push_data.d.ts +24 -2
- package/build/push_data.d.ts.map +1 -0
- package/build/push_data.js +44 -12
- package/build/push_data.js.map +1 -0
- package/build/script.d.ts +33 -8
- package/build/script.d.ts.map +1 -0
- package/build/script.js +100 -36
- package/build/script.js.map +1 -0
- package/build/script_number.d.ts +17 -0
- package/build/script_number.d.ts.map +1 -0
- package/build/script_number.js +19 -0
- package/build/script_number.js.map +1 -0
- package/build/script_signature.d.ts +23 -5
- package/build/script_signature.d.ts.map +1 -0
- package/build/script_signature.js +48 -15
- package/build/script_signature.js.map +1 -0
- package/build/transaction.d.ts +160 -18
- package/build/transaction.d.ts.map +1 -0
- package/build/transaction.js +443 -176
- package/build/transaction.js.map +1 -0
- package/build/tsconfig.build.tsbuildinfo +1 -0
- package/build/types.d.ts +36 -38
- package/build/types.d.ts.map +1 -0
- package/build/types.js +175 -57
- package/build/types.js.map +1 -0
- package/build/workers/WorkerSigningPool.d.ts +174 -0
- package/build/workers/WorkerSigningPool.d.ts.map +1 -0
- package/build/workers/WorkerSigningPool.js +553 -0
- package/build/workers/WorkerSigningPool.js.map +1 -0
- package/build/workers/WorkerSigningPool.node.d.ts +124 -0
- package/build/workers/WorkerSigningPool.node.d.ts.map +1 -0
- package/build/workers/WorkerSigningPool.node.js +753 -0
- package/build/workers/WorkerSigningPool.node.js.map +1 -0
- package/build/workers/ecc-bundle.d.ts +25 -0
- package/build/workers/ecc-bundle.d.ts.map +1 -0
- package/build/workers/ecc-bundle.js +25 -0
- package/build/workers/ecc-bundle.js.map +1 -0
- package/build/workers/index.d.ts +91 -0
- package/build/workers/index.d.ts.map +1 -0
- package/build/workers/index.js +114 -0
- package/build/workers/index.js.map +1 -0
- package/build/workers/psbt-parallel.d.ts +117 -0
- package/build/workers/psbt-parallel.d.ts.map +1 -0
- package/build/workers/psbt-parallel.js +233 -0
- package/build/workers/psbt-parallel.js.map +1 -0
- package/build/workers/signing-worker.d.ts +37 -0
- package/build/workers/signing-worker.d.ts.map +1 -0
- package/build/workers/signing-worker.js +350 -0
- package/build/workers/signing-worker.js.map +1 -0
- package/build/workers/types.d.ts +365 -0
- package/build/workers/types.d.ts.map +1 -0
- package/build/workers/types.js +60 -0
- package/build/workers/types.js.map +1 -0
- package/package.json +66 -8
- package/scripts/bundle-ecc.ts +111 -0
- package/src/address.ts +81 -44
- package/src/bech32utils.ts +3 -3
- package/src/bip66.ts +34 -24
- package/src/block.ts +196 -84
- package/src/branded.ts +18 -0
- package/src/crypto.ts +64 -26
- package/src/ecc/context.ts +277 -0
- package/src/ecc/index.ts +14 -0
- package/src/ecc/types.ts +154 -0
- package/src/ecpair.d.ts +99 -0
- package/src/errors.ts +163 -0
- package/src/index.ts +113 -9
- package/src/io/BinaryReader.ts +461 -0
- package/src/io/BinaryWriter.ts +696 -0
- package/src/io/MemoryPool.ts +343 -0
- package/src/io/base64.ts +20 -0
- package/src/io/hex.ts +155 -0
- package/src/io/index.ts +41 -0
- package/src/io/utils.ts +283 -0
- package/src/merkle.ts +14 -9
- package/src/networks.ts +9 -9
- package/src/payments/bip341.ts +34 -33
- package/src/payments/embed.ts +244 -41
- package/src/payments/index.ts +12 -10
- package/src/payments/p2ms.ts +490 -118
- package/src/payments/p2op.ts +431 -133
- package/src/payments/p2pk.ts +370 -72
- package/src/payments/p2pkh.ts +524 -130
- package/src/payments/p2sh.ts +572 -172
- package/src/payments/p2tr.ts +686 -194
- package/src/payments/p2wpkh.ts +484 -107
- package/src/payments/p2wsh.ts +526 -164
- package/src/payments/types.ts +80 -66
- package/src/psbt/bip371.ts +68 -51
- package/src/psbt/psbtutils.ts +39 -40
- package/src/psbt/types.ts +331 -0
- package/src/psbt/utils.ts +188 -0
- package/src/psbt/validation.ts +192 -0
- package/src/psbt.ts +566 -809
- package/src/pubkey.ts +22 -23
- package/src/push_data.ts +18 -16
- package/src/script.ts +82 -64
- package/src/script_number.ts +6 -6
- package/src/script_signature.ts +33 -36
- package/src/transaction.ts +458 -238
- package/src/types.ts +231 -100
- package/src/workers/WorkerSigningPool.node.ts +887 -0
- package/src/workers/WorkerSigningPool.ts +670 -0
- package/src/workers/ecc-bundle.ts +26 -0
- package/src/workers/index.ts +165 -0
- package/src/workers/psbt-parallel.ts +332 -0
- package/src/workers/signing-worker.ts +353 -0
- package/src/workers/types.ts +413 -0
- package/test/address.spec.ts +9 -6
- package/test/bitcoin.core.spec.ts +16 -17
- package/test/block.spec.ts +8 -7
- package/test/bufferutils.spec.ts +228 -214
- package/test/crypto.spec.ts +19 -11
- package/test/fixtures/p2pk.json +0 -8
- package/test/fixtures/p2pkh.json +1 -1
- package/test/fixtures/p2sh.json +1 -1
- package/test/fixtures/script.json +1 -1
- package/test/fixtures/transaction.json +2 -2
- package/test/integration/_regtest.ts +25 -0
- package/test/integration/addresses.spec.ts +4 -3
- package/test/integration/bip32.spec.ts +2 -1
- package/test/integration/blocks.spec.ts +1 -1
- package/test/integration/cltv.spec.ts +18 -16
- package/test/integration/csv.spec.ts +37 -64
- package/test/integration/payments.spec.ts +5 -3
- package/test/integration/taproot.spec.ts +76 -83
- package/test/integration/transactions.spec.ts +38 -35
- package/test/payments.spec.ts +35 -13
- package/test/payments.utils.ts +17 -16
- package/test/psbt.spec.ts +111 -100
- package/test/script.spec.ts +11 -10
- package/test/script_signature.spec.ts +9 -11
- package/test/taproot-cache.spec.ts +694 -0
- package/test/transaction.spec.ts +32 -40
- package/test/types.spec.ts +74 -29
- package/test/workers-pool.spec.ts +963 -0
- package/test/workers-signing.spec.ts +635 -0
- package/test/workers.spec.ts +1390 -0
- package/tsconfig.base.json +34 -18
- package/tsconfig.browser.json +15 -0
- package/tsconfig.build.json +5 -0
- package/tsconfig.json +5 -14
- package/vite.config.browser.ts +3 -42
- package/vitest.config.integration.ts +2 -0
- package/browser/bufferutils.d.ts +0 -34
- package/browser/chunks/crypto-BhCpKpek.js +0 -2033
- package/browser/chunks/payments-B1wlSccx.js +0 -1089
- package/browser/chunks/psbt-BCNk7JUx.js +0 -4055
- package/browser/chunks/script-DyPItFEl.js +0 -318
- package/browser/chunks/transaction-C_UbhMGn.js +0 -432
- package/browser/chunks/utils-DNZi-T5W.js +0 -761
- package/browser/ecc_lib.d.ts +0 -3
- package/browser/hooks/AdvancedSignatureManager.d.ts +0 -16
- package/browser/hooks/HookedSigner.d.ts +0 -4
- package/browser/hooks/SignatureManager.d.ts +0 -13
- package/browser/payments/lazy.d.ts +0 -2
- package/browser/typeforce.d.ts +0 -38
- package/build/bufferutils.d.ts +0 -34
- package/build/bufferutils.js +0 -141
- package/build/ecc_lib.d.ts +0 -3
- package/build/ecc_lib.js +0 -61
- package/build/hooks/AdvancedSignatureManager.d.ts +0 -16
- package/build/hooks/AdvancedSignatureManager.js +0 -52
- package/build/hooks/HookedSigner.d.ts +0 -4
- package/build/hooks/HookedSigner.js +0 -64
- package/build/hooks/SignatureManager.d.ts +0 -13
- package/build/hooks/SignatureManager.js +0 -45
- package/build/payments/lazy.d.ts +0 -2
- package/build/payments/lazy.js +0 -28
- package/build/tsconfig.tsbuildinfo +0 -1
- package/src/bufferutils.ts +0 -188
- package/src/ecc_lib.ts +0 -94
- package/src/hooks/AdvancedSignatureManager.ts +0 -104
- package/src/hooks/HookedSigner.ts +0 -108
- package/src/hooks/SignatureManager.ts +0 -84
- package/src/payments/lazy.ts +0 -28
- package/src/typeforce.d.ts +0 -38
- package/tsconfig.webpack.json +0 -18
|
@@ -3,9 +3,10 @@ import { BIP32Factory } from '@btc-vision/bip32';
|
|
|
3
3
|
import * as bip39 from 'bip39';
|
|
4
4
|
import * as ecc from 'tiny-secp256k1';
|
|
5
5
|
import { describe, it } from 'vitest';
|
|
6
|
-
import { regtestUtils } from './_regtest.js';
|
|
6
|
+
import { regtestUtils, broadcastAndVerify } from './_regtest.js';
|
|
7
7
|
import * as bitcoin from '../../src/index.js';
|
|
8
|
-
import
|
|
8
|
+
import { toHex, fromHex, concat } from '../../src/index.js';
|
|
9
|
+
import type { PsbtInput, TapLeaf, TapLeafScript, Taptree, XOnlyPublicKey, PublicKey, Satoshi, Bytes32, EccLib } from '../../src/index.js';
|
|
9
10
|
import { LEAF_VERSION_TAPSCRIPT } from '../../src/payments/bip341.js';
|
|
10
11
|
import { tapTreeFromList, tapTreeToList } from '../../src/psbt/bip371.js';
|
|
11
12
|
import { witnessStackToScriptWitness } from '../../src/psbt/psbtutils.js';
|
|
@@ -14,7 +15,7 @@ import { toXOnly } from '../../src/pubkey.js';
|
|
|
14
15
|
import rng from 'randombytes';
|
|
15
16
|
|
|
16
17
|
const regtest = regtestUtils.network;
|
|
17
|
-
bitcoin.initEccLib(ecc);
|
|
18
|
+
bitcoin.initEccLib(ecc as unknown as EccLib);
|
|
18
19
|
const bip32 = BIP32Factory(ecc);
|
|
19
20
|
|
|
20
21
|
describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
@@ -25,10 +26,9 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
25
26
|
const xprv =
|
|
26
27
|
'xprv9s21ZrQH143K3GJpoapnV8SFfukcVBSfeCficPSGfubmSFDxo1kuHnLisriDvSnRRuL2Qrg5ggqHKNVpxR86QEC8w35uxmGoggxtQTPvfUu';
|
|
27
28
|
const path = `m/86'/0'/0'/0/0`; // Path to first child of receiving wallet on first account
|
|
28
|
-
const internalPubkey =
|
|
29
|
+
const internalPubkey = fromHex(
|
|
29
30
|
'cc8a4bc64d897bddc5fbc2f670f7a8ba0b386779106cf1223c6fc5d7cd6fc115',
|
|
30
|
-
|
|
31
|
-
);
|
|
31
|
+
) as XOnlyPublicKey;
|
|
32
32
|
const expectedAddress = 'bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr';
|
|
33
33
|
|
|
34
34
|
// Verify the above (Below is no different than other HD wallets)
|
|
@@ -37,7 +37,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
37
37
|
assert.strictEqual(rootKey.toBase58(), xprv);
|
|
38
38
|
const childNode = rootKey.derivePath(path);
|
|
39
39
|
// Since internalKey is an xOnly pubkey, we drop the DER header byte
|
|
40
|
-
const childNodeXOnlyPubkey = toXOnly(childNode.publicKey);
|
|
40
|
+
const childNodeXOnlyPubkey = toXOnly(childNode.publicKey as PublicKey);
|
|
41
41
|
assert.deepEqual(childNodeXOnlyPubkey, internalPubkey);
|
|
42
42
|
|
|
43
43
|
// This is new for taproot
|
|
@@ -59,18 +59,18 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
59
59
|
// amount to send
|
|
60
60
|
const sendAmount = amount - 1e4;
|
|
61
61
|
// Send some sats to the address via faucet. Get the hash and index. (txid/vout)
|
|
62
|
-
const { txId: hash, vout: index } = await regtestUtils.faucetComplex(output, amount);
|
|
62
|
+
const { txId: hash, vout: index } = await regtestUtils.faucetComplex(Buffer.from(output), amount);
|
|
63
63
|
// Sent 420000 sats to taproot address
|
|
64
64
|
|
|
65
65
|
const psbt = new bitcoin.Psbt({ network: regtest })
|
|
66
66
|
.addInput({
|
|
67
67
|
hash,
|
|
68
68
|
index,
|
|
69
|
-
witnessUtxo: { value: amount, script: output },
|
|
69
|
+
witnessUtxo: { value: BigInt(amount) as Satoshi as Satoshi, script: output },
|
|
70
70
|
tapInternalKey: childNodeXOnlyPubkey,
|
|
71
71
|
})
|
|
72
72
|
.addOutput({
|
|
73
|
-
value: sendAmount,
|
|
73
|
+
value: BigInt(sendAmount) as Satoshi as Satoshi,
|
|
74
74
|
address: regtestUtils.RANDOM_ADDRESS,
|
|
75
75
|
})
|
|
76
76
|
.signInput(0, tweakedChildNode)
|
|
@@ -91,12 +91,12 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
91
91
|
const p2pkhKey = bip32.fromSeed(rng(64), regtest);
|
|
92
92
|
|
|
93
93
|
const { output } = bitcoin.payments.p2tr({
|
|
94
|
-
internalPubkey: toXOnly(internalKey.publicKey),
|
|
94
|
+
internalPubkey: toXOnly(internalKey.publicKey as PublicKey),
|
|
95
95
|
network: regtest,
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
const { output: p2pkhOutput } = bitcoin.payments.p2pkh({
|
|
99
|
-
pubkey: p2pkhKey.publicKey,
|
|
99
|
+
pubkey: p2pkhKey.publicKey as PublicKey,
|
|
100
100
|
network: regtest,
|
|
101
101
|
});
|
|
102
102
|
|
|
@@ -105,46 +105,44 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
105
105
|
// amount to send
|
|
106
106
|
const sendAmount = amount - 1e4;
|
|
107
107
|
// get faucet
|
|
108
|
-
const unspent = await regtestUtils.faucetComplex(output
|
|
108
|
+
const unspent = await regtestUtils.faucetComplex(Buffer.from(output!), amount);
|
|
109
109
|
|
|
110
110
|
// non segwit utxo
|
|
111
|
-
const p2pkhUnspent = await regtestUtils.faucetComplex(p2pkhOutput
|
|
111
|
+
const p2pkhUnspent = await regtestUtils.faucetComplex(Buffer.from(p2pkhOutput!), amount);
|
|
112
112
|
const utx = await regtestUtils.fetch(p2pkhUnspent.txId);
|
|
113
|
-
const nonWitnessUtxo =
|
|
113
|
+
const nonWitnessUtxo = fromHex(utx.txHex);
|
|
114
114
|
|
|
115
115
|
const psbt = new bitcoin.Psbt({ network: regtest });
|
|
116
116
|
psbt.addInput({
|
|
117
117
|
hash: unspent.txId,
|
|
118
118
|
index: 0,
|
|
119
|
-
witnessUtxo: { value: amount, script: output! },
|
|
120
|
-
tapInternalKey: toXOnly(internalKey.publicKey),
|
|
119
|
+
witnessUtxo: { value: BigInt(amount) as Satoshi, script: output! },
|
|
120
|
+
tapInternalKey: toXOnly(internalKey.publicKey as PublicKey),
|
|
121
121
|
});
|
|
122
122
|
psbt.addInput({ index: 0, hash: p2pkhUnspent.txId, nonWitnessUtxo });
|
|
123
123
|
|
|
124
124
|
const sendInternalKey = bip32.fromSeed(rng(64), regtest);
|
|
125
|
-
const sendPubKey = toXOnly(sendInternalKey.publicKey);
|
|
125
|
+
const sendPubKey = toXOnly(sendInternalKey.publicKey as PublicKey);
|
|
126
126
|
const { address: sendAddress } = bitcoin.payments.p2tr({
|
|
127
127
|
internalPubkey: sendPubKey,
|
|
128
128
|
network: regtest,
|
|
129
129
|
});
|
|
130
130
|
|
|
131
131
|
psbt.addOutput({
|
|
132
|
-
value: sendAmount,
|
|
132
|
+
value: BigInt(sendAmount) as Satoshi,
|
|
133
133
|
address: sendAddress!,
|
|
134
134
|
tapInternalKey: sendPubKey,
|
|
135
135
|
});
|
|
136
136
|
|
|
137
137
|
const tweakedSigner = internalKey.tweak(
|
|
138
|
-
bitcoin.crypto.taggedHash('TapTweak', toXOnly(internalKey.publicKey)),
|
|
138
|
+
bitcoin.crypto.taggedHash('TapTweak', toXOnly(internalKey.publicKey as PublicKey)),
|
|
139
139
|
);
|
|
140
140
|
await psbt.signInputAsync(0, tweakedSigner);
|
|
141
141
|
await psbt.signInputAsync(1, p2pkhKey);
|
|
142
142
|
|
|
143
143
|
psbt.finalizeAllInputs();
|
|
144
144
|
const tx = psbt.extractTransaction();
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
const hex = rawTx.toString('hex');
|
|
145
|
+
const hex = tx.toHex();
|
|
148
146
|
|
|
149
147
|
await regtestUtils.broadcast(hex);
|
|
150
148
|
await regtestUtils.verify({
|
|
@@ -159,7 +157,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
159
157
|
const internalKey = bip32.fromSeed(rng(64), regtest);
|
|
160
158
|
const leafKey = bip32.fromSeed(rng(64), regtest);
|
|
161
159
|
|
|
162
|
-
const leafScriptAsm = `${toXOnly(leafKey.publicKey)
|
|
160
|
+
const leafScriptAsm = `${toHex(toXOnly(leafKey.publicKey as PublicKey))} OP_CHECKSIG`;
|
|
163
161
|
const leafScript = bitcoin.script.fromASM(leafScriptAsm);
|
|
164
162
|
|
|
165
163
|
const scriptTree = {
|
|
@@ -167,7 +165,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
167
165
|
};
|
|
168
166
|
|
|
169
167
|
const { output, address, hash } = bitcoin.payments.p2tr({
|
|
170
|
-
internalPubkey: toXOnly(internalKey.publicKey),
|
|
168
|
+
internalPubkey: toXOnly(internalKey.publicKey as PublicKey),
|
|
171
169
|
scriptTree,
|
|
172
170
|
network: regtest,
|
|
173
171
|
});
|
|
@@ -177,31 +175,29 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
177
175
|
// amount to send
|
|
178
176
|
const sendAmount = amount - 1e4;
|
|
179
177
|
// get faucet
|
|
180
|
-
const unspent = await regtestUtils.faucetComplex(output
|
|
178
|
+
const unspent = await regtestUtils.faucetComplex(Buffer.from(output!), amount);
|
|
181
179
|
|
|
182
180
|
const psbt = new bitcoin.Psbt({ network: regtest });
|
|
183
181
|
psbt.addInput({
|
|
184
182
|
hash: unspent.txId,
|
|
185
183
|
index: 0,
|
|
186
|
-
witnessUtxo: { value: amount, script: output! },
|
|
187
|
-
tapInternalKey: toXOnly(internalKey.publicKey),
|
|
188
|
-
tapMerkleRoot: hash,
|
|
184
|
+
witnessUtxo: { value: BigInt(amount) as Satoshi, script: output! },
|
|
185
|
+
tapInternalKey: toXOnly(internalKey.publicKey as PublicKey),
|
|
186
|
+
...(hash ? { tapMerkleRoot: hash } : {}),
|
|
189
187
|
});
|
|
190
|
-
psbt.addOutput({ value: sendAmount, address: address! });
|
|
188
|
+
psbt.addOutput({ value: BigInt(sendAmount) as Satoshi, address: address! });
|
|
191
189
|
|
|
192
190
|
const tweakedSigner = internalKey.tweak(
|
|
193
191
|
bitcoin.crypto.taggedHash(
|
|
194
192
|
'TapTweak',
|
|
195
|
-
|
|
193
|
+
concat([toXOnly(internalKey.publicKey as PublicKey), hash!]),
|
|
196
194
|
),
|
|
197
195
|
);
|
|
198
196
|
psbt.signInput(0, tweakedSigner);
|
|
199
197
|
|
|
200
198
|
psbt.finalizeAllInputs();
|
|
201
199
|
const tx = psbt.extractTransaction();
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
const hex = rawTx.toString('hex');
|
|
200
|
+
const hex = tx.toHex();
|
|
205
201
|
|
|
206
202
|
await regtestUtils.broadcast(hex);
|
|
207
203
|
await regtestUtils.verify({
|
|
@@ -216,7 +212,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
216
212
|
const internalKey = bip32.fromSeed(rng(64), regtest);
|
|
217
213
|
const leafKey = bip32.fromSeed(rng(64), regtest);
|
|
218
214
|
|
|
219
|
-
const leafScriptAsm = `${toXOnly(leafKey.publicKey)
|
|
215
|
+
const leafScriptAsm = `${toHex(toXOnly(leafKey.publicKey as PublicKey))} OP_CHECKSIG`;
|
|
220
216
|
const leafScript = bitcoin.script.fromASM(leafScriptAsm);
|
|
221
217
|
|
|
222
218
|
const scriptTree: Taptree = [
|
|
@@ -270,7 +266,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
270
266
|
};
|
|
271
267
|
|
|
272
268
|
const { output, witness } = bitcoin.payments.p2tr({
|
|
273
|
-
internalPubkey: toXOnly(internalKey.publicKey),
|
|
269
|
+
internalPubkey: toXOnly(internalKey.publicKey as PublicKey),
|
|
274
270
|
scriptTree,
|
|
275
271
|
redeem,
|
|
276
272
|
network: regtest,
|
|
@@ -281,26 +277,26 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
281
277
|
// amount to send
|
|
282
278
|
const sendAmount = amount - 1e4;
|
|
283
279
|
// get faucet
|
|
284
|
-
const unspent = await regtestUtils.faucetComplex(output
|
|
280
|
+
const unspent = await regtestUtils.faucetComplex(Buffer.from(output!), amount);
|
|
285
281
|
|
|
286
282
|
const psbt = new bitcoin.Psbt({ network: regtest });
|
|
287
283
|
psbt.addInput({
|
|
288
284
|
hash: unspent.txId,
|
|
289
285
|
index: 0,
|
|
290
|
-
witnessUtxo: { value: amount, script: output! },
|
|
286
|
+
witnessUtxo: { value: BigInt(amount) as Satoshi, script: output! },
|
|
291
287
|
});
|
|
292
288
|
psbt.updateInput(0, {
|
|
293
289
|
tapLeafScript: [
|
|
294
290
|
{
|
|
295
291
|
leafVersion: redeem.redeemVersion,
|
|
296
292
|
script: redeem.output,
|
|
297
|
-
controlBlock: witness![witness!.length - 1]
|
|
293
|
+
controlBlock: witness![witness!.length - 1]!,
|
|
298
294
|
},
|
|
299
295
|
],
|
|
300
296
|
});
|
|
301
297
|
|
|
302
298
|
const sendInternalKey = bip32.fromSeed(rng(64), regtest);
|
|
303
|
-
const sendPubKey = toXOnly(sendInternalKey.publicKey);
|
|
299
|
+
const sendPubKey = toXOnly(sendInternalKey.publicKey as PublicKey);
|
|
304
300
|
const { address: sendAddress } = bitcoin.payments.p2tr({
|
|
305
301
|
internalPubkey: sendPubKey,
|
|
306
302
|
scriptTree,
|
|
@@ -308,7 +304,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
308
304
|
});
|
|
309
305
|
|
|
310
306
|
psbt.addOutput({
|
|
311
|
-
value: sendAmount,
|
|
307
|
+
value: BigInt(sendAmount) as Satoshi,
|
|
312
308
|
address: sendAddress!,
|
|
313
309
|
tapInternalKey: sendPubKey,
|
|
314
310
|
tapTree: { leaves: tapTreeToList(scriptTree) },
|
|
@@ -317,8 +313,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
317
313
|
psbt.signInput(0, leafKey);
|
|
318
314
|
psbt.finalizeInput(0);
|
|
319
315
|
const tx = psbt.extractTransaction();
|
|
320
|
-
const
|
|
321
|
-
const hex = rawTx.toString('hex');
|
|
316
|
+
const hex = tx.toHex();
|
|
322
317
|
|
|
323
318
|
await regtestUtils.broadcast(hex);
|
|
324
319
|
await regtestUtils.verify({
|
|
@@ -332,7 +327,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
332
327
|
it('can create (and broadcast via 3PBP) a taproot script-path spend Transaction - OP_CHECKSEQUENCEVERIFY', async () => {
|
|
333
328
|
const internalKey = bip32.fromSeed(rng(64), regtest);
|
|
334
329
|
const leafKey = bip32.fromSeed(rng(64), regtest);
|
|
335
|
-
const leafPubkey = toXOnly(leafKey.publicKey)
|
|
330
|
+
const leafPubkey = toHex(toXOnly(leafKey.publicKey as PublicKey));
|
|
336
331
|
|
|
337
332
|
const leafScriptAsm = `OP_10 OP_CHECKSEQUENCEVERIFY OP_DROP ${leafPubkey} OP_CHECKSIG`;
|
|
338
333
|
const leafScript = bitcoin.script.fromASM(leafScriptAsm);
|
|
@@ -360,7 +355,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
360
355
|
};
|
|
361
356
|
|
|
362
357
|
const { output, witness } = bitcoin.payments.p2tr({
|
|
363
|
-
internalPubkey: toXOnly(internalKey.publicKey),
|
|
358
|
+
internalPubkey: toXOnly(internalKey.publicKey as PublicKey),
|
|
364
359
|
scriptTree,
|
|
365
360
|
redeem,
|
|
366
361
|
network: regtest,
|
|
@@ -371,34 +366,34 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
371
366
|
// amount to send
|
|
372
367
|
const sendAmount = amount - 1e4;
|
|
373
368
|
// get faucet
|
|
374
|
-
const unspent = await regtestUtils.faucetComplex(output
|
|
369
|
+
const unspent = await regtestUtils.faucetComplex(Buffer.from(output!), amount);
|
|
375
370
|
|
|
376
371
|
const psbt = new bitcoin.Psbt({ network: regtest });
|
|
377
372
|
psbt.addInput({
|
|
378
373
|
hash: unspent.txId,
|
|
379
374
|
index: 0,
|
|
380
375
|
sequence: 10,
|
|
381
|
-
witnessUtxo: { value: amount, script: output! },
|
|
376
|
+
witnessUtxo: { value: BigInt(amount) as Satoshi, script: output! },
|
|
382
377
|
});
|
|
383
378
|
psbt.updateInput(0, {
|
|
384
379
|
tapLeafScript: [
|
|
385
380
|
{
|
|
386
381
|
leafVersion: redeem.redeemVersion,
|
|
387
382
|
script: redeem.output,
|
|
388
|
-
controlBlock: witness![witness!.length - 1]
|
|
383
|
+
controlBlock: witness![witness!.length - 1]!,
|
|
389
384
|
},
|
|
390
385
|
],
|
|
391
386
|
});
|
|
392
387
|
|
|
393
388
|
const sendInternalKey = bip32.fromSeed(rng(64), regtest);
|
|
394
|
-
const sendPubKey = toXOnly(sendInternalKey.publicKey);
|
|
389
|
+
const sendPubKey = toXOnly(sendInternalKey.publicKey as PublicKey);
|
|
395
390
|
const { address: sendAddress } = bitcoin.payments.p2tr({
|
|
396
391
|
internalPubkey: sendPubKey,
|
|
397
392
|
scriptTree,
|
|
398
393
|
network: regtest,
|
|
399
394
|
});
|
|
400
395
|
|
|
401
|
-
psbt.addOutput({ value: sendAmount, address: sendAddress! });
|
|
396
|
+
psbt.addOutput({ value: BigInt(sendAmount) as Satoshi, address: sendAddress! });
|
|
402
397
|
// just to test that updateOutput works as expected
|
|
403
398
|
psbt.updateOutput(0, {
|
|
404
399
|
tapInternalKey: sendPubKey,
|
|
@@ -409,8 +404,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
409
404
|
|
|
410
405
|
psbt.finalizeInput(0);
|
|
411
406
|
const tx = psbt.extractTransaction();
|
|
412
|
-
const
|
|
413
|
-
const hex = rawTx.toString('hex');
|
|
407
|
+
const hex = tx.toHex();
|
|
414
408
|
|
|
415
409
|
try {
|
|
416
410
|
// broadcast before the confirmation period has expired
|
|
@@ -440,7 +434,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
440
434
|
for (let i = 0; i < 3; i++) {
|
|
441
435
|
const leafKey = bip32.fromSeed(rng(64), regtest);
|
|
442
436
|
leafKeys.push(leafKey);
|
|
443
|
-
leafPubkeys.push(toXOnly(leafKey.publicKey)
|
|
437
|
+
leafPubkeys.push(toHex(toXOnly(leafKey.publicKey as PublicKey)));
|
|
444
438
|
}
|
|
445
439
|
|
|
446
440
|
const leafScriptAsm = `${leafPubkeys[2]} OP_CHECKSIG ${leafPubkeys[1]} OP_CHECKSIGADD ${leafPubkeys[0]} OP_CHECKSIGADD OP_3 OP_NUMEQUAL`;
|
|
@@ -470,7 +464,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
470
464
|
};
|
|
471
465
|
|
|
472
466
|
const { output, address, witness } = bitcoin.payments.p2tr({
|
|
473
|
-
internalPubkey: toXOnly(internalKey.publicKey),
|
|
467
|
+
internalPubkey: toXOnly(internalKey.publicKey as PublicKey),
|
|
474
468
|
scriptTree,
|
|
475
469
|
redeem,
|
|
476
470
|
network: regtest,
|
|
@@ -481,25 +475,25 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
481
475
|
// amount to send
|
|
482
476
|
const sendAmount = amount - 1e4;
|
|
483
477
|
// get faucet
|
|
484
|
-
const unspent = await regtestUtils.faucetComplex(output
|
|
478
|
+
const unspent = await regtestUtils.faucetComplex(Buffer.from(output!), amount);
|
|
485
479
|
|
|
486
480
|
const psbt = new bitcoin.Psbt({ network: regtest });
|
|
487
481
|
psbt.addInput({
|
|
488
482
|
hash: unspent.txId,
|
|
489
483
|
index: 0,
|
|
490
|
-
witnessUtxo: { value: amount, script: output! },
|
|
484
|
+
witnessUtxo: { value: BigInt(amount) as Satoshi, script: output! },
|
|
491
485
|
});
|
|
492
486
|
psbt.updateInput(0, {
|
|
493
487
|
tapLeafScript: [
|
|
494
488
|
{
|
|
495
489
|
leafVersion: redeem.redeemVersion,
|
|
496
490
|
script: redeem.output,
|
|
497
|
-
controlBlock: witness![witness!.length - 1]
|
|
491
|
+
controlBlock: witness![witness!.length - 1]!,
|
|
498
492
|
},
|
|
499
493
|
],
|
|
500
494
|
});
|
|
501
495
|
|
|
502
|
-
psbt.addOutput({ value: sendAmount, address: address! });
|
|
496
|
+
psbt.addOutput({ value: BigInt(sendAmount) as Satoshi, address: address! });
|
|
503
497
|
|
|
504
498
|
// random order for signers
|
|
505
499
|
psbt.signInput(0, leafKeys[1]);
|
|
@@ -508,8 +502,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
508
502
|
|
|
509
503
|
psbt.finalizeInput(0);
|
|
510
504
|
const tx = psbt.extractTransaction();
|
|
511
|
-
const
|
|
512
|
-
const hex = rawTx.toString('hex');
|
|
505
|
+
const hex = tx.toHex();
|
|
513
506
|
|
|
514
507
|
await regtestUtils.broadcast(hex);
|
|
515
508
|
await regtestUtils.verify({
|
|
@@ -540,7 +533,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
540
533
|
|
|
541
534
|
const internalKey = bip32.fromSeed(rng(64), regtest);
|
|
542
535
|
const { output, witness } = bitcoin.payments.p2tr({
|
|
543
|
-
internalPubkey: toXOnly(internalKey.publicKey),
|
|
536
|
+
internalPubkey: toXOnly(internalKey.publicKey as PublicKey),
|
|
544
537
|
scriptTree,
|
|
545
538
|
redeem,
|
|
546
539
|
network: regtest,
|
|
@@ -551,46 +544,46 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
551
544
|
// amount to send
|
|
552
545
|
const sendAmount = amount - 1e4;
|
|
553
546
|
// get faucet
|
|
554
|
-
const unspent = await regtestUtils.faucetComplex(output
|
|
547
|
+
const unspent = await regtestUtils.faucetComplex(Buffer.from(output!), amount);
|
|
555
548
|
|
|
556
549
|
const psbt = new bitcoin.Psbt({ network: regtest });
|
|
557
550
|
psbt.addInput({
|
|
558
551
|
hash: unspent.txId,
|
|
559
552
|
index: 0,
|
|
560
|
-
witnessUtxo: { value: amount, script: output! },
|
|
553
|
+
witnessUtxo: { value: BigInt(amount) as Satoshi, script: output! },
|
|
561
554
|
});
|
|
562
555
|
|
|
563
556
|
const tapLeafScript: TapLeafScript = {
|
|
564
557
|
leafVersion: redeem.redeemVersion,
|
|
565
558
|
script: redeem.output,
|
|
566
|
-
controlBlock: witness![witness!.length - 1]
|
|
559
|
+
controlBlock: witness![witness!.length - 1]!,
|
|
567
560
|
};
|
|
568
561
|
psbt.updateInput(0, { tapLeafScript: [tapLeafScript] });
|
|
569
562
|
|
|
570
563
|
const sendAddress = 'bcrt1pqknex3jwpsaatu5e5dcjw70nac3fr5k5y3hcxr4hgg6rljzp59nqs6a0vh';
|
|
571
564
|
psbt.addOutput({
|
|
572
|
-
value: sendAmount,
|
|
565
|
+
value: BigInt(sendAmount) as Satoshi,
|
|
573
566
|
address: sendAddress,
|
|
574
567
|
});
|
|
575
568
|
|
|
576
569
|
const leafIndexFinalizerFn = buildLeafIndexFinalizer(tapLeafScript, leafIndex);
|
|
577
570
|
psbt.finalizeInput(0, leafIndexFinalizerFn);
|
|
578
571
|
const tx = psbt.extractTransaction();
|
|
579
|
-
const
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
572
|
+
const hex = tx.toHex();
|
|
573
|
+
|
|
574
|
+
await broadcastAndVerify(hex, () =>
|
|
575
|
+
regtestUtils.verify({
|
|
576
|
+
txId: tx.getId(),
|
|
577
|
+
address: sendAddress!,
|
|
578
|
+
vout: 0,
|
|
579
|
+
value: sendAmount,
|
|
580
|
+
}),
|
|
581
|
+
);
|
|
589
582
|
}
|
|
590
583
|
});
|
|
591
584
|
|
|
592
585
|
it('should fail validating invalid signatures for taproot (See issue #1931)', () => {
|
|
593
|
-
const schnorrValidator = (pubkey:
|
|
586
|
+
const schnorrValidator = (pubkey: Uint8Array, msghash: Uint8Array, signature: Uint8Array) => {
|
|
594
587
|
return ecc.verifySchnorr(msghash, pubkey, signature);
|
|
595
588
|
};
|
|
596
589
|
|
|
@@ -614,7 +607,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
614
607
|
});
|
|
615
608
|
|
|
616
609
|
it('should succeed validating valid signatures for taproot (See issue #1934)', () => {
|
|
617
|
-
const schnorrValidator = (pubkey:
|
|
610
|
+
const schnorrValidator = (pubkey: Uint8Array, msghash: Uint8Array, signature: Uint8Array) => {
|
|
618
611
|
return ecc.verifySchnorr(msghash, pubkey, signature);
|
|
619
612
|
};
|
|
620
613
|
|
|
@@ -639,20 +632,20 @@ function buildLeafIndexFinalizer(
|
|
|
639
632
|
): (
|
|
640
633
|
inputIndex: number,
|
|
641
634
|
_input: PsbtInput,
|
|
642
|
-
_tapLeafHashToFinalize?:
|
|
635
|
+
_tapLeafHashToFinalize?: Uint8Array,
|
|
643
636
|
) => {
|
|
644
|
-
finalScriptWitness:
|
|
637
|
+
finalScriptWitness: Uint8Array | undefined;
|
|
645
638
|
} {
|
|
646
639
|
return (
|
|
647
640
|
inputIndex: number,
|
|
648
641
|
_input: PsbtInput,
|
|
649
|
-
_tapLeafHashToFinalize?:
|
|
642
|
+
_tapLeafHashToFinalize?: Uint8Array,
|
|
650
643
|
): {
|
|
651
|
-
finalScriptWitness:
|
|
644
|
+
finalScriptWitness: Uint8Array | undefined;
|
|
652
645
|
} => {
|
|
653
646
|
try {
|
|
654
|
-
const scriptSolution = [
|
|
655
|
-
const witness:
|
|
647
|
+
const scriptSolution = [new Uint8Array([leafIndex]), new Uint8Array([leafIndex])];
|
|
648
|
+
const witness: Uint8Array[] = [
|
|
656
649
|
...scriptSolution,
|
|
657
650
|
tapLeafScript.script,
|
|
658
651
|
tapLeafScript.controlBlock,
|