@btc-vision/bitcoin 6.5.5 → 7.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AUDIT/README.md +9 -0
- package/HOW_TO_WRITE_GOOD_CODE.md +2436 -0
- package/SECURITY.md +27 -0
- package/benchmark/psbt-2000-inputs.bench.ts +178 -0
- package/benchmark/signing.bench.ts +147 -0
- package/browser/address.d.ts +56 -9
- package/browser/address.d.ts.map +1 -0
- package/browser/bech32utils.d.ts +9 -1
- package/browser/bech32utils.d.ts.map +1 -0
- package/browser/bip66.d.ts +11 -6
- package/browser/bip66.d.ts.map +1 -0
- package/browser/block.d.ts +117 -11
- package/browser/block.d.ts.map +1 -0
- package/browser/branded.d.ts +20 -0
- package/browser/branded.d.ts.map +1 -0
- package/browser/crypto/crypto.d.ts +1 -0
- package/browser/crypto/crypto.d.ts.map +1 -0
- package/browser/crypto.d.ts +46 -7
- package/browser/crypto.d.ts.map +1 -0
- package/browser/ecc/context.d.ts +129 -0
- package/browser/ecc/context.d.ts.map +1 -0
- package/browser/ecc/index.d.ts +11 -0
- package/browser/ecc/index.d.ts.map +1 -0
- package/browser/ecc/types.d.ts +128 -0
- package/browser/ecc/types.d.ts.map +1 -0
- package/browser/ecpair.d.ts +99 -0
- package/browser/errors.d.ts +124 -0
- package/browser/errors.d.ts.map +1 -0
- package/browser/index.d.ts +32 -5
- package/browser/index.d.ts.map +1 -0
- package/browser/index.js +12482 -101
- package/browser/io/BinaryReader.d.ts +276 -0
- package/browser/io/BinaryReader.d.ts.map +1 -0
- package/browser/io/BinaryWriter.d.ts +391 -0
- package/browser/io/BinaryWriter.d.ts.map +1 -0
- package/browser/io/MemoryPool.d.ts +220 -0
- package/browser/io/MemoryPool.d.ts.map +1 -0
- package/browser/io/base64.d.ts +13 -0
- package/browser/io/base64.d.ts.map +1 -0
- package/browser/io/hex.d.ts +67 -0
- package/browser/io/hex.d.ts.map +1 -0
- package/browser/io/index.d.ts +17 -0
- package/browser/io/index.d.ts.map +1 -0
- package/browser/io/utils.d.ts +199 -0
- package/browser/io/utils.d.ts.map +1 -0
- package/browser/merkle.d.ts +10 -1
- package/browser/merkle.d.ts.map +1 -0
- package/browser/networks.d.ts +70 -9
- package/browser/networks.d.ts.map +1 -0
- package/browser/opcodes.d.ts +1 -0
- package/browser/opcodes.d.ts.map +1 -0
- package/browser/payments/bip341.d.ts +35 -9
- package/browser/payments/bip341.d.ts.map +1 -0
- package/browser/payments/embed.d.ts +112 -1
- package/browser/payments/embed.d.ts.map +1 -0
- package/browser/payments/index.d.ts +17 -10
- package/browser/payments/index.d.ts.map +1 -0
- package/browser/payments/p2ms.d.ts +150 -0
- package/browser/payments/p2ms.d.ts.map +1 -0
- package/browser/payments/p2op.d.ts +150 -24
- package/browser/payments/p2op.d.ts.map +1 -0
- package/browser/payments/p2pk.d.ts +154 -1
- package/browser/payments/p2pk.d.ts.map +1 -0
- package/browser/payments/p2pkh.d.ts +176 -1
- package/browser/payments/p2pkh.d.ts.map +1 -0
- package/browser/payments/p2sh.d.ts +150 -1
- package/browser/payments/p2sh.d.ts.map +1 -0
- package/browser/payments/p2tr.d.ts +185 -1
- package/browser/payments/p2tr.d.ts.map +1 -0
- package/browser/payments/p2wpkh.d.ts +161 -1
- package/browser/payments/p2wpkh.d.ts.map +1 -0
- package/browser/payments/p2wsh.d.ts +146 -1
- package/browser/payments/p2wsh.d.ts.map +1 -0
- package/browser/payments/types.d.ts +94 -64
- package/browser/payments/types.d.ts.map +1 -0
- package/browser/psbt/bip371.d.ts +34 -8
- package/browser/psbt/bip371.d.ts.map +1 -0
- package/browser/psbt/psbtutils.d.ts +56 -16
- package/browser/psbt/psbtutils.d.ts.map +1 -0
- package/browser/psbt/types.d.ts +245 -0
- package/browser/psbt/types.d.ts.map +1 -0
- package/browser/psbt/utils.d.ts +64 -0
- package/browser/psbt/utils.d.ts.map +1 -0
- package/browser/psbt/validation.d.ts +84 -0
- package/browser/psbt/validation.d.ts.map +1 -0
- package/browser/psbt.d.ts +82 -118
- package/browser/psbt.d.ts.map +1 -0
- package/browser/pubkey.d.ts +27 -6
- package/browser/pubkey.d.ts.map +1 -0
- package/browser/push_data.d.ts +24 -2
- package/browser/push_data.d.ts.map +1 -0
- package/browser/script.d.ts +33 -8
- package/browser/script.d.ts.map +1 -0
- package/browser/script_number.d.ts +17 -0
- package/browser/script_number.d.ts.map +1 -0
- package/browser/script_signature.d.ts +23 -5
- package/browser/script_signature.d.ts.map +1 -0
- package/browser/transaction.d.ts +160 -18
- package/browser/transaction.d.ts.map +1 -0
- package/browser/types.d.ts +36 -38
- package/browser/types.d.ts.map +1 -0
- package/browser/workers/WorkerSigningPool.d.ts +143 -0
- package/browser/workers/WorkerSigningPool.d.ts.map +1 -0
- package/browser/workers/WorkerSigningPool.node.d.ts +116 -0
- package/browser/workers/WorkerSigningPool.node.d.ts.map +1 -0
- package/browser/workers/ecc-bundle.d.ts +25 -0
- package/browser/workers/ecc-bundle.d.ts.map +1 -0
- package/browser/workers/index.d.ts +91 -0
- package/browser/workers/index.d.ts.map +1 -0
- package/browser/workers/psbt-parallel.d.ts +88 -0
- package/browser/workers/psbt-parallel.d.ts.map +1 -0
- package/browser/workers/signing-worker.d.ts +37 -0
- package/browser/workers/signing-worker.d.ts.map +1 -0
- package/browser/workers/types.d.ts +365 -0
- package/browser/workers/types.d.ts.map +1 -0
- package/build/address.d.ts +57 -10
- package/build/address.d.ts.map +1 -0
- package/build/address.js +80 -24
- package/build/address.js.map +1 -0
- package/build/bech32utils.d.ts +9 -1
- package/build/bech32utils.d.ts.map +1 -0
- package/build/bech32utils.js +10 -2
- package/build/bech32utils.js.map +1 -0
- package/build/bip66.d.ts +11 -6
- package/build/bip66.d.ts.map +1 -0
- package/build/bip66.js +32 -3
- package/build/bip66.js.map +1 -0
- package/build/block.d.ts +117 -11
- package/build/block.d.ts.map +1 -0
- package/build/block.js +204 -72
- package/build/block.js.map +1 -0
- package/build/branded.d.ts +20 -0
- package/build/branded.d.ts.map +1 -0
- package/build/branded.js +7 -0
- package/build/branded.js.map +1 -0
- package/build/crypto/crypto.d.ts +1 -0
- package/build/crypto/crypto.d.ts.map +1 -0
- package/build/crypto/crypto.js +1 -0
- package/build/crypto/crypto.js.map +1 -0
- package/build/crypto.d.ts +46 -7
- package/build/crypto.d.ts.map +1 -0
- package/build/crypto.js +65 -20
- package/build/crypto.js.map +1 -0
- package/build/ecc/context.d.ts +135 -0
- package/build/ecc/context.d.ts.map +1 -0
- package/build/ecc/context.js +232 -0
- package/build/ecc/context.js.map +1 -0
- package/build/ecc/index.d.ts +11 -0
- package/build/ecc/index.d.ts.map +1 -0
- package/build/ecc/index.js +11 -0
- package/build/ecc/index.js.map +1 -0
- package/build/ecc/types.d.ts +134 -0
- package/build/ecc/types.d.ts.map +1 -0
- package/build/ecc/types.js +8 -0
- package/build/ecc/types.js.map +1 -0
- package/build/errors.d.ts +124 -0
- package/build/errors.d.ts.map +1 -0
- package/build/errors.js +155 -0
- package/build/errors.js.map +1 -0
- package/build/index.d.ts +32 -5
- package/build/index.d.ts.map +1 -0
- package/build/index.js +26 -3
- package/build/index.js.map +1 -0
- package/build/io/BinaryReader.d.ts +276 -0
- package/build/io/BinaryReader.d.ts.map +1 -0
- package/build/io/BinaryReader.js +425 -0
- package/build/io/BinaryReader.js.map +1 -0
- package/build/io/BinaryWriter.d.ts +391 -0
- package/build/io/BinaryWriter.d.ts.map +1 -0
- package/build/io/BinaryWriter.js +611 -0
- package/build/io/BinaryWriter.js.map +1 -0
- package/build/io/MemoryPool.d.ts +220 -0
- package/build/io/MemoryPool.d.ts.map +1 -0
- package/build/io/MemoryPool.js +309 -0
- package/build/io/MemoryPool.js.map +1 -0
- package/build/io/base64.d.ts +13 -0
- package/build/io/base64.d.ts.map +1 -0
- package/build/io/base64.js +20 -0
- package/build/io/base64.js.map +1 -0
- package/build/io/hex.d.ts +67 -0
- package/build/io/hex.d.ts.map +1 -0
- package/build/io/hex.js +138 -0
- package/build/io/hex.js.map +1 -0
- package/build/io/index.d.ts +17 -0
- package/build/io/index.d.ts.map +1 -0
- package/build/io/index.js +23 -0
- package/build/io/index.js.map +1 -0
- package/build/io/utils.d.ts +199 -0
- package/build/io/utils.d.ts.map +1 -0
- package/build/io/utils.js +271 -0
- package/build/io/utils.js.map +1 -0
- package/build/merkle.d.ts +10 -1
- package/build/merkle.d.ts.map +1 -0
- package/build/merkle.js +12 -1
- package/build/merkle.js.map +1 -0
- package/build/networks.d.ts +70 -9
- package/build/networks.d.ts.map +1 -0
- package/build/networks.js +90 -4
- package/build/networks.js.map +1 -0
- package/build/opcodes.d.ts +1 -0
- package/build/opcodes.d.ts.map +1 -0
- package/build/opcodes.js +1 -0
- package/build/opcodes.js.map +1 -0
- package/build/payments/bip341.d.ts +36 -9
- package/build/payments/bip341.d.ts.map +1 -0
- package/build/payments/bip341.js +35 -15
- package/build/payments/bip341.js.map +1 -0
- package/build/payments/embed.d.ts +120 -1
- package/build/payments/embed.d.ts.map +1 -0
- package/build/payments/embed.js +215 -34
- package/build/payments/embed.js.map +1 -0
- package/build/payments/index.d.ts +17 -10
- package/build/payments/index.d.ts.map +1 -0
- package/build/payments/index.js +20 -10
- package/build/payments/index.js.map +1 -0
- package/build/payments/p2ms.d.ts +159 -1
- package/build/payments/p2ms.d.ts.map +1 -0
- package/build/payments/p2ms.js +427 -108
- package/build/payments/p2ms.js.map +1 -0
- package/build/payments/p2op.d.ts +158 -24
- package/build/payments/p2op.d.ts.map +1 -0
- package/build/payments/p2op.js +379 -93
- package/build/payments/p2op.js.map +1 -0
- package/build/payments/p2pk.d.ts +162 -1
- package/build/payments/p2pk.d.ts.map +1 -0
- package/build/payments/p2pk.js +327 -58
- package/build/payments/p2pk.js.map +1 -0
- package/build/payments/p2pkh.d.ts +185 -1
- package/build/payments/p2pkh.d.ts.map +1 -0
- package/build/payments/p2pkh.js +467 -114
- package/build/payments/p2pkh.js.map +1 -0
- package/build/payments/p2sh.d.ts +159 -1
- package/build/payments/p2sh.d.ts.map +1 -0
- package/build/payments/p2sh.js +500 -152
- package/build/payments/p2sh.js.map +1 -0
- package/build/payments/p2tr.d.ts +193 -1
- package/build/payments/p2tr.d.ts.map +1 -0
- package/build/payments/p2tr.js +592 -174
- package/build/payments/p2tr.js.map +1 -0
- package/build/payments/p2wpkh.d.ts +170 -1
- package/build/payments/p2wpkh.d.ts.map +1 -0
- package/build/payments/p2wpkh.js +429 -104
- package/build/payments/p2wpkh.js.map +1 -0
- package/build/payments/p2wsh.d.ts +155 -1
- package/build/payments/p2wsh.d.ts.map +1 -0
- package/build/payments/p2wsh.js +466 -144
- package/build/payments/p2wsh.js.map +1 -0
- package/build/payments/types.d.ts +98 -64
- package/build/payments/types.d.ts.map +1 -0
- package/build/payments/types.js +17 -13
- package/build/payments/types.js.map +1 -0
- package/build/psbt/bip371.d.ts +35 -9
- package/build/psbt/bip371.d.ts.map +1 -0
- package/build/psbt/bip371.js +113 -28
- package/build/psbt/bip371.js.map +1 -0
- package/build/psbt/psbtutils.d.ts +56 -16
- package/build/psbt/psbtutils.d.ts.map +1 -0
- package/build/psbt/psbtutils.js +71 -16
- package/build/psbt/psbtutils.js.map +1 -0
- package/build/psbt/types.d.ts +249 -0
- package/build/psbt/types.d.ts.map +1 -0
- package/build/psbt/types.js +6 -0
- package/build/psbt/types.js.map +1 -0
- package/build/psbt/utils.d.ts +68 -0
- package/build/psbt/utils.d.ts.map +1 -0
- package/build/psbt/utils.js +171 -0
- package/build/psbt/utils.js.map +1 -0
- package/build/psbt/validation.d.ts +88 -0
- package/build/psbt/validation.d.ts.map +1 -0
- package/build/psbt/validation.js +149 -0
- package/build/psbt/validation.js.map +1 -0
- package/build/psbt.d.ts +84 -120
- package/build/psbt.d.ts.map +1 -0
- package/build/psbt.js +411 -412
- package/build/psbt.js.map +1 -0
- package/build/pubkey.d.ts +27 -6
- package/build/pubkey.d.ts.map +1 -0
- package/build/pubkey.js +37 -13
- package/build/pubkey.js.map +1 -0
- package/build/push_data.d.ts +24 -2
- package/build/push_data.d.ts.map +1 -0
- package/build/push_data.js +44 -12
- package/build/push_data.js.map +1 -0
- package/build/script.d.ts +33 -8
- package/build/script.d.ts.map +1 -0
- package/build/script.js +100 -36
- package/build/script.js.map +1 -0
- package/build/script_number.d.ts +17 -0
- package/build/script_number.d.ts.map +1 -0
- package/build/script_number.js +19 -0
- package/build/script_number.js.map +1 -0
- package/build/script_signature.d.ts +23 -5
- package/build/script_signature.d.ts.map +1 -0
- package/build/script_signature.js +48 -15
- package/build/script_signature.js.map +1 -0
- package/build/transaction.d.ts +160 -18
- package/build/transaction.d.ts.map +1 -0
- package/build/transaction.js +443 -176
- package/build/transaction.js.map +1 -0
- package/build/tsconfig.build.tsbuildinfo +1 -0
- package/build/types.d.ts +36 -38
- package/build/types.d.ts.map +1 -0
- package/build/types.js +175 -57
- package/build/types.js.map +1 -0
- package/build/workers/WorkerSigningPool.d.ts +174 -0
- package/build/workers/WorkerSigningPool.d.ts.map +1 -0
- package/build/workers/WorkerSigningPool.js +553 -0
- package/build/workers/WorkerSigningPool.js.map +1 -0
- package/build/workers/WorkerSigningPool.node.d.ts +124 -0
- package/build/workers/WorkerSigningPool.node.d.ts.map +1 -0
- package/build/workers/WorkerSigningPool.node.js +753 -0
- package/build/workers/WorkerSigningPool.node.js.map +1 -0
- package/build/workers/ecc-bundle.d.ts +25 -0
- package/build/workers/ecc-bundle.d.ts.map +1 -0
- package/build/workers/ecc-bundle.js +25 -0
- package/build/workers/ecc-bundle.js.map +1 -0
- package/build/workers/index.d.ts +91 -0
- package/build/workers/index.d.ts.map +1 -0
- package/build/workers/index.js +114 -0
- package/build/workers/index.js.map +1 -0
- package/build/workers/psbt-parallel.d.ts +117 -0
- package/build/workers/psbt-parallel.d.ts.map +1 -0
- package/build/workers/psbt-parallel.js +233 -0
- package/build/workers/psbt-parallel.js.map +1 -0
- package/build/workers/signing-worker.d.ts +37 -0
- package/build/workers/signing-worker.d.ts.map +1 -0
- package/build/workers/signing-worker.js +350 -0
- package/build/workers/signing-worker.js.map +1 -0
- package/build/workers/types.d.ts +365 -0
- package/build/workers/types.d.ts.map +1 -0
- package/build/workers/types.js +60 -0
- package/build/workers/types.js.map +1 -0
- package/package.json +83 -25
- package/scripts/bundle-ecc.ts +111 -0
- package/src/address.ts +81 -44
- package/src/bech32utils.ts +3 -3
- package/src/bip66.ts +34 -24
- package/src/block.ts +196 -84
- package/src/branded.ts +18 -0
- package/src/crypto.ts +64 -26
- package/src/ecc/context.ts +277 -0
- package/src/ecc/index.ts +14 -0
- package/src/ecc/types.ts +154 -0
- package/src/ecpair.d.ts +99 -0
- package/src/errors.ts +163 -0
- package/src/index.ts +113 -9
- package/src/io/BinaryReader.ts +461 -0
- package/src/io/BinaryWriter.ts +696 -0
- package/src/io/MemoryPool.ts +343 -0
- package/src/io/base64.ts +20 -0
- package/src/io/hex.ts +155 -0
- package/src/io/index.ts +41 -0
- package/src/io/utils.ts +283 -0
- package/src/merkle.ts +14 -9
- package/src/networks.ts +9 -9
- package/src/payments/bip341.ts +34 -33
- package/src/payments/embed.ts +244 -41
- package/src/payments/index.ts +12 -10
- package/src/payments/p2ms.ts +490 -118
- package/src/payments/p2op.ts +431 -133
- package/src/payments/p2pk.ts +370 -72
- package/src/payments/p2pkh.ts +524 -130
- package/src/payments/p2sh.ts +572 -172
- package/src/payments/p2tr.ts +686 -194
- package/src/payments/p2wpkh.ts +484 -107
- package/src/payments/p2wsh.ts +526 -164
- package/src/payments/types.ts +80 -66
- package/src/psbt/bip371.ts +68 -51
- package/src/psbt/psbtutils.ts +39 -40
- package/src/psbt/types.ts +331 -0
- package/src/psbt/utils.ts +188 -0
- package/src/psbt/validation.ts +192 -0
- package/src/psbt.ts +566 -809
- package/src/pubkey.ts +24 -25
- package/src/push_data.ts +18 -16
- package/src/script.ts +82 -64
- package/src/script_number.ts +6 -6
- package/src/script_signature.ts +33 -36
- package/src/transaction.ts +458 -238
- package/src/types.ts +231 -100
- package/src/workers/WorkerSigningPool.node.ts +887 -0
- package/src/workers/WorkerSigningPool.ts +670 -0
- package/src/workers/ecc-bundle.ts +26 -0
- package/src/workers/index.ts +165 -0
- package/src/workers/psbt-parallel.ts +332 -0
- package/src/workers/signing-worker.ts +353 -0
- package/src/workers/types.ts +413 -0
- package/test/address.spec.ts +9 -6
- package/test/bitcoin.core.spec.ts +16 -17
- package/test/block.spec.ts +8 -7
- package/test/bufferutils.spec.ts +228 -214
- package/test/crypto.spec.ts +19 -11
- package/test/fixtures/p2pk.json +0 -8
- package/test/fixtures/p2pkh.json +1 -1
- package/test/fixtures/p2sh.json +1 -1
- package/test/fixtures/script.json +1 -1
- package/test/fixtures/transaction.json +2 -2
- package/test/integration/_regtest.ts +25 -0
- package/test/integration/addresses.spec.ts +4 -3
- package/test/integration/bip32.spec.ts +2 -1
- package/test/integration/blocks.spec.ts +1 -1
- package/test/integration/cltv.spec.ts +18 -16
- package/test/integration/csv.spec.ts +37 -64
- package/test/integration/payments.spec.ts +5 -3
- package/test/integration/taproot.spec.ts +76 -83
- package/test/integration/transactions.spec.ts +38 -35
- package/test/payments.spec.ts +35 -13
- package/test/payments.utils.ts +17 -16
- package/test/psbt.spec.ts +111 -100
- package/test/script.spec.ts +11 -10
- package/test/script_signature.spec.ts +9 -11
- package/test/taproot-cache.spec.ts +694 -0
- package/test/transaction.spec.ts +32 -40
- package/test/types.spec.ts +74 -29
- package/test/workers-pool.spec.ts +963 -0
- package/test/workers-signing.spec.ts +635 -0
- package/test/workers.spec.ts +1390 -0
- package/tsconfig.base.json +34 -18
- package/tsconfig.browser.json +15 -0
- package/tsconfig.build.json +5 -0
- package/tsconfig.json +5 -14
- package/vite.config.browser.ts +3 -42
- package/vitest.config.integration.ts +11 -0
- package/browser/bufferutils.d.ts +0 -34
- package/browser/chunks/crypto-BhCpKpek.js +0 -2033
- package/browser/chunks/payments-yjA0Evsv.js +0 -1089
- package/browser/chunks/psbt-URK2hBFc.js +0 -4039
- package/browser/chunks/script-DyPItFEl.js +0 -318
- package/browser/chunks/transaction-C_UbhMGn.js +0 -432
- package/browser/chunks/utils-DNZi-T5W.js +0 -761
- package/browser/ecc_lib.d.ts +0 -3
- package/browser/hooks/AdvancedSignatureManager.d.ts +0 -16
- package/browser/hooks/HookedSigner.d.ts +0 -4
- package/browser/hooks/SignatureManager.d.ts +0 -13
- package/browser/payments/lazy.d.ts +0 -2
- package/browser/typeforce.d.ts +0 -38
- package/build/bufferutils.d.ts +0 -34
- package/build/bufferutils.js +0 -141
- package/build/ecc_lib.d.ts +0 -3
- package/build/ecc_lib.js +0 -61
- package/build/hooks/AdvancedSignatureManager.d.ts +0 -16
- package/build/hooks/AdvancedSignatureManager.js +0 -52
- package/build/hooks/HookedSigner.d.ts +0 -4
- package/build/hooks/HookedSigner.js +0 -64
- package/build/hooks/SignatureManager.d.ts +0 -13
- package/build/hooks/SignatureManager.js +0 -45
- package/build/payments/lazy.d.ts +0 -2
- package/build/payments/lazy.js +0 -28
- package/build/tsconfig.tsbuildinfo +0 -1
- package/src/bufferutils.ts +0 -188
- package/src/ecc_lib.ts +0 -94
- package/src/hooks/AdvancedSignatureManager.ts +0 -104
- package/src/hooks/HookedSigner.ts +0 -108
- package/src/hooks/SignatureManager.ts +0 -84
- package/src/payments/lazy.ts +0 -28
- package/src/typeforce.d.ts +0 -38
- package/tsconfig.webpack.json +0 -18
package/build/io/hex.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hex encoding and decoding utilities.
|
|
3
|
+
*
|
|
4
|
+
* Direct implementations with zero dependencies and no wrappers.
|
|
5
|
+
* Optimized for performance with lookup tables.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Lookup table for byte to hex conversion.
|
|
11
|
+
* Pre-computed for O(1) lookup per byte.
|
|
12
|
+
*/
|
|
13
|
+
const BYTE_TO_HEX = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));
|
|
14
|
+
/**
|
|
15
|
+
* Lookup table for hex character to nibble conversion.
|
|
16
|
+
* Returns -1 for invalid characters.
|
|
17
|
+
*/
|
|
18
|
+
const HEX_TO_NIBBLE = (() => {
|
|
19
|
+
const table = new Array(128).fill(-1);
|
|
20
|
+
for (let i = 0; i < 10; i++) {
|
|
21
|
+
table[0x30 + i] = i; // '0'-'9'
|
|
22
|
+
}
|
|
23
|
+
for (let i = 0; i < 6; i++) {
|
|
24
|
+
table[0x41 + i] = 10 + i; // 'A'-'F'
|
|
25
|
+
table[0x61 + i] = 10 + i; // 'a'-'f'
|
|
26
|
+
}
|
|
27
|
+
return table;
|
|
28
|
+
})();
|
|
29
|
+
/**
|
|
30
|
+
* Converts a Uint8Array to a lowercase hex string.
|
|
31
|
+
*
|
|
32
|
+
* @param bytes - The byte array to convert
|
|
33
|
+
* @returns Lowercase hex string representation
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* import { toHex } from '@btc-vision/bitcoin';
|
|
38
|
+
*
|
|
39
|
+
* const bytes = new Uint8Array([0xde, 0xad, 0xbe, 0xef]);
|
|
40
|
+
* const hex = toHex(bytes);
|
|
41
|
+
* console.log(hex); // 'deadbeef'
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export function toHex(bytes) {
|
|
45
|
+
let result = '';
|
|
46
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
47
|
+
result += BYTE_TO_HEX[bytes[i]];
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Converts a hex string to a Uint8Array.
|
|
53
|
+
*
|
|
54
|
+
* Accepts hex strings with or without '0x' prefix.
|
|
55
|
+
* Case-insensitive (accepts both 'DEADBEEF' and 'deadbeef').
|
|
56
|
+
*
|
|
57
|
+
* @param hex - The hex string to convert
|
|
58
|
+
* @returns Uint8Array containing the decoded bytes
|
|
59
|
+
* @throws TypeError if hex string has odd length
|
|
60
|
+
* @throws TypeError if hex string contains invalid characters
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* import { fromHex, toHex } from '@btc-vision/bitcoin';
|
|
65
|
+
*
|
|
66
|
+
* const bytes = fromHex('deadbeef');
|
|
67
|
+
* console.log(bytes); // Uint8Array [222, 173, 190, 239]
|
|
68
|
+
*
|
|
69
|
+
* // Also works with 0x prefix
|
|
70
|
+
* const bytes2 = fromHex('0xCAFEBABE');
|
|
71
|
+
* console.log(toHex(bytes2)); // 'cafebabe'
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export function fromHex(hex) {
|
|
75
|
+
// Strip 0x prefix if present
|
|
76
|
+
if (hex.length >= 2 && hex[0] === '0' && (hex[1] === 'x' || hex[1] === 'X')) {
|
|
77
|
+
hex = hex.slice(2);
|
|
78
|
+
}
|
|
79
|
+
const len = hex.length;
|
|
80
|
+
if (len % 2 !== 0) {
|
|
81
|
+
throw new TypeError('Invalid hex string: odd length');
|
|
82
|
+
}
|
|
83
|
+
const byteLength = len / 2;
|
|
84
|
+
const result = new Uint8Array(byteLength);
|
|
85
|
+
for (let i = 0; i < byteLength; i++) {
|
|
86
|
+
const charIndex = i * 2;
|
|
87
|
+
const highCode = hex.charCodeAt(charIndex);
|
|
88
|
+
const lowCode = hex.charCodeAt(charIndex + 1);
|
|
89
|
+
// Bounds check for lookup table
|
|
90
|
+
if (highCode >= 128 || lowCode >= 128) {
|
|
91
|
+
throw new TypeError(`Invalid hex character at position ${charIndex}`);
|
|
92
|
+
}
|
|
93
|
+
const high = HEX_TO_NIBBLE[highCode];
|
|
94
|
+
const low = HEX_TO_NIBBLE[lowCode];
|
|
95
|
+
if (high === -1) {
|
|
96
|
+
throw new TypeError(`Invalid hex character at position ${charIndex}`);
|
|
97
|
+
}
|
|
98
|
+
if (low === -1) {
|
|
99
|
+
throw new TypeError(`Invalid hex character at position ${charIndex + 1}`);
|
|
100
|
+
}
|
|
101
|
+
result[i] = (high << 4) | low;
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Checks if a string is valid hexadecimal.
|
|
107
|
+
*
|
|
108
|
+
* @param value - The string to check
|
|
109
|
+
* @returns True if the string is valid hex (even length, valid chars)
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* import { isHex } from '@btc-vision/bitcoin';
|
|
114
|
+
*
|
|
115
|
+
* isHex('deadbeef'); // true
|
|
116
|
+
* isHex('0xdeadbeef'); // true
|
|
117
|
+
* isHex('DEADBEEF'); // true
|
|
118
|
+
* isHex('deadbee'); // false (odd length)
|
|
119
|
+
* isHex('deadbeeg'); // false (invalid char)
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export function isHex(value) {
|
|
123
|
+
let hex = value;
|
|
124
|
+
if (hex.length >= 2 && hex[0] === '0' && (hex[1] === 'x' || hex[1] === 'X')) {
|
|
125
|
+
hex = hex.slice(2);
|
|
126
|
+
}
|
|
127
|
+
if (hex.length % 2 !== 0) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
for (let i = 0; i < hex.length; i++) {
|
|
131
|
+
const code = hex.charCodeAt(i);
|
|
132
|
+
if (code >= 128 || HEX_TO_NIBBLE[code] === -1) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=hex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hex.js","sourceRoot":"","sources":["../../src/io/hex.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;GAGG;AACH,MAAM,WAAW,GAAsB,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CACxE,CAAC,CAAC,QAAQ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CAAC;QAC9E,CAAC;QAED,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,IAAK,IAAI,CAAC,CAAC,GAAG,GAAI,CAAC;IACpC,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,KAAK,CAAC,KAAa;IAC/B,IAAI,GAAG,GAAG,KAAK,CAAC;IAChB,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC;QAC1E,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC;IAED,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC/B,IAAI,IAAI,IAAI,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YAC5C,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-performance binary I/O module.
|
|
3
|
+
*
|
|
4
|
+
* This module provides efficient binary reading and writing with
|
|
5
|
+
* zero-allocation operations through stateful DataView instances.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import * as varuint from 'varuint-bitcoin';
|
|
10
|
+
export { BinaryReader } from './BinaryReader.js';
|
|
11
|
+
export { BinaryWriter, GrowableBinaryWriter } from './BinaryWriter.js';
|
|
12
|
+
export { toHex, fromHex, isHex } from './hex.js';
|
|
13
|
+
export { fromBase64 } from './base64.js';
|
|
14
|
+
export { concat, equals, compare, isZero, clone, reverse, reverseCopy, alloc, xor, fromUtf8, toUtf8, } from './utils.js';
|
|
15
|
+
export { MemoryPool, SimpleMemoryPool } from './MemoryPool.js';
|
|
16
|
+
export { varuint };
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/io/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAC;AAG3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAGvE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAGjD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EACH,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,KAAK,EACL,OAAO,EACP,WAAW,EACX,KAAK,EACL,GAAG,EACH,QAAQ,EACR,MAAM,GACT,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAG/D,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-performance binary I/O module.
|
|
3
|
+
*
|
|
4
|
+
* This module provides efficient binary reading and writing with
|
|
5
|
+
* zero-allocation operations through stateful DataView instances.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import * as varuint from 'varuint-bitcoin';
|
|
10
|
+
// Binary reading and writing
|
|
11
|
+
export { BinaryReader } from './BinaryReader.js';
|
|
12
|
+
export { BinaryWriter, GrowableBinaryWriter } from './BinaryWriter.js';
|
|
13
|
+
// Hex encoding/decoding
|
|
14
|
+
export { toHex, fromHex, isHex } from './hex.js';
|
|
15
|
+
// Base64 decoding
|
|
16
|
+
export { fromBase64 } from './base64.js';
|
|
17
|
+
// Utility functions
|
|
18
|
+
export { concat, equals, compare, isZero, clone, reverse, reverseCopy, alloc, xor, fromUtf8, toUtf8, } from './utils.js';
|
|
19
|
+
// Memory pools
|
|
20
|
+
export { MemoryPool, SimpleMemoryPool } from './MemoryPool.js';
|
|
21
|
+
// Re-export varuint for Bitcoin CompactSize encoding
|
|
22
|
+
export { varuint };
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/io/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAC;AAE3C,6BAA6B;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEvE,wBAAwB;AACxB,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjD,kBAAkB;AAClB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,oBAAoB;AACpB,OAAO,EACH,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,KAAK,EACL,OAAO,EACP,WAAW,EACX,KAAK,EACL,GAAG,EACH,QAAQ,EACR,MAAM,GACT,MAAM,YAAY,CAAC;AAEpB,eAAe;AACf,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAE/D,qDAAqD;AACrD,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure utility functions for Uint8Array operations.
|
|
3
|
+
*
|
|
4
|
+
* No DataView allocations. No wrappers.
|
|
5
|
+
* Optimized for performance with minimal allocations.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Concatenates multiple Uint8Arrays into a single Uint8Array.
|
|
11
|
+
*
|
|
12
|
+
* Allocates exactly once for the result array.
|
|
13
|
+
*
|
|
14
|
+
* @param arrays - Arrays to concatenate
|
|
15
|
+
* @returns A new Uint8Array containing all input arrays
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { concat, fromHex } from '@btc-vision/bitcoin';
|
|
20
|
+
*
|
|
21
|
+
* const a = fromHex('deadbeef');
|
|
22
|
+
* const b = fromHex('cafebabe');
|
|
23
|
+
* const result = concat([a, b]);
|
|
24
|
+
* // result contains deadbeefcafebabe
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function concat(arrays: readonly Uint8Array[]): Uint8Array;
|
|
28
|
+
/**
|
|
29
|
+
* Checks if two Uint8Arrays have identical contents.
|
|
30
|
+
*
|
|
31
|
+
* @param a - First array
|
|
32
|
+
* @param b - Second array
|
|
33
|
+
* @returns True if arrays have the same length and contents
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* import { equals, fromHex } from '@btc-vision/bitcoin';
|
|
38
|
+
*
|
|
39
|
+
* const a = fromHex('deadbeef');
|
|
40
|
+
* const b = fromHex('deadbeef');
|
|
41
|
+
* const c = fromHex('cafebabe');
|
|
42
|
+
*
|
|
43
|
+
* equals(a, b); // true
|
|
44
|
+
* equals(a, c); // false
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function equals(a: Uint8Array, b: Uint8Array): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Compares two Uint8Arrays lexicographically.
|
|
50
|
+
*
|
|
51
|
+
* @param a - First array
|
|
52
|
+
* @param b - Second array
|
|
53
|
+
* @returns Negative if a < b, positive if a > b, 0 if equal
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* import { compare, fromHex } from '@btc-vision/bitcoin';
|
|
58
|
+
*
|
|
59
|
+
* const a = fromHex('0001');
|
|
60
|
+
* const b = fromHex('0002');
|
|
61
|
+
*
|
|
62
|
+
* compare(a, b); // -1 (a < b)
|
|
63
|
+
* compare(b, a); // 1 (b > a)
|
|
64
|
+
* compare(a, a); // 0 (equal)
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare function compare(a: Uint8Array, b: Uint8Array): number;
|
|
68
|
+
/**
|
|
69
|
+
* Checks if a Uint8Array contains only zero bytes.
|
|
70
|
+
*
|
|
71
|
+
* @param bytes - Array to check
|
|
72
|
+
* @returns True if all bytes are zero
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* import { isZero } from '@btc-vision/bitcoin';
|
|
77
|
+
*
|
|
78
|
+
* isZero(new Uint8Array(32)); // true
|
|
79
|
+
* isZero(new Uint8Array([0, 0, 1])); // false
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare function isZero(bytes: Uint8Array): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Creates a copy of a Uint8Array.
|
|
85
|
+
*
|
|
86
|
+
* @param bytes - Array to clone
|
|
87
|
+
* @returns A new Uint8Array with the same contents
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* import { clone, fromHex } from '@btc-vision/bitcoin';
|
|
92
|
+
*
|
|
93
|
+
* const original = fromHex('deadbeef');
|
|
94
|
+
* const copy = clone(original);
|
|
95
|
+
* copy[0] = 0; // Modifying copy doesn't affect original
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export declare function clone(bytes: Uint8Array): Uint8Array;
|
|
99
|
+
/**
|
|
100
|
+
* Reverses a Uint8Array in place.
|
|
101
|
+
*
|
|
102
|
+
* @param bytes - Array to reverse
|
|
103
|
+
* @returns The same array, reversed
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* import { reverse, fromHex, toHex } from '@btc-vision/bitcoin';
|
|
108
|
+
*
|
|
109
|
+
* const bytes = fromHex('01020304');
|
|
110
|
+
* reverse(bytes);
|
|
111
|
+
* toHex(bytes); // '04030201'
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export declare function reverse(bytes: Uint8Array): Uint8Array;
|
|
115
|
+
/**
|
|
116
|
+
* Creates a reversed copy of a Uint8Array.
|
|
117
|
+
*
|
|
118
|
+
* @param bytes - Array to copy and reverse
|
|
119
|
+
* @returns A new reversed Uint8Array
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* import { reverseCopy, fromHex, toHex } from '@btc-vision/bitcoin';
|
|
124
|
+
*
|
|
125
|
+
* const bytes = fromHex('01020304');
|
|
126
|
+
* const reversed = reverseCopy(bytes);
|
|
127
|
+
* toHex(reversed); // '04030201'
|
|
128
|
+
* toHex(bytes); // '01020304' (original unchanged)
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export declare function reverseCopy(bytes: Uint8Array): Uint8Array;
|
|
132
|
+
/**
|
|
133
|
+
* Allocates a new Uint8Array of the specified size.
|
|
134
|
+
*
|
|
135
|
+
* @param size - Number of bytes to allocate
|
|
136
|
+
* @param fill - Optional fill value (default 0)
|
|
137
|
+
* @returns A new Uint8Array filled with the specified value
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* import { alloc, toHex } from '@btc-vision/bitcoin';
|
|
142
|
+
*
|
|
143
|
+
* const zeros = alloc(4); // 4 zero bytes
|
|
144
|
+
* const ones = alloc(4, 0xff); // 4 bytes of 0xff
|
|
145
|
+
* toHex(ones); // 'ffffffff'
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export declare function alloc(size: number, fill?: number): Uint8Array;
|
|
149
|
+
/**
|
|
150
|
+
* XORs two Uint8Arrays together.
|
|
151
|
+
*
|
|
152
|
+
* @param a - First array
|
|
153
|
+
* @param b - Second array
|
|
154
|
+
* @returns A new Uint8Array with the XOR result
|
|
155
|
+
* @throws TypeError if arrays have different lengths
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* import { xor, fromHex, toHex } from '@btc-vision/bitcoin';
|
|
160
|
+
*
|
|
161
|
+
* const a = fromHex('ff00ff00');
|
|
162
|
+
* const b = fromHex('0f0f0f0f');
|
|
163
|
+
* const result = xor(a, b);
|
|
164
|
+
* toHex(result); // 'f00ff00f'
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
export declare function xor(a: Uint8Array, b: Uint8Array): Uint8Array;
|
|
168
|
+
/**
|
|
169
|
+
* Creates a Uint8Array from a UTF-8 string.
|
|
170
|
+
*
|
|
171
|
+
* @param str - String to encode
|
|
172
|
+
* @returns Uint8Array containing UTF-8 encoded bytes
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* import { fromUtf8, toHex } from '@btc-vision/bitcoin';
|
|
177
|
+
*
|
|
178
|
+
* const bytes = fromUtf8('hello');
|
|
179
|
+
* toHex(bytes); // '68656c6c6f'
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
export declare function fromUtf8(str: string): Uint8Array;
|
|
183
|
+
/**
|
|
184
|
+
* Decodes a Uint8Array to a UTF-8 string.
|
|
185
|
+
*
|
|
186
|
+
* @param bytes - Uint8Array to decode
|
|
187
|
+
* @returns Decoded string
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* import { toUtf8, fromHex } from '@btc-vision/bitcoin';
|
|
192
|
+
*
|
|
193
|
+
* const bytes = fromHex('68656c6c6f');
|
|
194
|
+
* const str = toUtf8(bytes);
|
|
195
|
+
* // str is 'hello'
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
export declare function toUtf8(bytes: Uint8Array): string;
|
|
199
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/io/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,GAAG,UAAU,CAehE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO,CAU5D;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,MAAM,CAS5D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAOjD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAKnD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAGrD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAMzD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,MAAU,GAAG,UAAU,CAMhE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,UAAU,CAS5D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAEhD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAEhD"}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure utility functions for Uint8Array operations.
|
|
3
|
+
*
|
|
4
|
+
* No DataView allocations. No wrappers.
|
|
5
|
+
* Optimized for performance with minimal allocations.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Concatenates multiple Uint8Arrays into a single Uint8Array.
|
|
11
|
+
*
|
|
12
|
+
* Allocates exactly once for the result array.
|
|
13
|
+
*
|
|
14
|
+
* @param arrays - Arrays to concatenate
|
|
15
|
+
* @returns A new Uint8Array containing all input arrays
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { concat, fromHex } from '@btc-vision/bitcoin';
|
|
20
|
+
*
|
|
21
|
+
* const a = fromHex('deadbeef');
|
|
22
|
+
* const b = fromHex('cafebabe');
|
|
23
|
+
* const result = concat([a, b]);
|
|
24
|
+
* // result contains deadbeefcafebabe
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function concat(arrays) {
|
|
28
|
+
let totalLength = 0;
|
|
29
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
30
|
+
totalLength += arrays[i].length;
|
|
31
|
+
}
|
|
32
|
+
const result = new Uint8Array(totalLength);
|
|
33
|
+
let offset = 0;
|
|
34
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
35
|
+
const arr = arrays[i];
|
|
36
|
+
result.set(arr, offset);
|
|
37
|
+
offset += arr.length;
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Checks if two Uint8Arrays have identical contents.
|
|
43
|
+
*
|
|
44
|
+
* @param a - First array
|
|
45
|
+
* @param b - Second array
|
|
46
|
+
* @returns True if arrays have the same length and contents
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* import { equals, fromHex } from '@btc-vision/bitcoin';
|
|
51
|
+
*
|
|
52
|
+
* const a = fromHex('deadbeef');
|
|
53
|
+
* const b = fromHex('deadbeef');
|
|
54
|
+
* const c = fromHex('cafebabe');
|
|
55
|
+
*
|
|
56
|
+
* equals(a, b); // true
|
|
57
|
+
* equals(a, c); // false
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export function equals(a, b) {
|
|
61
|
+
if (a.length !== b.length) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
for (let i = 0; i < a.length; i++) {
|
|
65
|
+
if (a[i] !== b[i]) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Compares two Uint8Arrays lexicographically.
|
|
73
|
+
*
|
|
74
|
+
* @param a - First array
|
|
75
|
+
* @param b - Second array
|
|
76
|
+
* @returns Negative if a < b, positive if a > b, 0 if equal
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* import { compare, fromHex } from '@btc-vision/bitcoin';
|
|
81
|
+
*
|
|
82
|
+
* const a = fromHex('0001');
|
|
83
|
+
* const b = fromHex('0002');
|
|
84
|
+
*
|
|
85
|
+
* compare(a, b); // -1 (a < b)
|
|
86
|
+
* compare(b, a); // 1 (b > a)
|
|
87
|
+
* compare(a, a); // 0 (equal)
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export function compare(a, b) {
|
|
91
|
+
const minLength = Math.min(a.length, b.length);
|
|
92
|
+
for (let i = 0; i < minLength; i++) {
|
|
93
|
+
const diff = a[i] - b[i];
|
|
94
|
+
if (diff !== 0) {
|
|
95
|
+
return diff;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return a.length - b.length;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Checks if a Uint8Array contains only zero bytes.
|
|
102
|
+
*
|
|
103
|
+
* @param bytes - Array to check
|
|
104
|
+
* @returns True if all bytes are zero
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* import { isZero } from '@btc-vision/bitcoin';
|
|
109
|
+
*
|
|
110
|
+
* isZero(new Uint8Array(32)); // true
|
|
111
|
+
* isZero(new Uint8Array([0, 0, 1])); // false
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export function isZero(bytes) {
|
|
115
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
116
|
+
if (bytes[i] !== 0) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Creates a copy of a Uint8Array.
|
|
124
|
+
*
|
|
125
|
+
* @param bytes - Array to clone
|
|
126
|
+
* @returns A new Uint8Array with the same contents
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* import { clone, fromHex } from '@btc-vision/bitcoin';
|
|
131
|
+
*
|
|
132
|
+
* const original = fromHex('deadbeef');
|
|
133
|
+
* const copy = clone(original);
|
|
134
|
+
* copy[0] = 0; // Modifying copy doesn't affect original
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export function clone(bytes) {
|
|
138
|
+
// Create a true copy - .slice() on Buffer returns a view, not a copy
|
|
139
|
+
const copy = new Uint8Array(bytes.length);
|
|
140
|
+
copy.set(bytes);
|
|
141
|
+
return copy;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Reverses a Uint8Array in place.
|
|
145
|
+
*
|
|
146
|
+
* @param bytes - Array to reverse
|
|
147
|
+
* @returns The same array, reversed
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* import { reverse, fromHex, toHex } from '@btc-vision/bitcoin';
|
|
152
|
+
*
|
|
153
|
+
* const bytes = fromHex('01020304');
|
|
154
|
+
* reverse(bytes);
|
|
155
|
+
* toHex(bytes); // '04030201'
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export function reverse(bytes) {
|
|
159
|
+
bytes.reverse();
|
|
160
|
+
return bytes;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Creates a reversed copy of a Uint8Array.
|
|
164
|
+
*
|
|
165
|
+
* @param bytes - Array to copy and reverse
|
|
166
|
+
* @returns A new reversed Uint8Array
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* import { reverseCopy, fromHex, toHex } from '@btc-vision/bitcoin';
|
|
171
|
+
*
|
|
172
|
+
* const bytes = fromHex('01020304');
|
|
173
|
+
* const reversed = reverseCopy(bytes);
|
|
174
|
+
* toHex(reversed); // '04030201'
|
|
175
|
+
* toHex(bytes); // '01020304' (original unchanged)
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
export function reverseCopy(bytes) {
|
|
179
|
+
const result = new Uint8Array(bytes.length);
|
|
180
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
181
|
+
result[i] = bytes[bytes.length - 1 - i];
|
|
182
|
+
}
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Allocates a new Uint8Array of the specified size.
|
|
187
|
+
*
|
|
188
|
+
* @param size - Number of bytes to allocate
|
|
189
|
+
* @param fill - Optional fill value (default 0)
|
|
190
|
+
* @returns A new Uint8Array filled with the specified value
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* import { alloc, toHex } from '@btc-vision/bitcoin';
|
|
195
|
+
*
|
|
196
|
+
* const zeros = alloc(4); // 4 zero bytes
|
|
197
|
+
* const ones = alloc(4, 0xff); // 4 bytes of 0xff
|
|
198
|
+
* toHex(ones); // 'ffffffff'
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
export function alloc(size, fill = 0) {
|
|
202
|
+
const result = new Uint8Array(size);
|
|
203
|
+
if (fill !== 0) {
|
|
204
|
+
result.fill(fill);
|
|
205
|
+
}
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* XORs two Uint8Arrays together.
|
|
210
|
+
*
|
|
211
|
+
* @param a - First array
|
|
212
|
+
* @param b - Second array
|
|
213
|
+
* @returns A new Uint8Array with the XOR result
|
|
214
|
+
* @throws TypeError if arrays have different lengths
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```typescript
|
|
218
|
+
* import { xor, fromHex, toHex } from '@btc-vision/bitcoin';
|
|
219
|
+
*
|
|
220
|
+
* const a = fromHex('ff00ff00');
|
|
221
|
+
* const b = fromHex('0f0f0f0f');
|
|
222
|
+
* const result = xor(a, b);
|
|
223
|
+
* toHex(result); // 'f00ff00f'
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
export function xor(a, b) {
|
|
227
|
+
if (a.length !== b.length) {
|
|
228
|
+
throw new TypeError('Arrays must have the same length for XOR operation');
|
|
229
|
+
}
|
|
230
|
+
const result = new Uint8Array(a.length);
|
|
231
|
+
for (let i = 0; i < a.length; i++) {
|
|
232
|
+
result[i] = a[i] ^ b[i];
|
|
233
|
+
}
|
|
234
|
+
return result;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Creates a Uint8Array from a UTF-8 string.
|
|
238
|
+
*
|
|
239
|
+
* @param str - String to encode
|
|
240
|
+
* @returns Uint8Array containing UTF-8 encoded bytes
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* import { fromUtf8, toHex } from '@btc-vision/bitcoin';
|
|
245
|
+
*
|
|
246
|
+
* const bytes = fromUtf8('hello');
|
|
247
|
+
* toHex(bytes); // '68656c6c6f'
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
export function fromUtf8(str) {
|
|
251
|
+
return new TextEncoder().encode(str);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Decodes a Uint8Array to a UTF-8 string.
|
|
255
|
+
*
|
|
256
|
+
* @param bytes - Uint8Array to decode
|
|
257
|
+
* @returns Decoded string
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```typescript
|
|
261
|
+
* import { toUtf8, fromHex } from '@btc-vision/bitcoin';
|
|
262
|
+
*
|
|
263
|
+
* const bytes = fromHex('68656c6c6f');
|
|
264
|
+
* const str = toUtf8(bytes);
|
|
265
|
+
* // str is 'hello'
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
268
|
+
export function toUtf8(bytes) {
|
|
269
|
+
return new TextDecoder().decode(bytes);
|
|
270
|
+
}
|
|
271
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/io/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,MAAM,CAAC,MAA6B;IAChD,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,WAAW,IAAI,MAAM,CAAC,CAAC,CAAE,CAAC,MAAM,CAAC;IACrC,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;IAC3C,IAAI,MAAM,GAAG,C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,IAAI,CAAC,CAAC;IACpC,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;QACb,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,GAAG,CAAC,CAAa,EAAE,CAAa;IAC5C,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QACxB,MAAM,IAAI,SAAS,CAAC,oDAAoD,CAAC,CAAC;IAC9E,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC;IAC9B,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAW;IAChC,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACzC,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,MAAM,CAAC,KAAiB;IACpC,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC3C,CAAC"}
|
package/build/merkle.d.ts
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
-
|
|
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
|
+
*/
|
|
9
|
+
export declare function fastMerkleRoot(values: Uint8Array[], digestFn: (b: Uint8Array) => Uint8Array): Uint8Array;
|
|
10
|
+
//# sourceMappingURL=merkle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merkle.d.ts","sourceRoot":"","sources":["../src/merkle.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC1B,MAAM,EAAE,UAAU,EAAE,EACpB,QAAQ,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,UAAU,GACxC,UAAU,CAwBZ"}
|