@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/types.ts
CHANGED
|
@@ -1,132 +1,263 @@
|
|
|
1
|
-
import { Buffer as NBuffer } from 'buffer';
|
|
2
|
-
import typeforce from 'typeforce';
|
|
3
|
-
|
|
4
|
-
export { typeforce };
|
|
5
|
-
|
|
6
1
|
/**
|
|
7
|
-
*
|
|
2
|
+
* Core type definitions, branded types, and type guard functions.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
8
5
|
*/
|
|
9
|
-
|
|
6
|
+
import { isZero, compare, fromHex, equals } from './io/index.js';
|
|
10
7
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
'hex',
|
|
15
|
-
);
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Branded Types (re-exported from branded.ts to avoid circular dependencies)
|
|
10
|
+
// ============================================================================
|
|
16
11
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
12
|
+
export type {
|
|
13
|
+
Bytes32,
|
|
14
|
+
Bytes20,
|
|
15
|
+
PublicKey,
|
|
16
|
+
XOnlyPublicKey,
|
|
17
|
+
Satoshi,
|
|
18
|
+
PrivateKey,
|
|
19
|
+
Signature,
|
|
20
|
+
SchnorrSignature,
|
|
21
|
+
Script,
|
|
22
|
+
} from './branded.js';
|
|
23
|
+
|
|
24
|
+
import type { Bytes32, Bytes20, Satoshi, PrivateKey, XOnlyPublicKey, PublicKey, SchnorrSignature, Signature, Script } from './branded.js';
|
|
25
|
+
|
|
26
|
+
// ============================================================================
|
|
27
|
+
// Constants
|
|
28
|
+
// ============================================================================
|
|
29
|
+
|
|
30
|
+
/** @internal Do not mutate */
|
|
31
|
+
const EC_P = fromHex('fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f');
|
|
32
|
+
/** @internal Do not mutate — secp256k1 curve order */
|
|
33
|
+
const EC_N = fromHex('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141');
|
|
34
|
+
|
|
35
|
+
export const SATOSHI_MAX = 21n * 10n ** 14n;
|
|
36
|
+
export const TAPLEAF_VERSION_MASK = 0xfe;
|
|
25
37
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
38
|
+
// ============================================================================
|
|
39
|
+
// Type Guards
|
|
40
|
+
// ============================================================================
|
|
41
|
+
|
|
42
|
+
export function isUInt8(value: unknown): value is number {
|
|
43
|
+
return (
|
|
44
|
+
typeof value === 'number' &&
|
|
45
|
+
Number.isInteger(value) &&
|
|
46
|
+
value >= 0 &&
|
|
47
|
+
value <= 0xff
|
|
48
|
+
);
|
|
29
49
|
}
|
|
30
50
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
51
|
+
export function isUInt32(value: unknown): value is number {
|
|
52
|
+
return (
|
|
53
|
+
typeof value === 'number' &&
|
|
54
|
+
Number.isInteger(value) &&
|
|
55
|
+
value >= 0 &&
|
|
56
|
+
value <= 0xffffffff
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function isNumber(value: unknown): value is number {
|
|
61
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
62
|
+
}
|
|
39
63
|
|
|
40
|
-
|
|
41
|
-
|
|
64
|
+
export function isUint8Array(value: unknown): value is Uint8Array {
|
|
65
|
+
return value instanceof Uint8Array;
|
|
66
|
+
}
|
|
42
67
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
68
|
+
export function isUint8ArrayN<N extends number>(
|
|
69
|
+
value: unknown,
|
|
70
|
+
n: N,
|
|
71
|
+
): value is Uint8Array & { readonly length: N } {
|
|
72
|
+
return value instanceof Uint8Array && value.length === n;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function isArray(value: unknown): value is unknown[] {
|
|
76
|
+
return Array.isArray(value);
|
|
77
|
+
}
|
|
46
78
|
|
|
47
|
-
|
|
48
|
-
if (
|
|
79
|
+
export function isHex(value: unknown): value is string {
|
|
80
|
+
if (typeof value !== 'string') return false;
|
|
81
|
+
if (value.length % 2 !== 0) return false;
|
|
82
|
+
return /^[0-9a-fA-F]*$/.test(value);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function isBytes32(value: unknown): value is Bytes32 {
|
|
86
|
+
return value instanceof Uint8Array && value.length === 32;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function isBytes20(value: unknown): value is Bytes20 {
|
|
90
|
+
return value instanceof Uint8Array && value.length === 20;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function isXOnlyPublicKey(value: unknown): value is XOnlyPublicKey {
|
|
94
|
+
if (!(value instanceof Uint8Array) || value.length !== 32) return false;
|
|
95
|
+
if (isZero(value)) return false;
|
|
96
|
+
if (compare(value, EC_P) >= 0) return false;
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function isPoint(value: unknown): value is PublicKey {
|
|
101
|
+
if (!(value instanceof Uint8Array)) return false;
|
|
102
|
+
if (value.length < 33) return false;
|
|
103
|
+
|
|
104
|
+
const prefix = value[0];
|
|
105
|
+
const x = value.subarray(1, 33);
|
|
106
|
+
|
|
107
|
+
if (isZero(x)) return false;
|
|
108
|
+
if (compare(x, EC_P) >= 0) return false;
|
|
109
|
+
|
|
110
|
+
if ((prefix === 0x02 || prefix === 0x03) && value.length === 33) {
|
|
49
111
|
return true;
|
|
50
112
|
}
|
|
51
113
|
|
|
52
|
-
|
|
53
|
-
if (p.length !== 65) return false;
|
|
114
|
+
if (value.length !== 65) return false;
|
|
54
115
|
|
|
55
|
-
const y =
|
|
116
|
+
const y = value.subarray(33);
|
|
117
|
+
if (isZero(y)) return false;
|
|
118
|
+
if (compare(y, EC_P) >= 0) return false;
|
|
56
119
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (y.compare(EC_P) >= 0) return false; // Y must be < P
|
|
120
|
+
return prefix === 0x04 || prefix === 0x06 || prefix === 0x07;
|
|
121
|
+
}
|
|
60
122
|
|
|
61
|
-
|
|
62
|
-
return
|
|
123
|
+
export function isSatoshi(value: unknown): value is Satoshi {
|
|
124
|
+
return typeof value === 'bigint' && value >= 0n && value <= SATOSHI_MAX;
|
|
63
125
|
}
|
|
64
126
|
|
|
65
|
-
|
|
127
|
+
export function isPrivateKey(value: unknown): value is PrivateKey {
|
|
128
|
+
if (!(value instanceof Uint8Array) || value.length !== 32) return false;
|
|
129
|
+
if (isZero(value)) return false;
|
|
130
|
+
if (compare(value, EC_N) >= 0) return false;
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
66
133
|
|
|
67
|
-
export function
|
|
68
|
-
return
|
|
134
|
+
export function isSchnorrSignature(value: unknown): value is SchnorrSignature {
|
|
135
|
+
return value instanceof Uint8Array && value.length === 64;
|
|
69
136
|
}
|
|
70
137
|
|
|
71
|
-
export
|
|
72
|
-
|
|
73
|
-
xOnlyPubkey: Uint8Array;
|
|
138
|
+
export function isSignature(value: unknown): value is Signature {
|
|
139
|
+
return value instanceof Uint8Array && value.length >= 8 && value.length <= 73;
|
|
74
140
|
}
|
|
75
141
|
|
|
142
|
+
export function isScript(value: unknown): value is Script {
|
|
143
|
+
return value instanceof Uint8Array;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// ============================================================================
|
|
147
|
+
// Taproot Types
|
|
148
|
+
// ============================================================================
|
|
149
|
+
|
|
76
150
|
export interface Tapleaf {
|
|
77
|
-
output:
|
|
78
|
-
version?: number;
|
|
151
|
+
readonly output: Uint8Array;
|
|
152
|
+
readonly version?: number;
|
|
79
153
|
}
|
|
80
154
|
|
|
81
|
-
export
|
|
155
|
+
export type Taptree = [Taptree | Tapleaf, Taptree | Tapleaf] | Tapleaf;
|
|
156
|
+
|
|
157
|
+
export function isTapleaf(value: unknown): value is Tapleaf {
|
|
158
|
+
if (!value || typeof value !== 'object') return false;
|
|
159
|
+
|
|
160
|
+
const obj = value as Record<string, unknown>;
|
|
161
|
+
if (!('output' in obj)) return false;
|
|
162
|
+
if (!(obj['output'] instanceof Uint8Array)) return false;
|
|
163
|
+
|
|
164
|
+
if (obj['version'] !== undefined) {
|
|
165
|
+
if (typeof obj['version'] !== 'number') return false;
|
|
166
|
+
if ((obj['version'] & TAPLEAF_VERSION_MASK) !== obj['version']) return false;
|
|
167
|
+
}
|
|
82
168
|
|
|
83
|
-
export function isTapleaf(o: unknown): o is Tapleaf {
|
|
84
|
-
if (!o || typeof o !== 'object' || !('output' in o)) return false;
|
|
85
|
-
const obj = o as Record<string, unknown>;
|
|
86
|
-
if (!NBuffer.isBuffer(obj.output)) return false;
|
|
87
|
-
if (obj.version !== undefined)
|
|
88
|
-
return ((obj.version as number) & TAPLEAF_VERSION_MASK) === obj.version;
|
|
89
169
|
return true;
|
|
90
170
|
}
|
|
91
171
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
172
|
+
export function isTaptree(value: unknown): value is Taptree {
|
|
173
|
+
if (!Array.isArray(value)) return isTapleaf(value);
|
|
174
|
+
if (value.length !== 2) return false;
|
|
175
|
+
return value.every((node: unknown) => isTaptree(node));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ============================================================================
|
|
179
|
+
// ECC Interface (re-exported from ecc/types.ts for backward compatibility)
|
|
180
|
+
// ============================================================================
|
|
98
181
|
|
|
99
|
-
export
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
export
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
xOnlyPointAddTweak(p: Uint8Array, tweak: Uint8Array): XOnlyPointAddTweakResult | null;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export const Buffer256bit: TypeforceValidator = typeforce.BufferN(32);
|
|
112
|
-
export const Hash160bit: TypeforceValidator = typeforce.BufferN(20);
|
|
113
|
-
export const Hash256bit: TypeforceValidator = typeforce.BufferN(32);
|
|
114
|
-
export const Number: TypeforceValidator = typeforce.Number;
|
|
115
|
-
export const Array: TypeforceValidator = typeforce.Array;
|
|
116
|
-
export const Boolean: TypeforceValidator = typeforce.Boolean;
|
|
117
|
-
export const String: TypeforceValidator = typeforce.String;
|
|
118
|
-
export const Buffer: TypeforceValidator = typeforce.Buffer;
|
|
119
|
-
export const Hex: TypeforceValidator = typeforce.Hex;
|
|
120
|
-
export const maybe: (type: unknown) => TypeforceValidator = typeforce.maybe;
|
|
121
|
-
export const tuple: (...types: unknown[]) => TypeforceValidator = typeforce.tuple;
|
|
122
|
-
export const UInt8: TypeforceValidator = typeforce.UInt8;
|
|
123
|
-
export const UInt32: TypeforceValidator = typeforce.UInt32;
|
|
124
|
-
export const Function: TypeforceValidator = typeforce.Function;
|
|
125
|
-
export const BufferN: (n: number) => TypeforceValidator = typeforce.BufferN;
|
|
126
|
-
export const Null: TypeforceValidator = typeforce.Null;
|
|
127
|
-
export const oneOf: (...types: unknown[]) => TypeforceValidator = typeforce.oneOf;
|
|
128
|
-
|
|
129
|
-
// Stack types - used by script and payments
|
|
130
|
-
export type StackElement = globalThis.Buffer | number;
|
|
131
|
-
export type Stack = StackElement[];
|
|
182
|
+
export type { XOnlyPointAddTweakResult, EccLib, Parity } from './ecc/types.js';
|
|
183
|
+
|
|
184
|
+
// ============================================================================
|
|
185
|
+
// Stack Types
|
|
186
|
+
// ============================================================================
|
|
187
|
+
|
|
188
|
+
export type StackElement = Uint8Array | number;
|
|
189
|
+
export type Stack = readonly StackElement[];
|
|
132
190
|
export type StackFunction = () => Stack;
|
|
191
|
+
|
|
192
|
+
// ============================================================================
|
|
193
|
+
// Utility Functions
|
|
194
|
+
// ============================================================================
|
|
195
|
+
|
|
196
|
+
export function stacksEqual(a: Uint8Array[], b: Uint8Array[]): boolean {
|
|
197
|
+
if (a.length !== b.length) return false;
|
|
198
|
+
return a.every((x, i) => equals(x, b[i]!));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function toBytes32(value: Uint8Array): Bytes32 {
|
|
202
|
+
if (!isBytes32(value)) {
|
|
203
|
+
throw new TypeError(`Expected 32-byte Uint8Array, got ${value.length} bytes`);
|
|
204
|
+
}
|
|
205
|
+
return value;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function toBytes20(value: Uint8Array): Bytes20 {
|
|
209
|
+
if (!isBytes20(value)) {
|
|
210
|
+
throw new TypeError(`Expected 20-byte Uint8Array, got ${value.length} bytes`);
|
|
211
|
+
}
|
|
212
|
+
return value;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function toSatoshi(value: bigint): Satoshi {
|
|
216
|
+
if (value < 0n) {
|
|
217
|
+
throw new RangeError(`Satoshi cannot be negative, got ${value}`);
|
|
218
|
+
}
|
|
219
|
+
if (value > SATOSHI_MAX) {
|
|
220
|
+
throw new RangeError(`Satoshi exceeds maximum supply (${SATOSHI_MAX}), got ${value}`);
|
|
221
|
+
}
|
|
222
|
+
return value as Satoshi;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// ============================================================================
|
|
226
|
+
// Assertion Helpers
|
|
227
|
+
// ============================================================================
|
|
228
|
+
|
|
229
|
+
export function assertXOnlyPublicKey(
|
|
230
|
+
value: unknown,
|
|
231
|
+
name: string,
|
|
232
|
+
): asserts value is XOnlyPublicKey {
|
|
233
|
+
if (!(value instanceof Uint8Array)) {
|
|
234
|
+
throw new TypeError(`${name} must be Uint8Array, got ${typeof value}`);
|
|
235
|
+
}
|
|
236
|
+
if (value.length !== 32) {
|
|
237
|
+
throw new TypeError(`${name} must be 32 bytes, got ${value.length}`);
|
|
238
|
+
}
|
|
239
|
+
if (isZero(value)) {
|
|
240
|
+
throw new RangeError(`${name} cannot be zero`);
|
|
241
|
+
}
|
|
242
|
+
if (compare(value, EC_P) >= 0) {
|
|
243
|
+
throw new RangeError(`${name} exceeds curve order`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export function assertPrivateKey(
|
|
248
|
+
value: unknown,
|
|
249
|
+
name: string,
|
|
250
|
+
): asserts value is PrivateKey {
|
|
251
|
+
if (!(value instanceof Uint8Array)) {
|
|
252
|
+
throw new TypeError(`${name} must be Uint8Array, got ${typeof value}`);
|
|
253
|
+
}
|
|
254
|
+
if (value.length !== 32) {
|
|
255
|
+
throw new TypeError(`${name} must be 32 bytes, got ${value.length}`);
|
|
256
|
+
}
|
|
257
|
+
if (isZero(value)) {
|
|
258
|
+
throw new RangeError(`${name} cannot be zero`);
|
|
259
|
+
}
|
|
260
|
+
if (compare(value, EC_N) >= 0) {
|
|
261
|
+
throw new RangeError(`${name} exceeds curve order`);
|
|
262
|
+
}
|
|
263
|
+
}
|