@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
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker thread types for parallel signing operations.
|
|
3
|
+
*
|
|
4
|
+
* SECURITY NOTES:
|
|
5
|
+
* - Private keys are NEVER shared via SharedArrayBuffer
|
|
6
|
+
* - Keys are cloned via postMessage (isolated per worker)
|
|
7
|
+
* - Keys are zeroed immediately after signing
|
|
8
|
+
* - Workers are pooled for performance but keys don't persist
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Signature type enum for worker operations.
|
|
15
|
+
*/
|
|
16
|
+
export const SignatureType = {
|
|
17
|
+
/** ECDSA signature (secp256k1) */
|
|
18
|
+
ECDSA: 0,
|
|
19
|
+
/** Schnorr signature (BIP340) */
|
|
20
|
+
Schnorr: 1,
|
|
21
|
+
} as const;
|
|
22
|
+
|
|
23
|
+
export type SignatureType = (typeof SignatureType)[keyof typeof SignatureType];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Message sent to worker for signing operation.
|
|
27
|
+
*
|
|
28
|
+
* SECURITY: privateKey is cloned via postMessage, NOT shared.
|
|
29
|
+
* Worker MUST zero the key after signing.
|
|
30
|
+
*/
|
|
31
|
+
export interface SigningTaskMessage {
|
|
32
|
+
/** Message type discriminator */
|
|
33
|
+
readonly type: 'sign';
|
|
34
|
+
/** Task identifier for correlation */
|
|
35
|
+
readonly taskId: string;
|
|
36
|
+
/** Hash to sign (32 bytes) */
|
|
37
|
+
readonly hash: Uint8Array;
|
|
38
|
+
/** Private key (32 bytes) - WILL BE ZEROED after use */
|
|
39
|
+
readonly privateKey: Uint8Array;
|
|
40
|
+
/** Public key for verification (33 or 65 bytes) */
|
|
41
|
+
readonly publicKey: Uint8Array;
|
|
42
|
+
/** Signature type (ECDSA or Schnorr) */
|
|
43
|
+
readonly signatureType: SignatureType;
|
|
44
|
+
/** Low R signing for ECDSA (optional) */
|
|
45
|
+
readonly lowR?: boolean | undefined;
|
|
46
|
+
/** Input index this signature is for */
|
|
47
|
+
readonly inputIndex: number;
|
|
48
|
+
/** Sighash type for encoding */
|
|
49
|
+
readonly sighashType: number;
|
|
50
|
+
/** Leaf hash for Taproot script-path (optional) */
|
|
51
|
+
readonly leafHash?: Uint8Array | undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Initialization message for worker with ECC library.
|
|
56
|
+
*/
|
|
57
|
+
export interface WorkerInitMessage {
|
|
58
|
+
/** Message type discriminator */
|
|
59
|
+
readonly type: 'init';
|
|
60
|
+
/** Serialized ECC library functions (or library identifier) */
|
|
61
|
+
readonly eccLibId: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Shutdown message for worker.
|
|
66
|
+
*/
|
|
67
|
+
export interface WorkerShutdownMessage {
|
|
68
|
+
/** Message type discriminator */
|
|
69
|
+
readonly type: 'shutdown';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Individual task in a batch (without privateKey - shared across batch).
|
|
74
|
+
*/
|
|
75
|
+
export interface BatchSigningTask {
|
|
76
|
+
/** Task identifier */
|
|
77
|
+
readonly taskId: string;
|
|
78
|
+
/** Hash to sign (32 bytes) */
|
|
79
|
+
readonly hash: Uint8Array;
|
|
80
|
+
/** Public key for verification */
|
|
81
|
+
readonly publicKey: Uint8Array;
|
|
82
|
+
/** Signature type */
|
|
83
|
+
readonly signatureType: SignatureType;
|
|
84
|
+
/** Low R for ECDSA */
|
|
85
|
+
readonly lowR?: boolean | undefined;
|
|
86
|
+
/** Input index */
|
|
87
|
+
readonly inputIndex: number;
|
|
88
|
+
/** Sighash type */
|
|
89
|
+
readonly sighashType: number;
|
|
90
|
+
/** Leaf hash for Taproot */
|
|
91
|
+
readonly leafHash?: Uint8Array | undefined;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Batch signing message - multiple tasks with single private key.
|
|
96
|
+
* More efficient than sending tasks one at a time.
|
|
97
|
+
*/
|
|
98
|
+
export interface BatchSigningMessage {
|
|
99
|
+
/** Message type discriminator */
|
|
100
|
+
readonly type: 'signBatch';
|
|
101
|
+
/** Batch identifier for correlation */
|
|
102
|
+
readonly batchId: string;
|
|
103
|
+
/** Tasks to sign */
|
|
104
|
+
readonly tasks: readonly BatchSigningTask[];
|
|
105
|
+
/** Private key (32 bytes) - WILL BE ZEROED after all tasks */
|
|
106
|
+
readonly privateKey: Uint8Array;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Individual result from a batch.
|
|
111
|
+
*/
|
|
112
|
+
export interface BatchSigningTaskResult {
|
|
113
|
+
/** Task identifier */
|
|
114
|
+
readonly taskId: string;
|
|
115
|
+
/** Signature bytes */
|
|
116
|
+
readonly signature: Uint8Array;
|
|
117
|
+
/** Input index */
|
|
118
|
+
readonly inputIndex: number;
|
|
119
|
+
/** Public key used */
|
|
120
|
+
readonly publicKey: Uint8Array;
|
|
121
|
+
/** Signature type */
|
|
122
|
+
readonly signatureType: SignatureType;
|
|
123
|
+
/** Leaf hash (if applicable) */
|
|
124
|
+
readonly leafHash?: Uint8Array | undefined;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Individual error from a batch.
|
|
129
|
+
*/
|
|
130
|
+
export interface BatchSigningTaskError {
|
|
131
|
+
/** Task identifier */
|
|
132
|
+
readonly taskId: string;
|
|
133
|
+
/** Input index */
|
|
134
|
+
readonly inputIndex: number;
|
|
135
|
+
/** Error message */
|
|
136
|
+
readonly error: string;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Batch result message from worker.
|
|
141
|
+
*/
|
|
142
|
+
export interface BatchSigningResultMessage {
|
|
143
|
+
/** Message type discriminator */
|
|
144
|
+
readonly type: 'batchResult';
|
|
145
|
+
/** Batch identifier for correlation */
|
|
146
|
+
readonly batchId: string;
|
|
147
|
+
/** Successful results */
|
|
148
|
+
readonly results: readonly BatchSigningTaskResult[];
|
|
149
|
+
/** Errors */
|
|
150
|
+
readonly errors: readonly BatchSigningTaskError[];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* All possible messages to worker.
|
|
155
|
+
*/
|
|
156
|
+
export type WorkerMessage = SigningTaskMessage | BatchSigningMessage | WorkerInitMessage | WorkerShutdownMessage;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Result from worker after signing.
|
|
160
|
+
*/
|
|
161
|
+
export interface SigningResultMessage {
|
|
162
|
+
/** Message type discriminator */
|
|
163
|
+
readonly type: 'result';
|
|
164
|
+
/** Task identifier for correlation */
|
|
165
|
+
readonly taskId: string;
|
|
166
|
+
/** Signature bytes (64 bytes raw for Schnorr, or with sighash for ECDSA) */
|
|
167
|
+
readonly signature: Uint8Array;
|
|
168
|
+
/** Input index this signature is for */
|
|
169
|
+
readonly inputIndex: number;
|
|
170
|
+
/** Public key used for signing */
|
|
171
|
+
readonly publicKey: Uint8Array;
|
|
172
|
+
/** Signature type that was used */
|
|
173
|
+
readonly signatureType: SignatureType;
|
|
174
|
+
/** Leaf hash for Taproot script-path spending (if applicable) */
|
|
175
|
+
readonly leafHash?: Uint8Array | undefined;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Error result from worker.
|
|
180
|
+
*/
|
|
181
|
+
export interface SigningErrorMessage {
|
|
182
|
+
/** Message type discriminator */
|
|
183
|
+
readonly type: 'error';
|
|
184
|
+
/** Task identifier for correlation */
|
|
185
|
+
readonly taskId: string;
|
|
186
|
+
/** Error message */
|
|
187
|
+
readonly error: string;
|
|
188
|
+
/** Input index that failed */
|
|
189
|
+
readonly inputIndex: number;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Worker ready message.
|
|
194
|
+
*/
|
|
195
|
+
export interface WorkerReadyMessage {
|
|
196
|
+
/** Message type discriminator */
|
|
197
|
+
readonly type: 'ready';
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Worker shutdown acknowledgment.
|
|
202
|
+
*/
|
|
203
|
+
export interface WorkerShutdownAckMessage {
|
|
204
|
+
/** Message type discriminator */
|
|
205
|
+
readonly type: 'shutdown-ack';
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Union of all worker response types.
|
|
210
|
+
*/
|
|
211
|
+
export type WorkerResponse =
|
|
212
|
+
| SigningResultMessage
|
|
213
|
+
| SigningErrorMessage
|
|
214
|
+
| BatchSigningResultMessage
|
|
215
|
+
| WorkerReadyMessage
|
|
216
|
+
| WorkerShutdownAckMessage;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Type guard for error responses.
|
|
220
|
+
*/
|
|
221
|
+
export function isSigningError(response: WorkerResponse): response is SigningErrorMessage {
|
|
222
|
+
return response.type === 'error';
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Type guard for success responses.
|
|
227
|
+
*/
|
|
228
|
+
export function isSigningResult(response: WorkerResponse): response is SigningResultMessage {
|
|
229
|
+
return response.type === 'result';
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Type guard for batch result responses.
|
|
234
|
+
*/
|
|
235
|
+
export function isBatchResult(response: WorkerResponse): response is BatchSigningResultMessage {
|
|
236
|
+
return response.type === 'batchResult';
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Type guard for ready responses.
|
|
241
|
+
*/
|
|
242
|
+
export function isWorkerReady(response: WorkerResponse): response is WorkerReadyMessage {
|
|
243
|
+
return response.type === 'ready';
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Interface for the ECC library used by workers.
|
|
248
|
+
* Provides signing functions for ECDSA and Schnorr signatures.
|
|
249
|
+
*/
|
|
250
|
+
export interface WorkerEccLib {
|
|
251
|
+
/**
|
|
252
|
+
* Create an ECDSA signature.
|
|
253
|
+
*
|
|
254
|
+
* @param hash - 32-byte hash to sign
|
|
255
|
+
* @param privateKey - 32-byte private key
|
|
256
|
+
* @param lowR - Optional: grind for low R value
|
|
257
|
+
* @returns 64-byte raw signature (r || s)
|
|
258
|
+
*/
|
|
259
|
+
sign(hash: Uint8Array, privateKey: Uint8Array, lowR?: boolean): Uint8Array;
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Create a Schnorr signature (BIP340).
|
|
263
|
+
*
|
|
264
|
+
* @param hash - 32-byte hash to sign
|
|
265
|
+
* @param privateKey - 32-byte private key
|
|
266
|
+
* @returns 64-byte Schnorr signature
|
|
267
|
+
*/
|
|
268
|
+
signSchnorr(hash: Uint8Array, privateKey: Uint8Array): Uint8Array;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Configuration for the worker signing pool.
|
|
273
|
+
*/
|
|
274
|
+
export interface WorkerPoolConfig {
|
|
275
|
+
/**
|
|
276
|
+
* Number of workers to create.
|
|
277
|
+
* Default: number of CPU cores (navigator.hardwareConcurrency or os.cpus().length)
|
|
278
|
+
*/
|
|
279
|
+
readonly workerCount?: number;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Timeout per signing operation in milliseconds.
|
|
283
|
+
* Worker is terminated if exceeded (key safety measure).
|
|
284
|
+
* Default: 30000 (30 seconds)
|
|
285
|
+
*/
|
|
286
|
+
readonly taskTimeoutMs?: number;
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Maximum time a worker can hold a private key in milliseconds.
|
|
290
|
+
* Acts as a safety net - worker is terminated if signing takes too long.
|
|
291
|
+
* Default: 5000 (5 seconds)
|
|
292
|
+
*/
|
|
293
|
+
readonly maxKeyHoldTimeMs?: number;
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Whether to verify signatures after signing.
|
|
297
|
+
* Adds overhead but ensures correctness.
|
|
298
|
+
* Default: true
|
|
299
|
+
*/
|
|
300
|
+
readonly verifySignatures?: boolean;
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Whether to preserve workers between signing batches.
|
|
304
|
+
* true = workers stay alive (faster for multiple batches)
|
|
305
|
+
* false = workers terminated after each batch (more secure)
|
|
306
|
+
* Default: true (use preserveWorkers() to enable)
|
|
307
|
+
*/
|
|
308
|
+
readonly preserveWorkers?: boolean;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Signing task for the worker queue.
|
|
313
|
+
*/
|
|
314
|
+
export interface SigningTask {
|
|
315
|
+
/** Task identifier */
|
|
316
|
+
readonly taskId: string;
|
|
317
|
+
/** Input index */
|
|
318
|
+
readonly inputIndex: number;
|
|
319
|
+
/** Hash to sign (32 bytes) */
|
|
320
|
+
readonly hash: Uint8Array;
|
|
321
|
+
/** Signature type */
|
|
322
|
+
readonly signatureType: SignatureType;
|
|
323
|
+
/** Low R for ECDSA */
|
|
324
|
+
readonly lowR?: boolean | undefined;
|
|
325
|
+
/** Sighash type */
|
|
326
|
+
readonly sighashType: number;
|
|
327
|
+
/** Leaf hash for Taproot script-path */
|
|
328
|
+
readonly leafHash?: Uint8Array | undefined;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Signer key pair interface for parallel signing.
|
|
333
|
+
*
|
|
334
|
+
* SECURITY: getPrivateKey() is only called when dispatching to worker.
|
|
335
|
+
* The returned bytes are cloned to the worker and then the original
|
|
336
|
+
* should be considered potentially compromised (in main thread memory).
|
|
337
|
+
*
|
|
338
|
+
* For maximum security, use a hardware wallet that never exposes keys.
|
|
339
|
+
*/
|
|
340
|
+
export interface ParallelSignerKeyPair {
|
|
341
|
+
/** Public key (compressed 33 bytes or uncompressed 65 bytes) */
|
|
342
|
+
readonly publicKey: Uint8Array;
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Get private key bytes (32 bytes).
|
|
346
|
+
*
|
|
347
|
+
* SECURITY WARNING: This exposes the raw private key.
|
|
348
|
+
* - Called only when dispatching to worker
|
|
349
|
+
* - Key is cloned to worker via postMessage
|
|
350
|
+
* - Original in main thread should be zeroed by caller if possible
|
|
351
|
+
*
|
|
352
|
+
* For high-security applications, use hardware wallets instead.
|
|
353
|
+
*/
|
|
354
|
+
getPrivateKey(): Uint8Array;
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Optional: Sign ECDSA directly (fallback if workers unavailable).
|
|
358
|
+
*/
|
|
359
|
+
sign?(hash: Uint8Array, lowR?: boolean): Uint8Array;
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Optional: Sign Schnorr directly (fallback if workers unavailable).
|
|
363
|
+
*/
|
|
364
|
+
signSchnorr?(hash: Uint8Array): Uint8Array;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Result of a parallel signing batch.
|
|
369
|
+
*/
|
|
370
|
+
export interface ParallelSigningResult {
|
|
371
|
+
/** Whether all signatures were created successfully */
|
|
372
|
+
readonly success: boolean;
|
|
373
|
+
/** Signatures indexed by input index */
|
|
374
|
+
readonly signatures: ReadonlyMap<number, SigningResultMessage>;
|
|
375
|
+
/** Errors indexed by input index */
|
|
376
|
+
readonly errors: ReadonlyMap<number, string>;
|
|
377
|
+
/** Total time taken in milliseconds */
|
|
378
|
+
readonly durationMs: number;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Worker state for pool management.
|
|
383
|
+
*/
|
|
384
|
+
export const WorkerState = {
|
|
385
|
+
/** Worker is initializing */
|
|
386
|
+
Initializing: 0,
|
|
387
|
+
/** Worker is ready and idle */
|
|
388
|
+
Idle: 1,
|
|
389
|
+
/** Worker is processing a task */
|
|
390
|
+
Busy: 2,
|
|
391
|
+
/** Worker is shutting down */
|
|
392
|
+
ShuttingDown: 3,
|
|
393
|
+
/** Worker has terminated */
|
|
394
|
+
Terminated: 4,
|
|
395
|
+
} as const;
|
|
396
|
+
|
|
397
|
+
export type WorkerState = (typeof WorkerState)[keyof typeof WorkerState];
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Internal worker wrapper for pool management.
|
|
401
|
+
*/
|
|
402
|
+
export interface PooledWorker {
|
|
403
|
+
/** Unique worker identifier */
|
|
404
|
+
readonly id: number;
|
|
405
|
+
/** Current worker state */
|
|
406
|
+
state: WorkerState;
|
|
407
|
+
/** The actual worker instance */
|
|
408
|
+
readonly worker: Worker;
|
|
409
|
+
/** Current task ID (if busy) */
|
|
410
|
+
currentTaskId: string | null;
|
|
411
|
+
/** Timestamp when current task started */
|
|
412
|
+
taskStartTime: number | null;
|
|
413
|
+
}
|
package/test/address.spec.ts
CHANGED
|
@@ -7,8 +7,11 @@ import * as bscript from '../src/script.js';
|
|
|
7
7
|
import fixtures from './fixtures/address.json' with { type: 'json' };
|
|
8
8
|
|
|
9
9
|
import { initEccLib } from '../src/index.js';
|
|
10
|
+
import type { EccLib } from '../src/index.js';
|
|
10
11
|
import type { Network } from '../src/networks.js';
|
|
11
12
|
import * as networks from '../src/networks.js';
|
|
13
|
+
import { toHex, fromHex } from '../src/io/index.js';
|
|
14
|
+
import type { Bytes20 } from '../src/types.js';
|
|
12
15
|
|
|
13
16
|
const NETWORKS: Record<string, Network> = Object.assign(
|
|
14
17
|
{
|
|
@@ -37,7 +40,7 @@ describe('address', () => {
|
|
|
37
40
|
const decode = baddress.fromBase58Check(f.base58check);
|
|
38
41
|
|
|
39
42
|
assert.strictEqual(decode.version, f.version);
|
|
40
|
-
assert.strictEqual(decode.hash
|
|
43
|
+
assert.strictEqual(toHex(decode.hash), f.hash);
|
|
41
44
|
});
|
|
42
45
|
});
|
|
43
46
|
|
|
@@ -68,7 +71,7 @@ describe('address', () => {
|
|
|
68
71
|
validPrefixes.includes(actual.prefix),
|
|
69
72
|
`Expected prefix to be one of [${validPrefixes.join(', ')}], got ${actual.prefix}`,
|
|
70
73
|
);
|
|
71
|
-
assert.strictEqual(actual.data
|
|
74
|
+
assert.strictEqual(toHex(actual.data), f.data);
|
|
72
75
|
});
|
|
73
76
|
});
|
|
74
77
|
|
|
@@ -82,7 +85,7 @@ describe('address', () => {
|
|
|
82
85
|
});
|
|
83
86
|
|
|
84
87
|
describe('fromOutputScript', () => {
|
|
85
|
-
initEccLib(ecc);
|
|
88
|
+
initEccLib(ecc as unknown as EccLib);
|
|
86
89
|
fixtures.standard.forEach((f) => {
|
|
87
90
|
it('encodes ' + f.script.slice(0, 30) + '... (' + f.network + ')', () => {
|
|
88
91
|
const script = bscript.fromASM(f.script);
|
|
@@ -108,7 +111,7 @@ describe('address', () => {
|
|
|
108
111
|
if (!f.base58check) return;
|
|
109
112
|
|
|
110
113
|
it('encodes ' + f.hash + ' (' + f.network + ')', () => {
|
|
111
|
-
const address = baddress.toBase58Check(
|
|
114
|
+
const address = baddress.toBase58Check(fromHex(f.hash) as Bytes20, f.version);
|
|
112
115
|
|
|
113
116
|
assert.strictEqual(address, f.base58check);
|
|
114
117
|
});
|
|
@@ -118,7 +121,7 @@ describe('address', () => {
|
|
|
118
121
|
describe('toBech32', () => {
|
|
119
122
|
fixtures.bech32.forEach((f) => {
|
|
120
123
|
if (!f.address) return;
|
|
121
|
-
const data =
|
|
124
|
+
const data = fromHex(f.data);
|
|
122
125
|
|
|
123
126
|
it('encode ' + f.address, () => {
|
|
124
127
|
assert.deepStrictEqual(
|
|
@@ -134,7 +137,7 @@ describe('address', () => {
|
|
|
134
137
|
|
|
135
138
|
it('encode fails (' + f.exception, () => {
|
|
136
139
|
assert.throws(() => {
|
|
137
|
-
baddress.toBech32(
|
|
140
|
+
baddress.toBech32(fromHex(f.data), f.version, f.prefix);
|
|
138
141
|
}, new RegExp(f.exception));
|
|
139
142
|
});
|
|
140
143
|
});
|
|
@@ -2,6 +2,8 @@ import assert from 'assert';
|
|
|
2
2
|
import base58 from 'bs58';
|
|
3
3
|
import { describe, it } from 'vitest';
|
|
4
4
|
import * as bitcoin from '../src/index.js';
|
|
5
|
+
import type { Bytes20, Satoshi, Script } from '../src/types.js';
|
|
6
|
+
import { toHex, fromHex, reverseCopy } from '../src/io/index.js';
|
|
5
7
|
import base58EncodeDecode from './fixtures/core/base58_encode_decode.json' with { type: 'json' };
|
|
6
8
|
import base58KeysInvalid from './fixtures/core/base58_keys_invalid.json' with { type: 'json' };
|
|
7
9
|
import base58KeysValid from './fixtures/core/base58_keys_valid.json' with { type: 'json' };
|
|
@@ -20,13 +22,13 @@ describe('Bitcoin-core', () => {
|
|
|
20
22
|
|
|
21
23
|
it('can decode ' + fb58, () => {
|
|
22
24
|
const buffer = base58.decode(fb58);
|
|
23
|
-
const actual =
|
|
25
|
+
const actual = toHex(new Uint8Array(buffer));
|
|
24
26
|
|
|
25
27
|
assert.strictEqual(actual, fhex);
|
|
26
28
|
});
|
|
27
29
|
|
|
28
30
|
it('can encode ' + fhex, () => {
|
|
29
|
-
const buffer =
|
|
31
|
+
const buffer = fromHex(fhex);
|
|
30
32
|
const actual = base58.encode(buffer);
|
|
31
33
|
|
|
32
34
|
assert.strictEqual(actual, fb58);
|
|
@@ -43,7 +45,7 @@ describe('Bitcoin-core', () => {
|
|
|
43
45
|
|
|
44
46
|
base58KeysValid.forEach((f) => {
|
|
45
47
|
const expected = f[0];
|
|
46
|
-
const hash =
|
|
48
|
+
const hash = fromHex(f[1] as any);
|
|
47
49
|
const params = f[2] as any;
|
|
48
50
|
|
|
49
51
|
if (params.isPrivkey) return;
|
|
@@ -55,7 +57,7 @@ describe('Bitcoin-core', () => {
|
|
|
55
57
|
const version = network[typeMap[params.addrType]];
|
|
56
58
|
|
|
57
59
|
it(`can export ${expected as string}`, () => {
|
|
58
|
-
assert.strictEqual(bitcoin.address.toBase58Check(hash, version), expected);
|
|
60
|
+
assert.strictEqual(bitcoin.address.toBase58Check(hash as Bytes20, version), expected);
|
|
59
61
|
});
|
|
60
62
|
});
|
|
61
63
|
});
|
|
@@ -114,7 +116,7 @@ describe('Bitcoin-core', () => {
|
|
|
114
116
|
const input = inputs[i];
|
|
115
117
|
|
|
116
118
|
// reverse because test data is reversed
|
|
117
|
-
const prevOutHash =
|
|
119
|
+
const prevOutHash = reverseCopy(fromHex(input[0] as string));
|
|
118
120
|
const prevOutIndex = input[1];
|
|
119
121
|
|
|
120
122
|
assert.deepStrictEqual(txIn.hash, prevOutHash);
|
|
@@ -153,23 +155,20 @@ describe('Bitcoin-core', () => {
|
|
|
153
155
|
const transaction = bitcoin.Transaction.fromHex(txHex);
|
|
154
156
|
assert.strictEqual(transaction.toHex(), txHex);
|
|
155
157
|
|
|
156
|
-
const script =
|
|
158
|
+
const script = fromHex(scriptHex);
|
|
157
159
|
const scriptChunks = bitcoin.script.decompile(script);
|
|
158
|
-
assert.strictEqual(
|
|
159
|
-
bitcoin.script.compile(scriptChunks!).toString('hex'),
|
|
160
|
-
scriptHex,
|
|
161
|
-
);
|
|
160
|
+
assert.strictEqual(toHex(bitcoin.script.compile(scriptChunks!)), scriptHex);
|
|
162
161
|
|
|
163
|
-
const hash = transaction.hashForSignature(inIndex, script, hashType);
|
|
162
|
+
const hash = transaction.hashForSignature(inIndex, script as Script, hashType);
|
|
164
163
|
|
|
165
164
|
// reverse because test data is reversed
|
|
166
|
-
assert.strictEqual((hash
|
|
165
|
+
assert.strictEqual(toHex(reverseCopy(hash)), expectedHash);
|
|
167
166
|
|
|
168
167
|
assert.doesNotThrow(() =>
|
|
169
168
|
transaction.hashForWitnessV0(
|
|
170
169
|
inIndex,
|
|
171
|
-
script,
|
|
172
|
-
|
|
170
|
+
script as Script,
|
|
171
|
+
0n as Satoshi,
|
|
173
172
|
// convert to UInt32
|
|
174
173
|
hashType < 0 ? 0x100000000 + hashType : hashType,
|
|
175
174
|
),
|
|
@@ -180,13 +179,13 @@ describe('Bitcoin-core', () => {
|
|
|
180
179
|
|
|
181
180
|
describe('script.signature.decode', () => {
|
|
182
181
|
sigCanonical.forEach((hex) => {
|
|
183
|
-
const buffer =
|
|
182
|
+
const buffer = fromHex(hex);
|
|
184
183
|
|
|
185
184
|
it('can parse ' + hex, () => {
|
|
186
185
|
const parsed = bitcoin.script.signature.decode(buffer);
|
|
187
186
|
const actual = bitcoin.script.signature.encode(parsed.signature, parsed.hashType);
|
|
188
187
|
|
|
189
|
-
assert.strictEqual(actual
|
|
188
|
+
assert.strictEqual(toHex(actual), hex);
|
|
190
189
|
});
|
|
191
190
|
});
|
|
192
191
|
|
|
@@ -195,7 +194,7 @@ describe('Bitcoin-core', () => {
|
|
|
195
194
|
if (i % 2 !== 0) return;
|
|
196
195
|
|
|
197
196
|
const description = sigNoncanonical[i - 1].slice(0, -1);
|
|
198
|
-
const buffer =
|
|
197
|
+
const buffer = fromHex(hex);
|
|
199
198
|
|
|
200
199
|
it('throws on ' + description, () => {
|
|
201
200
|
const reg = new RegExp(
|
package/test/block.spec.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import assert from 'assert';
|
|
2
2
|
import { beforeEach, describe, it } from 'vitest';
|
|
3
3
|
import { Block } from '../src/index.js';
|
|
4
|
+
import { toHex } from '../src/io/index.js';
|
|
4
5
|
|
|
5
6
|
import fixtures from './fixtures/block.json' with { type: 'json' };
|
|
6
7
|
|
|
@@ -22,7 +23,7 @@ describe('Block', () => {
|
|
|
22
23
|
it('returns ' + f.expected + ' for 0x' + f.bits, () => {
|
|
23
24
|
const bits = parseInt(f.bits, 16);
|
|
24
25
|
|
|
25
|
-
assert.strictEqual(Block.calculateTarget(bits)
|
|
26
|
+
assert.strictEqual(toHex(Block.calculateTarget(bits)), f.expected);
|
|
26
27
|
});
|
|
27
28
|
});
|
|
28
29
|
});
|
|
@@ -33,10 +34,10 @@ describe('Block', () => {
|
|
|
33
34
|
const block = Block.fromHex(f.hex);
|
|
34
35
|
|
|
35
36
|
assert.strictEqual(block.version, f.version);
|
|
36
|
-
assert.strictEqual(block.prevHash
|
|
37
|
-
assert.strictEqual(block.merkleRoot
|
|
37
|
+
assert.strictEqual(toHex(block.prevHash!), f.prevHash);
|
|
38
|
+
assert.strictEqual(toHex(block.merkleRoot!), f.merkleRoot);
|
|
38
39
|
if (block.witnessCommit) {
|
|
39
|
-
assert.strictEqual(block.witnessCommit
|
|
40
|
+
assert.strictEqual(toHex(block.witnessCommit), f.witnessCommit);
|
|
40
41
|
}
|
|
41
42
|
assert.strictEqual(block.timestamp, f.timestamp);
|
|
42
43
|
assert.strictEqual(block.bits, f.bits);
|
|
@@ -83,7 +84,7 @@ describe('Block', () => {
|
|
|
83
84
|
});
|
|
84
85
|
|
|
85
86
|
it('returns ' + f.id + ' for ' + f.description, () => {
|
|
86
|
-
assert.strictEqual(block.getHash()
|
|
87
|
+
assert.strictEqual(toHex(block.getHash()), f.hash);
|
|
87
88
|
assert.strictEqual(block.getId(), f.id);
|
|
88
89
|
});
|
|
89
90
|
});
|
|
@@ -123,7 +124,7 @@ describe('Block', () => {
|
|
|
123
124
|
|
|
124
125
|
it('returns ' + f.merkleRoot + ' for ' + f.id, () => {
|
|
125
126
|
assert.strictEqual(
|
|
126
|
-
Block.calculateMerkleRoot(block.transactions!)
|
|
127
|
+
toHex(Block.calculateMerkleRoot(block.transactions!)),
|
|
127
128
|
f.merkleRoot,
|
|
128
129
|
);
|
|
129
130
|
});
|
|
@@ -131,7 +132,7 @@ describe('Block', () => {
|
|
|
131
132
|
if (f.witnessCommit) {
|
|
132
133
|
it('returns witness commit ' + f.witnessCommit + ' for ' + f.id, () => {
|
|
133
134
|
assert.strictEqual(
|
|
134
|
-
Block.calculateMerkleRoot(block.transactions!, true)
|
|
135
|
+
toHex(Block.calculateMerkleRoot(block.transactions!, true)),
|
|
135
136
|
f.witnessCommit,
|
|
136
137
|
);
|
|
137
138
|
});
|