@btc-vision/bitcoin 6.5.6 → 7.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HOW_TO_WRITE_GOOD_CODE.md +2436 -0
- package/benchmark/psbt-2000-inputs.bench.ts +178 -0
- package/benchmark/signing.bench.ts +147 -0
- package/browser/address.d.ts +57 -10
- package/browser/address.d.ts.map +1 -0
- package/browser/bech32utils.d.ts +9 -1
- package/browser/bech32utils.d.ts.map +1 -0
- package/browser/bip66.d.ts +11 -6
- package/browser/bip66.d.ts.map +1 -0
- package/browser/block.d.ts +117 -11
- package/browser/block.d.ts.map +1 -0
- package/browser/branded.d.ts +20 -0
- package/browser/branded.d.ts.map +1 -0
- package/browser/crypto/crypto.d.ts +1 -0
- package/browser/crypto/crypto.d.ts.map +1 -0
- package/browser/crypto.d.ts +46 -7
- package/browser/crypto.d.ts.map +1 -0
- package/browser/ecc/context.d.ts +129 -0
- package/browser/ecc/context.d.ts.map +1 -0
- package/browser/ecc/index.d.ts +11 -0
- package/browser/ecc/index.d.ts.map +1 -0
- package/browser/ecc/types.d.ts +128 -0
- package/browser/ecc/types.d.ts.map +1 -0
- package/browser/ecpair.d.ts +99 -0
- package/browser/errors.d.ts +124 -0
- package/browser/errors.d.ts.map +1 -0
- package/browser/index.d.ts +32 -5
- package/browser/index.d.ts.map +1 -0
- package/browser/index.js +12477 -101
- package/browser/io/BinaryReader.d.ts +276 -0
- package/browser/io/BinaryReader.d.ts.map +1 -0
- package/browser/io/BinaryWriter.d.ts +391 -0
- package/browser/io/BinaryWriter.d.ts.map +1 -0
- package/browser/io/MemoryPool.d.ts +220 -0
- package/browser/io/MemoryPool.d.ts.map +1 -0
- package/browser/io/base64.d.ts +13 -0
- package/browser/io/base64.d.ts.map +1 -0
- package/browser/io/hex.d.ts +67 -0
- package/browser/io/hex.d.ts.map +1 -0
- package/browser/io/index.d.ts +17 -0
- package/browser/io/index.d.ts.map +1 -0
- package/browser/io/utils.d.ts +199 -0
- package/browser/io/utils.d.ts.map +1 -0
- package/browser/merkle.d.ts +10 -1
- package/browser/merkle.d.ts.map +1 -0
- package/browser/networks.d.ts +70 -9
- package/browser/networks.d.ts.map +1 -0
- package/browser/opcodes.d.ts +1 -0
- package/browser/opcodes.d.ts.map +1 -0
- package/browser/payments/bip341.d.ts +35 -9
- package/browser/payments/bip341.d.ts.map +1 -0
- package/browser/payments/embed.d.ts +112 -1
- package/browser/payments/embed.d.ts.map +1 -0
- package/browser/payments/index.d.ts +17 -10
- package/browser/payments/index.d.ts.map +1 -0
- package/browser/payments/p2ms.d.ts +150 -0
- package/browser/payments/p2ms.d.ts.map +1 -0
- package/browser/payments/p2op.d.ts +150 -24
- package/browser/payments/p2op.d.ts.map +1 -0
- package/browser/payments/p2pk.d.ts +154 -1
- package/browser/payments/p2pk.d.ts.map +1 -0
- package/browser/payments/p2pkh.d.ts +176 -1
- package/browser/payments/p2pkh.d.ts.map +1 -0
- package/browser/payments/p2sh.d.ts +150 -1
- package/browser/payments/p2sh.d.ts.map +1 -0
- package/browser/payments/p2tr.d.ts +185 -1
- package/browser/payments/p2tr.d.ts.map +1 -0
- package/browser/payments/p2wpkh.d.ts +161 -1
- package/browser/payments/p2wpkh.d.ts.map +1 -0
- package/browser/payments/p2wsh.d.ts +146 -1
- package/browser/payments/p2wsh.d.ts.map +1 -0
- package/browser/payments/types.d.ts +94 -64
- package/browser/payments/types.d.ts.map +1 -0
- package/browser/psbt/bip371.d.ts +34 -8
- package/browser/psbt/bip371.d.ts.map +1 -0
- package/browser/psbt/psbtutils.d.ts +56 -16
- package/browser/psbt/psbtutils.d.ts.map +1 -0
- package/browser/psbt/types.d.ts +245 -0
- package/browser/psbt/types.d.ts.map +1 -0
- package/browser/psbt/utils.d.ts +64 -0
- package/browser/psbt/utils.d.ts.map +1 -0
- package/browser/psbt/validation.d.ts +84 -0
- package/browser/psbt/validation.d.ts.map +1 -0
- package/browser/psbt.d.ts +82 -118
- package/browser/psbt.d.ts.map +1 -0
- package/browser/pubkey.d.ts +27 -6
- package/browser/pubkey.d.ts.map +1 -0
- package/browser/push_data.d.ts +24 -2
- package/browser/push_data.d.ts.map +1 -0
- package/browser/script.d.ts +33 -8
- package/browser/script.d.ts.map +1 -0
- package/browser/script_number.d.ts +17 -0
- package/browser/script_number.d.ts.map +1 -0
- package/browser/script_signature.d.ts +23 -5
- package/browser/script_signature.d.ts.map +1 -0
- package/browser/transaction.d.ts +160 -18
- package/browser/transaction.d.ts.map +1 -0
- package/browser/types.d.ts +36 -38
- package/browser/types.d.ts.map +1 -0
- package/browser/workers/WorkerSigningPool.d.ts +143 -0
- package/browser/workers/WorkerSigningPool.d.ts.map +1 -0
- package/browser/workers/WorkerSigningPool.node.d.ts +116 -0
- package/browser/workers/WorkerSigningPool.node.d.ts.map +1 -0
- package/browser/workers/ecc-bundle.d.ts +25 -0
- package/browser/workers/ecc-bundle.d.ts.map +1 -0
- package/browser/workers/index.d.ts +91 -0
- package/browser/workers/index.d.ts.map +1 -0
- package/browser/workers/psbt-parallel.d.ts +88 -0
- package/browser/workers/psbt-parallel.d.ts.map +1 -0
- package/browser/workers/signing-worker.d.ts +37 -0
- package/browser/workers/signing-worker.d.ts.map +1 -0
- package/browser/workers/types.d.ts +365 -0
- package/browser/workers/types.d.ts.map +1 -0
- package/build/address.d.ts +58 -11
- package/build/address.d.ts.map +1 -0
- package/build/address.js +82 -25
- package/build/address.js.map +1 -0
- package/build/bech32utils.d.ts +9 -1
- package/build/bech32utils.d.ts.map +1 -0
- package/build/bech32utils.js +10 -2
- package/build/bech32utils.js.map +1 -0
- package/build/bip66.d.ts +11 -6
- package/build/bip66.d.ts.map +1 -0
- package/build/bip66.js +32 -3
- package/build/bip66.js.map +1 -0
- package/build/block.d.ts +117 -11
- package/build/block.d.ts.map +1 -0
- package/build/block.js +202 -72
- package/build/block.js.map +1 -0
- package/build/branded.d.ts +20 -0
- package/build/branded.d.ts.map +1 -0
- package/build/branded.js +7 -0
- package/build/branded.js.map +1 -0
- package/build/crypto/crypto.d.ts +1 -0
- package/build/crypto/crypto.d.ts.map +1 -0
- package/build/crypto/crypto.js +1 -0
- package/build/crypto/crypto.js.map +1 -0
- package/build/crypto.d.ts +46 -7
- package/build/crypto.d.ts.map +1 -0
- package/build/crypto.js +65 -20
- package/build/crypto.js.map +1 -0
- package/build/ecc/context.d.ts +135 -0
- package/build/ecc/context.d.ts.map +1 -0
- package/build/ecc/context.js +232 -0
- package/build/ecc/context.js.map +1 -0
- package/build/ecc/index.d.ts +11 -0
- package/build/ecc/index.d.ts.map +1 -0
- package/build/ecc/index.js +11 -0
- package/build/ecc/index.js.map +1 -0
- package/build/ecc/types.d.ts +134 -0
- package/build/ecc/types.d.ts.map +1 -0
- package/build/ecc/types.js +8 -0
- package/build/ecc/types.js.map +1 -0
- package/build/errors.d.ts +124 -0
- package/build/errors.d.ts.map +1 -0
- package/build/errors.js +155 -0
- package/build/errors.js.map +1 -0
- package/build/index.d.ts +32 -5
- package/build/index.d.ts.map +1 -0
- package/build/index.js +26 -3
- package/build/index.js.map +1 -0
- package/build/io/BinaryReader.d.ts +276 -0
- package/build/io/BinaryReader.d.ts.map +1 -0
- package/build/io/BinaryReader.js +425 -0
- package/build/io/BinaryReader.js.map +1 -0
- package/build/io/BinaryWriter.d.ts +391 -0
- package/build/io/BinaryWriter.d.ts.map +1 -0
- package/build/io/BinaryWriter.js +611 -0
- package/build/io/BinaryWriter.js.map +1 -0
- package/build/io/MemoryPool.d.ts +220 -0
- package/build/io/MemoryPool.d.ts.map +1 -0
- package/build/io/MemoryPool.js +309 -0
- package/build/io/MemoryPool.js.map +1 -0
- package/build/io/base64.d.ts +13 -0
- package/build/io/base64.d.ts.map +1 -0
- package/build/io/base64.js +20 -0
- package/build/io/base64.js.map +1 -0
- package/build/io/hex.d.ts +67 -0
- package/build/io/hex.d.ts.map +1 -0
- package/build/io/hex.js +138 -0
- package/build/io/hex.js.map +1 -0
- package/build/io/index.d.ts +17 -0
- package/build/io/index.d.ts.map +1 -0
- package/build/io/index.js +23 -0
- package/build/io/index.js.map +1 -0
- package/build/io/utils.d.ts +199 -0
- package/build/io/utils.d.ts.map +1 -0
- package/build/io/utils.js +271 -0
- package/build/io/utils.js.map +1 -0
- package/build/merkle.d.ts +10 -1
- package/build/merkle.d.ts.map +1 -0
- package/build/merkle.js +12 -1
- package/build/merkle.js.map +1 -0
- package/build/networks.d.ts +70 -9
- package/build/networks.d.ts.map +1 -0
- package/build/networks.js +90 -4
- package/build/networks.js.map +1 -0
- package/build/opcodes.d.ts +1 -0
- package/build/opcodes.d.ts.map +1 -0
- package/build/opcodes.js +1 -0
- package/build/opcodes.js.map +1 -0
- package/build/payments/bip341.d.ts +35 -9
- package/build/payments/bip341.d.ts.map +1 -0
- package/build/payments/bip341.js +34 -15
- package/build/payments/bip341.js.map +1 -0
- package/build/payments/embed.d.ts +120 -1
- package/build/payments/embed.d.ts.map +1 -0
- package/build/payments/embed.js +215 -34
- package/build/payments/embed.js.map +1 -0
- package/build/payments/index.d.ts +17 -10
- package/build/payments/index.d.ts.map +1 -0
- package/build/payments/index.js +20 -10
- package/build/payments/index.js.map +1 -0
- package/build/payments/p2ms.d.ts +159 -1
- package/build/payments/p2ms.d.ts.map +1 -0
- package/build/payments/p2ms.js +427 -108
- package/build/payments/p2ms.js.map +1 -0
- package/build/payments/p2op.d.ts +158 -24
- package/build/payments/p2op.d.ts.map +1 -0
- package/build/payments/p2op.js +379 -93
- package/build/payments/p2op.js.map +1 -0
- package/build/payments/p2pk.d.ts +162 -1
- package/build/payments/p2pk.d.ts.map +1 -0
- package/build/payments/p2pk.js +327 -58
- package/build/payments/p2pk.js.map +1 -0
- package/build/payments/p2pkh.d.ts +185 -1
- package/build/payments/p2pkh.d.ts.map +1 -0
- package/build/payments/p2pkh.js +467 -114
- package/build/payments/p2pkh.js.map +1 -0
- package/build/payments/p2sh.d.ts +159 -1
- package/build/payments/p2sh.d.ts.map +1 -0
- package/build/payments/p2sh.js +500 -150
- package/build/payments/p2sh.js.map +1 -0
- package/build/payments/p2tr.d.ts +193 -1
- package/build/payments/p2tr.d.ts.map +1 -0
- package/build/payments/p2tr.js +592 -174
- package/build/payments/p2tr.js.map +1 -0
- package/build/payments/p2wpkh.d.ts +170 -1
- package/build/payments/p2wpkh.d.ts.map +1 -0
- package/build/payments/p2wpkh.js +428 -103
- package/build/payments/p2wpkh.js.map +1 -0
- package/build/payments/p2wsh.d.ts +155 -1
- package/build/payments/p2wsh.d.ts.map +1 -0
- package/build/payments/p2wsh.js +465 -143
- package/build/payments/p2wsh.js.map +1 -0
- package/build/payments/types.d.ts +98 -64
- package/build/payments/types.d.ts.map +1 -0
- package/build/payments/types.js +17 -13
- package/build/payments/types.js.map +1 -0
- package/build/psbt/bip371.d.ts +35 -9
- package/build/psbt/bip371.d.ts.map +1 -0
- package/build/psbt/bip371.js +117 -28
- package/build/psbt/bip371.js.map +1 -0
- package/build/psbt/psbtutils.d.ts +56 -16
- package/build/psbt/psbtutils.d.ts.map +1 -0
- package/build/psbt/psbtutils.js +71 -16
- package/build/psbt/psbtutils.js.map +1 -0
- package/build/psbt/types.d.ts +249 -0
- package/build/psbt/types.d.ts.map +1 -0
- package/build/psbt/types.js +6 -0
- package/build/psbt/types.js.map +1 -0
- package/build/psbt/utils.d.ts +68 -0
- package/build/psbt/utils.d.ts.map +1 -0
- package/build/psbt/utils.js +171 -0
- package/build/psbt/utils.js.map +1 -0
- package/build/psbt/validation.d.ts +88 -0
- package/build/psbt/validation.d.ts.map +1 -0
- package/build/psbt/validation.js +149 -0
- package/build/psbt/validation.js.map +1 -0
- package/build/psbt.d.ts +84 -120
- package/build/psbt.d.ts.map +1 -0
- package/build/psbt.js +406 -413
- package/build/psbt.js.map +1 -0
- package/build/pubkey.d.ts +27 -6
- package/build/pubkey.d.ts.map +1 -0
- package/build/pubkey.js +36 -12
- package/build/pubkey.js.map +1 -0
- package/build/push_data.d.ts +24 -2
- package/build/push_data.d.ts.map +1 -0
- package/build/push_data.js +44 -12
- package/build/push_data.js.map +1 -0
- package/build/script.d.ts +33 -8
- package/build/script.d.ts.map +1 -0
- package/build/script.js +101 -37
- package/build/script.js.map +1 -0
- package/build/script_number.d.ts +17 -0
- package/build/script_number.d.ts.map +1 -0
- package/build/script_number.js +19 -0
- package/build/script_number.js.map +1 -0
- package/build/script_signature.d.ts +23 -5
- package/build/script_signature.d.ts.map +1 -0
- package/build/script_signature.js +48 -15
- package/build/script_signature.js.map +1 -0
- package/build/transaction.d.ts +160 -18
- package/build/transaction.d.ts.map +1 -0
- package/build/transaction.js +443 -176
- package/build/transaction.js.map +1 -0
- package/build/tsconfig.build.tsbuildinfo +1 -0
- package/build/types.d.ts +36 -38
- package/build/types.d.ts.map +1 -0
- package/build/types.js +169 -57
- package/build/types.js.map +1 -0
- package/build/workers/WorkerSigningPool.d.ts +174 -0
- package/build/workers/WorkerSigningPool.d.ts.map +1 -0
- package/build/workers/WorkerSigningPool.js +553 -0
- package/build/workers/WorkerSigningPool.js.map +1 -0
- package/build/workers/WorkerSigningPool.node.d.ts +124 -0
- package/build/workers/WorkerSigningPool.node.d.ts.map +1 -0
- package/build/workers/WorkerSigningPool.node.js +753 -0
- package/build/workers/WorkerSigningPool.node.js.map +1 -0
- package/build/workers/ecc-bundle.d.ts +25 -0
- package/build/workers/ecc-bundle.d.ts.map +1 -0
- package/build/workers/ecc-bundle.js +25 -0
- package/build/workers/ecc-bundle.js.map +1 -0
- package/build/workers/index.d.ts +91 -0
- package/build/workers/index.d.ts.map +1 -0
- package/build/workers/index.js +114 -0
- package/build/workers/index.js.map +1 -0
- package/build/workers/psbt-parallel.d.ts +117 -0
- package/build/workers/psbt-parallel.d.ts.map +1 -0
- package/build/workers/psbt-parallel.js +233 -0
- package/build/workers/psbt-parallel.js.map +1 -0
- package/build/workers/signing-worker.d.ts +37 -0
- package/build/workers/signing-worker.d.ts.map +1 -0
- package/build/workers/signing-worker.js +350 -0
- package/build/workers/signing-worker.js.map +1 -0
- package/build/workers/types.d.ts +365 -0
- package/build/workers/types.d.ts.map +1 -0
- package/build/workers/types.js +60 -0
- package/build/workers/types.js.map +1 -0
- package/package.json +68 -9
- package/scripts/bundle-ecc.ts +111 -0
- package/src/address.ts +91 -45
- package/src/bech32utils.ts +3 -3
- package/src/bip66.ts +34 -24
- package/src/block.ts +205 -86
- package/src/branded.ts +18 -0
- package/src/crypto.ts +64 -26
- package/src/ecc/context.ts +280 -0
- package/src/ecc/index.ts +14 -0
- package/src/ecc/types.ts +147 -0
- package/src/ecpair.d.ts +99 -0
- package/src/errors.ts +163 -0
- package/src/index.ts +112 -9
- package/src/io/BinaryReader.ts +461 -0
- package/src/io/BinaryWriter.ts +696 -0
- package/src/io/MemoryPool.ts +343 -0
- package/src/io/base64.ts +20 -0
- package/src/io/hex.ts +155 -0
- package/src/io/index.ts +41 -0
- package/src/io/utils.ts +283 -0
- package/src/merkle.ts +14 -9
- package/src/networks.ts +9 -9
- package/src/payments/bip341.ts +32 -33
- package/src/payments/embed.ts +244 -41
- package/src/payments/index.ts +12 -10
- package/src/payments/p2ms.ts +497 -118
- package/src/payments/p2op.ts +432 -134
- package/src/payments/p2pk.ts +370 -72
- package/src/payments/p2pkh.ts +524 -130
- package/src/payments/p2sh.ts +572 -169
- package/src/payments/p2tr.ts +686 -194
- package/src/payments/p2wpkh.ts +482 -105
- package/src/payments/p2wsh.ts +524 -162
- package/src/payments/types.ts +80 -66
- package/src/psbt/bip371.ts +72 -51
- package/src/psbt/psbtutils.ts +39 -40
- package/src/psbt/types.ts +324 -0
- package/src/psbt/utils.ts +188 -0
- package/src/psbt/validation.ts +185 -0
- package/src/psbt.ts +608 -827
- package/src/pubkey.ts +22 -23
- package/src/push_data.ts +18 -16
- package/src/script.ts +81 -66
- package/src/script_number.ts +6 -6
- package/src/script_signature.ts +33 -36
- package/src/transaction.ts +462 -239
- package/src/types.ts +229 -100
- package/src/workers/WorkerSigningPool.node.ts +887 -0
- package/src/workers/WorkerSigningPool.ts +666 -0
- package/src/workers/ecc-bundle.ts +26 -0
- package/src/workers/index.ts +165 -0
- package/src/workers/psbt-parallel.ts +327 -0
- package/src/workers/signing-worker.ts +353 -0
- package/src/workers/types.ts +417 -0
- package/test/address.spec.ts +9 -6
- package/test/bitcoin.core.spec.ts +16 -17
- package/test/block.spec.ts +8 -7
- package/test/bufferutils.spec.ts +228 -214
- package/test/crypto.spec.ts +19 -11
- package/test/fixtures/p2pk.json +0 -8
- package/test/fixtures/p2pkh.json +1 -1
- package/test/fixtures/p2sh.json +1 -1
- package/test/fixtures/script.json +1 -1
- package/test/fixtures/transaction.json +2 -2
- package/test/integration/_regtest.ts +25 -0
- package/test/integration/addresses.spec.ts +4 -3
- package/test/integration/bip32.spec.ts +2 -1
- package/test/integration/blocks.spec.ts +1 -1
- package/test/integration/cltv.spec.ts +18 -16
- package/test/integration/csv.spec.ts +37 -64
- package/test/integration/payments.spec.ts +5 -3
- package/test/integration/taproot.spec.ts +76 -83
- package/test/integration/transactions.spec.ts +38 -35
- package/test/payments.spec.ts +35 -13
- package/test/payments.utils.ts +17 -16
- package/test/psbt.spec.ts +111 -100
- package/test/script.spec.ts +11 -10
- package/test/script_signature.spec.ts +9 -11
- package/test/taproot-cache.spec.ts +694 -0
- package/test/transaction.spec.ts +32 -40
- package/test/types.spec.ts +74 -29
- package/test/workers-pool.spec.ts +963 -0
- package/test/workers-signing.spec.ts +635 -0
- package/test/workers.spec.ts +1390 -0
- package/tsconfig.base.json +34 -18
- package/tsconfig.browser.json +15 -0
- package/tsconfig.build.json +5 -0
- package/tsconfig.json +5 -14
- package/typedoc.json +29 -0
- package/vite.config.browser.ts +3 -42
- package/vitest.config.integration.ts +2 -0
- package/browser/bufferutils.d.ts +0 -34
- package/browser/chunks/crypto-BhCpKpek.js +0 -2033
- package/browser/chunks/payments-B1wlSccx.js +0 -1089
- package/browser/chunks/psbt-BCNk7JUx.js +0 -4055
- package/browser/chunks/script-DyPItFEl.js +0 -318
- package/browser/chunks/transaction-C_UbhMGn.js +0 -432
- package/browser/chunks/utils-DNZi-T5W.js +0 -761
- package/browser/ecc_lib.d.ts +0 -3
- package/browser/hooks/AdvancedSignatureManager.d.ts +0 -16
- package/browser/hooks/HookedSigner.d.ts +0 -4
- package/browser/hooks/SignatureManager.d.ts +0 -13
- package/browser/payments/lazy.d.ts +0 -2
- package/browser/typeforce.d.ts +0 -38
- package/build/bufferutils.d.ts +0 -34
- package/build/bufferutils.js +0 -141
- package/build/ecc_lib.d.ts +0 -3
- package/build/ecc_lib.js +0 -61
- package/build/hooks/AdvancedSignatureManager.d.ts +0 -16
- package/build/hooks/AdvancedSignatureManager.js +0 -52
- package/build/hooks/HookedSigner.d.ts +0 -4
- package/build/hooks/HookedSigner.js +0 -64
- package/build/hooks/SignatureManager.d.ts +0 -13
- package/build/hooks/SignatureManager.js +0 -45
- package/build/payments/lazy.d.ts +0 -2
- package/build/payments/lazy.js +0 -28
- package/build/tsconfig.tsbuildinfo +0 -1
- package/src/bufferutils.ts +0 -188
- package/src/ecc_lib.ts +0 -94
- package/src/hooks/AdvancedSignatureManager.ts +0 -104
- package/src/hooks/HookedSigner.ts +0 -108
- package/src/hooks/SignatureManager.ts +0 -84
- package/src/payments/lazy.ts +0 -28
- package/src/typeforce.d.ts +0 -38
- package/tsconfig.webpack.json +0 -18
package/build/address.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Network } from './networks.js';
|
|
1
|
+
import { type Bech32Result, fromBech32 } from './bech32utils.js';
|
|
2
|
+
import type { Network } from './networks.js';
|
|
3
|
+
import { type 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,KAAK,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAU7C,OAAO,EACH,KAAK,OAAO,EAOf,MAAM,YAAY,CAAC;AAEpB,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;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;GAKG;AACH,wBAAgB,cAAc,CAC1B,OAAO,EAAE,MAAM,EACf,gBAAgB,CAAC,EAAE,OAAO,GAAG,qBAAqB,GACnD,UAAU,CAwEZ"}
|
package/build/address.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bitcoin address decode and encode tools, include base58、bech32 and output script
|
|
3
|
+
*
|
|
4
|
+
* networks support bitcoin、bitcoin testnet and bitcoin regtest
|
|
5
|
+
*
|
|
6
|
+
* addresses support P2PKH、P2SH、P2WPKH、P2WSH、P2TR and so on
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
1
10
|
import { bech32, bech32m } from 'bech32';
|
|
2
11
|
import * as bs58check from 'bs58check';
|
|
3
12
|
import { fromBech32 } from './bech32utils.js';
|
|
13
|
+
import { alloc } from './io/index.js';
|
|
4
14
|
import * as networks from './networks.js';
|
|
5
15
|
import { p2op } from './payments/p2op.js';
|
|
6
16
|
import { p2pkh } from './payments/p2pkh.js';
|
|
@@ -10,7 +20,7 @@ import { p2wpkh } from './payments/p2wpkh.js';
|
|
|
10
20
|
import { p2wsh } from './payments/p2wsh.js';
|
|
11
21
|
import * as bscript from './script.js';
|
|
12
22
|
import { opcodes } from './script.js';
|
|
13
|
-
import {
|
|
23
|
+
import { isBytes20, isUInt8, toBytes20, toBytes32, } from './types.js';
|
|
14
24
|
export { fromBech32 };
|
|
15
25
|
export const FUTURE_SEGWIT_MAX_SIZE = 40;
|
|
16
26
|
export const FUTURE_SEGWIT_MIN_SIZE = 2;
|
|
@@ -25,7 +35,7 @@ const FUTURE_SEGWIT_VERSION_WARNING = 'WARNING: Sending to a future segwit versi
|
|
|
25
35
|
'then decide when it is safe to use which version of segwit.';
|
|
26
36
|
export const isUnknownSegwitVersion = (output) => {
|
|
27
37
|
try {
|
|
28
|
-
const data =
|
|
38
|
+
const data = output.subarray(2);
|
|
29
39
|
if (data.length < FUTURE_SEGWIT_MIN_SIZE || data.length > FUTURE_SEGWIT_MAX_SIZE) {
|
|
30
40
|
throw new TypeError('Invalid program length for segwit address');
|
|
31
41
|
}
|
|
@@ -40,12 +50,21 @@ export const isUnknownSegwitVersion = (output) => {
|
|
|
40
50
|
catch (e) { }
|
|
41
51
|
return false;
|
|
42
52
|
};
|
|
53
|
+
/**
|
|
54
|
+
* Encode a future Taproot-style segwit address (SegWit v2 - v16) using bech32m.
|
|
55
|
+
* Only for versions not yet assigned specific meanings (future use).
|
|
56
|
+
*
|
|
57
|
+
* @param output - Output script buffer containing the version and witness program
|
|
58
|
+
* @param network - Network object containing bech32 and optional bech32Opnet prefix
|
|
59
|
+
* @returns Bech32m-encoded future Taproot-style address
|
|
60
|
+
*/
|
|
43
61
|
export function toFutureOPNetAddress(output, network) {
|
|
44
|
-
if (!
|
|
45
|
-
throw new TypeError('output must be a
|
|
62
|
+
if (!(output instanceof Uint8Array))
|
|
63
|
+
throw new TypeError('output must be a Uint8Array');
|
|
46
64
|
if (!network.bech32Opnet)
|
|
47
65
|
throw new Error('Network does not support opnet');
|
|
48
66
|
const opcode = output[0];
|
|
67
|
+
// work out where the push-data really starts
|
|
49
68
|
let pushPos = 1, progLen;
|
|
50
69
|
if (output[1] < 0x4c) {
|
|
51
70
|
progLen = output[1];
|
|
@@ -58,7 +77,7 @@ export function toFutureOPNetAddress(output, network) {
|
|
|
58
77
|
else {
|
|
59
78
|
throw new TypeError('Unsupported push opcode in script');
|
|
60
79
|
}
|
|
61
|
-
const program =
|
|
80
|
+
const program = output.subarray(pushPos, pushPos + progLen);
|
|
62
81
|
if (program.length < FUTURE_SEGWIT_MIN_SIZE || program.length > FUTURE_SEGWIT_MAX_SIZE)
|
|
63
82
|
throw new TypeError('Invalid program length for segwit address');
|
|
64
83
|
const version = opcode === opcodes.OP_0
|
|
@@ -72,7 +91,7 @@ export function toFutureOPNetAddress(output, network) {
|
|
|
72
91
|
return bech32m.encode(network.bech32Opnet, words);
|
|
73
92
|
}
|
|
74
93
|
export function _toFutureSegwitAddress(output, network) {
|
|
75
|
-
const data =
|
|
94
|
+
const data = output.subarray(2);
|
|
76
95
|
if (data.length < FUTURE_SEGWIT_MIN_SIZE || data.length > FUTURE_SEGWIT_MAX_SIZE) {
|
|
77
96
|
throw new TypeError('Invalid program length for segwit address');
|
|
78
97
|
}
|
|
@@ -85,23 +104,36 @@ export function _toFutureSegwitAddress(output, network) {
|
|
|
85
104
|
}
|
|
86
105
|
return toBech32(data, version, network.bech32, network.bech32Opnet);
|
|
87
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* decode address with base58 specification, return address version and address hash if valid
|
|
109
|
+
*/
|
|
88
110
|
export function fromBase58Check(address) {
|
|
89
|
-
const payload =
|
|
111
|
+
const payload = new Uint8Array(bs58check.default.decode(address));
|
|
112
|
+
// TODO: 4.0.0, move to "toOutputScript"
|
|
90
113
|
if (payload.length < 21)
|
|
91
114
|
throw new TypeError(address + ' is too short');
|
|
92
115
|
if (payload.length > 21)
|
|
93
116
|
throw new TypeError(address + ' is too long');
|
|
94
|
-
const version = payload
|
|
95
|
-
const hash =
|
|
117
|
+
const version = payload[0];
|
|
118
|
+
const hash = payload.subarray(1);
|
|
96
119
|
return { version, hash };
|
|
97
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* encode address hash to base58 address with version
|
|
123
|
+
*/
|
|
98
124
|
export function toBase58Check(hash, version) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
125
|
+
if (!isBytes20(hash))
|
|
126
|
+
throw new TypeError('Expected 20 bytes hash');
|
|
127
|
+
if (!isUInt8(version))
|
|
128
|
+
throw new TypeError('Expected UInt8 version');
|
|
129
|
+
const payload = alloc(21);
|
|
130
|
+
payload[0] = version;
|
|
131
|
+
payload.set(hash, 1);
|
|
103
132
|
return bs58check.default.encode(payload);
|
|
104
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* encode address hash to bech32 address with version and prefix
|
|
136
|
+
*/
|
|
105
137
|
export function toBech32(data, version, prefix, prefixOpnet) {
|
|
106
138
|
const words = bech32.toWords(data);
|
|
107
139
|
words.unshift(version);
|
|
@@ -110,26 +142,30 @@ export function toBech32(data, version, prefix, prefixOpnet) {
|
|
|
110
142
|
}
|
|
111
143
|
return version === 0 ? bech32.encode(prefix, words) : bech32m.encode(prefix, words);
|
|
112
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* decode address from output script with network, return address if matched
|
|
147
|
+
*/
|
|
113
148
|
export function fromOutputScript(output, network) {
|
|
149
|
+
// TODO: Network
|
|
114
150
|
network = network || networks.bitcoin;
|
|
115
151
|
try {
|
|
116
|
-
return p2pkh({ output, network }).address;
|
|
152
|
+
return p2pkh({ output: output, network }).address;
|
|
117
153
|
}
|
|
118
154
|
catch (e) { }
|
|
119
155
|
try {
|
|
120
|
-
return p2sh({ output, network }).address;
|
|
156
|
+
return p2sh({ output: output, network }).address;
|
|
121
157
|
}
|
|
122
158
|
catch (e) { }
|
|
123
159
|
try {
|
|
124
|
-
return p2wpkh({ output, network }).address;
|
|
160
|
+
return p2wpkh({ output: output, network }).address;
|
|
125
161
|
}
|
|
126
162
|
catch (e) { }
|
|
127
163
|
try {
|
|
128
|
-
return p2wsh({ output, network }).address;
|
|
164
|
+
return p2wsh({ output: output, network }).address;
|
|
129
165
|
}
|
|
130
166
|
catch (e) { }
|
|
131
167
|
try {
|
|
132
|
-
return p2tr({ output, network }).address;
|
|
168
|
+
return p2tr({ output: output, network }).address;
|
|
133
169
|
}
|
|
134
170
|
catch (e) { }
|
|
135
171
|
try {
|
|
@@ -142,8 +178,27 @@ export function fromOutputScript(output, network) {
|
|
|
142
178
|
catch (e) { }
|
|
143
179
|
throw new Error(bscript.toASM(output) + ' has no matching Address');
|
|
144
180
|
}
|
|
145
|
-
|
|
146
|
-
|
|
181
|
+
/**
|
|
182
|
+
* Encodes address to output script with network, return output script if address matched.
|
|
183
|
+
* @param address - The address to encode
|
|
184
|
+
* @param networkOrOptions - Network or options object
|
|
185
|
+
* @returns The output script as Uint8Array
|
|
186
|
+
*/
|
|
187
|
+
export function toOutputScript(address, networkOrOptions) {
|
|
188
|
+
let network;
|
|
189
|
+
let onFutureSegwitWarning;
|
|
190
|
+
if (networkOrOptions && 'bech32' in networkOrOptions) {
|
|
191
|
+
// It's a Network object
|
|
192
|
+
network = networkOrOptions;
|
|
193
|
+
}
|
|
194
|
+
else if (networkOrOptions && typeof networkOrOptions === 'object') {
|
|
195
|
+
// It's an options object
|
|
196
|
+
network = networkOrOptions.network || networks.bitcoin;
|
|
197
|
+
onFutureSegwitWarning = networkOrOptions.onFutureSegwitWarning;
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
network = networks.bitcoin;
|
|
201
|
+
}
|
|
147
202
|
let decodeBase58;
|
|
148
203
|
let decodeBech32;
|
|
149
204
|
try {
|
|
@@ -168,13 +223,14 @@ export function toOutputScript(address, network) {
|
|
|
168
223
|
throw new Error(address + ' has an invalid prefix');
|
|
169
224
|
if (decodeBech32.version === 0) {
|
|
170
225
|
if (decodeBech32.data.length === 20)
|
|
171
|
-
return p2wpkh({ hash: decodeBech32.data }).output;
|
|
226
|
+
return p2wpkh({ hash: toBytes20(decodeBech32.data) }).output;
|
|
172
227
|
if (decodeBech32.data.length === 32)
|
|
173
|
-
return p2wsh({ hash: decodeBech32.data }).output;
|
|
228
|
+
return p2wsh({ hash: toBytes32(decodeBech32.data) }).output;
|
|
174
229
|
}
|
|
175
230
|
else if (decodeBech32.version === 1) {
|
|
176
231
|
if (decodeBech32.data.length === 32)
|
|
177
|
-
return p2tr({ pubkey: decodeBech32.data })
|
|
232
|
+
return p2tr({ pubkey: decodeBech32.data })
|
|
233
|
+
.output;
|
|
178
234
|
}
|
|
179
235
|
else if (decodeBech32.version === FUTURE_OPNET_VERSION) {
|
|
180
236
|
if (!network.bech32Opnet)
|
|
@@ -188,8 +244,8 @@ export function toOutputScript(address, network) {
|
|
|
188
244
|
decodeBech32.version <= FUTURE_SEGWIT_MAX_VERSION &&
|
|
189
245
|
decodeBech32.data.length >= FUTURE_SEGWIT_MIN_SIZE &&
|
|
190
246
|
decodeBech32.data.length <= FUTURE_SEGWIT_MAX_SIZE) {
|
|
191
|
-
if (decodeBech32.version !== FUTURE_OPNET_VERSION) {
|
|
192
|
-
|
|
247
|
+
if (decodeBech32.version !== FUTURE_OPNET_VERSION && onFutureSegwitWarning) {
|
|
248
|
+
onFutureSegwitWarning(FUTURE_SEGWIT_VERSION_WARNING);
|
|
193
249
|
}
|
|
194
250
|
return bscript.compile([
|
|
195
251
|
decodeBech32.version + FUTURE_SEGWIT_VERSION_DIFF,
|
|
@@ -200,3 +256,4 @@ export function toOutputScript(address, network) {
|
|
|
200
256
|
}
|
|
201
257
|
throw new TypeError(address + ' has no matching Script');
|
|
202
258
|
}
|
|
259
|
+
//# sourceMappingURL=address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AACvC,OAAO,EAAqB,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,KAAK,OAAO,MAAM,aAAa,CAAC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AO,CAAC,WAAW;oBAAE,MAAM,IAAI,KAAK,CAAC,OAAO,GAAG,wBAAwB,CAAC,CAAC;gBAC9E,OAAO,IAAI,CAAC;oBACR,OAAO,EAAE,YAAY,CAAC,IAAI;oBAC1B,OAAO;iBACV,CAAC,CAAC,MAAoB,CAAC;YAC5B,CAAC;iBAAM,IACH,YAAY,CAAC,OAAO,IAAI,yBAAyB;gBACjD,YAAY,CAAC,OAAO,IAAI,yBAAyB;gBACjD,YAAY,CAAC,IAAI,CAAC,MAAM,IAAI,sBAAsB;gBAClD,YAAY,CAAC,IAAI,CAAC,MAAM,IAAI,sBAAsB,EACpD,CAAC;gBACC,IAAI,YAAY,CAAC,OAAO,KAAK,oBAAoB,IAAI,qBAAqB,EAAE,CAAC;oBACzE,qBAAqB,CAAC,6BAA6B,CAAC,CAAC;gBACzD,CAAC;gBAED,OAAO,OAAO,CAAC,OAAO,CAAC;oBACnB,YAAY,CAAC,OAAO,GAAG,0BAA0B;oBACjD,YAAY,CAAC,IAAI;iBACpB,CAAC,CAAC;YACP,CAAC;QACL,CAAC;IACL,CAAC;IAED,MAAM,IAAI,SAAS,CAAC,OAAO,GAAG,yBAAyB,CAAC,CAAC;AAC7D,CAAC"}
|
package/build/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/build/bech32utils.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bech32 encoding/decoding utilities
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
1
5
|
import { bech32, bech32m } from 'bech32';
|
|
6
|
+
/**
|
|
7
|
+
* decode address with bech32 specification, return address version、address prefix and address data if valid
|
|
8
|
+
*/
|
|
2
9
|
export function fromBech32(address) {
|
|
3
10
|
let result;
|
|
4
11
|
let version;
|
|
@@ -19,8 +26,9 @@ export function fromBech32(address) {
|
|
|
19
26
|
}
|
|
20
27
|
const data = bech32.fromWords(result.words.slice(1));
|
|
21
28
|
return {
|
|
22
|
-
version,
|
|
29
|
+
version: version,
|
|
23
30
|
prefix: result.prefix,
|
|
24
|
-
data:
|
|
31
|
+
data: new Uint8Array(data),
|
|
25
32
|
};
|
|
26
33
|
}
|
|
34
|
+
//# sourceMappingURL=bech32utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bech32utils.js","sourceRoot":"","sources":["../src/bech32utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAYzC;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,OAAe;IACtC,IAAI,MAAM,CAAC;IACX,IAAI,OAAO,CAAC;IACZ,IAAI,CAAC;QACD,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC;IAEd,IAAI,MAAM,EAAE,CAAC;QACT,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC1B,IAAI,OAAO,KAAK,CAAC;YAAE,MAAM,IAAI,SAAS,CAAC,OAAO,GAAG,sBAAsB,CAAC,CAAC;IAC7E,CAAC;SAAM,CAAC;QACJ,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACjC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC1B,IAAI,OAAO,KAAK,CAAC;YAAE,MAAM,IAAI,SAAS,CAAC,OAAO,GAAG,sBAAsB,CAAC,CAAC;IAC7E,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAErD,OAAO;QACH,OAAO,EAAE,OAAQ;QACjB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,IAAI,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC;KAC7B,CAAC;AACN,CAAC"}
|
package/build/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/build/bip66.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// Reference https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki
|
|
2
|
+
// Format: 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S]
|
|
3
|
+
// NOTE: SIGHASH byte ignored AND restricted, truncate before use
|
|
4
|
+
import { alloc } from './io/index.js';
|
|
1
5
|
export function check(buffer) {
|
|
2
6
|
if (buffer.length < 8)
|
|
3
7
|
return false;
|
|
@@ -62,11 +66,34 @@ export function decode(buffer) {
|
|
|
62
66
|
throw new Error('S value is negative');
|
|
63
67
|
if (lenS > 1 && buffer[lenR + 6] === 0x00 && !(buffer[lenR + 7] & 0x80))
|
|
64
68
|
throw new Error('S value excessively padded');
|
|
69
|
+
// non-BIP66 - extract R, S values
|
|
65
70
|
return {
|
|
66
71
|
r: buffer.subarray(4, 4 + lenR),
|
|
67
72
|
s: buffer.subarray(6 + lenR),
|
|
68
73
|
};
|
|
69
74
|
}
|
|
75
|
+
/*
|
|
76
|
+
* Expects r and s to be positive DER integers.
|
|
77
|
+
*
|
|
78
|
+
* The DER format uses the most significant bit as a sign bit (& 0x80).
|
|
79
|
+
* If the significant bit is set AND the integer is positive, a 0x00 is prepended.
|
|
80
|
+
*
|
|
81
|
+
* Examples:
|
|
82
|
+
*
|
|
83
|
+
* 0 => 0x00
|
|
84
|
+
* 1 => 0x01
|
|
85
|
+
* -1 => 0xff
|
|
86
|
+
* 127 => 0x7f
|
|
87
|
+
* -127 => 0x81
|
|
88
|
+
* 128 => 0x0080
|
|
89
|
+
* -128 => 0x80
|
|
90
|
+
* 255 => 0x00ff
|
|
91
|
+
* -255 => 0xff01
|
|
92
|
+
* 16300 => 0x3fac
|
|
93
|
+
* -16300 => 0xc054
|
|
94
|
+
* 62300 => 0x00f35c
|
|
95
|
+
* -62300 => 0xff0ca4
|
|
96
|
+
*/
|
|
70
97
|
export function encode(r, s) {
|
|
71
98
|
const lenR = r.length;
|
|
72
99
|
const lenS = s.length;
|
|
@@ -86,14 +113,16 @@ export function encode(r, s) {
|
|
|
86
113
|
throw new Error('R value excessively padded');
|
|
87
114
|
if (lenS > 1 && s[0] === 0x00 && !(s[1] & 0x80))
|
|
88
115
|
throw new Error('S value excessively padded');
|
|
89
|
-
const signature =
|
|
116
|
+
const signature = alloc(6 + lenR + lenS);
|
|
117
|
+
// 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S]
|
|
90
118
|
signature[0] = 0x30;
|
|
91
119
|
signature[1] = signature.length - 2;
|
|
92
120
|
signature[2] = 0x02;
|
|
93
121
|
signature[3] = r.length;
|
|
94
|
-
|
|
122
|
+
signature.set(r, 4);
|
|
95
123
|
signature[4 + lenR] = 0x02;
|
|
96
124
|
signature[5 + lenR] = s.length;
|
|
97
|
-
|
|
125
|
+
signature.set(s, 6 + lenR);
|
|
98
126
|
return signature;
|
|
99
127
|
}
|
|
128
|
+
//# sourceMappingURL=bip66.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bip66.js","sourceRoot":"","sources":["../src/bip66.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,sEA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,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAC3B,SAAS,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;IAE3B,OAAO,SAAS,CAAC;AACrB,CAAC"}
|
package/build/block.d.ts
CHANGED
|
@@ -1,29 +1,135 @@
|
|
|
1
1
|
import { Transaction } from './transaction.js';
|
|
2
|
+
import type { 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":"AAaA,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;IAoC5C;;;;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;IAC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