@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
|
@@ -0,0 +1,611 @@
|
|
|
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
|
+
import { toHex } from './hex.js';
|
|
10
|
+
/**
|
|
11
|
+
* High-performance binary writer for serializing binary data.
|
|
12
|
+
*
|
|
13
|
+
* Creates exactly ONE DataView instance that is reused for all write operations.
|
|
14
|
+
* This eliminates garbage collection pressure from repeated DataView allocations.
|
|
15
|
+
*
|
|
16
|
+
* Methods return `this` for chaining.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { BinaryWriter } from '@btc-vision/bitcoin';
|
|
21
|
+
*
|
|
22
|
+
* // Serialize a simple structure
|
|
23
|
+
* const writer = new BinaryWriter(16);
|
|
24
|
+
* writer
|
|
25
|
+
* .writeInt32LE(1) // version
|
|
26
|
+
* .writeUInt32LE(0) // input count
|
|
27
|
+
* .writeUInt32LE(0) // output count
|
|
28
|
+
* .writeUInt32LE(0); // locktime
|
|
29
|
+
*
|
|
30
|
+
* const bytes = writer.finish();
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export class BinaryWriter {
|
|
34
|
+
/**
|
|
35
|
+
* The underlying byte array.
|
|
36
|
+
*/
|
|
37
|
+
#data;
|
|
38
|
+
/**
|
|
39
|
+
* Single DataView instance reused for all writes.
|
|
40
|
+
*/
|
|
41
|
+
#view;
|
|
42
|
+
/**
|
|
43
|
+
* Current write position.
|
|
44
|
+
*/
|
|
45
|
+
#offset;
|
|
46
|
+
constructor(arg, offset = 0) {
|
|
47
|
+
if (typeof arg === 'number') {
|
|
48
|
+
this.#data = new Uint8Array(arg);
|
|
49
|
+
this.#offset = 0;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
this.#data = arg;
|
|
53
|
+
this.#offset = offset;
|
|
54
|
+
}
|
|
55
|
+
this.#view = new DataView(this.#data.buffer, this.#data.byteOffset, this.#data.byteLength);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Creates a BinaryWriter with automatic capacity management.
|
|
59
|
+
*
|
|
60
|
+
* Initial capacity is 256 bytes, grows as needed.
|
|
61
|
+
*
|
|
62
|
+
* @returns A new GrowableBinaryWriter instance
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* import { BinaryWriter } from '@btc-vision/bitcoin';
|
|
67
|
+
*
|
|
68
|
+
* const writer = BinaryWriter.growable();
|
|
69
|
+
* writer.writeUInt32LE(1);
|
|
70
|
+
* writer.writeBytes(new Uint8Array(1000)); // Automatically grows
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
static growable(initialCapacity = 256) {
|
|
74
|
+
return new GrowableBinaryWriter(initialCapacity);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Current write position in the buffer.
|
|
78
|
+
*/
|
|
79
|
+
get offset() {
|
|
80
|
+
return this.#offset;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Sets the write position.
|
|
84
|
+
*
|
|
85
|
+
* @param value - New offset value
|
|
86
|
+
* @throws RangeError if offset is negative or beyond buffer length
|
|
87
|
+
*/
|
|
88
|
+
set offset(value) {
|
|
89
|
+
if (value < 0 || value > this.#data.length) {
|
|
90
|
+
throw new RangeError(`Offset ${value} is out of bounds [0, ${this.#data.length}]`);
|
|
91
|
+
}
|
|
92
|
+
this.#offset = value;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Total capacity of the underlying buffer.
|
|
96
|
+
*/
|
|
97
|
+
get capacity() {
|
|
98
|
+
return this.#data.length;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Number of bytes remaining in the buffer.
|
|
102
|
+
*/
|
|
103
|
+
get remaining() {
|
|
104
|
+
return this.#data.length - this.#offset;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The underlying data buffer.
|
|
108
|
+
*/
|
|
109
|
+
get data() {
|
|
110
|
+
return this.#data;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Writes an 8-bit unsigned integer.
|
|
114
|
+
*
|
|
115
|
+
* @param value - Value to write (0-255)
|
|
116
|
+
* @returns This writer for chaining
|
|
117
|
+
* @throws RangeError if writing past end of buffer
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* writer.writeUInt8(255);
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
writeUInt8(value) {
|
|
125
|
+
if (this.#offset >= this.#data.length) {
|
|
126
|
+
throw new RangeError('Write past end of buffer');
|
|
127
|
+
}
|
|
128
|
+
this.#data[this.#offset++] = value & 0xff;
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Writes an 8-bit signed integer.
|
|
133
|
+
*
|
|
134
|
+
* @param value - Value to write (-128 to 127)
|
|
135
|
+
* @returns This writer for chaining
|
|
136
|
+
* @throws RangeError if writing past end of buffer
|
|
137
|
+
*/
|
|
138
|
+
writeInt8(value) {
|
|
139
|
+
return this.writeUInt8(value < 0 ? value + 256 : value);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Writes a 16-bit unsigned integer in little-endian format.
|
|
143
|
+
*
|
|
144
|
+
* @param value - Value to write (0-65535)
|
|
145
|
+
* @returns This writer for chaining
|
|
146
|
+
* @throws RangeError if writing past end of buffer
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* writer.writeUInt16LE(1); // Writes 01 00
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
writeUInt16LE(value) {
|
|
154
|
+
if (this.#offset + 2 > this.#data.length) {
|
|
155
|
+
throw new RangeError('Write past end of buffer');
|
|
156
|
+
}
|
|
157
|
+
this.#view.setUint16(this.#offset, value, true);
|
|
158
|
+
this.#offset += 2;
|
|
159
|
+
return this;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Writes a 16-bit signed integer in little-endian format.
|
|
163
|
+
*
|
|
164
|
+
* @param value - Value to write (-32768 to 32767)
|
|
165
|
+
* @returns This writer for chaining
|
|
166
|
+
* @throws RangeError if writing past end of buffer
|
|
167
|
+
*/
|
|
168
|
+
writeInt16LE(value) {
|
|
169
|
+
if (this.#offset + 2 > this.#data.length) {
|
|
170
|
+
throw new RangeError('Write past end of buffer');
|
|
171
|
+
}
|
|
172
|
+
this.#view.setInt16(this.#offset, value, true);
|
|
173
|
+
this.#offset += 2;
|
|
174
|
+
return this;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Writes a 32-bit unsigned integer in little-endian format.
|
|
178
|
+
*
|
|
179
|
+
* @param value - Value to write (0 to 4294967295)
|
|
180
|
+
* @returns This writer for chaining
|
|
181
|
+
* @throws RangeError if writing past end of buffer
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* writer.writeUInt32LE(1); // Writes 01 00 00 00
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
writeUInt32LE(value) {
|
|
189
|
+
if (this.#offset + 4 > this.#data.length) {
|
|
190
|
+
throw new RangeError('Write past end of buffer');
|
|
191
|
+
}
|
|
192
|
+
this.#view.setUint32(this.#offset, value, true);
|
|
193
|
+
this.#offset += 4;
|
|
194
|
+
return this;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Writes a 32-bit signed integer in little-endian format.
|
|
198
|
+
*
|
|
199
|
+
* @param value - Value to write (-2147483648 to 2147483647)
|
|
200
|
+
* @returns This writer for chaining
|
|
201
|
+
* @throws RangeError if writing past end of buffer
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* writer.writeInt32LE(-1); // Writes ff ff ff ff
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
writeInt32LE(value) {
|
|
209
|
+
if (this.#offset + 4 > this.#data.length) {
|
|
210
|
+
throw new RangeError('Write past end of buffer');
|
|
211
|
+
}
|
|
212
|
+
this.#view.setInt32(this.#offset, value, true);
|
|
213
|
+
this.#offset += 4;
|
|
214
|
+
return this;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Writes a 64-bit unsigned integer in little-endian format.
|
|
218
|
+
*
|
|
219
|
+
* @param value - Value to write as bigint
|
|
220
|
+
* @returns This writer for chaining
|
|
221
|
+
* @throws RangeError if writing past end of buffer
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```typescript
|
|
225
|
+
* writer.writeUInt64LE(50000n); // Writes 50 c3 00 00 00 00 00 00
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
writeUInt64LE(value) {
|
|
229
|
+
if (this.#offset + 8 > this.#data.length) {
|
|
230
|
+
throw new RangeError('Write past end of buffer');
|
|
231
|
+
}
|
|
232
|
+
this.#view.setBigUint64(this.#offset, value, true);
|
|
233
|
+
this.#offset += 8;
|
|
234
|
+
return this;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Writes a 64-bit signed integer in little-endian format.
|
|
238
|
+
*
|
|
239
|
+
* @param value - Value to write as bigint
|
|
240
|
+
* @returns This writer for chaining
|
|
241
|
+
* @throws RangeError if writing past end of buffer
|
|
242
|
+
*/
|
|
243
|
+
writeInt64LE(value) {
|
|
244
|
+
if (this.#offset + 8 > this.#data.length) {
|
|
245
|
+
throw new RangeError('Write past end of buffer');
|
|
246
|
+
}
|
|
247
|
+
this.#view.setBigInt64(this.#offset, value, true);
|
|
248
|
+
this.#offset += 8;
|
|
249
|
+
return this;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Writes raw bytes.
|
|
253
|
+
*
|
|
254
|
+
* @param bytes - Bytes to write
|
|
255
|
+
* @returns This writer for chaining
|
|
256
|
+
* @throws RangeError if writing past end of buffer
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```typescript
|
|
260
|
+
* writer.writeBytes(new Uint8Array([0xde, 0xad, 0xbe, 0xef]));
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
writeBytes(bytes) {
|
|
264
|
+
if (this.#offset + bytes.length > this.#data.length) {
|
|
265
|
+
throw new RangeError('Write past end of buffer');
|
|
266
|
+
}
|
|
267
|
+
this.#data.set(bytes, this.#offset);
|
|
268
|
+
this.#offset += bytes.length;
|
|
269
|
+
return this;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Writes a Bitcoin CompactSize variable-length integer.
|
|
273
|
+
*
|
|
274
|
+
* CompactSize encoding:
|
|
275
|
+
* - 0x00-0xFC: 1 byte (value as-is)
|
|
276
|
+
* - 0xFD-0xFFFF: 3 bytes (0xFD + 2-byte LE uint16)
|
|
277
|
+
* - 0x10000-0xFFFFFFFF: 5 bytes (0xFE + 4-byte LE uint32)
|
|
278
|
+
* - Larger: 9 bytes (0xFF + 8-byte LE uint64)
|
|
279
|
+
*
|
|
280
|
+
* @param value - Value to write
|
|
281
|
+
* @returns This writer for chaining
|
|
282
|
+
* @throws RangeError if writing past end of buffer
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```typescript
|
|
286
|
+
* writer.writeVarInt(252); // Writes fc
|
|
287
|
+
* writer.writeVarInt(253); // Writes fd fd 00
|
|
288
|
+
* writer.writeVarInt(65535); // Writes fd ff ff
|
|
289
|
+
* writer.writeVarInt(65536); // Writes fe 00 00 01 00
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
writeVarInt(value) {
|
|
293
|
+
if (value < 0xfd) {
|
|
294
|
+
return this.writeUInt8(value);
|
|
295
|
+
}
|
|
296
|
+
if (value <= 0xffff) {
|
|
297
|
+
this.writeUInt8(0xfd);
|
|
298
|
+
return this.writeUInt16LE(value);
|
|
299
|
+
}
|
|
300
|
+
if (value <= 0xffffffff) {
|
|
301
|
+
this.writeUInt8(0xfe);
|
|
302
|
+
return this.writeUInt32LE(value);
|
|
303
|
+
}
|
|
304
|
+
this.writeUInt8(0xff);
|
|
305
|
+
return this.writeUInt64LE(BigInt(value));
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Writes a Bitcoin CompactSize variable-length integer from bigint.
|
|
309
|
+
*
|
|
310
|
+
* @param value - Value to write as bigint
|
|
311
|
+
* @returns This writer for chaining
|
|
312
|
+
* @throws RangeError if writing past end of buffer
|
|
313
|
+
*/
|
|
314
|
+
writeVarIntBig(value) {
|
|
315
|
+
if (value < 0xfdn) {
|
|
316
|
+
return this.writeUInt8(Number(value));
|
|
317
|
+
}
|
|
318
|
+
if (value <= 0xffffn) {
|
|
319
|
+
this.writeUInt8(0xfd);
|
|
320
|
+
return this.writeUInt16LE(Number(value));
|
|
321
|
+
}
|
|
322
|
+
if (value <= 0xffffffffn) {
|
|
323
|
+
this.writeUInt8(0xfe);
|
|
324
|
+
return this.writeUInt32LE(Number(value));
|
|
325
|
+
}
|
|
326
|
+
this.writeUInt8(0xff);
|
|
327
|
+
return this.writeUInt64LE(value);
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Writes a length-prefixed byte array (VarInt length + bytes).
|
|
331
|
+
*
|
|
332
|
+
* @param bytes - Bytes to write
|
|
333
|
+
* @returns This writer for chaining
|
|
334
|
+
* @throws RangeError if writing past end of buffer
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* ```typescript
|
|
338
|
+
* writer.writeVarBytes(new Uint8Array([0xde, 0xad])); // Writes 02 de ad
|
|
339
|
+
* ```
|
|
340
|
+
*/
|
|
341
|
+
writeVarBytes(bytes) {
|
|
342
|
+
this.writeVarInt(bytes.length);
|
|
343
|
+
return this.writeBytes(bytes);
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Writes an array of length-prefixed byte arrays.
|
|
347
|
+
*
|
|
348
|
+
* Format: VarInt count + (VarInt length + bytes) for each item.
|
|
349
|
+
*
|
|
350
|
+
* @param vector - Array of byte arrays to write
|
|
351
|
+
* @returns This writer for chaining
|
|
352
|
+
* @throws RangeError if writing past end of buffer
|
|
353
|
+
*/
|
|
354
|
+
writeVector(vector) {
|
|
355
|
+
this.writeVarInt(vector.length);
|
|
356
|
+
for (const item of vector) {
|
|
357
|
+
this.writeVarBytes(item);
|
|
358
|
+
}
|
|
359
|
+
return this;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Fills a region with a specific byte value.
|
|
363
|
+
*
|
|
364
|
+
* @param value - Byte value to fill with
|
|
365
|
+
* @param length - Number of bytes to fill
|
|
366
|
+
* @returns This writer for chaining
|
|
367
|
+
* @throws RangeError if writing past end of buffer
|
|
368
|
+
*/
|
|
369
|
+
fill(value, length) {
|
|
370
|
+
if (this.#offset + length > this.#data.length) {
|
|
371
|
+
throw new RangeError('Write past end of buffer');
|
|
372
|
+
}
|
|
373
|
+
this.#data.fill(value, this.#offset, this.#offset + length);
|
|
374
|
+
this.#offset += length;
|
|
375
|
+
return this;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Skips a specified number of bytes (leaves them unchanged).
|
|
379
|
+
*
|
|
380
|
+
* @param length - Number of bytes to skip
|
|
381
|
+
* @returns This writer for chaining
|
|
382
|
+
* @throws RangeError if skipping past end of buffer
|
|
383
|
+
*/
|
|
384
|
+
skip(length) {
|
|
385
|
+
if (this.#offset + length > this.#data.length) {
|
|
386
|
+
throw new RangeError('Skip past end of buffer');
|
|
387
|
+
}
|
|
388
|
+
this.#offset += length;
|
|
389
|
+
return this;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Resets the write position to the beginning.
|
|
393
|
+
*
|
|
394
|
+
* @returns This writer for chaining
|
|
395
|
+
*/
|
|
396
|
+
reset() {
|
|
397
|
+
this.#offset = 0;
|
|
398
|
+
return this;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Verifies the buffer was fully written and returns it.
|
|
402
|
+
*
|
|
403
|
+
* Unlike {@link finish}, this method throws if the writer has not
|
|
404
|
+
* written exactly to the end of the buffer.
|
|
405
|
+
*
|
|
406
|
+
* @returns The underlying buffer
|
|
407
|
+
* @throws Error if the buffer was not fully written
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* ```typescript
|
|
411
|
+
* const writer = new BinaryWriter(8);
|
|
412
|
+
* writer.writeUInt32LE(1);
|
|
413
|
+
* writer.writeUInt32LE(2);
|
|
414
|
+
* const bytes = writer.end(); // OK: wrote exactly 8 bytes
|
|
415
|
+
*
|
|
416
|
+
* const writer2 = new BinaryWriter(8);
|
|
417
|
+
* writer2.writeUInt32LE(1);
|
|
418
|
+
* writer2.end(); // throws: buffer size 8, offset 4
|
|
419
|
+
* ```
|
|
420
|
+
*/
|
|
421
|
+
end() {
|
|
422
|
+
if (this.#offset === this.#data.length) {
|
|
423
|
+
return this.#data;
|
|
424
|
+
}
|
|
425
|
+
throw new Error(`buffer size ${this.#data.length}, offset ${this.#offset}`);
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Returns the written portion of the buffer.
|
|
429
|
+
*
|
|
430
|
+
* If the entire buffer was written, returns the buffer directly (no copy).
|
|
431
|
+
* Otherwise, returns a subarray view.
|
|
432
|
+
*
|
|
433
|
+
* @returns Uint8Array containing the written data
|
|
434
|
+
*
|
|
435
|
+
* @example
|
|
436
|
+
* ```typescript
|
|
437
|
+
* const writer = new BinaryWriter(100);
|
|
438
|
+
* writer.writeUInt32LE(42);
|
|
439
|
+
* const bytes = writer.finish(); // 4 bytes
|
|
440
|
+
* ```
|
|
441
|
+
*/
|
|
442
|
+
finish() {
|
|
443
|
+
return this.#offset === this.#data.length
|
|
444
|
+
? this.#data
|
|
445
|
+
: this.#data.subarray(0, this.#offset);
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Returns the written portion as a hex string.
|
|
449
|
+
*
|
|
450
|
+
* @returns Hex string representation
|
|
451
|
+
*
|
|
452
|
+
* @example
|
|
453
|
+
* ```typescript
|
|
454
|
+
* const writer = new BinaryWriter(4);
|
|
455
|
+
* writer.writeUInt32LE(1);
|
|
456
|
+
* writer.toHex(); // '01000000'
|
|
457
|
+
* ```
|
|
458
|
+
*/
|
|
459
|
+
toHex() {
|
|
460
|
+
return toHex(this.finish());
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* A BinaryWriter that automatically grows its buffer as needed.
|
|
465
|
+
*
|
|
466
|
+
* Use when the final size is unknown.
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* ```typescript
|
|
470
|
+
* const writer = BinaryWriter.growable();
|
|
471
|
+
* writer.writeBytes(largeData); // Automatically grows
|
|
472
|
+
* const bytes = writer.finish();
|
|
473
|
+
* ```
|
|
474
|
+
*/
|
|
475
|
+
export class GrowableBinaryWriter {
|
|
476
|
+
#data;
|
|
477
|
+
#view;
|
|
478
|
+
#offset = 0;
|
|
479
|
+
/**
|
|
480
|
+
* Creates a new GrowableBinaryWriter.
|
|
481
|
+
*
|
|
482
|
+
* @param initialCapacity - Initial buffer size (default 256)
|
|
483
|
+
*/
|
|
484
|
+
constructor(initialCapacity = 256) {
|
|
485
|
+
this.#data = new Uint8Array(initialCapacity);
|
|
486
|
+
this.#view = new DataView(this.#data.buffer);
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Current write position.
|
|
490
|
+
*/
|
|
491
|
+
get offset() {
|
|
492
|
+
return this.#offset;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Sets the write position.
|
|
496
|
+
*
|
|
497
|
+
* @param value - New offset value
|
|
498
|
+
* @throws RangeError if offset is negative
|
|
499
|
+
*/
|
|
500
|
+
set offset(value) {
|
|
501
|
+
if (value < 0) {
|
|
502
|
+
throw new RangeError(`Offset ${value} cannot be negative`);
|
|
503
|
+
}
|
|
504
|
+
// GrowableBinaryWriter can grow, so allow setting offset beyond current capacity
|
|
505
|
+
this.#offset = value;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Current buffer capacity.
|
|
509
|
+
*/
|
|
510
|
+
get capacity() {
|
|
511
|
+
return this.#data.length;
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Ensures the buffer has enough space for additional bytes.
|
|
515
|
+
*
|
|
516
|
+
* @param additionalBytes - Number of additional bytes needed
|
|
517
|
+
*/
|
|
518
|
+
#ensureCapacity(additionalBytes) {
|
|
519
|
+
const required = this.#offset + additionalBytes;
|
|
520
|
+
if (required <= this.#data.length) {
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
// Grow by at least 2x or to required size
|
|
524
|
+
let newCapacity = this.#data.length * 2;
|
|
525
|
+
while (newCapacity < required) {
|
|
526
|
+
newCapacity *= 2;
|
|
527
|
+
}
|
|
528
|
+
const newData = new Uint8Array(newCapacity);
|
|
529
|
+
newData.set(this.#data.subarray(0, this.#offset));
|
|
530
|
+
this.#data = newData;
|
|
531
|
+
this.#view = new DataView(this.#data.buffer);
|
|
532
|
+
}
|
|
533
|
+
writeUInt8(value) {
|
|
534
|
+
this.#ensureCapacity(1);
|
|
535
|
+
this.#data[this.#offset++] = value & 0xff;
|
|
536
|
+
return this;
|
|
537
|
+
}
|
|
538
|
+
writeUInt16LE(value) {
|
|
539
|
+
this.#ensureCapacity(2);
|
|
540
|
+
this.#view.setUint16(this.#offset, value, true);
|
|
541
|
+
this.#offset += 2;
|
|
542
|
+
return this;
|
|
543
|
+
}
|
|
544
|
+
writeUInt32LE(value) {
|
|
545
|
+
this.#ensureCapacity(4);
|
|
546
|
+
this.#view.setUint32(this.#offset, value, true);
|
|
547
|
+
this.#offset += 4;
|
|
548
|
+
return this;
|
|
549
|
+
}
|
|
550
|
+
writeInt32LE(value) {
|
|
551
|
+
this.#ensureCapacity(4);
|
|
552
|
+
this.#view.setInt32(this.#offset, value, true);
|
|
553
|
+
this.#offset += 4;
|
|
554
|
+
return this;
|
|
555
|
+
}
|
|
556
|
+
writeUInt64LE(value) {
|
|
557
|
+
this.#ensureCapacity(8);
|
|
558
|
+
this.#view.setBigUint64(this.#offset, value, true);
|
|
559
|
+
this.#offset += 8;
|
|
560
|
+
return this;
|
|
561
|
+
}
|
|
562
|
+
writeBytes(bytes) {
|
|
563
|
+
this.#ensureCapacity(bytes.length);
|
|
564
|
+
this.#data.set(bytes, this.#offset);
|
|
565
|
+
this.#offset += bytes.length;
|
|
566
|
+
return this;
|
|
567
|
+
}
|
|
568
|
+
writeVarInt(value) {
|
|
569
|
+
if (value < 0xfd) {
|
|
570
|
+
return this.writeUInt8(value);
|
|
571
|
+
}
|
|
572
|
+
if (value <= 0xffff) {
|
|
573
|
+
this.writeUInt8(0xfd);
|
|
574
|
+
return this.writeUInt16LE(value);
|
|
575
|
+
}
|
|
576
|
+
if (value <= 0xffffffff) {
|
|
577
|
+
this.writeUInt8(0xfe);
|
|
578
|
+
return this.writeUInt32LE(value);
|
|
579
|
+
}
|
|
580
|
+
this.writeUInt8(0xff);
|
|
581
|
+
return this.writeUInt64LE(BigInt(value));
|
|
582
|
+
}
|
|
583
|
+
writeVarBytes(bytes) {
|
|
584
|
+
this.writeVarInt(bytes.length);
|
|
585
|
+
return this.writeBytes(bytes);
|
|
586
|
+
}
|
|
587
|
+
writeVector(vector) {
|
|
588
|
+
this.writeVarInt(vector.length);
|
|
589
|
+
for (const item of vector) {
|
|
590
|
+
this.writeVarBytes(item);
|
|
591
|
+
}
|
|
592
|
+
return this;
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Returns the written data as a new Uint8Array.
|
|
596
|
+
*
|
|
597
|
+
* @returns Copy of the written data
|
|
598
|
+
*/
|
|
599
|
+
finish() {
|
|
600
|
+
return this.#data.slice(0, this.#offset);
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Returns the written data as a hex string.
|
|
604
|
+
*
|
|
605
|
+
* @returns Hex string representation
|
|
606
|
+
*/
|
|
607
|
+
toHex() {
|
|
608
|
+
return toHex(this.finish());
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
//# sourceMappingURL=BinaryWriter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BinaryWriter.js","sourceRoot":"","sources":["../../src/io/BinaryWriter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC;;;;;;;;;;;;;;;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