@btc-vision/bitcoin 6.5.5 → 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/AUDIT/README.md +9 -0
- package/HOW_TO_WRITE_GOOD_CODE.md +2436 -0
- package/SECURITY.md +27 -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 +37 -13
- 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 +83 -25
- 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 +24 -25
- 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 +11 -0
- package/browser/bufferutils.d.ts +0 -34
- package/browser/chunks/crypto-BhCpKpek.js +0 -2033
- package/browser/chunks/payments-yjA0Evsv.js +0 -1089
- package/browser/chunks/psbt-URK2hBFc.js +0 -4039
- 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/SECURITY.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported Versions
|
|
4
|
+
|
|
5
|
+
| Version | Status |
|
|
6
|
+
|---------|--------------------|
|
|
7
|
+
| 6.x | Supported |
|
|
8
|
+
| < 6.0 | Not supported |
|
|
9
|
+
|
|
10
|
+
## Reporting a Vulnerability
|
|
11
|
+
|
|
12
|
+
**DO NOT** open a public GitHub issue for security vulnerabilities.
|
|
13
|
+
|
|
14
|
+
Report vulnerabilities through [GitHub Security Advisories](https://github.com/btc-vision/bitcoin/security/advisories/new).
|
|
15
|
+
|
|
16
|
+
Include:
|
|
17
|
+
- Description of the vulnerability
|
|
18
|
+
- Affected version(s)
|
|
19
|
+
- Steps to reproduce
|
|
20
|
+
- Potential impact
|
|
21
|
+
- Suggested fix (if any)
|
|
22
|
+
|
|
23
|
+
## Contact
|
|
24
|
+
|
|
25
|
+
- **Security Issues**: [GitHub Security Advisories](https://github.com/btc-vision/bitcoin/security/advisories)
|
|
26
|
+
- **General Issues**: [GitHub Issues](https://github.com/btc-vision/bitcoin/issues)
|
|
27
|
+
- **Website**: [opnet.org](https://opnet.org)
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PSBT 2000 Input Benchmark - Tests Taproot signing performance
|
|
3
|
+
*
|
|
4
|
+
* This benchmark measures the O(n^2) -> O(n) optimization for Taproot signing.
|
|
5
|
+
*
|
|
6
|
+
* Run with: npx tsx benchmark/psbt-2000-inputs.bench.ts
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as ecc from 'tiny-secp256k1';
|
|
10
|
+
import { randomBytes } from 'crypto';
|
|
11
|
+
import { BIP32Factory } from '@btc-vision/bip32';
|
|
12
|
+
import { initEccLib, Psbt, payments, crypto, Transaction } from '../src/index.js';
|
|
13
|
+
import { toXOnly } from '../src/pubkey.js';
|
|
14
|
+
|
|
15
|
+
// Initialize ECC library
|
|
16
|
+
initEccLib(ecc);
|
|
17
|
+
const bip32 = BIP32Factory(ecc);
|
|
18
|
+
|
|
19
|
+
// Generate a test keypair for taproot key-path spending
|
|
20
|
+
function generateTaprootKeyPair() {
|
|
21
|
+
const node = bip32.fromSeed(randomBytes(64));
|
|
22
|
+
const xOnlyPubkey = toXOnly(node.publicKey);
|
|
23
|
+
|
|
24
|
+
// Create tweaked signer for taproot key-path spending
|
|
25
|
+
const tweakedNode = node.tweak(crypto.taggedHash('TapTweak', xOnlyPubkey));
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
xOnlyPubkey,
|
|
29
|
+
signer: tweakedNode,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Create a fake previous transaction for nonWitnessUtxo
|
|
34
|
+
function createFakePrevTx(outputScript: Uint8Array, value: bigint, index: number): Buffer {
|
|
35
|
+
const tx = new Transaction();
|
|
36
|
+
tx.version = 2;
|
|
37
|
+
const inputHash = Buffer.alloc(32);
|
|
38
|
+
inputHash.writeUInt32LE(index, 0);
|
|
39
|
+
tx.addInput(inputHash, 0);
|
|
40
|
+
tx.addOutput(outputScript, value);
|
|
41
|
+
return tx.toBuffer();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function runBenchmark(inputCount: number, iterations: number = 5) {
|
|
45
|
+
console.log(`\n--- Benchmarking ${inputCount} P2TR inputs ---`);
|
|
46
|
+
|
|
47
|
+
const keyPair = generateTaprootKeyPair();
|
|
48
|
+
|
|
49
|
+
const { output } = payments.p2tr({
|
|
50
|
+
internalPubkey: keyPair.xOnlyPubkey,
|
|
51
|
+
});
|
|
52
|
+
if (!output) throw new Error('Failed to create P2TR output');
|
|
53
|
+
|
|
54
|
+
const inputValue = 10000n;
|
|
55
|
+
const totalInput = inputValue * BigInt(inputCount);
|
|
56
|
+
const fee = 1000n;
|
|
57
|
+
const outputValue = (totalInput - fee) / 5n;
|
|
58
|
+
|
|
59
|
+
console.log(` Generating ${inputCount} fake previous transactions...`);
|
|
60
|
+
const setupStart = performance.now();
|
|
61
|
+
|
|
62
|
+
const prevTxs: Buffer[] = [];
|
|
63
|
+
const txIds: Buffer[] = [];
|
|
64
|
+
for (let i = 0; i < inputCount; i++) {
|
|
65
|
+
const prevTx = createFakePrevTx(output, inputValue, i);
|
|
66
|
+
prevTxs.push(prevTx);
|
|
67
|
+
const hash1 = crypto.sha256(prevTx);
|
|
68
|
+
const hash2 = crypto.sha256(hash1);
|
|
69
|
+
const txId = Buffer.from(hash2).reverse();
|
|
70
|
+
txIds.push(txId);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
console.log(` Setup done in ${((performance.now() - setupStart) / 1000).toFixed(2)}s`);
|
|
74
|
+
|
|
75
|
+
// Warmup
|
|
76
|
+
console.log(' Warming up...');
|
|
77
|
+
{
|
|
78
|
+
const psbt = new Psbt();
|
|
79
|
+
for (let i = 0; i < Math.min(100, inputCount); i++) {
|
|
80
|
+
psbt.addInput({
|
|
81
|
+
hash: txIds[i],
|
|
82
|
+
index: 0,
|
|
83
|
+
nonWitnessUtxo: prevTxs[i],
|
|
84
|
+
tapInternalKey: keyPair.xOnlyPubkey,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
for (let i = 0; i < 5; i++) {
|
|
88
|
+
psbt.addOutput({ script: output, value: outputValue });
|
|
89
|
+
}
|
|
90
|
+
psbt.signAllInputs(keyPair.signer);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const times: number[] = [];
|
|
94
|
+
|
|
95
|
+
for (let iter = 0; iter < iterations; iter++) {
|
|
96
|
+
const psbt = new Psbt();
|
|
97
|
+
|
|
98
|
+
for (let i = 0; i < inputCount; i++) {
|
|
99
|
+
psbt.addInput({
|
|
100
|
+
hash: txIds[i],
|
|
101
|
+
index: 0,
|
|
102
|
+
nonWitnessUtxo: prevTxs[i],
|
|
103
|
+
tapInternalKey: keyPair.xOnlyPubkey,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
for (let i = 0; i < 5; i++) {
|
|
108
|
+
psbt.addOutput({ script: output, value: outputValue });
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const start = performance.now();
|
|
112
|
+
psbt.signAllInputs(keyPair.signer);
|
|
113
|
+
const elapsed = performance.now() - start;
|
|
114
|
+
times.push(elapsed);
|
|
115
|
+
|
|
116
|
+
console.log(` Iteration ${iter + 1}: ${elapsed.toFixed(2)}ms`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const avg = times.reduce((a, b) => a + b, 0) / times.length;
|
|
120
|
+
const min = Math.min(...times);
|
|
121
|
+
const max = Math.max(...times);
|
|
122
|
+
|
|
123
|
+
console.log(`\n Results for ${inputCount} inputs:`);
|
|
124
|
+
console.log(` Average: ${avg.toFixed(2)}ms`);
|
|
125
|
+
console.log(` Min: ${min.toFixed(2)}ms`);
|
|
126
|
+
console.log(` Max: ${max.toFixed(2)}ms`);
|
|
127
|
+
console.log(` Per-input: ${(avg / inputCount).toFixed(4)}ms`);
|
|
128
|
+
|
|
129
|
+
return { inputCount, avg, min, max };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function main() {
|
|
133
|
+
console.log('='.repeat(70));
|
|
134
|
+
console.log(' PSBT Taproot Signing Benchmark (prevOuts caching optimization)');
|
|
135
|
+
console.log('='.repeat(70));
|
|
136
|
+
|
|
137
|
+
const inputCounts = [100, 500, 1000, 2000];
|
|
138
|
+
const results: Array<{ inputCount: number; avg: number; min: number; max: number }> = [];
|
|
139
|
+
|
|
140
|
+
for (const count of inputCounts) {
|
|
141
|
+
const result = await runBenchmark(count, 3);
|
|
142
|
+
results.push(result);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
console.log('\n' + '='.repeat(70));
|
|
146
|
+
console.log(' SUMMARY');
|
|
147
|
+
console.log('='.repeat(70));
|
|
148
|
+
console.log('\n Inputs | Avg (ms) | Min (ms) | Max (ms) | Per-input (ms)');
|
|
149
|
+
console.log(' -------|----------|----------|----------|---------------');
|
|
150
|
+
for (const r of results) {
|
|
151
|
+
console.log(
|
|
152
|
+
` ${String(r.inputCount).padStart(6)} | ${r.avg.toFixed(2).padStart(8)} | ${r.min.toFixed(2).padStart(8)} | ${r.max.toFixed(2).padStart(8)} | ${(r.avg / r.inputCount).toFixed(4).padStart(13)}`,
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
console.log('\n Scaling Analysis:');
|
|
157
|
+
if (results.length >= 2) {
|
|
158
|
+
const first = results[0];
|
|
159
|
+
const last = results[results.length - 1];
|
|
160
|
+
const perInputFirst = first.avg / first.inputCount;
|
|
161
|
+
const perInputLast = last.avg / last.inputCount;
|
|
162
|
+
const ratio = perInputLast / perInputFirst;
|
|
163
|
+
|
|
164
|
+
console.log(` Per-input time at ${first.inputCount} inputs: ${perInputFirst.toFixed(4)}ms`);
|
|
165
|
+
console.log(` Per-input time at ${last.inputCount} inputs: ${perInputLast.toFixed(4)}ms`);
|
|
166
|
+
console.log(` Ratio: ${ratio.toFixed(2)}x`);
|
|
167
|
+
|
|
168
|
+
if (ratio < 2) {
|
|
169
|
+
console.log(' Result: O(n) scaling achieved!');
|
|
170
|
+
} else {
|
|
171
|
+
console.log(' Result: Scaling is worse than O(n).');
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
console.log();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone Worker Signing Benchmark
|
|
3
|
+
*
|
|
4
|
+
* Run with: npx tsx benchmark/signing.bench.ts
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as ecc from 'tiny-secp256k1';
|
|
8
|
+
import { randomBytes } from 'crypto';
|
|
9
|
+
import { initEccLib } from '../src/ecc/context.js';
|
|
10
|
+
import { SignatureType, type SigningTask } from '../src/workers/types.js';
|
|
11
|
+
|
|
12
|
+
// Initialize ECC
|
|
13
|
+
initEccLib(ecc);
|
|
14
|
+
|
|
15
|
+
// Test key pair
|
|
16
|
+
const TEST_PRIVATE_KEY = randomBytes(32);
|
|
17
|
+
const TEST_PUBLIC_KEY = ecc.pointFromScalar(TEST_PRIVATE_KEY, true)!;
|
|
18
|
+
|
|
19
|
+
const signer = {
|
|
20
|
+
publicKey: TEST_PUBLIC_KEY,
|
|
21
|
+
sign: (hash: Uint8Array) => ecc.sign(hash, TEST_PRIVATE_KEY),
|
|
22
|
+
getPrivateKey: () => new Uint8Array(TEST_PRIVATE_KEY),
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
async function main() {
|
|
26
|
+
console.log('='.repeat(70));
|
|
27
|
+
console.log(' WORKER SIGNING BENCHMARK');
|
|
28
|
+
console.log('='.repeat(70));
|
|
29
|
+
console.log();
|
|
30
|
+
|
|
31
|
+
const inputCounts = [4, 8, 16, 32, 64, 100, 200, 2000];
|
|
32
|
+
const iterations = 50;
|
|
33
|
+
|
|
34
|
+
// Pre-generate ALL hashes upfront (just random 32-byte arrays)
|
|
35
|
+
console.log('Generating test hashes...');
|
|
36
|
+
const setupStart = performance.now();
|
|
37
|
+
|
|
38
|
+
const allTasks: Map<number, SigningTask[][]> = new Map();
|
|
39
|
+
for (const inputCount of inputCounts) {
|
|
40
|
+
const iters = inputCount >= 2000 ? 10 : iterations;
|
|
41
|
+
const tasksForCount: SigningTask[][] = [];
|
|
42
|
+
|
|
43
|
+
for (let i = 0; i < iters + 5; i++) {
|
|
44
|
+
const tasks: SigningTask[] = [];
|
|
45
|
+
for (let j = 0; j < inputCount; j++) {
|
|
46
|
+
tasks.push({
|
|
47
|
+
taskId: `task-${i}-${j}`,
|
|
48
|
+
inputIndex: j,
|
|
49
|
+
hash: randomBytes(32),
|
|
50
|
+
signatureType: SignatureType.ECDSA,
|
|
51
|
+
sighashType: 0x01,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
tasksForCount.push(tasks);
|
|
55
|
+
}
|
|
56
|
+
allTasks.set(inputCount, tasksForCount);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
console.log(`Setup done in ${((performance.now() - setupStart) / 1000).toFixed(2)}s`);
|
|
60
|
+
console.log();
|
|
61
|
+
|
|
62
|
+
// Initialize worker pool
|
|
63
|
+
const { NodeWorkerSigningPool } = await import('../src/workers/WorkerSigningPool.node.js');
|
|
64
|
+
NodeWorkerSigningPool.resetInstance();
|
|
65
|
+
const pool = NodeWorkerSigningPool.getInstance({ workerCount: 4 });
|
|
66
|
+
await pool.initialize();
|
|
67
|
+
pool.preserveWorkers();
|
|
68
|
+
|
|
69
|
+
console.log(`Worker pool: ${pool.workerCount} workers`);
|
|
70
|
+
console.log(`Iterations: ${iterations} (10 for 2000 inputs)`);
|
|
71
|
+
console.log();
|
|
72
|
+
|
|
73
|
+
const results: Array<{
|
|
74
|
+
inputs: number;
|
|
75
|
+
seqAvg: number;
|
|
76
|
+
parAvg: number;
|
|
77
|
+
speedup: number;
|
|
78
|
+
}> = [];
|
|
79
|
+
|
|
80
|
+
for (const inputCount of inputCounts) {
|
|
81
|
+
console.log(`--- ${inputCount} Inputs ---`);
|
|
82
|
+
|
|
83
|
+
const testIterations = inputCount >= 2000 ? 10 : iterations;
|
|
84
|
+
const tasks = allTasks.get(inputCount)!;
|
|
85
|
+
|
|
86
|
+
// Warmup sequential
|
|
87
|
+
for (let i = 0; i < 5; i++) {
|
|
88
|
+
for (const task of tasks[i]) {
|
|
89
|
+
signer.sign(task.hash);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Benchmark sequential
|
|
94
|
+
const seqTimes: number[] = [];
|
|
95
|
+
for (let i = 5; i < testIterations + 5; i++) {
|
|
96
|
+
const start = performance.now();
|
|
97
|
+
for (const task of tasks[i]) {
|
|
98
|
+
signer.sign(task.hash);
|
|
99
|
+
}
|
|
100
|
+
seqTimes.push(performance.now() - start);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Warmup parallel
|
|
104
|
+
for (let i = 0; i < 5; i++) {
|
|
105
|
+
await pool.signBatch(tasks[i], signer);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Benchmark parallel
|
|
109
|
+
const parTimes: number[] = [];
|
|
110
|
+
for (let i = 5; i < testIterations + 5; i++) {
|
|
111
|
+
const start = performance.now();
|
|
112
|
+
await pool.signBatch(tasks[i], signer);
|
|
113
|
+
parTimes.push(performance.now() - start);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const seqTotal = seqTimes.reduce((a, b) => a + b, 0);
|
|
117
|
+
const seqAvg = seqTotal / seqTimes.length;
|
|
118
|
+
const parTotal = parTimes.reduce((a, b) => a + b, 0);
|
|
119
|
+
const parAvg = parTotal / parTimes.length;
|
|
120
|
+
const speedup = seqAvg / parAvg;
|
|
121
|
+
|
|
122
|
+
console.log(` Sequential: ${seqAvg.toFixed(2)}ms avg (total: ${(seqTotal / 1000).toFixed(2)}s)`);
|
|
123
|
+
console.log(` Parallel: ${parAvg.toFixed(2)}ms avg (total: ${(parTotal / 1000).toFixed(2)}s)`);
|
|
124
|
+
console.log(` Speedup: ${speedup.toFixed(2)}x`);
|
|
125
|
+
console.log();
|
|
126
|
+
|
|
127
|
+
results.push({ inputs: inputCount, seqAvg, parAvg, speedup });
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
await pool.shutdown();
|
|
131
|
+
|
|
132
|
+
// Summary
|
|
133
|
+
console.log('='.repeat(70));
|
|
134
|
+
console.log(' SUMMARY');
|
|
135
|
+
console.log('='.repeat(70));
|
|
136
|
+
console.log();
|
|
137
|
+
console.log(' Inputs | Sequential (avg) | Parallel (avg) | Speedup');
|
|
138
|
+
console.log(' -------|------------------|----------------|--------');
|
|
139
|
+
for (const r of results) {
|
|
140
|
+
console.log(
|
|
141
|
+
` ${String(r.inputs).padStart(6)} | ${r.seqAvg.toFixed(2).padStart(14)}ms | ${r.parAvg.toFixed(2).padStart(12)}ms | ${r.speedup.toFixed(2).padStart(6)}x`,
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
console.log();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
main().catch(console.error);
|
package/browser/address.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { fromBech32, Bech32Result } from './bech32utils.js';
|
|
2
2
|
import { Network } from './networks.js';
|
|
3
|
+
import { Bytes20 } from './types.js';
|
|
3
4
|
export { fromBech32, type Bech32Result };
|
|
5
|
+
/** base58check decode result */
|
|
4
6
|
export interface Base58CheckResult {
|
|
5
|
-
hash
|
|
6
|
-
|
|
7
|
+
/** address hash */
|
|
8
|
+
readonly hash: Bytes20;
|
|
9
|
+
/** address version: 0x00 for P2PKH, 0x05 for P2SH */
|
|
10
|
+
readonly version: number;
|
|
7
11
|
}
|
|
8
12
|
export declare const FUTURE_SEGWIT_MAX_SIZE: number;
|
|
9
13
|
export declare const FUTURE_SEGWIT_MIN_SIZE: number;
|
|
@@ -12,11 +16,54 @@ export declare const FUTURE_MAX_VERSION: number;
|
|
|
12
16
|
export declare const FUTURE_OPNET_VERSION: number;
|
|
13
17
|
export declare const FUTURE_SEGWIT_MIN_VERSION: number;
|
|
14
18
|
export declare const FUTURE_SEGWIT_VERSION_DIFF: number;
|
|
15
|
-
export declare const isUnknownSegwitVersion: (output:
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
export declare const isUnknownSegwitVersion: (output: Uint8Array) => boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Encode a future Taproot-style segwit address (SegWit v2 - v16) using bech32m.
|
|
22
|
+
* Only for versions not yet assigned specific meanings (future use).
|
|
23
|
+
*
|
|
24
|
+
* @param output - Output script buffer containing the version and witness program
|
|
25
|
+
* @param network - Network object containing bech32 and optional bech32Opnet prefix
|
|
26
|
+
* @returns Bech32m-encoded future Taproot-style address
|
|
27
|
+
*/
|
|
28
|
+
export declare function toFutureOPNetAddress(output: Uint8Array, network: Network): string;
|
|
29
|
+
export declare function _toFutureSegwitAddress(output: Uint8Array, network: Network): string;
|
|
30
|
+
/**
|
|
31
|
+
* decode address with base58 specification, return address version and address hash if valid
|
|
32
|
+
*/
|
|
18
33
|
export declare function fromBase58Check(address: string): Base58CheckResult;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export declare function
|
|
34
|
+
/**
|
|
35
|
+
* encode address hash to base58 address with version
|
|
36
|
+
*/
|
|
37
|
+
export declare function toBase58Check(hash: Bytes20, version: number): string;
|
|
38
|
+
/**
|
|
39
|
+
* encode address hash to bech32 address with version and prefix
|
|
40
|
+
*/
|
|
41
|
+
export declare function toBech32(data: Uint8Array, version: number, prefix: string, prefixOpnet?: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* decode address from output script with network, return address if matched
|
|
44
|
+
*/
|
|
45
|
+
export declare function fromOutputScript(output: Uint8Array, network?: Network): string;
|
|
46
|
+
/**
|
|
47
|
+
* Options for toOutputScript function.
|
|
48
|
+
*/
|
|
49
|
+
export interface ToOutputScriptOptions {
|
|
50
|
+
/**
|
|
51
|
+
* Network to use for encoding. Defaults to bitcoin mainnet.
|
|
52
|
+
*/
|
|
53
|
+
readonly network?: Network;
|
|
54
|
+
/**
|
|
55
|
+
* Optional callback for future segwit version warnings.
|
|
56
|
+
* If provided, called with FUTURE_SEGWIT_VERSION_WARNING when encoding
|
|
57
|
+
* to a future segwit version (v2-v15) address.
|
|
58
|
+
* If not provided, no warning is emitted.
|
|
59
|
+
*/
|
|
60
|
+
readonly onFutureSegwitWarning?: (warning: string) => void;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Encodes address to output script with network, return output script if address matched.
|
|
64
|
+
* @param address - The address to encode
|
|
65
|
+
* @param networkOrOptions - Network or options object
|
|
66
|
+
* @returns The output script as Uint8Array
|
|
67
|
+
*/
|
|
68
|
+
export declare function toOutputScript(address: string, networkOrOptions?: Network | ToOutputScriptOptions): Uint8Array;
|
|
69
|
+
//# sourceMappingURL=address.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAE,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAS7C,OAAO,EAA4C,KAAK,OAAO,EAAoC,MAAM,YAAY,CAAC;AAEtH,OAAO,EAAE,UAAU,EAAE,KAAK,YAAY,EAAE,CAAC;AAEzC,gCAAgC;AAChC,MAAM,WAAW,iBAAiB;IAC9B,mBAAmB;IACnB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,qDAAqD;IACrD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC5B;AAED,eAAO,MAAM,sBAAsB,EAAE,MAAW,CAAC;AACjD,eAAO,MAAM,sBAAsB,EAAE,MAAU,CAAC;AAChD,eAAO,MAAM,yBAAyB,EAAE,MAAW,CAAC;AACpD,eAAO,MAAM,kBAAkB,EAAE,MAAW,CAAC;AAC7C,eAAO,MAAM,oBAAoB,EAAE,MAAW,CAAC;AAC/C,eAAO,MAAM,yBAAyB,EAAE,MAAU,CAAC;AACnD,eAAO,MAAM,0BAA0B,EAAE,MAAa,CAAC;AAOvD,eAAO,MAAM,sBAAsB,GAAI,QAAQ,UAAU,KAAG,OAkB3D,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAoCjF;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAgBnF;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,iBAAiB,CAWlE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CASpE;AAED;;GAEG;AACH,wBAAgB,QAAQ,CACpB,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,MAAM,GACrB,MAAM,CASR;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CA2B9E;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IAClC;;OAEG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,qBAAqB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC1B,OAAO,EAAE,MAAM,EACf,gBAAgB,CAAC,EAAE,OAAO,GAAG,qBAAqB,GACnD,UAAU,CAuEZ"}
|
package/browser/bech32utils.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
/** bech32 decode result */
|
|
1
2
|
export interface Bech32Result {
|
|
3
|
+
/** address version: 0x00 for P2WPKH、P2WSH, 0x01 for P2TR*/
|
|
2
4
|
version: number;
|
|
5
|
+
/** address prefix: bc for P2WPKH、P2WSH、P2TR */
|
|
3
6
|
prefix: string;
|
|
4
|
-
data
|
|
7
|
+
/** address data:20 bytes for P2WPKH, 32 bytes for P2WSH、P2TR */
|
|
8
|
+
data: Uint8Array;
|
|
5
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* decode address with bech32 specification, return address version、address prefix and address data if valid
|
|
12
|
+
*/
|
|
6
13
|
export declare function fromBech32(address: string): Bech32Result;
|
|
14
|
+
//# sourceMappingURL=bech32utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bech32utils.d.ts","sourceRoot":"","sources":["../src/bech32utils.ts"],"names":[],"mappings":"AAMA,2BAA2B;AAC3B,MAAM,WAAW,YAAY;IACzB,2DAA2D;IAC3D,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,gEAAgE;IAChE,IAAI,EAAE,UAAU,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,CAuBxD"}
|
package/browser/bip66.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/**
|
|
2
|
+
* DER-encoded signature components.
|
|
3
|
+
*/
|
|
4
|
+
export interface DerSignature {
|
|
5
|
+
readonly r: Uint8Array;
|
|
6
|
+
readonly s: Uint8Array;
|
|
7
|
+
}
|
|
8
|
+
export declare function check(buffer: Uint8Array): boolean;
|
|
9
|
+
export declare function decode(buffer: Uint8Array): DerSignature;
|
|
10
|
+
export declare function encode(r: Uint8Array, s: Uint8Array): Uint8Array;
|
|
11
|
+
//# sourceMappingURL=bip66.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bip66.d.ts","sourceRoot":"","sources":["../src/bip66.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,QAAQ,CAAC,CAAC,EAAE,UAAU,CAAC;IACvB,QAAQ,CAAC,CAAC,EAAE,UAAU,CAAC;CAC1B;AAED,wBAAgB,KAAK,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAsBjD;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,YAAY,CA6BvD;AAwBD,wBAAgB,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,UAAU,CAyB/D"}
|
package/browser/block.d.ts
CHANGED
|
@@ -1,29 +1,135 @@
|
|
|
1
1
|
import { Transaction } from './transaction.js';
|
|
2
|
+
import { Bytes32 } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a Bitcoin block with header fields and optional transactions.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { Block, fromHex } from '@btc-vision/bitcoin';
|
|
9
|
+
*
|
|
10
|
+
* // Parse a block from hex
|
|
11
|
+
* const block = Block.fromHex('0100000000000000...');
|
|
12
|
+
*
|
|
13
|
+
* // Access block properties
|
|
14
|
+
* console.log(block.version);
|
|
15
|
+
* console.log(block.getId());
|
|
16
|
+
* console.log(block.timestamp);
|
|
17
|
+
*
|
|
18
|
+
* // Check proof of work
|
|
19
|
+
* if (block.checkProofOfWork()) {
|
|
20
|
+
* console.log('Valid PoW');
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
2
24
|
export declare class Block {
|
|
25
|
+
#private;
|
|
26
|
+
/** Block version number */
|
|
3
27
|
version: number;
|
|
4
|
-
|
|
5
|
-
|
|
28
|
+
/** Hash of the previous block (32 bytes) */
|
|
29
|
+
prevHash?: Bytes32;
|
|
30
|
+
/** Merkle root of the transactions (32 bytes) */
|
|
31
|
+
merkleRoot?: Bytes32;
|
|
32
|
+
/** Block timestamp (Unix time) */
|
|
6
33
|
timestamp: number;
|
|
7
|
-
|
|
34
|
+
/** Witness commitment for SegWit blocks (32 bytes) */
|
|
35
|
+
witnessCommit?: Bytes32;
|
|
36
|
+
/** Compact representation of the target threshold */
|
|
8
37
|
bits: number;
|
|
38
|
+
/** Nonce used for proof of work */
|
|
9
39
|
nonce: number;
|
|
40
|
+
/** Array of transactions included in the block */
|
|
10
41
|
transactions?: Transaction[];
|
|
11
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Parses a Block from a Uint8Array.
|
|
44
|
+
* @param buffer - The raw block data (minimum 80 bytes for header only)
|
|
45
|
+
* @returns Parsed Block instance
|
|
46
|
+
* @throws Error if buffer is too small
|
|
47
|
+
*/
|
|
48
|
+
static fromBuffer(buffer: Uint8Array): Block;
|
|
49
|
+
/**
|
|
50
|
+
* Parses a Block from a hex string.
|
|
51
|
+
* @param hex - Hexadecimal representation of the block
|
|
52
|
+
* @returns Parsed Block instance
|
|
53
|
+
*/
|
|
12
54
|
static fromHex(hex: string): Block;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Calculates the target threshold from the compact bits representation.
|
|
57
|
+
* @param bits - Compact bits value from block header
|
|
58
|
+
* @returns 32-byte target threshold
|
|
59
|
+
*/
|
|
60
|
+
static calculateTarget(bits: number): Bytes32;
|
|
61
|
+
/**
|
|
62
|
+
* Calculates the merkle root for a list of transactions.
|
|
63
|
+
* @param transactions - Array of transactions
|
|
64
|
+
* @param forWitness - If true, calculate witness merkle root (for SegWit)
|
|
65
|
+
* @returns 32-byte merkle root hash
|
|
66
|
+
* @throws TypeError if transactions is empty or not an array
|
|
67
|
+
*/
|
|
68
|
+
static calculateMerkleRoot(transactions: Transaction[], forWitness?: boolean): Bytes32;
|
|
69
|
+
/**
|
|
70
|
+
* Extracts the witness commitment from the coinbase transaction.
|
|
71
|
+
* @returns 32-byte witness commitment or null if not found
|
|
72
|
+
*/
|
|
73
|
+
getWitnessCommit(): Bytes32 | null;
|
|
74
|
+
/**
|
|
75
|
+
* Checks if this block has a witness commitment.
|
|
76
|
+
* @returns True if the block has a witness commitment
|
|
77
|
+
*/
|
|
16
78
|
hasWitnessCommit(): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Checks if any transaction in this block has witness data.
|
|
81
|
+
* @returns True if any transaction has witness data
|
|
82
|
+
*/
|
|
17
83
|
hasWitness(): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Calculates the weight of this block.
|
|
86
|
+
* Weight = (base size * 3) + total size
|
|
87
|
+
* @returns Block weight in weight units
|
|
88
|
+
*/
|
|
18
89
|
weight(): number;
|
|
90
|
+
/**
|
|
91
|
+
* Calculates the serialized byte length of this block.
|
|
92
|
+
* @param headersOnly - If true, return only header size (80 bytes)
|
|
93
|
+
* @param allowWitness - If true, include witness data in calculation
|
|
94
|
+
* @returns Byte length of the serialized block
|
|
95
|
+
*/
|
|
19
96
|
byteLength(headersOnly?: boolean, allowWitness?: boolean): number;
|
|
20
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Computes the double-SHA256 hash of the block header.
|
|
99
|
+
* @returns 32-byte block hash
|
|
100
|
+
*/
|
|
101
|
+
getHash(): Bytes32;
|
|
102
|
+
/**
|
|
103
|
+
* Returns the block ID (hash in reversed hex format, as displayed in block explorers).
|
|
104
|
+
* @returns Block ID as hex string
|
|
105
|
+
*/
|
|
21
106
|
getId(): string;
|
|
107
|
+
/**
|
|
108
|
+
* Converts the block timestamp to a Date object.
|
|
109
|
+
* @returns UTC date of the block
|
|
110
|
+
*/
|
|
22
111
|
getUTCDate(): Date;
|
|
23
|
-
|
|
112
|
+
/**
|
|
113
|
+
* Serializes the block to a Uint8Array.
|
|
114
|
+
* @param headersOnly - If true, only serialize the 80-byte header
|
|
115
|
+
* @returns Serialized block data
|
|
116
|
+
*/
|
|
117
|
+
toBuffer(headersOnly?: boolean): Uint8Array;
|
|
118
|
+
/**
|
|
119
|
+
* Serializes the block to a hex string.
|
|
120
|
+
* @param headersOnly - If true, only serialize the 80-byte header
|
|
121
|
+
* @returns Hex string representation of the block
|
|
122
|
+
*/
|
|
24
123
|
toHex(headersOnly?: boolean): string;
|
|
124
|
+
/**
|
|
125
|
+
* Validates the merkle root and witness commitment (if present).
|
|
126
|
+
* @returns True if the transaction roots are valid
|
|
127
|
+
*/
|
|
25
128
|
checkTxRoots(): boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Validates that the block hash meets the target threshold (proof of work).
|
|
131
|
+
* @returns True if the block's proof of work is valid
|
|
132
|
+
*/
|
|
26
133
|
checkProofOfWork(): boolean;
|
|
27
|
-
private __checkMerkleRoot;
|
|
28
|
-
private __checkWitnessCommit;
|
|
29
134
|
}
|
|
135
|
+
//# sourceMappingURL=block.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../src/block.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAO1C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,KAAK;;IACd,2BAA2B;IAC3B,OAAO,EAAE,MAAM,CAAK;IACpB,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,OAAO,CAAa;IAC/B,iDAAiD;IACjD,UAAU,CAAC,EAAE,OAAO,CAAa;IACjC,kCAAkC;IAClC,SAAS,EAAE,MAAM,CAAK;IACtB,sDAAsD;IACtD,aAAa,CAAC,EAAE,OAAO,CAAa;IACpC,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAK;IACjB,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAK;IAClB,kDAAkD;IAClD,YAAY,CAAC,EAAE,WAAW,EAAE,CAAa;IAEzC;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,KAAK;IAuC5C;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK;IAIlC;;;;OAIG;IACH,MAAM,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAY7C;;;;;;OAMG;IACH,MAAM,CAAC,mBAAmB,CAAC,YAAY,EAAE,WAAW,EAAE,EAAE,UAAU,CAAC,EAAE,OAAO,GAAG,OAAO;IAqBtF;;;OAGG;IACH,gBAAgB,IAAI,OAAO,GAAG,IAAI;IAkBlC;;;OAGG;IACH,gBAAgB,IAAI,OAAO;IAO3B;;;OAGG;IACH,UAAU,IAAI,OAAO;IAIrB;;;;OAIG;IACH,MAAM,IAAI,MAAM;IAMhB;;;;;OAKG;IACH,UAAU,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,YAAY,GAAE,OAAc,GAAG,MAAM;IAUvE;;;OAGG;IACH,OAAO,IAAI,OAAO;IAIlB;;;OAGG;IACH,KAAK,IAAI,MAAM;IAIf;;;OAGG;IACH,UAAU,IAAI,IAAI;IAOlB;;;;OAIG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,GAAG,UAAU;IA4B3C;;;;OAIG;IACH,KAAK,CAAC,WAAW,CAAC,EAAE,OAAO,GAAG,MAAM;IAIpC;;;OAGG;IACH,YAAY,IAAI,OAAO;IAQvB;;;OAGG;IACH,gBAAgB,IAAI,OAAO;CAuB9B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Branded type definitions for type-safe primitives.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
declare const __brand: unique symbol;
|
|
7
|
+
type Brand<T, B extends string> = T & {
|
|
8
|
+
readonly [__brand]: B;
|
|
9
|
+
};
|
|
10
|
+
export type Bytes32 = Brand<Uint8Array, 'Bytes32'>;
|
|
11
|
+
export type Bytes20 = Brand<Uint8Array, 'Bytes20'>;
|
|
12
|
+
export type PublicKey = Brand<Uint8Array, 'PublicKey'>;
|
|
13
|
+
export type XOnlyPublicKey = Brand<Uint8Array, 'XOnlyPublicKey'>;
|
|
14
|
+
export type Satoshi = Brand<bigint, 'Satoshi'>;
|
|
15
|
+
export type PrivateKey = Brand<Uint8Array, 'PrivateKey'>;
|
|
16
|
+
export type Signature = Brand<Uint8Array, 'Signature'>;
|
|
17
|
+
export type SchnorrSignature = Brand<Uint8Array, 'SchnorrSignature'>;
|
|
18
|
+
export type Script = Brand<Uint8Array, 'Script'>;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=branded.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"branded.d.ts","sourceRoot":"","sources":["../src/branded.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,CAAC,MAAM,OAAO,EAAE,OAAO,MAAM,CAAC;AACrC,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,IAAI,CAAC,GAAG;IAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;CAAE,CAAC;AAEhE,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AACnD,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AACnD,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;AACvD,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC;AACjE,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAC/C,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;AACzD,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;AACvD,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;AACrE,MAAM,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/crypto/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC"}
|