@btc-vision/bitcoin 6.5.6 → 7.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HOW_TO_WRITE_GOOD_CODE.md +2436 -0
- package/benchmark/psbt-2000-inputs.bench.ts +178 -0
- package/benchmark/signing.bench.ts +147 -0
- package/browser/address.d.ts +56 -9
- package/browser/address.d.ts.map +1 -0
- package/browser/bech32utils.d.ts +9 -1
- package/browser/bech32utils.d.ts.map +1 -0
- package/browser/bip66.d.ts +11 -6
- package/browser/bip66.d.ts.map +1 -0
- package/browser/block.d.ts +117 -11
- package/browser/block.d.ts.map +1 -0
- package/browser/branded.d.ts +20 -0
- package/browser/branded.d.ts.map +1 -0
- package/browser/crypto/crypto.d.ts +1 -0
- package/browser/crypto/crypto.d.ts.map +1 -0
- package/browser/crypto.d.ts +46 -7
- package/browser/crypto.d.ts.map +1 -0
- package/browser/ecc/context.d.ts +129 -0
- package/browser/ecc/context.d.ts.map +1 -0
- package/browser/ecc/index.d.ts +11 -0
- package/browser/ecc/index.d.ts.map +1 -0
- package/browser/ecc/types.d.ts +128 -0
- package/browser/ecc/types.d.ts.map +1 -0
- package/browser/ecpair.d.ts +99 -0
- package/browser/errors.d.ts +124 -0
- package/browser/errors.d.ts.map +1 -0
- package/browser/index.d.ts +32 -5
- package/browser/index.d.ts.map +1 -0
- package/browser/index.js +12482 -101
- package/browser/io/BinaryReader.d.ts +276 -0
- package/browser/io/BinaryReader.d.ts.map +1 -0
- package/browser/io/BinaryWriter.d.ts +391 -0
- package/browser/io/BinaryWriter.d.ts.map +1 -0
- package/browser/io/MemoryPool.d.ts +220 -0
- package/browser/io/MemoryPool.d.ts.map +1 -0
- package/browser/io/base64.d.ts +13 -0
- package/browser/io/base64.d.ts.map +1 -0
- package/browser/io/hex.d.ts +67 -0
- package/browser/io/hex.d.ts.map +1 -0
- package/browser/io/index.d.ts +17 -0
- package/browser/io/index.d.ts.map +1 -0
- package/browser/io/utils.d.ts +199 -0
- package/browser/io/utils.d.ts.map +1 -0
- package/browser/merkle.d.ts +10 -1
- package/browser/merkle.d.ts.map +1 -0
- package/browser/networks.d.ts +70 -9
- package/browser/networks.d.ts.map +1 -0
- package/browser/opcodes.d.ts +1 -0
- package/browser/opcodes.d.ts.map +1 -0
- package/browser/payments/bip341.d.ts +35 -9
- package/browser/payments/bip341.d.ts.map +1 -0
- package/browser/payments/embed.d.ts +112 -1
- package/browser/payments/embed.d.ts.map +1 -0
- package/browser/payments/index.d.ts +17 -10
- package/browser/payments/index.d.ts.map +1 -0
- package/browser/payments/p2ms.d.ts +150 -0
- package/browser/payments/p2ms.d.ts.map +1 -0
- package/browser/payments/p2op.d.ts +150 -24
- package/browser/payments/p2op.d.ts.map +1 -0
- package/browser/payments/p2pk.d.ts +154 -1
- package/browser/payments/p2pk.d.ts.map +1 -0
- package/browser/payments/p2pkh.d.ts +176 -1
- package/browser/payments/p2pkh.d.ts.map +1 -0
- package/browser/payments/p2sh.d.ts +150 -1
- package/browser/payments/p2sh.d.ts.map +1 -0
- package/browser/payments/p2tr.d.ts +185 -1
- package/browser/payments/p2tr.d.ts.map +1 -0
- package/browser/payments/p2wpkh.d.ts +161 -1
- package/browser/payments/p2wpkh.d.ts.map +1 -0
- package/browser/payments/p2wsh.d.ts +146 -1
- package/browser/payments/p2wsh.d.ts.map +1 -0
- package/browser/payments/types.d.ts +94 -64
- package/browser/payments/types.d.ts.map +1 -0
- package/browser/psbt/bip371.d.ts +34 -8
- package/browser/psbt/bip371.d.ts.map +1 -0
- package/browser/psbt/psbtutils.d.ts +56 -16
- package/browser/psbt/psbtutils.d.ts.map +1 -0
- package/browser/psbt/types.d.ts +245 -0
- package/browser/psbt/types.d.ts.map +1 -0
- package/browser/psbt/utils.d.ts +64 -0
- package/browser/psbt/utils.d.ts.map +1 -0
- package/browser/psbt/validation.d.ts +84 -0
- package/browser/psbt/validation.d.ts.map +1 -0
- package/browser/psbt.d.ts +82 -118
- package/browser/psbt.d.ts.map +1 -0
- package/browser/pubkey.d.ts +27 -6
- package/browser/pubkey.d.ts.map +1 -0
- package/browser/push_data.d.ts +24 -2
- package/browser/push_data.d.ts.map +1 -0
- package/browser/script.d.ts +33 -8
- package/browser/script.d.ts.map +1 -0
- package/browser/script_number.d.ts +17 -0
- package/browser/script_number.d.ts.map +1 -0
- package/browser/script_signature.d.ts +23 -5
- package/browser/script_signature.d.ts.map +1 -0
- package/browser/transaction.d.ts +160 -18
- package/browser/transaction.d.ts.map +1 -0
- package/browser/types.d.ts +36 -38
- package/browser/types.d.ts.map +1 -0
- package/browser/workers/WorkerSigningPool.d.ts +143 -0
- package/browser/workers/WorkerSigningPool.d.ts.map +1 -0
- package/browser/workers/WorkerSigningPool.node.d.ts +116 -0
- package/browser/workers/WorkerSigningPool.node.d.ts.map +1 -0
- package/browser/workers/ecc-bundle.d.ts +25 -0
- package/browser/workers/ecc-bundle.d.ts.map +1 -0
- package/browser/workers/index.d.ts +91 -0
- package/browser/workers/index.d.ts.map +1 -0
- package/browser/workers/psbt-parallel.d.ts +88 -0
- package/browser/workers/psbt-parallel.d.ts.map +1 -0
- package/browser/workers/signing-worker.d.ts +37 -0
- package/browser/workers/signing-worker.d.ts.map +1 -0
- package/browser/workers/types.d.ts +365 -0
- package/browser/workers/types.d.ts.map +1 -0
- package/build/address.d.ts +57 -10
- package/build/address.d.ts.map +1 -0
- package/build/address.js +80 -24
- package/build/address.js.map +1 -0
- package/build/bech32utils.d.ts +9 -1
- package/build/bech32utils.d.ts.map +1 -0
- package/build/bech32utils.js +10 -2
- package/build/bech32utils.js.map +1 -0
- package/build/bip66.d.ts +11 -6
- package/build/bip66.d.ts.map +1 -0
- package/build/bip66.js +32 -3
- package/build/bip66.js.map +1 -0
- package/build/block.d.ts +117 -11
- package/build/block.d.ts.map +1 -0
- package/build/block.js +204 -72
- package/build/block.js.map +1 -0
- package/build/branded.d.ts +20 -0
- package/build/branded.d.ts.map +1 -0
- package/build/branded.js +7 -0
- package/build/branded.js.map +1 -0
- package/build/crypto/crypto.d.ts +1 -0
- package/build/crypto/crypto.d.ts.map +1 -0
- package/build/crypto/crypto.js +1 -0
- package/build/crypto/crypto.js.map +1 -0
- package/build/crypto.d.ts +46 -7
- package/build/crypto.d.ts.map +1 -0
- package/build/crypto.js +65 -20
- package/build/crypto.js.map +1 -0
- package/build/ecc/context.d.ts +135 -0
- package/build/ecc/context.d.ts.map +1 -0
- package/build/ecc/context.js +232 -0
- package/build/ecc/context.js.map +1 -0
- package/build/ecc/index.d.ts +11 -0
- package/build/ecc/index.d.ts.map +1 -0
- package/build/ecc/index.js +11 -0
- package/build/ecc/index.js.map +1 -0
- package/build/ecc/types.d.ts +134 -0
- package/build/ecc/types.d.ts.map +1 -0
- package/build/ecc/types.js +8 -0
- package/build/ecc/types.js.map +1 -0
- package/build/errors.d.ts +124 -0
- package/build/errors.d.ts.map +1 -0
- package/build/errors.js +155 -0
- package/build/errors.js.map +1 -0
- package/build/index.d.ts +32 -5
- package/build/index.d.ts.map +1 -0
- package/build/index.js +26 -3
- package/build/index.js.map +1 -0
- package/build/io/BinaryReader.d.ts +276 -0
- package/build/io/BinaryReader.d.ts.map +1 -0
- package/build/io/BinaryReader.js +425 -0
- package/build/io/BinaryReader.js.map +1 -0
- package/build/io/BinaryWriter.d.ts +391 -0
- package/build/io/BinaryWriter.d.ts.map +1 -0
- package/build/io/BinaryWriter.js +611 -0
- package/build/io/BinaryWriter.js.map +1 -0
- package/build/io/MemoryPool.d.ts +220 -0
- package/build/io/MemoryPool.d.ts.map +1 -0
- package/build/io/MemoryPool.js +309 -0
- package/build/io/MemoryPool.js.map +1 -0
- package/build/io/base64.d.ts +13 -0
- package/build/io/base64.d.ts.map +1 -0
- package/build/io/base64.js +20 -0
- package/build/io/base64.js.map +1 -0
- package/build/io/hex.d.ts +67 -0
- package/build/io/hex.d.ts.map +1 -0
- package/build/io/hex.js +138 -0
- package/build/io/hex.js.map +1 -0
- package/build/io/index.d.ts +17 -0
- package/build/io/index.d.ts.map +1 -0
- package/build/io/index.js +23 -0
- package/build/io/index.js.map +1 -0
- package/build/io/utils.d.ts +199 -0
- package/build/io/utils.d.ts.map +1 -0
- package/build/io/utils.js +271 -0
- package/build/io/utils.js.map +1 -0
- package/build/merkle.d.ts +10 -1
- package/build/merkle.d.ts.map +1 -0
- package/build/merkle.js +12 -1
- package/build/merkle.js.map +1 -0
- package/build/networks.d.ts +70 -9
- package/build/networks.d.ts.map +1 -0
- package/build/networks.js +90 -4
- package/build/networks.js.map +1 -0
- package/build/opcodes.d.ts +1 -0
- package/build/opcodes.d.ts.map +1 -0
- package/build/opcodes.js +1 -0
- package/build/opcodes.js.map +1 -0
- package/build/payments/bip341.d.ts +36 -9
- package/build/payments/bip341.d.ts.map +1 -0
- package/build/payments/bip341.js +35 -15
- package/build/payments/bip341.js.map +1 -0
- package/build/payments/embed.d.ts +120 -1
- package/build/payments/embed.d.ts.map +1 -0
- package/build/payments/embed.js +215 -34
- package/build/payments/embed.js.map +1 -0
- package/build/payments/index.d.ts +17 -10
- package/build/payments/index.d.ts.map +1 -0
- package/build/payments/index.js +20 -10
- package/build/payments/index.js.map +1 -0
- package/build/payments/p2ms.d.ts +159 -1
- package/build/payments/p2ms.d.ts.map +1 -0
- package/build/payments/p2ms.js +427 -108
- package/build/payments/p2ms.js.map +1 -0
- package/build/payments/p2op.d.ts +158 -24
- package/build/payments/p2op.d.ts.map +1 -0
- package/build/payments/p2op.js +379 -93
- package/build/payments/p2op.js.map +1 -0
- package/build/payments/p2pk.d.ts +162 -1
- package/build/payments/p2pk.d.ts.map +1 -0
- package/build/payments/p2pk.js +327 -58
- package/build/payments/p2pk.js.map +1 -0
- package/build/payments/p2pkh.d.ts +185 -1
- package/build/payments/p2pkh.d.ts.map +1 -0
- package/build/payments/p2pkh.js +467 -114
- package/build/payments/p2pkh.js.map +1 -0
- package/build/payments/p2sh.d.ts +159 -1
- package/build/payments/p2sh.d.ts.map +1 -0
- package/build/payments/p2sh.js +500 -152
- package/build/payments/p2sh.js.map +1 -0
- package/build/payments/p2tr.d.ts +193 -1
- package/build/payments/p2tr.d.ts.map +1 -0
- package/build/payments/p2tr.js +592 -174
- package/build/payments/p2tr.js.map +1 -0
- package/build/payments/p2wpkh.d.ts +170 -1
- package/build/payments/p2wpkh.d.ts.map +1 -0
- package/build/payments/p2wpkh.js +429 -104
- package/build/payments/p2wpkh.js.map +1 -0
- package/build/payments/p2wsh.d.ts +155 -1
- package/build/payments/p2wsh.d.ts.map +1 -0
- package/build/payments/p2wsh.js +466 -144
- package/build/payments/p2wsh.js.map +1 -0
- package/build/payments/types.d.ts +98 -64
- package/build/payments/types.d.ts.map +1 -0
- package/build/payments/types.js +17 -13
- package/build/payments/types.js.map +1 -0
- package/build/psbt/bip371.d.ts +35 -9
- package/build/psbt/bip371.d.ts.map +1 -0
- package/build/psbt/bip371.js +113 -28
- package/build/psbt/bip371.js.map +1 -0
- package/build/psbt/psbtutils.d.ts +56 -16
- package/build/psbt/psbtutils.d.ts.map +1 -0
- package/build/psbt/psbtutils.js +71 -16
- package/build/psbt/psbtutils.js.map +1 -0
- package/build/psbt/types.d.ts +249 -0
- package/build/psbt/types.d.ts.map +1 -0
- package/build/psbt/types.js +6 -0
- package/build/psbt/types.js.map +1 -0
- package/build/psbt/utils.d.ts +68 -0
- package/build/psbt/utils.d.ts.map +1 -0
- package/build/psbt/utils.js +171 -0
- package/build/psbt/utils.js.map +1 -0
- package/build/psbt/validation.d.ts +88 -0
- package/build/psbt/validation.d.ts.map +1 -0
- package/build/psbt/validation.js +149 -0
- package/build/psbt/validation.js.map +1 -0
- package/build/psbt.d.ts +84 -120
- package/build/psbt.d.ts.map +1 -0
- package/build/psbt.js +411 -412
- package/build/psbt.js.map +1 -0
- package/build/pubkey.d.ts +27 -6
- package/build/pubkey.d.ts.map +1 -0
- package/build/pubkey.js +36 -12
- package/build/pubkey.js.map +1 -0
- package/build/push_data.d.ts +24 -2
- package/build/push_data.d.ts.map +1 -0
- package/build/push_data.js +44 -12
- package/build/push_data.js.map +1 -0
- package/build/script.d.ts +33 -8
- package/build/script.d.ts.map +1 -0
- package/build/script.js +100 -36
- package/build/script.js.map +1 -0
- package/build/script_number.d.ts +17 -0
- package/build/script_number.d.ts.map +1 -0
- package/build/script_number.js +19 -0
- package/build/script_number.js.map +1 -0
- package/build/script_signature.d.ts +23 -5
- package/build/script_signature.d.ts.map +1 -0
- package/build/script_signature.js +48 -15
- package/build/script_signature.js.map +1 -0
- package/build/transaction.d.ts +160 -18
- package/build/transaction.d.ts.map +1 -0
- package/build/transaction.js +443 -176
- package/build/transaction.js.map +1 -0
- package/build/tsconfig.build.tsbuildinfo +1 -0
- package/build/types.d.ts +36 -38
- package/build/types.d.ts.map +1 -0
- package/build/types.js +175 -57
- package/build/types.js.map +1 -0
- package/build/workers/WorkerSigningPool.d.ts +174 -0
- package/build/workers/WorkerSigningPool.d.ts.map +1 -0
- package/build/workers/WorkerSigningPool.js +553 -0
- package/build/workers/WorkerSigningPool.js.map +1 -0
- package/build/workers/WorkerSigningPool.node.d.ts +124 -0
- package/build/workers/WorkerSigningPool.node.d.ts.map +1 -0
- package/build/workers/WorkerSigningPool.node.js +753 -0
- package/build/workers/WorkerSigningPool.node.js.map +1 -0
- package/build/workers/ecc-bundle.d.ts +25 -0
- package/build/workers/ecc-bundle.d.ts.map +1 -0
- package/build/workers/ecc-bundle.js +25 -0
- package/build/workers/ecc-bundle.js.map +1 -0
- package/build/workers/index.d.ts +91 -0
- package/build/workers/index.d.ts.map +1 -0
- package/build/workers/index.js +114 -0
- package/build/workers/index.js.map +1 -0
- package/build/workers/psbt-parallel.d.ts +117 -0
- package/build/workers/psbt-parallel.d.ts.map +1 -0
- package/build/workers/psbt-parallel.js +233 -0
- package/build/workers/psbt-parallel.js.map +1 -0
- package/build/workers/signing-worker.d.ts +37 -0
- package/build/workers/signing-worker.d.ts.map +1 -0
- package/build/workers/signing-worker.js +350 -0
- package/build/workers/signing-worker.js.map +1 -0
- package/build/workers/types.d.ts +365 -0
- package/build/workers/types.d.ts.map +1 -0
- package/build/workers/types.js +60 -0
- package/build/workers/types.js.map +1 -0
- package/package.json +66 -8
- package/scripts/bundle-ecc.ts +111 -0
- package/src/address.ts +81 -44
- package/src/bech32utils.ts +3 -3
- package/src/bip66.ts +34 -24
- package/src/block.ts +196 -84
- package/src/branded.ts +18 -0
- package/src/crypto.ts +64 -26
- package/src/ecc/context.ts +277 -0
- package/src/ecc/index.ts +14 -0
- package/src/ecc/types.ts +154 -0
- package/src/ecpair.d.ts +99 -0
- package/src/errors.ts +163 -0
- package/src/index.ts +113 -9
- package/src/io/BinaryReader.ts +461 -0
- package/src/io/BinaryWriter.ts +696 -0
- package/src/io/MemoryPool.ts +343 -0
- package/src/io/base64.ts +20 -0
- package/src/io/hex.ts +155 -0
- package/src/io/index.ts +41 -0
- package/src/io/utils.ts +283 -0
- package/src/merkle.ts +14 -9
- package/src/networks.ts +9 -9
- package/src/payments/bip341.ts +34 -33
- package/src/payments/embed.ts +244 -41
- package/src/payments/index.ts +12 -10
- package/src/payments/p2ms.ts +490 -118
- package/src/payments/p2op.ts +431 -133
- package/src/payments/p2pk.ts +370 -72
- package/src/payments/p2pkh.ts +524 -130
- package/src/payments/p2sh.ts +572 -172
- package/src/payments/p2tr.ts +686 -194
- package/src/payments/p2wpkh.ts +484 -107
- package/src/payments/p2wsh.ts +526 -164
- package/src/payments/types.ts +80 -66
- package/src/psbt/bip371.ts +68 -51
- package/src/psbt/psbtutils.ts +39 -40
- package/src/psbt/types.ts +331 -0
- package/src/psbt/utils.ts +188 -0
- package/src/psbt/validation.ts +192 -0
- package/src/psbt.ts +566 -809
- package/src/pubkey.ts +22 -23
- package/src/push_data.ts +18 -16
- package/src/script.ts +82 -64
- package/src/script_number.ts +6 -6
- package/src/script_signature.ts +33 -36
- package/src/transaction.ts +458 -238
- package/src/types.ts +231 -100
- package/src/workers/WorkerSigningPool.node.ts +887 -0
- package/src/workers/WorkerSigningPool.ts +670 -0
- package/src/workers/ecc-bundle.ts +26 -0
- package/src/workers/index.ts +165 -0
- package/src/workers/psbt-parallel.ts +332 -0
- package/src/workers/signing-worker.ts +353 -0
- package/src/workers/types.ts +413 -0
- package/test/address.spec.ts +9 -6
- package/test/bitcoin.core.spec.ts +16 -17
- package/test/block.spec.ts +8 -7
- package/test/bufferutils.spec.ts +228 -214
- package/test/crypto.spec.ts +19 -11
- package/test/fixtures/p2pk.json +0 -8
- package/test/fixtures/p2pkh.json +1 -1
- package/test/fixtures/p2sh.json +1 -1
- package/test/fixtures/script.json +1 -1
- package/test/fixtures/transaction.json +2 -2
- package/test/integration/_regtest.ts +25 -0
- package/test/integration/addresses.spec.ts +4 -3
- package/test/integration/bip32.spec.ts +2 -1
- package/test/integration/blocks.spec.ts +1 -1
- package/test/integration/cltv.spec.ts +18 -16
- package/test/integration/csv.spec.ts +37 -64
- package/test/integration/payments.spec.ts +5 -3
- package/test/integration/taproot.spec.ts +76 -83
- package/test/integration/transactions.spec.ts +38 -35
- package/test/payments.spec.ts +35 -13
- package/test/payments.utils.ts +17 -16
- package/test/psbt.spec.ts +111 -100
- package/test/script.spec.ts +11 -10
- package/test/script_signature.spec.ts +9 -11
- package/test/taproot-cache.spec.ts +694 -0
- package/test/transaction.spec.ts +32 -40
- package/test/types.spec.ts +74 -29
- package/test/workers-pool.spec.ts +963 -0
- package/test/workers-signing.spec.ts +635 -0
- package/test/workers.spec.ts +1390 -0
- package/tsconfig.base.json +34 -18
- package/tsconfig.browser.json +15 -0
- package/tsconfig.build.json +5 -0
- package/tsconfig.json +5 -14
- package/vite.config.browser.ts +3 -42
- package/vitest.config.integration.ts +2 -0
- package/browser/bufferutils.d.ts +0 -34
- package/browser/chunks/crypto-BhCpKpek.js +0 -2033
- package/browser/chunks/payments-B1wlSccx.js +0 -1089
- package/browser/chunks/psbt-BCNk7JUx.js +0 -4055
- package/browser/chunks/script-DyPItFEl.js +0 -318
- package/browser/chunks/transaction-C_UbhMGn.js +0 -432
- package/browser/chunks/utils-DNZi-T5W.js +0 -761
- package/browser/ecc_lib.d.ts +0 -3
- package/browser/hooks/AdvancedSignatureManager.d.ts +0 -16
- package/browser/hooks/HookedSigner.d.ts +0 -4
- package/browser/hooks/SignatureManager.d.ts +0 -13
- package/browser/payments/lazy.d.ts +0 -2
- package/browser/typeforce.d.ts +0 -38
- package/build/bufferutils.d.ts +0 -34
- package/build/bufferutils.js +0 -141
- package/build/ecc_lib.d.ts +0 -3
- package/build/ecc_lib.js +0 -61
- package/build/hooks/AdvancedSignatureManager.d.ts +0 -16
- package/build/hooks/AdvancedSignatureManager.js +0 -52
- package/build/hooks/HookedSigner.d.ts +0 -4
- package/build/hooks/HookedSigner.js +0 -64
- package/build/hooks/SignatureManager.d.ts +0 -13
- package/build/hooks/SignatureManager.js +0 -45
- package/build/payments/lazy.d.ts +0 -2
- package/build/payments/lazy.js +0 -28
- package/build/tsconfig.tsbuildinfo +0 -1
- package/src/bufferutils.ts +0 -188
- package/src/ecc_lib.ts +0 -94
- package/src/hooks/AdvancedSignatureManager.ts +0 -104
- package/src/hooks/HookedSigner.ts +0 -108
- package/src/hooks/SignatureManager.ts +0 -84
- package/src/payments/lazy.ts +0 -28
- package/src/typeforce.d.ts +0 -38
- package/tsconfig.webpack.json +0 -18
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stateful binary reader with a single DataView instance.
|
|
3
|
+
*
|
|
4
|
+
* Zero allocations during read operations. The DataView is created once
|
|
5
|
+
* in the constructor and reused for all reads.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* High-performance binary reader for parsing binary data.
|
|
11
|
+
*
|
|
12
|
+
* Creates exactly ONE DataView instance that is reused for all read operations.
|
|
13
|
+
* This eliminates garbage collection pressure from repeated DataView allocations.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { BinaryReader, fromHex } from '@btc-vision/bitcoin';
|
|
18
|
+
*
|
|
19
|
+
* // Parse a Bitcoin transaction
|
|
20
|
+
* const data = fromHex('01000000...');
|
|
21
|
+
* const reader = new BinaryReader(data);
|
|
22
|
+
*
|
|
23
|
+
* const version = reader.readInt32LE();
|
|
24
|
+
* const inputCount = reader.readVarInt();
|
|
25
|
+
*
|
|
26
|
+
* for (let i = 0; i < inputCount; i++) {
|
|
27
|
+
* const txid = reader.readBytes(32);
|
|
28
|
+
* const vout = reader.readUInt32LE();
|
|
29
|
+
* const script = reader.readVarBytes();
|
|
30
|
+
* const sequence = reader.readUInt32LE();
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare class BinaryReader {
|
|
35
|
+
#private;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new BinaryReader.
|
|
38
|
+
*
|
|
39
|
+
* @param data - The byte array to read from
|
|
40
|
+
* @param offset - Initial read position (default 0)
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* import { BinaryReader, fromHex } from '@btc-vision/bitcoin';
|
|
45
|
+
*
|
|
46
|
+
* const data = fromHex('01020304');
|
|
47
|
+
* const reader = new BinaryReader(data);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
constructor(data: Uint8Array, offset?: number);
|
|
51
|
+
/**
|
|
52
|
+
* Creates a BinaryReader from a hex string.
|
|
53
|
+
*
|
|
54
|
+
* @param hex - Hex string (with or without 0x prefix)
|
|
55
|
+
* @returns A new BinaryReader instance
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* import { BinaryReader } from '@btc-vision/bitcoin';
|
|
60
|
+
*
|
|
61
|
+
* const reader = BinaryReader.fromHex('01000000');
|
|
62
|
+
* const version = reader.readInt32LE(); // 1
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
static fromHex(hex: string): BinaryReader;
|
|
66
|
+
/**
|
|
67
|
+
* Current read position in the buffer.
|
|
68
|
+
*/
|
|
69
|
+
get offset(): number;
|
|
70
|
+
/**
|
|
71
|
+
* Sets the read position.
|
|
72
|
+
*
|
|
73
|
+
* @param value - New offset value
|
|
74
|
+
* @throws RangeError if offset is negative or beyond buffer length
|
|
75
|
+
*/
|
|
76
|
+
set offset(value: number);
|
|
77
|
+
/**
|
|
78
|
+
* Total length of the underlying buffer.
|
|
79
|
+
*/
|
|
80
|
+
get length(): number;
|
|
81
|
+
/**
|
|
82
|
+
* Number of bytes remaining to be read.
|
|
83
|
+
*/
|
|
84
|
+
get remaining(): number;
|
|
85
|
+
/**
|
|
86
|
+
* The underlying data buffer.
|
|
87
|
+
*/
|
|
88
|
+
get data(): Uint8Array;
|
|
89
|
+
/**
|
|
90
|
+
* Reads an 8-bit unsigned integer.
|
|
91
|
+
*
|
|
92
|
+
* @returns The value (0-255)
|
|
93
|
+
* @throws RangeError if reading past end of buffer
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const reader = BinaryReader.fromHex('ff');
|
|
98
|
+
* reader.readUInt8(); // 255
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
readUInt8(): number;
|
|
102
|
+
/**
|
|
103
|
+
* Reads an 8-bit signed integer.
|
|
104
|
+
*
|
|
105
|
+
* @returns The value (-128 to 127)
|
|
106
|
+
* @throws RangeError if reading past end of buffer
|
|
107
|
+
*/
|
|
108
|
+
readInt8(): number;
|
|
109
|
+
/**
|
|
110
|
+
* Reads a 16-bit unsigned integer in little-endian format.
|
|
111
|
+
*
|
|
112
|
+
* @returns The value (0-65535)
|
|
113
|
+
* @throws RangeError if reading past end of buffer
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const reader = BinaryReader.fromHex('0100'); // 1 in LE
|
|
118
|
+
* reader.readUInt16LE(); // 1
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
readUInt16LE(): number;
|
|
122
|
+
/**
|
|
123
|
+
* Reads a 16-bit signed integer in little-endian format.
|
|
124
|
+
*
|
|
125
|
+
* @returns The value (-32768 to 32767)
|
|
126
|
+
* @throws RangeError if reading past end of buffer
|
|
127
|
+
*/
|
|
128
|
+
readInt16LE(): number;
|
|
129
|
+
/**
|
|
130
|
+
* Reads a 32-bit unsigned integer in little-endian format.
|
|
131
|
+
*
|
|
132
|
+
* @returns The value (0 to 4294967295)
|
|
133
|
+
* @throws RangeError if reading past end of buffer
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* const reader = BinaryReader.fromHex('01000000'); // 1 in LE
|
|
138
|
+
* reader.readUInt32LE(); // 1
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
readUInt32LE(): number;
|
|
142
|
+
/**
|
|
143
|
+
* Reads a 32-bit signed integer in little-endian format.
|
|
144
|
+
*
|
|
145
|
+
* @returns The value (-2147483648 to 2147483647)
|
|
146
|
+
* @throws RangeError if reading past end of buffer
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* const reader = BinaryReader.fromHex('ffffffff'); // -1 in LE signed
|
|
151
|
+
* reader.readInt32LE(); // -1
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
readInt32LE(): number;
|
|
155
|
+
/**
|
|
156
|
+
* Reads a 64-bit unsigned integer in little-endian format as bigint.
|
|
157
|
+
*
|
|
158
|
+
* @returns The value as bigint
|
|
159
|
+
* @throws RangeError if reading past end of buffer
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* const reader = BinaryReader.fromHex('0100000000000000'); // 1 in LE 64-bit
|
|
164
|
+
* reader.readUInt64LE(); // 1n
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
readUInt64LE(): bigint;
|
|
168
|
+
/**
|
|
169
|
+
* Reads a 64-bit signed integer in little-endian format as bigint.
|
|
170
|
+
*
|
|
171
|
+
* @returns The value as bigint
|
|
172
|
+
* @throws RangeError if reading past end of buffer
|
|
173
|
+
*/
|
|
174
|
+
readInt64LE(): bigint;
|
|
175
|
+
/**
|
|
176
|
+
* Reads a specified number of bytes.
|
|
177
|
+
*
|
|
178
|
+
* Returns a subarray view (no copy) for performance.
|
|
179
|
+
* Use readBytesCopy() if you need an independent copy.
|
|
180
|
+
*
|
|
181
|
+
* @param length - Number of bytes to read
|
|
182
|
+
* @returns Uint8Array view into the buffer
|
|
183
|
+
* @throws RangeError if reading past end of buffer
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* const reader = BinaryReader.fromHex('deadbeefcafebabe');
|
|
188
|
+
* const first4 = reader.readBytes(4); // deadbeef
|
|
189
|
+
* const next4 = reader.readBytes(4); // cafebabe
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
readBytes(length: number): Uint8Array;
|
|
193
|
+
/**
|
|
194
|
+
* Reads a specified number of bytes as an independent copy.
|
|
195
|
+
*
|
|
196
|
+
* @param length - Number of bytes to read
|
|
197
|
+
* @returns New Uint8Array with copied data
|
|
198
|
+
* @throws RangeError if reading past end of buffer
|
|
199
|
+
*/
|
|
200
|
+
readBytesCopy(length: number): Uint8Array;
|
|
201
|
+
/**
|
|
202
|
+
* Reads a Bitcoin CompactSize variable-length integer.
|
|
203
|
+
*
|
|
204
|
+
* CompactSize encoding:
|
|
205
|
+
* - 0x00-0xFC: 1 byte (value as-is)
|
|
206
|
+
* - 0xFD: 3 bytes (0xFD + 2-byte LE uint16)
|
|
207
|
+
* - 0xFE: 5 bytes (0xFE + 4-byte LE uint32)
|
|
208
|
+
* - 0xFF: 9 bytes (0xFF + 8-byte LE uint64)
|
|
209
|
+
*
|
|
210
|
+
* @returns The decoded integer value
|
|
211
|
+
* @throws RangeError if reading past end of buffer
|
|
212
|
+
* @throws RangeError if value exceeds MAX_SAFE_INTEGER
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```typescript
|
|
216
|
+
* const reader = BinaryReader.fromHex('fd0302'); // 515 encoded
|
|
217
|
+
* reader.readVarInt(); // 515
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
readVarInt(): number;
|
|
221
|
+
/**
|
|
222
|
+
* Reads a Bitcoin CompactSize variable-length integer as bigint.
|
|
223
|
+
*
|
|
224
|
+
* Use this when you need the full 64-bit range.
|
|
225
|
+
*
|
|
226
|
+
* @returns The decoded integer value as bigint
|
|
227
|
+
* @throws RangeError if reading past end of buffer
|
|
228
|
+
*/
|
|
229
|
+
readVarIntBig(): bigint;
|
|
230
|
+
/**
|
|
231
|
+
* Reads a length-prefixed byte array (VarInt length + bytes).
|
|
232
|
+
*
|
|
233
|
+
* @returns Uint8Array view into the buffer
|
|
234
|
+
* @throws RangeError if reading past end of buffer
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```typescript
|
|
238
|
+
* const reader = BinaryReader.fromHex('04deadbeef');
|
|
239
|
+
* reader.readVarBytes(); // Uint8Array [0xde, 0xad, 0xbe, 0xef]
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
readVarBytes(): Uint8Array;
|
|
243
|
+
/**
|
|
244
|
+
* Reads an array of length-prefixed byte arrays.
|
|
245
|
+
*
|
|
246
|
+
* Format: VarInt count + (VarInt length + bytes) for each item.
|
|
247
|
+
*
|
|
248
|
+
* @returns Array of Uint8Array views
|
|
249
|
+
* @throws RangeError if reading past end of buffer
|
|
250
|
+
*/
|
|
251
|
+
readVector(): Uint8Array[];
|
|
252
|
+
/**
|
|
253
|
+
* Peeks at the next byte without advancing the position.
|
|
254
|
+
*
|
|
255
|
+
* @returns The next byte value, or undefined if at end
|
|
256
|
+
*/
|
|
257
|
+
peek(): number | undefined;
|
|
258
|
+
/**
|
|
259
|
+
* Skips a specified number of bytes.
|
|
260
|
+
*
|
|
261
|
+
* @param length - Number of bytes to skip
|
|
262
|
+
* @throws RangeError if skipping past end of buffer
|
|
263
|
+
*/
|
|
264
|
+
skip(length: number): void;
|
|
265
|
+
/**
|
|
266
|
+
* Resets the read position to the beginning.
|
|
267
|
+
*/
|
|
268
|
+
reset(): void;
|
|
269
|
+
/**
|
|
270
|
+
* Checks if there are more bytes to read.
|
|
271
|
+
*
|
|
272
|
+
* @returns True if there are remaining bytes
|
|
273
|
+
*/
|
|
274
|
+
hasMore(): boolean;
|
|
275
|
+
}
|
|
276
|
+
//# sourceMappingURL=BinaryReader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BinaryReader.d.ts","sourceRoot":"","sources":["../../src/io/BinaryReader.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,YAAY;;IAgBrB;;;;;;;;;;;;;OAaG;gBACgB,IAAI,EAAE,UAAU,EAAE,MAAM,GAAE,MAAU;IAMvD;;;;;;;;;;;;;OAaG;WACW,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY;IAIhD;;OAEG;IACH,IAAW,MAAM,IAAI,MAAM,CAE1B;IAED;;;;;OAKG;IACH,IAAW,MAAM,CAAC,KAAK,EAAE,MAAM,EAK9B;IAED;;OAEG;IACH,IAAW,MAAM,IAAI,MAAM,CAE1B;IAED;;OAEG;IACH,IAAW,SAAS,IAAI,MAAM,CAE7B;IAED;;OAEG;IACH,IAAW,IAAI,IAAI,UAAU,CAE5B;IAED;;;;;;;;;;;OAWG;IACI,SAAS,IAAI,MAAM;IAO1B;;;;;OAKG;IACI,QAAQ,IAAI,MAAM;IAKzB;;;;;;;;;;;OAWG;IACI,YAAY,IAAI,MAAM;IAS7B;;;;;OAKG;IACI,WAAW,IAAI,MAAM;IAS5B;;;;;;;;;;;OAWG;IACI,YAAY,IAAI,MAAM;IAS7B;;;;;;;;;;;OAWG;IACI,WAAW,IAAI,MAAM;IAS5B;;;;;;;;;;;OAWG;IACI,YAAY,IAAI,MAAM;IAS7B;;;;;OAKG;IACI,WAAW,IAAI,MAAM;IAS5B;;;;;;;;;;;;;;;;OAgBG;IACI,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU;IAS5C;;;;;;OAMG;IACI,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU;IAShD;;;;;;;;;;;;;;;;;;OAkBG;IACI,UAAU,IAAI,MAAM;IAuB3B;;;;;;;OAOG;IACI,aAAa,IAAI,MAAM;IAmB9B;;;;;;;;;;;OAWG;IACI,YAAY,IAAI,UAAU;IAKjC;;;;;;;OAOG;IACI,UAAU,IAAI,UAAU,EAAE;IASjC;;;;OAIG;IACI,IAAI,IAAI,MAAM,GAAG,SAAS;IAOjC;;;;;OAKG;IACI,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAOjC;;OAEG;IACI,KAAK,IAAI,IAAI;IAIpB;;;;OAIG;IACI,OAAO,IAAI,OAAO;CAG5B"}
|
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stateful binary writer with a single DataView instance.
|
|
3
|
+
*
|
|
4
|
+
* Zero allocations during write operations. The DataView is created once
|
|
5
|
+
* in the constructor and reused for all writes.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* High-performance binary writer for serializing binary data.
|
|
11
|
+
*
|
|
12
|
+
* Creates exactly ONE DataView instance that is reused for all write operations.
|
|
13
|
+
* This eliminates garbage collection pressure from repeated DataView allocations.
|
|
14
|
+
*
|
|
15
|
+
* Methods return `this` for chaining.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { BinaryWriter } from '@btc-vision/bitcoin';
|
|
20
|
+
*
|
|
21
|
+
* // Serialize a simple structure
|
|
22
|
+
* const writer = new BinaryWriter(16);
|
|
23
|
+
* writer
|
|
24
|
+
* .writeInt32LE(1) // version
|
|
25
|
+
* .writeUInt32LE(0) // input count
|
|
26
|
+
* .writeUInt32LE(0) // output count
|
|
27
|
+
* .writeUInt32LE(0); // locktime
|
|
28
|
+
*
|
|
29
|
+
* const bytes = writer.finish();
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class BinaryWriter {
|
|
33
|
+
#private;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a new BinaryWriter with a pre-allocated buffer.
|
|
36
|
+
*
|
|
37
|
+
* @param size - Size of the buffer in bytes
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* import { BinaryWriter } from '@btc-vision/bitcoin';
|
|
42
|
+
*
|
|
43
|
+
* const writer = new BinaryWriter(1024);
|
|
44
|
+
* writer.writeUInt32LE(42);
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
constructor(size: number);
|
|
48
|
+
/**
|
|
49
|
+
* Creates a new BinaryWriter wrapping an existing buffer.
|
|
50
|
+
*
|
|
51
|
+
* @param buffer - Existing buffer to write into
|
|
52
|
+
* @param offset - Initial write position (default 0)
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* import { BinaryWriter } from '@btc-vision/bitcoin';
|
|
57
|
+
*
|
|
58
|
+
* const buffer = new Uint8Array(1024);
|
|
59
|
+
* const writer = new BinaryWriter(buffer, 10); // Start at offset 10
|
|
60
|
+
* writer.writeUInt32LE(42);
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
constructor(buffer: Uint8Array, offset?: number);
|
|
64
|
+
/**
|
|
65
|
+
* Creates a BinaryWriter with automatic capacity management.
|
|
66
|
+
*
|
|
67
|
+
* Initial capacity is 256 bytes, grows as needed.
|
|
68
|
+
*
|
|
69
|
+
* @returns A new GrowableBinaryWriter instance
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* import { BinaryWriter } from '@btc-vision/bitcoin';
|
|
74
|
+
*
|
|
75
|
+
* const writer = BinaryWriter.growable();
|
|
76
|
+
* writer.writeUInt32LE(1);
|
|
77
|
+
* writer.writeBytes(new Uint8Array(1000)); // Automatically grows
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
static growable(initialCapacity?: number): GrowableBinaryWriter;
|
|
81
|
+
/**
|
|
82
|
+
* Current write position in the buffer.
|
|
83
|
+
*/
|
|
84
|
+
get offset(): number;
|
|
85
|
+
/**
|
|
86
|
+
* Sets the write position.
|
|
87
|
+
*
|
|
88
|
+
* @param value - New offset value
|
|
89
|
+
* @throws RangeError if offset is negative or beyond buffer length
|
|
90
|
+
*/
|
|
91
|
+
set offset(value: number);
|
|
92
|
+
/**
|
|
93
|
+
* Total capacity of the underlying buffer.
|
|
94
|
+
*/
|
|
95
|
+
get capacity(): number;
|
|
96
|
+
/**
|
|
97
|
+
* Number of bytes remaining in the buffer.
|
|
98
|
+
*/
|
|
99
|
+
get remaining(): number;
|
|
100
|
+
/**
|
|
101
|
+
* The underlying data buffer.
|
|
102
|
+
*/
|
|
103
|
+
get data(): Uint8Array;
|
|
104
|
+
/**
|
|
105
|
+
* Writes an 8-bit unsigned integer.
|
|
106
|
+
*
|
|
107
|
+
* @param value - Value to write (0-255)
|
|
108
|
+
* @returns This writer for chaining
|
|
109
|
+
* @throws RangeError if writing past end of buffer
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* writer.writeUInt8(255);
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
writeUInt8(value: number): this;
|
|
117
|
+
/**
|
|
118
|
+
* Writes an 8-bit signed integer.
|
|
119
|
+
*
|
|
120
|
+
* @param value - Value to write (-128 to 127)
|
|
121
|
+
* @returns This writer for chaining
|
|
122
|
+
* @throws RangeError if writing past end of buffer
|
|
123
|
+
*/
|
|
124
|
+
writeInt8(value: number): this;
|
|
125
|
+
/**
|
|
126
|
+
* Writes a 16-bit unsigned integer in little-endian format.
|
|
127
|
+
*
|
|
128
|
+
* @param value - Value to write (0-65535)
|
|
129
|
+
* @returns This writer for chaining
|
|
130
|
+
* @throws RangeError if writing past end of buffer
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* writer.writeUInt16LE(1); // Writes 01 00
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
writeUInt16LE(value: number): this;
|
|
138
|
+
/**
|
|
139
|
+
* Writes a 16-bit signed integer in little-endian format.
|
|
140
|
+
*
|
|
141
|
+
* @param value - Value to write (-32768 to 32767)
|
|
142
|
+
* @returns This writer for chaining
|
|
143
|
+
* @throws RangeError if writing past end of buffer
|
|
144
|
+
*/
|
|
145
|
+
writeInt16LE(value: number): this;
|
|
146
|
+
/**
|
|
147
|
+
* Writes a 32-bit unsigned integer in little-endian format.
|
|
148
|
+
*
|
|
149
|
+
* @param value - Value to write (0 to 4294967295)
|
|
150
|
+
* @returns This writer for chaining
|
|
151
|
+
* @throws RangeError if writing past end of buffer
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* writer.writeUInt32LE(1); // Writes 01 00 00 00
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
writeUInt32LE(value: number): this;
|
|
159
|
+
/**
|
|
160
|
+
* Writes a 32-bit signed integer in little-endian format.
|
|
161
|
+
*
|
|
162
|
+
* @param value - Value to write (-2147483648 to 2147483647)
|
|
163
|
+
* @returns This writer for chaining
|
|
164
|
+
* @throws RangeError if writing past end of buffer
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* writer.writeInt32LE(-1); // Writes ff ff ff ff
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
writeInt32LE(value: number): this;
|
|
172
|
+
/**
|
|
173
|
+
* Writes a 64-bit unsigned integer in little-endian format.
|
|
174
|
+
*
|
|
175
|
+
* @param value - Value to write as bigint
|
|
176
|
+
* @returns This writer for chaining
|
|
177
|
+
* @throws RangeError if writing past end of buffer
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* writer.writeUInt64LE(50000n); // Writes 50 c3 00 00 00 00 00 00
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
writeUInt64LE(value: bigint): this;
|
|
185
|
+
/**
|
|
186
|
+
* Writes a 64-bit signed integer in little-endian format.
|
|
187
|
+
*
|
|
188
|
+
* @param value - Value to write as bigint
|
|
189
|
+
* @returns This writer for chaining
|
|
190
|
+
* @throws RangeError if writing past end of buffer
|
|
191
|
+
*/
|
|
192
|
+
writeInt64LE(value: bigint): this;
|
|
193
|
+
/**
|
|
194
|
+
* Writes raw bytes.
|
|
195
|
+
*
|
|
196
|
+
* @param bytes - Bytes to write
|
|
197
|
+
* @returns This writer for chaining
|
|
198
|
+
* @throws RangeError if writing past end of buffer
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```typescript
|
|
202
|
+
* writer.writeBytes(new Uint8Array([0xde, 0xad, 0xbe, 0xef]));
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
writeBytes(bytes: Uint8Array): this;
|
|
206
|
+
/**
|
|
207
|
+
* Writes a Bitcoin CompactSize variable-length integer.
|
|
208
|
+
*
|
|
209
|
+
* CompactSize encoding:
|
|
210
|
+
* - 0x00-0xFC: 1 byte (value as-is)
|
|
211
|
+
* - 0xFD-0xFFFF: 3 bytes (0xFD + 2-byte LE uint16)
|
|
212
|
+
* - 0x10000-0xFFFFFFFF: 5 bytes (0xFE + 4-byte LE uint32)
|
|
213
|
+
* - Larger: 9 bytes (0xFF + 8-byte LE uint64)
|
|
214
|
+
*
|
|
215
|
+
* @param value - Value to write
|
|
216
|
+
* @returns This writer for chaining
|
|
217
|
+
* @throws RangeError if writing past end of buffer
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```typescript
|
|
221
|
+
* writer.writeVarInt(252); // Writes fc
|
|
222
|
+
* writer.writeVarInt(253); // Writes fd fd 00
|
|
223
|
+
* writer.writeVarInt(65535); // Writes fd ff ff
|
|
224
|
+
* writer.writeVarInt(65536); // Writes fe 00 00 01 00
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
writeVarInt(value: number): this;
|
|
228
|
+
/**
|
|
229
|
+
* Writes a Bitcoin CompactSize variable-length integer from bigint.
|
|
230
|
+
*
|
|
231
|
+
* @param value - Value to write as bigint
|
|
232
|
+
* @returns This writer for chaining
|
|
233
|
+
* @throws RangeError if writing past end of buffer
|
|
234
|
+
*/
|
|
235
|
+
writeVarIntBig(value: bigint): this;
|
|
236
|
+
/**
|
|
237
|
+
* Writes a length-prefixed byte array (VarInt length + bytes).
|
|
238
|
+
*
|
|
239
|
+
* @param bytes - Bytes to write
|
|
240
|
+
* @returns This writer for chaining
|
|
241
|
+
* @throws RangeError if writing past end of buffer
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```typescript
|
|
245
|
+
* writer.writeVarBytes(new Uint8Array([0xde, 0xad])); // Writes 02 de ad
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
writeVarBytes(bytes: Uint8Array): this;
|
|
249
|
+
/**
|
|
250
|
+
* Writes an array of length-prefixed byte arrays.
|
|
251
|
+
*
|
|
252
|
+
* Format: VarInt count + (VarInt length + bytes) for each item.
|
|
253
|
+
*
|
|
254
|
+
* @param vector - Array of byte arrays to write
|
|
255
|
+
* @returns This writer for chaining
|
|
256
|
+
* @throws RangeError if writing past end of buffer
|
|
257
|
+
*/
|
|
258
|
+
writeVector(vector: readonly Uint8Array[]): this;
|
|
259
|
+
/**
|
|
260
|
+
* Fills a region with a specific byte value.
|
|
261
|
+
*
|
|
262
|
+
* @param value - Byte value to fill with
|
|
263
|
+
* @param length - Number of bytes to fill
|
|
264
|
+
* @returns This writer for chaining
|
|
265
|
+
* @throws RangeError if writing past end of buffer
|
|
266
|
+
*/
|
|
267
|
+
fill(value: number, length: number): this;
|
|
268
|
+
/**
|
|
269
|
+
* Skips a specified number of bytes (leaves them unchanged).
|
|
270
|
+
*
|
|
271
|
+
* @param length - Number of bytes to skip
|
|
272
|
+
* @returns This writer for chaining
|
|
273
|
+
* @throws RangeError if skipping past end of buffer
|
|
274
|
+
*/
|
|
275
|
+
skip(length: number): this;
|
|
276
|
+
/**
|
|
277
|
+
* Resets the write position to the beginning.
|
|
278
|
+
*
|
|
279
|
+
* @returns This writer for chaining
|
|
280
|
+
*/
|
|
281
|
+
reset(): this;
|
|
282
|
+
/**
|
|
283
|
+
* Verifies the buffer was fully written and returns it.
|
|
284
|
+
*
|
|
285
|
+
* Unlike {@link finish}, this method throws if the writer has not
|
|
286
|
+
* written exactly to the end of the buffer.
|
|
287
|
+
*
|
|
288
|
+
* @returns The underlying buffer
|
|
289
|
+
* @throws Error if the buffer was not fully written
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```typescript
|
|
293
|
+
* const writer = new BinaryWriter(8);
|
|
294
|
+
* writer.writeUInt32LE(1);
|
|
295
|
+
* writer.writeUInt32LE(2);
|
|
296
|
+
* const bytes = writer.end(); // OK: wrote exactly 8 bytes
|
|
297
|
+
*
|
|
298
|
+
* const writer2 = new BinaryWriter(8);
|
|
299
|
+
* writer2.writeUInt32LE(1);
|
|
300
|
+
* writer2.end(); // throws: buffer size 8, offset 4
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
end(): Uint8Array;
|
|
304
|
+
/**
|
|
305
|
+
* Returns the written portion of the buffer.
|
|
306
|
+
*
|
|
307
|
+
* If the entire buffer was written, returns the buffer directly (no copy).
|
|
308
|
+
* Otherwise, returns a subarray view.
|
|
309
|
+
*
|
|
310
|
+
* @returns Uint8Array containing the written data
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* ```typescript
|
|
314
|
+
* const writer = new BinaryWriter(100);
|
|
315
|
+
* writer.writeUInt32LE(42);
|
|
316
|
+
* const bytes = writer.finish(); // 4 bytes
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
finish(): Uint8Array;
|
|
320
|
+
/**
|
|
321
|
+
* Returns the written portion as a hex string.
|
|
322
|
+
*
|
|
323
|
+
* @returns Hex string representation
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* ```typescript
|
|
327
|
+
* const writer = new BinaryWriter(4);
|
|
328
|
+
* writer.writeUInt32LE(1);
|
|
329
|
+
* writer.toHex(); // '01000000'
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
332
|
+
toHex(): string;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* A BinaryWriter that automatically grows its buffer as needed.
|
|
336
|
+
*
|
|
337
|
+
* Use when the final size is unknown.
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* ```typescript
|
|
341
|
+
* const writer = BinaryWriter.growable();
|
|
342
|
+
* writer.writeBytes(largeData); // Automatically grows
|
|
343
|
+
* const bytes = writer.finish();
|
|
344
|
+
* ```
|
|
345
|
+
*/
|
|
346
|
+
export declare class GrowableBinaryWriter {
|
|
347
|
+
#private;
|
|
348
|
+
/**
|
|
349
|
+
* Creates a new GrowableBinaryWriter.
|
|
350
|
+
*
|
|
351
|
+
* @param initialCapacity - Initial buffer size (default 256)
|
|
352
|
+
*/
|
|
353
|
+
constructor(initialCapacity?: number);
|
|
354
|
+
/**
|
|
355
|
+
* Current write position.
|
|
356
|
+
*/
|
|
357
|
+
get offset(): number;
|
|
358
|
+
/**
|
|
359
|
+
* Sets the write position.
|
|
360
|
+
*
|
|
361
|
+
* @param value - New offset value
|
|
362
|
+
* @throws RangeError if offset is negative
|
|
363
|
+
*/
|
|
364
|
+
set offset(value: number);
|
|
365
|
+
/**
|
|
366
|
+
* Current buffer capacity.
|
|
367
|
+
*/
|
|
368
|
+
get capacity(): number;
|
|
369
|
+
writeUInt8(value: number): this;
|
|
370
|
+
writeUInt16LE(value: number): this;
|
|
371
|
+
writeUInt32LE(value: number): this;
|
|
372
|
+
writeInt32LE(value: number): this;
|
|
373
|
+
writeUInt64LE(value: bigint): this;
|
|
374
|
+
writeBytes(bytes: Uint8Array): this;
|
|
375
|
+
writeVarInt(value: number): this;
|
|
376
|
+
writeVarBytes(bytes: Uint8Array): this;
|
|
377
|
+
writeVector(vector: readonly Uint8Array[]): this;
|
|
378
|
+
/**
|
|
379
|
+
* Returns the written data as a new Uint8Array.
|
|
380
|
+
*
|
|
381
|
+
* @returns Copy of the written data
|
|
382
|
+
*/
|
|
383
|
+
finish(): Uint8Array;
|
|
384
|
+
/**
|
|
385
|
+
* Returns the written data as a hex string.
|
|
386
|
+
*
|
|
387
|
+
* @returns Hex string representation
|
|
388
|
+
*/
|
|
389
|
+
toHex(): string;
|
|
390
|
+
}
|
|
391
|
+
//# sourceMappingURL=BinaryWriter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BinaryWriter.d.ts","sourceRoot":"","sources":["../../src/io/BinaryWriter.ts"],"names":[],"mappings":"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"}
|