@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/merkle.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the Merkle root of an array of Uint8Arrays using a specified digest function.
|
|
3
|
+
*
|
|
4
|
+
* @param values - The array of Uint8Arrays.
|
|
5
|
+
* @param digestFn - The digest function used to calculate the hash of the concatenated arrays.
|
|
6
|
+
* @returns The Merkle root as a Uint8Array.
|
|
7
|
+
* @throws {TypeError} If the values parameter is not an array or the digestFn parameter is not a function.
|
|
8
|
+
*/
|
|
1
9
|
export function fastMerkleRoot(values, digestFn) {
|
|
2
10
|
if (!Array.isArray(values))
|
|
3
11
|
throw TypeError('Expected values Array');
|
|
@@ -10,10 +18,13 @@ export function fastMerkleRoot(values, digestFn) {
|
|
|
10
18
|
for (let i = 0; i < length; i += 2, ++j) {
|
|
11
19
|
const left = results[i];
|
|
12
20
|
const right = i + 1 === length ? left : results[i + 1];
|
|
13
|
-
const data =
|
|
21
|
+
const data = new Uint8Array(left.length + right.length);
|
|
22
|
+
data.set(left);
|
|
23
|
+
data.set(right, left.length);
|
|
14
24
|
results[j] = digestFn(data);
|
|
15
25
|
}
|
|
16
26
|
length = j;
|
|
17
27
|
}
|
|
18
28
|
return results[0];
|
|
19
29
|
}
|
|
30
|
+
//# sourceMappingURL=merkle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merkle.js","sourceRoot":"","sources":["../src/merkle.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAC1B,MAAoB,EACpB,QAAuC;IAEvC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,MAAM,SAAS,CAAC,uBAAuB,CAAC,CAAC;IACrE,IAAI,OAAO,QAAQ,KAAK,UAAU;QAAE,MAAM,SAAS,CAAC,0BAA0B,CAAC,CAAC;IAEhF,IAAI,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3B,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;IAEhC,OAAO,MAAM,GAAG,CAAC,EAAE,CAAC;QAChB,IAAI,CAAC,GAAG,CAAC,CAAC;QAEV,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;YACtC,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC;YACzB,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAE,CAAC;YACxD,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;YACxD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACf,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YAE7B,OAAO,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC;QAED,MAAM,GAAG,CAAC,CAAC;IACf,CAAC;IAED,OAAO,OAAO,CAAC,CAAC,CAAE,CAAC;AACvB,CAAC"}
|
package/build/networks.d.ts
CHANGED
|
@@ -1,24 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a Bitcoin network configuration,including messagePrefix, bech32, bip32, pubKeyHash, scriptHash, wif.
|
|
3
|
+
* Support bitcoin、bitcoin testnet and bitcoin regtest.
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
1
6
|
export interface Bip32 {
|
|
2
|
-
public: number;
|
|
3
|
-
private: number;
|
|
7
|
+
readonly public: number;
|
|
8
|
+
readonly private: number;
|
|
4
9
|
}
|
|
5
10
|
export interface Network {
|
|
6
|
-
wif: number;
|
|
7
|
-
bip32: Bip32;
|
|
8
|
-
messagePrefix: string;
|
|
9
|
-
bech32: string;
|
|
10
|
-
bech32Opnet?: string;
|
|
11
|
-
pubKeyHash: number;
|
|
12
|
-
scriptHash: number;
|
|
11
|
+
readonly wif: number;
|
|
12
|
+
readonly bip32: Bip32;
|
|
13
|
+
readonly messagePrefix: string;
|
|
14
|
+
readonly bech32: string;
|
|
15
|
+
readonly bech32Opnet?: string;
|
|
16
|
+
readonly pubKeyHash: number;
|
|
17
|
+
readonly scriptHash: number;
|
|
13
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Represents the Bitcoin network configuration.
|
|
21
|
+
*/
|
|
14
22
|
export declare const bitcoin: Network;
|
|
23
|
+
/**
|
|
24
|
+
* Represents the regtest network configuration.
|
|
25
|
+
*/
|
|
15
26
|
export declare const regtest: Network;
|
|
27
|
+
/**
|
|
28
|
+
* Represents the testnet network configuration.
|
|
29
|
+
*/
|
|
16
30
|
export declare const testnet: Network;
|
|
31
|
+
/**
|
|
32
|
+
* Represents the Dogecoin mainnet configuration.
|
|
33
|
+
*
|
|
34
|
+
* Prefixes from:
|
|
35
|
+
* - P2PKH: 0x1e (30 decimal) - addresses start with 'D'
|
|
36
|
+
* - P2SH: 0x16 (22 decimal) - addresses often start with '9' or 'A'
|
|
37
|
+
* - WIF: 0x9e (158 decimal)
|
|
38
|
+
* - BIP32:
|
|
39
|
+
* - public: 0x02facafd
|
|
40
|
+
* - private: 0x02fac398
|
|
41
|
+
* Message prefix:
|
|
42
|
+
* - Dogecoin uses "\x19Dogecoin Signed Message:\n"
|
|
43
|
+
*/
|
|
17
44
|
export declare const dogecoin: Network;
|
|
45
|
+
/**
|
|
46
|
+
* Represents the Dogecoin testnet configuration.
|
|
47
|
+
*
|
|
48
|
+
* Prefixes from Dogecoin testnet chainparams:
|
|
49
|
+
* - P2PKH: 0x71 (113 decimal)
|
|
50
|
+
* - P2SH: 0xc4 (196 decimal)
|
|
51
|
+
* - WIF: 0xf1 (241 decimal)
|
|
52
|
+
* - BIP32:
|
|
53
|
+
* - public: 0x0432a9a8
|
|
54
|
+
* - private: 0x0432a243
|
|
55
|
+
* Message prefix:
|
|
56
|
+
* - Same as mainnet: "\x19Dogecoin Signed Message:\n"
|
|
57
|
+
*/
|
|
18
58
|
export declare const dogecoinTestnet: Network;
|
|
59
|
+
/**
|
|
60
|
+
* Litecoin mainnet configuration.
|
|
61
|
+
*/
|
|
19
62
|
export declare const litecoin: Network;
|
|
63
|
+
/**
|
|
64
|
+
* Litecoin testnet configuration.
|
|
65
|
+
*/
|
|
20
66
|
export declare const litecoinTestnet: Network;
|
|
67
|
+
/**
|
|
68
|
+
* Bitcoin Cash mainnet configuration (legacy).
|
|
69
|
+
* Note: Bitcoin Cash uses Cashaddr starting with 'q' or 'p',
|
|
70
|
+
* but we retain the legacy prefixes for compatibility.
|
|
71
|
+
*/
|
|
21
72
|
export declare const bitcoinCash: Network;
|
|
73
|
+
/**
|
|
74
|
+
* Bitcoin Cash testnet configuration (legacy).
|
|
75
|
+
*/
|
|
22
76
|
export declare const bitcoinCashTestnet: Network;
|
|
77
|
+
/**
|
|
78
|
+
* Dash mainnet configuration.
|
|
79
|
+
*/
|
|
23
80
|
export declare const dash: Network;
|
|
81
|
+
/**
|
|
82
|
+
* Dash testnet configuration.
|
|
83
|
+
*/
|
|
24
84
|
export declare const dashTestnet: Network;
|
|
85
|
+
//# sourceMappingURL=networks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"networks.d.ts","sourceRoot":"","sources":["../src/networks.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AAEH,MAAM,WAAW,KAAK;IAClB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,OAAO;IACpB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC/B;AAED;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,OAmCrB,CAAC;AACF;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,OAWrB,CAAC;AACF;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,OAWrB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,QAAQ,EAAE,OAWtB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,eAAe,EAAE,OAW7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,OAWtB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,OAW7B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,OAazB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,OAWhC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,IAAI,EAAE,OAalB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,OAWzB,CAAC"}
|
package/build/networks.js
CHANGED
|
@@ -1,15 +1,47 @@
|
|
|
1
|
+
// https://en.bitcoin.it/wiki/List_of_address_prefixes
|
|
2
|
+
// Dogecoin BIP32 is a proposed standard: https://bitcointalk.org/index.php?topic=409731
|
|
3
|
+
/**
|
|
4
|
+
* Represents the Bitcoin network configuration.
|
|
5
|
+
*/
|
|
1
6
|
export const bitcoin = {
|
|
7
|
+
/**
|
|
8
|
+
* The message prefix used for signing Bitcoin messages.
|
|
9
|
+
*/
|
|
2
10
|
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
|
11
|
+
/**
|
|
12
|
+
* The Bech32 prefix used for Bitcoin addresses.
|
|
13
|
+
*/
|
|
3
14
|
bech32: 'bc',
|
|
4
15
|
bech32Opnet: 'op',
|
|
16
|
+
/**
|
|
17
|
+
* The BIP32 key prefixes for Bitcoin.
|
|
18
|
+
*/
|
|
5
19
|
bip32: {
|
|
20
|
+
/**
|
|
21
|
+
* The public key prefix for BIP32 extended public keys.
|
|
22
|
+
*/
|
|
6
23
|
public: 0x0488b21e,
|
|
24
|
+
/**
|
|
25
|
+
* The private key prefix for BIP32 extended private keys.
|
|
26
|
+
*/
|
|
7
27
|
private: 0x0488ade4,
|
|
8
28
|
},
|
|
29
|
+
/**
|
|
30
|
+
* The prefix for Bitcoin public key hashes.
|
|
31
|
+
*/
|
|
9
32
|
pubKeyHash: 0x00,
|
|
33
|
+
/**
|
|
34
|
+
* The prefix for Bitcoin script hashes.
|
|
35
|
+
*/
|
|
10
36
|
scriptHash: 0x05,
|
|
37
|
+
/**
|
|
38
|
+
* The prefix for Bitcoin Wallet Import Format (WIF) private keys.
|
|
39
|
+
*/
|
|
11
40
|
wif: 0x80,
|
|
12
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* Represents the regtest network configuration.
|
|
44
|
+
*/
|
|
13
45
|
export const regtest = {
|
|
14
46
|
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
|
15
47
|
bech32: 'bcrt',
|
|
@@ -22,6 +54,9 @@ export const regtest = {
|
|
|
22
54
|
scriptHash: 0xc4,
|
|
23
55
|
wif: 0xef,
|
|
24
56
|
};
|
|
57
|
+
/**
|
|
58
|
+
* Represents the testnet network configuration.
|
|
59
|
+
*/
|
|
25
60
|
export const testnet = {
|
|
26
61
|
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
|
27
62
|
bech32: 'tb',
|
|
@@ -34,9 +69,22 @@ export const testnet = {
|
|
|
34
69
|
scriptHash: 0xc4,
|
|
35
70
|
wif: 0xef,
|
|
36
71
|
};
|
|
72
|
+
/**
|
|
73
|
+
* Represents the Dogecoin mainnet configuration.
|
|
74
|
+
*
|
|
75
|
+
* Prefixes from:
|
|
76
|
+
* - P2PKH: 0x1e (30 decimal) - addresses start with 'D'
|
|
77
|
+
* - P2SH: 0x16 (22 decimal) - addresses often start with '9' or 'A'
|
|
78
|
+
* - WIF: 0x9e (158 decimal)
|
|
79
|
+
* - BIP32:
|
|
80
|
+
* - public: 0x02facafd
|
|
81
|
+
* - private: 0x02fac398
|
|
82
|
+
* Message prefix:
|
|
83
|
+
* - Dogecoin uses "\x19Dogecoin Signed Message:\n"
|
|
84
|
+
*/
|
|
37
85
|
export const dogecoin = {
|
|
38
86
|
messagePrefix: '\x19Dogecoin Signed Message:\n',
|
|
39
|
-
bech32: '',
|
|
87
|
+
bech32: '', // Dogecoin does not currently use Bech32
|
|
40
88
|
bech32Opnet: '',
|
|
41
89
|
bip32: {
|
|
42
90
|
public: 0x02facafd,
|
|
@@ -46,9 +94,22 @@ export const dogecoin = {
|
|
|
46
94
|
scriptHash: 0x16,
|
|
47
95
|
wif: 0x9e,
|
|
48
96
|
};
|
|
97
|
+
/**
|
|
98
|
+
* Represents the Dogecoin testnet configuration.
|
|
99
|
+
*
|
|
100
|
+
* Prefixes from Dogecoin testnet chainparams:
|
|
101
|
+
* - P2PKH: 0x71 (113 decimal)
|
|
102
|
+
* - P2SH: 0xc4 (196 decimal)
|
|
103
|
+
* - WIF: 0xf1 (241 decimal)
|
|
104
|
+
* - BIP32:
|
|
105
|
+
* - public: 0x0432a9a8
|
|
106
|
+
* - private: 0x0432a243
|
|
107
|
+
* Message prefix:
|
|
108
|
+
* - Same as mainnet: "\x19Dogecoin Signed Message:\n"
|
|
109
|
+
*/
|
|
49
110
|
export const dogecoinTestnet = {
|
|
50
111
|
messagePrefix: '\x19Dogecoin Signed Message:\n',
|
|
51
|
-
bech32: '',
|
|
112
|
+
bech32: '', // Dogecoin testnet does not currently use Bech32
|
|
52
113
|
bech32Opnet: '',
|
|
53
114
|
bip32: {
|
|
54
115
|
public: 0x0432a9a8,
|
|
@@ -58,6 +119,9 @@ export const dogecoinTestnet = {
|
|
|
58
119
|
scriptHash: 0xc4,
|
|
59
120
|
wif: 0xf1,
|
|
60
121
|
};
|
|
122
|
+
/**
|
|
123
|
+
* Litecoin mainnet configuration.
|
|
124
|
+
*/
|
|
61
125
|
export const litecoin = {
|
|
62
126
|
messagePrefix: '\x19Litecoin Signed Message:\n',
|
|
63
127
|
bech32: 'ltc',
|
|
@@ -70,6 +134,9 @@ export const litecoin = {
|
|
|
70
134
|
scriptHash: 0x32,
|
|
71
135
|
wif: 0xb0,
|
|
72
136
|
};
|
|
137
|
+
/**
|
|
138
|
+
* Litecoin testnet configuration.
|
|
139
|
+
*/
|
|
73
140
|
export const litecoinTestnet = {
|
|
74
141
|
messagePrefix: '\x19Litecoin Signed Message:\n',
|
|
75
142
|
bech32: 'tltc',
|
|
@@ -82,8 +149,15 @@ export const litecoinTestnet = {
|
|
|
82
149
|
scriptHash: 0x3a,
|
|
83
150
|
wif: 0xef,
|
|
84
151
|
};
|
|
152
|
+
/**
|
|
153
|
+
* Bitcoin Cash mainnet configuration (legacy).
|
|
154
|
+
* Note: Bitcoin Cash uses Cashaddr starting with 'q' or 'p',
|
|
155
|
+
* but we retain the legacy prefixes for compatibility.
|
|
156
|
+
*/
|
|
85
157
|
export const bitcoinCash = {
|
|
86
158
|
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
|
159
|
+
// Cashaddr prefix differs from bech32 for general usage, but we can set it similarly.
|
|
160
|
+
// Actual cashaddr prefix is "bitcoincash", but this field is for bech32 which BCH doesn't fully use for segwit (it doesn't have segwit).
|
|
87
161
|
bech32: 'bitcoincash',
|
|
88
162
|
bech32Opnet: 'opbch',
|
|
89
163
|
bip32: {
|
|
@@ -94,6 +168,9 @@ export const bitcoinCash = {
|
|
|
94
168
|
scriptHash: 0x05,
|
|
95
169
|
wif: 0x80,
|
|
96
170
|
};
|
|
171
|
+
/**
|
|
172
|
+
* Bitcoin Cash testnet configuration (legacy).
|
|
173
|
+
*/
|
|
97
174
|
export const bitcoinCashTestnet = {
|
|
98
175
|
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
|
99
176
|
bech32: 'bchtest',
|
|
@@ -106,9 +183,14 @@ export const bitcoinCashTestnet = {
|
|
|
106
183
|
scriptHash: 0xc4,
|
|
107
184
|
wif: 0xef,
|
|
108
185
|
};
|
|
186
|
+
/**
|
|
187
|
+
* Dash mainnet configuration.
|
|
188
|
+
*/
|
|
109
189
|
export const dash = {
|
|
190
|
+
// Historically Dash used DarkCoin message prefix, and most implementations use this:
|
|
191
|
+
// As of Dash Core 0.17, this has not changed in code.
|
|
110
192
|
messagePrefix: '\x19DarkCoin Signed Message:\n',
|
|
111
|
-
bech32: '',
|
|
193
|
+
bech32: '', // Dash does not use Bech32
|
|
112
194
|
bech32Opnet: '',
|
|
113
195
|
bip32: {
|
|
114
196
|
public: 0x02fe52cc,
|
|
@@ -118,9 +200,12 @@ export const dash = {
|
|
|
118
200
|
scriptHash: 0x10,
|
|
119
201
|
wif: 0xcc,
|
|
120
202
|
};
|
|
203
|
+
/**
|
|
204
|
+
* Dash testnet configuration.
|
|
205
|
+
*/
|
|
121
206
|
export const dashTestnet = {
|
|
122
207
|
messagePrefix: '\x19DarkCoin Signed Message:\n',
|
|
123
|
-
bech32: '',
|
|
208
|
+
bech32: '', // Dash testnet does not use Bech32
|
|
124
209
|
bech32Opnet: '',
|
|
125
210
|
bip32: {
|
|
126
211
|
public: 0x3a8061a0,
|
|
@@ -130,3 +215,4 @@ export const dashTestnet = {
|
|
|
130
215
|
scriptHash: 0x13,
|
|
131
216
|
wif: 0xef,
|
|
132
217
|
};
|
|
218
|
+
//# sourceMappingURL=networks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"networks.js","sourceRoot":"","sources":["../src/networks.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,wFAAwF;AAuBxF;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAY;IAC5B;;OAEG;IACH,aAAa,EAAE,+BAA+B;IAC9C;;OAEG;IACH,MAAM,EAAE,IAAI;IACZ,WAAW,EAAE,IAAI;IACjB;;OAEG;IACH,KAAK,EAAE;QACH;;WAEG;QACH,MAAM,EAAE,UAAU;QAClB;;WAEG;QACH,OAAO,EAAE,UAAU;KACtB;IACD;;OAEG;IACH,UAAU,EAAE,IAAI;IAChB;;OAEG;IACH,UAAU,EAAE,IAAI;IAChB;;OAEG;IACH,GAAG,EAAE,IAAI;CACZ,CAAC;AACF;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAY;IAC5B,aAAa,EAAE,+BAA+B;IAC9C,MAAM,EAAE,MAAM;IACd,WAAW,EAAE,KAAK;I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O,CAAC,EAAmB,CAAC,CAAC;IAC1C,WAAW,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;AAC3B,CAAC"}
|
|
@@ -1,23 +1,49 @@
|
|
|
1
|
-
import { Tapleaf, Taptree } from '../types.js';
|
|
1
|
+
import type { Bytes32, Tapleaf, Taptree, XOnlyPublicKey } from '../types.js';
|
|
2
2
|
export declare const LEAF_VERSION_TAPSCRIPT = 192;
|
|
3
3
|
export declare const MAX_TAPTREE_DEPTH = 128;
|
|
4
4
|
interface HashLeaf {
|
|
5
|
-
hash:
|
|
5
|
+
hash: Bytes32;
|
|
6
6
|
}
|
|
7
7
|
interface HashBranch {
|
|
8
|
-
hash:
|
|
8
|
+
hash: Bytes32;
|
|
9
9
|
left: HashTree;
|
|
10
10
|
right: HashTree;
|
|
11
11
|
}
|
|
12
12
|
interface TweakedPublicKey {
|
|
13
13
|
parity: number;
|
|
14
|
-
x:
|
|
14
|
+
x: XOnlyPublicKey;
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Binary tree representing leaf, branch, and root node hashes of a Taptree.
|
|
18
|
+
* Each node contains a hash, and potentially left and right branch hashes.
|
|
19
|
+
* This tree is used for 2 purposes: Providing the root hash for tweaking,
|
|
20
|
+
* and calculating merkle inclusion proofs when constructing a control block.
|
|
21
|
+
*/
|
|
16
22
|
export type HashTree = HashLeaf | HashBranch;
|
|
17
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Calculates the root hash from a given control block and leaf hash.
|
|
25
|
+
* @param controlBlock - The control block.
|
|
26
|
+
* @param leafHash - The leaf hash.
|
|
27
|
+
* @returns The root hash.
|
|
28
|
+
* @throws {TypeError} If the control block length is less than 33.
|
|
29
|
+
*/
|
|
30
|
+
export declare function rootHashFromPath(controlBlock: Uint8Array, leafHash: Uint8Array): Bytes32;
|
|
31
|
+
/**
|
|
32
|
+
* Build a hash tree of merkle nodes from the scripts binary tree.
|
|
33
|
+
* @param scriptTree - the tree of scripts to pairwise hash.
|
|
34
|
+
*/
|
|
18
35
|
export declare function toHashTree(scriptTree: Taptree): HashTree;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Given a HashTree, finds the path from a particular hash to the root.
|
|
38
|
+
* @param node - the root of the tree
|
|
39
|
+
* @param hash - the hash to search for
|
|
40
|
+
* @returns - array of sibling hashes, from leaf (inclusive) to root
|
|
41
|
+
* (exclusive) needed to prove inclusion of the specified hash. undefined if no
|
|
42
|
+
* path is found
|
|
43
|
+
*/
|
|
44
|
+
export declare function findScriptPath(node: HashTree, hash: Bytes32): Bytes32[] | undefined;
|
|
45
|
+
export declare function tapleafHash(leaf: Tapleaf): Bytes32;
|
|
46
|
+
export declare function tapTweakHash(pubKey: XOnlyPublicKey, h: Bytes32 | undefined): Bytes32;
|
|
47
|
+
export declare function tweakKey(pubKey: XOnlyPublicKey, h: Bytes32 | undefined): TweakedPublicKey | null;
|
|
23
48
|
export {};
|
|
49
|
+
//# sourceMappingURL=bip341.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bip341.d.ts","sourceRoot":"","sources":["../../src/payments/bip341.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7E,eAAO,MAAM,sBAAsB,MAAO,CAAC;AAC3C,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC,UAAU,QAAQ;IACd,IAAI,EAAE,OAAO,CAAC;CACjB;AAED,UAAU,UAAU;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,QAAQ,CAAC;CACnB;AAED,UAAU,gBAAgB;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,CAAC,EAAE,cAAc,CAAC;CACrB;AAID;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,UAAU,CAAC;AAE7C;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,GAAG,OAAO,CAkBxF;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,OAAO,GAAG,QAAQ,CAYxD;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,EAAE,GAAG,SAAS,CAYnF;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAMlD;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO,CAEpF;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,gBAAgB,GAAG,IAAI,CAchG"}
|
package/build/payments/bip341.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import { Buffer as NBuffer } from 'buffer';
|
|
2
1
|
import * as bcrypto from '../crypto.js';
|
|
3
|
-
import { getEccLib } from '../
|
|
4
|
-
import { varuint } from '../
|
|
2
|
+
import { getEccLib } from '../ecc/context.js';
|
|
3
|
+
import { alloc, compare, concat, equals, varuint } from '../io/index.js';
|
|
5
4
|
import { isTapleaf } from '../types.js';
|
|
6
5
|
export const LEAF_VERSION_TAPSCRIPT = 0xc0;
|
|
7
6
|
export const MAX_TAPTREE_DEPTH = 128;
|
|
8
7
|
const isHashBranch = (ht) => 'left' in ht && 'right' in ht;
|
|
8
|
+
/**
|
|
9
|
+
* Calculates the root hash from a given control block and leaf hash.
|
|
10
|
+
* @param controlBlock - The control block.
|
|
11
|
+
* @param leafHash - The leaf hash.
|
|
12
|
+
* @returns The root hash.
|
|
13
|
+
* @throws {TypeError} If the control block length is less than 33.
|
|
14
|
+
*/
|
|
9
15
|
export function rootHashFromPath(controlBlock, leafHash) {
|
|
10
16
|
if (controlBlock.length < 33)
|
|
11
17
|
throw new TypeError(`The control-block length is too small. Got ${controlBlock.length}, expected min 33.`);
|
|
@@ -13,7 +19,7 @@ export function rootHashFromPath(controlBlock, leafHash) {
|
|
|
13
19
|
let kj = leafHash;
|
|
14
20
|
for (let j = 0; j < m; j++) {
|
|
15
21
|
const ej = controlBlock.subarray(33 + 32 * j, 65 + 32 * j);
|
|
16
|
-
if (
|
|
22
|
+
if (compare(kj, ej) < 0) {
|
|
17
23
|
kj = tapBranchHash(kj, ej);
|
|
18
24
|
}
|
|
19
25
|
else {
|
|
@@ -22,18 +28,30 @@ export function rootHashFromPath(controlBlock, leafHash) {
|
|
|
22
28
|
}
|
|
23
29
|
return kj;
|
|
24
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Build a hash tree of merkle nodes from the scripts binary tree.
|
|
33
|
+
* @param scriptTree - the tree of scripts to pairwise hash.
|
|
34
|
+
*/
|
|
25
35
|
export function toHashTree(scriptTree) {
|
|
26
36
|
if (isTapleaf(scriptTree))
|
|
27
37
|
return { hash: tapleafHash(scriptTree) };
|
|
28
38
|
const hashes = [toHashTree(scriptTree[0]), toHashTree(scriptTree[1])];
|
|
29
|
-
hashes.sort((a, b) => a.hash
|
|
39
|
+
hashes.sort((a, b) => compare(a.hash, b.hash));
|
|
30
40
|
const [left, right] = hashes;
|
|
31
41
|
return {
|
|
32
42
|
hash: tapBranchHash(left.hash, right.hash),
|
|
33
|
-
left,
|
|
34
|
-
right,
|
|
43
|
+
left: left,
|
|
44
|
+
right: right,
|
|
35
45
|
};
|
|
36
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Given a HashTree, finds the path from a particular hash to the root.
|
|
49
|
+
* @param node - the root of the tree
|
|
50
|
+
* @param hash - the hash to search for
|
|
51
|
+
* @returns - array of sibling hashes, from leaf (inclusive) to root
|
|
52
|
+
* (exclusive) needed to prove inclusion of the specified hash. undefined if no
|
|
53
|
+
* path is found
|
|
54
|
+
*/
|
|
37
55
|
export function findScriptPath(node, hash) {
|
|
38
56
|
if (isHashBranch(node)) {
|
|
39
57
|
const leftPath = findScriptPath(node.left, hash);
|
|
@@ -43,20 +61,20 @@ export function findScriptPath(node, hash) {
|
|
|
43
61
|
if (rightPath !== undefined)
|
|
44
62
|
return [...rightPath, node.left.hash];
|
|
45
63
|
}
|
|
46
|
-
else if (node.hash
|
|
64
|
+
else if (equals(node.hash, hash)) {
|
|
47
65
|
return [];
|
|
48
66
|
}
|
|
49
67
|
return undefined;
|
|
50
68
|
}
|
|
51
69
|
export function tapleafHash(leaf) {
|
|
52
70
|
const version = leaf.version || LEAF_VERSION_TAPSCRIPT;
|
|
53
|
-
return bcrypto.taggedHash('TapLeaf',
|
|
71
|
+
return bcrypto.taggedHash('TapLeaf', concat([new Uint8Array([version]), serializeScript(leaf.output)]));
|
|
54
72
|
}
|
|
55
73
|
export function tapTweakHash(pubKey, h) {
|
|
56
|
-
return bcrypto.taggedHash('TapTweak',
|
|
74
|
+
return bcrypto.taggedHash('TapTweak', h ? concat([pubKey, h]) : pubKey);
|
|
57
75
|
}
|
|
58
76
|
export function tweakKey(pubKey, h) {
|
|
59
|
-
if (!
|
|
77
|
+
if (!(pubKey instanceof Uint8Array))
|
|
60
78
|
return null;
|
|
61
79
|
if (pubKey.length !== 32)
|
|
62
80
|
return null;
|
|
@@ -68,15 +86,16 @@ export function tweakKey(pubKey, h) {
|
|
|
68
86
|
return null;
|
|
69
87
|
return {
|
|
70
88
|
parity: res.parity,
|
|
71
|
-
x:
|
|
89
|
+
x: new Uint8Array(res.xOnlyPubkey),
|
|
72
90
|
};
|
|
73
91
|
}
|
|
74
92
|
function tapBranchHash(a, b) {
|
|
75
|
-
return bcrypto.taggedHash('TapBranch',
|
|
93
|
+
return bcrypto.taggedHash('TapBranch', concat([a, b]));
|
|
76
94
|
}
|
|
77
95
|
function serializeScript(s) {
|
|
78
96
|
const varintLen = varuint.encodingLength(s.length);
|
|
79
|
-
const buffer =
|
|
97
|
+
const buffer = alloc(varintLen);
|
|
80
98
|
varuint.encode(s.length, buffer);
|
|
81
|
-
return
|
|
99
|
+
return concat([buffer, s]);
|
|
82
100
|
}
|
|
101
|
+
//# sourceMappingURL=bip341.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bip341.js","sourceRoot":"","sources":["../../src/payments/bip341.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAC3C,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAiBrC,MAAM,YAAY,GAAG,CAAC,EAAY,EAAoB,EAAE,CAAC,MAAM,IAAI,EAAE,IAAI,OAAO,IAAI,EAAE,CAAC;AAUvF;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,YAAwB,EAAE,QAAoB;IAC3E,IAAI,YAAY,CAAC,MAAM,GAAG,EAAE;QACxB,MAAM,IAAI,SAAS,CACf,8CAA8C,YAAY,CAAC,MAAM,oBAAoB,CACxF,CAAC;IACN,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC;IAE1C,IAAI,EAAE,GAAG,QAAQ,CAAC;IAClB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACzB,MAAM,EAAE,GAAG,YAAY,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC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C,kBAAkB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC9D,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,WAAW,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAElD,OAAO;QACH,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,CAAC,EAAE,IAAI,UAAU,CAAC,GAAG,CAAC,WAAW,CAAmB;KACvD,CAAC;AACN,CAAC;AAED,SAAS,aAAa,CAAC,CAAa,EAAE,CAAa;IAC/C,OAAO,OAAO,CAAC,UAAU,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAY,CAAC;AACtE,CAAC;AAED,SAAS,eAAe,CAAC,CAAa;IAClC,MAAM,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IACnD,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,OAAO,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -1,2 +1,121 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* OP_RETURN Embed payment class.
|
|
3
|
+
*
|
|
4
|
+
* Embed payments use OP_RETURN to store arbitrary data in the blockchain.
|
|
5
|
+
* These outputs are provably unspendable.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import { type Network } from '../networks.js';
|
|
10
|
+
import type { Script } from '../types.js';
|
|
11
|
+
import { type EmbedPayment, type PaymentOpts, PaymentType } from './types.js';
|
|
12
|
+
/**
|
|
13
|
+
* OP_RETURN Embed payment class.
|
|
14
|
+
*
|
|
15
|
+
* Creates outputs of the form: `OP_RETURN {data1} {data2} ...`
|
|
16
|
+
* These outputs are provably unspendable and used for data storage.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { Embed } from '@btc-vision/bitcoin';
|
|
21
|
+
*
|
|
22
|
+
* // Create from data
|
|
23
|
+
* const payment = Embed.fromData([Buffer.from('Hello, Bitcoin!')]);
|
|
24
|
+
* console.log(payment.output); // scriptPubKey with OP_RETURN
|
|
25
|
+
*
|
|
26
|
+
* // Decode an existing output
|
|
27
|
+
* const decoded = Embed.fromOutput(scriptPubKey);
|
|
28
|
+
* console.log(decoded.data); // array of data chunks
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare class Embed {
|
|
32
|
+
#private;
|
|
33
|
+
static readonly NAME: "embed";
|
|
34
|
+
/**
|
|
35
|
+
* Creates a new Embed payment instance.
|
|
36
|
+
*
|
|
37
|
+
* @param params - Payment parameters
|
|
38
|
+
* @param params.data - Array of data chunks to embed
|
|
39
|
+
* @param params.output - The scriptPubKey
|
|
40
|
+
* @param params.network - Network parameters (defaults to mainnet)
|
|
41
|
+
* @param opts - Payment options
|
|
42
|
+
* @param opts.validate - Whether to validate inputs (default: true)
|
|
43
|
+
*
|
|
44
|
+
* @throws {TypeError} If validation is enabled and data is invalid
|
|
45
|
+
*/
|
|
46
|
+
constructor(params: {
|
|
47
|
+
data?: Uint8Array[] | undefined;
|
|
48
|
+
output?: Uint8Array | undefined;
|
|
49
|
+
network?: Network | undefined;
|
|
50
|
+
}, opts?: PaymentOpts);
|
|
51
|
+
/**
|
|
52
|
+
* Payment type discriminant.
|
|
53
|
+
*/
|
|
54
|
+
get name(): typeof PaymentType.Embed;
|
|
55
|
+
/**
|
|
56
|
+
* Network parameters.
|
|
57
|
+
*/
|
|
58
|
+
get network(): Network;
|
|
59
|
+
/**
|
|
60
|
+
* The embedded data chunks.
|
|
61
|
+
*/
|
|
62
|
+
get data(): Uint8Array[];
|
|
63
|
+
/**
|
|
64
|
+
* The scriptPubKey: `OP_RETURN {data...}`
|
|
65
|
+
*/
|
|
66
|
+
get output(): Script | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* Creates an Embed payment from data chunks.
|
|
69
|
+
*
|
|
70
|
+
* @param data - Array of data chunks to embed
|
|
71
|
+
* @param network - Network parameters (defaults to mainnet)
|
|
72
|
+
* @returns A new Embed payment instance
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const payment = Embed.fromData([
|
|
77
|
+
* new TextEncoder().encode('Hello'),
|
|
78
|
+
* new TextEncoder().encode('Bitcoin')
|
|
79
|
+
* ]);
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
static fromData(data: Uint8Array[], network?: Network): Embed;
|
|
83
|
+
/**
|
|
84
|
+
* Creates an Embed payment from a scriptPubKey.
|
|
85
|
+
*
|
|
86
|
+
* @param output - The scriptPubKey
|
|
87
|
+
* @param network - Network parameters (defaults to mainnet)
|
|
88
|
+
* @returns A new Embed payment instance
|
|
89
|
+
*/
|
|
90
|
+
static fromOutput(output: Uint8Array, network?: Network): Embed;
|
|
91
|
+
/**
|
|
92
|
+
* Converts to a plain EmbedPayment object for backwards compatibility.
|
|
93
|
+
*
|
|
94
|
+
* @returns An EmbedPayment object
|
|
95
|
+
*/
|
|
96
|
+
toPayment(): EmbedPayment;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Creates an OP_RETURN Embed payment object.
|
|
100
|
+
*
|
|
101
|
+
* This is the legacy factory function for backwards compatibility.
|
|
102
|
+
* For new code, prefer using the Embed class directly.
|
|
103
|
+
*
|
|
104
|
+
* @param a - The payment object containing the necessary data
|
|
105
|
+
* @param opts - Optional payment options
|
|
106
|
+
* @returns The Embed payment object
|
|
107
|
+
* @throws {TypeError} If the required data is not provided or if the data is invalid
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* import { p2data } from '@btc-vision/bitcoin';
|
|
112
|
+
*
|
|
113
|
+
* // Create from data
|
|
114
|
+
* const payment = p2data({ data: [Buffer.from('Hello')] });
|
|
115
|
+
*
|
|
116
|
+
* // Decode from output
|
|
117
|
+
* const decoded = p2data({ output: scriptPubKey });
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
2
120
|
export declare function p2data(a: Omit<EmbedPayment, 'name'>, opts?: PaymentOpts): EmbedPayment;
|
|
121
|
+
//# sourceMappingURL=embed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed.d.ts","sourceRoot":"","sources":["../../src/payments/embed.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAA8B,KAAK,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE1E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAI9E;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,KAAK;;IAEd,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAqB;IAkBzC;;;;;;;;;;;OAWG;gBAEC,MAAM,EAAE;QACJ,IAAI,CAAC,EAAE,UAAU,EAAE,GAAG,SAAS,CAAC;QAChC,MAAM,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;QAChC,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;KACjC,EACD,IAAI,CAAC,EAAE,WAAW;IAoBtB;;OAEG;IACH,IAAI,IAAI,IAAI,OAAO,WAAW,CAAC,KAAK,CAEnC;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,OAAO,CAErB;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,UAAU,EAAE,CAMvB;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,GAAG,SAAS,CAM/B;IAID;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,OAAO,CAAC,EAAE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