@btc-vision/bitcoin 6.5.6 → 7.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +57 -10
- 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 +12477 -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 +58 -11
- package/build/address.d.ts.map +1 -0
- package/build/address.js +82 -25
- 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 +202 -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 +35 -9
- package/build/payments/bip341.d.ts.map +1 -0
- package/build/payments/bip341.js +34 -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 -150
- 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 +428 -103
- 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 +465 -143
- 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 +117 -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 +406 -413
- 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 +101 -37
- 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 +169 -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 +68 -9
- package/scripts/bundle-ecc.ts +111 -0
- package/src/address.ts +91 -45
- package/src/bech32utils.ts +3 -3
- package/src/bip66.ts +34 -24
- package/src/block.ts +205 -86
- package/src/branded.ts +18 -0
- package/src/crypto.ts +64 -26
- package/src/ecc/context.ts +280 -0
- package/src/ecc/index.ts +14 -0
- package/src/ecc/types.ts +147 -0
- package/src/ecpair.d.ts +99 -0
- package/src/errors.ts +163 -0
- package/src/index.ts +112 -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 +32 -33
- package/src/payments/embed.ts +244 -41
- package/src/payments/index.ts +12 -10
- package/src/payments/p2ms.ts +497 -118
- package/src/payments/p2op.ts +432 -134
- package/src/payments/p2pk.ts +370 -72
- package/src/payments/p2pkh.ts +524 -130
- package/src/payments/p2sh.ts +572 -169
- package/src/payments/p2tr.ts +686 -194
- package/src/payments/p2wpkh.ts +482 -105
- package/src/payments/p2wsh.ts +524 -162
- package/src/payments/types.ts +80 -66
- package/src/psbt/bip371.ts +72 -51
- package/src/psbt/psbtutils.ts +39 -40
- package/src/psbt/types.ts +324 -0
- package/src/psbt/utils.ts +188 -0
- package/src/psbt/validation.ts +185 -0
- package/src/psbt.ts +608 -827
- package/src/pubkey.ts +22 -23
- package/src/push_data.ts +18 -16
- package/src/script.ts +81 -66
- package/src/script_number.ts +6 -6
- package/src/script_signature.ts +33 -36
- package/src/transaction.ts +462 -239
- package/src/types.ts +229 -100
- package/src/workers/WorkerSigningPool.node.ts +887 -0
- package/src/workers/WorkerSigningPool.ts +666 -0
- package/src/workers/ecc-bundle.ts +26 -0
- package/src/workers/index.ts +165 -0
- package/src/workers/psbt-parallel.ts +327 -0
- package/src/workers/signing-worker.ts +353 -0
- package/src/workers/types.ts +417 -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/typedoc.json +29 -0
- 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
package/test/psbt.spec.ts
CHANGED
|
@@ -3,14 +3,15 @@ import { BIP32Factory } from '@btc-vision/bip32';
|
|
|
3
3
|
import * as ecc from 'tiny-secp256k1';
|
|
4
4
|
import * as crypto from 'crypto';
|
|
5
5
|
import { ECPairFactory } from 'ecpair';
|
|
6
|
-
import { describe, it } from 'vitest';
|
|
6
|
+
import { beforeEach, describe, it } from 'vitest';
|
|
7
7
|
|
|
8
8
|
import { convertScriptTree } from './payments.utils.js';
|
|
9
9
|
import { LEAF_VERSION_TAPSCRIPT } from '../src/payments/bip341.js';
|
|
10
10
|
import { tapTreeFromList, tapTreeToList } from '../src/psbt/bip371.js';
|
|
11
|
-
import type { Taptree } from '../src/types.js';
|
|
11
|
+
import type { Taptree, Bytes32, Script, Satoshi, PublicKey, Signature, EccLib } from '../src/types.js';
|
|
12
12
|
import { initEccLib, networks as NETWORKS, payments, Psbt } from '../src/index.js';
|
|
13
|
-
import type { Signer, SignerAsync } from '../src/index.js';
|
|
13
|
+
import type { Signer, SignerAsync, HDSigner, HDSignerAsync, ValidateSigFunction } from '../src/index.js';
|
|
14
|
+
import { equals } from '../src/io/index.js';
|
|
14
15
|
|
|
15
16
|
import preFixtures from './fixtures/psbt.json' with { type: 'json' };
|
|
16
17
|
import taprootFixtures from './fixtures/p2tr.json' with { type: 'json' };
|
|
@@ -18,10 +19,10 @@ import taprootFixtures from './fixtures/p2tr.json' with { type: 'json' };
|
|
|
18
19
|
const bip32 = BIP32Factory(ecc);
|
|
19
20
|
const ECPair = ECPairFactory(ecc);
|
|
20
21
|
|
|
21
|
-
const validator = (pubkey
|
|
22
|
+
const validator: ValidateSigFunction = (pubkey, msghash, signature): boolean =>
|
|
22
23
|
ECPair.fromPublicKey(pubkey).verify(msghash, signature);
|
|
23
24
|
|
|
24
|
-
const schnorrValidator = (pubkey
|
|
25
|
+
const schnorrValidator: ValidateSigFunction = (pubkey, msghash, signature): boolean =>
|
|
25
26
|
ecc.verifySchnorr(msghash, pubkey, signature);
|
|
26
27
|
|
|
27
28
|
const initBuffers = (object: any): typeof preFixtures =>
|
|
@@ -43,7 +44,7 @@ const upperCaseFirstLetter = (str: string): string => str.replace(/^./, (s) => s
|
|
|
43
44
|
const toAsyncSigner = (signer: Signer): SignerAsync => {
|
|
44
45
|
return {
|
|
45
46
|
publicKey: signer.publicKey,
|
|
46
|
-
sign: (hash:
|
|
47
|
+
sign: (hash: Bytes32, lowerR: boolean | undefined): Promise<Signature> => {
|
|
47
48
|
return new Promise((resolve, rejects): void => {
|
|
48
49
|
setTimeout(() => {
|
|
49
50
|
try {
|
|
@@ -59,8 +60,8 @@ const toAsyncSigner = (signer: Signer): SignerAsync => {
|
|
|
59
60
|
};
|
|
60
61
|
const failedAsyncSigner = (publicKey: Buffer): SignerAsync => {
|
|
61
62
|
return <SignerAsync>{
|
|
62
|
-
publicKey,
|
|
63
|
-
sign: (__:
|
|
63
|
+
publicKey: publicKey as unknown as PublicKey,
|
|
64
|
+
sign: (__: Bytes32): Promise<Signature> => {
|
|
64
65
|
return new Promise((_, reject): void => {
|
|
65
66
|
setTimeout(() => {
|
|
66
67
|
reject(new Error('sign failed'));
|
|
@@ -110,8 +111,9 @@ describe(`Psbt`, () => {
|
|
|
110
111
|
psbt.addInput(input);
|
|
111
112
|
}
|
|
112
113
|
for (const output of f.outputs) {
|
|
113
|
-
const script = Buffer.from(output.script, 'hex');
|
|
114
|
-
|
|
114
|
+
const script = Buffer.from(output.script, 'hex') as unknown as Script;
|
|
115
|
+
const value = BigInt(output.value) as Satoshi;
|
|
116
|
+
psbt.addOutput({ ...output, script, value });
|
|
115
117
|
}
|
|
116
118
|
assert.strictEqual(psbt.toBase64(), f.result);
|
|
117
119
|
});
|
|
@@ -119,7 +121,7 @@ describe(`Psbt`, () => {
|
|
|
119
121
|
|
|
120
122
|
fixtures.bip174.updater.forEach((f) => {
|
|
121
123
|
it('Updates PSBT to the expected result', () => {
|
|
122
|
-
if (f.isTaproot) initEccLib(ecc);
|
|
124
|
+
if (f.isTaproot) initEccLib(ecc as unknown as EccLib);
|
|
123
125
|
const psbt = Psbt.fromBase64(f.psbt);
|
|
124
126
|
|
|
125
127
|
for (const inputOrOutput of ['input', 'output']) {
|
|
@@ -138,7 +140,7 @@ describe(`Psbt`, () => {
|
|
|
138
140
|
|
|
139
141
|
fixtures.bip174.signer.forEach((f) => {
|
|
140
142
|
it('Signs PSBT to the expected result', () => {
|
|
141
|
-
if (f.isTaproot) initEccLib(ecc);
|
|
143
|
+
if (f.isTaproot) initEccLib(ecc as unknown as EccLib);
|
|
142
144
|
const psbt = Psbt.fromBase64(f.psbt);
|
|
143
145
|
|
|
144
146
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -168,17 +170,17 @@ describe(`Psbt`, () => {
|
|
|
168
170
|
|
|
169
171
|
psbts[0].combine(psbts[1]);
|
|
170
172
|
|
|
171
|
-
// Produces a different Base64 string due to
|
|
173
|
+
// Produces a different Base64 string due to implementation specific key-value ordering.
|
|
172
174
|
// That means this test will fail:
|
|
173
175
|
// assert.strictEqual(psbts[0].toBase64(), f.result)
|
|
174
|
-
//
|
|
175
|
-
assert.
|
|
176
|
+
// Compare the serialized PSBT hex instead - this is deterministic
|
|
177
|
+
assert.strictEqual(psbts[0].toHex(), Psbt.fromBase64(f.result).toHex());
|
|
176
178
|
});
|
|
177
179
|
});
|
|
178
180
|
|
|
179
181
|
fixtures.bip174.finalizer.forEach((f) => {
|
|
180
182
|
it('Finalizes inputs and gives the expected PSBT', () => {
|
|
181
|
-
if (f.isTaproot) initEccLib(ecc);
|
|
183
|
+
if (f.isTaproot) initEccLib(ecc as unknown as EccLib);
|
|
182
184
|
const psbt = Psbt.fromBase64(f.psbt);
|
|
183
185
|
|
|
184
186
|
psbt.finalizeAllInputs();
|
|
@@ -228,7 +230,7 @@ describe(`Psbt`, () => {
|
|
|
228
230
|
describe('signInputAsync', () => {
|
|
229
231
|
fixtures.signInput.checks.forEach((f) => {
|
|
230
232
|
it(f.description, async () => {
|
|
231
|
-
if (f.isTaproot) initEccLib(ecc);
|
|
233
|
+
if (f.isTaproot) initEccLib(ecc as unknown as EccLib);
|
|
232
234
|
if (f.shouldSign) {
|
|
233
235
|
const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt);
|
|
234
236
|
await assert.doesNotReject(async () => {
|
|
@@ -289,7 +291,7 @@ describe(`Psbt`, () => {
|
|
|
289
291
|
describe('signInput', () => {
|
|
290
292
|
fixtures.signInput.checks.forEach((f) => {
|
|
291
293
|
it(f.description, () => {
|
|
292
|
-
if (f.isTaproot) initEccLib(ecc);
|
|
294
|
+
if (f.isTaproot) initEccLib(ecc as unknown as EccLib);
|
|
293
295
|
if (f.shouldSign) {
|
|
294
296
|
const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt);
|
|
295
297
|
assert.doesNotThrow(() => {
|
|
@@ -322,7 +324,7 @@ describe(`Psbt`, () => {
|
|
|
322
324
|
fixtures.signInput.checks.forEach((f) => {
|
|
323
325
|
if (f.description === 'checks the input exists') return;
|
|
324
326
|
it(f.description, async () => {
|
|
325
|
-
if (f.isTaproot) initEccLib(ecc);
|
|
327
|
+
if (f.isTaproot) initEccLib(ecc as unknown as EccLib);
|
|
326
328
|
if (f.shouldSign) {
|
|
327
329
|
const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt);
|
|
328
330
|
await assert.doesNotReject(async () => {
|
|
@@ -353,7 +355,7 @@ describe(`Psbt`, () => {
|
|
|
353
355
|
fixtures.signInput.checks.forEach((f) => {
|
|
354
356
|
if (f.description === 'checks the input exists') return;
|
|
355
357
|
it(f.description, () => {
|
|
356
|
-
if (f.isTaproot) initEccLib(ecc);
|
|
358
|
+
if (f.isTaproot) initEccLib(ecc as unknown as EccLib);
|
|
357
359
|
if (f.shouldSign) {
|
|
358
360
|
const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt);
|
|
359
361
|
assert.doesNotThrow(() => {
|
|
@@ -388,7 +390,7 @@ describe(`Psbt`, () => {
|
|
|
388
390
|
await assert.doesNotReject(async () => {
|
|
389
391
|
await psbtThatShouldsign.signInputHDAsync(
|
|
390
392
|
f.shouldSign.inputToCheck,
|
|
391
|
-
bip32.fromBase58(f.shouldSign.xprv),
|
|
393
|
+
bip32.fromBase58(f.shouldSign.xprv) as unknown as HDSigner,
|
|
392
394
|
(f.shouldSign as any).sighashTypes || undefined,
|
|
393
395
|
);
|
|
394
396
|
});
|
|
@@ -399,7 +401,7 @@ describe(`Psbt`, () => {
|
|
|
399
401
|
await assert.rejects(async () => {
|
|
400
402
|
await psbtThatShouldThrow.signInputHDAsync(
|
|
401
403
|
f.shouldThrow.inputToCheck,
|
|
402
|
-
bip32.fromBase58(f.shouldThrow.xprv),
|
|
404
|
+
bip32.fromBase58(f.shouldThrow.xprv) as unknown as HDSigner,
|
|
403
405
|
(f.shouldThrow as any).sighashTypes || undefined,
|
|
404
406
|
);
|
|
405
407
|
}, new RegExp(f.shouldThrow.errorMessage));
|
|
@@ -421,7 +423,7 @@ describe(`Psbt`, () => {
|
|
|
421
423
|
assert.doesNotThrow(() => {
|
|
422
424
|
psbtThatShouldsign.signInputHD(
|
|
423
425
|
f.shouldSign.inputToCheck,
|
|
424
|
-
bip32.fromBase58(f.shouldSign.xprv),
|
|
426
|
+
bip32.fromBase58(f.shouldSign.xprv) as unknown as HDSigner,
|
|
425
427
|
(f.shouldSign as any).sighashTypes || undefined,
|
|
426
428
|
);
|
|
427
429
|
});
|
|
@@ -432,7 +434,7 @@ describe(`Psbt`, () => {
|
|
|
432
434
|
assert.throws(() => {
|
|
433
435
|
psbtThatShouldThrow.signInputHD(
|
|
434
436
|
f.shouldThrow.inputToCheck,
|
|
435
|
-
bip32.fromBase58(f.shouldThrow.xprv),
|
|
437
|
+
bip32.fromBase58(f.shouldThrow.xprv) as unknown as HDSigner,
|
|
436
438
|
(f.shouldThrow as any).sighashTypes || undefined,
|
|
437
439
|
);
|
|
438
440
|
}, new RegExp(f.shouldThrow.errorMessage));
|
|
@@ -451,7 +453,7 @@ describe(`Psbt`, () => {
|
|
|
451
453
|
const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt);
|
|
452
454
|
await assert.doesNotReject(async () => {
|
|
453
455
|
await psbtThatShouldsign.signAllInputsHDAsync(
|
|
454
|
-
bip32.fromBase58(f.shouldSign.xprv),
|
|
456
|
+
bip32.fromBase58(f.shouldSign.xprv) as unknown as HDSigner,
|
|
455
457
|
(f.shouldSign as any).sighashTypes || undefined,
|
|
456
458
|
);
|
|
457
459
|
});
|
|
@@ -461,7 +463,7 @@ describe(`Psbt`, () => {
|
|
|
461
463
|
const psbtThatShouldThrow = Psbt.fromBase64(f.shouldThrow.psbt);
|
|
462
464
|
await assert.rejects(async () => {
|
|
463
465
|
await psbtThatShouldThrow.signAllInputsHDAsync(
|
|
464
|
-
bip32.fromBase58(f.shouldThrow.xprv),
|
|
466
|
+
bip32.fromBase58(f.shouldThrow.xprv) as unknown as HDSigner,
|
|
465
467
|
(f.shouldThrow as any).sighashTypes || undefined,
|
|
466
468
|
);
|
|
467
469
|
}, new RegExp('No inputs were signed'));
|
|
@@ -480,7 +482,7 @@ describe(`Psbt`, () => {
|
|
|
480
482
|
const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt);
|
|
481
483
|
assert.doesNotThrow(() => {
|
|
482
484
|
psbtThatShouldsign.signAllInputsHD(
|
|
483
|
-
bip32.fromBase58(f.shouldSign.xprv),
|
|
485
|
+
bip32.fromBase58(f.shouldSign.xprv) as unknown as HDSigner,
|
|
484
486
|
(f.shouldSign as any).sighashTypes || undefined,
|
|
485
487
|
);
|
|
486
488
|
});
|
|
@@ -490,7 +492,7 @@ describe(`Psbt`, () => {
|
|
|
490
492
|
const psbtThatShouldThrow = Psbt.fromBase64(f.shouldThrow.psbt);
|
|
491
493
|
assert.throws(() => {
|
|
492
494
|
psbtThatShouldThrow.signAllInputsHD(
|
|
493
|
-
bip32.fromBase58(f.shouldThrow.xprv),
|
|
495
|
+
bip32.fromBase58(f.shouldThrow.xprv) as unknown as HDSigner,
|
|
494
496
|
(f.shouldThrow as any).sighashTypes || undefined,
|
|
495
497
|
);
|
|
496
498
|
}, new RegExp('No inputs were signed'));
|
|
@@ -507,7 +509,7 @@ describe(`Psbt`, () => {
|
|
|
507
509
|
const f = fixtures.finalizeInput.finalizeTapleafByHash;
|
|
508
510
|
const psbt = Psbt.fromBase64(f.psbt);
|
|
509
511
|
|
|
510
|
-
psbt.finalizeTaprootInput(f.index, Buffer.from(f.leafHash, 'hex'));
|
|
512
|
+
psbt.finalizeTaprootInput(f.index, Buffer.from(f.leafHash, 'hex') as unknown as Bytes32);
|
|
511
513
|
|
|
512
514
|
assert.strictEqual(psbt.toBase64(), f.result);
|
|
513
515
|
});
|
|
@@ -517,7 +519,7 @@ describe(`Psbt`, () => {
|
|
|
517
519
|
const psbt = Psbt.fromBase64(f.psbt);
|
|
518
520
|
|
|
519
521
|
assert.throws(() => {
|
|
520
|
-
psbt.finalizeTaprootInput(f.index, Buffer.from(f.leafHash, 'hex').reverse());
|
|
522
|
+
psbt.finalizeTaprootInput(f.index, Buffer.from(f.leafHash, 'hex').reverse() as unknown as Bytes32);
|
|
521
523
|
}, new RegExp('Can not finalize taproot input #0. Signature for tapleaf script not found.'));
|
|
522
524
|
});
|
|
523
525
|
|
|
@@ -555,8 +557,8 @@ describe(`Psbt`, () => {
|
|
|
555
557
|
}, new RegExp('No script found for input #0'));
|
|
556
558
|
psbt.updateInput(0, {
|
|
557
559
|
witnessUtxo: {
|
|
558
|
-
script: Buffer.from('0014d85c2b71d0060b09c9886aeb815e50991dda124d', 'hex'),
|
|
559
|
-
value:
|
|
560
|
+
script: Buffer.from('0014d85c2b71d0060b09c9886aeb815e50991dda124d', 'hex') as unknown as Script,
|
|
561
|
+
value: 200000n as Satoshi,
|
|
560
562
|
},
|
|
561
563
|
});
|
|
562
564
|
assert.throws(() => {
|
|
@@ -609,9 +611,15 @@ describe(`Psbt`, () => {
|
|
|
609
611
|
describe('addOutput', () => {
|
|
610
612
|
fixtures.addOutput.checks.forEach((f) => {
|
|
611
613
|
it(f.description, () => {
|
|
612
|
-
if (f.isTaproot) initEccLib(ecc);
|
|
614
|
+
if (f.isTaproot) initEccLib(ecc as unknown as EccLib);
|
|
613
615
|
const psbt = f.psbt ? Psbt.fromBase64(f.psbt) : new Psbt();
|
|
614
616
|
|
|
617
|
+
// Convert numeric value to bigint for valid outputs
|
|
618
|
+
const outputData =
|
|
619
|
+
f.outputData && typeof f.outputData.value === 'number'
|
|
620
|
+
? { ...f.outputData, value: BigInt(f.outputData.value) }
|
|
621
|
+
: f.outputData;
|
|
622
|
+
|
|
615
623
|
if (f.exception) {
|
|
616
624
|
assert.throws(() => {
|
|
617
625
|
psbt.addOutput(f.outputData as any);
|
|
@@ -621,13 +629,13 @@ describe(`Psbt`, () => {
|
|
|
621
629
|
}, new RegExp(f.exception));
|
|
622
630
|
} else {
|
|
623
631
|
assert.doesNotThrow(() => {
|
|
624
|
-
psbt.addOutput(
|
|
632
|
+
psbt.addOutput(outputData as any);
|
|
625
633
|
});
|
|
626
634
|
if (f.result) {
|
|
627
635
|
assert.strictEqual(psbt.toBase64(), f.result);
|
|
628
636
|
}
|
|
629
637
|
assert.doesNotThrow(() => {
|
|
630
|
-
psbt.addOutputs([
|
|
638
|
+
psbt.addOutputs([outputData as any]);
|
|
631
639
|
});
|
|
632
640
|
}
|
|
633
641
|
});
|
|
@@ -684,24 +692,24 @@ describe(`Psbt`, () => {
|
|
|
684
692
|
describe('getInputType', () => {
|
|
685
693
|
const key = ECPair.makeRandom();
|
|
686
694
|
const { publicKey } = key;
|
|
687
|
-
const p2wpkhPub = (pubkey: Buffer):
|
|
695
|
+
const p2wpkhPub = (pubkey: Buffer): Script =>
|
|
688
696
|
payments.p2wpkh({
|
|
689
|
-
pubkey,
|
|
697
|
+
pubkey: pubkey as unknown as PublicKey,
|
|
690
698
|
}).output!;
|
|
691
|
-
const p2pkhPub = (pubkey: Buffer):
|
|
699
|
+
const p2pkhPub = (pubkey: Buffer): Script =>
|
|
692
700
|
payments.p2pkh({
|
|
693
|
-
pubkey,
|
|
701
|
+
pubkey: pubkey as unknown as PublicKey,
|
|
694
702
|
}).output!;
|
|
695
|
-
const p2shOut = (output:
|
|
703
|
+
const p2shOut = (output: Uint8Array): Script =>
|
|
696
704
|
payments.p2sh({
|
|
697
|
-
redeem: { output },
|
|
705
|
+
redeem: { output: output as Script },
|
|
698
706
|
}).output!;
|
|
699
|
-
const p2wshOut = (output:
|
|
707
|
+
const p2wshOut = (output: Uint8Array): Script =>
|
|
700
708
|
payments.p2wsh({
|
|
701
|
-
redeem: { output },
|
|
709
|
+
redeem: { output: output as Script },
|
|
702
710
|
}).output!;
|
|
703
|
-
const p2shp2wshOut = (output:
|
|
704
|
-
const noOuter = (output:
|
|
711
|
+
const p2shp2wshOut = (output: Uint8Array): Script => p2shOut(p2wshOut(output));
|
|
712
|
+
const noOuter = (output: Uint8Array): Script => output as Script;
|
|
705
713
|
|
|
706
714
|
function getInputTypeTest({
|
|
707
715
|
innerScript,
|
|
@@ -717,13 +725,13 @@ describe(`Psbt`, () => {
|
|
|
717
725
|
index: 0,
|
|
718
726
|
witnessUtxo: {
|
|
719
727
|
script: outerScript(innerScript(publicKey)),
|
|
720
|
-
value:
|
|
728
|
+
value: 2000n,
|
|
721
729
|
},
|
|
722
730
|
...(redeemGetter ? { redeemScript: redeemGetter(publicKey) } : {}),
|
|
723
731
|
...(witnessGetter ? { witnessScript: witnessGetter(publicKey) } : {}),
|
|
724
732
|
}).addOutput({
|
|
725
|
-
script: Buffer.from('0014d85c2b71d0060b09c9886aeb815e50991dda124d'),
|
|
726
|
-
value:
|
|
733
|
+
script: Buffer.from('0014d85c2b71d0060b09c9886aeb815e50991dda124d', 'hex') as unknown as Script,
|
|
734
|
+
value: 1800n as Satoshi,
|
|
727
735
|
});
|
|
728
736
|
if (finalize) psbt.signInput(0, key).finalizeInput(0);
|
|
729
737
|
const type = psbt.getInputType(0);
|
|
@@ -771,7 +779,7 @@ describe(`Psbt`, () => {
|
|
|
771
779
|
{
|
|
772
780
|
innerScript: p2pkhPub,
|
|
773
781
|
outerScript: p2shp2wshOut,
|
|
774
|
-
redeemGetter: (pk: Buffer):
|
|
782
|
+
redeemGetter: (pk: Buffer): Script => p2wshOut(p2pkhPub(pk)),
|
|
775
783
|
witnessGetter: p2pkhPub,
|
|
776
784
|
expectedType: 'p2sh-p2wsh-pubkeyhash',
|
|
777
785
|
},
|
|
@@ -800,8 +808,8 @@ describe(`Psbt`, () => {
|
|
|
800
808
|
},
|
|
801
809
|
],
|
|
802
810
|
});
|
|
803
|
-
assert.strictEqual(psbt.inputHasHDKey(0, root), true);
|
|
804
|
-
assert.strictEqual(psbt.inputHasHDKey(0, root2), false);
|
|
811
|
+
assert.strictEqual(psbt.inputHasHDKey(0, root as unknown as HDSigner), true);
|
|
812
|
+
assert.strictEqual(psbt.inputHasHDKey(0, root2 as unknown as HDSigner), false);
|
|
805
813
|
});
|
|
806
814
|
});
|
|
807
815
|
|
|
@@ -822,9 +830,9 @@ describe(`Psbt`, () => {
|
|
|
822
830
|
|
|
823
831
|
psbt.updateInput(0, {
|
|
824
832
|
witnessUtxo: {
|
|
825
|
-
value:
|
|
833
|
+
value: 1337n as Satoshi,
|
|
826
834
|
script: payments.p2sh({
|
|
827
|
-
redeem: { output: Buffer.from([0x51]) },
|
|
835
|
+
redeem: { output: Buffer.from([0x51]) as unknown as Script },
|
|
828
836
|
}).output!,
|
|
829
837
|
},
|
|
830
838
|
});
|
|
@@ -837,9 +845,9 @@ describe(`Psbt`, () => {
|
|
|
837
845
|
|
|
838
846
|
psbt.updateInput(0, {
|
|
839
847
|
witnessUtxo: {
|
|
840
|
-
value:
|
|
848
|
+
value: 1337n as Satoshi,
|
|
841
849
|
script: payments.p2wsh({
|
|
842
|
-
redeem: { output: Buffer.from([0x51]) },
|
|
850
|
+
redeem: { output: Buffer.from([0x51]) as unknown as Script },
|
|
843
851
|
}).output!,
|
|
844
852
|
},
|
|
845
853
|
});
|
|
@@ -859,15 +867,15 @@ describe(`Psbt`, () => {
|
|
|
859
867
|
|
|
860
868
|
psbt.updateInput(0, {
|
|
861
869
|
witnessUtxo: {
|
|
862
|
-
value:
|
|
870
|
+
value: 1337n as Satoshi,
|
|
863
871
|
script: payments.p2sh({
|
|
864
872
|
redeem: payments.p2wsh({
|
|
865
|
-
redeem: { output: scriptWithPubkey },
|
|
873
|
+
redeem: { output: scriptWithPubkey as unknown as Script },
|
|
866
874
|
}),
|
|
867
875
|
}).output!,
|
|
868
876
|
},
|
|
869
877
|
redeemScript: payments.p2wsh({
|
|
870
|
-
redeem: { output: scriptWithPubkey },
|
|
878
|
+
redeem: { output: scriptWithPubkey as unknown as Script },
|
|
871
879
|
}).output!,
|
|
872
880
|
});
|
|
873
881
|
|
|
@@ -896,8 +904,8 @@ describe(`Psbt`, () => {
|
|
|
896
904
|
hash: '0000000000000000000000000000000000000000000000000000000000000000',
|
|
897
905
|
index: 0,
|
|
898
906
|
}).addOutput({
|
|
899
|
-
script: Buffer.from('0014000102030405060708090a0b0c0d0e0f00010203', 'hex'),
|
|
900
|
-
value:
|
|
907
|
+
script: Buffer.from('0014000102030405060708090a0b0c0d0e0f00010203', 'hex') as unknown as Script,
|
|
908
|
+
value: 2000n as Satoshi,
|
|
901
909
|
bip32Derivation: [
|
|
902
910
|
{
|
|
903
911
|
masterFingerprint: Buffer.from(root.fingerprint),
|
|
@@ -906,8 +914,8 @@ describe(`Psbt`, () => {
|
|
|
906
914
|
},
|
|
907
915
|
],
|
|
908
916
|
});
|
|
909
|
-
assert.strictEqual(psbt.outputHasHDKey(0, root), true);
|
|
910
|
-
assert.strictEqual(psbt.outputHasHDKey(0, root2), false);
|
|
917
|
+
assert.strictEqual(psbt.outputHasHDKey(0, root as unknown as HDSigner), true);
|
|
918
|
+
assert.strictEqual(psbt.outputHasHDKey(0, root2 as unknown as HDSigner), false);
|
|
911
919
|
});
|
|
912
920
|
});
|
|
913
921
|
|
|
@@ -928,32 +936,32 @@ describe(`Psbt`, () => {
|
|
|
928
936
|
index: 0,
|
|
929
937
|
}).addOutput({
|
|
930
938
|
script: payments.p2sh({
|
|
931
|
-
redeem: { output: Buffer.from([0x51]) },
|
|
939
|
+
redeem: { output: Buffer.from([0x51]) as unknown as Script },
|
|
932
940
|
}).output!,
|
|
933
|
-
value:
|
|
941
|
+
value: 1337n as Satoshi,
|
|
934
942
|
});
|
|
935
943
|
|
|
936
944
|
assert.throws(() => {
|
|
937
945
|
psbt.outputHasPubkey(0, testPubkey);
|
|
938
946
|
}, new RegExp('scriptPubkey is P2SH but redeemScript missing'));
|
|
939
947
|
|
|
940
|
-
(psbt as any).__CACHE.
|
|
941
|
-
redeem: { output: Buffer.from([0x51]) },
|
|
948
|
+
(psbt as any).__CACHE.tx.outs[0].script = payments.p2wsh({
|
|
949
|
+
redeem: { output: Buffer.from([0x51]) as unknown as Script },
|
|
942
950
|
}).output!;
|
|
943
951
|
|
|
944
952
|
assert.throws(() => {
|
|
945
953
|
psbt.outputHasPubkey(0, testPubkey);
|
|
946
954
|
}, new RegExp('scriptPubkey or redeemScript is P2WSH but witnessScript missing'));
|
|
947
955
|
|
|
948
|
-
(psbt as any).__CACHE.
|
|
956
|
+
(psbt as any).__CACHE.tx.outs[0].script = payments.p2sh({
|
|
949
957
|
redeem: payments.p2wsh({
|
|
950
|
-
redeem: { output: scriptWithPubkey },
|
|
958
|
+
redeem: { output: scriptWithPubkey as unknown as Script },
|
|
951
959
|
}),
|
|
952
960
|
}).output!;
|
|
953
961
|
|
|
954
962
|
psbt.updateOutput(0, {
|
|
955
963
|
redeemScript: payments.p2wsh({
|
|
956
|
-
redeem: { output: scriptWithPubkey },
|
|
964
|
+
redeem: { output: scriptWithPubkey as unknown as Script },
|
|
957
965
|
}).output!,
|
|
958
966
|
});
|
|
959
967
|
|
|
@@ -973,7 +981,7 @@ describe(`Psbt`, () => {
|
|
|
973
981
|
|
|
974
982
|
psbt.updateOutput(0, {
|
|
975
983
|
redeemScript: payments.p2wsh({
|
|
976
|
-
redeem: { output: scriptWithPubkey },
|
|
984
|
+
redeem: { output: scriptWithPubkey as unknown as Script },
|
|
977
985
|
}).output!,
|
|
978
986
|
});
|
|
979
987
|
|
|
@@ -995,7 +1003,7 @@ describe(`Psbt`, () => {
|
|
|
995
1003
|
assert.strictEqual(clone.toBase64(), psbt.toBase64());
|
|
996
1004
|
assert.strictEqual(clone.toBase64(), notAClone.toBase64());
|
|
997
1005
|
assert.strictEqual(psbt.toBase64(), notAClone.toBase64());
|
|
998
|
-
(psbt as any).__CACHE.
|
|
1006
|
+
(psbt as any).__CACHE.tx.version |= 0xff0000;
|
|
999
1007
|
assert.notStrictEqual(clone.toBase64(), psbt.toBase64());
|
|
1000
1008
|
assert.notStrictEqual(clone.toBase64(), notAClone.toBase64());
|
|
1001
1009
|
assert.strictEqual(psbt.toBase64(), notAClone.toBase64());
|
|
@@ -1038,13 +1046,13 @@ describe(`Psbt`, () => {
|
|
|
1038
1046
|
describe('validateSignaturesOfTapKeyInput', () => {
|
|
1039
1047
|
const f = fixtures.validateSignaturesOfTapKeyInput;
|
|
1040
1048
|
it('Correctly validates all signatures', () => {
|
|
1041
|
-
initEccLib(ecc);
|
|
1049
|
+
initEccLib(ecc as unknown as EccLib);
|
|
1042
1050
|
const psbt = Psbt.fromBase64(f.psbt);
|
|
1043
1051
|
assert.strictEqual(psbt.validateSignaturesOfInput(f.index, schnorrValidator), true);
|
|
1044
1052
|
});
|
|
1045
1053
|
|
|
1046
1054
|
it('Correctly validates a signature against a pubkey', () => {
|
|
1047
|
-
initEccLib(ecc);
|
|
1055
|
+
initEccLib(ecc as unknown as EccLib);
|
|
1048
1056
|
const psbt = Psbt.fromBase64(f.psbt);
|
|
1049
1057
|
assert.strictEqual(
|
|
1050
1058
|
psbt.validateSignaturesOfInput(f.index, schnorrValidator, f.pubkey as any),
|
|
@@ -1059,13 +1067,13 @@ describe(`Psbt`, () => {
|
|
|
1059
1067
|
describe('validateSignaturesOfTapScriptInput', () => {
|
|
1060
1068
|
const f = fixtures.validateSignaturesOfTapScriptInput;
|
|
1061
1069
|
it('Correctly validates all signatures', () => {
|
|
1062
|
-
initEccLib(ecc);
|
|
1070
|
+
initEccLib(ecc as unknown as EccLib);
|
|
1063
1071
|
const psbt = Psbt.fromBase64(f.psbt);
|
|
1064
1072
|
assert.strictEqual(psbt.validateSignaturesOfInput(f.index, schnorrValidator), true);
|
|
1065
1073
|
});
|
|
1066
1074
|
|
|
1067
1075
|
it('Correctly validates a signature against a pubkey', () => {
|
|
1068
|
-
initEccLib(ecc);
|
|
1076
|
+
initEccLib(ecc as unknown as EccLib);
|
|
1069
1077
|
const psbt = Psbt.fromBase64(f.psbt);
|
|
1070
1078
|
assert.strictEqual(
|
|
1071
1079
|
psbt.validateSignaturesOfInput(f.index, schnorrValidator, f.pubkey as any),
|
|
@@ -1129,7 +1137,7 @@ describe(`Psbt`, () => {
|
|
|
1129
1137
|
}));
|
|
1130
1138
|
|
|
1131
1139
|
assert.throws(() => {
|
|
1132
|
-
tapTreeToList(tree as Taptree);
|
|
1140
|
+
tapTreeToList(tree as unknown as Taptree);
|
|
1133
1141
|
}, new RegExp('Cannot convert taptree to tapleaf list. Expecting a tapree structure.'));
|
|
1134
1142
|
});
|
|
1135
1143
|
});
|
|
@@ -1146,7 +1154,7 @@ describe(`Psbt`, () => {
|
|
|
1146
1154
|
psbt.finalizeAllInputs();
|
|
1147
1155
|
|
|
1148
1156
|
assert.strictEqual(psbt.getFeeRate(), f.fee);
|
|
1149
|
-
(psbt as any).__CACHE.
|
|
1157
|
+
(psbt as any).__CACHE.feeRate = undefined;
|
|
1150
1158
|
assert.strictEqual(psbt.getFeeRate(), f.fee);
|
|
1151
1159
|
});
|
|
1152
1160
|
});
|
|
@@ -1171,7 +1179,7 @@ describe(`Psbt`, () => {
|
|
|
1171
1179
|
});
|
|
1172
1180
|
psbt.addOutput({
|
|
1173
1181
|
address: '1KRMKfeZcmosxALVYESdPNez1AP1mEtywp',
|
|
1174
|
-
value:
|
|
1182
|
+
value: 80000n as Satoshi,
|
|
1175
1183
|
});
|
|
1176
1184
|
psbt.signInput(0, alice);
|
|
1177
1185
|
assert.throws(() => {
|
|
@@ -1205,17 +1213,17 @@ describe(`Psbt`, () => {
|
|
|
1205
1213
|
),
|
|
1206
1214
|
);
|
|
1207
1215
|
assert.strictEqual(psbt instanceof Psbt, true);
|
|
1208
|
-
assert.ok((psbt as any).__CACHE.
|
|
1216
|
+
assert.ok((psbt as any).__CACHE.tx);
|
|
1209
1217
|
});
|
|
1210
1218
|
it('fromBase64 returns Psbt type (not base class)', () => {
|
|
1211
1219
|
const psbt = Psbt.fromBase64('cHNidP8BAAoBAAAAAAAAAAAAAAAA');
|
|
1212
1220
|
assert.strictEqual(psbt instanceof Psbt, true);
|
|
1213
|
-
assert.ok((psbt as any).__CACHE.
|
|
1221
|
+
assert.ok((psbt as any).__CACHE.tx);
|
|
1214
1222
|
});
|
|
1215
1223
|
it('fromHex returns Psbt type (not base class)', () => {
|
|
1216
1224
|
const psbt = Psbt.fromHex('70736274ff01000a01000000000000000000000000');
|
|
1217
1225
|
assert.strictEqual(psbt instanceof Psbt, true);
|
|
1218
|
-
assert.ok((psbt as any).__CACHE.
|
|
1226
|
+
assert.ok((psbt as any).__CACHE.tx);
|
|
1219
1227
|
});
|
|
1220
1228
|
});
|
|
1221
1229
|
|
|
@@ -1227,7 +1235,7 @@ describe(`Psbt`, () => {
|
|
|
1227
1235
|
|
|
1228
1236
|
// Cache is empty
|
|
1229
1237
|
assert.strictEqual(
|
|
1230
|
-
(psbt as any).__CACHE.
|
|
1238
|
+
(psbt as any).__CACHE.nonWitnessUtxoBufCache[index],
|
|
1231
1239
|
undefined,
|
|
1232
1240
|
);
|
|
1233
1241
|
|
|
@@ -1236,15 +1244,18 @@ describe(`Psbt`, () => {
|
|
|
1236
1244
|
nonWitnessUtxo: f.nonWitnessUtxo as any,
|
|
1237
1245
|
});
|
|
1238
1246
|
const value = psbt.data.inputs[index].nonWitnessUtxo;
|
|
1239
|
-
assert.ok((psbt as any).__CACHE.
|
|
1247
|
+
assert.ok(equals((psbt as any).__CACHE.nonWitnessUtxoBufCache[index], value));
|
|
1240
1248
|
assert.ok(
|
|
1241
|
-
|
|
1249
|
+
equals(
|
|
1250
|
+
(psbt as any).__CACHE.nonWitnessUtxoBufCache[index],
|
|
1251
|
+
f.nonWitnessUtxo as any,
|
|
1252
|
+
),
|
|
1242
1253
|
);
|
|
1243
1254
|
|
|
1244
1255
|
// Cache is rebuilt from internal transaction object when cleared
|
|
1245
|
-
psbt.data.inputs[index].nonWitnessUtxo =
|
|
1246
|
-
(psbt as any).__CACHE.
|
|
1247
|
-
assert.ok((psbt as any).data.inputs[index].nonWitnessUtxo
|
|
1256
|
+
psbt.data.inputs[index].nonWitnessUtxo = new Uint8Array([1, 2, 3]);
|
|
1257
|
+
(psbt as any).__CACHE.nonWitnessUtxoBufCache[index] = undefined;
|
|
1258
|
+
assert.ok(equals((psbt as any).data.inputs[index].nonWitnessUtxo!, value!));
|
|
1248
1259
|
});
|
|
1249
1260
|
});
|
|
1250
1261
|
|
|
@@ -1253,34 +1264,34 @@ describe(`Psbt`, () => {
|
|
|
1253
1264
|
const psbt = new Psbt();
|
|
1254
1265
|
|
|
1255
1266
|
assert.strictEqual(psbt.version, 2);
|
|
1256
|
-
assert.strictEqual(psbt.version, (psbt as any).__CACHE.
|
|
1267
|
+
assert.strictEqual(psbt.version, (psbt as any).__CACHE.tx.version);
|
|
1257
1268
|
|
|
1258
1269
|
psbt.version = 1;
|
|
1259
1270
|
assert.strictEqual(psbt.version, 1);
|
|
1260
|
-
assert.strictEqual(psbt.version, (psbt as any).__CACHE.
|
|
1271
|
+
assert.strictEqual(psbt.version, (psbt as any).__CACHE.tx.version);
|
|
1261
1272
|
});
|
|
1262
1273
|
|
|
1263
1274
|
it('.locktime is exposed and is settable', () => {
|
|
1264
1275
|
const psbt = new Psbt();
|
|
1265
1276
|
|
|
1266
1277
|
assert.strictEqual(psbt.locktime, 0);
|
|
1267
|
-
assert.strictEqual(psbt.locktime, (psbt as any).__CACHE.
|
|
1278
|
+
assert.strictEqual(psbt.locktime, (psbt as any).__CACHE.tx.locktime);
|
|
1268
1279
|
|
|
1269
1280
|
psbt.locktime = 123;
|
|
1270
1281
|
assert.strictEqual(psbt.locktime, 123);
|
|
1271
|
-
assert.strictEqual(psbt.locktime, (psbt as any).__CACHE.
|
|
1282
|
+
assert.strictEqual(psbt.locktime, (psbt as any).__CACHE.tx.locktime);
|
|
1272
1283
|
});
|
|
1273
1284
|
|
|
1274
1285
|
it('.txInputs is exposed as a readonly clone', () => {
|
|
1275
1286
|
const psbt = new Psbt();
|
|
1276
|
-
const hash = Buffer.alloc(32);
|
|
1287
|
+
const hash = Buffer.alloc(32) as unknown as Bytes32;
|
|
1277
1288
|
const index = 0;
|
|
1278
1289
|
psbt.addInput({ hash, index });
|
|
1279
1290
|
|
|
1280
1291
|
const input = psbt.txInputs[0];
|
|
1281
|
-
const internalInput = (psbt as any).__CACHE.
|
|
1292
|
+
const internalInput = (psbt as any).__CACHE.tx.ins[0];
|
|
1282
1293
|
|
|
1283
|
-
assert.ok(input.hash
|
|
1294
|
+
assert.ok(equals(input.hash, internalInput.hash));
|
|
1284
1295
|
assert.strictEqual(input.index, internalInput.index);
|
|
1285
1296
|
assert.strictEqual(input.sequence, internalInput.sequence);
|
|
1286
1297
|
|
|
@@ -1288,7 +1299,7 @@ describe(`Psbt`, () => {
|
|
|
1288
1299
|
input.index = 123;
|
|
1289
1300
|
input.sequence = 123;
|
|
1290
1301
|
|
|
1291
|
-
assert.ok(!input.hash
|
|
1302
|
+
assert.ok(!equals(input.hash, internalInput.hash));
|
|
1292
1303
|
assert.notEqual(input.index, internalInput.index);
|
|
1293
1304
|
assert.notEqual(input.sequence, internalInput.sequence);
|
|
1294
1305
|
});
|
|
@@ -1296,21 +1307,21 @@ describe(`Psbt`, () => {
|
|
|
1296
1307
|
it('.txOutputs is exposed as a readonly clone', () => {
|
|
1297
1308
|
const psbt = new Psbt();
|
|
1298
1309
|
const address = '1LukeQU5jwebXbMLDVydeH4vFSobRV9rkj';
|
|
1299
|
-
const value =
|
|
1310
|
+
const value = 100000n as Satoshi;
|
|
1300
1311
|
psbt.addOutput({ address, value });
|
|
1301
1312
|
|
|
1302
1313
|
const output = psbt.txOutputs[0];
|
|
1303
|
-
const internalInput = (psbt as any).__CACHE.
|
|
1314
|
+
const internalInput = (psbt as any).__CACHE.tx.outs[0];
|
|
1304
1315
|
|
|
1305
1316
|
assert.strictEqual(output.address, address);
|
|
1306
1317
|
|
|
1307
|
-
assert.ok(output.script
|
|
1318
|
+
assert.ok(equals(output.script, internalInput.script));
|
|
1308
1319
|
assert.strictEqual(output.value, internalInput.value);
|
|
1309
1320
|
|
|
1310
1321
|
output.script[0] = 123;
|
|
1311
|
-
output.value =
|
|
1322
|
+
output.value = 123n;
|
|
1312
1323
|
|
|
1313
|
-
assert.ok(!output.script
|
|
1324
|
+
assert.ok(!equals(output.script, internalInput.script));
|
|
1314
1325
|
assert.notEqual(output.value, internalInput.value);
|
|
1315
1326
|
});
|
|
1316
1327
|
});
|