@btc-vision/bitcoin 6.5.6 → 7.0.0-alpha.1
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 +57 -10
- 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 +12477 -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 +58 -11
- package/build/address.d.ts.map +1 -0
- package/build/address.js +82 -25
- 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 +202 -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 +35 -9
- package/build/payments/bip341.d.ts.map +1 -0
- package/build/payments/bip341.js +34 -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 -150
- 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 +428 -103
- 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 +465 -143
- 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 +117 -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 +406 -413
- 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 +101 -37
- 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 +169 -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 +68 -9
- package/scripts/bundle-ecc.ts +111 -0
- package/src/address.ts +91 -45
- package/src/bech32utils.ts +3 -3
- package/src/bip66.ts +34 -24
- package/src/block.ts +205 -86
- package/src/branded.ts +18 -0
- package/src/crypto.ts +64 -26
- package/src/ecc/context.ts +280 -0
- package/src/ecc/index.ts +14 -0
- package/src/ecc/types.ts +147 -0
- package/src/ecpair.d.ts +99 -0
- package/src/errors.ts +163 -0
- package/src/index.ts +112 -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 +32 -33
- package/src/payments/embed.ts +244 -41
- package/src/payments/index.ts +12 -10
- package/src/payments/p2ms.ts +497 -118
- package/src/payments/p2op.ts +432 -134
- package/src/payments/p2pk.ts +370 -72
- package/src/payments/p2pkh.ts +524 -130
- package/src/payments/p2sh.ts +572 -169
- package/src/payments/p2tr.ts +686 -194
- package/src/payments/p2wpkh.ts +482 -105
- package/src/payments/p2wsh.ts +524 -162
- package/src/payments/types.ts +80 -66
- package/src/psbt/bip371.ts +72 -51
- package/src/psbt/psbtutils.ts +39 -40
- package/src/psbt/types.ts +324 -0
- package/src/psbt/utils.ts +188 -0
- package/src/psbt/validation.ts +185 -0
- package/src/psbt.ts +608 -827
- package/src/pubkey.ts +22 -23
- package/src/push_data.ts +18 -16
- package/src/script.ts +81 -66
- package/src/script_number.ts +6 -6
- package/src/script_signature.ts +33 -36
- package/src/transaction.ts +462 -239
- package/src/types.ts +229 -100
- package/src/workers/WorkerSigningPool.node.ts +887 -0
- package/src/workers/WorkerSigningPool.ts +666 -0
- package/src/workers/ecc-bundle.ts +26 -0
- package/src/workers/index.ts +165 -0
- package/src/workers/psbt-parallel.ts +327 -0
- package/src/workers/signing-worker.ts +353 -0
- package/src/workers/types.ts +417 -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/typedoc.json +29 -0
- 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
|
@@ -1,1089 +0,0 @@
|
|
|
1
|
-
import { b as v, d as g, f as ie, i as L, a as D } from "./psbt-BCNk7JUx.js";
|
|
2
|
-
import { o as _, c as l, i as H, d as m, b as oe, e as fe, f as me } from "./script-DyPItFEl.js";
|
|
3
|
-
import { t as r, d as P, s as j, b as we, e as le, f as ye, i as be, T as $ } from "./utils-DNZi-T5W.js";
|
|
4
|
-
import { a as k, B as c, h as T, t as X, s as Y } from "./crypto-BhCpKpek.js";
|
|
5
|
-
var E = /* @__PURE__ */ ((e) => (e.P2PK = "p2pk", e.P2PKH = "p2pkh", e.P2SH = "p2sh", e.P2MS = "p2ms", e.P2WPKH = "p2wpkh", e.P2WSH = "p2wsh", e.P2TR = "p2tr", e.P2OP = "p2op", e.Embed = "embed", e.ScriptRedeem = "scriptRedeem", e))(E || {});
|
|
6
|
-
function p(e, o, f) {
|
|
7
|
-
Object.defineProperty(e, o, {
|
|
8
|
-
configurable: !0,
|
|
9
|
-
enumerable: !0,
|
|
10
|
-
get() {
|
|
11
|
-
const i = f.call(this);
|
|
12
|
-
return this[o] = i, i;
|
|
13
|
-
},
|
|
14
|
-
set(i) {
|
|
15
|
-
Object.defineProperty(this, o, {
|
|
16
|
-
configurable: !0,
|
|
17
|
-
enumerable: !0,
|
|
18
|
-
value: i,
|
|
19
|
-
writable: !0
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
function y(e) {
|
|
25
|
-
let o;
|
|
26
|
-
return () => (o !== void 0 || (o = e()), o);
|
|
27
|
-
}
|
|
28
|
-
const Q = _, z = 16, Z = 2, J = 40;
|
|
29
|
-
function ge(e, o) {
|
|
30
|
-
if (!e.address && !e.output && !e.program && (typeof e.deploymentVersion > "u" || !e.hash160))
|
|
31
|
-
throw new TypeError("At least one of address, output or program must be provided");
|
|
32
|
-
o = Object.assign({ validate: !0 }, o || {}), r(
|
|
33
|
-
{
|
|
34
|
-
address: r.maybe(r.String),
|
|
35
|
-
output: r.maybe(r.Buffer),
|
|
36
|
-
program: r.maybe(r.Buffer),
|
|
37
|
-
network: r.maybe(r.Object),
|
|
38
|
-
deploymentVersion: r.maybe(r.Number),
|
|
39
|
-
hash160: r.maybe(r.BufferN(20))
|
|
40
|
-
},
|
|
41
|
-
e
|
|
42
|
-
);
|
|
43
|
-
const f = () => {
|
|
44
|
-
if (typeof e.deploymentVersion < "u" && typeof e.hash160 < "u") {
|
|
45
|
-
if (e.hash160.length !== 20) throw new TypeError("hash160 must be exactly 20 bytes");
|
|
46
|
-
if (e.deploymentVersion < 0 || e.deploymentVersion > 255)
|
|
47
|
-
throw new TypeError("deploymentVersion must fit in one byte");
|
|
48
|
-
return c.concat([c.of(e.deploymentVersion), e.hash160]);
|
|
49
|
-
}
|
|
50
|
-
}, i = y(() => ie(e.address)), s = e.network || v, u = {
|
|
51
|
-
name: E.P2OP,
|
|
52
|
-
network: s,
|
|
53
|
-
deploymentVersion: 0
|
|
54
|
-
};
|
|
55
|
-
if (p(u, "program", () => {
|
|
56
|
-
if (e.program) return e.program;
|
|
57
|
-
const n = f();
|
|
58
|
-
if (n) return n;
|
|
59
|
-
if (e.output) {
|
|
60
|
-
if (e.output[0] !== Q.OP_16) throw new TypeError("Invalid P2OP script");
|
|
61
|
-
let t = 1, h;
|
|
62
|
-
if (e.output[1] < 76)
|
|
63
|
-
h = e.output[1], t = 2;
|
|
64
|
-
else if (e.output[1] === 76)
|
|
65
|
-
h = e.output[2], t = 3;
|
|
66
|
-
else
|
|
67
|
-
throw new TypeError("Unsupported push opcode in P2OP script");
|
|
68
|
-
return e.output.subarray(t, t + h);
|
|
69
|
-
}
|
|
70
|
-
if (e.address)
|
|
71
|
-
return i().data;
|
|
72
|
-
}), p(u, "deploymentVersion", () => {
|
|
73
|
-
if (u.program)
|
|
74
|
-
return u.program[0];
|
|
75
|
-
}), p(u, "hash160", () => {
|
|
76
|
-
if (u.program)
|
|
77
|
-
return u.program.subarray(1);
|
|
78
|
-
}), p(u, "output", () => {
|
|
79
|
-
if (u.program)
|
|
80
|
-
return l([Q.OP_16, u.program]);
|
|
81
|
-
}), p(u, "address", () => {
|
|
82
|
-
if (!u.program) return;
|
|
83
|
-
if (!s.bech32Opnet)
|
|
84
|
-
throw new TypeError("Network does not support opnet");
|
|
85
|
-
const n = g.bech32m.toWords(u.program);
|
|
86
|
-
return n.unshift(z), g.bech32m.encode(s.bech32Opnet, n);
|
|
87
|
-
}), o.validate) {
|
|
88
|
-
let n = k.alloc(0);
|
|
89
|
-
if (e.address) {
|
|
90
|
-
const t = i();
|
|
91
|
-
if (s.bech32Opnet !== t.prefix)
|
|
92
|
-
throw new TypeError("Invalid prefix or network mismatch");
|
|
93
|
-
if (t.version !== z)
|
|
94
|
-
throw new TypeError("Invalid witness version for p2op");
|
|
95
|
-
if (t.data.length < Z || t.data.length > J)
|
|
96
|
-
throw new TypeError("Invalid witness program length");
|
|
97
|
-
n = t.data;
|
|
98
|
-
}
|
|
99
|
-
if (e.program) {
|
|
100
|
-
if (n.length && !n.equals(e.program)) throw new TypeError("Program mismatch");
|
|
101
|
-
n = e.program;
|
|
102
|
-
}
|
|
103
|
-
if (!n.length && e.deploymentVersion !== void 0 && e.hash160 && (n = f()), e.output) {
|
|
104
|
-
const t = u.program;
|
|
105
|
-
if (n.length && !n.equals(t))
|
|
106
|
-
throw new TypeError("Program mismatch (output vs other source)");
|
|
107
|
-
n = t;
|
|
108
|
-
}
|
|
109
|
-
if (n.length < Z || n.length > J)
|
|
110
|
-
throw new TypeError(`Witness program must be 2–40 bytes. Was ${n.length} bytes`);
|
|
111
|
-
if (e.deploymentVersion !== void 0 && e.deploymentVersion !== n[0])
|
|
112
|
-
throw new TypeError("deploymentVersion mismatch");
|
|
113
|
-
if (e.hash160 && !e.hash160.equals(n.subarray(1)))
|
|
114
|
-
throw new TypeError("hash160 mismatch");
|
|
115
|
-
}
|
|
116
|
-
return Object.assign(u, e);
|
|
117
|
-
}
|
|
118
|
-
const S = _;
|
|
119
|
-
function ke(e, o) {
|
|
120
|
-
if (!e.address && !e.hash && !e.output && !e.pubkey && !e.input)
|
|
121
|
-
throw new TypeError("Not enough data");
|
|
122
|
-
o = Object.assign({ validate: !0 }, o || {}), r(
|
|
123
|
-
{
|
|
124
|
-
network: r.maybe(r.Object),
|
|
125
|
-
address: r.maybe(r.String),
|
|
126
|
-
hash: r.maybe(r.BufferN(20)),
|
|
127
|
-
output: r.maybe(r.BufferN(25)),
|
|
128
|
-
pubkey: r.maybe(P),
|
|
129
|
-
signature: r.maybe(H),
|
|
130
|
-
input: r.maybe(r.Buffer)
|
|
131
|
-
},
|
|
132
|
-
e
|
|
133
|
-
);
|
|
134
|
-
const f = y(() => {
|
|
135
|
-
const n = c.from(L.decode(e.address)), t = n.readUInt8(0), h = n.subarray(1);
|
|
136
|
-
return { version: t, hash: h };
|
|
137
|
-
}), i = y(() => m(e.input)), s = e.network || v, u = {
|
|
138
|
-
name: E.P2PKH,
|
|
139
|
-
network: s,
|
|
140
|
-
hash: void 0
|
|
141
|
-
};
|
|
142
|
-
if (p(u, "address", () => {
|
|
143
|
-
if (!u.hash) return;
|
|
144
|
-
const n = c.allocUnsafe(21);
|
|
145
|
-
return n.writeUInt8(s.pubKeyHash, 0), u.hash.copy(n, 1), L.encode(n);
|
|
146
|
-
}), p(u, "hash", () => {
|
|
147
|
-
if (e.output) return e.output.subarray(3, 23);
|
|
148
|
-
if (e.address) return f().hash;
|
|
149
|
-
if (e.pubkey || u.pubkey) return T(e.pubkey || u.pubkey);
|
|
150
|
-
}), p(u, "output", () => {
|
|
151
|
-
if (u.hash)
|
|
152
|
-
return l([
|
|
153
|
-
S.OP_DUP,
|
|
154
|
-
S.OP_HASH160,
|
|
155
|
-
u.hash,
|
|
156
|
-
S.OP_EQUALVERIFY,
|
|
157
|
-
S.OP_CHECKSIG
|
|
158
|
-
]);
|
|
159
|
-
}), p(u, "pubkey", () => {
|
|
160
|
-
if (e.input)
|
|
161
|
-
return i()[1];
|
|
162
|
-
}), p(u, "signature", () => {
|
|
163
|
-
if (e.input)
|
|
164
|
-
return i()[0];
|
|
165
|
-
}), p(u, "input", () => {
|
|
166
|
-
if (!e.pubkey || !e.signature) return;
|
|
167
|
-
let n = e.pubkey;
|
|
168
|
-
if (e.useHybrid || e.useUncompressed) {
|
|
169
|
-
const t = D(e.pubkey);
|
|
170
|
-
t && (e.useUncompressed ? n = t.uncompressed : n = t.hybrid);
|
|
171
|
-
}
|
|
172
|
-
return l([e.signature, n]);
|
|
173
|
-
}), p(u, "witness", () => {
|
|
174
|
-
if (u.input)
|
|
175
|
-
return [];
|
|
176
|
-
}), o.validate) {
|
|
177
|
-
let n = c.from([]);
|
|
178
|
-
if (e.address) {
|
|
179
|
-
if (f().version !== s.pubKeyHash)
|
|
180
|
-
throw new TypeError("Invalid version or Network mismatch");
|
|
181
|
-
if (f().hash.length !== 20)
|
|
182
|
-
throw new TypeError("Invalid address");
|
|
183
|
-
n = f().hash;
|
|
184
|
-
}
|
|
185
|
-
if (e.hash) {
|
|
186
|
-
if (n.length > 0 && !n.equals(e.hash))
|
|
187
|
-
throw new TypeError("Hash mismatch");
|
|
188
|
-
n = e.hash;
|
|
189
|
-
}
|
|
190
|
-
if (e.output) {
|
|
191
|
-
if (e.output.length !== 25 || e.output[0] !== S.OP_DUP || e.output[1] !== S.OP_HASH160 || e.output[2] !== 20 || e.output[23] !== S.OP_EQUALVERIFY || e.output[24] !== S.OP_CHECKSIG)
|
|
192
|
-
throw new TypeError("Output is invalid");
|
|
193
|
-
const t = e.output.subarray(3, 23);
|
|
194
|
-
if (n.length > 0 && !n.equals(t)) throw new TypeError("Hash mismatch");
|
|
195
|
-
n = t;
|
|
196
|
-
}
|
|
197
|
-
if (e.pubkey) {
|
|
198
|
-
const t = T(e.pubkey);
|
|
199
|
-
let h = n.length > 0 && !n.equals(t);
|
|
200
|
-
if (h && (e.pubkey.length === 33 && (e.pubkey[0] === 2 || e.pubkey[0] === 3) || e.pubkey.length === 65 && e.pubkey[0] === 4)) {
|
|
201
|
-
const d = D(e.pubkey);
|
|
202
|
-
if (d) {
|
|
203
|
-
const a = T(d.uncompressed);
|
|
204
|
-
if (n.equals(a))
|
|
205
|
-
h = !1, e.useUncompressed = !0;
|
|
206
|
-
else {
|
|
207
|
-
const w = T(d.hybrid);
|
|
208
|
-
h = !n.equals(w), h || (e.useHybrid = !0);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
if (h)
|
|
213
|
-
throw new TypeError("Hash mismatch");
|
|
214
|
-
n = t;
|
|
215
|
-
}
|
|
216
|
-
if (e.input) {
|
|
217
|
-
const t = i();
|
|
218
|
-
if (t.length !== 2) throw new TypeError("Input is invalid");
|
|
219
|
-
if (!H(t[0]))
|
|
220
|
-
throw new TypeError("Input has invalid signature");
|
|
221
|
-
if (!P(t[1])) throw new TypeError("Input has invalid pubkey");
|
|
222
|
-
if (e.signature && !e.signature.equals(t[0]))
|
|
223
|
-
throw new TypeError("Signature mismatch");
|
|
224
|
-
if (e.pubkey && !e.pubkey.equals(t[1]))
|
|
225
|
-
throw new TypeError("Pubkey mismatch");
|
|
226
|
-
const h = T(t[1]);
|
|
227
|
-
if (n.length > 0 && !n.equals(h)) throw new TypeError("Hash mismatch (input)");
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
return Object.assign(u, e);
|
|
231
|
-
}
|
|
232
|
-
const q = _;
|
|
233
|
-
function Ee(e, o) {
|
|
234
|
-
if (!e.address && !e.hash && !e.output && !e.redeem && !e.input)
|
|
235
|
-
throw new TypeError("Not enough data");
|
|
236
|
-
o = Object.assign({ validate: !0 }, o || {}), r(
|
|
237
|
-
{
|
|
238
|
-
network: r.maybe(r.Object),
|
|
239
|
-
address: r.maybe(r.String),
|
|
240
|
-
hash: r.maybe(r.BufferN(20)),
|
|
241
|
-
output: r.maybe(r.BufferN(23)),
|
|
242
|
-
redeem: r.maybe({
|
|
243
|
-
network: r.maybe(r.Object),
|
|
244
|
-
output: r.maybe(r.Buffer),
|
|
245
|
-
input: r.maybe(r.Buffer),
|
|
246
|
-
witness: r.maybe(r.arrayOf(r.Buffer))
|
|
247
|
-
}),
|
|
248
|
-
input: r.maybe(r.Buffer),
|
|
249
|
-
witness: r.maybe(r.arrayOf(r.Buffer))
|
|
250
|
-
},
|
|
251
|
-
e
|
|
252
|
-
);
|
|
253
|
-
let f = e.network;
|
|
254
|
-
f || (f = e.redeem && e.redeem.network || v);
|
|
255
|
-
const i = {
|
|
256
|
-
network: f,
|
|
257
|
-
name: E.P2SH
|
|
258
|
-
}, s = y(() => {
|
|
259
|
-
const t = c.from(L.decode(e.address)), h = t.readUInt8(0), d = t.subarray(1);
|
|
260
|
-
return { version: h, hash: d };
|
|
261
|
-
}), u = y(() => m(e.input)), n = y(() => {
|
|
262
|
-
const t = u(), h = t[t.length - 1];
|
|
263
|
-
return {
|
|
264
|
-
network: f,
|
|
265
|
-
output: h === q.OP_FALSE ? c.from([]) : h,
|
|
266
|
-
input: l(t.slice(0, -1)),
|
|
267
|
-
witness: e.witness || []
|
|
268
|
-
};
|
|
269
|
-
});
|
|
270
|
-
if (p(i, "address", () => {
|
|
271
|
-
if (!i.hash) return;
|
|
272
|
-
const t = c.allocUnsafe(21);
|
|
273
|
-
return t.writeUInt8(i.network.scriptHash, 0), i.hash.copy(t, 1), L.encode(t);
|
|
274
|
-
}), p(i, "hash", () => {
|
|
275
|
-
if (e.output) return e.output.subarray(2, 22);
|
|
276
|
-
if (e.address) return s().hash;
|
|
277
|
-
if (i.redeem && i.redeem.output) return T(i.redeem.output);
|
|
278
|
-
}), p(i, "output", () => {
|
|
279
|
-
if (i.hash)
|
|
280
|
-
return l([q.OP_HASH160, i.hash, q.OP_EQUAL]);
|
|
281
|
-
}), p(i, "redeem", () => {
|
|
282
|
-
if (e.input)
|
|
283
|
-
return n();
|
|
284
|
-
}), p(i, "input", () => {
|
|
285
|
-
if (!(!e.redeem || !e.redeem.input || !e.redeem.output))
|
|
286
|
-
return l(
|
|
287
|
-
[].concat(m(e.redeem.input), e.redeem.output)
|
|
288
|
-
);
|
|
289
|
-
}), p(i, "witness", () => {
|
|
290
|
-
if (i.redeem && i.redeem.witness) return i.redeem.witness;
|
|
291
|
-
if (i.input) return [];
|
|
292
|
-
}), p(i, "name", () => {
|
|
293
|
-
const t = ["p2sh"];
|
|
294
|
-
return i.redeem !== void 0 && i.redeem.name !== void 0 && t.push(i.redeem.name), t.join("-");
|
|
295
|
-
}), o.validate) {
|
|
296
|
-
let t = c.from([]);
|
|
297
|
-
if (e.address) {
|
|
298
|
-
if (s().version !== f.scriptHash)
|
|
299
|
-
throw new TypeError("Invalid version or Network mismatch");
|
|
300
|
-
if (s().hash.length !== 20) throw new TypeError("Invalid address");
|
|
301
|
-
t = s().hash;
|
|
302
|
-
}
|
|
303
|
-
if (e.hash) {
|
|
304
|
-
if (t.length > 0 && !t.equals(e.hash)) throw new TypeError("Hash mismatch");
|
|
305
|
-
t = e.hash;
|
|
306
|
-
}
|
|
307
|
-
if (e.output) {
|
|
308
|
-
if (e.output.length !== 23 || e.output[0] !== q.OP_HASH160 || e.output[1] !== 20 || e.output[22] !== q.OP_EQUAL)
|
|
309
|
-
throw new TypeError("Output is invalid");
|
|
310
|
-
const d = e.output.subarray(2, 22);
|
|
311
|
-
if (t.length > 0 && !t.equals(d)) throw new TypeError("Hash mismatch");
|
|
312
|
-
t = d;
|
|
313
|
-
}
|
|
314
|
-
const h = (d) => {
|
|
315
|
-
if (d.output) {
|
|
316
|
-
const a = m(d.output);
|
|
317
|
-
if (!a || a.length < 1)
|
|
318
|
-
throw new TypeError("Redeem.output too short");
|
|
319
|
-
if (d.output.byteLength > 520)
|
|
320
|
-
throw new TypeError("Redeem.output unspendable if larger than 520 bytes");
|
|
321
|
-
if (oe(a) > 201)
|
|
322
|
-
throw new TypeError(
|
|
323
|
-
"Redeem.output unspendable with more than 201 non-push ops"
|
|
324
|
-
);
|
|
325
|
-
const w = T(d.output);
|
|
326
|
-
if (t.length > 0 && !t.equals(w)) throw new TypeError("Hash mismatch");
|
|
327
|
-
t = w;
|
|
328
|
-
}
|
|
329
|
-
if (d.input) {
|
|
330
|
-
const a = d.input.length > 0, w = d.witness && d.witness.length > 0;
|
|
331
|
-
if (!a && !w) throw new TypeError("Empty input");
|
|
332
|
-
if (a && w) throw new TypeError("Input and witness provided");
|
|
333
|
-
if (a) {
|
|
334
|
-
const I = m(d.input);
|
|
335
|
-
if (!fe(I))
|
|
336
|
-
throw new TypeError("Non push-only scriptSig");
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
if (e.input) {
|
|
341
|
-
const d = u();
|
|
342
|
-
if (!d || d.length < 1) throw new TypeError("Input too short");
|
|
343
|
-
if (!c.isBuffer(n().output)) throw new TypeError("Input is invalid");
|
|
344
|
-
h(n());
|
|
345
|
-
}
|
|
346
|
-
if (e.redeem) {
|
|
347
|
-
if (e.redeem.network && e.redeem.network !== f)
|
|
348
|
-
throw new TypeError("Network mismatch");
|
|
349
|
-
if (e.input) {
|
|
350
|
-
const d = n();
|
|
351
|
-
if (e.redeem.output && !e.redeem.output.equals(d.output))
|
|
352
|
-
throw new TypeError("Redeem.output mismatch");
|
|
353
|
-
if (e.redeem.input && !e.redeem.input.equals(d.input))
|
|
354
|
-
throw new TypeError("Redeem.input mismatch");
|
|
355
|
-
}
|
|
356
|
-
h(e.redeem);
|
|
357
|
-
}
|
|
358
|
-
if (e.witness && e.redeem && e.redeem.witness && !j(e.redeem.witness, e.witness))
|
|
359
|
-
throw new TypeError("Witness and redeem.witness mismatch");
|
|
360
|
-
}
|
|
361
|
-
return Object.assign(i, e);
|
|
362
|
-
}
|
|
363
|
-
const R = {};
|
|
364
|
-
function We(e) {
|
|
365
|
-
e ? e !== R.eccLib && (Te(e), R.eccLib = e) : R.eccLib = e;
|
|
366
|
-
}
|
|
367
|
-
function pe() {
|
|
368
|
-
if (!R.eccLib)
|
|
369
|
-
throw new Error(
|
|
370
|
-
"No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance"
|
|
371
|
-
);
|
|
372
|
-
return R.eccLib;
|
|
373
|
-
}
|
|
374
|
-
const O = (e) => c.from(e, "hex");
|
|
375
|
-
function Te(e) {
|
|
376
|
-
b(typeof e.isXOnlyPoint == "function"), b(e.isXOnlyPoint(O("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))), b(e.isXOnlyPoint(O("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))), b(e.isXOnlyPoint(O("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))), b(e.isXOnlyPoint(O("0000000000000000000000000000000000000000000000000000000000000001"))), b(
|
|
377
|
-
!e.isXOnlyPoint(O("0000000000000000000000000000000000000000000000000000000000000000"))
|
|
378
|
-
), b(
|
|
379
|
-
!e.isXOnlyPoint(O("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))
|
|
380
|
-
), b(typeof e.xOnlyPointAddTweak == "function"), Pe.forEach((o) => {
|
|
381
|
-
const f = e.xOnlyPointAddTweak(O(o.pubkey), O(o.tweak));
|
|
382
|
-
o.result === null ? b(f === null) : (b(f !== null), b(f.parity === o.parity), b(c.from(f.xOnlyPubkey).equals(O(o.result))));
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
function b(e) {
|
|
386
|
-
if (!e) throw new Error("ecc library invalid");
|
|
387
|
-
}
|
|
388
|
-
const Pe = [
|
|
389
|
-
{
|
|
390
|
-
pubkey: "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
|
|
391
|
-
tweak: "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",
|
|
392
|
-
parity: -1,
|
|
393
|
-
result: null
|
|
394
|
-
},
|
|
395
|
-
{
|
|
396
|
-
pubkey: "1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b",
|
|
397
|
-
tweak: "a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac",
|
|
398
|
-
parity: 1,
|
|
399
|
-
result: "e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"
|
|
400
|
-
},
|
|
401
|
-
{
|
|
402
|
-
pubkey: "2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991",
|
|
403
|
-
tweak: "823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47",
|
|
404
|
-
parity: 0,
|
|
405
|
-
result: "9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"
|
|
406
|
-
}
|
|
407
|
-
], G = 192, Oe = 128, ve = (e) => "left" in e && "right" in e;
|
|
408
|
-
function F(e, o) {
|
|
409
|
-
if (e.length < 33)
|
|
410
|
-
throw new TypeError(
|
|
411
|
-
`The control-block length is too small. Got ${e.length}, expected min 33.`
|
|
412
|
-
);
|
|
413
|
-
const f = (e.length - 33) / 32;
|
|
414
|
-
let i = o;
|
|
415
|
-
for (let s = 0; s < f; s++) {
|
|
416
|
-
const u = e.subarray(33 + 32 * s, 65 + 32 * s);
|
|
417
|
-
i.compare(u) < 0 ? i = M(i, u) : i = M(u, i);
|
|
418
|
-
}
|
|
419
|
-
return i;
|
|
420
|
-
}
|
|
421
|
-
function W(e) {
|
|
422
|
-
if (we(e)) return { hash: B(e) };
|
|
423
|
-
const o = [W(e[0]), W(e[1])];
|
|
424
|
-
o.sort((s, u) => s.hash.compare(u.hash));
|
|
425
|
-
const [f, i] = o;
|
|
426
|
-
return {
|
|
427
|
-
hash: M(f.hash, i.hash),
|
|
428
|
-
left: f,
|
|
429
|
-
right: i
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
function x(e, o) {
|
|
433
|
-
if (ve(e)) {
|
|
434
|
-
const f = x(e.left, o);
|
|
435
|
-
if (f !== void 0) return [...f, e.right.hash];
|
|
436
|
-
const i = x(e.right, o);
|
|
437
|
-
if (i !== void 0) return [...i, e.left.hash];
|
|
438
|
-
} else if (e.hash.equals(o))
|
|
439
|
-
return [];
|
|
440
|
-
}
|
|
441
|
-
function B(e) {
|
|
442
|
-
const o = e.version || G;
|
|
443
|
-
return X(
|
|
444
|
-
"TapLeaf",
|
|
445
|
-
k.concat([k.from([o]), Se(e.output)])
|
|
446
|
-
);
|
|
447
|
-
}
|
|
448
|
-
function _e(e, o) {
|
|
449
|
-
return X("TapTweak", k.concat(o ? [e, o] : [e]));
|
|
450
|
-
}
|
|
451
|
-
function V(e, o) {
|
|
452
|
-
if (!k.isBuffer(e) || e.length !== 32 || o && o.length !== 32) return null;
|
|
453
|
-
const f = _e(e, o), i = pe().xOnlyPointAddTweak(e, f);
|
|
454
|
-
return !i || i.xOnlyPubkey === null ? null : {
|
|
455
|
-
parity: i.parity,
|
|
456
|
-
x: k.from(i.xOnlyPubkey)
|
|
457
|
-
};
|
|
458
|
-
}
|
|
459
|
-
function M(e, o) {
|
|
460
|
-
return X("TapBranch", k.concat([e, o]));
|
|
461
|
-
}
|
|
462
|
-
function Se(e) {
|
|
463
|
-
const o = le(e.length), f = k.allocUnsafe(o);
|
|
464
|
-
return ye(e.length, f), k.concat([f, e]);
|
|
465
|
-
}
|
|
466
|
-
const ee = _, re = 1, Ie = 80;
|
|
467
|
-
function He(e, o) {
|
|
468
|
-
if (!e.address && !e.output && !e.pubkey && !e.internalPubkey && !(e.witness && e.witness.length > 1))
|
|
469
|
-
throw new TypeError("Not enough data");
|
|
470
|
-
o = Object.assign({ validate: !0 }, o || {}), r(
|
|
471
|
-
{
|
|
472
|
-
address: r.maybe(r.String),
|
|
473
|
-
input: r.maybe(r.BufferN(0)),
|
|
474
|
-
network: r.maybe(r.Object),
|
|
475
|
-
output: r.maybe(r.BufferN(34)),
|
|
476
|
-
internalPubkey: r.maybe(r.BufferN(32)),
|
|
477
|
-
hash: r.maybe(r.BufferN(32)),
|
|
478
|
-
// merkle root hash, the tweak
|
|
479
|
-
pubkey: r.maybe(r.BufferN(32)),
|
|
480
|
-
// tweaked with `hash` from `internalPubkey`
|
|
481
|
-
signature: r.maybe(r.anyOf(r.BufferN(64), r.BufferN(65))),
|
|
482
|
-
witness: r.maybe(r.arrayOf(r.Buffer)),
|
|
483
|
-
scriptTree: r.maybe(be),
|
|
484
|
-
redeem: r.maybe({
|
|
485
|
-
output: r.maybe(r.Buffer),
|
|
486
|
-
// tapleaf script
|
|
487
|
-
redeemVersion: r.maybe(r.Number),
|
|
488
|
-
// tapleaf version
|
|
489
|
-
witness: r.maybe(r.arrayOf(r.Buffer))
|
|
490
|
-
}),
|
|
491
|
-
redeemVersion: r.maybe(r.Number)
|
|
492
|
-
},
|
|
493
|
-
e
|
|
494
|
-
);
|
|
495
|
-
const f = y(() => ie(e.address)), i = y(() => {
|
|
496
|
-
if (!(!e.witness || !e.witness.length))
|
|
497
|
-
return e.witness.length >= 2 && e.witness[e.witness.length - 1][0] === Ie ? e.witness.slice(0, -1) : e.witness.slice();
|
|
498
|
-
}), s = y(() => {
|
|
499
|
-
if (e.scriptTree) return W(e.scriptTree);
|
|
500
|
-
if (e.hash) return { hash: e.hash };
|
|
501
|
-
}), u = e.network || v, n = {
|
|
502
|
-
name: E.P2TR,
|
|
503
|
-
network: u
|
|
504
|
-
};
|
|
505
|
-
if (p(n, "address", () => {
|
|
506
|
-
if (!n.pubkey) return;
|
|
507
|
-
const t = g.bech32m.toWords(n.pubkey);
|
|
508
|
-
return t.unshift(re), g.bech32m.encode(u.bech32, t);
|
|
509
|
-
}), p(n, "hash", () => {
|
|
510
|
-
const t = s();
|
|
511
|
-
if (t) return t.hash;
|
|
512
|
-
const h = i();
|
|
513
|
-
if (h && h.length > 1) {
|
|
514
|
-
const d = h[h.length - 1], a = d[0] & $, w = h[h.length - 2], I = B({
|
|
515
|
-
output: w,
|
|
516
|
-
version: a
|
|
517
|
-
});
|
|
518
|
-
return F(d, I);
|
|
519
|
-
}
|
|
520
|
-
}), p(n, "output", () => {
|
|
521
|
-
if (n.pubkey)
|
|
522
|
-
return l([ee.OP_1, n.pubkey]);
|
|
523
|
-
}), p(n, "redeemVersion", () => e.redeemVersion ? e.redeemVersion : e.redeem && e.redeem.redeemVersion !== void 0 && e.redeem.redeemVersion !== null ? e.redeem.redeemVersion : G), p(n, "redeem", () => {
|
|
524
|
-
const t = i();
|
|
525
|
-
if (!(!t || t.length < 2))
|
|
526
|
-
return {
|
|
527
|
-
output: t[t.length - 2],
|
|
528
|
-
witness: t.slice(0, -2),
|
|
529
|
-
redeemVersion: t[t.length - 1][0] & $
|
|
530
|
-
};
|
|
531
|
-
}), p(n, "pubkey", () => {
|
|
532
|
-
if (e.pubkey) return e.pubkey;
|
|
533
|
-
if (e.output) return e.output.subarray(2);
|
|
534
|
-
if (e.address) return f().data;
|
|
535
|
-
if (n.internalPubkey) {
|
|
536
|
-
const t = V(n.internalPubkey, n.hash);
|
|
537
|
-
if (t) return t.x;
|
|
538
|
-
}
|
|
539
|
-
}), p(n, "internalPubkey", () => {
|
|
540
|
-
if (e.internalPubkey) return e.internalPubkey;
|
|
541
|
-
const t = i();
|
|
542
|
-
if (t && t.length > 1) return t[t.length - 1].subarray(1, 33);
|
|
543
|
-
}), p(n, "signature", () => {
|
|
544
|
-
if (e.signature) return e.signature;
|
|
545
|
-
const t = i();
|
|
546
|
-
if (!(!t || t.length !== 1))
|
|
547
|
-
return t[0];
|
|
548
|
-
}), p(n, "witness", () => {
|
|
549
|
-
if (e.witness) return e.witness;
|
|
550
|
-
const t = s();
|
|
551
|
-
if (t && e.redeem && e.redeem.output && e.internalPubkey) {
|
|
552
|
-
const h = B({
|
|
553
|
-
output: e.redeem.output,
|
|
554
|
-
version: n.redeemVersion
|
|
555
|
-
}), d = x(t, h);
|
|
556
|
-
if (!d) return;
|
|
557
|
-
const a = V(e.internalPubkey, t.hash);
|
|
558
|
-
if (!a) return;
|
|
559
|
-
const w = k.concat(
|
|
560
|
-
[k.from([n.redeemVersion | a.parity]), e.internalPubkey].concat(
|
|
561
|
-
d
|
|
562
|
-
)
|
|
563
|
-
);
|
|
564
|
-
return [e.redeem.output, w];
|
|
565
|
-
}
|
|
566
|
-
if (e.signature) return [e.signature];
|
|
567
|
-
}), o.validate) {
|
|
568
|
-
let t = k.from([]);
|
|
569
|
-
if (e.address) {
|
|
570
|
-
if (u && u.bech32 !== f().prefix)
|
|
571
|
-
throw new TypeError("Invalid prefix or Network mismatch");
|
|
572
|
-
if (f().version !== re)
|
|
573
|
-
throw new TypeError("Invalid address version");
|
|
574
|
-
if (f().data.length !== 32) throw new TypeError("Invalid address data");
|
|
575
|
-
t = f().data;
|
|
576
|
-
}
|
|
577
|
-
if (e.pubkey) {
|
|
578
|
-
if (t.length > 0 && !t.equals(e.pubkey))
|
|
579
|
-
throw new TypeError("Pubkey mismatch");
|
|
580
|
-
t = e.pubkey;
|
|
581
|
-
}
|
|
582
|
-
if (e.output) {
|
|
583
|
-
if (e.output.length !== 34 || e.output[0] !== ee.OP_1 || e.output[1] !== 32)
|
|
584
|
-
throw new TypeError("Output is invalid");
|
|
585
|
-
if (t.length > 0 && !t.equals(e.output.subarray(2)))
|
|
586
|
-
throw new TypeError("Pubkey mismatch");
|
|
587
|
-
t = e.output.subarray(2);
|
|
588
|
-
}
|
|
589
|
-
if (e.internalPubkey) {
|
|
590
|
-
const a = V(e.internalPubkey, n.hash);
|
|
591
|
-
if (t.length > 0 && !t.equals(a.x))
|
|
592
|
-
throw new TypeError("Pubkey mismatch");
|
|
593
|
-
t = a.x;
|
|
594
|
-
}
|
|
595
|
-
const h = s();
|
|
596
|
-
if (e.hash && h && !e.hash.equals(h.hash))
|
|
597
|
-
throw new TypeError("Hash mismatch");
|
|
598
|
-
if (e.redeem && e.redeem.output && h) {
|
|
599
|
-
const a = B({
|
|
600
|
-
output: e.redeem.output,
|
|
601
|
-
version: n.redeemVersion
|
|
602
|
-
});
|
|
603
|
-
if (!x(h, a))
|
|
604
|
-
throw new TypeError("Redeem script not in tree");
|
|
605
|
-
}
|
|
606
|
-
const d = i();
|
|
607
|
-
if (e.redeem && n.redeem) {
|
|
608
|
-
if (e.redeem.redeemVersion && e.redeem.redeemVersion !== n.redeem.redeemVersion)
|
|
609
|
-
throw new TypeError("Redeem.redeemVersion and witness mismatch");
|
|
610
|
-
if (e.redeem.output) {
|
|
611
|
-
if (m(e.redeem.output).length === 0)
|
|
612
|
-
throw new TypeError("Redeem.output is invalid");
|
|
613
|
-
if (n.redeem.output && !e.redeem.output.equals(n.redeem.output))
|
|
614
|
-
throw new TypeError("Redeem.output and witness mismatch");
|
|
615
|
-
}
|
|
616
|
-
if (e.redeem.witness && n.redeem.witness && !j(e.redeem.witness, n.redeem.witness))
|
|
617
|
-
throw new TypeError("Redeem.witness and witness mismatch");
|
|
618
|
-
}
|
|
619
|
-
if (d && d.length)
|
|
620
|
-
if (d.length === 1) {
|
|
621
|
-
if (e.signature && !e.signature.equals(d[0]))
|
|
622
|
-
throw new TypeError("Signature mismatch");
|
|
623
|
-
} else {
|
|
624
|
-
const a = d[d.length - 1];
|
|
625
|
-
if (a.length < 33)
|
|
626
|
-
throw new TypeError(
|
|
627
|
-
`The control-block length is too small. Got ${a.length}, expected min 33.`
|
|
628
|
-
);
|
|
629
|
-
if ((a.length - 33) % 32 !== 0)
|
|
630
|
-
throw new TypeError(
|
|
631
|
-
`The control-block length of ${a.length} is incorrect!`
|
|
632
|
-
);
|
|
633
|
-
const w = (a.length - 33) / 32;
|
|
634
|
-
if (w > 128)
|
|
635
|
-
throw new TypeError(`The script path is too long. Got ${w}, expected max 128.`);
|
|
636
|
-
const I = a.subarray(1, 33);
|
|
637
|
-
if (e.internalPubkey && !e.internalPubkey.equals(I))
|
|
638
|
-
throw new TypeError("Internal pubkey mismatch");
|
|
639
|
-
if (!pe().isXOnlyPoint(I))
|
|
640
|
-
throw new TypeError("Invalid internalPubkey for p2tr witness");
|
|
641
|
-
const he = a[0] & $, de = d[d.length - 2], ae = B({
|
|
642
|
-
output: de,
|
|
643
|
-
version: he
|
|
644
|
-
}), ce = F(a, ae), C = V(I, ce);
|
|
645
|
-
if (!C)
|
|
646
|
-
throw new TypeError("Invalid outputKey for p2tr witness");
|
|
647
|
-
if (t.length && !t.equals(C.x))
|
|
648
|
-
throw new TypeError("Pubkey mismatch for p2tr witness");
|
|
649
|
-
if (C.parity !== (a[0] & 1)) throw new Error("Incorrect parity");
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
return Object.assign(n, e);
|
|
653
|
-
}
|
|
654
|
-
const te = _, Ne = c.alloc(0);
|
|
655
|
-
function Be(e, o) {
|
|
656
|
-
if (!e.address && !e.hash && !e.output && !e.pubkey && !e.witness)
|
|
657
|
-
throw new TypeError("Not enough data");
|
|
658
|
-
o = Object.assign({ validate: !0 }, o || {}), r(
|
|
659
|
-
{
|
|
660
|
-
address: r.maybe(r.String),
|
|
661
|
-
hash: r.maybe(r.BufferN(20)),
|
|
662
|
-
input: r.maybe(r.BufferN(0)),
|
|
663
|
-
network: r.maybe(r.Object),
|
|
664
|
-
output: r.maybe(r.BufferN(22)),
|
|
665
|
-
pubkey: r.maybe(P),
|
|
666
|
-
signature: r.maybe(H),
|
|
667
|
-
witness: r.maybe(r.arrayOf(r.Buffer))
|
|
668
|
-
},
|
|
669
|
-
e
|
|
670
|
-
);
|
|
671
|
-
const f = y(() => {
|
|
672
|
-
const u = g.bech32.decode(e.address), n = u.words.shift(), t = g.bech32.fromWords(u.words);
|
|
673
|
-
return {
|
|
674
|
-
version: n,
|
|
675
|
-
prefix: u.prefix,
|
|
676
|
-
data: c.from(t)
|
|
677
|
-
};
|
|
678
|
-
}), i = e.network || v, s = {
|
|
679
|
-
name: E.P2WPKH,
|
|
680
|
-
network: i
|
|
681
|
-
};
|
|
682
|
-
if (p(s, "address", () => {
|
|
683
|
-
if (!s.hash) return;
|
|
684
|
-
const u = g.bech32.toWords(s.hash);
|
|
685
|
-
return u.unshift(0), g.bech32.encode(i.bech32, u);
|
|
686
|
-
}), p(s, "hash", () => {
|
|
687
|
-
if (e.output) return e.output.subarray(2, 22);
|
|
688
|
-
if (e.address) return f().data;
|
|
689
|
-
if (e.pubkey || s.pubkey) return T(e.pubkey || s.pubkey);
|
|
690
|
-
}), p(s, "output", () => {
|
|
691
|
-
if (s.hash)
|
|
692
|
-
return l([te.OP_0, s.hash]);
|
|
693
|
-
}), p(s, "pubkey", () => {
|
|
694
|
-
if (e.pubkey) return e.pubkey;
|
|
695
|
-
if (e.witness)
|
|
696
|
-
return e.witness[1];
|
|
697
|
-
}), p(s, "signature", () => {
|
|
698
|
-
if (e.witness)
|
|
699
|
-
return e.witness[0];
|
|
700
|
-
}), p(s, "input", () => {
|
|
701
|
-
if (s.witness)
|
|
702
|
-
return Ne;
|
|
703
|
-
}), p(s, "witness", () => {
|
|
704
|
-
if (e.pubkey && e.signature)
|
|
705
|
-
return [e.signature, e.pubkey];
|
|
706
|
-
}), o.validate) {
|
|
707
|
-
let u = c.from([]);
|
|
708
|
-
if (e.address) {
|
|
709
|
-
if (i && i.bech32 !== f().prefix)
|
|
710
|
-
throw new TypeError("Invalid prefix or Network mismatch");
|
|
711
|
-
if (f().version !== 0) throw new TypeError("Invalid address version");
|
|
712
|
-
if (f().data.length !== 20) throw new TypeError("Invalid address data");
|
|
713
|
-
u = f().data;
|
|
714
|
-
}
|
|
715
|
-
if (e.hash) {
|
|
716
|
-
if (u.length > 0 && !u.equals(e.hash)) throw new TypeError("Hash mismatch");
|
|
717
|
-
u = e.hash;
|
|
718
|
-
}
|
|
719
|
-
if (e.output) {
|
|
720
|
-
if (e.output.length !== 22 || e.output[0] !== te.OP_0 || e.output[1] !== 20)
|
|
721
|
-
throw new TypeError("Output is invalid");
|
|
722
|
-
if (u.length > 0 && !u.equals(e.output.subarray(2)))
|
|
723
|
-
throw new TypeError("Hash mismatch");
|
|
724
|
-
u = e.output.subarray(2);
|
|
725
|
-
}
|
|
726
|
-
if (e.pubkey) {
|
|
727
|
-
const n = T(e.pubkey);
|
|
728
|
-
if (u.length > 0 && !u.equals(n)) throw new TypeError("Hash mismatch");
|
|
729
|
-
if (u = n, !P(e.pubkey) || e.pubkey.length !== 33)
|
|
730
|
-
throw new TypeError("Invalid pubkey for p2wpkh");
|
|
731
|
-
}
|
|
732
|
-
if (e.witness) {
|
|
733
|
-
if (e.witness.length !== 2) throw new TypeError("Witness is invalid");
|
|
734
|
-
if (!H(e.witness[0]))
|
|
735
|
-
throw new TypeError("Witness has invalid signature");
|
|
736
|
-
if (!P(e.witness[1]) || e.witness[1].length !== 33)
|
|
737
|
-
throw new TypeError("Witness has invalid pubkey");
|
|
738
|
-
if (e.signature && !e.signature.equals(e.witness[0]))
|
|
739
|
-
throw new TypeError("Signature mismatch");
|
|
740
|
-
if (e.pubkey && !e.pubkey.equals(e.witness[1])) throw new TypeError("Pubkey mismatch");
|
|
741
|
-
const n = T(e.witness[1]);
|
|
742
|
-
if (u.length > 0 && !u.equals(n)) throw new TypeError("Hash mismatch");
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
return Object.assign(s, e);
|
|
746
|
-
}
|
|
747
|
-
const ne = _, K = c.alloc(0);
|
|
748
|
-
function A(e) {
|
|
749
|
-
return !!(c.isBuffer(e) && e.length === 65 && e[0] === 4 && P(e));
|
|
750
|
-
}
|
|
751
|
-
function je(e, o) {
|
|
752
|
-
if (!e.address && !e.hash && !e.output && !e.redeem && !e.witness)
|
|
753
|
-
throw new TypeError("Not enough data");
|
|
754
|
-
o = Object.assign({ validate: !0 }, o || {}), r(
|
|
755
|
-
{
|
|
756
|
-
network: r.maybe(r.Object),
|
|
757
|
-
address: r.maybe(r.String),
|
|
758
|
-
hash: r.maybe(r.BufferN(32)),
|
|
759
|
-
output: r.maybe(r.BufferN(34)),
|
|
760
|
-
redeem: r.maybe({
|
|
761
|
-
input: r.maybe(r.Buffer),
|
|
762
|
-
network: r.maybe(r.Object),
|
|
763
|
-
output: r.maybe(r.Buffer),
|
|
764
|
-
witness: r.maybe(r.arrayOf(r.Buffer))
|
|
765
|
-
}),
|
|
766
|
-
input: r.maybe(r.BufferN(0)),
|
|
767
|
-
witness: r.maybe(r.arrayOf(r.Buffer))
|
|
768
|
-
},
|
|
769
|
-
e
|
|
770
|
-
);
|
|
771
|
-
const f = y(() => {
|
|
772
|
-
const n = g.bech32.decode(e.address), t = n.words.shift(), h = g.bech32.fromWords(n.words);
|
|
773
|
-
return {
|
|
774
|
-
version: t,
|
|
775
|
-
prefix: n.prefix,
|
|
776
|
-
data: c.from(h)
|
|
777
|
-
};
|
|
778
|
-
}), i = y(() => m(e.redeem.input));
|
|
779
|
-
let s = e.network;
|
|
780
|
-
s || (s = e.redeem && e.redeem.network || v);
|
|
781
|
-
const u = {
|
|
782
|
-
network: s,
|
|
783
|
-
name: E.P2WSH
|
|
784
|
-
};
|
|
785
|
-
if (p(u, "address", () => {
|
|
786
|
-
if (!u.hash) return;
|
|
787
|
-
const n = g.bech32.toWords(u.hash);
|
|
788
|
-
return n.unshift(0), g.bech32.encode(s.bech32, n);
|
|
789
|
-
}), p(u, "hash", () => {
|
|
790
|
-
if (e.output) return e.output.subarray(2);
|
|
791
|
-
if (e.address) return f().data;
|
|
792
|
-
if (u.redeem && u.redeem.output) return Y(u.redeem.output);
|
|
793
|
-
}), p(u, "output", () => {
|
|
794
|
-
if (u.hash)
|
|
795
|
-
return l([ne.OP_0, u.hash]);
|
|
796
|
-
}), p(u, "redeem", () => {
|
|
797
|
-
if (e.witness)
|
|
798
|
-
return {
|
|
799
|
-
output: e.witness[e.witness.length - 1],
|
|
800
|
-
input: K,
|
|
801
|
-
witness: e.witness.slice(0, -1)
|
|
802
|
-
};
|
|
803
|
-
}), p(u, "input", () => {
|
|
804
|
-
if (u.witness)
|
|
805
|
-
return K;
|
|
806
|
-
}), p(u, "witness", () => {
|
|
807
|
-
if (e.redeem && e.redeem.input && e.redeem.input.length > 0 && e.redeem.output && e.redeem.output.length > 0) {
|
|
808
|
-
const n = me(i());
|
|
809
|
-
return u.redeem = Object.assign({ witness: n }, e.redeem), u.redeem.input = K, [].concat(n, e.redeem.output);
|
|
810
|
-
}
|
|
811
|
-
if (e.redeem && e.redeem.output && e.redeem.witness)
|
|
812
|
-
return [].concat(e.redeem.witness, e.redeem.output);
|
|
813
|
-
}), p(u, "name", () => {
|
|
814
|
-
const n = ["p2wsh"];
|
|
815
|
-
return u.redeem !== void 0 && u.redeem.name !== void 0 && n.push(u.redeem.name), n.join("-");
|
|
816
|
-
}), o.validate) {
|
|
817
|
-
let n = c.from([]);
|
|
818
|
-
if (e.address) {
|
|
819
|
-
if (f().prefix !== s.bech32)
|
|
820
|
-
throw new TypeError("Invalid prefix or Network mismatch");
|
|
821
|
-
if (f().version !== 0) throw new TypeError("Invalid address version");
|
|
822
|
-
if (f().data.length !== 32) throw new TypeError("Invalid address data");
|
|
823
|
-
n = f().data;
|
|
824
|
-
}
|
|
825
|
-
if (e.hash) {
|
|
826
|
-
if (n.length > 0 && !n.equals(e.hash)) throw new TypeError("Hash mismatch");
|
|
827
|
-
n = e.hash;
|
|
828
|
-
}
|
|
829
|
-
if (e.output) {
|
|
830
|
-
if (e.output.length !== 34 || e.output[0] !== ne.OP_0 || e.output[1] !== 32)
|
|
831
|
-
throw new TypeError("Output is invalid");
|
|
832
|
-
const t = e.output.subarray(2);
|
|
833
|
-
if (n.length > 0 && !n.equals(t)) throw new TypeError("Hash mismatch");
|
|
834
|
-
n = t;
|
|
835
|
-
}
|
|
836
|
-
if (e.redeem) {
|
|
837
|
-
if (e.redeem.network && e.redeem.network !== s)
|
|
838
|
-
throw new TypeError("Network mismatch");
|
|
839
|
-
if (e.redeem.input && e.redeem.input.length > 0 && e.redeem.witness && e.redeem.witness.length > 0)
|
|
840
|
-
throw new TypeError("Ambiguous witness source");
|
|
841
|
-
if (e.redeem.output) {
|
|
842
|
-
const t = m(e.redeem.output);
|
|
843
|
-
if (!t || t.length < 1)
|
|
844
|
-
throw new TypeError("Redeem.output is invalid");
|
|
845
|
-
if (e.redeem.output.byteLength > 3600)
|
|
846
|
-
throw new TypeError("Redeem.output unspendable if larger than 3600 bytes");
|
|
847
|
-
if (oe(t) > 201)
|
|
848
|
-
throw new TypeError(
|
|
849
|
-
"Redeem.output unspendable with more than 201 non-push ops"
|
|
850
|
-
);
|
|
851
|
-
const h = Y(e.redeem.output);
|
|
852
|
-
if (n.length > 0 && !n.equals(h)) throw new TypeError("Hash mismatch");
|
|
853
|
-
n = h;
|
|
854
|
-
}
|
|
855
|
-
if (e.redeem.input && !fe(i()))
|
|
856
|
-
throw new TypeError("Non push-only scriptSig");
|
|
857
|
-
if (e.witness && e.redeem.witness && !j(e.witness, e.redeem.witness))
|
|
858
|
-
throw new TypeError("Witness and redeem.witness mismatch");
|
|
859
|
-
if (e.redeem.input && i().some(A) || e.redeem.output && (m(e.redeem.output) || []).some(A))
|
|
860
|
-
throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey");
|
|
861
|
-
}
|
|
862
|
-
if (e.witness && e.witness.length > 0) {
|
|
863
|
-
const t = e.witness[e.witness.length - 1];
|
|
864
|
-
if (e.redeem && e.redeem.output && !e.redeem.output.equals(t))
|
|
865
|
-
throw new TypeError("Witness and redeem.output mismatch");
|
|
866
|
-
if (e.witness.some(A) || (m(t) || []).some(A))
|
|
867
|
-
throw new TypeError("Witness contains uncompressed pubkey");
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
return Object.assign(u, e);
|
|
871
|
-
}
|
|
872
|
-
const se = _;
|
|
873
|
-
function qe(e, o) {
|
|
874
|
-
if (!e.data && !e.output) throw new TypeError("Not enough data");
|
|
875
|
-
o = Object.assign({ validate: !0 }, o || {}), r(
|
|
876
|
-
{
|
|
877
|
-
network: r.maybe(r.Object),
|
|
878
|
-
output: r.maybe(r.Buffer),
|
|
879
|
-
data: r.maybe(r.arrayOf(r.Buffer))
|
|
880
|
-
},
|
|
881
|
-
e
|
|
882
|
-
);
|
|
883
|
-
const f = e.network || v, i = { name: E.Embed, network: f, data: [] };
|
|
884
|
-
if (p(i, "output", () => {
|
|
885
|
-
if (e.data)
|
|
886
|
-
return l([se.OP_RETURN].concat(e.data));
|
|
887
|
-
}), p(i, "data", () => {
|
|
888
|
-
if (!e.output) return;
|
|
889
|
-
const s = m(e.output);
|
|
890
|
-
if (s != null)
|
|
891
|
-
return s.slice(1);
|
|
892
|
-
}), o.validate && e.output) {
|
|
893
|
-
const s = m(e.output);
|
|
894
|
-
if (s[0] !== se.OP_RETURN) throw new TypeError("Output is invalid");
|
|
895
|
-
if (!s.slice(1).every(r.Buffer)) throw new TypeError("Output is invalid");
|
|
896
|
-
if (e.data && !j(e.data, i.data)) throw new TypeError("Data mismatch");
|
|
897
|
-
}
|
|
898
|
-
return Object.assign(i, e);
|
|
899
|
-
}
|
|
900
|
-
const N = _, U = N.OP_RESERVED;
|
|
901
|
-
function Ve(e, o) {
|
|
902
|
-
if (!e.input && !e.output && !(e.pubkeys && e.m !== void 0) && !e.signatures)
|
|
903
|
-
throw new TypeError("Not enough data");
|
|
904
|
-
o = Object.assign({ validate: !0 }, o || {});
|
|
905
|
-
function f(h) {
|
|
906
|
-
return H(h) || (o.allowIncomplete && h === N.OP_0) !== void 0;
|
|
907
|
-
}
|
|
908
|
-
r(
|
|
909
|
-
{
|
|
910
|
-
network: r.maybe(r.Object),
|
|
911
|
-
m: r.maybe(r.Number),
|
|
912
|
-
n: r.maybe(r.Number),
|
|
913
|
-
output: r.maybe(r.Buffer),
|
|
914
|
-
pubkeys: r.maybe(r.arrayOf(P)),
|
|
915
|
-
signatures: r.maybe(r.arrayOf(f)),
|
|
916
|
-
input: r.maybe(r.Buffer)
|
|
917
|
-
},
|
|
918
|
-
e
|
|
919
|
-
);
|
|
920
|
-
const s = {
|
|
921
|
-
network: e.network || v,
|
|
922
|
-
name: E.P2MS
|
|
923
|
-
};
|
|
924
|
-
let u = [], n = !1;
|
|
925
|
-
function t(h) {
|
|
926
|
-
n || (n = !0, u = m(h), s.m = u[0] - U, s.n = u[u.length - 2] - U, s.pubkeys = u.slice(1, -2));
|
|
927
|
-
}
|
|
928
|
-
if (p(s, "output", () => {
|
|
929
|
-
if (e.m && s.n && e.pubkeys)
|
|
930
|
-
return l(
|
|
931
|
-
[].concat(
|
|
932
|
-
U + e.m,
|
|
933
|
-
e.pubkeys,
|
|
934
|
-
U + s.n,
|
|
935
|
-
N.OP_CHECKMULTISIG
|
|
936
|
-
)
|
|
937
|
-
);
|
|
938
|
-
}), p(s, "m", () => {
|
|
939
|
-
if (s.output)
|
|
940
|
-
return t(s.output), s.m;
|
|
941
|
-
}), p(s, "n", () => {
|
|
942
|
-
if (s.pubkeys)
|
|
943
|
-
return s.pubkeys.length;
|
|
944
|
-
}), p(s, "pubkeys", () => {
|
|
945
|
-
if (e.output)
|
|
946
|
-
return t(e.output), s.pubkeys;
|
|
947
|
-
}), p(s, "signatures", () => {
|
|
948
|
-
if (!e.input) return;
|
|
949
|
-
const h = m(e.input);
|
|
950
|
-
if (h != null)
|
|
951
|
-
return h.slice(1);
|
|
952
|
-
}), p(s, "input", () => {
|
|
953
|
-
if (e.signatures)
|
|
954
|
-
return l([N.OP_0].concat(e.signatures));
|
|
955
|
-
}), p(s, "witness", () => {
|
|
956
|
-
if (s.input)
|
|
957
|
-
return [];
|
|
958
|
-
}), p(s, "name", () => {
|
|
959
|
-
if (!(!s.m || !s.n))
|
|
960
|
-
return `p2ms(${s.m} of ${s.n})`;
|
|
961
|
-
}), o.validate) {
|
|
962
|
-
if (e.output) {
|
|
963
|
-
if (t(e.output), !r.Number(u[0])) throw new TypeError("Output is invalid");
|
|
964
|
-
if (!r.Number(u[u.length - 2])) throw new TypeError("Output is invalid");
|
|
965
|
-
if (u[u.length - 1] !== N.OP_CHECKMULTISIG)
|
|
966
|
-
throw new TypeError("Output is invalid");
|
|
967
|
-
if (s.m <= 0 || s.n > 16 || s.m > s.n || s.n !== u.length - 3)
|
|
968
|
-
throw new TypeError("Output is invalid");
|
|
969
|
-
if (!s.pubkeys.every((h) => P(h))) throw new TypeError("Output is invalid");
|
|
970
|
-
if (e.m !== void 0 && e.m !== s.m) throw new TypeError("m mismatch");
|
|
971
|
-
if (e.n !== void 0 && e.n !== s.n) throw new TypeError("n mismatch");
|
|
972
|
-
if (e.pubkeys && !j(e.pubkeys, s.pubkeys))
|
|
973
|
-
throw new TypeError("Pubkeys mismatch");
|
|
974
|
-
}
|
|
975
|
-
if (e.pubkeys) {
|
|
976
|
-
if (e.n !== void 0 && e.n !== e.pubkeys.length)
|
|
977
|
-
throw new TypeError("Pubkey count mismatch");
|
|
978
|
-
if (s.n = e.pubkeys.length, s.n < s.m) throw new TypeError("Pubkey count cannot be less than m");
|
|
979
|
-
}
|
|
980
|
-
if (e.signatures) {
|
|
981
|
-
if (e.signatures.length < s.m) throw new TypeError("Not enough signatures provided");
|
|
982
|
-
if (e.signatures.length > s.m) throw new TypeError("Too many signatures provided");
|
|
983
|
-
}
|
|
984
|
-
if (e.input) {
|
|
985
|
-
if (e.input[0] !== N.OP_0) throw new TypeError("Input is invalid");
|
|
986
|
-
if (s.signatures.length === 0 || !s.signatures.every(f))
|
|
987
|
-
throw new TypeError("Input has invalid signature(s)");
|
|
988
|
-
if (e.signatures && !j(e.signatures, s.signatures))
|
|
989
|
-
throw new TypeError("Signature mismatch");
|
|
990
|
-
if (e.m !== void 0 && e.m !== e.signatures.length)
|
|
991
|
-
throw new TypeError("Signature count mismatch");
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
return Object.assign(s, e);
|
|
995
|
-
}
|
|
996
|
-
const ue = _;
|
|
997
|
-
function Re(e, o) {
|
|
998
|
-
if (!e.input && !e.output && !e.pubkey && !e.input && !e.signature)
|
|
999
|
-
throw new TypeError("Not enough data");
|
|
1000
|
-
o = Object.assign({ validate: !0 }, o || {}), r(
|
|
1001
|
-
{
|
|
1002
|
-
network: r.maybe(r.Object),
|
|
1003
|
-
output: r.maybe(r.Buffer),
|
|
1004
|
-
pubkey: r.maybe(P),
|
|
1005
|
-
signature: r.maybe(H),
|
|
1006
|
-
input: r.maybe(r.Buffer)
|
|
1007
|
-
},
|
|
1008
|
-
e
|
|
1009
|
-
);
|
|
1010
|
-
const f = y(() => m(e.input)), i = e.network || v, s = {
|
|
1011
|
-
name: E.P2PK,
|
|
1012
|
-
network: i,
|
|
1013
|
-
pubkey: void 0
|
|
1014
|
-
};
|
|
1015
|
-
if (p(s, "output", () => {
|
|
1016
|
-
if (e.pubkey)
|
|
1017
|
-
return l([e.pubkey, ue.OP_CHECKSIG]);
|
|
1018
|
-
}), p(s, "pubkey", () => {
|
|
1019
|
-
if (e.output)
|
|
1020
|
-
return e.output.subarray(1, -1);
|
|
1021
|
-
}), p(s, "signature", () => {
|
|
1022
|
-
if (e.input)
|
|
1023
|
-
return f()[0];
|
|
1024
|
-
}), p(s, "input", () => {
|
|
1025
|
-
if (e.signature)
|
|
1026
|
-
return l([e.signature]);
|
|
1027
|
-
}), p(s, "witness", () => {
|
|
1028
|
-
if (s.input)
|
|
1029
|
-
return [];
|
|
1030
|
-
}), o.validate) {
|
|
1031
|
-
if (e.output) {
|
|
1032
|
-
if (e.output[e.output.length - 1] !== ue.OP_CHECKSIG)
|
|
1033
|
-
throw new TypeError("Output is invalid");
|
|
1034
|
-
if (!P(s.pubkey)) throw new TypeError("Output pubkey is invalid");
|
|
1035
|
-
if (e.pubkey && !e.pubkey.equals(s.pubkey)) throw new TypeError("Pubkey mismatch");
|
|
1036
|
-
}
|
|
1037
|
-
if (e.signature && e.input && !e.input.equals(s.input))
|
|
1038
|
-
throw new TypeError("Signature mismatch");
|
|
1039
|
-
if (e.input) {
|
|
1040
|
-
if (f().length !== 1) throw new TypeError("Input is invalid");
|
|
1041
|
-
if (!H(s.signature))
|
|
1042
|
-
throw new TypeError("Input has invalid signature");
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
return Object.assign(s, e);
|
|
1046
|
-
}
|
|
1047
|
-
const Ce = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1048
|
-
__proto__: null,
|
|
1049
|
-
LEAF_VERSION_TAPSCRIPT: G,
|
|
1050
|
-
MAX_TAPTREE_DEPTH: Oe,
|
|
1051
|
-
PaymentType: E,
|
|
1052
|
-
findScriptPath: x,
|
|
1053
|
-
p2data: qe,
|
|
1054
|
-
p2ms: Ve,
|
|
1055
|
-
p2op: ge,
|
|
1056
|
-
p2pk: Re,
|
|
1057
|
-
p2pkh: ke,
|
|
1058
|
-
p2sh: Ee,
|
|
1059
|
-
p2tr: He,
|
|
1060
|
-
p2wpkh: Be,
|
|
1061
|
-
p2wsh: je,
|
|
1062
|
-
prop: p,
|
|
1063
|
-
rootHashFromPath: F,
|
|
1064
|
-
tapleafHash: B,
|
|
1065
|
-
toHashTree: W,
|
|
1066
|
-
tweakKey: V,
|
|
1067
|
-
value: y
|
|
1068
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
1069
|
-
export {
|
|
1070
|
-
G as L,
|
|
1071
|
-
Oe as M,
|
|
1072
|
-
E as P,
|
|
1073
|
-
Ee as a,
|
|
1074
|
-
Be as b,
|
|
1075
|
-
je as c,
|
|
1076
|
-
He as d,
|
|
1077
|
-
ge as e,
|
|
1078
|
-
Re as f,
|
|
1079
|
-
Ve as g,
|
|
1080
|
-
B as h,
|
|
1081
|
-
Ce as i,
|
|
1082
|
-
We as j,
|
|
1083
|
-
W as k,
|
|
1084
|
-
x as l,
|
|
1085
|
-
_e as m,
|
|
1086
|
-
ke as p,
|
|
1087
|
-
F as r,
|
|
1088
|
-
V as t
|
|
1089
|
-
};
|