@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
package/src/address.ts
CHANGED
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
import { bech32, bech32m } from 'bech32';
|
|
11
11
|
import * as bs58check from 'bs58check';
|
|
12
12
|
import { fromBech32, type Bech32Result } from './bech32utils.js';
|
|
13
|
+
import { alloc } from './io/index.js';
|
|
13
14
|
import * as networks from './networks.js';
|
|
14
|
-
import { Network } from './networks.js';
|
|
15
|
+
import type { Network } from './networks.js';
|
|
15
16
|
import { p2op } from './payments/p2op.js';
|
|
16
17
|
import { p2pkh } from './payments/p2pkh.js';
|
|
17
18
|
import { p2sh } from './payments/p2sh.js';
|
|
@@ -20,16 +21,16 @@ import { p2wpkh } from './payments/p2wpkh.js';
|
|
|
20
21
|
import { p2wsh } from './payments/p2wsh.js';
|
|
21
22
|
import * as bscript from './script.js';
|
|
22
23
|
import { opcodes } from './script.js';
|
|
23
|
-
import {
|
|
24
|
+
import { isBytes20, isUInt8, toBytes20, toBytes32, type Bytes20, type XOnlyPublicKey, type Script } from './types.js';
|
|
24
25
|
|
|
25
26
|
export { fromBech32, type Bech32Result };
|
|
26
27
|
|
|
27
28
|
/** base58check decode result */
|
|
28
29
|
export interface Base58CheckResult {
|
|
29
30
|
/** address hash */
|
|
30
|
-
hash:
|
|
31
|
+
readonly hash: Bytes20;
|
|
31
32
|
/** address version: 0x00 for P2PKH, 0x05 for P2SH */
|
|
32
|
-
version: number;
|
|
33
|
+
readonly version: number;
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
export const FUTURE_SEGWIT_MAX_SIZE: number = 40;
|
|
@@ -45,14 +46,14 @@ const FUTURE_SEGWIT_VERSION_WARNING: string =
|
|
|
45
46
|
'with caution. Wallets should verify the segwit version from the output of fromBech32, ' +
|
|
46
47
|
'then decide when it is safe to use which version of segwit.';
|
|
47
48
|
|
|
48
|
-
export const isUnknownSegwitVersion = (output:
|
|
49
|
+
export const isUnknownSegwitVersion = (output: Uint8Array): boolean => {
|
|
49
50
|
try {
|
|
50
|
-
const data =
|
|
51
|
+
const data = output.subarray(2);
|
|
51
52
|
if (data.length < FUTURE_SEGWIT_MIN_SIZE || data.length > FUTURE_SEGWIT_MAX_SIZE) {
|
|
52
53
|
throw new TypeError('Invalid program length for segwit address');
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
const version = output[0] - FUTURE_SEGWIT_VERSION_DIFF;
|
|
56
|
+
const version = output[0]! - FUTURE_SEGWIT_VERSION_DIFF;
|
|
56
57
|
if (version < FUTURE_SEGWIT_MIN_VERSION || version > FUTURE_SEGWIT_MAX_VERSION + 1) {
|
|
57
58
|
throw new TypeError('Invalid version for segwit address');
|
|
58
59
|
}
|
|
@@ -73,8 +74,8 @@ export const isUnknownSegwitVersion = (output: Buffer): boolean => {
|
|
|
73
74
|
* @param network - Network object containing bech32 and optional bech32Opnet prefix
|
|
74
75
|
* @returns Bech32m-encoded future Taproot-style address
|
|
75
76
|
*/
|
|
76
|
-
export function toFutureOPNetAddress(output:
|
|
77
|
-
if (!
|
|
77
|
+
export function toFutureOPNetAddress(output: Uint8Array, network: Network): string {
|
|
78
|
+
if (!(output instanceof Uint8Array)) throw new TypeError('output must be a Uint8Array');
|
|
78
79
|
if (!network.bech32Opnet) throw new Error('Network does not support opnet');
|
|
79
80
|
|
|
80
81
|
const opcode = output[0];
|
|
@@ -82,17 +83,17 @@ export function toFutureOPNetAddress(output: Buffer, network: Network): string {
|
|
|
82
83
|
// work out where the push-data really starts
|
|
83
84
|
let pushPos = 1,
|
|
84
85
|
progLen: number;
|
|
85
|
-
if (output[1] < 0x4c) {
|
|
86
|
-
progLen = output[1]
|
|
86
|
+
if (output[1]! < 0x4c) {
|
|
87
|
+
progLen = output[1]!;
|
|
87
88
|
pushPos = 2;
|
|
88
89
|
} else if (output[1] === 0x4c) {
|
|
89
|
-
progLen = output[2]
|
|
90
|
+
progLen = output[2]!;
|
|
90
91
|
pushPos = 3;
|
|
91
92
|
} else {
|
|
92
93
|
throw new TypeError('Unsupported push opcode in script');
|
|
93
94
|
}
|
|
94
95
|
|
|
95
|
-
const program =
|
|
96
|
+
const program = output.subarray(pushPos, pushPos + progLen);
|
|
96
97
|
|
|
97
98
|
if (program.length < FUTURE_SEGWIT_MIN_SIZE || program.length > FUTURE_SEGWIT_MAX_SIZE)
|
|
98
99
|
throw new TypeError('Invalid program length for segwit address');
|
|
@@ -100,8 +101,8 @@ export function toFutureOPNetAddress(output: Buffer, network: Network): string {
|
|
|
100
101
|
const version =
|
|
101
102
|
opcode === opcodes.OP_0
|
|
102
103
|
? 0
|
|
103
|
-
: opcode >= opcodes.OP_1 && opcode <= opcodes.OP_16
|
|
104
|
-
? opcode - (opcodes.OP_1 - 1)
|
|
104
|
+
: opcode! >= opcodes.OP_1 && opcode! <= opcodes.OP_16
|
|
105
|
+
? opcode! - (opcodes.OP_1 - 1)
|
|
105
106
|
: -1;
|
|
106
107
|
|
|
107
108
|
if (version < FUTURE_SEGWIT_MAX_VERSION || version > FUTURE_MAX_VERSION)
|
|
@@ -111,13 +112,13 @@ export function toFutureOPNetAddress(output: Buffer, network: Network): string {
|
|
|
111
112
|
return bech32m.encode(network.bech32Opnet, words);
|
|
112
113
|
}
|
|
113
114
|
|
|
114
|
-
export function _toFutureSegwitAddress(output:
|
|
115
|
-
const data =
|
|
115
|
+
export function _toFutureSegwitAddress(output: Uint8Array, network: Network): string {
|
|
116
|
+
const data = output.subarray(2);
|
|
116
117
|
if (data.length < FUTURE_SEGWIT_MIN_SIZE || data.length > FUTURE_SEGWIT_MAX_SIZE) {
|
|
117
118
|
throw new TypeError('Invalid program length for segwit address');
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
const version = output[0] - FUTURE_SEGWIT_VERSION_DIFF;
|
|
121
|
+
const version = output[0]! - FUTURE_SEGWIT_VERSION_DIFF;
|
|
121
122
|
if (version < FUTURE_SEGWIT_MIN_VERSION || version > FUTURE_SEGWIT_MAX_VERSION) {
|
|
122
123
|
throw new TypeError('Invalid version for segwit address');
|
|
123
124
|
}
|
|
@@ -133,14 +134,14 @@ export function _toFutureSegwitAddress(output: Buffer, network: Network): string
|
|
|
133
134
|
* decode address with base58 specification, return address version and address hash if valid
|
|
134
135
|
*/
|
|
135
136
|
export function fromBase58Check(address: string): Base58CheckResult {
|
|
136
|
-
const payload =
|
|
137
|
+
const payload = new Uint8Array(bs58check.default.decode(address));
|
|
137
138
|
|
|
138
139
|
// TODO: 4.0.0, move to "toOutputScript"
|
|
139
140
|
if (payload.length < 21) throw new TypeError(address + ' is too short');
|
|
140
141
|
if (payload.length > 21) throw new TypeError(address + ' is too long');
|
|
141
142
|
|
|
142
|
-
const version = payload
|
|
143
|
-
const hash =
|
|
143
|
+
const version = payload[0]!;
|
|
144
|
+
const hash = payload.subarray(1) as Bytes20;
|
|
144
145
|
|
|
145
146
|
return { version, hash };
|
|
146
147
|
}
|
|
@@ -148,12 +149,13 @@ export function fromBase58Check(address: string): Base58CheckResult {
|
|
|
148
149
|
/**
|
|
149
150
|
* encode address hash to base58 address with version
|
|
150
151
|
*/
|
|
151
|
-
export function toBase58Check(hash:
|
|
152
|
-
|
|
152
|
+
export function toBase58Check(hash: Bytes20, version: number): string {
|
|
153
|
+
if (!isBytes20(hash)) throw new TypeError('Expected 20 bytes hash');
|
|
154
|
+
if (!isUInt8(version)) throw new TypeError('Expected UInt8 version');
|
|
153
155
|
|
|
154
|
-
const payload =
|
|
155
|
-
payload
|
|
156
|
-
|
|
156
|
+
const payload = alloc(21);
|
|
157
|
+
payload[0] = version;
|
|
158
|
+
payload.set(hash, 1);
|
|
157
159
|
|
|
158
160
|
return bs58check.default.encode(payload);
|
|
159
161
|
}
|
|
@@ -162,7 +164,7 @@ export function toBase58Check(hash: Buffer, version: number): string {
|
|
|
162
164
|
* encode address hash to bech32 address with version and prefix
|
|
163
165
|
*/
|
|
164
166
|
export function toBech32(
|
|
165
|
-
data:
|
|
167
|
+
data: Uint8Array,
|
|
166
168
|
version: number,
|
|
167
169
|
prefix: string,
|
|
168
170
|
prefixOpnet?: string,
|
|
@@ -180,24 +182,24 @@ export function toBech32(
|
|
|
180
182
|
/**
|
|
181
183
|
* decode address from output script with network, return address if matched
|
|
182
184
|
*/
|
|
183
|
-
export function fromOutputScript(output:
|
|
185
|
+
export function fromOutputScript(output: Uint8Array, network?: Network): string {
|
|
184
186
|
// TODO: Network
|
|
185
187
|
network = network || networks.bitcoin;
|
|
186
188
|
|
|
187
189
|
try {
|
|
188
|
-
return p2pkh({ output, network }).address as string;
|
|
190
|
+
return p2pkh({ output: output as Script, network }).address as string;
|
|
189
191
|
} catch (e) {}
|
|
190
192
|
try {
|
|
191
|
-
return p2sh({ output, network }).address as string;
|
|
193
|
+
return p2sh({ output: output as Script, network }).address as string;
|
|
192
194
|
} catch (e) {}
|
|
193
195
|
try {
|
|
194
|
-
return p2wpkh({ output, network }).address as string;
|
|
196
|
+
return p2wpkh({ output: output as Script, network }).address as string;
|
|
195
197
|
} catch (e) {}
|
|
196
198
|
try {
|
|
197
|
-
return p2wsh({ output, network }).address as string;
|
|
199
|
+
return p2wsh({ output: output as Script, network }).address as string;
|
|
198
200
|
} catch (e) {}
|
|
199
201
|
try {
|
|
200
|
-
return p2tr({ output, network }).address as string;
|
|
202
|
+
return p2tr({ output: output as Script, network }).address as string;
|
|
201
203
|
} catch (e) {}
|
|
202
204
|
try {
|
|
203
205
|
return toFutureOPNetAddress(output, network);
|
|
@@ -210,10 +212,45 @@ export function fromOutputScript(output: Buffer, network?: Network): string {
|
|
|
210
212
|
}
|
|
211
213
|
|
|
212
214
|
/**
|
|
213
|
-
*
|
|
215
|
+
* Options for toOutputScript function.
|
|
214
216
|
*/
|
|
215
|
-
export
|
|
216
|
-
|
|
217
|
+
export interface ToOutputScriptOptions {
|
|
218
|
+
/**
|
|
219
|
+
* Network to use for encoding. Defaults to bitcoin mainnet.
|
|
220
|
+
*/
|
|
221
|
+
readonly network?: Network;
|
|
222
|
+
/**
|
|
223
|
+
* Optional callback for future segwit version warnings.
|
|
224
|
+
* If provided, called with FUTURE_SEGWIT_VERSION_WARNING when encoding
|
|
225
|
+
* to a future segwit version (v2-v15) address.
|
|
226
|
+
* If not provided, no warning is emitted.
|
|
227
|
+
*/
|
|
228
|
+
readonly onFutureSegwitWarning?: (warning: string) => void;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Encodes address to output script with network, return output script if address matched.
|
|
233
|
+
* @param address - The address to encode
|
|
234
|
+
* @param networkOrOptions - Network or options object
|
|
235
|
+
* @returns The output script as Uint8Array
|
|
236
|
+
*/
|
|
237
|
+
export function toOutputScript(
|
|
238
|
+
address: string,
|
|
239
|
+
networkOrOptions?: Network | ToOutputScriptOptions,
|
|
240
|
+
): Uint8Array {
|
|
241
|
+
let network: Network;
|
|
242
|
+
let onFutureSegwitWarning: ((warning: string) => void) | undefined;
|
|
243
|
+
|
|
244
|
+
if (networkOrOptions && 'bech32' in networkOrOptions) {
|
|
245
|
+
// It's a Network object
|
|
246
|
+
network = networkOrOptions;
|
|
247
|
+
} else if (networkOrOptions && typeof networkOrOptions === 'object') {
|
|
248
|
+
// It's an options object
|
|
249
|
+
network = networkOrOptions.network || networks.bitcoin;
|
|
250
|
+
onFutureSegwitWarning = networkOrOptions.onFutureSegwitWarning;
|
|
251
|
+
} else {
|
|
252
|
+
network = networks.bitcoin;
|
|
253
|
+
}
|
|
217
254
|
|
|
218
255
|
let decodeBase58: Base58CheckResult | undefined;
|
|
219
256
|
let decodeBech32: Bech32Result | undefined;
|
|
@@ -223,9 +260,9 @@ export function toOutputScript(address: string, network?: Network): Buffer {
|
|
|
223
260
|
|
|
224
261
|
if (decodeBase58) {
|
|
225
262
|
if (decodeBase58.version === network.pubKeyHash)
|
|
226
|
-
return p2pkh({ hash: decodeBase58.hash }).output as
|
|
263
|
+
return p2pkh({ hash: decodeBase58.hash }).output as Uint8Array;
|
|
227
264
|
if (decodeBase58.version === network.scriptHash)
|
|
228
|
-
return p2sh({ hash: decodeBase58.hash }).output as
|
|
265
|
+
return p2sh({ hash: decodeBase58.hash }).output as Uint8Array;
|
|
229
266
|
} else {
|
|
230
267
|
try {
|
|
231
268
|
decodeBech32 = fromBech32(address);
|
|
@@ -240,26 +277,26 @@ export function toOutputScript(address: string, network?: Network): Buffer {
|
|
|
240
277
|
throw new Error(address + ' has an invalid prefix');
|
|
241
278
|
if (decodeBech32.version === 0) {
|
|
242
279
|
if (decodeBech32.data.length === 20)
|
|
243
|
-
return p2wpkh({ hash: decodeBech32.data }).output as
|
|
280
|
+
return p2wpkh({ hash: toBytes20(decodeBech32.data) }).output as Uint8Array;
|
|
244
281
|
if (decodeBech32.data.length === 32)
|
|
245
|
-
return p2wsh({ hash: decodeBech32.data }).output as
|
|
282
|
+
return p2wsh({ hash: toBytes32(decodeBech32.data) }).output as Uint8Array;
|
|
246
283
|
} else if (decodeBech32.version === 1) {
|
|
247
284
|
if (decodeBech32.data.length === 32)
|
|
248
|
-
return p2tr({ pubkey: decodeBech32.data }).output as
|
|
285
|
+
return p2tr({ pubkey: decodeBech32.data as XOnlyPublicKey }).output as Uint8Array;
|
|
249
286
|
} else if (decodeBech32.version === FUTURE_OPNET_VERSION) {
|
|
250
287
|
if (!network.bech32Opnet) throw new Error(address + ' has an invalid prefix');
|
|
251
288
|
return p2op({
|
|
252
289
|
program: decodeBech32.data,
|
|
253
290
|
network,
|
|
254
|
-
}).output as
|
|
291
|
+
}).output as Uint8Array;
|
|
255
292
|
} else if (
|
|
256
293
|
decodeBech32.version >= FUTURE_SEGWIT_MIN_VERSION &&
|
|
257
294
|
decodeBech32.version <= FUTURE_SEGWIT_MAX_VERSION &&
|
|
258
295
|
decodeBech32.data.length >= FUTURE_SEGWIT_MIN_SIZE &&
|
|
259
296
|
decodeBech32.data.length <= FUTURE_SEGWIT_MAX_SIZE
|
|
260
297
|
) {
|
|
261
|
-
if (decodeBech32.version !== FUTURE_OPNET_VERSION) {
|
|
262
|
-
|
|
298
|
+
if (decodeBech32.version !== FUTURE_OPNET_VERSION && onFutureSegwitWarning) {
|
|
299
|
+
onFutureSegwitWarning(FUTURE_SEGWIT_VERSION_WARNING);
|
|
263
300
|
}
|
|
264
301
|
|
|
265
302
|
return bscript.compile([
|
package/src/bech32utils.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface Bech32Result {
|
|
|
11
11
|
/** address prefix: bc for P2WPKH、P2WSH、P2TR */
|
|
12
12
|
prefix: string;
|
|
13
13
|
/** address data:20 bytes for P2WPKH, 32 bytes for P2WSH、P2TR */
|
|
14
|
-
data:
|
|
14
|
+
data: Uint8Array;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -36,8 +36,8 @@ export function fromBech32(address: string): Bech32Result {
|
|
|
36
36
|
const data = bech32.fromWords(result.words.slice(1));
|
|
37
37
|
|
|
38
38
|
return {
|
|
39
|
-
version
|
|
39
|
+
version: version!,
|
|
40
40
|
prefix: result.prefix,
|
|
41
|
-
data:
|
|
41
|
+
data: new Uint8Array(data),
|
|
42
42
|
};
|
|
43
43
|
}
|
package/src/bip66.ts
CHANGED
|
@@ -2,52 +2,62 @@
|
|
|
2
2
|
// Format: 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S]
|
|
3
3
|
// NOTE: SIGHASH byte ignored AND restricted, truncate before use
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import { alloc } from './io/index.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* DER-encoded signature components.
|
|
9
|
+
*/
|
|
10
|
+
export interface DerSignature {
|
|
11
|
+
readonly r: Uint8Array;
|
|
12
|
+
readonly s: Uint8Array;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function check(buffer: Uint8Array): boolean {
|
|
6
16
|
if (buffer.length < 8) return false;
|
|
7
17
|
if (buffer.length > 72) return false;
|
|
8
18
|
if (buffer[0] !== 0x30) return false;
|
|
9
19
|
if (buffer[1] !== buffer.length - 2) return false;
|
|
10
20
|
if (buffer[2] !== 0x02) return false;
|
|
11
21
|
|
|
12
|
-
const lenR = buffer[3]
|
|
22
|
+
const lenR = buffer[3]!;
|
|
13
23
|
if (lenR === 0) return false;
|
|
14
24
|
if (5 + lenR >= buffer.length) return false;
|
|
15
|
-
if (buffer[4 + lenR] !== 0x02) return false;
|
|
25
|
+
if (buffer[4 + lenR]! !== 0x02) return false;
|
|
16
26
|
|
|
17
|
-
const lenS = buffer[5 + lenR]
|
|
27
|
+
const lenS = buffer[5 + lenR]!;
|
|
18
28
|
if (lenS === 0) return false;
|
|
19
29
|
if (6 + lenR + lenS !== buffer.length) return false;
|
|
20
30
|
|
|
21
|
-
if (buffer[4] & 0x80) return false;
|
|
22
|
-
if (lenR > 1 && buffer[4] === 0x00 && !(buffer[5] & 0x80)) return false;
|
|
31
|
+
if (buffer[4]! & 0x80) return false;
|
|
32
|
+
if (lenR > 1 && buffer[4] === 0x00 && !(buffer[5]! & 0x80)) return false;
|
|
23
33
|
|
|
24
|
-
if (buffer[lenR + 6] & 0x80) return false;
|
|
25
|
-
if (lenS > 1 && buffer[lenR + 6] === 0x00 && !(buffer[lenR + 7] & 0x80)) return false;
|
|
34
|
+
if (buffer[lenR + 6]! & 0x80) return false;
|
|
35
|
+
if (lenS > 1 && buffer[lenR + 6] === 0x00 && !(buffer[lenR + 7]! & 0x80)) return false;
|
|
26
36
|
return true;
|
|
27
37
|
}
|
|
28
38
|
|
|
29
|
-
export function decode(buffer:
|
|
39
|
+
export function decode(buffer: Uint8Array): DerSignature {
|
|
30
40
|
if (buffer.length < 8) throw new Error('DER sequence length is too short');
|
|
31
41
|
if (buffer.length > 72) throw new Error('DER sequence length is too long');
|
|
32
42
|
if (buffer[0] !== 0x30) throw new Error('Expected DER sequence');
|
|
33
43
|
if (buffer[1] !== buffer.length - 2) throw new Error('DER sequence length is invalid');
|
|
34
44
|
if (buffer[2] !== 0x02) throw new Error('Expected DER integer');
|
|
35
45
|
|
|
36
|
-
const lenR = buffer[3]
|
|
46
|
+
const lenR = buffer[3]!;
|
|
37
47
|
if (lenR === 0) throw new Error('R length is zero');
|
|
38
48
|
if (5 + lenR >= buffer.length) throw new Error('R length is too long');
|
|
39
|
-
if (buffer[4 + lenR] !== 0x02) throw new Error('Expected DER integer (2)');
|
|
49
|
+
if (buffer[4 + lenR]! !== 0x02) throw new Error('Expected DER integer (2)');
|
|
40
50
|
|
|
41
|
-
const lenS = buffer[5 + lenR]
|
|
51
|
+
const lenS = buffer[5 + lenR]!;
|
|
42
52
|
if (lenS === 0) throw new Error('S length is zero');
|
|
43
53
|
if (6 + lenR + lenS !== buffer.length) throw new Error('S length is invalid');
|
|
44
54
|
|
|
45
|
-
if (buffer[4] & 0x80) throw new Error('R value is negative');
|
|
46
|
-
if (lenR > 1 && buffer[4] === 0x00 && !(buffer[5] & 0x80))
|
|
55
|
+
if (buffer[4]! & 0x80) throw new Error('R value is negative');
|
|
56
|
+
if (lenR > 1 && buffer[4] === 0x00 && !(buffer[5]! & 0x80))
|
|
47
57
|
throw new Error('R value excessively padded');
|
|
48
58
|
|
|
49
|
-
if (buffer[lenR + 6] & 0x80) throw new Error('S value is negative');
|
|
50
|
-
if (lenS > 1 && buffer[lenR + 6] === 0x00 && !(buffer[lenR + 7] & 0x80))
|
|
59
|
+
if (buffer[lenR + 6]! & 0x80) throw new Error('S value is negative');
|
|
60
|
+
if (lenS > 1 && buffer[lenR + 6] === 0x00 && !(buffer[lenR + 7]! & 0x80))
|
|
51
61
|
throw new Error('S value excessively padded');
|
|
52
62
|
|
|
53
63
|
// non-BIP66 - extract R, S values
|
|
@@ -79,29 +89,29 @@ export function decode(buffer: Buffer): { r: Buffer; s: Buffer } {
|
|
|
79
89
|
* 62300 => 0x00f35c
|
|
80
90
|
* -62300 => 0xff0ca4
|
|
81
91
|
*/
|
|
82
|
-
export function encode(r:
|
|
92
|
+
export function encode(r: Uint8Array, s: Uint8Array): Uint8Array {
|
|
83
93
|
const lenR = r.length;
|
|
84
94
|
const lenS = s.length;
|
|
85
95
|
if (lenR === 0) throw new Error('R length is zero');
|
|
86
96
|
if (lenS === 0) throw new Error('S length is zero');
|
|
87
97
|
if (lenR > 33) throw new Error('R length is too long');
|
|
88
98
|
if (lenS > 33) throw new Error('S length is too long');
|
|
89
|
-
if (r[0] & 0x80) throw new Error('R value is negative');
|
|
90
|
-
if (s[0] & 0x80) throw new Error('S value is negative');
|
|
91
|
-
if (lenR > 1 && r[0] === 0x00 && !(r[1] & 0x80)) throw new Error('R value excessively padded');
|
|
92
|
-
if (lenS > 1 && s[0] === 0x00 && !(s[1] & 0x80)) throw new Error('S value excessively padded');
|
|
99
|
+
if (r[0]! & 0x80) throw new Error('R value is negative');
|
|
100
|
+
if (s[0]! & 0x80) throw new Error('S value is negative');
|
|
101
|
+
if (lenR > 1 && r[0] === 0x00 && !(r[1]! & 0x80)) throw new Error('R value excessively padded');
|
|
102
|
+
if (lenS > 1 && s[0] === 0x00 && !(s[1]! & 0x80)) throw new Error('S value excessively padded');
|
|
93
103
|
|
|
94
|
-
const signature =
|
|
104
|
+
const signature = alloc(6 + lenR + lenS);
|
|
95
105
|
|
|
96
106
|
// 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S]
|
|
97
107
|
signature[0] = 0x30;
|
|
98
108
|
signature[1] = signature.length - 2;
|
|
99
109
|
signature[2] = 0x02;
|
|
100
110
|
signature[3] = r.length;
|
|
101
|
-
|
|
111
|
+
signature.set(r, 4);
|
|
102
112
|
signature[4 + lenR] = 0x02;
|
|
103
113
|
signature[5 + lenR] = s.length;
|
|
104
|
-
|
|
114
|
+
signature.set(s, 6 + lenR);
|
|
105
115
|
|
|
106
116
|
return signature;
|
|
107
117
|
}
|