@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,4055 +0,0 @@
|
|
|
1
|
-
import { B as l, h as et } from "./crypto-BhCpKpek.js";
|
|
2
|
-
import { p as we, a as Ee, b as Xe, c as be, d as Te, e as On, f as Pn, g as De, t as Tr, h as qe, M as Nn, L as _r, r as mr } from "./payments-B1wlSccx.js";
|
|
3
|
-
import { o as ve, t as Ir, c as vr, d as ue, i as Un, s as de, a as kr } from "./script-DyPItFEl.js";
|
|
4
|
-
import { t as Ar, a as xr, H as Cr, U as Or, i as Pr, b as Hn, c as At, r as Bn } from "./utils-DNZi-T5W.js";
|
|
5
|
-
import { T as v } from "./transaction-C_UbhMGn.js";
|
|
6
|
-
const Ve = {
|
|
7
|
-
/**
|
|
8
|
-
* The message prefix used for signing Bitcoin messages.
|
|
9
|
-
*/
|
|
10
|
-
messagePrefix: `Bitcoin Signed Message:
|
|
11
|
-
`,
|
|
12
|
-
/**
|
|
13
|
-
* The Bech32 prefix used for Bitcoin addresses.
|
|
14
|
-
*/
|
|
15
|
-
bech32: "bc",
|
|
16
|
-
bech32Opnet: "op",
|
|
17
|
-
/**
|
|
18
|
-
* The BIP32 key prefixes for Bitcoin.
|
|
19
|
-
*/
|
|
20
|
-
bip32: {
|
|
21
|
-
/**
|
|
22
|
-
* The public key prefix for BIP32 extended public keys.
|
|
23
|
-
*/
|
|
24
|
-
public: 76067358,
|
|
25
|
-
/**
|
|
26
|
-
* The private key prefix for BIP32 extended private keys.
|
|
27
|
-
*/
|
|
28
|
-
private: 76066276
|
|
29
|
-
},
|
|
30
|
-
/**
|
|
31
|
-
* The prefix for Bitcoin public key hashes.
|
|
32
|
-
*/
|
|
33
|
-
pubKeyHash: 0,
|
|
34
|
-
/**
|
|
35
|
-
* The prefix for Bitcoin script hashes.
|
|
36
|
-
*/
|
|
37
|
-
scriptHash: 5,
|
|
38
|
-
/**
|
|
39
|
-
* The prefix for Bitcoin Wallet Import Format (WIF) private keys.
|
|
40
|
-
*/
|
|
41
|
-
wif: 128
|
|
42
|
-
}, Nr = {
|
|
43
|
-
messagePrefix: `Bitcoin Signed Message:
|
|
44
|
-
`,
|
|
45
|
-
bech32: "bcrt",
|
|
46
|
-
bech32Opnet: "opr",
|
|
47
|
-
bip32: {
|
|
48
|
-
public: 70617039,
|
|
49
|
-
private: 70615956
|
|
50
|
-
},
|
|
51
|
-
pubKeyHash: 111,
|
|
52
|
-
scriptHash: 196,
|
|
53
|
-
wif: 239
|
|
54
|
-
}, Ur = {
|
|
55
|
-
messagePrefix: `Bitcoin Signed Message:
|
|
56
|
-
`,
|
|
57
|
-
bech32: "tb",
|
|
58
|
-
bech32Opnet: "opt",
|
|
59
|
-
bip32: {
|
|
60
|
-
public: 70617039,
|
|
61
|
-
private: 70615956
|
|
62
|
-
},
|
|
63
|
-
pubKeyHash: 111,
|
|
64
|
-
scriptHash: 196,
|
|
65
|
-
wif: 239
|
|
66
|
-
}, Hr = {
|
|
67
|
-
messagePrefix: `Dogecoin Signed Message:
|
|
68
|
-
`,
|
|
69
|
-
bech32: "",
|
|
70
|
-
// Dogecoin does not currently use Bech32
|
|
71
|
-
bech32Opnet: "",
|
|
72
|
-
bip32: {
|
|
73
|
-
public: 49990397,
|
|
74
|
-
private: 49988504
|
|
75
|
-
},
|
|
76
|
-
pubKeyHash: 30,
|
|
77
|
-
scriptHash: 22,
|
|
78
|
-
wif: 158
|
|
79
|
-
}, Br = {
|
|
80
|
-
messagePrefix: `Dogecoin Signed Message:
|
|
81
|
-
`,
|
|
82
|
-
bech32: "",
|
|
83
|
-
// Dogecoin testnet does not currently use Bech32
|
|
84
|
-
bech32Opnet: "",
|
|
85
|
-
bip32: {
|
|
86
|
-
public: 70429096,
|
|
87
|
-
private: 70427203
|
|
88
|
-
},
|
|
89
|
-
pubKeyHash: 113,
|
|
90
|
-
scriptHash: 196,
|
|
91
|
-
wif: 241
|
|
92
|
-
}, Rr = {
|
|
93
|
-
messagePrefix: `Litecoin Signed Message:
|
|
94
|
-
`,
|
|
95
|
-
bech32: "ltc",
|
|
96
|
-
bech32Opnet: "opl",
|
|
97
|
-
bip32: {
|
|
98
|
-
public: 27108450,
|
|
99
|
-
private: 27106558
|
|
100
|
-
},
|
|
101
|
-
pubKeyHash: 48,
|
|
102
|
-
scriptHash: 50,
|
|
103
|
-
wif: 176
|
|
104
|
-
}, Fr = {
|
|
105
|
-
messagePrefix: `Litecoin Signed Message:
|
|
106
|
-
`,
|
|
107
|
-
bech32: "tltc",
|
|
108
|
-
bech32Opnet: "oplt",
|
|
109
|
-
bip32: {
|
|
110
|
-
public: 70709117,
|
|
111
|
-
private: 70711009
|
|
112
|
-
},
|
|
113
|
-
pubKeyHash: 111,
|
|
114
|
-
scriptHash: 58,
|
|
115
|
-
wif: 239
|
|
116
|
-
}, Kr = {
|
|
117
|
-
messagePrefix: `Bitcoin Signed Message:
|
|
118
|
-
`,
|
|
119
|
-
// Cashaddr prefix differs from bech32 for general usage, but we can set it similarly.
|
|
120
|
-
// Actual cashaddr prefix is "bitcoincash", but this field is for bech32 which BCH doesn't fully use for segwit (it doesn't have segwit).
|
|
121
|
-
bech32: "bitcoincash",
|
|
122
|
-
bech32Opnet: "opbch",
|
|
123
|
-
bip32: {
|
|
124
|
-
public: 76067358,
|
|
125
|
-
private: 76066276
|
|
126
|
-
},
|
|
127
|
-
pubKeyHash: 0,
|
|
128
|
-
scriptHash: 5,
|
|
129
|
-
wif: 128
|
|
130
|
-
}, Lr = {
|
|
131
|
-
messagePrefix: `Bitcoin Signed Message:
|
|
132
|
-
`,
|
|
133
|
-
bech32: "bchtest",
|
|
134
|
-
bech32Opnet: "opbcht",
|
|
135
|
-
bip32: {
|
|
136
|
-
public: 70617039,
|
|
137
|
-
private: 70615956
|
|
138
|
-
},
|
|
139
|
-
pubKeyHash: 111,
|
|
140
|
-
scriptHash: 196,
|
|
141
|
-
wif: 239
|
|
142
|
-
}, Mr = {
|
|
143
|
-
// Historically Dash used DarkCoin message prefix, and most implementations use this:
|
|
144
|
-
// As of Dash Core 0.17, this has not changed in code.
|
|
145
|
-
messagePrefix: `DarkCoin Signed Message:
|
|
146
|
-
`,
|
|
147
|
-
bech32: "",
|
|
148
|
-
// Dash does not use Bech32
|
|
149
|
-
bech32Opnet: "",
|
|
150
|
-
bip32: {
|
|
151
|
-
public: 50221772,
|
|
152
|
-
private: 50221816
|
|
153
|
-
},
|
|
154
|
-
pubKeyHash: 76,
|
|
155
|
-
scriptHash: 16,
|
|
156
|
-
wif: 204
|
|
157
|
-
}, Wr = {
|
|
158
|
-
messagePrefix: `DarkCoin Signed Message:
|
|
159
|
-
`,
|
|
160
|
-
bech32: "",
|
|
161
|
-
// Dash testnet does not use Bech32
|
|
162
|
-
bech32Opnet: "",
|
|
163
|
-
bip32: {
|
|
164
|
-
public: 981492128,
|
|
165
|
-
private: 981489719
|
|
166
|
-
},
|
|
167
|
-
pubKeyHash: 140,
|
|
168
|
-
scriptHash: 19,
|
|
169
|
-
wif: 239
|
|
170
|
-
}, Wo = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
171
|
-
__proto__: null,
|
|
172
|
-
bitcoin: Ve,
|
|
173
|
-
bitcoinCash: Kr,
|
|
174
|
-
bitcoinCashTestnet: Lr,
|
|
175
|
-
dash: Mr,
|
|
176
|
-
dashTestnet: Wr,
|
|
177
|
-
dogecoin: Hr,
|
|
178
|
-
dogecoinTestnet: Br,
|
|
179
|
-
litecoin: Rr,
|
|
180
|
-
litecoinTestnet: Fr,
|
|
181
|
-
regtest: Nr,
|
|
182
|
-
testnet: Ur
|
|
183
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
184
|
-
var ne = {}, xt;
|
|
185
|
-
function Gr() {
|
|
186
|
-
if (xt) return ne;
|
|
187
|
-
xt = 1, Object.defineProperty(ne, "__esModule", { value: !0 }), ne.bech32m = ne.bech32 = void 0;
|
|
188
|
-
const t = "qpzry9x8gf2tvdw0s3jn54khce6mua7l", e = {};
|
|
189
|
-
for (let u = 0; u < t.length; u++) {
|
|
190
|
-
const f = t.charAt(u);
|
|
191
|
-
e[f] = u;
|
|
192
|
-
}
|
|
193
|
-
function n(u) {
|
|
194
|
-
const f = u >> 25;
|
|
195
|
-
return (u & 33554431) << 5 ^ -(f >> 0 & 1) & 996825010 ^ -(f >> 1 & 1) & 642813549 ^ -(f >> 2 & 1) & 513874426 ^ -(f >> 3 & 1) & 1027748829 ^ -(f >> 4 & 1) & 705979059;
|
|
196
|
-
}
|
|
197
|
-
function r(u) {
|
|
198
|
-
let f = 1;
|
|
199
|
-
for (let h = 0; h < u.length; ++h) {
|
|
200
|
-
const g = u.charCodeAt(h);
|
|
201
|
-
if (g < 33 || g > 126)
|
|
202
|
-
return "Invalid prefix (" + u + ")";
|
|
203
|
-
f = n(f) ^ g >> 5;
|
|
204
|
-
}
|
|
205
|
-
f = n(f);
|
|
206
|
-
for (let h = 0; h < u.length; ++h) {
|
|
207
|
-
const g = u.charCodeAt(h);
|
|
208
|
-
f = n(f) ^ g & 31;
|
|
209
|
-
}
|
|
210
|
-
return f;
|
|
211
|
-
}
|
|
212
|
-
function c(u, f, h, g) {
|
|
213
|
-
let y = 0, p = 0;
|
|
214
|
-
const d = (1 << h) - 1, E = [];
|
|
215
|
-
for (let b = 0; b < u.length; ++b)
|
|
216
|
-
for (y = y << f | u[b], p += f; p >= h; )
|
|
217
|
-
p -= h, E.push(y >> p & d);
|
|
218
|
-
if (g)
|
|
219
|
-
p > 0 && E.push(y << h - p & d);
|
|
220
|
-
else {
|
|
221
|
-
if (p >= f)
|
|
222
|
-
return "Excess padding";
|
|
223
|
-
if (y << h - p & d)
|
|
224
|
-
return "Non-zero padding";
|
|
225
|
-
}
|
|
226
|
-
return E;
|
|
227
|
-
}
|
|
228
|
-
function s(u) {
|
|
229
|
-
return c(u, 8, 5, !0);
|
|
230
|
-
}
|
|
231
|
-
function o(u) {
|
|
232
|
-
const f = c(u, 5, 8, !1);
|
|
233
|
-
if (Array.isArray(f))
|
|
234
|
-
return f;
|
|
235
|
-
}
|
|
236
|
-
function i(u) {
|
|
237
|
-
const f = c(u, 5, 8, !1);
|
|
238
|
-
if (Array.isArray(f))
|
|
239
|
-
return f;
|
|
240
|
-
throw new Error(f);
|
|
241
|
-
}
|
|
242
|
-
function a(u) {
|
|
243
|
-
let f;
|
|
244
|
-
u === "bech32" ? f = 1 : f = 734539939;
|
|
245
|
-
function h(d, E, b) {
|
|
246
|
-
if (b = b || 90, d.length + 7 + E.length > b)
|
|
247
|
-
throw new TypeError("Exceeds length limit");
|
|
248
|
-
d = d.toLowerCase();
|
|
249
|
-
let S = r(d);
|
|
250
|
-
if (typeof S == "string")
|
|
251
|
-
throw new Error(S);
|
|
252
|
-
let w = d + "1";
|
|
253
|
-
for (let _ = 0; _ < E.length; ++_) {
|
|
254
|
-
const I = E[_];
|
|
255
|
-
if (I >> 5 !== 0)
|
|
256
|
-
throw new Error("Non 5-bit word");
|
|
257
|
-
S = n(S) ^ I, w += t.charAt(I);
|
|
258
|
-
}
|
|
259
|
-
for (let _ = 0; _ < 6; ++_)
|
|
260
|
-
S = n(S);
|
|
261
|
-
S ^= f;
|
|
262
|
-
for (let _ = 0; _ < 6; ++_) {
|
|
263
|
-
const I = S >> (5 - _) * 5 & 31;
|
|
264
|
-
w += t.charAt(I);
|
|
265
|
-
}
|
|
266
|
-
return w;
|
|
267
|
-
}
|
|
268
|
-
function g(d, E) {
|
|
269
|
-
if (E = E || 90, d.length < 8)
|
|
270
|
-
return d + " too short";
|
|
271
|
-
if (d.length > E)
|
|
272
|
-
return "Exceeds length limit";
|
|
273
|
-
const b = d.toLowerCase(), S = d.toUpperCase();
|
|
274
|
-
if (d !== b && d !== S)
|
|
275
|
-
return "Mixed-case string " + d;
|
|
276
|
-
d = b;
|
|
277
|
-
const w = d.lastIndexOf("1");
|
|
278
|
-
if (w === -1)
|
|
279
|
-
return "No separator character for " + d;
|
|
280
|
-
if (w === 0)
|
|
281
|
-
return "Missing prefix for " + d;
|
|
282
|
-
const _ = d.slice(0, w), I = d.slice(w + 1);
|
|
283
|
-
if (I.length < 6)
|
|
284
|
-
return "Data too short";
|
|
285
|
-
let P = r(_);
|
|
286
|
-
if (typeof P == "string")
|
|
287
|
-
return P;
|
|
288
|
-
const m = [];
|
|
289
|
-
for (let k = 0; k < I.length; ++k) {
|
|
290
|
-
const U = I.charAt(k), B = e[U];
|
|
291
|
-
if (B === void 0)
|
|
292
|
-
return "Unknown character " + U;
|
|
293
|
-
P = n(P) ^ B, !(k + 6 >= I.length) && m.push(B);
|
|
294
|
-
}
|
|
295
|
-
return P !== f ? "Invalid checksum for " + d : { prefix: _, words: m };
|
|
296
|
-
}
|
|
297
|
-
function y(d, E) {
|
|
298
|
-
const b = g(d, E);
|
|
299
|
-
if (typeof b == "object")
|
|
300
|
-
return b;
|
|
301
|
-
}
|
|
302
|
-
function p(d, E) {
|
|
303
|
-
const b = g(d, E);
|
|
304
|
-
if (typeof b == "object")
|
|
305
|
-
return b;
|
|
306
|
-
throw new Error(b);
|
|
307
|
-
}
|
|
308
|
-
return {
|
|
309
|
-
decodeUnsafe: y,
|
|
310
|
-
decode: p,
|
|
311
|
-
encode: h,
|
|
312
|
-
toWords: s,
|
|
313
|
-
fromWordsUnsafe: o,
|
|
314
|
-
fromWords: i
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
return ne.bech32 = a("bech32"), ne.bech32m = a("bech32m"), ne;
|
|
318
|
-
}
|
|
319
|
-
var K = Gr();
|
|
320
|
-
function Xr(t) {
|
|
321
|
-
return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
|
|
322
|
-
}
|
|
323
|
-
function bt(t, ...e) {
|
|
324
|
-
if (!Xr(t))
|
|
325
|
-
throw new Error("Uint8Array expected");
|
|
326
|
-
if (e.length > 0 && !e.includes(t.length))
|
|
327
|
-
throw new Error("Uint8Array expected of length " + e + ", got length=" + t.length);
|
|
328
|
-
}
|
|
329
|
-
function Ct(t, e = !0) {
|
|
330
|
-
if (t.destroyed)
|
|
331
|
-
throw new Error("Hash instance has been destroyed");
|
|
332
|
-
if (e && t.finished)
|
|
333
|
-
throw new Error("Hash#digest() has already been called");
|
|
334
|
-
}
|
|
335
|
-
function Dr(t, e) {
|
|
336
|
-
bt(t);
|
|
337
|
-
const n = e.outputLen;
|
|
338
|
-
if (t.length < n)
|
|
339
|
-
throw new Error("digestInto() expects output buffer of length at least " + n);
|
|
340
|
-
}
|
|
341
|
-
function ft(...t) {
|
|
342
|
-
for (let e = 0; e < t.length; e++)
|
|
343
|
-
t[e].fill(0);
|
|
344
|
-
}
|
|
345
|
-
function tt(t) {
|
|
346
|
-
return new DataView(t.buffer, t.byteOffset, t.byteLength);
|
|
347
|
-
}
|
|
348
|
-
function H(t, e) {
|
|
349
|
-
return t << 32 - e | t >>> e;
|
|
350
|
-
}
|
|
351
|
-
function qr(t) {
|
|
352
|
-
if (typeof t != "string")
|
|
353
|
-
throw new Error("string expected");
|
|
354
|
-
return new Uint8Array(new TextEncoder().encode(t));
|
|
355
|
-
}
|
|
356
|
-
function Rn(t) {
|
|
357
|
-
return typeof t == "string" && (t = qr(t)), bt(t), t;
|
|
358
|
-
}
|
|
359
|
-
class Vr {
|
|
360
|
-
}
|
|
361
|
-
function jr(t) {
|
|
362
|
-
const e = (r) => t().update(Rn(r)).digest(), n = t();
|
|
363
|
-
return e.outputLen = n.outputLen, e.blockLen = n.blockLen, e.create = () => t(), e;
|
|
364
|
-
}
|
|
365
|
-
function zr(t, e, n, r) {
|
|
366
|
-
if (typeof t.setBigUint64 == "function")
|
|
367
|
-
return t.setBigUint64(e, n, r);
|
|
368
|
-
const c = BigInt(32), s = BigInt(4294967295), o = Number(n >> c & s), i = Number(n & s), a = r ? 4 : 0, u = r ? 0 : 4;
|
|
369
|
-
t.setUint32(e + a, o, r), t.setUint32(e + u, i, r);
|
|
370
|
-
}
|
|
371
|
-
function Yr(t, e, n) {
|
|
372
|
-
return t & e ^ ~t & n;
|
|
373
|
-
}
|
|
374
|
-
function $r(t, e, n) {
|
|
375
|
-
return t & e ^ t & n ^ e & n;
|
|
376
|
-
}
|
|
377
|
-
class Zr extends Vr {
|
|
378
|
-
constructor(e, n, r, c) {
|
|
379
|
-
super(), this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.blockLen = e, this.outputLen = n, this.padOffset = r, this.isLE = c, this.buffer = new Uint8Array(e), this.view = tt(this.buffer);
|
|
380
|
-
}
|
|
381
|
-
update(e) {
|
|
382
|
-
Ct(this), e = Rn(e), bt(e);
|
|
383
|
-
const { view: n, buffer: r, blockLen: c } = this, s = e.length;
|
|
384
|
-
for (let o = 0; o < s; ) {
|
|
385
|
-
const i = Math.min(c - this.pos, s - o);
|
|
386
|
-
if (i === c) {
|
|
387
|
-
const a = tt(e);
|
|
388
|
-
for (; c <= s - o; o += c)
|
|
389
|
-
this.process(a, o);
|
|
390
|
-
continue;
|
|
391
|
-
}
|
|
392
|
-
r.set(e.subarray(o, o + i), this.pos), this.pos += i, o += i, this.pos === c && (this.process(n, 0), this.pos = 0);
|
|
393
|
-
}
|
|
394
|
-
return this.length += e.length, this.roundClean(), this;
|
|
395
|
-
}
|
|
396
|
-
digestInto(e) {
|
|
397
|
-
Ct(this), Dr(e, this), this.finished = !0;
|
|
398
|
-
const { buffer: n, view: r, blockLen: c, isLE: s } = this;
|
|
399
|
-
let { pos: o } = this;
|
|
400
|
-
n[o++] = 128, ft(this.buffer.subarray(o)), this.padOffset > c - o && (this.process(r, 0), o = 0);
|
|
401
|
-
for (let h = o; h < c; h++)
|
|
402
|
-
n[h] = 0;
|
|
403
|
-
zr(r, c - 8, BigInt(this.length * 8), s), this.process(r, 0);
|
|
404
|
-
const i = tt(e), a = this.outputLen;
|
|
405
|
-
if (a % 4)
|
|
406
|
-
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
407
|
-
const u = a / 4, f = this.get();
|
|
408
|
-
if (u > f.length)
|
|
409
|
-
throw new Error("_sha2: outputLen bigger than state");
|
|
410
|
-
for (let h = 0; h < u; h++)
|
|
411
|
-
i.setUint32(4 * h, f[h], s);
|
|
412
|
-
}
|
|
413
|
-
digest() {
|
|
414
|
-
const { buffer: e, outputLen: n } = this;
|
|
415
|
-
this.digestInto(e);
|
|
416
|
-
const r = e.slice(0, n);
|
|
417
|
-
return this.destroy(), r;
|
|
418
|
-
}
|
|
419
|
-
_cloneInto(e) {
|
|
420
|
-
e || (e = new this.constructor()), e.set(...this.get());
|
|
421
|
-
const { blockLen: n, buffer: r, length: c, finished: s, destroyed: o, pos: i } = this;
|
|
422
|
-
return e.destroyed = o, e.finished = s, e.length = c, e.pos = i, c % n && e.buffer.set(r), e;
|
|
423
|
-
}
|
|
424
|
-
clone() {
|
|
425
|
-
return this._cloneInto();
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
const L = /* @__PURE__ */ Uint32Array.from([
|
|
429
|
-
1779033703,
|
|
430
|
-
3144134277,
|
|
431
|
-
1013904242,
|
|
432
|
-
2773480762,
|
|
433
|
-
1359893119,
|
|
434
|
-
2600822924,
|
|
435
|
-
528734635,
|
|
436
|
-
1541459225
|
|
437
|
-
]), Jr = /* @__PURE__ */ Uint32Array.from([
|
|
438
|
-
1116352408,
|
|
439
|
-
1899447441,
|
|
440
|
-
3049323471,
|
|
441
|
-
3921009573,
|
|
442
|
-
961987163,
|
|
443
|
-
1508970993,
|
|
444
|
-
2453635748,
|
|
445
|
-
2870763221,
|
|
446
|
-
3624381080,
|
|
447
|
-
310598401,
|
|
448
|
-
607225278,
|
|
449
|
-
1426881987,
|
|
450
|
-
1925078388,
|
|
451
|
-
2162078206,
|
|
452
|
-
2614888103,
|
|
453
|
-
3248222580,
|
|
454
|
-
3835390401,
|
|
455
|
-
4022224774,
|
|
456
|
-
264347078,
|
|
457
|
-
604807628,
|
|
458
|
-
770255983,
|
|
459
|
-
1249150122,
|
|
460
|
-
1555081692,
|
|
461
|
-
1996064986,
|
|
462
|
-
2554220882,
|
|
463
|
-
2821834349,
|
|
464
|
-
2952996808,
|
|
465
|
-
3210313671,
|
|
466
|
-
3336571891,
|
|
467
|
-
3584528711,
|
|
468
|
-
113926993,
|
|
469
|
-
338241895,
|
|
470
|
-
666307205,
|
|
471
|
-
773529912,
|
|
472
|
-
1294757372,
|
|
473
|
-
1396182291,
|
|
474
|
-
1695183700,
|
|
475
|
-
1986661051,
|
|
476
|
-
2177026350,
|
|
477
|
-
2456956037,
|
|
478
|
-
2730485921,
|
|
479
|
-
2820302411,
|
|
480
|
-
3259730800,
|
|
481
|
-
3345764771,
|
|
482
|
-
3516065817,
|
|
483
|
-
3600352804,
|
|
484
|
-
4094571909,
|
|
485
|
-
275423344,
|
|
486
|
-
430227734,
|
|
487
|
-
506948616,
|
|
488
|
-
659060556,
|
|
489
|
-
883997877,
|
|
490
|
-
958139571,
|
|
491
|
-
1322822218,
|
|
492
|
-
1537002063,
|
|
493
|
-
1747873779,
|
|
494
|
-
1955562222,
|
|
495
|
-
2024104815,
|
|
496
|
-
2227730452,
|
|
497
|
-
2361852424,
|
|
498
|
-
2428436474,
|
|
499
|
-
2756734187,
|
|
500
|
-
3204031479,
|
|
501
|
-
3329325298
|
|
502
|
-
]), M = /* @__PURE__ */ new Uint32Array(64);
|
|
503
|
-
class Qr extends Zr {
|
|
504
|
-
constructor(e = 32) {
|
|
505
|
-
super(64, e, 8, !1), this.A = L[0] | 0, this.B = L[1] | 0, this.C = L[2] | 0, this.D = L[3] | 0, this.E = L[4] | 0, this.F = L[5] | 0, this.G = L[6] | 0, this.H = L[7] | 0;
|
|
506
|
-
}
|
|
507
|
-
get() {
|
|
508
|
-
const { A: e, B: n, C: r, D: c, E: s, F: o, G: i, H: a } = this;
|
|
509
|
-
return [e, n, r, c, s, o, i, a];
|
|
510
|
-
}
|
|
511
|
-
// prettier-ignore
|
|
512
|
-
set(e, n, r, c, s, o, i, a) {
|
|
513
|
-
this.A = e | 0, this.B = n | 0, this.C = r | 0, this.D = c | 0, this.E = s | 0, this.F = o | 0, this.G = i | 0, this.H = a | 0;
|
|
514
|
-
}
|
|
515
|
-
process(e, n) {
|
|
516
|
-
for (let h = 0; h < 16; h++, n += 4)
|
|
517
|
-
M[h] = e.getUint32(n, !1);
|
|
518
|
-
for (let h = 16; h < 64; h++) {
|
|
519
|
-
const g = M[h - 15], y = M[h - 2], p = H(g, 7) ^ H(g, 18) ^ g >>> 3, d = H(y, 17) ^ H(y, 19) ^ y >>> 10;
|
|
520
|
-
M[h] = d + M[h - 7] + p + M[h - 16] | 0;
|
|
521
|
-
}
|
|
522
|
-
let { A: r, B: c, C: s, D: o, E: i, F: a, G: u, H: f } = this;
|
|
523
|
-
for (let h = 0; h < 64; h++) {
|
|
524
|
-
const g = H(i, 6) ^ H(i, 11) ^ H(i, 25), y = f + g + Yr(i, a, u) + Jr[h] + M[h] | 0, d = (H(r, 2) ^ H(r, 13) ^ H(r, 22)) + $r(r, c, s) | 0;
|
|
525
|
-
f = u, u = a, a = i, i = o + y | 0, o = s, s = c, c = r, r = y + d | 0;
|
|
526
|
-
}
|
|
527
|
-
r = r + this.A | 0, c = c + this.B | 0, s = s + this.C | 0, o = o + this.D | 0, i = i + this.E | 0, a = a + this.F | 0, u = u + this.G | 0, f = f + this.H | 0, this.set(r, c, s, o, i, a, u, f);
|
|
528
|
-
}
|
|
529
|
-
roundClean() {
|
|
530
|
-
ft(M);
|
|
531
|
-
}
|
|
532
|
-
destroy() {
|
|
533
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0), ft(this.buffer);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
const es = /* @__PURE__ */ jr(() => new Qr()), Ot = es;
|
|
537
|
-
function ts(t) {
|
|
538
|
-
if (t.length >= 255)
|
|
539
|
-
throw new TypeError("Alphabet too long");
|
|
540
|
-
const e = new Uint8Array(256);
|
|
541
|
-
for (let u = 0; u < e.length; u++)
|
|
542
|
-
e[u] = 255;
|
|
543
|
-
for (let u = 0; u < t.length; u++) {
|
|
544
|
-
const f = t.charAt(u), h = f.charCodeAt(0);
|
|
545
|
-
if (e[h] !== 255)
|
|
546
|
-
throw new TypeError(f + " is ambiguous");
|
|
547
|
-
e[h] = u;
|
|
548
|
-
}
|
|
549
|
-
const n = t.length, r = t.charAt(0), c = Math.log(n) / Math.log(256), s = Math.log(256) / Math.log(n);
|
|
550
|
-
function o(u) {
|
|
551
|
-
if (u instanceof Uint8Array || (ArrayBuffer.isView(u) ? u = new Uint8Array(u.buffer, u.byteOffset, u.byteLength) : Array.isArray(u) && (u = Uint8Array.from(u))), !(u instanceof Uint8Array))
|
|
552
|
-
throw new TypeError("Expected Uint8Array");
|
|
553
|
-
if (u.length === 0)
|
|
554
|
-
return "";
|
|
555
|
-
let f = 0, h = 0, g = 0;
|
|
556
|
-
const y = u.length;
|
|
557
|
-
for (; g !== y && u[g] === 0; )
|
|
558
|
-
g++, f++;
|
|
559
|
-
const p = (y - g) * s + 1 >>> 0, d = new Uint8Array(p);
|
|
560
|
-
for (; g !== y; ) {
|
|
561
|
-
let S = u[g], w = 0;
|
|
562
|
-
for (let _ = p - 1; (S !== 0 || w < h) && _ !== -1; _--, w++)
|
|
563
|
-
S += 256 * d[_] >>> 0, d[_] = S % n >>> 0, S = S / n >>> 0;
|
|
564
|
-
if (S !== 0)
|
|
565
|
-
throw new Error("Non-zero carry");
|
|
566
|
-
h = w, g++;
|
|
567
|
-
}
|
|
568
|
-
let E = p - h;
|
|
569
|
-
for (; E !== p && d[E] === 0; )
|
|
570
|
-
E++;
|
|
571
|
-
let b = r.repeat(f);
|
|
572
|
-
for (; E < p; ++E)
|
|
573
|
-
b += t.charAt(d[E]);
|
|
574
|
-
return b;
|
|
575
|
-
}
|
|
576
|
-
function i(u) {
|
|
577
|
-
if (typeof u != "string")
|
|
578
|
-
throw new TypeError("Expected String");
|
|
579
|
-
if (u.length === 0)
|
|
580
|
-
return new Uint8Array();
|
|
581
|
-
let f = 0, h = 0, g = 0;
|
|
582
|
-
for (; u[f] === r; )
|
|
583
|
-
h++, f++;
|
|
584
|
-
const y = (u.length - f) * c + 1 >>> 0, p = new Uint8Array(y);
|
|
585
|
-
for (; f < u.length; ) {
|
|
586
|
-
const S = u.charCodeAt(f);
|
|
587
|
-
if (S > 255)
|
|
588
|
-
return;
|
|
589
|
-
let w = e[S];
|
|
590
|
-
if (w === 255)
|
|
591
|
-
return;
|
|
592
|
-
let _ = 0;
|
|
593
|
-
for (let I = y - 1; (w !== 0 || _ < g) && I !== -1; I--, _++)
|
|
594
|
-
w += n * p[I] >>> 0, p[I] = w % 256 >>> 0, w = w / 256 >>> 0;
|
|
595
|
-
if (w !== 0)
|
|
596
|
-
throw new Error("Non-zero carry");
|
|
597
|
-
g = _, f++;
|
|
598
|
-
}
|
|
599
|
-
let d = y - g;
|
|
600
|
-
for (; d !== y && p[d] === 0; )
|
|
601
|
-
d++;
|
|
602
|
-
const E = new Uint8Array(h + (y - d));
|
|
603
|
-
let b = h;
|
|
604
|
-
for (; d !== y; )
|
|
605
|
-
E[b++] = p[d++];
|
|
606
|
-
return E;
|
|
607
|
-
}
|
|
608
|
-
function a(u) {
|
|
609
|
-
const f = i(u);
|
|
610
|
-
if (f)
|
|
611
|
-
return f;
|
|
612
|
-
throw new Error("Non-base" + n + " character");
|
|
613
|
-
}
|
|
614
|
-
return {
|
|
615
|
-
encode: o,
|
|
616
|
-
decodeUnsafe: i,
|
|
617
|
-
decode: a
|
|
618
|
-
};
|
|
619
|
-
}
|
|
620
|
-
var ns = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
621
|
-
const nt = ts(ns);
|
|
622
|
-
function rs(t) {
|
|
623
|
-
function e(s) {
|
|
624
|
-
var o = Uint8Array.from(s), i = t(o), a = o.length + 4, u = new Uint8Array(a);
|
|
625
|
-
return u.set(o, 0), u.set(i.subarray(0, 4), o.length), nt.encode(u);
|
|
626
|
-
}
|
|
627
|
-
function n(s) {
|
|
628
|
-
var o = s.slice(0, -4), i = s.slice(-4), a = t(o);
|
|
629
|
-
if (!(i[0] ^ a[0] | i[1] ^ a[1] | i[2] ^ a[2] | i[3] ^ a[3]))
|
|
630
|
-
return o;
|
|
631
|
-
}
|
|
632
|
-
function r(s) {
|
|
633
|
-
var o = nt.decodeUnsafe(s);
|
|
634
|
-
if (o != null)
|
|
635
|
-
return n(o);
|
|
636
|
-
}
|
|
637
|
-
function c(s) {
|
|
638
|
-
var o = nt.decode(s), i = n(o);
|
|
639
|
-
if (i == null)
|
|
640
|
-
throw new Error("Invalid checksum");
|
|
641
|
-
return i;
|
|
642
|
-
}
|
|
643
|
-
return {
|
|
644
|
-
encode: e,
|
|
645
|
-
decode: c,
|
|
646
|
-
decodeUnsafe: r
|
|
647
|
-
};
|
|
648
|
-
}
|
|
649
|
-
function ss(t) {
|
|
650
|
-
return Ot(Ot(t));
|
|
651
|
-
}
|
|
652
|
-
const Fn = rs(ss);
|
|
653
|
-
function Kn(t) {
|
|
654
|
-
let e, n;
|
|
655
|
-
try {
|
|
656
|
-
e = K.bech32.decode(t);
|
|
657
|
-
} catch {
|
|
658
|
-
}
|
|
659
|
-
if (e) {
|
|
660
|
-
if (n = e.words[0], n !== 0) throw new TypeError(t + " uses wrong encoding");
|
|
661
|
-
} else if (e = K.bech32m.decode(t), n = e.words[0], n === 0) throw new TypeError(t + " uses wrong encoding");
|
|
662
|
-
const r = K.bech32.fromWords(e.words.slice(1));
|
|
663
|
-
return {
|
|
664
|
-
version: n,
|
|
665
|
-
prefix: e.prefix,
|
|
666
|
-
data: l.from(r)
|
|
667
|
-
};
|
|
668
|
-
}
|
|
669
|
-
const Ln = {
|
|
670
|
-
p: 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,
|
|
671
|
-
n: 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,
|
|
672
|
-
h: 1n,
|
|
673
|
-
a: 0n,
|
|
674
|
-
b: 7n,
|
|
675
|
-
Gx: 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,
|
|
676
|
-
Gy: 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n
|
|
677
|
-
}, { p: se, n: os, Gx: is, Gy: cs, b: Mn } = Ln, ht = 32, Tt = 64, as = {
|
|
678
|
-
publicKey: ht + 1,
|
|
679
|
-
publicKeyUncompressed: Tt + 1
|
|
680
|
-
}, us = (...t) => {
|
|
681
|
-
"captureStackTrace" in Error && typeof Error.captureStackTrace == "function" && Error.captureStackTrace(...t);
|
|
682
|
-
}, C = (t = "") => {
|
|
683
|
-
const e = new Error(t);
|
|
684
|
-
throw us(e, C), e;
|
|
685
|
-
}, fs = (t) => typeof t == "bigint", hs = (t) => typeof t == "string", ps = (t) => t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array", _t = (t, e, n = "") => {
|
|
686
|
-
const r = ps(t), c = t?.length, s = e !== void 0;
|
|
687
|
-
if (!r || s && c !== e) {
|
|
688
|
-
const o = n && `"${n}" `, i = s ? ` of length ${e}` : "", a = r ? `length=${c}` : `type=${typeof t}`;
|
|
689
|
-
C(o + "expected Uint8Array" + i + ", got " + a);
|
|
690
|
-
}
|
|
691
|
-
return t;
|
|
692
|
-
}, Wn = (t) => new Uint8Array(t), Gn = (t, e) => t.toString(16).padStart(e, "0"), Xn = (t) => Array.from(_t(t)).map((e) => Gn(e, 2)).join(""), R = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 }, Pt = (t) => {
|
|
693
|
-
if (t >= R._0 && t <= R._9)
|
|
694
|
-
return t - R._0;
|
|
695
|
-
if (t >= R.A && t <= R.F)
|
|
696
|
-
return t - (R.A - 10);
|
|
697
|
-
if (t >= R.a && t <= R.f)
|
|
698
|
-
return t - (R.a - 10);
|
|
699
|
-
}, Dn = (t) => {
|
|
700
|
-
const e = "hex invalid";
|
|
701
|
-
if (!hs(t))
|
|
702
|
-
return C(e);
|
|
703
|
-
const n = t.length, r = n / 2;
|
|
704
|
-
if (n % 2)
|
|
705
|
-
return C(e);
|
|
706
|
-
const c = Wn(r);
|
|
707
|
-
for (let s = 0, o = 0; s < r; s++, o += 2) {
|
|
708
|
-
const i = Pt(t.charCodeAt(o)), a = Pt(t.charCodeAt(o + 1));
|
|
709
|
-
if (i === void 0 || a === void 0)
|
|
710
|
-
return C(e);
|
|
711
|
-
c[s] = i * 16 + a;
|
|
712
|
-
}
|
|
713
|
-
return c;
|
|
714
|
-
}, Nt = (...t) => {
|
|
715
|
-
const e = Wn(t.reduce((r, c) => r + _t(c).length, 0));
|
|
716
|
-
let n = 0;
|
|
717
|
-
return t.forEach((r) => {
|
|
718
|
-
e.set(r, n), n += r.length;
|
|
719
|
-
}), e;
|
|
720
|
-
}, Le = BigInt, je = (t, e, n, r = "bad number: out of range") => fs(t) && e <= t && t < n ? t : C(r), T = (t, e = se) => {
|
|
721
|
-
const n = t % e;
|
|
722
|
-
return n >= 0n ? n : e + n;
|
|
723
|
-
}, ls = (t, e) => {
|
|
724
|
-
(t === 0n || e <= 0n) && C("no inverse n=" + t + " mod=" + e);
|
|
725
|
-
let n = T(t, e), r = e, c = 0n, s = 1n;
|
|
726
|
-
for (; n !== 0n; ) {
|
|
727
|
-
const o = r / n, i = r % n, a = c - s * o;
|
|
728
|
-
r = n, n = i, c = s, s = a;
|
|
729
|
-
}
|
|
730
|
-
return r === 1n ? T(c, e) : C("no inverse");
|
|
731
|
-
}, rt = (t) => t instanceof O ? t : C("Point expected"), qn = (t) => T(T(t * t) * t + Mn), Ut = (t) => je(t, 0n, se), Ke = (t) => je(t, 1n, se), ds = (t) => je(t, 1n, os), pt = (t) => (t & 1n) === 0n, Vn = (t) => Uint8Array.of(t), gs = (t) => Vn(pt(t) ? 2 : 3), ys = (t) => {
|
|
732
|
-
const e = qn(Ke(t));
|
|
733
|
-
let n = 1n;
|
|
734
|
-
for (let r = e, c = (se + 1n) / 4n; c > 0n; c >>= 1n)
|
|
735
|
-
c & 1n && (n = n * r % se), r = r * r % se;
|
|
736
|
-
return T(n * n) === e ? n : C("sqrt invalid");
|
|
737
|
-
};
|
|
738
|
-
class O {
|
|
739
|
-
static BASE;
|
|
740
|
-
static ZERO;
|
|
741
|
-
X;
|
|
742
|
-
Y;
|
|
743
|
-
Z;
|
|
744
|
-
constructor(e, n, r) {
|
|
745
|
-
this.X = Ut(e), this.Y = Ke(n), this.Z = Ut(r), Object.freeze(this);
|
|
746
|
-
}
|
|
747
|
-
static CURVE() {
|
|
748
|
-
return Ln;
|
|
749
|
-
}
|
|
750
|
-
/** Create 3d xyz point from 2d xy. (0, 0) => (0, 1, 0), not (0, 0, 1) */
|
|
751
|
-
static fromAffine(e) {
|
|
752
|
-
const { x: n, y: r } = e;
|
|
753
|
-
return n === 0n && r === 0n ? re : new O(n, r, 1n);
|
|
754
|
-
}
|
|
755
|
-
/** Convert Uint8Array or hex string to Point. */
|
|
756
|
-
static fromBytes(e) {
|
|
757
|
-
_t(e);
|
|
758
|
-
const { publicKey: n, publicKeyUncompressed: r } = as;
|
|
759
|
-
let c;
|
|
760
|
-
const s = e.length, o = e[0], i = e.subarray(1), a = Ht(i, 0, ht);
|
|
761
|
-
if (s === n && (o === 2 || o === 3)) {
|
|
762
|
-
let u = ys(a);
|
|
763
|
-
const f = pt(u);
|
|
764
|
-
pt(Le(o)) !== f && (u = T(-u)), c = new O(a, u, 1n);
|
|
765
|
-
}
|
|
766
|
-
return s === r && o === 4 && (c = new O(a, Ht(i, ht, Tt), 1n)), c ? c.assertValidity() : C("bad point: not on curve");
|
|
767
|
-
}
|
|
768
|
-
static fromHex(e) {
|
|
769
|
-
return O.fromBytes(Dn(e));
|
|
770
|
-
}
|
|
771
|
-
get x() {
|
|
772
|
-
return this.toAffine().x;
|
|
773
|
-
}
|
|
774
|
-
get y() {
|
|
775
|
-
return this.toAffine().y;
|
|
776
|
-
}
|
|
777
|
-
/** Equality check: compare points P&Q. */
|
|
778
|
-
equals(e) {
|
|
779
|
-
const { X: n, Y: r, Z: c } = this, { X: s, Y: o, Z: i } = rt(e), a = T(n * i), u = T(s * c), f = T(r * i), h = T(o * c);
|
|
780
|
-
return a === u && f === h;
|
|
781
|
-
}
|
|
782
|
-
is0() {
|
|
783
|
-
return this.equals(re);
|
|
784
|
-
}
|
|
785
|
-
/** Flip point over y coordinate. */
|
|
786
|
-
negate() {
|
|
787
|
-
return new O(this.X, T(-this.Y), this.Z);
|
|
788
|
-
}
|
|
789
|
-
/** Point doubling: P+P, complete formula. */
|
|
790
|
-
double() {
|
|
791
|
-
return this.add(this);
|
|
792
|
-
}
|
|
793
|
-
/**
|
|
794
|
-
* Point addition: P+Q, complete, exception-free formula
|
|
795
|
-
* (Renes-Costello-Batina, algo 1 of [2015/1060](https://eprint.iacr.org/2015/1060)).
|
|
796
|
-
* Cost: `12M + 0S + 3*a + 3*b3 + 23add`.
|
|
797
|
-
*/
|
|
798
|
-
// prettier-ignore
|
|
799
|
-
add(e) {
|
|
800
|
-
const { X: n, Y: r, Z: c } = this, { X: s, Y: o, Z: i } = rt(e), a = 0n, u = Mn;
|
|
801
|
-
let f = 0n, h = 0n, g = 0n;
|
|
802
|
-
const y = T(u * 3n);
|
|
803
|
-
let p = T(n * s), d = T(r * o), E = T(c * i), b = T(n + r), S = T(s + o);
|
|
804
|
-
b = T(b * S), S = T(p + d), b = T(b - S), S = T(n + c);
|
|
805
|
-
let w = T(s + i);
|
|
806
|
-
return S = T(S * w), w = T(p + E), S = T(S - w), w = T(r + c), f = T(o + i), w = T(w * f), f = T(d + E), w = T(w - f), g = T(a * S), f = T(y * E), g = T(f + g), f = T(d - g), g = T(d + g), h = T(f * g), d = T(p + p), d = T(d + p), E = T(a * E), S = T(y * S), d = T(d + E), E = T(p - E), E = T(a * E), S = T(S + E), p = T(d * S), h = T(h + p), p = T(w * S), f = T(b * f), f = T(f - p), p = T(b * d), g = T(w * g), g = T(g + p), new O(f, h, g);
|
|
807
|
-
}
|
|
808
|
-
subtract(e) {
|
|
809
|
-
return this.add(rt(e).negate());
|
|
810
|
-
}
|
|
811
|
-
/**
|
|
812
|
-
* Point-by-scalar multiplication. Scalar must be in range 1 <= n < CURVE.n.
|
|
813
|
-
* Uses {@link wNAF} for base point.
|
|
814
|
-
* Uses fake point to mitigate side-channel leakage.
|
|
815
|
-
* @param n scalar by which point is multiplied
|
|
816
|
-
* @param safe safe mode guards against timing attacks; unsafe mode is faster
|
|
817
|
-
*/
|
|
818
|
-
multiply(e, n = !0) {
|
|
819
|
-
if (!n && e === 0n)
|
|
820
|
-
return re;
|
|
821
|
-
if (ds(e), e === 1n)
|
|
822
|
-
return this;
|
|
823
|
-
if (this.equals(Se))
|
|
824
|
-
return Ts(e).p;
|
|
825
|
-
let r = re, c = Se;
|
|
826
|
-
for (let s = this; e > 0n; s = s.double(), e >>= 1n)
|
|
827
|
-
e & 1n ? r = r.add(s) : n && (c = c.add(s));
|
|
828
|
-
return r;
|
|
829
|
-
}
|
|
830
|
-
multiplyUnsafe(e) {
|
|
831
|
-
return this.multiply(e, !1);
|
|
832
|
-
}
|
|
833
|
-
/** Convert point to 2d xy affine point. (X, Y, Z) ∋ (x=X/Z, y=Y/Z) */
|
|
834
|
-
toAffine() {
|
|
835
|
-
const { X: e, Y: n, Z: r } = this;
|
|
836
|
-
if (this.equals(re))
|
|
837
|
-
return { x: 0n, y: 0n };
|
|
838
|
-
if (r === 1n)
|
|
839
|
-
return { x: e, y: n };
|
|
840
|
-
const c = ls(r, se);
|
|
841
|
-
return T(r * c) !== 1n && C("inverse invalid"), { x: T(e * c), y: T(n * c) };
|
|
842
|
-
}
|
|
843
|
-
/** Checks if the point is valid and on-curve. */
|
|
844
|
-
assertValidity() {
|
|
845
|
-
const { x: e, y: n } = this.toAffine();
|
|
846
|
-
return Ke(e), Ke(n), T(n * n) === qn(e) ? this : C("bad point: not on curve");
|
|
847
|
-
}
|
|
848
|
-
/** Converts point to 33/65-byte Uint8Array. */
|
|
849
|
-
toBytes(e = !0) {
|
|
850
|
-
const { x: n, y: r } = this.assertValidity().toAffine(), c = Bt(n);
|
|
851
|
-
return e ? Nt(gs(r), c) : Nt(Vn(4), c, Bt(r));
|
|
852
|
-
}
|
|
853
|
-
toHex(e) {
|
|
854
|
-
return Xn(this.toBytes(e));
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
const Se = new O(is, cs, 1n), re = new O(0n, 1n, 0n);
|
|
858
|
-
O.BASE = Se;
|
|
859
|
-
O.ZERO = re;
|
|
860
|
-
const Ss = (t) => Le("0x" + (Xn(t) || "0")), Ht = (t, e, n) => Ss(t.subarray(e, n)), ws = 2n ** 256n, Bt = (t) => Dn(Gn(je(t, 0n, ws), Tt)), Me = 8, Es = 256, jn = Math.ceil(Es / Me) + 1, lt = 2 ** (Me - 1), bs = () => {
|
|
861
|
-
const t = [];
|
|
862
|
-
let e = Se, n = e;
|
|
863
|
-
for (let r = 0; r < jn; r++) {
|
|
864
|
-
n = e, t.push(n);
|
|
865
|
-
for (let c = 1; c < lt; c++)
|
|
866
|
-
n = n.add(e), t.push(n);
|
|
867
|
-
e = n.double();
|
|
868
|
-
}
|
|
869
|
-
return t;
|
|
870
|
-
};
|
|
871
|
-
let Rt;
|
|
872
|
-
const Ft = (t, e) => {
|
|
873
|
-
const n = e.negate();
|
|
874
|
-
return t ? n : e;
|
|
875
|
-
}, Ts = (t) => {
|
|
876
|
-
const e = Rt || (Rt = bs());
|
|
877
|
-
let n = re, r = Se;
|
|
878
|
-
const c = 2 ** Me, s = c, o = Le(c - 1), i = Le(Me);
|
|
879
|
-
for (let a = 0; a < jn; a++) {
|
|
880
|
-
let u = Number(t & o);
|
|
881
|
-
t >>= i, u > lt && (u -= s, t += 1n);
|
|
882
|
-
const f = a * lt, h = f, g = f + Math.abs(u) - 1, y = a % 2 !== 0, p = u < 0;
|
|
883
|
-
u === 0 ? r = r.add(Ft(y, e[h])) : n = n.add(Ft(p, e[g]));
|
|
884
|
-
}
|
|
885
|
-
return t !== 0n && C("invalid wnaf"), { p: n, f: r };
|
|
886
|
-
}, ge = (t) => {
|
|
887
|
-
const e = t.length === 32 ? t : t.subarray(1, 33);
|
|
888
|
-
return l.isBuffer(e) ? e : l.from(e);
|
|
889
|
-
};
|
|
890
|
-
function Kt(t) {
|
|
891
|
-
let e = t.toString(16);
|
|
892
|
-
return e = e.padStart(64, "0"), e.length > 64 && (e = e.slice(-64)), l.from(e, "hex");
|
|
893
|
-
}
|
|
894
|
-
function _s(t) {
|
|
895
|
-
if (t.length === 32)
|
|
896
|
-
return;
|
|
897
|
-
if (![33, 65].includes(t.length)) {
|
|
898
|
-
console.warn(
|
|
899
|
-
`Unsupported key length=${t.length}. Must be 33 (compressed) or 65 (uncompressed).`
|
|
900
|
-
);
|
|
901
|
-
return;
|
|
902
|
-
}
|
|
903
|
-
let e;
|
|
904
|
-
try {
|
|
905
|
-
e = O.fromHex(l.from(t).toString("hex"));
|
|
906
|
-
} catch {
|
|
907
|
-
throw new Error("Invalid secp256k1 public key bytes. Cannot parse.");
|
|
908
|
-
}
|
|
909
|
-
const n = Kt(e.x), r = Kt(e.y), s = e.y % 2n === 0n ? 6 : 7, o = l.alloc(65);
|
|
910
|
-
o[0] = s, n.copy(o, 1), r.copy(o, 33);
|
|
911
|
-
const i = l.concat([l.from([4]), n, r]);
|
|
912
|
-
return {
|
|
913
|
-
hybrid: o,
|
|
914
|
-
uncompressed: i
|
|
915
|
-
};
|
|
916
|
-
}
|
|
917
|
-
function ke(t, e) {
|
|
918
|
-
if (t.equals(e)) return !0;
|
|
919
|
-
if (t.length === 65 && e.length === 65) {
|
|
920
|
-
const n = l.from(t), r = l.from(e);
|
|
921
|
-
return (n[0] === 6 || n[0] === 7) && (n[0] = 4), (r[0] === 6 || r[0] === 7) && (r[0] = 4), n.equals(r);
|
|
922
|
-
}
|
|
923
|
-
return !1;
|
|
924
|
-
}
|
|
925
|
-
const _e = 40, me = 2, Ie = 15, zn = 16, We = 16, ze = 2, Ye = 80, ms = "WARNING: Sending to a future segwit version address can lead to loss of funds. End users MUST be warned carefully in the GUI and asked if they wish to proceed with caution. Wallets should verify the segwit version from the output of fromBech32, then decide when it is safe to use which version of segwit.", Yn = (t) => {
|
|
926
|
-
try {
|
|
927
|
-
const e = l.from(t.subarray(2));
|
|
928
|
-
if (e.length < me || e.length > _e)
|
|
929
|
-
throw new TypeError("Invalid program length for segwit address");
|
|
930
|
-
const n = t[0] - Ye;
|
|
931
|
-
if (n < ze || n > Ie + 1)
|
|
932
|
-
throw new TypeError("Invalid version for segwit address");
|
|
933
|
-
if (n === 1) throw new TypeError("taproot");
|
|
934
|
-
return !0;
|
|
935
|
-
} catch {
|
|
936
|
-
}
|
|
937
|
-
return !1;
|
|
938
|
-
};
|
|
939
|
-
function $n(t, e) {
|
|
940
|
-
if (!l.isBuffer(t)) throw new TypeError("output must be a Buffer");
|
|
941
|
-
if (!e.bech32Opnet) throw new Error("Network does not support opnet");
|
|
942
|
-
const n = t[0];
|
|
943
|
-
let r = 1, c;
|
|
944
|
-
if (t[1] < 76)
|
|
945
|
-
c = t[1], r = 2;
|
|
946
|
-
else if (t[1] === 76)
|
|
947
|
-
c = t[2], r = 3;
|
|
948
|
-
else
|
|
949
|
-
throw new TypeError("Unsupported push opcode in script");
|
|
950
|
-
const s = l.from(t.subarray(r, r + c));
|
|
951
|
-
if (s.length < me || s.length > _e)
|
|
952
|
-
throw new TypeError("Invalid program length for segwit address");
|
|
953
|
-
const o = n === ve.OP_0 ? 0 : n >= ve.OP_1 && n <= ve.OP_16 ? n - (ve.OP_1 - 1) : -1;
|
|
954
|
-
if (o < Ie || o > zn)
|
|
955
|
-
throw new TypeError(`Invalid segwit version ${o}`);
|
|
956
|
-
const i = [o, ...K.bech32m.toWords(s)];
|
|
957
|
-
return K.bech32m.encode(e.bech32Opnet, i);
|
|
958
|
-
}
|
|
959
|
-
function Zn(t, e) {
|
|
960
|
-
const n = l.from(t.subarray(2));
|
|
961
|
-
if (n.length < me || n.length > _e)
|
|
962
|
-
throw new TypeError("Invalid program length for segwit address");
|
|
963
|
-
const r = t[0] - Ye;
|
|
964
|
-
if (r < ze || r > Ie)
|
|
965
|
-
throw new TypeError("Invalid version for segwit address");
|
|
966
|
-
if (t[1] !== n.length)
|
|
967
|
-
throw new TypeError(`Invalid script for segwit address ${t[1]} !== ${n.length}`);
|
|
968
|
-
return Qn(n, r, e.bech32, e.bech32Opnet);
|
|
969
|
-
}
|
|
970
|
-
function Jn(t) {
|
|
971
|
-
const e = l.from(Fn.decode(t));
|
|
972
|
-
if (e.length < 21) throw new TypeError(t + " is too short");
|
|
973
|
-
if (e.length > 21) throw new TypeError(t + " is too long");
|
|
974
|
-
const n = e.readUInt8(0), r = l.from(e.subarray(1));
|
|
975
|
-
return { version: n, hash: r };
|
|
976
|
-
}
|
|
977
|
-
function Is(t, e) {
|
|
978
|
-
Ar(xr(Cr, Or), [t, e]);
|
|
979
|
-
const n = l.allocUnsafe(21);
|
|
980
|
-
return n.writeUInt8(e, 0), t.copy(n, 1), Fn.encode(n);
|
|
981
|
-
}
|
|
982
|
-
function Qn(t, e, n, r) {
|
|
983
|
-
const c = K.bech32.toWords(t);
|
|
984
|
-
return c.unshift(e), e === We && r ? K.bech32m.encode(r, c) : e === 0 ? K.bech32.encode(n, c) : K.bech32m.encode(n, c);
|
|
985
|
-
}
|
|
986
|
-
function er(t, e) {
|
|
987
|
-
e = e || Ve;
|
|
988
|
-
try {
|
|
989
|
-
return we({ output: t, network: e }).address;
|
|
990
|
-
} catch {
|
|
991
|
-
}
|
|
992
|
-
try {
|
|
993
|
-
return Ee({ output: t, network: e }).address;
|
|
994
|
-
} catch {
|
|
995
|
-
}
|
|
996
|
-
try {
|
|
997
|
-
return Xe({ output: t, network: e }).address;
|
|
998
|
-
} catch {
|
|
999
|
-
}
|
|
1000
|
-
try {
|
|
1001
|
-
return be({ output: t, network: e }).address;
|
|
1002
|
-
} catch {
|
|
1003
|
-
}
|
|
1004
|
-
try {
|
|
1005
|
-
return Te({ output: t, network: e }).address;
|
|
1006
|
-
} catch {
|
|
1007
|
-
}
|
|
1008
|
-
try {
|
|
1009
|
-
return $n(t, e);
|
|
1010
|
-
} catch {
|
|
1011
|
-
}
|
|
1012
|
-
try {
|
|
1013
|
-
return Zn(t, e);
|
|
1014
|
-
} catch {
|
|
1015
|
-
}
|
|
1016
|
-
throw new Error(Ir(t) + " has no matching Address");
|
|
1017
|
-
}
|
|
1018
|
-
function tr(t, e) {
|
|
1019
|
-
e = e || Ve;
|
|
1020
|
-
let n, r;
|
|
1021
|
-
try {
|
|
1022
|
-
n = Jn(t);
|
|
1023
|
-
} catch {
|
|
1024
|
-
}
|
|
1025
|
-
if (n) {
|
|
1026
|
-
if (n.version === e.pubKeyHash)
|
|
1027
|
-
return we({ hash: n.hash }).output;
|
|
1028
|
-
if (n.version === e.scriptHash)
|
|
1029
|
-
return Ee({ hash: n.hash }).output;
|
|
1030
|
-
} else {
|
|
1031
|
-
try {
|
|
1032
|
-
r = Kn(t);
|
|
1033
|
-
} catch {
|
|
1034
|
-
}
|
|
1035
|
-
if (r) {
|
|
1036
|
-
if (r.prefix !== e.bech32 && e.bech32Opnet && r.prefix !== e.bech32Opnet)
|
|
1037
|
-
throw new Error(t + " has an invalid prefix");
|
|
1038
|
-
if (r.version === 0) {
|
|
1039
|
-
if (r.data.length === 20)
|
|
1040
|
-
return Xe({ hash: r.data }).output;
|
|
1041
|
-
if (r.data.length === 32)
|
|
1042
|
-
return be({ hash: r.data }).output;
|
|
1043
|
-
} else if (r.version === 1) {
|
|
1044
|
-
if (r.data.length === 32)
|
|
1045
|
-
return Te({ pubkey: r.data }).output;
|
|
1046
|
-
} else if (r.version === We) {
|
|
1047
|
-
if (!e.bech32Opnet) throw new Error(t + " has an invalid prefix");
|
|
1048
|
-
return On({
|
|
1049
|
-
program: r.data,
|
|
1050
|
-
network: e
|
|
1051
|
-
}).output;
|
|
1052
|
-
} else if (r.version >= ze && r.version <= Ie && r.data.length >= me && r.data.length <= _e)
|
|
1053
|
-
return r.version !== We && console.warn(ms), vr([
|
|
1054
|
-
r.version + Ye,
|
|
1055
|
-
r.data
|
|
1056
|
-
]);
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
throw new TypeError(t + " has no matching Script");
|
|
1060
|
-
}
|
|
1061
|
-
const Go = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1062
|
-
__proto__: null,
|
|
1063
|
-
FUTURE_MAX_VERSION: zn,
|
|
1064
|
-
FUTURE_OPNET_VERSION: We,
|
|
1065
|
-
FUTURE_SEGWIT_MAX_SIZE: _e,
|
|
1066
|
-
FUTURE_SEGWIT_MAX_VERSION: Ie,
|
|
1067
|
-
FUTURE_SEGWIT_MIN_SIZE: me,
|
|
1068
|
-
FUTURE_SEGWIT_MIN_VERSION: ze,
|
|
1069
|
-
FUTURE_SEGWIT_VERSION_DIFF: Ye,
|
|
1070
|
-
_toFutureSegwitAddress: Zn,
|
|
1071
|
-
fromBase58Check: Jn,
|
|
1072
|
-
fromBech32: Kn,
|
|
1073
|
-
fromOutputScript: er,
|
|
1074
|
-
isUnknownSegwitVersion: Yn,
|
|
1075
|
-
toBase58Check: Is,
|
|
1076
|
-
toBech32: Qn,
|
|
1077
|
-
toFutureOPNetAddress: $n,
|
|
1078
|
-
toOutputScript: tr
|
|
1079
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
1080
|
-
var Ae = {}, xe = {}, st = {}, oe = {}, ie = {}, ot = {}, Lt;
|
|
1081
|
-
function A() {
|
|
1082
|
-
return Lt || (Lt = 1, (function(t) {
|
|
1083
|
-
Object.defineProperty(t, "__esModule", { value: !0 }), (function(e) {
|
|
1084
|
-
e[e.UNSIGNED_TX = 0] = "UNSIGNED_TX", e[e.GLOBAL_XPUB = 1] = "GLOBAL_XPUB";
|
|
1085
|
-
})(t.GlobalTypes || (t.GlobalTypes = {})), t.GLOBAL_TYPE_NAMES = ["unsignedTx", "globalXpub"], (function(e) {
|
|
1086
|
-
e[e.NON_WITNESS_UTXO = 0] = "NON_WITNESS_UTXO", e[e.WITNESS_UTXO = 1] = "WITNESS_UTXO", e[e.PARTIAL_SIG = 2] = "PARTIAL_SIG", e[e.SIGHASH_TYPE = 3] = "SIGHASH_TYPE", e[e.REDEEM_SCRIPT = 4] = "REDEEM_SCRIPT", e[e.WITNESS_SCRIPT = 5] = "WITNESS_SCRIPT", e[e.BIP32_DERIVATION = 6] = "BIP32_DERIVATION", e[e.FINAL_SCRIPTSIG = 7] = "FINAL_SCRIPTSIG", e[e.FINAL_SCRIPTWITNESS = 8] = "FINAL_SCRIPTWITNESS", e[e.POR_COMMITMENT = 9] = "POR_COMMITMENT", e[e.TAP_KEY_SIG = 19] = "TAP_KEY_SIG", e[e.TAP_SCRIPT_SIG = 20] = "TAP_SCRIPT_SIG", e[e.TAP_LEAF_SCRIPT = 21] = "TAP_LEAF_SCRIPT", e[e.TAP_BIP32_DERIVATION = 22] = "TAP_BIP32_DERIVATION", e[e.TAP_INTERNAL_KEY = 23] = "TAP_INTERNAL_KEY", e[e.TAP_MERKLE_ROOT = 24] = "TAP_MERKLE_ROOT";
|
|
1087
|
-
})(t.InputTypes || (t.InputTypes = {})), t.INPUT_TYPE_NAMES = [
|
|
1088
|
-
"nonWitnessUtxo",
|
|
1089
|
-
"witnessUtxo",
|
|
1090
|
-
"partialSig",
|
|
1091
|
-
"sighashType",
|
|
1092
|
-
"redeemScript",
|
|
1093
|
-
"witnessScript",
|
|
1094
|
-
"bip32Derivation",
|
|
1095
|
-
"finalScriptSig",
|
|
1096
|
-
"finalScriptWitness",
|
|
1097
|
-
"porCommitment",
|
|
1098
|
-
"tapKeySig",
|
|
1099
|
-
"tapScriptSig",
|
|
1100
|
-
"tapLeafScript",
|
|
1101
|
-
"tapBip32Derivation",
|
|
1102
|
-
"tapInternalKey",
|
|
1103
|
-
"tapMerkleRoot"
|
|
1104
|
-
], (function(e) {
|
|
1105
|
-
e[e.REDEEM_SCRIPT = 0] = "REDEEM_SCRIPT", e[e.WITNESS_SCRIPT = 1] = "WITNESS_SCRIPT", e[e.BIP32_DERIVATION = 2] = "BIP32_DERIVATION", e[e.TAP_INTERNAL_KEY = 5] = "TAP_INTERNAL_KEY", e[e.TAP_TREE = 6] = "TAP_TREE", e[e.TAP_BIP32_DERIVATION = 7] = "TAP_BIP32_DERIVATION";
|
|
1106
|
-
})(t.OutputTypes || (t.OutputTypes = {})), t.OUTPUT_TYPE_NAMES = [
|
|
1107
|
-
"redeemScript",
|
|
1108
|
-
"witnessScript",
|
|
1109
|
-
"bip32Derivation",
|
|
1110
|
-
"tapInternalKey",
|
|
1111
|
-
"tapTree",
|
|
1112
|
-
"tapBip32Derivation"
|
|
1113
|
-
];
|
|
1114
|
-
})(ot)), ot;
|
|
1115
|
-
}
|
|
1116
|
-
var W = {}, Mt;
|
|
1117
|
-
function vs() {
|
|
1118
|
-
if (Mt) return W;
|
|
1119
|
-
Mt = 1, Object.defineProperty(W, "__esModule", { value: !0 });
|
|
1120
|
-
const t = A(), e = (o) => [...Array(o).keys()];
|
|
1121
|
-
function n(o) {
|
|
1122
|
-
if (o.key[0] !== t.GlobalTypes.GLOBAL_XPUB)
|
|
1123
|
-
throw new Error(
|
|
1124
|
-
"Decode Error: could not decode globalXpub with key 0x" + o.key.toString("hex")
|
|
1125
|
-
);
|
|
1126
|
-
if (o.key.length !== 79 || ![2, 3].includes(o.key[46]))
|
|
1127
|
-
throw new Error(
|
|
1128
|
-
"Decode Error: globalXpub has invalid extended pubkey in key 0x" + o.key.toString("hex")
|
|
1129
|
-
);
|
|
1130
|
-
if (o.value.length / 4 % 1 !== 0)
|
|
1131
|
-
throw new Error(
|
|
1132
|
-
"Decode Error: Global GLOBAL_XPUB value length should be multiple of 4"
|
|
1133
|
-
);
|
|
1134
|
-
const i = o.key.slice(1), a = {
|
|
1135
|
-
masterFingerprint: o.value.slice(0, 4),
|
|
1136
|
-
extendedPubkey: i,
|
|
1137
|
-
path: "m"
|
|
1138
|
-
};
|
|
1139
|
-
for (const u of e(o.value.length / 4 - 1)) {
|
|
1140
|
-
const f = o.value.readUInt32LE(u * 4 + 4), h = !!(f & 2147483648), g = f & 2147483647;
|
|
1141
|
-
a.path += "/" + g.toString(10) + (h ? "'" : "");
|
|
1142
|
-
}
|
|
1143
|
-
return a;
|
|
1144
|
-
}
|
|
1145
|
-
W.decode = n;
|
|
1146
|
-
function r(o) {
|
|
1147
|
-
const i = l.from([t.GlobalTypes.GLOBAL_XPUB]), a = l.concat([i, o.extendedPubkey]), u = o.path.split("/"), f = l.allocUnsafe(u.length * 4);
|
|
1148
|
-
o.masterFingerprint.copy(f, 0);
|
|
1149
|
-
let h = 4;
|
|
1150
|
-
return u.slice(1).forEach((g) => {
|
|
1151
|
-
const y = g.slice(-1) === "'";
|
|
1152
|
-
let p = 2147483647 & parseInt(y ? g.slice(0, -1) : g, 10);
|
|
1153
|
-
y && (p += 2147483648), f.writeUInt32LE(p, h), h += 4;
|
|
1154
|
-
}), {
|
|
1155
|
-
key: a,
|
|
1156
|
-
value: f
|
|
1157
|
-
};
|
|
1158
|
-
}
|
|
1159
|
-
W.encode = r, W.expected = "{ masterFingerprint: Buffer; extendedPubkey: Buffer; path: string; }";
|
|
1160
|
-
function c(o) {
|
|
1161
|
-
const i = o.extendedPubkey, a = o.masterFingerprint, u = o.path;
|
|
1162
|
-
return l.isBuffer(i) && i.length === 78 && [2, 3].indexOf(i[45]) > -1 && l.isBuffer(a) && a.length === 4 && typeof u == "string" && !!u.match(/^m(\/\d+'?)*$/);
|
|
1163
|
-
}
|
|
1164
|
-
W.check = c;
|
|
1165
|
-
function s(o, i, a) {
|
|
1166
|
-
const u = i.extendedPubkey.toString("hex");
|
|
1167
|
-
return a.has(u) ? !1 : (a.add(u), o.filter((f) => f.extendedPubkey.equals(i.extendedPubkey)).length === 0);
|
|
1168
|
-
}
|
|
1169
|
-
return W.canAddToArray = s, W;
|
|
1170
|
-
}
|
|
1171
|
-
var Ce = {}, Wt;
|
|
1172
|
-
function ks() {
|
|
1173
|
-
if (Wt) return Ce;
|
|
1174
|
-
Wt = 1, Object.defineProperty(Ce, "__esModule", { value: !0 });
|
|
1175
|
-
const t = A();
|
|
1176
|
-
function e(n) {
|
|
1177
|
-
return {
|
|
1178
|
-
key: l.from([t.GlobalTypes.UNSIGNED_TX]),
|
|
1179
|
-
value: n.toBuffer()
|
|
1180
|
-
};
|
|
1181
|
-
}
|
|
1182
|
-
return Ce.encode = e, Ce;
|
|
1183
|
-
}
|
|
1184
|
-
var G = {}, Gt;
|
|
1185
|
-
function As() {
|
|
1186
|
-
if (Gt) return G;
|
|
1187
|
-
Gt = 1, Object.defineProperty(G, "__esModule", { value: !0 });
|
|
1188
|
-
const t = A();
|
|
1189
|
-
function e(s) {
|
|
1190
|
-
if (s.key[0] !== t.InputTypes.FINAL_SCRIPTSIG)
|
|
1191
|
-
throw new Error(
|
|
1192
|
-
"Decode Error: could not decode finalScriptSig with key 0x" + s.key.toString("hex")
|
|
1193
|
-
);
|
|
1194
|
-
return s.value;
|
|
1195
|
-
}
|
|
1196
|
-
G.decode = e;
|
|
1197
|
-
function n(s) {
|
|
1198
|
-
return {
|
|
1199
|
-
key: l.from([t.InputTypes.FINAL_SCRIPTSIG]),
|
|
1200
|
-
value: s
|
|
1201
|
-
};
|
|
1202
|
-
}
|
|
1203
|
-
G.encode = n, G.expected = "Buffer";
|
|
1204
|
-
function r(s) {
|
|
1205
|
-
return l.isBuffer(s);
|
|
1206
|
-
}
|
|
1207
|
-
G.check = r;
|
|
1208
|
-
function c(s, o) {
|
|
1209
|
-
return !!s && !!o && s.finalScriptSig === void 0;
|
|
1210
|
-
}
|
|
1211
|
-
return G.canAdd = c, G;
|
|
1212
|
-
}
|
|
1213
|
-
var X = {}, Xt;
|
|
1214
|
-
function xs() {
|
|
1215
|
-
if (Xt) return X;
|
|
1216
|
-
Xt = 1, Object.defineProperty(X, "__esModule", { value: !0 });
|
|
1217
|
-
const t = A();
|
|
1218
|
-
function e(s) {
|
|
1219
|
-
if (s.key[0] !== t.InputTypes.FINAL_SCRIPTWITNESS)
|
|
1220
|
-
throw new Error(
|
|
1221
|
-
"Decode Error: could not decode finalScriptWitness with key 0x" + s.key.toString("hex")
|
|
1222
|
-
);
|
|
1223
|
-
return s.value;
|
|
1224
|
-
}
|
|
1225
|
-
X.decode = e;
|
|
1226
|
-
function n(s) {
|
|
1227
|
-
return {
|
|
1228
|
-
key: l.from([t.InputTypes.FINAL_SCRIPTWITNESS]),
|
|
1229
|
-
value: s
|
|
1230
|
-
};
|
|
1231
|
-
}
|
|
1232
|
-
X.encode = n, X.expected = "Buffer";
|
|
1233
|
-
function r(s) {
|
|
1234
|
-
return l.isBuffer(s);
|
|
1235
|
-
}
|
|
1236
|
-
X.check = r;
|
|
1237
|
-
function c(s, o) {
|
|
1238
|
-
return !!s && !!o && s.finalScriptWitness === void 0;
|
|
1239
|
-
}
|
|
1240
|
-
return X.canAdd = c, X;
|
|
1241
|
-
}
|
|
1242
|
-
var D = {}, Dt;
|
|
1243
|
-
function Cs() {
|
|
1244
|
-
if (Dt) return D;
|
|
1245
|
-
Dt = 1, Object.defineProperty(D, "__esModule", { value: !0 });
|
|
1246
|
-
const t = A();
|
|
1247
|
-
function e(s) {
|
|
1248
|
-
if (s.key[0] !== t.InputTypes.NON_WITNESS_UTXO)
|
|
1249
|
-
throw new Error(
|
|
1250
|
-
"Decode Error: could not decode nonWitnessUtxo with key 0x" + s.key.toString("hex")
|
|
1251
|
-
);
|
|
1252
|
-
return s.value;
|
|
1253
|
-
}
|
|
1254
|
-
D.decode = e;
|
|
1255
|
-
function n(s) {
|
|
1256
|
-
return {
|
|
1257
|
-
key: l.from([t.InputTypes.NON_WITNESS_UTXO]),
|
|
1258
|
-
value: s
|
|
1259
|
-
};
|
|
1260
|
-
}
|
|
1261
|
-
D.encode = n, D.expected = "Buffer";
|
|
1262
|
-
function r(s) {
|
|
1263
|
-
return l.isBuffer(s);
|
|
1264
|
-
}
|
|
1265
|
-
D.check = r;
|
|
1266
|
-
function c(s, o) {
|
|
1267
|
-
return !!s && !!o && s.nonWitnessUtxo === void 0;
|
|
1268
|
-
}
|
|
1269
|
-
return D.canAdd = c, D;
|
|
1270
|
-
}
|
|
1271
|
-
var q = {}, qt;
|
|
1272
|
-
function Os() {
|
|
1273
|
-
if (qt) return q;
|
|
1274
|
-
qt = 1, Object.defineProperty(q, "__esModule", { value: !0 });
|
|
1275
|
-
const t = A();
|
|
1276
|
-
function e(o) {
|
|
1277
|
-
if (o.key[0] !== t.InputTypes.PARTIAL_SIG)
|
|
1278
|
-
throw new Error(
|
|
1279
|
-
"Decode Error: could not decode partialSig with key 0x" + o.key.toString("hex")
|
|
1280
|
-
);
|
|
1281
|
-
if (!(o.key.length === 34 || o.key.length === 66) || ![2, 3, 4].includes(o.key[1]))
|
|
1282
|
-
throw new Error(
|
|
1283
|
-
"Decode Error: partialSig has invalid pubkey in key 0x" + o.key.toString("hex")
|
|
1284
|
-
);
|
|
1285
|
-
return {
|
|
1286
|
-
pubkey: o.key.slice(1),
|
|
1287
|
-
signature: o.value
|
|
1288
|
-
};
|
|
1289
|
-
}
|
|
1290
|
-
q.decode = e;
|
|
1291
|
-
function n(o) {
|
|
1292
|
-
const i = l.from([t.InputTypes.PARTIAL_SIG]);
|
|
1293
|
-
return {
|
|
1294
|
-
key: l.concat([i, o.pubkey]),
|
|
1295
|
-
value: o.signature
|
|
1296
|
-
};
|
|
1297
|
-
}
|
|
1298
|
-
q.encode = n, q.expected = "{ pubkey: Buffer; signature: Buffer; }";
|
|
1299
|
-
function r(o) {
|
|
1300
|
-
return l.isBuffer(o.pubkey) && l.isBuffer(o.signature) && [33, 65].includes(o.pubkey.length) && [2, 3, 4].includes(o.pubkey[0]) && c(o.signature);
|
|
1301
|
-
}
|
|
1302
|
-
q.check = r;
|
|
1303
|
-
function c(o) {
|
|
1304
|
-
if (!l.isBuffer(o) || o.length < 9 || o[0] !== 48 || o.length !== o[1] + 3 || o[2] !== 2) return !1;
|
|
1305
|
-
const i = o[3];
|
|
1306
|
-
if (i > 33 || i < 1 || o[3 + i + 1] !== 2) return !1;
|
|
1307
|
-
const a = o[3 + i + 2];
|
|
1308
|
-
return !(a > 33 || a < 1 || o.length !== 3 + i + 2 + a + 2);
|
|
1309
|
-
}
|
|
1310
|
-
function s(o, i, a) {
|
|
1311
|
-
const u = i.pubkey.toString("hex");
|
|
1312
|
-
return a.has(u) ? !1 : (a.add(u), o.filter((f) => f.pubkey.equals(i.pubkey)).length === 0);
|
|
1313
|
-
}
|
|
1314
|
-
return q.canAddToArray = s, q;
|
|
1315
|
-
}
|
|
1316
|
-
var V = {}, Vt;
|
|
1317
|
-
function Ps() {
|
|
1318
|
-
if (Vt) return V;
|
|
1319
|
-
Vt = 1, Object.defineProperty(V, "__esModule", { value: !0 });
|
|
1320
|
-
const t = A();
|
|
1321
|
-
function e(s) {
|
|
1322
|
-
if (s.key[0] !== t.InputTypes.POR_COMMITMENT)
|
|
1323
|
-
throw new Error(
|
|
1324
|
-
"Decode Error: could not decode porCommitment with key 0x" + s.key.toString("hex")
|
|
1325
|
-
);
|
|
1326
|
-
return s.value.toString("utf8");
|
|
1327
|
-
}
|
|
1328
|
-
V.decode = e;
|
|
1329
|
-
function n(s) {
|
|
1330
|
-
return {
|
|
1331
|
-
key: l.from([t.InputTypes.POR_COMMITMENT]),
|
|
1332
|
-
value: l.from(s, "utf8")
|
|
1333
|
-
};
|
|
1334
|
-
}
|
|
1335
|
-
V.encode = n, V.expected = "string";
|
|
1336
|
-
function r(s) {
|
|
1337
|
-
return typeof s == "string";
|
|
1338
|
-
}
|
|
1339
|
-
V.check = r;
|
|
1340
|
-
function c(s, o) {
|
|
1341
|
-
return !!s && !!o && s.porCommitment === void 0;
|
|
1342
|
-
}
|
|
1343
|
-
return V.canAdd = c, V;
|
|
1344
|
-
}
|
|
1345
|
-
var j = {}, jt;
|
|
1346
|
-
function Ns() {
|
|
1347
|
-
if (jt) return j;
|
|
1348
|
-
jt = 1, Object.defineProperty(j, "__esModule", { value: !0 });
|
|
1349
|
-
const t = A();
|
|
1350
|
-
function e(s) {
|
|
1351
|
-
if (s.key[0] !== t.InputTypes.SIGHASH_TYPE)
|
|
1352
|
-
throw new Error(
|
|
1353
|
-
"Decode Error: could not decode sighashType with key 0x" + s.key.toString("hex")
|
|
1354
|
-
);
|
|
1355
|
-
return s.value.readUInt32LE(0);
|
|
1356
|
-
}
|
|
1357
|
-
j.decode = e;
|
|
1358
|
-
function n(s) {
|
|
1359
|
-
const o = l.from([t.InputTypes.SIGHASH_TYPE]), i = l.allocUnsafe(4);
|
|
1360
|
-
return i.writeUInt32LE(s, 0), {
|
|
1361
|
-
key: o,
|
|
1362
|
-
value: i
|
|
1363
|
-
};
|
|
1364
|
-
}
|
|
1365
|
-
j.encode = n, j.expected = "number";
|
|
1366
|
-
function r(s) {
|
|
1367
|
-
return typeof s == "number";
|
|
1368
|
-
}
|
|
1369
|
-
j.check = r;
|
|
1370
|
-
function c(s, o) {
|
|
1371
|
-
return !!s && !!o && s.sighashType === void 0;
|
|
1372
|
-
}
|
|
1373
|
-
return j.canAdd = c, j;
|
|
1374
|
-
}
|
|
1375
|
-
var z = {}, zt;
|
|
1376
|
-
function Us() {
|
|
1377
|
-
if (zt) return z;
|
|
1378
|
-
zt = 1, Object.defineProperty(z, "__esModule", { value: !0 });
|
|
1379
|
-
const t = A();
|
|
1380
|
-
function e(s) {
|
|
1381
|
-
if (s.key[0] !== t.InputTypes.TAP_KEY_SIG || s.key.length !== 1)
|
|
1382
|
-
throw new Error(
|
|
1383
|
-
"Decode Error: could not decode tapKeySig with key 0x" + s.key.toString("hex")
|
|
1384
|
-
);
|
|
1385
|
-
if (!r(s.value))
|
|
1386
|
-
throw new Error(
|
|
1387
|
-
"Decode Error: tapKeySig not a valid 64-65-byte BIP340 signature"
|
|
1388
|
-
);
|
|
1389
|
-
return s.value;
|
|
1390
|
-
}
|
|
1391
|
-
z.decode = e;
|
|
1392
|
-
function n(s) {
|
|
1393
|
-
return { key: l.from([t.InputTypes.TAP_KEY_SIG]), value: s };
|
|
1394
|
-
}
|
|
1395
|
-
z.encode = n, z.expected = "Buffer";
|
|
1396
|
-
function r(s) {
|
|
1397
|
-
return l.isBuffer(s) && (s.length === 64 || s.length === 65);
|
|
1398
|
-
}
|
|
1399
|
-
z.check = r;
|
|
1400
|
-
function c(s, o) {
|
|
1401
|
-
return !!s && !!o && s.tapKeySig === void 0;
|
|
1402
|
-
}
|
|
1403
|
-
return z.canAdd = c, z;
|
|
1404
|
-
}
|
|
1405
|
-
var Y = {}, Yt;
|
|
1406
|
-
function Hs() {
|
|
1407
|
-
if (Yt) return Y;
|
|
1408
|
-
Yt = 1, Object.defineProperty(Y, "__esModule", { value: !0 });
|
|
1409
|
-
const t = A();
|
|
1410
|
-
function e(s) {
|
|
1411
|
-
if (s.key[0] !== t.InputTypes.TAP_LEAF_SCRIPT)
|
|
1412
|
-
throw new Error(
|
|
1413
|
-
"Decode Error: could not decode tapLeafScript with key 0x" + s.key.toString("hex")
|
|
1414
|
-
);
|
|
1415
|
-
if ((s.key.length - 2) % 32 !== 0)
|
|
1416
|
-
throw new Error(
|
|
1417
|
-
"Decode Error: tapLeafScript has invalid control block in key 0x" + s.key.toString("hex")
|
|
1418
|
-
);
|
|
1419
|
-
const o = s.value[s.value.length - 1];
|
|
1420
|
-
if ((s.key[1] & 254) !== o)
|
|
1421
|
-
throw new Error(
|
|
1422
|
-
"Decode Error: tapLeafScript bad leaf version in key 0x" + s.key.toString("hex")
|
|
1423
|
-
);
|
|
1424
|
-
const i = s.value.slice(0, -1);
|
|
1425
|
-
return { controlBlock: s.key.slice(1), script: i, leafVersion: o };
|
|
1426
|
-
}
|
|
1427
|
-
Y.decode = e;
|
|
1428
|
-
function n(s) {
|
|
1429
|
-
const o = l.from([t.InputTypes.TAP_LEAF_SCRIPT]), i = l.from([s.leafVersion]);
|
|
1430
|
-
return {
|
|
1431
|
-
key: l.concat([o, s.controlBlock]),
|
|
1432
|
-
value: l.concat([s.script, i])
|
|
1433
|
-
};
|
|
1434
|
-
}
|
|
1435
|
-
Y.encode = n, Y.expected = "{ controlBlock: Buffer; leafVersion: number, script: Buffer; }";
|
|
1436
|
-
function r(s) {
|
|
1437
|
-
return l.isBuffer(s.controlBlock) && (s.controlBlock.length - 1) % 32 === 0 && (s.controlBlock[0] & 254) === s.leafVersion && l.isBuffer(s.script);
|
|
1438
|
-
}
|
|
1439
|
-
Y.check = r;
|
|
1440
|
-
function c(s, o, i) {
|
|
1441
|
-
const a = o.controlBlock.toString("hex");
|
|
1442
|
-
return i.has(a) ? !1 : (i.add(a), s.filter((u) => u.controlBlock.equals(o.controlBlock)).length === 0);
|
|
1443
|
-
}
|
|
1444
|
-
return Y.canAddToArray = c, Y;
|
|
1445
|
-
}
|
|
1446
|
-
var $ = {}, $t;
|
|
1447
|
-
function Bs() {
|
|
1448
|
-
if ($t) return $;
|
|
1449
|
-
$t = 1, Object.defineProperty($, "__esModule", { value: !0 });
|
|
1450
|
-
const t = A();
|
|
1451
|
-
function e(s) {
|
|
1452
|
-
if (s.key[0] !== t.InputTypes.TAP_MERKLE_ROOT || s.key.length !== 1)
|
|
1453
|
-
throw new Error(
|
|
1454
|
-
"Decode Error: could not decode tapMerkleRoot with key 0x" + s.key.toString("hex")
|
|
1455
|
-
);
|
|
1456
|
-
if (!r(s.value))
|
|
1457
|
-
throw new Error("Decode Error: tapMerkleRoot not a 32-byte hash");
|
|
1458
|
-
return s.value;
|
|
1459
|
-
}
|
|
1460
|
-
$.decode = e;
|
|
1461
|
-
function n(s) {
|
|
1462
|
-
return { key: l.from([t.InputTypes.TAP_MERKLE_ROOT]), value: s };
|
|
1463
|
-
}
|
|
1464
|
-
$.encode = n, $.expected = "Buffer";
|
|
1465
|
-
function r(s) {
|
|
1466
|
-
return l.isBuffer(s) && s.length === 32;
|
|
1467
|
-
}
|
|
1468
|
-
$.check = r;
|
|
1469
|
-
function c(s, o) {
|
|
1470
|
-
return !!s && !!o && s.tapMerkleRoot === void 0;
|
|
1471
|
-
}
|
|
1472
|
-
return $.canAdd = c, $;
|
|
1473
|
-
}
|
|
1474
|
-
var Z = {}, Zt;
|
|
1475
|
-
function Rs() {
|
|
1476
|
-
if (Zt) return Z;
|
|
1477
|
-
Zt = 1, Object.defineProperty(Z, "__esModule", { value: !0 });
|
|
1478
|
-
const t = A();
|
|
1479
|
-
function e(s) {
|
|
1480
|
-
if (s.key[0] !== t.InputTypes.TAP_SCRIPT_SIG)
|
|
1481
|
-
throw new Error(
|
|
1482
|
-
"Decode Error: could not decode tapScriptSig with key 0x" + s.key.toString("hex")
|
|
1483
|
-
);
|
|
1484
|
-
if (s.key.length !== 65)
|
|
1485
|
-
throw new Error(
|
|
1486
|
-
"Decode Error: tapScriptSig has invalid key 0x" + s.key.toString("hex")
|
|
1487
|
-
);
|
|
1488
|
-
if (s.value.length !== 64 && s.value.length !== 65)
|
|
1489
|
-
throw new Error(
|
|
1490
|
-
"Decode Error: tapScriptSig has invalid signature in key 0x" + s.key.toString("hex")
|
|
1491
|
-
);
|
|
1492
|
-
const o = s.key.slice(1, 33), i = s.key.slice(33);
|
|
1493
|
-
return {
|
|
1494
|
-
pubkey: o,
|
|
1495
|
-
leafHash: i,
|
|
1496
|
-
signature: s.value
|
|
1497
|
-
};
|
|
1498
|
-
}
|
|
1499
|
-
Z.decode = e;
|
|
1500
|
-
function n(s) {
|
|
1501
|
-
const o = l.from([t.InputTypes.TAP_SCRIPT_SIG]);
|
|
1502
|
-
return {
|
|
1503
|
-
key: l.concat([o, s.pubkey, s.leafHash]),
|
|
1504
|
-
value: s.signature
|
|
1505
|
-
};
|
|
1506
|
-
}
|
|
1507
|
-
Z.encode = n, Z.expected = "{ pubkey: Buffer; leafHash: Buffer; signature: Buffer; }";
|
|
1508
|
-
function r(s) {
|
|
1509
|
-
return l.isBuffer(s.pubkey) && l.isBuffer(s.leafHash) && l.isBuffer(s.signature) && s.pubkey.length === 32 && s.leafHash.length === 32 && (s.signature.length === 64 || s.signature.length === 65);
|
|
1510
|
-
}
|
|
1511
|
-
Z.check = r;
|
|
1512
|
-
function c(s, o, i) {
|
|
1513
|
-
const a = o.pubkey.toString("hex") + o.leafHash.toString("hex");
|
|
1514
|
-
return i.has(a) ? !1 : (i.add(a), s.filter(
|
|
1515
|
-
(u) => u.pubkey.equals(o.pubkey) && u.leafHash.equals(o.leafHash)
|
|
1516
|
-
).length === 0);
|
|
1517
|
-
}
|
|
1518
|
-
return Z.canAddToArray = c, Z;
|
|
1519
|
-
}
|
|
1520
|
-
var J = {}, F = {}, ce = {}, Jt;
|
|
1521
|
-
function fe() {
|
|
1522
|
-
if (Jt) return ce;
|
|
1523
|
-
Jt = 1, Object.defineProperty(ce, "__esModule", { value: !0 });
|
|
1524
|
-
const t = 9007199254740991;
|
|
1525
|
-
function e(s) {
|
|
1526
|
-
if (s < 0 || s > t || s % 1 !== 0)
|
|
1527
|
-
throw new RangeError("value out of range");
|
|
1528
|
-
}
|
|
1529
|
-
function n(s, o, i) {
|
|
1530
|
-
if (e(s), o || (o = l.allocUnsafe(c(s))), !l.isBuffer(o))
|
|
1531
|
-
throw new TypeError("buffer must be a Buffer instance");
|
|
1532
|
-
return i || (i = 0), s < 253 ? (o.writeUInt8(s, i), Object.assign(n, { bytes: 1 })) : s <= 65535 ? (o.writeUInt8(253, i), o.writeUInt16LE(s, i + 1), Object.assign(n, { bytes: 3 })) : s <= 4294967295 ? (o.writeUInt8(254, i), o.writeUInt32LE(s, i + 1), Object.assign(n, { bytes: 5 })) : (o.writeUInt8(255, i), o.writeUInt32LE(s >>> 0, i + 1), o.writeUInt32LE(s / 4294967296 | 0, i + 5), Object.assign(n, { bytes: 9 })), o;
|
|
1533
|
-
}
|
|
1534
|
-
ce.encode = n;
|
|
1535
|
-
function r(s, o) {
|
|
1536
|
-
if (!l.isBuffer(s))
|
|
1537
|
-
throw new TypeError("buffer must be a Buffer instance");
|
|
1538
|
-
o || (o = 0);
|
|
1539
|
-
const i = s.readUInt8(o);
|
|
1540
|
-
if (i < 253)
|
|
1541
|
-
return Object.assign(r, { bytes: 1 }), i;
|
|
1542
|
-
if (i === 253)
|
|
1543
|
-
return Object.assign(r, { bytes: 3 }), s.readUInt16LE(o + 1);
|
|
1544
|
-
if (i === 254)
|
|
1545
|
-
return Object.assign(r, { bytes: 5 }), s.readUInt32LE(o + 1);
|
|
1546
|
-
{
|
|
1547
|
-
Object.assign(r, { bytes: 9 });
|
|
1548
|
-
const a = s.readUInt32LE(o + 1), f = s.readUInt32LE(o + 5) * 4294967296 + a;
|
|
1549
|
-
return e(f), f;
|
|
1550
|
-
}
|
|
1551
|
-
}
|
|
1552
|
-
ce.decode = r;
|
|
1553
|
-
function c(s) {
|
|
1554
|
-
return e(s), s < 253 ? 1 : s <= 65535 ? 3 : s <= 4294967295 ? 5 : 9;
|
|
1555
|
-
}
|
|
1556
|
-
return ce.encodingLength = c, ce;
|
|
1557
|
-
}
|
|
1558
|
-
var Qt;
|
|
1559
|
-
function mt() {
|
|
1560
|
-
if (Qt) return F;
|
|
1561
|
-
Qt = 1, Object.defineProperty(F, "__esModule", { value: !0 });
|
|
1562
|
-
const t = fe();
|
|
1563
|
-
F.range = (i) => [...Array(i).keys()];
|
|
1564
|
-
function e(i) {
|
|
1565
|
-
if (i.length < 1) return i;
|
|
1566
|
-
let a = i.length - 1, u = 0;
|
|
1567
|
-
for (let f = 0; f < i.length / 2; f++)
|
|
1568
|
-
u = i[f], i[f] = i[a], i[a] = u, a--;
|
|
1569
|
-
return i;
|
|
1570
|
-
}
|
|
1571
|
-
F.reverseBuffer = e;
|
|
1572
|
-
function n(i) {
|
|
1573
|
-
const a = i.map(r);
|
|
1574
|
-
return a.push(l.from([0])), l.concat(a);
|
|
1575
|
-
}
|
|
1576
|
-
F.keyValsToBuffer = n;
|
|
1577
|
-
function r(i) {
|
|
1578
|
-
const a = i.key.length, u = i.value.length, f = t.encodingLength(a), h = t.encodingLength(u), g = l.allocUnsafe(
|
|
1579
|
-
f + a + h + u
|
|
1580
|
-
);
|
|
1581
|
-
return t.encode(a, g, 0), i.key.copy(g, f), t.encode(u, g, f + a), i.value.copy(g, f + a + h), g;
|
|
1582
|
-
}
|
|
1583
|
-
F.keyValToBuffer = r;
|
|
1584
|
-
function c(i, a) {
|
|
1585
|
-
if (typeof i != "number")
|
|
1586
|
-
throw new Error("cannot write a non-number as a number");
|
|
1587
|
-
if (i < 0)
|
|
1588
|
-
throw new Error("specified a negative value for writing an unsigned value");
|
|
1589
|
-
if (i > a) throw new Error("RangeError: value out of range");
|
|
1590
|
-
if (Math.floor(i) !== i)
|
|
1591
|
-
throw new Error("value has a fractional component");
|
|
1592
|
-
}
|
|
1593
|
-
function s(i, a) {
|
|
1594
|
-
const u = i.readUInt32LE(a);
|
|
1595
|
-
let f = i.readUInt32LE(a + 4);
|
|
1596
|
-
return f *= 4294967296, c(f + u, 9007199254740991), f + u;
|
|
1597
|
-
}
|
|
1598
|
-
F.readUInt64LE = s;
|
|
1599
|
-
function o(i, a, u) {
|
|
1600
|
-
return c(a, 9007199254740991), i.writeInt32LE(a & -1, u), i.writeUInt32LE(Math.floor(a / 4294967296), u + 4), u + 8;
|
|
1601
|
-
}
|
|
1602
|
-
return F.writeUInt64LE = o, F;
|
|
1603
|
-
}
|
|
1604
|
-
var en;
|
|
1605
|
-
function Fs() {
|
|
1606
|
-
if (en) return J;
|
|
1607
|
-
en = 1, Object.defineProperty(J, "__esModule", { value: !0 });
|
|
1608
|
-
const t = A(), e = mt(), n = fe();
|
|
1609
|
-
function r(i) {
|
|
1610
|
-
if (i.key[0] !== t.InputTypes.WITNESS_UTXO)
|
|
1611
|
-
throw new Error(
|
|
1612
|
-
"Decode Error: could not decode witnessUtxo with key 0x" + i.key.toString("hex")
|
|
1613
|
-
);
|
|
1614
|
-
const a = e.readUInt64LE(i.value, 0);
|
|
1615
|
-
let u = 8;
|
|
1616
|
-
const f = n.decode(i.value, u);
|
|
1617
|
-
u += n.encodingLength(f);
|
|
1618
|
-
const h = i.value.slice(u);
|
|
1619
|
-
if (h.length !== f)
|
|
1620
|
-
throw new Error("Decode Error: WITNESS_UTXO script is not proper length");
|
|
1621
|
-
return {
|
|
1622
|
-
script: h,
|
|
1623
|
-
value: a
|
|
1624
|
-
};
|
|
1625
|
-
}
|
|
1626
|
-
J.decode = r;
|
|
1627
|
-
function c(i) {
|
|
1628
|
-
const { script: a, value: u } = i, f = n.encodingLength(a.length), h = l.allocUnsafe(8 + f + a.length);
|
|
1629
|
-
return e.writeUInt64LE(h, u, 0), n.encode(a.length, h, 8), a.copy(h, 8 + f), {
|
|
1630
|
-
key: l.from([t.InputTypes.WITNESS_UTXO]),
|
|
1631
|
-
value: h
|
|
1632
|
-
};
|
|
1633
|
-
}
|
|
1634
|
-
J.encode = c, J.expected = "{ script: Buffer; value: number; }";
|
|
1635
|
-
function s(i) {
|
|
1636
|
-
return l.isBuffer(i.script) && typeof i.value == "number";
|
|
1637
|
-
}
|
|
1638
|
-
J.check = s;
|
|
1639
|
-
function o(i, a) {
|
|
1640
|
-
return !!i && !!a && i.witnessUtxo === void 0;
|
|
1641
|
-
}
|
|
1642
|
-
return J.canAdd = o, J;
|
|
1643
|
-
}
|
|
1644
|
-
var Q = {}, tn;
|
|
1645
|
-
function Ks() {
|
|
1646
|
-
if (tn) return Q;
|
|
1647
|
-
tn = 1, Object.defineProperty(Q, "__esModule", { value: !0 });
|
|
1648
|
-
const t = A(), e = fe();
|
|
1649
|
-
function n(o) {
|
|
1650
|
-
if (o.key[0] !== t.OutputTypes.TAP_TREE || o.key.length !== 1)
|
|
1651
|
-
throw new Error(
|
|
1652
|
-
"Decode Error: could not decode tapTree with key 0x" + o.key.toString("hex")
|
|
1653
|
-
);
|
|
1654
|
-
let i = 0;
|
|
1655
|
-
const a = [];
|
|
1656
|
-
for (; i < o.value.length; ) {
|
|
1657
|
-
const u = o.value[i++], f = o.value[i++], h = e.decode(o.value, i);
|
|
1658
|
-
i += e.encodingLength(h), a.push({
|
|
1659
|
-
depth: u,
|
|
1660
|
-
leafVersion: f,
|
|
1661
|
-
script: o.value.slice(i, i + h)
|
|
1662
|
-
}), i += h;
|
|
1663
|
-
}
|
|
1664
|
-
return { leaves: a };
|
|
1665
|
-
}
|
|
1666
|
-
Q.decode = n;
|
|
1667
|
-
function r(o) {
|
|
1668
|
-
const i = l.from([t.OutputTypes.TAP_TREE]), a = [].concat(
|
|
1669
|
-
...o.leaves.map((u) => [
|
|
1670
|
-
l.of(u.depth, u.leafVersion),
|
|
1671
|
-
e.encode(u.script.length),
|
|
1672
|
-
u.script
|
|
1673
|
-
])
|
|
1674
|
-
);
|
|
1675
|
-
return {
|
|
1676
|
-
key: i,
|
|
1677
|
-
value: l.concat(a)
|
|
1678
|
-
};
|
|
1679
|
-
}
|
|
1680
|
-
Q.encode = r, Q.expected = "{ leaves: [{ depth: number; leafVersion: number, script: Buffer; }] }";
|
|
1681
|
-
function c(o) {
|
|
1682
|
-
return Array.isArray(o.leaves) && o.leaves.every(
|
|
1683
|
-
(i) => i.depth >= 0 && i.depth <= 128 && (i.leafVersion & 254) === i.leafVersion && l.isBuffer(i.script)
|
|
1684
|
-
);
|
|
1685
|
-
}
|
|
1686
|
-
Q.check = c;
|
|
1687
|
-
function s(o, i) {
|
|
1688
|
-
return !!o && !!i && o.tapTree === void 0;
|
|
1689
|
-
}
|
|
1690
|
-
return Q.canAdd = s, Q;
|
|
1691
|
-
}
|
|
1692
|
-
var Oe = {}, nn;
|
|
1693
|
-
function nr() {
|
|
1694
|
-
if (nn) return Oe;
|
|
1695
|
-
nn = 1, Object.defineProperty(Oe, "__esModule", { value: !0 });
|
|
1696
|
-
const t = (r) => [...Array(r).keys()], e = (r) => r.length === 33 && [2, 3].includes(r[0]) || r.length === 65 && r[0] === 4;
|
|
1697
|
-
function n(r, c = e) {
|
|
1698
|
-
function s(f) {
|
|
1699
|
-
if (f.key[0] !== r)
|
|
1700
|
-
throw new Error(
|
|
1701
|
-
"Decode Error: could not decode bip32Derivation with key 0x" + f.key.toString("hex")
|
|
1702
|
-
);
|
|
1703
|
-
const h = f.key.slice(1);
|
|
1704
|
-
if (!c(h))
|
|
1705
|
-
throw new Error(
|
|
1706
|
-
"Decode Error: bip32Derivation has invalid pubkey in key 0x" + f.key.toString("hex")
|
|
1707
|
-
);
|
|
1708
|
-
if (f.value.length / 4 % 1 !== 0)
|
|
1709
|
-
throw new Error(
|
|
1710
|
-
"Decode Error: Input BIP32_DERIVATION value length should be multiple of 4"
|
|
1711
|
-
);
|
|
1712
|
-
const g = {
|
|
1713
|
-
masterFingerprint: f.value.slice(0, 4),
|
|
1714
|
-
pubkey: h,
|
|
1715
|
-
path: "m"
|
|
1716
|
-
};
|
|
1717
|
-
for (const y of t(f.value.length / 4 - 1)) {
|
|
1718
|
-
const p = f.value.readUInt32LE(y * 4 + 4), d = !!(p & 2147483648), E = p & 2147483647;
|
|
1719
|
-
g.path += "/" + E.toString(10) + (d ? "'" : "");
|
|
1720
|
-
}
|
|
1721
|
-
return g;
|
|
1722
|
-
}
|
|
1723
|
-
function o(f) {
|
|
1724
|
-
const h = l.from([r]), g = l.concat([h, f.pubkey]), y = f.path.split("/"), p = l.allocUnsafe(y.length * 4);
|
|
1725
|
-
f.masterFingerprint.copy(p, 0);
|
|
1726
|
-
let d = 4;
|
|
1727
|
-
return y.slice(1).forEach((E) => {
|
|
1728
|
-
const b = E.slice(-1) === "'";
|
|
1729
|
-
let S = 2147483647 & parseInt(b ? E.slice(0, -1) : E, 10);
|
|
1730
|
-
b && (S += 2147483648), p.writeUInt32LE(S, d), d += 4;
|
|
1731
|
-
}), {
|
|
1732
|
-
key: g,
|
|
1733
|
-
value: p
|
|
1734
|
-
};
|
|
1735
|
-
}
|
|
1736
|
-
const i = "{ masterFingerprint: Buffer; pubkey: Buffer; path: string; }";
|
|
1737
|
-
function a(f) {
|
|
1738
|
-
return l.isBuffer(f.pubkey) && l.isBuffer(f.masterFingerprint) && typeof f.path == "string" && c(f.pubkey) && f.masterFingerprint.length === 4;
|
|
1739
|
-
}
|
|
1740
|
-
function u(f, h, g) {
|
|
1741
|
-
const y = h.pubkey.toString("hex");
|
|
1742
|
-
return g.has(y) ? !1 : (g.add(y), f.filter((p) => p.pubkey.equals(h.pubkey)).length === 0);
|
|
1743
|
-
}
|
|
1744
|
-
return {
|
|
1745
|
-
decode: s,
|
|
1746
|
-
encode: o,
|
|
1747
|
-
check: a,
|
|
1748
|
-
expected: i,
|
|
1749
|
-
canAddToArray: u
|
|
1750
|
-
};
|
|
1751
|
-
}
|
|
1752
|
-
return Oe.makeConverter = n, Oe;
|
|
1753
|
-
}
|
|
1754
|
-
var Pe = {}, rn;
|
|
1755
|
-
function Ls() {
|
|
1756
|
-
if (rn) return Pe;
|
|
1757
|
-
rn = 1, Object.defineProperty(Pe, "__esModule", { value: !0 });
|
|
1758
|
-
function t(e) {
|
|
1759
|
-
return n;
|
|
1760
|
-
function n(r) {
|
|
1761
|
-
let c;
|
|
1762
|
-
if (e.includes(r.key[0]) && (c = r.key.slice(1), !(c.length === 33 || c.length === 65) || ![2, 3, 4].includes(c[0])))
|
|
1763
|
-
throw new Error(
|
|
1764
|
-
"Format Error: invalid pubkey in key 0x" + r.key.toString("hex")
|
|
1765
|
-
);
|
|
1766
|
-
return c;
|
|
1767
|
-
}
|
|
1768
|
-
}
|
|
1769
|
-
return Pe.makeChecker = t, Pe;
|
|
1770
|
-
}
|
|
1771
|
-
var Ne = {}, sn;
|
|
1772
|
-
function Ms() {
|
|
1773
|
-
if (sn) return Ne;
|
|
1774
|
-
sn = 1, Object.defineProperty(Ne, "__esModule", { value: !0 });
|
|
1775
|
-
function t(e) {
|
|
1776
|
-
function n(i) {
|
|
1777
|
-
if (i.key[0] !== e)
|
|
1778
|
-
throw new Error(
|
|
1779
|
-
"Decode Error: could not decode redeemScript with key 0x" + i.key.toString("hex")
|
|
1780
|
-
);
|
|
1781
|
-
return i.value;
|
|
1782
|
-
}
|
|
1783
|
-
function r(i) {
|
|
1784
|
-
return {
|
|
1785
|
-
key: l.from([e]),
|
|
1786
|
-
value: i
|
|
1787
|
-
};
|
|
1788
|
-
}
|
|
1789
|
-
const c = "Buffer";
|
|
1790
|
-
function s(i) {
|
|
1791
|
-
return l.isBuffer(i);
|
|
1792
|
-
}
|
|
1793
|
-
function o(i, a) {
|
|
1794
|
-
return !!i && !!a && i.redeemScript === void 0;
|
|
1795
|
-
}
|
|
1796
|
-
return {
|
|
1797
|
-
decode: n,
|
|
1798
|
-
encode: r,
|
|
1799
|
-
check: s,
|
|
1800
|
-
expected: c,
|
|
1801
|
-
canAdd: o
|
|
1802
|
-
};
|
|
1803
|
-
}
|
|
1804
|
-
return Ne.makeConverter = t, Ne;
|
|
1805
|
-
}
|
|
1806
|
-
var Ue = {}, on;
|
|
1807
|
-
function Ws() {
|
|
1808
|
-
if (on) return Ue;
|
|
1809
|
-
on = 1, Object.defineProperty(Ue, "__esModule", { value: !0 });
|
|
1810
|
-
const t = fe(), e = nr(), n = (c) => c.length === 32;
|
|
1811
|
-
function r(c) {
|
|
1812
|
-
const s = e.makeConverter(c, n);
|
|
1813
|
-
function o(f) {
|
|
1814
|
-
const h = t.decode(f.value), g = t.encodingLength(h), y = s.decode({
|
|
1815
|
-
key: f.key,
|
|
1816
|
-
value: f.value.slice(g + h * 32)
|
|
1817
|
-
}), p = new Array(h);
|
|
1818
|
-
for (let d = 0, E = g; d < h; d++, E += 32)
|
|
1819
|
-
p[d] = f.value.slice(E, E + 32);
|
|
1820
|
-
return Object.assign({}, y, { leafHashes: p });
|
|
1821
|
-
}
|
|
1822
|
-
function i(f) {
|
|
1823
|
-
const h = s.encode(f), g = t.encodingLength(f.leafHashes.length), y = l.allocUnsafe(g);
|
|
1824
|
-
t.encode(f.leafHashes.length, y);
|
|
1825
|
-
const p = l.concat([y, ...f.leafHashes, h.value]);
|
|
1826
|
-
return Object.assign({}, h, { value: p });
|
|
1827
|
-
}
|
|
1828
|
-
const a = "{ masterFingerprint: Buffer; pubkey: Buffer; path: string; leafHashes: Buffer[]; }";
|
|
1829
|
-
function u(f) {
|
|
1830
|
-
return Array.isArray(f.leafHashes) && f.leafHashes.every(
|
|
1831
|
-
(h) => l.isBuffer(h) && h.length === 32
|
|
1832
|
-
) && s.check(f);
|
|
1833
|
-
}
|
|
1834
|
-
return {
|
|
1835
|
-
decode: o,
|
|
1836
|
-
encode: i,
|
|
1837
|
-
check: u,
|
|
1838
|
-
expected: a,
|
|
1839
|
-
canAddToArray: s.canAddToArray
|
|
1840
|
-
};
|
|
1841
|
-
}
|
|
1842
|
-
return Ue.makeConverter = r, Ue;
|
|
1843
|
-
}
|
|
1844
|
-
var He = {}, cn;
|
|
1845
|
-
function Gs() {
|
|
1846
|
-
if (cn) return He;
|
|
1847
|
-
cn = 1, Object.defineProperty(He, "__esModule", { value: !0 });
|
|
1848
|
-
function t(e) {
|
|
1849
|
-
function n(i) {
|
|
1850
|
-
if (i.key[0] !== e || i.key.length !== 1)
|
|
1851
|
-
throw new Error(
|
|
1852
|
-
"Decode Error: could not decode tapInternalKey with key 0x" + i.key.toString("hex")
|
|
1853
|
-
);
|
|
1854
|
-
if (i.value.length !== 32)
|
|
1855
|
-
throw new Error(
|
|
1856
|
-
"Decode Error: tapInternalKey not a 32-byte x-only pubkey"
|
|
1857
|
-
);
|
|
1858
|
-
return i.value;
|
|
1859
|
-
}
|
|
1860
|
-
function r(i) {
|
|
1861
|
-
return { key: l.from([e]), value: i };
|
|
1862
|
-
}
|
|
1863
|
-
const c = "Buffer";
|
|
1864
|
-
function s(i) {
|
|
1865
|
-
return l.isBuffer(i) && i.length === 32;
|
|
1866
|
-
}
|
|
1867
|
-
function o(i, a) {
|
|
1868
|
-
return !!i && !!a && i.tapInternalKey === void 0;
|
|
1869
|
-
}
|
|
1870
|
-
return {
|
|
1871
|
-
decode: n,
|
|
1872
|
-
encode: r,
|
|
1873
|
-
check: s,
|
|
1874
|
-
expected: c,
|
|
1875
|
-
canAdd: o
|
|
1876
|
-
};
|
|
1877
|
-
}
|
|
1878
|
-
return He.makeConverter = t, He;
|
|
1879
|
-
}
|
|
1880
|
-
var Be = {}, an;
|
|
1881
|
-
function Xs() {
|
|
1882
|
-
if (an) return Be;
|
|
1883
|
-
an = 1, Object.defineProperty(Be, "__esModule", { value: !0 });
|
|
1884
|
-
function t(e) {
|
|
1885
|
-
function n(i) {
|
|
1886
|
-
if (i.key[0] !== e)
|
|
1887
|
-
throw new Error(
|
|
1888
|
-
"Decode Error: could not decode witnessScript with key 0x" + i.key.toString("hex")
|
|
1889
|
-
);
|
|
1890
|
-
return i.value;
|
|
1891
|
-
}
|
|
1892
|
-
function r(i) {
|
|
1893
|
-
return {
|
|
1894
|
-
key: l.from([e]),
|
|
1895
|
-
value: i
|
|
1896
|
-
};
|
|
1897
|
-
}
|
|
1898
|
-
const c = "Buffer";
|
|
1899
|
-
function s(i) {
|
|
1900
|
-
return l.isBuffer(i);
|
|
1901
|
-
}
|
|
1902
|
-
function o(i, a) {
|
|
1903
|
-
return !!i && !!a && i.witnessScript === void 0;
|
|
1904
|
-
}
|
|
1905
|
-
return {
|
|
1906
|
-
decode: n,
|
|
1907
|
-
encode: r,
|
|
1908
|
-
check: s,
|
|
1909
|
-
expected: c,
|
|
1910
|
-
canAdd: o
|
|
1911
|
-
};
|
|
1912
|
-
}
|
|
1913
|
-
return Be.makeConverter = t, Be;
|
|
1914
|
-
}
|
|
1915
|
-
var un;
|
|
1916
|
-
function It() {
|
|
1917
|
-
if (un) return ie;
|
|
1918
|
-
un = 1, Object.defineProperty(ie, "__esModule", { value: !0 });
|
|
1919
|
-
const t = A(), e = vs(), n = ks(), r = As(), c = xs(), s = Cs(), o = Os(), i = Ps(), a = Ns(), u = Us(), f = Hs(), h = Bs(), g = Rs(), y = Fs(), p = Ks(), d = nr(), E = Ls(), b = Ms(), S = Ws(), w = Gs(), _ = Xs(), I = {
|
|
1920
|
-
unsignedTx: n,
|
|
1921
|
-
globalXpub: e,
|
|
1922
|
-
// pass an Array of key bytes that require pubkey beside the key
|
|
1923
|
-
checkPubkey: E.makeChecker([])
|
|
1924
|
-
};
|
|
1925
|
-
ie.globals = I;
|
|
1926
|
-
const P = {
|
|
1927
|
-
nonWitnessUtxo: s,
|
|
1928
|
-
partialSig: o,
|
|
1929
|
-
sighashType: a,
|
|
1930
|
-
finalScriptSig: r,
|
|
1931
|
-
finalScriptWitness: c,
|
|
1932
|
-
porCommitment: i,
|
|
1933
|
-
witnessUtxo: y,
|
|
1934
|
-
bip32Derivation: d.makeConverter(
|
|
1935
|
-
t.InputTypes.BIP32_DERIVATION
|
|
1936
|
-
),
|
|
1937
|
-
redeemScript: b.makeConverter(
|
|
1938
|
-
t.InputTypes.REDEEM_SCRIPT
|
|
1939
|
-
),
|
|
1940
|
-
witnessScript: _.makeConverter(
|
|
1941
|
-
t.InputTypes.WITNESS_SCRIPT
|
|
1942
|
-
),
|
|
1943
|
-
checkPubkey: E.makeChecker([
|
|
1944
|
-
t.InputTypes.PARTIAL_SIG,
|
|
1945
|
-
t.InputTypes.BIP32_DERIVATION
|
|
1946
|
-
]),
|
|
1947
|
-
tapKeySig: u,
|
|
1948
|
-
tapScriptSig: g,
|
|
1949
|
-
tapLeafScript: f,
|
|
1950
|
-
tapBip32Derivation: S.makeConverter(
|
|
1951
|
-
t.InputTypes.TAP_BIP32_DERIVATION
|
|
1952
|
-
),
|
|
1953
|
-
tapInternalKey: w.makeConverter(
|
|
1954
|
-
t.InputTypes.TAP_INTERNAL_KEY
|
|
1955
|
-
),
|
|
1956
|
-
tapMerkleRoot: h
|
|
1957
|
-
};
|
|
1958
|
-
ie.inputs = P;
|
|
1959
|
-
const m = {
|
|
1960
|
-
bip32Derivation: d.makeConverter(
|
|
1961
|
-
t.OutputTypes.BIP32_DERIVATION
|
|
1962
|
-
),
|
|
1963
|
-
redeemScript: b.makeConverter(
|
|
1964
|
-
t.OutputTypes.REDEEM_SCRIPT
|
|
1965
|
-
),
|
|
1966
|
-
witnessScript: _.makeConverter(
|
|
1967
|
-
t.OutputTypes.WITNESS_SCRIPT
|
|
1968
|
-
),
|
|
1969
|
-
checkPubkey: E.makeChecker([
|
|
1970
|
-
t.OutputTypes.BIP32_DERIVATION
|
|
1971
|
-
]),
|
|
1972
|
-
tapBip32Derivation: S.makeConverter(
|
|
1973
|
-
t.OutputTypes.TAP_BIP32_DERIVATION
|
|
1974
|
-
),
|
|
1975
|
-
tapTree: p,
|
|
1976
|
-
tapInternalKey: w.makeConverter(
|
|
1977
|
-
t.OutputTypes.TAP_INTERNAL_KEY
|
|
1978
|
-
)
|
|
1979
|
-
};
|
|
1980
|
-
return ie.outputs = m, ie;
|
|
1981
|
-
}
|
|
1982
|
-
var fn;
|
|
1983
|
-
function Ds() {
|
|
1984
|
-
if (fn) return oe;
|
|
1985
|
-
fn = 1, Object.defineProperty(oe, "__esModule", { value: !0 });
|
|
1986
|
-
const t = It(), e = mt(), n = fe(), r = A();
|
|
1987
|
-
function c(i, a) {
|
|
1988
|
-
let u = 0;
|
|
1989
|
-
function f() {
|
|
1990
|
-
const m = n.decode(i, u);
|
|
1991
|
-
u += n.encodingLength(m);
|
|
1992
|
-
const k = i.slice(u, u + m);
|
|
1993
|
-
return u += m, k;
|
|
1994
|
-
}
|
|
1995
|
-
function h() {
|
|
1996
|
-
const m = i.readUInt32BE(u);
|
|
1997
|
-
return u += 4, m;
|
|
1998
|
-
}
|
|
1999
|
-
function g() {
|
|
2000
|
-
const m = i.readUInt8(u);
|
|
2001
|
-
return u += 1, m;
|
|
2002
|
-
}
|
|
2003
|
-
function y() {
|
|
2004
|
-
const m = f(), k = f();
|
|
2005
|
-
return {
|
|
2006
|
-
key: m,
|
|
2007
|
-
value: k
|
|
2008
|
-
};
|
|
2009
|
-
}
|
|
2010
|
-
function p() {
|
|
2011
|
-
if (u >= i.length)
|
|
2012
|
-
throw new Error("Format Error: Unexpected End of PSBT");
|
|
2013
|
-
const m = i.readUInt8(u) === 0;
|
|
2014
|
-
return m && u++, m;
|
|
2015
|
-
}
|
|
2016
|
-
if (h() !== 1886610036)
|
|
2017
|
-
throw new Error("Format Error: Invalid Magic Number");
|
|
2018
|
-
if (g() !== 255)
|
|
2019
|
-
throw new Error(
|
|
2020
|
-
"Format Error: Magic Number must be followed by 0xff separator"
|
|
2021
|
-
);
|
|
2022
|
-
const d = [], E = {};
|
|
2023
|
-
for (; !p(); ) {
|
|
2024
|
-
const m = y(), k = m.key.toString("hex");
|
|
2025
|
-
if (E[k])
|
|
2026
|
-
throw new Error(
|
|
2027
|
-
"Format Error: Keys must be unique for global keymap: key " + k
|
|
2028
|
-
);
|
|
2029
|
-
E[k] = 1, d.push(m);
|
|
2030
|
-
}
|
|
2031
|
-
const b = d.filter(
|
|
2032
|
-
(m) => m.key[0] === r.GlobalTypes.UNSIGNED_TX
|
|
2033
|
-
);
|
|
2034
|
-
if (b.length !== 1)
|
|
2035
|
-
throw new Error("Format Error: Only one UNSIGNED_TX allowed");
|
|
2036
|
-
const S = a(b[0].value), { inputCount: w, outputCount: _ } = S.getInputOutputCounts(), I = [], P = [];
|
|
2037
|
-
for (const m of e.range(w)) {
|
|
2038
|
-
const k = {}, U = [];
|
|
2039
|
-
for (; !p(); ) {
|
|
2040
|
-
const B = y(), te = B.key.toString("hex");
|
|
2041
|
-
if (k[te])
|
|
2042
|
-
throw new Error(
|
|
2043
|
-
"Format Error: Keys must be unique for each input: input index " + m + " key " + te
|
|
2044
|
-
);
|
|
2045
|
-
k[te] = 1, U.push(B);
|
|
2046
|
-
}
|
|
2047
|
-
I.push(U);
|
|
2048
|
-
}
|
|
2049
|
-
for (const m of e.range(_)) {
|
|
2050
|
-
const k = {}, U = [];
|
|
2051
|
-
for (; !p(); ) {
|
|
2052
|
-
const B = y(), te = B.key.toString("hex");
|
|
2053
|
-
if (k[te])
|
|
2054
|
-
throw new Error(
|
|
2055
|
-
"Format Error: Keys must be unique for each output: output index " + m + " key " + te
|
|
2056
|
-
);
|
|
2057
|
-
k[te] = 1, U.push(B);
|
|
2058
|
-
}
|
|
2059
|
-
P.push(U);
|
|
2060
|
-
}
|
|
2061
|
-
return o(S, {
|
|
2062
|
-
globalMapKeyVals: d,
|
|
2063
|
-
inputKeyVals: I,
|
|
2064
|
-
outputKeyVals: P
|
|
2065
|
-
});
|
|
2066
|
-
}
|
|
2067
|
-
oe.psbtFromBuffer = c;
|
|
2068
|
-
function s(i, a, u) {
|
|
2069
|
-
if (!a.equals(l.from([u])))
|
|
2070
|
-
throw new Error(
|
|
2071
|
-
`Format Error: Invalid ${i} key: ${a.toString("hex")}`
|
|
2072
|
-
);
|
|
2073
|
-
}
|
|
2074
|
-
oe.checkKeyBuffer = s;
|
|
2075
|
-
function o(i, { globalMapKeyVals: a, inputKeyVals: u, outputKeyVals: f }) {
|
|
2076
|
-
const h = {
|
|
2077
|
-
unsignedTx: i
|
|
2078
|
-
};
|
|
2079
|
-
let g = 0;
|
|
2080
|
-
for (const b of a)
|
|
2081
|
-
switch (b.key[0]) {
|
|
2082
|
-
case r.GlobalTypes.UNSIGNED_TX:
|
|
2083
|
-
if (s(
|
|
2084
|
-
"global",
|
|
2085
|
-
b.key,
|
|
2086
|
-
r.GlobalTypes.UNSIGNED_TX
|
|
2087
|
-
), g > 0)
|
|
2088
|
-
throw new Error("Format Error: GlobalMap has multiple UNSIGNED_TX");
|
|
2089
|
-
g++;
|
|
2090
|
-
break;
|
|
2091
|
-
case r.GlobalTypes.GLOBAL_XPUB:
|
|
2092
|
-
h.globalXpub === void 0 && (h.globalXpub = []), h.globalXpub.push(t.globals.globalXpub.decode(b));
|
|
2093
|
-
break;
|
|
2094
|
-
default:
|
|
2095
|
-
h.unknownKeyVals || (h.unknownKeyVals = []), h.unknownKeyVals.push(b);
|
|
2096
|
-
}
|
|
2097
|
-
const y = u.length, p = f.length, d = [], E = [];
|
|
2098
|
-
for (const b of e.range(y)) {
|
|
2099
|
-
const S = {};
|
|
2100
|
-
for (const w of u[b])
|
|
2101
|
-
switch (t.inputs.checkPubkey(w), w.key[0]) {
|
|
2102
|
-
case r.InputTypes.NON_WITNESS_UTXO:
|
|
2103
|
-
if (s(
|
|
2104
|
-
"input",
|
|
2105
|
-
w.key,
|
|
2106
|
-
r.InputTypes.NON_WITNESS_UTXO
|
|
2107
|
-
), S.nonWitnessUtxo !== void 0)
|
|
2108
|
-
throw new Error(
|
|
2109
|
-
"Format Error: Input has multiple NON_WITNESS_UTXO"
|
|
2110
|
-
);
|
|
2111
|
-
S.nonWitnessUtxo = t.inputs.nonWitnessUtxo.decode(w);
|
|
2112
|
-
break;
|
|
2113
|
-
case r.InputTypes.WITNESS_UTXO:
|
|
2114
|
-
if (s(
|
|
2115
|
-
"input",
|
|
2116
|
-
w.key,
|
|
2117
|
-
r.InputTypes.WITNESS_UTXO
|
|
2118
|
-
), S.witnessUtxo !== void 0)
|
|
2119
|
-
throw new Error("Format Error: Input has multiple WITNESS_UTXO");
|
|
2120
|
-
S.witnessUtxo = t.inputs.witnessUtxo.decode(w);
|
|
2121
|
-
break;
|
|
2122
|
-
case r.InputTypes.PARTIAL_SIG:
|
|
2123
|
-
S.partialSig === void 0 && (S.partialSig = []), S.partialSig.push(t.inputs.partialSig.decode(w));
|
|
2124
|
-
break;
|
|
2125
|
-
case r.InputTypes.SIGHASH_TYPE:
|
|
2126
|
-
if (s(
|
|
2127
|
-
"input",
|
|
2128
|
-
w.key,
|
|
2129
|
-
r.InputTypes.SIGHASH_TYPE
|
|
2130
|
-
), S.sighashType !== void 0)
|
|
2131
|
-
throw new Error("Format Error: Input has multiple SIGHASH_TYPE");
|
|
2132
|
-
S.sighashType = t.inputs.sighashType.decode(w);
|
|
2133
|
-
break;
|
|
2134
|
-
case r.InputTypes.REDEEM_SCRIPT:
|
|
2135
|
-
if (s(
|
|
2136
|
-
"input",
|
|
2137
|
-
w.key,
|
|
2138
|
-
r.InputTypes.REDEEM_SCRIPT
|
|
2139
|
-
), S.redeemScript !== void 0)
|
|
2140
|
-
throw new Error("Format Error: Input has multiple REDEEM_SCRIPT");
|
|
2141
|
-
S.redeemScript = t.inputs.redeemScript.decode(w);
|
|
2142
|
-
break;
|
|
2143
|
-
case r.InputTypes.WITNESS_SCRIPT:
|
|
2144
|
-
if (s(
|
|
2145
|
-
"input",
|
|
2146
|
-
w.key,
|
|
2147
|
-
r.InputTypes.WITNESS_SCRIPT
|
|
2148
|
-
), S.witnessScript !== void 0)
|
|
2149
|
-
throw new Error("Format Error: Input has multiple WITNESS_SCRIPT");
|
|
2150
|
-
S.witnessScript = t.inputs.witnessScript.decode(w);
|
|
2151
|
-
break;
|
|
2152
|
-
case r.InputTypes.BIP32_DERIVATION:
|
|
2153
|
-
S.bip32Derivation === void 0 && (S.bip32Derivation = []), S.bip32Derivation.push(
|
|
2154
|
-
t.inputs.bip32Derivation.decode(w)
|
|
2155
|
-
);
|
|
2156
|
-
break;
|
|
2157
|
-
case r.InputTypes.FINAL_SCRIPTSIG:
|
|
2158
|
-
s(
|
|
2159
|
-
"input",
|
|
2160
|
-
w.key,
|
|
2161
|
-
r.InputTypes.FINAL_SCRIPTSIG
|
|
2162
|
-
), S.finalScriptSig = t.inputs.finalScriptSig.decode(w);
|
|
2163
|
-
break;
|
|
2164
|
-
case r.InputTypes.FINAL_SCRIPTWITNESS:
|
|
2165
|
-
s(
|
|
2166
|
-
"input",
|
|
2167
|
-
w.key,
|
|
2168
|
-
r.InputTypes.FINAL_SCRIPTWITNESS
|
|
2169
|
-
), S.finalScriptWitness = t.inputs.finalScriptWitness.decode(
|
|
2170
|
-
w
|
|
2171
|
-
);
|
|
2172
|
-
break;
|
|
2173
|
-
case r.InputTypes.POR_COMMITMENT:
|
|
2174
|
-
s(
|
|
2175
|
-
"input",
|
|
2176
|
-
w.key,
|
|
2177
|
-
r.InputTypes.POR_COMMITMENT
|
|
2178
|
-
), S.porCommitment = t.inputs.porCommitment.decode(w);
|
|
2179
|
-
break;
|
|
2180
|
-
case r.InputTypes.TAP_KEY_SIG:
|
|
2181
|
-
s(
|
|
2182
|
-
"input",
|
|
2183
|
-
w.key,
|
|
2184
|
-
r.InputTypes.TAP_KEY_SIG
|
|
2185
|
-
), S.tapKeySig = t.inputs.tapKeySig.decode(w);
|
|
2186
|
-
break;
|
|
2187
|
-
case r.InputTypes.TAP_SCRIPT_SIG:
|
|
2188
|
-
S.tapScriptSig === void 0 && (S.tapScriptSig = []), S.tapScriptSig.push(t.inputs.tapScriptSig.decode(w));
|
|
2189
|
-
break;
|
|
2190
|
-
case r.InputTypes.TAP_LEAF_SCRIPT:
|
|
2191
|
-
S.tapLeafScript === void 0 && (S.tapLeafScript = []), S.tapLeafScript.push(t.inputs.tapLeafScript.decode(w));
|
|
2192
|
-
break;
|
|
2193
|
-
case r.InputTypes.TAP_BIP32_DERIVATION:
|
|
2194
|
-
S.tapBip32Derivation === void 0 && (S.tapBip32Derivation = []), S.tapBip32Derivation.push(
|
|
2195
|
-
t.inputs.tapBip32Derivation.decode(w)
|
|
2196
|
-
);
|
|
2197
|
-
break;
|
|
2198
|
-
case r.InputTypes.TAP_INTERNAL_KEY:
|
|
2199
|
-
s(
|
|
2200
|
-
"input",
|
|
2201
|
-
w.key,
|
|
2202
|
-
r.InputTypes.TAP_INTERNAL_KEY
|
|
2203
|
-
), S.tapInternalKey = t.inputs.tapInternalKey.decode(w);
|
|
2204
|
-
break;
|
|
2205
|
-
case r.InputTypes.TAP_MERKLE_ROOT:
|
|
2206
|
-
s(
|
|
2207
|
-
"input",
|
|
2208
|
-
w.key,
|
|
2209
|
-
r.InputTypes.TAP_MERKLE_ROOT
|
|
2210
|
-
), S.tapMerkleRoot = t.inputs.tapMerkleRoot.decode(w);
|
|
2211
|
-
break;
|
|
2212
|
-
default:
|
|
2213
|
-
S.unknownKeyVals || (S.unknownKeyVals = []), S.unknownKeyVals.push(w);
|
|
2214
|
-
}
|
|
2215
|
-
d.push(S);
|
|
2216
|
-
}
|
|
2217
|
-
for (const b of e.range(p)) {
|
|
2218
|
-
const S = {};
|
|
2219
|
-
for (const w of f[b])
|
|
2220
|
-
switch (t.outputs.checkPubkey(w), w.key[0]) {
|
|
2221
|
-
case r.OutputTypes.REDEEM_SCRIPT:
|
|
2222
|
-
if (s(
|
|
2223
|
-
"output",
|
|
2224
|
-
w.key,
|
|
2225
|
-
r.OutputTypes.REDEEM_SCRIPT
|
|
2226
|
-
), S.redeemScript !== void 0)
|
|
2227
|
-
throw new Error("Format Error: Output has multiple REDEEM_SCRIPT");
|
|
2228
|
-
S.redeemScript = t.outputs.redeemScript.decode(w);
|
|
2229
|
-
break;
|
|
2230
|
-
case r.OutputTypes.WITNESS_SCRIPT:
|
|
2231
|
-
if (s(
|
|
2232
|
-
"output",
|
|
2233
|
-
w.key,
|
|
2234
|
-
r.OutputTypes.WITNESS_SCRIPT
|
|
2235
|
-
), S.witnessScript !== void 0)
|
|
2236
|
-
throw new Error("Format Error: Output has multiple WITNESS_SCRIPT");
|
|
2237
|
-
S.witnessScript = t.outputs.witnessScript.decode(w);
|
|
2238
|
-
break;
|
|
2239
|
-
case r.OutputTypes.BIP32_DERIVATION:
|
|
2240
|
-
S.bip32Derivation === void 0 && (S.bip32Derivation = []), S.bip32Derivation.push(
|
|
2241
|
-
t.outputs.bip32Derivation.decode(w)
|
|
2242
|
-
);
|
|
2243
|
-
break;
|
|
2244
|
-
case r.OutputTypes.TAP_INTERNAL_KEY:
|
|
2245
|
-
s(
|
|
2246
|
-
"output",
|
|
2247
|
-
w.key,
|
|
2248
|
-
r.OutputTypes.TAP_INTERNAL_KEY
|
|
2249
|
-
), S.tapInternalKey = t.outputs.tapInternalKey.decode(w);
|
|
2250
|
-
break;
|
|
2251
|
-
case r.OutputTypes.TAP_TREE:
|
|
2252
|
-
s(
|
|
2253
|
-
"output",
|
|
2254
|
-
w.key,
|
|
2255
|
-
r.OutputTypes.TAP_TREE
|
|
2256
|
-
), S.tapTree = t.outputs.tapTree.decode(w);
|
|
2257
|
-
break;
|
|
2258
|
-
case r.OutputTypes.TAP_BIP32_DERIVATION:
|
|
2259
|
-
S.tapBip32Derivation === void 0 && (S.tapBip32Derivation = []), S.tapBip32Derivation.push(
|
|
2260
|
-
t.outputs.tapBip32Derivation.decode(w)
|
|
2261
|
-
);
|
|
2262
|
-
break;
|
|
2263
|
-
default:
|
|
2264
|
-
S.unknownKeyVals || (S.unknownKeyVals = []), S.unknownKeyVals.push(w);
|
|
2265
|
-
}
|
|
2266
|
-
E.push(S);
|
|
2267
|
-
}
|
|
2268
|
-
return { globalMap: h, inputs: d, outputs: E };
|
|
2269
|
-
}
|
|
2270
|
-
return oe.psbtFromKeyVals = o, oe;
|
|
2271
|
-
}
|
|
2272
|
-
var he = {}, hn;
|
|
2273
|
-
function qs() {
|
|
2274
|
-
if (hn) return he;
|
|
2275
|
-
hn = 1, Object.defineProperty(he, "__esModule", { value: !0 });
|
|
2276
|
-
const t = It(), e = mt();
|
|
2277
|
-
function n({ globalMap: o, inputs: i, outputs: a }) {
|
|
2278
|
-
const { globalKeyVals: u, inputKeyVals: f, outputKeyVals: h } = s({
|
|
2279
|
-
globalMap: o,
|
|
2280
|
-
inputs: i,
|
|
2281
|
-
outputs: a
|
|
2282
|
-
}), g = e.keyValsToBuffer(u), y = (b) => b.length === 0 ? [l.from([0])] : b.map(e.keyValsToBuffer), p = y(f), d = y(h), E = l.allocUnsafe(5);
|
|
2283
|
-
return E.writeUIntBE(482972169471, 0, 5), l.concat(
|
|
2284
|
-
[E, g].concat(p, d)
|
|
2285
|
-
);
|
|
2286
|
-
}
|
|
2287
|
-
he.psbtToBuffer = n;
|
|
2288
|
-
const r = (o, i) => o.key.compare(i.key);
|
|
2289
|
-
function c(o, i) {
|
|
2290
|
-
const a = /* @__PURE__ */ new Set(), u = Object.entries(o).reduce((h, [g, y]) => {
|
|
2291
|
-
if (g === "unknownKeyVals") return h;
|
|
2292
|
-
const p = i[g];
|
|
2293
|
-
if (p === void 0) return h;
|
|
2294
|
-
const d = (Array.isArray(y) ? y : [y]).map(
|
|
2295
|
-
p.encode
|
|
2296
|
-
);
|
|
2297
|
-
return d.map((b) => b.key.toString("hex")).forEach((b) => {
|
|
2298
|
-
if (a.has(b))
|
|
2299
|
-
throw new Error("Serialize Error: Duplicate key: " + b);
|
|
2300
|
-
a.add(b);
|
|
2301
|
-
}), h.concat(d);
|
|
2302
|
-
}, []), f = o.unknownKeyVals ? o.unknownKeyVals.filter((h) => !a.has(h.key.toString("hex"))) : [];
|
|
2303
|
-
return u.concat(f).sort(r);
|
|
2304
|
-
}
|
|
2305
|
-
function s({ globalMap: o, inputs: i, outputs: a }) {
|
|
2306
|
-
return {
|
|
2307
|
-
globalKeyVals: c(o, t.globals),
|
|
2308
|
-
inputKeyVals: i.map((u) => c(u, t.inputs)),
|
|
2309
|
-
outputKeyVals: a.map((u) => c(u, t.outputs))
|
|
2310
|
-
};
|
|
2311
|
-
}
|
|
2312
|
-
return he.psbtToKeyVals = s, he;
|
|
2313
|
-
}
|
|
2314
|
-
var pn;
|
|
2315
|
-
function rr() {
|
|
2316
|
-
return pn || (pn = 1, (function(t) {
|
|
2317
|
-
function e(n) {
|
|
2318
|
-
for (var r in n) t.hasOwnProperty(r) || (t[r] = n[r]);
|
|
2319
|
-
}
|
|
2320
|
-
Object.defineProperty(t, "__esModule", { value: !0 }), e(Ds()), e(qs());
|
|
2321
|
-
})(st)), st;
|
|
2322
|
-
}
|
|
2323
|
-
var ln;
|
|
2324
|
-
function Vs() {
|
|
2325
|
-
if (ln) return xe;
|
|
2326
|
-
ln = 1, Object.defineProperty(xe, "__esModule", { value: !0 });
|
|
2327
|
-
const t = rr();
|
|
2328
|
-
function e(s) {
|
|
2329
|
-
const o = s[0], i = t.psbtToKeyVals(o), a = s.slice(1);
|
|
2330
|
-
if (a.length === 0) throw new Error("Combine: Nothing to combine");
|
|
2331
|
-
const u = r(o);
|
|
2332
|
-
if (u === void 0)
|
|
2333
|
-
throw new Error("Combine: Self missing transaction");
|
|
2334
|
-
const f = c(i.globalKeyVals), h = i.inputKeyVals.map(c), g = i.outputKeyVals.map(c);
|
|
2335
|
-
for (const y of a) {
|
|
2336
|
-
const p = r(y);
|
|
2337
|
-
if (p === void 0 || !p.toBuffer().equals(u.toBuffer()))
|
|
2338
|
-
throw new Error(
|
|
2339
|
-
"Combine: One of the Psbts does not have the same transaction."
|
|
2340
|
-
);
|
|
2341
|
-
const d = t.psbtToKeyVals(y);
|
|
2342
|
-
c(d.globalKeyVals).forEach(
|
|
2343
|
-
n(
|
|
2344
|
-
f,
|
|
2345
|
-
i.globalKeyVals,
|
|
2346
|
-
d.globalKeyVals
|
|
2347
|
-
)
|
|
2348
|
-
), d.inputKeyVals.map(c).forEach(
|
|
2349
|
-
(w, _) => w.forEach(
|
|
2350
|
-
n(
|
|
2351
|
-
h[_],
|
|
2352
|
-
i.inputKeyVals[_],
|
|
2353
|
-
d.inputKeyVals[_]
|
|
2354
|
-
)
|
|
2355
|
-
)
|
|
2356
|
-
), d.outputKeyVals.map(c).forEach(
|
|
2357
|
-
(w, _) => w.forEach(
|
|
2358
|
-
n(
|
|
2359
|
-
g[_],
|
|
2360
|
-
i.outputKeyVals[_],
|
|
2361
|
-
d.outputKeyVals[_]
|
|
2362
|
-
)
|
|
2363
|
-
)
|
|
2364
|
-
);
|
|
2365
|
-
}
|
|
2366
|
-
return t.psbtFromKeyVals(u, {
|
|
2367
|
-
globalMapKeyVals: i.globalKeyVals,
|
|
2368
|
-
inputKeyVals: i.inputKeyVals,
|
|
2369
|
-
outputKeyVals: i.outputKeyVals
|
|
2370
|
-
});
|
|
2371
|
-
}
|
|
2372
|
-
xe.combine = e;
|
|
2373
|
-
function n(s, o, i) {
|
|
2374
|
-
return (a) => {
|
|
2375
|
-
if (s.has(a)) return;
|
|
2376
|
-
const u = i.filter((f) => f.key.toString("hex") === a)[0];
|
|
2377
|
-
o.push(u), s.add(a);
|
|
2378
|
-
};
|
|
2379
|
-
}
|
|
2380
|
-
function r(s) {
|
|
2381
|
-
return s.globalMap.unsignedTx;
|
|
2382
|
-
}
|
|
2383
|
-
function c(s) {
|
|
2384
|
-
const o = /* @__PURE__ */ new Set();
|
|
2385
|
-
return s.forEach((i) => {
|
|
2386
|
-
const a = i.key.toString("hex");
|
|
2387
|
-
if (o.has(a))
|
|
2388
|
-
throw new Error("Combine: KeyValue Map keys should be unique");
|
|
2389
|
-
o.add(a);
|
|
2390
|
-
}), o;
|
|
2391
|
-
}
|
|
2392
|
-
return xe;
|
|
2393
|
-
}
|
|
2394
|
-
var it = {}, dn;
|
|
2395
|
-
function sr() {
|
|
2396
|
-
return dn || (dn = 1, (function(t) {
|
|
2397
|
-
Object.defineProperty(t, "__esModule", { value: !0 });
|
|
2398
|
-
const e = It();
|
|
2399
|
-
function n(y, p) {
|
|
2400
|
-
const d = y[p];
|
|
2401
|
-
if (d === void 0) throw new Error(`No input #${p}`);
|
|
2402
|
-
return d;
|
|
2403
|
-
}
|
|
2404
|
-
t.checkForInput = n;
|
|
2405
|
-
function r(y, p) {
|
|
2406
|
-
const d = y[p];
|
|
2407
|
-
if (d === void 0) throw new Error(`No output #${p}`);
|
|
2408
|
-
return d;
|
|
2409
|
-
}
|
|
2410
|
-
t.checkForOutput = r;
|
|
2411
|
-
function c(y, p, d) {
|
|
2412
|
-
if (y.key[0] < d)
|
|
2413
|
-
throw new Error(
|
|
2414
|
-
"Use the method for your specific key instead of addUnknownKeyVal*"
|
|
2415
|
-
);
|
|
2416
|
-
if (p && p.filter((E) => E.key.equals(y.key)).length !== 0)
|
|
2417
|
-
throw new Error(`Duplicate Key: ${y.key.toString("hex")}`);
|
|
2418
|
-
}
|
|
2419
|
-
t.checkHasKey = c;
|
|
2420
|
-
function s(y) {
|
|
2421
|
-
let p = 0;
|
|
2422
|
-
return Object.keys(y).forEach((d) => {
|
|
2423
|
-
Number(isNaN(Number(d))) && p++;
|
|
2424
|
-
}), p;
|
|
2425
|
-
}
|
|
2426
|
-
t.getEnumLength = s;
|
|
2427
|
-
function o(y, p) {
|
|
2428
|
-
let d = !1;
|
|
2429
|
-
if (p.nonWitnessUtxo || p.witnessUtxo) {
|
|
2430
|
-
const E = !!p.redeemScript, b = !!p.witnessScript, S = !E || !!p.finalScriptSig, w = !b || !!p.finalScriptWitness, _ = !!p.finalScriptSig || !!p.finalScriptWitness;
|
|
2431
|
-
d = S && w && _;
|
|
2432
|
-
}
|
|
2433
|
-
if (d === !1)
|
|
2434
|
-
throw new Error(
|
|
2435
|
-
`Input #${y} has too much or too little data to clean`
|
|
2436
|
-
);
|
|
2437
|
-
}
|
|
2438
|
-
t.inputCheckUncleanFinalized = o;
|
|
2439
|
-
function i(y, p, d, E) {
|
|
2440
|
-
throw new Error(
|
|
2441
|
-
`Data for ${y} key ${p} is incorrect: Expected ${d} and got ${JSON.stringify(E)}`
|
|
2442
|
-
);
|
|
2443
|
-
}
|
|
2444
|
-
function a(y) {
|
|
2445
|
-
return (p, d) => {
|
|
2446
|
-
for (const E of Object.keys(p)) {
|
|
2447
|
-
const b = p[E], { canAdd: S, canAddToArray: w, check: _, expected: I } = (
|
|
2448
|
-
// @ts-ignore
|
|
2449
|
-
e[y + "s"][E] || {}
|
|
2450
|
-
), P = !!w;
|
|
2451
|
-
if (_)
|
|
2452
|
-
if (P) {
|
|
2453
|
-
if (!Array.isArray(b) || // @ts-ignore
|
|
2454
|
-
d[E] && !Array.isArray(d[E]))
|
|
2455
|
-
throw new Error(`Key type ${E} must be an array`);
|
|
2456
|
-
b.every(_) || i(y, E, I, b);
|
|
2457
|
-
const m = d[E] || [], k = /* @__PURE__ */ new Set();
|
|
2458
|
-
if (!b.every((U) => w(m, U, k)))
|
|
2459
|
-
throw new Error("Can not add duplicate data to array");
|
|
2460
|
-
d[E] = m.concat(b);
|
|
2461
|
-
} else {
|
|
2462
|
-
if (_(b) || i(y, E, I, b), !S(d, b))
|
|
2463
|
-
throw new Error(`Can not add duplicate data to ${y}`);
|
|
2464
|
-
d[E] = b;
|
|
2465
|
-
}
|
|
2466
|
-
}
|
|
2467
|
-
};
|
|
2468
|
-
}
|
|
2469
|
-
t.updateGlobal = a("global"), t.updateInput = a("input"), t.updateOutput = a("output");
|
|
2470
|
-
function u(y, p) {
|
|
2471
|
-
const d = y.length - 1, E = n(y, d);
|
|
2472
|
-
t.updateInput(p, E);
|
|
2473
|
-
}
|
|
2474
|
-
t.addInputAttributes = u;
|
|
2475
|
-
function f(y, p) {
|
|
2476
|
-
const d = y.length - 1, E = r(y, d);
|
|
2477
|
-
t.updateOutput(p, E);
|
|
2478
|
-
}
|
|
2479
|
-
t.addOutputAttributes = f;
|
|
2480
|
-
function h(y, p) {
|
|
2481
|
-
if (!l.isBuffer(p) || p.length < 4)
|
|
2482
|
-
throw new Error("Set Version: Invalid Transaction");
|
|
2483
|
-
return p.writeUInt32LE(y, 0), p;
|
|
2484
|
-
}
|
|
2485
|
-
t.defaultVersionSetter = h;
|
|
2486
|
-
function g(y, p) {
|
|
2487
|
-
if (!l.isBuffer(p) || p.length < 4)
|
|
2488
|
-
throw new Error("Set Locktime: Invalid Transaction");
|
|
2489
|
-
return p.writeUInt32LE(y, p.length - 4), p;
|
|
2490
|
-
}
|
|
2491
|
-
t.defaultLocktimeSetter = g;
|
|
2492
|
-
})(it)), it;
|
|
2493
|
-
}
|
|
2494
|
-
var gn;
|
|
2495
|
-
function js() {
|
|
2496
|
-
if (gn) return Ae;
|
|
2497
|
-
gn = 1, Object.defineProperty(Ae, "__esModule", { value: !0 });
|
|
2498
|
-
const t = Vs(), e = rr(), n = A(), r = sr();
|
|
2499
|
-
class c {
|
|
2500
|
-
constructor(o) {
|
|
2501
|
-
this.inputs = [], this.outputs = [], this.globalMap = {
|
|
2502
|
-
unsignedTx: o
|
|
2503
|
-
};
|
|
2504
|
-
}
|
|
2505
|
-
static fromBase64(o, i) {
|
|
2506
|
-
const a = l.from(o, "base64");
|
|
2507
|
-
return this.fromBuffer(a, i);
|
|
2508
|
-
}
|
|
2509
|
-
static fromHex(o, i) {
|
|
2510
|
-
const a = l.from(o, "hex");
|
|
2511
|
-
return this.fromBuffer(a, i);
|
|
2512
|
-
}
|
|
2513
|
-
static fromBuffer(o, i) {
|
|
2514
|
-
const a = e.psbtFromBuffer(o, i), u = new this(a.globalMap.unsignedTx);
|
|
2515
|
-
return Object.assign(u, a), u;
|
|
2516
|
-
}
|
|
2517
|
-
toBase64() {
|
|
2518
|
-
return this.toBuffer().toString("base64");
|
|
2519
|
-
}
|
|
2520
|
-
toHex() {
|
|
2521
|
-
return this.toBuffer().toString("hex");
|
|
2522
|
-
}
|
|
2523
|
-
toBuffer() {
|
|
2524
|
-
return e.psbtToBuffer(this);
|
|
2525
|
-
}
|
|
2526
|
-
updateGlobal(o) {
|
|
2527
|
-
return r.updateGlobal(o, this.globalMap), this;
|
|
2528
|
-
}
|
|
2529
|
-
updateInput(o, i) {
|
|
2530
|
-
const a = r.checkForInput(this.inputs, o);
|
|
2531
|
-
return r.updateInput(i, a), this;
|
|
2532
|
-
}
|
|
2533
|
-
updateOutput(o, i) {
|
|
2534
|
-
const a = r.checkForOutput(this.outputs, o);
|
|
2535
|
-
return r.updateOutput(i, a), this;
|
|
2536
|
-
}
|
|
2537
|
-
addUnknownKeyValToGlobal(o) {
|
|
2538
|
-
return r.checkHasKey(
|
|
2539
|
-
o,
|
|
2540
|
-
this.globalMap.unknownKeyVals,
|
|
2541
|
-
r.getEnumLength(n.GlobalTypes)
|
|
2542
|
-
), this.globalMap.unknownKeyVals || (this.globalMap.unknownKeyVals = []), this.globalMap.unknownKeyVals.push(o), this;
|
|
2543
|
-
}
|
|
2544
|
-
addUnknownKeyValToInput(o, i) {
|
|
2545
|
-
const a = r.checkForInput(this.inputs, o);
|
|
2546
|
-
return r.checkHasKey(
|
|
2547
|
-
i,
|
|
2548
|
-
a.unknownKeyVals,
|
|
2549
|
-
r.getEnumLength(n.InputTypes)
|
|
2550
|
-
), a.unknownKeyVals || (a.unknownKeyVals = []), a.unknownKeyVals.push(i), this;
|
|
2551
|
-
}
|
|
2552
|
-
addUnknownKeyValToOutput(o, i) {
|
|
2553
|
-
const a = r.checkForOutput(this.outputs, o);
|
|
2554
|
-
return r.checkHasKey(
|
|
2555
|
-
i,
|
|
2556
|
-
a.unknownKeyVals,
|
|
2557
|
-
r.getEnumLength(n.OutputTypes)
|
|
2558
|
-
), a.unknownKeyVals || (a.unknownKeyVals = []), a.unknownKeyVals.push(i), this;
|
|
2559
|
-
}
|
|
2560
|
-
addInput(o) {
|
|
2561
|
-
this.globalMap.unsignedTx.addInput(o), this.inputs.push({
|
|
2562
|
-
unknownKeyVals: []
|
|
2563
|
-
});
|
|
2564
|
-
const i = o.unknownKeyVals || [], a = this.inputs.length - 1;
|
|
2565
|
-
if (!Array.isArray(i))
|
|
2566
|
-
throw new Error("unknownKeyVals must be an Array");
|
|
2567
|
-
return i.forEach(
|
|
2568
|
-
(u) => this.addUnknownKeyValToInput(a, u)
|
|
2569
|
-
), r.addInputAttributes(this.inputs, o), this;
|
|
2570
|
-
}
|
|
2571
|
-
addOutput(o) {
|
|
2572
|
-
this.globalMap.unsignedTx.addOutput(o), this.outputs.push({
|
|
2573
|
-
unknownKeyVals: []
|
|
2574
|
-
});
|
|
2575
|
-
const i = o.unknownKeyVals || [], a = this.outputs.length - 1;
|
|
2576
|
-
if (!Array.isArray(i))
|
|
2577
|
-
throw new Error("unknownKeyVals must be an Array");
|
|
2578
|
-
return i.forEach(
|
|
2579
|
-
(u) => this.addUnknownKeyValToOutput(a, u)
|
|
2580
|
-
), r.addOutputAttributes(this.outputs, o), this;
|
|
2581
|
-
}
|
|
2582
|
-
clearFinalizedInput(o) {
|
|
2583
|
-
const i = r.checkForInput(this.inputs, o);
|
|
2584
|
-
r.inputCheckUncleanFinalized(o, i);
|
|
2585
|
-
for (const a of Object.keys(i))
|
|
2586
|
-
[
|
|
2587
|
-
"witnessUtxo",
|
|
2588
|
-
"nonWitnessUtxo",
|
|
2589
|
-
"finalScriptSig",
|
|
2590
|
-
"finalScriptWitness",
|
|
2591
|
-
"unknownKeyVals"
|
|
2592
|
-
].includes(a) || delete i[a];
|
|
2593
|
-
return this;
|
|
2594
|
-
}
|
|
2595
|
-
combine(...o) {
|
|
2596
|
-
const i = t.combine([this].concat(o));
|
|
2597
|
-
return Object.assign(this, i), this;
|
|
2598
|
-
}
|
|
2599
|
-
getTransaction() {
|
|
2600
|
-
return this.globalMap.unsignedTx.toBuffer();
|
|
2601
|
-
}
|
|
2602
|
-
}
|
|
2603
|
-
return Ae.Psbt = c, Ae;
|
|
2604
|
-
}
|
|
2605
|
-
var yn = js(), dt = fe(), x = sr();
|
|
2606
|
-
function ee(t) {
|
|
2607
|
-
return (e) => {
|
|
2608
|
-
try {
|
|
2609
|
-
return t({ output: e }), !0;
|
|
2610
|
-
} catch {
|
|
2611
|
-
return !1;
|
|
2612
|
-
}
|
|
2613
|
-
};
|
|
2614
|
-
}
|
|
2615
|
-
const zs = ee(De), Ys = ee(Pn), $s = ee(we), $e = ee(Xe), Sn = ee(be), or = ee(Ee), vt = ee(Te), Xo = ee(On), Do = (t) => t.length === 4 && t[0] === 81 && // OP_1
|
|
2616
|
-
t[1] === 2 && // push 2 bytes
|
|
2617
|
-
t[2] === 78 && t[3] === 115;
|
|
2618
|
-
function ye(t) {
|
|
2619
|
-
let e = l.allocUnsafe(0);
|
|
2620
|
-
function n(o) {
|
|
2621
|
-
e = l.concat([e, l.from(o)]);
|
|
2622
|
-
}
|
|
2623
|
-
function r(o) {
|
|
2624
|
-
const i = e.length, a = dt.encodingLength(o);
|
|
2625
|
-
e = l.concat([e, l.allocUnsafe(a)]), dt.encode(o, e, i);
|
|
2626
|
-
}
|
|
2627
|
-
function c(o) {
|
|
2628
|
-
r(o.length), n(o);
|
|
2629
|
-
}
|
|
2630
|
-
function s(o) {
|
|
2631
|
-
r(o.length), o.forEach(c);
|
|
2632
|
-
}
|
|
2633
|
-
return s(t), e;
|
|
2634
|
-
}
|
|
2635
|
-
function ir(t, e) {
|
|
2636
|
-
const n = ue(e);
|
|
2637
|
-
if (n === null) throw new Error("Unknown script error");
|
|
2638
|
-
const r = et(t), c = ge(t), s = _s(t), o = s?.hybrid ? et(s.hybrid) : void 0, i = s?.uncompressed ? et(s.uncompressed) : void 0;
|
|
2639
|
-
return n.findIndex((a) => {
|
|
2640
|
-
if (typeof a == "number") return !1;
|
|
2641
|
-
if (ke(a, t) || ke(a, c) || a.equals(r) || s && (ke(a, s.uncompressed) || ke(a, s.hybrid) || o && a.equals(o) || i && a.equals(i)))
|
|
2642
|
-
return !0;
|
|
2643
|
-
});
|
|
2644
|
-
}
|
|
2645
|
-
function Ze(t, e) {
|
|
2646
|
-
return ir(t, e) !== -1;
|
|
2647
|
-
}
|
|
2648
|
-
function Zs(t, e) {
|
|
2649
|
-
return Js(t).some((r) => cr(r, de.decode, e));
|
|
2650
|
-
}
|
|
2651
|
-
function cr(t, e, n) {
|
|
2652
|
-
const { hashType: r } = e(t), c = [];
|
|
2653
|
-
switch (r & v.SIGHASH_ANYONECANPAY && c.push("addInput"), r & 31) {
|
|
2654
|
-
case v.SIGHASH_ALL:
|
|
2655
|
-
break;
|
|
2656
|
-
case v.SIGHASH_SINGLE:
|
|
2657
|
-
case v.SIGHASH_NONE:
|
|
2658
|
-
c.push("addOutput"), c.push("setInputSequence");
|
|
2659
|
-
break;
|
|
2660
|
-
}
|
|
2661
|
-
return c.indexOf(n) === -1;
|
|
2662
|
-
}
|
|
2663
|
-
function Js(t) {
|
|
2664
|
-
const { partialSig: e } = t;
|
|
2665
|
-
let n;
|
|
2666
|
-
if (!e || e.length === 0) {
|
|
2667
|
-
if (!t.finalScriptSig && !t.finalScriptWitness) return [];
|
|
2668
|
-
n = Qs(t);
|
|
2669
|
-
} else
|
|
2670
|
-
n = e;
|
|
2671
|
-
return n.map((r) => r.signature);
|
|
2672
|
-
}
|
|
2673
|
-
function Qs(t) {
|
|
2674
|
-
const e = t.finalScriptSig ? ue(t.finalScriptSig) || [] : [], n = t.finalScriptWitness ? ue(t.finalScriptWitness) || [] : [];
|
|
2675
|
-
return e.concat(n).filter((r) => l.isBuffer(r) && Un(r)).map((r) => ({ signature: r }));
|
|
2676
|
-
}
|
|
2677
|
-
function wn(t, e, n) {
|
|
2678
|
-
const r = lo(e, t, n);
|
|
2679
|
-
try {
|
|
2680
|
-
const s = ho(e, r).concat(r.script).concat(r.controlBlock);
|
|
2681
|
-
return { finalScriptWitness: ye(s) };
|
|
2682
|
-
} catch (c) {
|
|
2683
|
-
throw new Error(`Can not finalize taproot input #${t}: ${c}`);
|
|
2684
|
-
}
|
|
2685
|
-
}
|
|
2686
|
-
function Re(t, e) {
|
|
2687
|
-
const n = e ? l.from([e]) : l.from([]);
|
|
2688
|
-
return l.concat([t, n]);
|
|
2689
|
-
}
|
|
2690
|
-
function N(t) {
|
|
2691
|
-
return t && !!(t.tapInternalKey || t.tapMerkleRoot || t.tapLeafScript && t.tapLeafScript.length || t.tapBip32Derivation && t.tapBip32Derivation.length || t.witnessUtxo && vt(t.witnessUtxo.script));
|
|
2692
|
-
}
|
|
2693
|
-
function ct(t, e) {
|
|
2694
|
-
return t && !!(t.tapInternalKey || t.tapTree || t.tapBip32Derivation && t.tapBip32Derivation.length || e && vt(e));
|
|
2695
|
-
}
|
|
2696
|
-
function En(t, e, n) {
|
|
2697
|
-
ao(t, e, n), fo(t, e, n);
|
|
2698
|
-
}
|
|
2699
|
-
function bn(t, e, n) {
|
|
2700
|
-
uo(t, e, n), eo(t, e);
|
|
2701
|
-
}
|
|
2702
|
-
function eo(t, e) {
|
|
2703
|
-
if (!e.tapTree && !e.tapInternalKey) return;
|
|
2704
|
-
const n = e.tapInternalKey || t.tapInternalKey, r = e.tapTree || t.tapTree;
|
|
2705
|
-
if (n) {
|
|
2706
|
-
const c = t.script, s = to(n, r);
|
|
2707
|
-
if (c && !c.equals(s))
|
|
2708
|
-
throw new Error("Error adding output. Script or address missmatch.");
|
|
2709
|
-
}
|
|
2710
|
-
}
|
|
2711
|
-
function to(t, e) {
|
|
2712
|
-
const n = e && no(e.leaves), { output: r } = Te({
|
|
2713
|
-
internalPubkey: t,
|
|
2714
|
-
scriptTree: n
|
|
2715
|
-
});
|
|
2716
|
-
if (!r) throw new Error("Failed to generate taproot script pubkey");
|
|
2717
|
-
return r;
|
|
2718
|
-
}
|
|
2719
|
-
function qo(t, e) {
|
|
2720
|
-
const n = e.tapInternalKey, r = n && Tr(n, e.tapMerkleRoot);
|
|
2721
|
-
if (!r)
|
|
2722
|
-
throw new Error(
|
|
2723
|
-
`Cannot tweak tap internal key for input #${t}. Public key: ${n && n.toString("hex")}`
|
|
2724
|
-
);
|
|
2725
|
-
return r.x;
|
|
2726
|
-
}
|
|
2727
|
-
function Vo(t) {
|
|
2728
|
-
if (!Pr(t))
|
|
2729
|
-
throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");
|
|
2730
|
-
return gt(t);
|
|
2731
|
-
}
|
|
2732
|
-
function no(t = []) {
|
|
2733
|
-
return t.length === 1 && t[0].depth === 0 ? {
|
|
2734
|
-
output: t[0].script,
|
|
2735
|
-
version: t[0].leafVersion
|
|
2736
|
-
} : co(t);
|
|
2737
|
-
}
|
|
2738
|
-
function ro(t, e) {
|
|
2739
|
-
return oo(t).some((r) => cr(r, so, e));
|
|
2740
|
-
}
|
|
2741
|
-
function so(t) {
|
|
2742
|
-
return {
|
|
2743
|
-
signature: t.subarray(0, 64),
|
|
2744
|
-
hashType: t.subarray(64)[0] || v.SIGHASH_DEFAULT
|
|
2745
|
-
};
|
|
2746
|
-
}
|
|
2747
|
-
function oo(t) {
|
|
2748
|
-
const e = [];
|
|
2749
|
-
if (t.tapKeySig && e.push(t.tapKeySig), t.tapScriptSig && e.push(...t.tapScriptSig.map((n) => n.signature)), !e.length) {
|
|
2750
|
-
const n = io(t.finalScriptWitness);
|
|
2751
|
-
n && e.push(n);
|
|
2752
|
-
}
|
|
2753
|
-
return e;
|
|
2754
|
-
}
|
|
2755
|
-
function io(t) {
|
|
2756
|
-
if (!t) return;
|
|
2757
|
-
const e = t.subarray(2);
|
|
2758
|
-
if (e.length === 64 || e.length === 65) return e;
|
|
2759
|
-
}
|
|
2760
|
-
function gt(t, e = [], n = 0) {
|
|
2761
|
-
if (n > Nn) throw new Error("Max taptree depth exceeded.");
|
|
2762
|
-
return t ? Hn(t) ? (e.push({
|
|
2763
|
-
depth: n,
|
|
2764
|
-
leafVersion: t.version || _r,
|
|
2765
|
-
script: t.output
|
|
2766
|
-
}), e) : (t[0] && gt(t[0], e, n + 1), t[1] && gt(t[1], e, n + 1), e) : [];
|
|
2767
|
-
}
|
|
2768
|
-
function co(t) {
|
|
2769
|
-
let e;
|
|
2770
|
-
for (const n of t)
|
|
2771
|
-
if (e = yt(n, e), !e) throw new Error("No room left to insert tapleaf in tree");
|
|
2772
|
-
return e;
|
|
2773
|
-
}
|
|
2774
|
-
function yt(t, e, n = 0) {
|
|
2775
|
-
if (n > Nn) throw new Error("Max taptree depth exceeded.");
|
|
2776
|
-
if (t.depth === n)
|
|
2777
|
-
return e ? void 0 : {
|
|
2778
|
-
output: t.script,
|
|
2779
|
-
version: t.leafVersion
|
|
2780
|
-
};
|
|
2781
|
-
if (Hn(e)) return;
|
|
2782
|
-
const r = yt(t, e && e[0], n + 1);
|
|
2783
|
-
if (r) return [r, e && e[1]];
|
|
2784
|
-
const c = yt(t, e && e[1], n + 1);
|
|
2785
|
-
if (c) return [e && e[0], c];
|
|
2786
|
-
}
|
|
2787
|
-
function ao(t, e, n) {
|
|
2788
|
-
const r = N(t) && ae(e), c = ae(t) && N(e), s = t === e && N(e) && ae(e);
|
|
2789
|
-
if (r || c || s)
|
|
2790
|
-
throw new Error(
|
|
2791
|
-
`Invalid arguments for Psbt.${n}. Cannot use both taproot and non-taproot fields.`
|
|
2792
|
-
);
|
|
2793
|
-
}
|
|
2794
|
-
function uo(t, e, n) {
|
|
2795
|
-
const r = ct(t) && ae(e), c = ae(t) && ct(e), s = t === e && ct(e) && ae(e);
|
|
2796
|
-
if (r || c || s)
|
|
2797
|
-
throw new Error(
|
|
2798
|
-
`Invalid arguments for Psbt.${n}. Cannot use both taproot and non-taproot fields.`
|
|
2799
|
-
);
|
|
2800
|
-
}
|
|
2801
|
-
function fo(t, e, n) {
|
|
2802
|
-
if (e.tapMerkleRoot) {
|
|
2803
|
-
const r = (e.tapLeafScript || []).every(
|
|
2804
|
-
(s) => at(s, e.tapMerkleRoot)
|
|
2805
|
-
), c = (t.tapLeafScript || []).every(
|
|
2806
|
-
(s) => at(s, e.tapMerkleRoot)
|
|
2807
|
-
);
|
|
2808
|
-
if (!r || !c)
|
|
2809
|
-
throw new Error(`Invalid arguments for Psbt.${n}. Tapleaf not part of taptree.`);
|
|
2810
|
-
} else if (t.tapMerkleRoot && !(e.tapLeafScript || []).every(
|
|
2811
|
-
(c) => at(c, t.tapMerkleRoot)
|
|
2812
|
-
))
|
|
2813
|
-
throw new Error(`Invalid arguments for Psbt.${n}. Tapleaf not part of taptree.`);
|
|
2814
|
-
}
|
|
2815
|
-
function at(t, e) {
|
|
2816
|
-
if (!e) return !0;
|
|
2817
|
-
const n = qe({
|
|
2818
|
-
output: t.script,
|
|
2819
|
-
version: t.leafVersion
|
|
2820
|
-
});
|
|
2821
|
-
return mr(t.controlBlock, n).equals(e);
|
|
2822
|
-
}
|
|
2823
|
-
function ho(t, e) {
|
|
2824
|
-
const n = qe({
|
|
2825
|
-
output: e.script,
|
|
2826
|
-
version: e.leafVersion
|
|
2827
|
-
});
|
|
2828
|
-
return (t.tapScriptSig || []).filter((r) => r.leafHash.equals(n)).map((r) => po(e.script, r)).sort((r, c) => c.positionInScript - r.positionInScript).map((r) => r.signature);
|
|
2829
|
-
}
|
|
2830
|
-
function po(t, e) {
|
|
2831
|
-
return Object.assign(
|
|
2832
|
-
{
|
|
2833
|
-
positionInScript: ir(e.pubkey, t)
|
|
2834
|
-
},
|
|
2835
|
-
e
|
|
2836
|
-
);
|
|
2837
|
-
}
|
|
2838
|
-
function lo(t, e, n) {
|
|
2839
|
-
const { tapScriptSig: r } = t;
|
|
2840
|
-
if (!r || !r.length)
|
|
2841
|
-
throw new Error(
|
|
2842
|
-
`Can not finalize taproot input #${e}. No tapleaf script signature provided.`
|
|
2843
|
-
);
|
|
2844
|
-
const c = (t.tapLeafScript || []).sort((s, o) => s.controlBlock.length - o.controlBlock.length).find((s) => go(s, r, n));
|
|
2845
|
-
if (!c)
|
|
2846
|
-
throw new Error(
|
|
2847
|
-
`Can not finalize taproot input #${e}. Signature for tapleaf script not found.`
|
|
2848
|
-
);
|
|
2849
|
-
return c;
|
|
2850
|
-
}
|
|
2851
|
-
function go(t, e, n) {
|
|
2852
|
-
const r = qe({
|
|
2853
|
-
output: t.script,
|
|
2854
|
-
version: t.leafVersion
|
|
2855
|
-
});
|
|
2856
|
-
return (!n || n.equals(r)) && e.find((s) => s.leafHash.equals(r)) !== void 0;
|
|
2857
|
-
}
|
|
2858
|
-
function ae(t) {
|
|
2859
|
-
return t && !!(t.redeemScript || t.witnessScript || t.bip32Derivation && t.bip32Derivation.length);
|
|
2860
|
-
}
|
|
2861
|
-
const Tn = dt.decode, yo = {
|
|
2862
|
-
/**
|
|
2863
|
-
* A bitcoinjs Network object. This is only used if you pass an `address`
|
|
2864
|
-
* parameter to addOutput. Otherwise it is not needed and can be left default.
|
|
2865
|
-
*/
|
|
2866
|
-
network: Ve,
|
|
2867
|
-
/**
|
|
2868
|
-
* When extractTransaction is called, the fee rate is checked.
|
|
2869
|
-
* THIS IS NOT TO BE RELIED ON.
|
|
2870
|
-
* It is only here as a last ditch effort to prevent sending a 500 BTC fee etc.
|
|
2871
|
-
*/
|
|
2872
|
-
maximumFeeRate: 5e3
|
|
2873
|
-
// satoshi per byte
|
|
2874
|
-
};
|
|
2875
|
-
class St {
|
|
2876
|
-
constructor(e = {}, n = new yn.Psbt(new ar())) {
|
|
2877
|
-
this.data = n, this.opts = Object.assign({}, yo, e), this.__CACHE = {
|
|
2878
|
-
__NON_WITNESS_UTXO_TX_CACHE: [],
|
|
2879
|
-
__NON_WITNESS_UTXO_BUF_CACHE: [],
|
|
2880
|
-
__TX_IN_CACHE: {},
|
|
2881
|
-
// unsignedTx.tx property is dynamically added by PsbtBase
|
|
2882
|
-
__TX: this.data.globalMap.unsignedTx.tx,
|
|
2883
|
-
__UNSAFE_SIGN_NONSEGWIT: !1
|
|
2884
|
-
}, e.version === 3 ? this.setVersionTRUC() : this.data.inputs.length === 0 && this.setVersion(2);
|
|
2885
|
-
const r = (c, s, o, i) => {
|
|
2886
|
-
Object.defineProperty(c, s, {
|
|
2887
|
-
enumerable: o,
|
|
2888
|
-
writable: i
|
|
2889
|
-
});
|
|
2890
|
-
};
|
|
2891
|
-
r(this, "__CACHE", !1, !0), r(this, "opts", !1, !0);
|
|
2892
|
-
}
|
|
2893
|
-
get inputCount() {
|
|
2894
|
-
return this.data.inputs.length;
|
|
2895
|
-
}
|
|
2896
|
-
get version() {
|
|
2897
|
-
return this.__CACHE.__TX.version;
|
|
2898
|
-
}
|
|
2899
|
-
set version(e) {
|
|
2900
|
-
this.setVersion(e);
|
|
2901
|
-
}
|
|
2902
|
-
get locktime() {
|
|
2903
|
-
return this.__CACHE.__TX.locktime;
|
|
2904
|
-
}
|
|
2905
|
-
set locktime(e) {
|
|
2906
|
-
this.setLocktime(e);
|
|
2907
|
-
}
|
|
2908
|
-
get txInputs() {
|
|
2909
|
-
return this.__CACHE.__TX.ins.map((e) => ({
|
|
2910
|
-
hash: At(e.hash),
|
|
2911
|
-
index: e.index,
|
|
2912
|
-
sequence: e.sequence
|
|
2913
|
-
}));
|
|
2914
|
-
}
|
|
2915
|
-
get txOutputs() {
|
|
2916
|
-
return this.__CACHE.__TX.outs.map((e) => {
|
|
2917
|
-
let n;
|
|
2918
|
-
try {
|
|
2919
|
-
n = er(e.script, this.opts.network);
|
|
2920
|
-
} catch {
|
|
2921
|
-
}
|
|
2922
|
-
return {
|
|
2923
|
-
script: At(e.script),
|
|
2924
|
-
value: e.value,
|
|
2925
|
-
address: n
|
|
2926
|
-
};
|
|
2927
|
-
});
|
|
2928
|
-
}
|
|
2929
|
-
static fromBase64(e, n = {}) {
|
|
2930
|
-
const r = l.from(e, "base64");
|
|
2931
|
-
return this.fromBuffer(r, n);
|
|
2932
|
-
}
|
|
2933
|
-
static fromHex(e, n = {}) {
|
|
2934
|
-
const r = l.from(e, "hex");
|
|
2935
|
-
return this.fromBuffer(r, n);
|
|
2936
|
-
}
|
|
2937
|
-
static fromBuffer(e, n = {}) {
|
|
2938
|
-
const r = yn.Psbt.fromBuffer(e, So), c = new St(n, r);
|
|
2939
|
-
return _o(c.__CACHE.__TX, c.__CACHE), c;
|
|
2940
|
-
}
|
|
2941
|
-
combine(...e) {
|
|
2942
|
-
return this.data.combine(...e.map((n) => n.data)), this;
|
|
2943
|
-
}
|
|
2944
|
-
clone() {
|
|
2945
|
-
const e = JSON.parse(JSON.stringify(this.opts));
|
|
2946
|
-
return St.fromBuffer(this.data.toBuffer(), e);
|
|
2947
|
-
}
|
|
2948
|
-
setMaximumFeeRate(e) {
|
|
2949
|
-
Fe(e), this.opts.maximumFeeRate = e;
|
|
2950
|
-
}
|
|
2951
|
-
setVersion(e) {
|
|
2952
|
-
Fe(e), pe(this.data.inputs, "setVersion");
|
|
2953
|
-
const n = this.__CACHE;
|
|
2954
|
-
return n.__TX.version = e, n.__EXTRACTED_TX = void 0, this;
|
|
2955
|
-
}
|
|
2956
|
-
setVersionTRUC() {
|
|
2957
|
-
return this.setVersion(v.TRUC_VERSION);
|
|
2958
|
-
}
|
|
2959
|
-
setLocktime(e) {
|
|
2960
|
-
Fe(e), pe(this.data.inputs, "setLocktime");
|
|
2961
|
-
const n = this.__CACHE;
|
|
2962
|
-
return n.__TX.locktime = e, n.__EXTRACTED_TX = void 0, this;
|
|
2963
|
-
}
|
|
2964
|
-
setInputSequence(e, n) {
|
|
2965
|
-
Fe(n), pe(this.data.inputs, "setInputSequence");
|
|
2966
|
-
const r = this.__CACHE;
|
|
2967
|
-
if (r.__TX.ins.length <= e)
|
|
2968
|
-
throw new Error("Input index too high");
|
|
2969
|
-
return r.__TX.ins[e].sequence = n, r.__EXTRACTED_TX = void 0, this;
|
|
2970
|
-
}
|
|
2971
|
-
addInputs(e, n = !0) {
|
|
2972
|
-
return e.forEach((r) => this.addInput(r, n)), this;
|
|
2973
|
-
}
|
|
2974
|
-
addInput(e, n = !0) {
|
|
2975
|
-
if (!e || e.hash === void 0 || e.index === void 0)
|
|
2976
|
-
throw new Error(
|
|
2977
|
-
"Invalid arguments for Psbt.addInput. Requires single object with at least [hash] and [index]"
|
|
2978
|
-
);
|
|
2979
|
-
En(e, e, "addInput"), n && pe(this.data.inputs, "addInput"), e.witnessScript && Ge(e.witnessScript);
|
|
2980
|
-
const r = this.__CACHE;
|
|
2981
|
-
this.data.addInput(e);
|
|
2982
|
-
const c = r.__TX.ins[r.__TX.ins.length - 1];
|
|
2983
|
-
hr(r, c);
|
|
2984
|
-
const s = this.data.inputs.length - 1, o = this.data.inputs[s];
|
|
2985
|
-
return o.nonWitnessUtxo && Et(this.__CACHE, o, s), r.__FEE = void 0, r.__FEE_RATE = void 0, r.__EXTRACTED_TX = void 0, this;
|
|
2986
|
-
}
|
|
2987
|
-
addOutputs(e) {
|
|
2988
|
-
return e.forEach((n) => this.addOutput(n)), this;
|
|
2989
|
-
}
|
|
2990
|
-
addOutput(e) {
|
|
2991
|
-
const n = "address" in e, r = "script" in e;
|
|
2992
|
-
if (arguments.length > 1 || !e || e.value === void 0 || !n && !r)
|
|
2993
|
-
throw new Error(
|
|
2994
|
-
"Invalid arguments for Psbt.addOutput. Requires single object with at least [script or address] and [value]"
|
|
2995
|
-
);
|
|
2996
|
-
if (pe(this.data.inputs, "addOutput"), n) {
|
|
2997
|
-
const { address: s } = e, { network: o } = this.opts, i = tr(s, o);
|
|
2998
|
-
e = Object.assign({}, e, { script: i });
|
|
2999
|
-
}
|
|
3000
|
-
bn(e, e, "addOutput");
|
|
3001
|
-
const c = this.__CACHE;
|
|
3002
|
-
return this.data.addOutput(e), c.__FEE = void 0, c.__FEE_RATE = void 0, c.__EXTRACTED_TX = void 0, this;
|
|
3003
|
-
}
|
|
3004
|
-
extractTransaction(e, n) {
|
|
3005
|
-
if (n && (this.data.inputs = this.data.inputs.filter((s) => !s.partialSig)), !this.data.inputs.every(ur)) throw new Error("Not finalized");
|
|
3006
|
-
const r = this.__CACHE;
|
|
3007
|
-
if (e || Eo(this, r, this.opts), r.__EXTRACTED_TX) return r.__EXTRACTED_TX;
|
|
3008
|
-
const c = r.__TX.clone();
|
|
3009
|
-
return Sr(this.data.inputs, c, r, !0, n), c;
|
|
3010
|
-
}
|
|
3011
|
-
getFeeRate(e = !1) {
|
|
3012
|
-
return kn(
|
|
3013
|
-
"__FEE_RATE",
|
|
3014
|
-
"fee rate",
|
|
3015
|
-
this.data.inputs,
|
|
3016
|
-
this.__CACHE,
|
|
3017
|
-
e
|
|
3018
|
-
);
|
|
3019
|
-
}
|
|
3020
|
-
getFee(e = !1) {
|
|
3021
|
-
return kn("__FEE", "fee", this.data.inputs, this.__CACHE, e);
|
|
3022
|
-
}
|
|
3023
|
-
finalizeAllInputs() {
|
|
3024
|
-
return x.checkForInput(this.data.inputs, 0), le(this.data.inputs.length).forEach((e) => this.finalizeInput(e)), this;
|
|
3025
|
-
}
|
|
3026
|
-
finalizeInput(e, n, r) {
|
|
3027
|
-
const c = x.checkForInput(this.data.inputs, e);
|
|
3028
|
-
return N(c) ? this._finalizeTaprootInput(
|
|
3029
|
-
e,
|
|
3030
|
-
c,
|
|
3031
|
-
void 0,
|
|
3032
|
-
n
|
|
3033
|
-
) : this._finalizeInput(
|
|
3034
|
-
e,
|
|
3035
|
-
c,
|
|
3036
|
-
n,
|
|
3037
|
-
r ?? !0
|
|
3038
|
-
);
|
|
3039
|
-
}
|
|
3040
|
-
finalizeTaprootInput(e, n, r = wn) {
|
|
3041
|
-
const c = x.checkForInput(this.data.inputs, e);
|
|
3042
|
-
if (N(c))
|
|
3043
|
-
return this._finalizeTaprootInput(
|
|
3044
|
-
e,
|
|
3045
|
-
c,
|
|
3046
|
-
n,
|
|
3047
|
-
r
|
|
3048
|
-
);
|
|
3049
|
-
throw new Error(`Cannot finalize input #${e}. Not Taproot.`);
|
|
3050
|
-
}
|
|
3051
|
-
getInputType(e) {
|
|
3052
|
-
const n = x.checkForInput(this.data.inputs, e), r = wr(e, n, this.__CACHE), c = Qe(
|
|
3053
|
-
r,
|
|
3054
|
-
e,
|
|
3055
|
-
"input",
|
|
3056
|
-
n.redeemScript || No(n.finalScriptSig),
|
|
3057
|
-
n.witnessScript || Uo(n.finalScriptWitness)
|
|
3058
|
-
), s = c.type === "raw" ? "" : c.type + "-", o = br(c.meaningfulScript);
|
|
3059
|
-
return s + o;
|
|
3060
|
-
}
|
|
3061
|
-
inputHasPubkey(e, n) {
|
|
3062
|
-
const r = x.checkForInput(this.data.inputs, e);
|
|
3063
|
-
return Oo(n, r, e, this.__CACHE);
|
|
3064
|
-
}
|
|
3065
|
-
inputHasHDKey(e, n) {
|
|
3066
|
-
const r = x.checkForInput(this.data.inputs, e), c = mn(n);
|
|
3067
|
-
return !!r.bip32Derivation && r.bip32Derivation.some(c);
|
|
3068
|
-
}
|
|
3069
|
-
outputHasPubkey(e, n) {
|
|
3070
|
-
const r = x.checkForOutput(this.data.outputs, e);
|
|
3071
|
-
return Po(n, r, e, this.__CACHE);
|
|
3072
|
-
}
|
|
3073
|
-
outputHasHDKey(e, n) {
|
|
3074
|
-
const r = x.checkForOutput(this.data.outputs, e), c = mn(n);
|
|
3075
|
-
return !!r.bip32Derivation && r.bip32Derivation.some(c);
|
|
3076
|
-
}
|
|
3077
|
-
validateSignaturesOfAllInputs(e) {
|
|
3078
|
-
return x.checkForInput(this.data.inputs, 0), le(this.data.inputs.length).map(
|
|
3079
|
-
(r) => this.validateSignaturesOfInput(r, e)
|
|
3080
|
-
).reduce((r, c) => c && r, !0);
|
|
3081
|
-
}
|
|
3082
|
-
validateSignaturesOfInput(e, n, r) {
|
|
3083
|
-
const c = this.data.inputs[e];
|
|
3084
|
-
return N(c) ? this.validateSignaturesOfTaprootInput(e, n, r) : this._validateSignaturesOfInput(e, n, r);
|
|
3085
|
-
}
|
|
3086
|
-
signAllInputsHD(e, n = [v.SIGHASH_ALL]) {
|
|
3087
|
-
if (!e || !e.publicKey || !e.fingerprint)
|
|
3088
|
-
throw new Error("Need HDSigner to sign input");
|
|
3089
|
-
const r = [];
|
|
3090
|
-
for (const c of le(this.data.inputs.length))
|
|
3091
|
-
try {
|
|
3092
|
-
this.signInputHD(c, e, n), r.push(!0);
|
|
3093
|
-
} catch {
|
|
3094
|
-
r.push(!1);
|
|
3095
|
-
}
|
|
3096
|
-
if (r.every((c) => !c))
|
|
3097
|
-
throw new Error("No inputs were signed");
|
|
3098
|
-
return this;
|
|
3099
|
-
}
|
|
3100
|
-
signAllInputsHDAsync(e, n = [v.SIGHASH_ALL]) {
|
|
3101
|
-
return new Promise((r, c) => {
|
|
3102
|
-
if (!e || !e.publicKey || !e.fingerprint)
|
|
3103
|
-
return c(new Error("Need HDSigner to sign input"));
|
|
3104
|
-
const s = [], o = [];
|
|
3105
|
-
for (const i of le(this.data.inputs.length))
|
|
3106
|
-
o.push(
|
|
3107
|
-
this.signInputHDAsync(i, e, n).then(
|
|
3108
|
-
() => {
|
|
3109
|
-
s.push(!0);
|
|
3110
|
-
},
|
|
3111
|
-
() => {
|
|
3112
|
-
s.push(!1);
|
|
3113
|
-
}
|
|
3114
|
-
)
|
|
3115
|
-
);
|
|
3116
|
-
return Promise.all(o).then(() => {
|
|
3117
|
-
if (s.every((i) => !i))
|
|
3118
|
-
return c(new Error("No inputs were signed"));
|
|
3119
|
-
r();
|
|
3120
|
-
});
|
|
3121
|
-
});
|
|
3122
|
-
}
|
|
3123
|
-
signInputHD(e, n, r = [v.SIGHASH_ALL]) {
|
|
3124
|
-
if (!n || !n.publicKey || !n.fingerprint)
|
|
3125
|
-
throw new Error("Need HDSigner to sign input");
|
|
3126
|
-
return Cn(e, this.data.inputs, n).forEach((s) => this.signInput(e, s, r)), this;
|
|
3127
|
-
}
|
|
3128
|
-
signInputHDAsync(e, n, r = [v.SIGHASH_ALL]) {
|
|
3129
|
-
return new Promise((c, s) => {
|
|
3130
|
-
if (!n || !n.publicKey || !n.fingerprint)
|
|
3131
|
-
return s(new Error("Need HDSigner to sign input"));
|
|
3132
|
-
const i = Cn(e, this.data.inputs, n).map(
|
|
3133
|
-
(a) => this.signInputAsync(e, a, r)
|
|
3134
|
-
);
|
|
3135
|
-
return Promise.all(i).then(() => {
|
|
3136
|
-
c();
|
|
3137
|
-
}).catch(s);
|
|
3138
|
-
});
|
|
3139
|
-
}
|
|
3140
|
-
signAllInputs(e, n) {
|
|
3141
|
-
if (!e || !e.publicKey) throw new Error("Need Signer to sign input");
|
|
3142
|
-
const r = [];
|
|
3143
|
-
for (const c of le(this.data.inputs.length))
|
|
3144
|
-
try {
|
|
3145
|
-
this.signInput(c, e, n), r.push(!0);
|
|
3146
|
-
} catch {
|
|
3147
|
-
r.push(!1);
|
|
3148
|
-
}
|
|
3149
|
-
if (r.every((c) => !c))
|
|
3150
|
-
throw new Error("No inputs were signed");
|
|
3151
|
-
return this;
|
|
3152
|
-
}
|
|
3153
|
-
signAllInputsAsync(e, n) {
|
|
3154
|
-
return new Promise((r, c) => {
|
|
3155
|
-
if (!e || !e.publicKey)
|
|
3156
|
-
return c(new Error("Need Signer to sign input"));
|
|
3157
|
-
const s = [], o = [];
|
|
3158
|
-
for (const [i] of this.data.inputs.entries())
|
|
3159
|
-
o.push(
|
|
3160
|
-
this.signInputAsync(i, e, n).then(
|
|
3161
|
-
() => {
|
|
3162
|
-
s.push(!0);
|
|
3163
|
-
},
|
|
3164
|
-
() => {
|
|
3165
|
-
s.push(!1);
|
|
3166
|
-
}
|
|
3167
|
-
)
|
|
3168
|
-
);
|
|
3169
|
-
return Promise.all(o).then(() => {
|
|
3170
|
-
if (s.every((i) => !i))
|
|
3171
|
-
return c(new Error("No inputs were signed"));
|
|
3172
|
-
r();
|
|
3173
|
-
});
|
|
3174
|
-
});
|
|
3175
|
-
}
|
|
3176
|
-
signInput(e, n, r) {
|
|
3177
|
-
if (!n || !n.publicKey)
|
|
3178
|
-
throw new Error("Need Signer to sign input");
|
|
3179
|
-
const c = x.checkForInput(this.data.inputs, e);
|
|
3180
|
-
return N(c) ? this._signTaprootInput(e, c, n, void 0, r) : this._signInput(e, n, r);
|
|
3181
|
-
}
|
|
3182
|
-
signTaprootInput(e, n, r, c) {
|
|
3183
|
-
if (!n || !n.publicKey)
|
|
3184
|
-
throw new Error("Need Signer to sign input");
|
|
3185
|
-
const s = x.checkForInput(this.data.inputs, e);
|
|
3186
|
-
if (N(s))
|
|
3187
|
-
return this._signTaprootInput(
|
|
3188
|
-
e,
|
|
3189
|
-
s,
|
|
3190
|
-
n,
|
|
3191
|
-
r,
|
|
3192
|
-
c
|
|
3193
|
-
);
|
|
3194
|
-
throw new Error(`Input #${e} is not of type Taproot.`);
|
|
3195
|
-
}
|
|
3196
|
-
signInputAsync(e, n, r) {
|
|
3197
|
-
return Promise.resolve().then(() => {
|
|
3198
|
-
if (!n || !n.publicKey) throw new Error("Need Signer to sign input");
|
|
3199
|
-
const c = x.checkForInput(this.data.inputs, e);
|
|
3200
|
-
return N(c) ? this._signTaprootInputAsync(
|
|
3201
|
-
e,
|
|
3202
|
-
c,
|
|
3203
|
-
n,
|
|
3204
|
-
void 0,
|
|
3205
|
-
r
|
|
3206
|
-
) : this._signInputAsync(e, n, r);
|
|
3207
|
-
});
|
|
3208
|
-
}
|
|
3209
|
-
signTaprootInputAsync(e, n, r, c) {
|
|
3210
|
-
return Promise.resolve().then(() => {
|
|
3211
|
-
if (!n || !n.publicKey) throw new Error("Need Signer to sign input");
|
|
3212
|
-
const s = x.checkForInput(this.data.inputs, e);
|
|
3213
|
-
if (N(s))
|
|
3214
|
-
return this._signTaprootInputAsync(
|
|
3215
|
-
e,
|
|
3216
|
-
s,
|
|
3217
|
-
n,
|
|
3218
|
-
r,
|
|
3219
|
-
c
|
|
3220
|
-
);
|
|
3221
|
-
throw new Error(`Input #${e} is not of type Taproot.`);
|
|
3222
|
-
});
|
|
3223
|
-
}
|
|
3224
|
-
toBuffer() {
|
|
3225
|
-
return ut(this.__CACHE), this.data.toBuffer();
|
|
3226
|
-
}
|
|
3227
|
-
toHex() {
|
|
3228
|
-
return ut(this.__CACHE), this.data.toHex();
|
|
3229
|
-
}
|
|
3230
|
-
toBase64() {
|
|
3231
|
-
return ut(this.__CACHE), this.data.toBase64();
|
|
3232
|
-
}
|
|
3233
|
-
updateGlobal(e) {
|
|
3234
|
-
return this.data.updateGlobal(e), this;
|
|
3235
|
-
}
|
|
3236
|
-
updateInput(e, n) {
|
|
3237
|
-
return n.witnessScript && Ge(n.witnessScript), En(this.data.inputs[e], n, "updateInput"), this.data.updateInput(e, n), n.nonWitnessUtxo && Et(this.__CACHE, this.data.inputs[e], e), this;
|
|
3238
|
-
}
|
|
3239
|
-
updateOutput(e, n) {
|
|
3240
|
-
const r = this.data.outputs[e];
|
|
3241
|
-
return bn(r, n, "updateOutput"), this.data.updateOutput(e, n), this;
|
|
3242
|
-
}
|
|
3243
|
-
addUnknownKeyValToGlobal(e) {
|
|
3244
|
-
return this.data.addUnknownKeyValToGlobal(e), this;
|
|
3245
|
-
}
|
|
3246
|
-
addUnknownKeyValToInput(e, n) {
|
|
3247
|
-
return this.data.addUnknownKeyValToInput(e, n), this;
|
|
3248
|
-
}
|
|
3249
|
-
addUnknownKeyValToOutput(e, n) {
|
|
3250
|
-
return this.data.addUnknownKeyValToOutput(e, n), this;
|
|
3251
|
-
}
|
|
3252
|
-
clearFinalizedInput(e) {
|
|
3253
|
-
return this.data.clearFinalizedInput(e), this;
|
|
3254
|
-
}
|
|
3255
|
-
checkTaprootHashesForSig(e, n, r, c, s) {
|
|
3256
|
-
if (typeof r.signSchnorr != "function")
|
|
3257
|
-
throw new Error(`Need Schnorr Signer to sign taproot input #${e}.`);
|
|
3258
|
-
const o = l.isBuffer(r.publicKey) ? r.publicKey : l.from(r.publicKey), i = wt(
|
|
3259
|
-
e,
|
|
3260
|
-
n,
|
|
3261
|
-
this.data.inputs,
|
|
3262
|
-
o,
|
|
3263
|
-
this.__CACHE,
|
|
3264
|
-
c,
|
|
3265
|
-
s
|
|
3266
|
-
);
|
|
3267
|
-
if (!i || !i.length)
|
|
3268
|
-
throw new Error(
|
|
3269
|
-
`Can not sign for input #${e} with the key ${o.toString("hex")}`
|
|
3270
|
-
);
|
|
3271
|
-
return i;
|
|
3272
|
-
}
|
|
3273
|
-
_finalizeInput(e, n, r = mo, c = !0) {
|
|
3274
|
-
const { script: s, isP2SH: o, isP2WSH: i, isSegwit: a } = Ao(
|
|
3275
|
-
e,
|
|
3276
|
-
n,
|
|
3277
|
-
this.__CACHE
|
|
3278
|
-
);
|
|
3279
|
-
if (!s) throw new Error(`No script found for input #${e}`);
|
|
3280
|
-
bo(n);
|
|
3281
|
-
const { finalScriptSig: u, finalScriptWitness: f } = r(
|
|
3282
|
-
e,
|
|
3283
|
-
n,
|
|
3284
|
-
s,
|
|
3285
|
-
a,
|
|
3286
|
-
o,
|
|
3287
|
-
i,
|
|
3288
|
-
c
|
|
3289
|
-
);
|
|
3290
|
-
if (u && this.data.updateInput(e, { finalScriptSig: u }), f && this.data.updateInput(e, { finalScriptWitness: f }), !u && !f)
|
|
3291
|
-
throw new Error(`Unknown error finalizing input #${e}`);
|
|
3292
|
-
return this.data.clearFinalizedInput(e), this;
|
|
3293
|
-
}
|
|
3294
|
-
_finalizeTaprootInput(e, n, r, c = wn) {
|
|
3295
|
-
if (!n.witnessUtxo)
|
|
3296
|
-
throw new Error(`Cannot finalize input #${e}. Missing witness utxo.`);
|
|
3297
|
-
if (n.tapKeySig) {
|
|
3298
|
-
const s = Te({
|
|
3299
|
-
output: n.witnessUtxo.script,
|
|
3300
|
-
signature: n.tapKeySig
|
|
3301
|
-
});
|
|
3302
|
-
if (!s.witness) throw new Error("Cannot finalize taproot key spend");
|
|
3303
|
-
const o = ye(s.witness);
|
|
3304
|
-
this.data.updateInput(e, { finalScriptWitness: o });
|
|
3305
|
-
} else {
|
|
3306
|
-
const { finalScriptWitness: s } = c(
|
|
3307
|
-
e,
|
|
3308
|
-
n,
|
|
3309
|
-
r
|
|
3310
|
-
);
|
|
3311
|
-
this.data.updateInput(e, { finalScriptWitness: s });
|
|
3312
|
-
}
|
|
3313
|
-
return this.data.clearFinalizedInput(e), this;
|
|
3314
|
-
}
|
|
3315
|
-
_validateSignaturesOfInput(e, n, r) {
|
|
3316
|
-
const c = this.data.inputs[e], s = (c || {}).partialSig;
|
|
3317
|
-
if (!c || !s || s.length < 1)
|
|
3318
|
-
throw new Error("No signatures to validate");
|
|
3319
|
-
if (typeof n != "function")
|
|
3320
|
-
throw new Error("Need validator function to validate signatures");
|
|
3321
|
-
const o = r ? s.filter((h) => h.pubkey.equals(r)) : s;
|
|
3322
|
-
if (o.length < 1) throw new Error("No signatures for this pubkey");
|
|
3323
|
-
const i = [];
|
|
3324
|
-
let a, u, f;
|
|
3325
|
-
for (const h of o) {
|
|
3326
|
-
const g = de.decode(h.signature), { hash: y, script: p } = f !== g.hashType || !a || !u ? lr(
|
|
3327
|
-
e,
|
|
3328
|
-
Object.assign({}, c, {
|
|
3329
|
-
sighashType: g.hashType
|
|
3330
|
-
}),
|
|
3331
|
-
this.__CACHE,
|
|
3332
|
-
!0
|
|
3333
|
-
) : { hash: a, script: u };
|
|
3334
|
-
f = g.hashType, a = y, u = p, fr(h.pubkey, p, "verify"), i.push(n(h.pubkey, y, g.signature));
|
|
3335
|
-
}
|
|
3336
|
-
return i.every((h) => h);
|
|
3337
|
-
}
|
|
3338
|
-
validateSignaturesOfTaprootInput(e, n, r) {
|
|
3339
|
-
const c = this.data.inputs[e], s = (c || {}).tapKeySig, o = (c || {}).tapScriptSig;
|
|
3340
|
-
if (!c && !s && !(o && !o.length))
|
|
3341
|
-
throw new Error("No signatures to validate");
|
|
3342
|
-
if (typeof n != "function")
|
|
3343
|
-
throw new Error("Need validator function to validate signatures");
|
|
3344
|
-
r = r && ge(r);
|
|
3345
|
-
const i = r ? wt(e, c, this.data.inputs, r, this.__CACHE) : vo(e, c, this.data.inputs, this.__CACHE);
|
|
3346
|
-
if (!i.length) throw new Error("No signatures for this pubkey");
|
|
3347
|
-
const a = i.find((f) => !f.leafHash);
|
|
3348
|
-
let u = 0;
|
|
3349
|
-
if (s && a) {
|
|
3350
|
-
if (!n(
|
|
3351
|
-
a.pubkey,
|
|
3352
|
-
a.hash,
|
|
3353
|
-
xn(s)
|
|
3354
|
-
)) return !1;
|
|
3355
|
-
u++;
|
|
3356
|
-
}
|
|
3357
|
-
if (o)
|
|
3358
|
-
for (const f of o) {
|
|
3359
|
-
const h = i.find((g) => f.pubkey.equals(g.pubkey));
|
|
3360
|
-
if (h) {
|
|
3361
|
-
if (!n(
|
|
3362
|
-
f.pubkey,
|
|
3363
|
-
h.hash,
|
|
3364
|
-
xn(f.signature)
|
|
3365
|
-
)) return !1;
|
|
3366
|
-
u++;
|
|
3367
|
-
}
|
|
3368
|
-
}
|
|
3369
|
-
return u > 0;
|
|
3370
|
-
}
|
|
3371
|
-
_signInput(e, n, r = [v.SIGHASH_ALL]) {
|
|
3372
|
-
const c = l.isBuffer(n.publicKey) ? n.publicKey : l.from(n.publicKey), { hash: s, sighashType: o } = An(
|
|
3373
|
-
this.data.inputs,
|
|
3374
|
-
e,
|
|
3375
|
-
c,
|
|
3376
|
-
this.__CACHE,
|
|
3377
|
-
r
|
|
3378
|
-
), i = n.sign(s), a = [
|
|
3379
|
-
{
|
|
3380
|
-
pubkey: c,
|
|
3381
|
-
signature: de.encode(
|
|
3382
|
-
l.isBuffer(i) ? i : l.from(i),
|
|
3383
|
-
o
|
|
3384
|
-
)
|
|
3385
|
-
}
|
|
3386
|
-
];
|
|
3387
|
-
return this.data.updateInput(e, { partialSig: a }), this;
|
|
3388
|
-
}
|
|
3389
|
-
_signTaprootInput(e, n, r, c, s = [v.SIGHASH_DEFAULT]) {
|
|
3390
|
-
const o = l.isBuffer(r.publicKey) ? r.publicKey : l.from(r.publicKey), i = this.checkTaprootHashesForSig(
|
|
3391
|
-
e,
|
|
3392
|
-
n,
|
|
3393
|
-
r,
|
|
3394
|
-
c,
|
|
3395
|
-
s
|
|
3396
|
-
), a = r.signSchnorr.bind(r), u = (g) => l.isBuffer(g) ? g : l.from(g), f = i.filter((g) => !g.leafHash).map(
|
|
3397
|
-
(g) => Re(u(a(g.hash)), n.sighashType)
|
|
3398
|
-
)[0], h = i.filter((g) => !!g.leafHash).map(
|
|
3399
|
-
(g) => ({
|
|
3400
|
-
pubkey: ge(o),
|
|
3401
|
-
signature: Re(
|
|
3402
|
-
u(a(g.hash)),
|
|
3403
|
-
n.sighashType
|
|
3404
|
-
),
|
|
3405
|
-
leafHash: g.leafHash
|
|
3406
|
-
})
|
|
3407
|
-
);
|
|
3408
|
-
return f && this.data.updateInput(e, { tapKeySig: f }), h.length && this.data.updateInput(e, { tapScriptSig: h }), this;
|
|
3409
|
-
}
|
|
3410
|
-
_signInputAsync(e, n, r = [v.SIGHASH_ALL]) {
|
|
3411
|
-
const c = l.isBuffer(n.publicKey) ? n.publicKey : l.from(n.publicKey), { hash: s, sighashType: o } = An(
|
|
3412
|
-
this.data.inputs,
|
|
3413
|
-
e,
|
|
3414
|
-
c,
|
|
3415
|
-
this.__CACHE,
|
|
3416
|
-
r
|
|
3417
|
-
);
|
|
3418
|
-
return Promise.resolve(n.sign(s)).then((i) => {
|
|
3419
|
-
const a = l.isBuffer(i) ? i : l.from(i), u = [
|
|
3420
|
-
{
|
|
3421
|
-
pubkey: c,
|
|
3422
|
-
signature: de.encode(a, o)
|
|
3423
|
-
}
|
|
3424
|
-
];
|
|
3425
|
-
this.data.updateInput(e, { partialSig: u });
|
|
3426
|
-
});
|
|
3427
|
-
}
|
|
3428
|
-
async _signTaprootInputAsync(e, n, r, c, s = [v.SIGHASH_DEFAULT]) {
|
|
3429
|
-
const o = l.isBuffer(r.publicKey) ? r.publicKey : l.from(r.publicKey), i = this.checkTaprootHashesForSig(
|
|
3430
|
-
e,
|
|
3431
|
-
n,
|
|
3432
|
-
r,
|
|
3433
|
-
c,
|
|
3434
|
-
s
|
|
3435
|
-
), a = r.signSchnorr.bind(r), u = (p) => l.isBuffer(p) ? p : l.from(p), f = [], h = i.filter((p) => !p.leafHash)[0];
|
|
3436
|
-
if (h) {
|
|
3437
|
-
const p = Promise.resolve(a(h.hash)).then((d) => ({
|
|
3438
|
-
tapKeySig: Re(u(d), n.sighashType)
|
|
3439
|
-
}));
|
|
3440
|
-
f.push(p);
|
|
3441
|
-
}
|
|
3442
|
-
const g = i.filter((p) => !!p.leafHash);
|
|
3443
|
-
if (g.length) {
|
|
3444
|
-
const p = g.map(async (d) => {
|
|
3445
|
-
const E = await a(d.hash);
|
|
3446
|
-
return { tapScriptSig: [
|
|
3447
|
-
{
|
|
3448
|
-
pubkey: ge(o),
|
|
3449
|
-
signature: Re(
|
|
3450
|
-
u(E),
|
|
3451
|
-
n.sighashType
|
|
3452
|
-
),
|
|
3453
|
-
leafHash: d.leafHash
|
|
3454
|
-
}
|
|
3455
|
-
] };
|
|
3456
|
-
});
|
|
3457
|
-
f.push(...p);
|
|
3458
|
-
}
|
|
3459
|
-
const y = await Promise.all(f);
|
|
3460
|
-
for (const p of y)
|
|
3461
|
-
this.data.updateInput(e, p);
|
|
3462
|
-
}
|
|
3463
|
-
}
|
|
3464
|
-
const So = (t) => new ar(t);
|
|
3465
|
-
class ar {
|
|
3466
|
-
constructor(e = l.from([2, 0, 0, 0, 0, 0, 0, 0, 0, 0])) {
|
|
3467
|
-
this.tx = v.fromBuffer(e), To(this.tx), Object.defineProperty(this, "tx", {
|
|
3468
|
-
enumerable: !1,
|
|
3469
|
-
writable: !0
|
|
3470
|
-
});
|
|
3471
|
-
}
|
|
3472
|
-
getInputOutputCounts() {
|
|
3473
|
-
return {
|
|
3474
|
-
inputCount: this.tx.ins.length,
|
|
3475
|
-
outputCount: this.tx.outs.length
|
|
3476
|
-
};
|
|
3477
|
-
}
|
|
3478
|
-
addInput(e) {
|
|
3479
|
-
if (e.hash === void 0 || e.index === void 0 || !l.isBuffer(e.hash) && typeof e.hash != "string" || typeof e.index != "number")
|
|
3480
|
-
throw new Error("Error adding input.");
|
|
3481
|
-
const n = typeof e.hash == "string" ? Bn(l.from(e.hash, "hex")) : e.hash;
|
|
3482
|
-
this.tx.addInput(n, e.index, e.sequence);
|
|
3483
|
-
}
|
|
3484
|
-
addOutput(e) {
|
|
3485
|
-
if (e.script === void 0 || e.value === void 0 || !l.isBuffer(e.script) || typeof e.value != "number")
|
|
3486
|
-
throw new Error("Error adding output.");
|
|
3487
|
-
this.tx.addOutput(e.script, e.value);
|
|
3488
|
-
}
|
|
3489
|
-
toBuffer() {
|
|
3490
|
-
return this.tx.toBuffer();
|
|
3491
|
-
}
|
|
3492
|
-
}
|
|
3493
|
-
function wo(t, e, n) {
|
|
3494
|
-
switch (n) {
|
|
3495
|
-
case "pubkey":
|
|
3496
|
-
case "pubkeyhash":
|
|
3497
|
-
case "witnesspubkeyhash":
|
|
3498
|
-
return _n(1, t.partialSig);
|
|
3499
|
-
case "multisig": {
|
|
3500
|
-
const r = De({
|
|
3501
|
-
output: e
|
|
3502
|
-
});
|
|
3503
|
-
return _n(r.m, t.partialSig, r.pubkeys);
|
|
3504
|
-
}
|
|
3505
|
-
case "nonstandard":
|
|
3506
|
-
return !0;
|
|
3507
|
-
default:
|
|
3508
|
-
return !1;
|
|
3509
|
-
}
|
|
3510
|
-
}
|
|
3511
|
-
function ut(t) {
|
|
3512
|
-
if (t.__UNSAFE_SIGN_NONSEGWIT)
|
|
3513
|
-
throw new Error("Not BIP174 compliant, can not export");
|
|
3514
|
-
}
|
|
3515
|
-
function _n(t, e, n) {
|
|
3516
|
-
if (!e) return !1;
|
|
3517
|
-
let r;
|
|
3518
|
-
if (n ? r = n.map((c) => {
|
|
3519
|
-
const s = Ho(c);
|
|
3520
|
-
return e.find((o) => o.pubkey.equals(s));
|
|
3521
|
-
}).filter((c) => !!c) : r = e, r.length > t) throw new Error("Too many signatures");
|
|
3522
|
-
return r.length === t;
|
|
3523
|
-
}
|
|
3524
|
-
function ur(t) {
|
|
3525
|
-
return !!t.finalScriptSig || !!t.finalScriptWitness;
|
|
3526
|
-
}
|
|
3527
|
-
function mn(t) {
|
|
3528
|
-
return (e) => {
|
|
3529
|
-
const n = l.isBuffer(t.fingerprint) ? t.fingerprint : l.from(t.fingerprint);
|
|
3530
|
-
if (!e.masterFingerprint.equals(n)) return !1;
|
|
3531
|
-
const r = t.derivePath(e.path).publicKey;
|
|
3532
|
-
return !!(l.isBuffer(r) ? r : l.from(r)).equals(e.pubkey);
|
|
3533
|
-
};
|
|
3534
|
-
}
|
|
3535
|
-
function Fe(t) {
|
|
3536
|
-
if (typeof t != "number" || t !== Math.floor(t) || t > 4294967295 || t < 0)
|
|
3537
|
-
throw new Error("Invalid 32 bit integer");
|
|
3538
|
-
}
|
|
3539
|
-
function Eo(t, e, n) {
|
|
3540
|
-
const r = e.__FEE_RATE || t.getFeeRate(), c = e.__EXTRACTED_TX.virtualSize(), s = r * c;
|
|
3541
|
-
if (r >= n.maximumFeeRate)
|
|
3542
|
-
throw new Error(
|
|
3543
|
-
`Warning: You are paying around ${(s / 1e8).toFixed(8)} in fees, which is ${r} satoshi per byte for a transaction with a VSize of ${c} bytes (segwit counted as 0.25 byte per byte). Use setMaximumFeeRate method to raise your threshold, or pass true to the first arg of extractTransaction.`
|
|
3544
|
-
);
|
|
3545
|
-
}
|
|
3546
|
-
function pe(t, e) {
|
|
3547
|
-
t.forEach((n) => {
|
|
3548
|
-
if (N(n) ? ro(n, e) : Zs(n, e)) throw new Error("Can not modify transaction, signatures exist.");
|
|
3549
|
-
});
|
|
3550
|
-
}
|
|
3551
|
-
function bo(t) {
|
|
3552
|
-
if (!t.sighashType || !t.partialSig) return;
|
|
3553
|
-
const { partialSig: e, sighashType: n } = t;
|
|
3554
|
-
e.forEach((r) => {
|
|
3555
|
-
const { hashType: c } = de.decode(r.signature);
|
|
3556
|
-
if (n !== c)
|
|
3557
|
-
throw new Error("Signature sighash does not match input sighash type");
|
|
3558
|
-
});
|
|
3559
|
-
}
|
|
3560
|
-
function fr(t, e, n) {
|
|
3561
|
-
if (!Ze(t, e))
|
|
3562
|
-
throw new Error(`Can not ${n} for this input with the key ${t.toString("hex")}`);
|
|
3563
|
-
}
|
|
3564
|
-
function To(t) {
|
|
3565
|
-
if (!t.ins.every(
|
|
3566
|
-
(n) => n.script && n.script.length === 0 && n.witness && n.witness.length === 0
|
|
3567
|
-
))
|
|
3568
|
-
throw new Error("Format Error: Transaction ScriptSigs are not empty");
|
|
3569
|
-
}
|
|
3570
|
-
function _o(t, e) {
|
|
3571
|
-
t.ins.forEach((n) => {
|
|
3572
|
-
hr(e, n);
|
|
3573
|
-
});
|
|
3574
|
-
}
|
|
3575
|
-
function hr(t, e) {
|
|
3576
|
-
const n = `${Bn(l.from(e.hash)).toString("hex")}:${e.index}`;
|
|
3577
|
-
if (t.__TX_IN_CACHE[n]) throw new Error("Duplicate input detected.");
|
|
3578
|
-
t.__TX_IN_CACHE[n] = 1;
|
|
3579
|
-
}
|
|
3580
|
-
function pr(t, e) {
|
|
3581
|
-
return (n, r, c, s) => {
|
|
3582
|
-
const o = t({
|
|
3583
|
-
redeem: { output: c }
|
|
3584
|
-
}).output;
|
|
3585
|
-
if (!r.equals(o))
|
|
3586
|
-
throw new Error(
|
|
3587
|
-
`${e} for ${s} #${n} doesn't match the scriptPubKey in the prevout`
|
|
3588
|
-
);
|
|
3589
|
-
};
|
|
3590
|
-
}
|
|
3591
|
-
const In = pr(Ee, "Redeem script"), vn = pr(be, "Witness script");
|
|
3592
|
-
function kn(t, e, n, r, c = !1) {
|
|
3593
|
-
if (!n.every(ur)) throw new Error(`PSBT must be finalized to calculate ${e}`);
|
|
3594
|
-
if (t === "__FEE_RATE" && r.__FEE_RATE) return r.__FEE_RATE;
|
|
3595
|
-
if (t === "__FEE" && r.__FEE) return r.__FEE;
|
|
3596
|
-
let s, o = !0;
|
|
3597
|
-
r.__EXTRACTED_TX ? (s = r.__EXTRACTED_TX, o = !1) : s = r.__TX.clone(), Sr(n, s, r, o, c);
|
|
3598
|
-
const i = t === "__FEE_RATE" ? r.__FEE_RATE : r.__FEE;
|
|
3599
|
-
if (i === void 0) throw new Error(`Failed to calculate ${e}`);
|
|
3600
|
-
return i;
|
|
3601
|
-
}
|
|
3602
|
-
function mo(t, e, n, r, c, s, o = !0, i) {
|
|
3603
|
-
const a = br(n);
|
|
3604
|
-
if (!wo(e, n, a) && o)
|
|
3605
|
-
throw new Error(`Can not finalize input #${t}`);
|
|
3606
|
-
return Io(
|
|
3607
|
-
n,
|
|
3608
|
-
a,
|
|
3609
|
-
e.partialSig,
|
|
3610
|
-
r,
|
|
3611
|
-
c,
|
|
3612
|
-
s,
|
|
3613
|
-
i
|
|
3614
|
-
);
|
|
3615
|
-
}
|
|
3616
|
-
function Io(t, e, n, r, c, s, o) {
|
|
3617
|
-
let i, a;
|
|
3618
|
-
const u = ko(t, e, n), f = s ? be({ redeem: u }) : null, h = c ? Ee({ redeem: f || u }) : null;
|
|
3619
|
-
return r ? (f ? a = ye(f.witness) : u ? a = ye(u.witness) : a = ye(o ?? [l.from([0])]), h && (i = h?.input)) : h ? i = h?.input : u ? i = u.input : i = Array.isArray(o) && o[0] ? o[0] : l.from([1]), {
|
|
3620
|
-
finalScriptSig: i,
|
|
3621
|
-
finalScriptWitness: a
|
|
3622
|
-
};
|
|
3623
|
-
}
|
|
3624
|
-
function An(t, e, n, r, c) {
|
|
3625
|
-
const s = x.checkForInput(t, e), { hash: o, sighashType: i, script: a } = lr(
|
|
3626
|
-
e,
|
|
3627
|
-
s,
|
|
3628
|
-
r,
|
|
3629
|
-
!1,
|
|
3630
|
-
c
|
|
3631
|
-
);
|
|
3632
|
-
return fr(n, a, "sign"), {
|
|
3633
|
-
hash: o,
|
|
3634
|
-
sighashType: i
|
|
3635
|
-
};
|
|
3636
|
-
}
|
|
3637
|
-
function lr(t, e, n, r, c) {
|
|
3638
|
-
const s = n.__TX, o = e.sighashType || v.SIGHASH_ALL;
|
|
3639
|
-
gr(o, c);
|
|
3640
|
-
let i, a;
|
|
3641
|
-
if (e.nonWitnessUtxo) {
|
|
3642
|
-
const h = Je(n, e, t), g = s.ins[t].hash, y = h.getHash();
|
|
3643
|
-
if (!g.equals(y))
|
|
3644
|
-
throw new Error(
|
|
3645
|
-
`Non-witness UTXO hash for input #${t} doesn't match the hash specified in the prevout`
|
|
3646
|
-
);
|
|
3647
|
-
const p = s.ins[t].index;
|
|
3648
|
-
a = h.outs[p];
|
|
3649
|
-
} else if (e.witnessUtxo)
|
|
3650
|
-
a = e.witnessUtxo;
|
|
3651
|
-
else
|
|
3652
|
-
throw new Error("Need a Utxo input item for signing");
|
|
3653
|
-
const { meaningfulScript: u, type: f } = Qe(
|
|
3654
|
-
a.script,
|
|
3655
|
-
t,
|
|
3656
|
-
"input",
|
|
3657
|
-
e.redeemScript,
|
|
3658
|
-
e.witnessScript
|
|
3659
|
-
);
|
|
3660
|
-
if (["p2sh-p2wsh", "p2wsh"].indexOf(f) >= 0)
|
|
3661
|
-
i = s.hashForWitnessV0(
|
|
3662
|
-
t,
|
|
3663
|
-
u,
|
|
3664
|
-
a.value,
|
|
3665
|
-
o
|
|
3666
|
-
);
|
|
3667
|
-
else if ($e(u)) {
|
|
3668
|
-
const h = we({
|
|
3669
|
-
hash: u.subarray(2)
|
|
3670
|
-
}).output;
|
|
3671
|
-
i = s.hashForWitnessV0(t, h, a.value, o);
|
|
3672
|
-
} else {
|
|
3673
|
-
if (e.nonWitnessUtxo === void 0 && !n.__UNSAFE_SIGN_NONSEGWIT)
|
|
3674
|
-
throw new Error(
|
|
3675
|
-
`Input #${t} has witnessUtxo but non-segwit script: ` + u.toString("hex")
|
|
3676
|
-
);
|
|
3677
|
-
!r && n.__UNSAFE_SIGN_NONSEGWIT && console.warn(
|
|
3678
|
-
`Warning: Signing non-segwit inputs without the full parent transaction means there is a chance that a miner could feed you incorrect information to trick you into paying large fees. This behavior is the same as Psbt's predecessor (TransactionBuilder - now removed) when signing non-segwit scripts. You are not able to export this Psbt with toBuffer|toBase64|toHex since it is not BIP174 compliant.
|
|
3679
|
-
*********************
|
|
3680
|
-
PROCEED WITH CAUTION!
|
|
3681
|
-
*********************`
|
|
3682
|
-
), i = s.hashForSignature(t, u, o);
|
|
3683
|
-
}
|
|
3684
|
-
return {
|
|
3685
|
-
script: u,
|
|
3686
|
-
sighashType: o,
|
|
3687
|
-
hash: i
|
|
3688
|
-
};
|
|
3689
|
-
}
|
|
3690
|
-
function vo(t, e, n, r) {
|
|
3691
|
-
const c = [];
|
|
3692
|
-
if (e.tapInternalKey) {
|
|
3693
|
-
const o = dr(t, e, r);
|
|
3694
|
-
o && c.push(o);
|
|
3695
|
-
}
|
|
3696
|
-
if (e.tapScriptSig) {
|
|
3697
|
-
const o = e.tapScriptSig.map((i) => i.pubkey);
|
|
3698
|
-
c.push(...o);
|
|
3699
|
-
}
|
|
3700
|
-
return c.map(
|
|
3701
|
-
(o) => wt(t, e, n, o, r)
|
|
3702
|
-
).flat();
|
|
3703
|
-
}
|
|
3704
|
-
function dr(t, e, n) {
|
|
3705
|
-
const { script: r } = kt(t, e, n);
|
|
3706
|
-
return vt(r) ? l.from(r.subarray(2, 34)) : null;
|
|
3707
|
-
}
|
|
3708
|
-
function xn(t) {
|
|
3709
|
-
return t.length === 64 ? t : l.from(t.subarray(0, 64));
|
|
3710
|
-
}
|
|
3711
|
-
function wt(t, e, n, r, c, s, o) {
|
|
3712
|
-
const i = c.__TX, a = e.sighashType || v.SIGHASH_DEFAULT;
|
|
3713
|
-
gr(a, o);
|
|
3714
|
-
const u = n.map(
|
|
3715
|
-
(p, d) => kt(d, p, c)
|
|
3716
|
-
), f = u.map((p) => p.script), h = u.map((p) => p.value), g = [];
|
|
3717
|
-
if (e.tapInternalKey && !s) {
|
|
3718
|
-
const p = dr(t, e, c) || l.from([]);
|
|
3719
|
-
if (ge(r).equals(p)) {
|
|
3720
|
-
const d = i.hashForWitnessV1(
|
|
3721
|
-
t,
|
|
3722
|
-
f,
|
|
3723
|
-
h,
|
|
3724
|
-
a
|
|
3725
|
-
);
|
|
3726
|
-
g.push({ pubkey: r, hash: d });
|
|
3727
|
-
}
|
|
3728
|
-
}
|
|
3729
|
-
const y = (e.tapLeafScript || []).filter((p) => Ze(r, p.script)).map((p) => {
|
|
3730
|
-
const d = qe({
|
|
3731
|
-
output: p.script,
|
|
3732
|
-
version: p.leafVersion
|
|
3733
|
-
});
|
|
3734
|
-
return Object.assign({ hash: d }, p);
|
|
3735
|
-
}).filter((p) => !s || s.equals(p.hash)).map((p) => {
|
|
3736
|
-
const d = i.hashForWitnessV1(
|
|
3737
|
-
t,
|
|
3738
|
-
f,
|
|
3739
|
-
h,
|
|
3740
|
-
a,
|
|
3741
|
-
p.hash
|
|
3742
|
-
);
|
|
3743
|
-
return {
|
|
3744
|
-
pubkey: r,
|
|
3745
|
-
hash: d,
|
|
3746
|
-
leafHash: p.hash
|
|
3747
|
-
};
|
|
3748
|
-
});
|
|
3749
|
-
return g.concat(y);
|
|
3750
|
-
}
|
|
3751
|
-
function gr(t, e) {
|
|
3752
|
-
if (e && e.indexOf(t) < 0) {
|
|
3753
|
-
const n = Co(t);
|
|
3754
|
-
throw new Error(
|
|
3755
|
-
`Sighash type is not allowed. Retry the sign method passing the sighashTypes array of whitelisted types. Sighash type: ${n}`
|
|
3756
|
-
);
|
|
3757
|
-
}
|
|
3758
|
-
}
|
|
3759
|
-
function ko(t, e, n) {
|
|
3760
|
-
let r;
|
|
3761
|
-
switch (e) {
|
|
3762
|
-
case "multisig": {
|
|
3763
|
-
const c = xo(t, n);
|
|
3764
|
-
r = De({
|
|
3765
|
-
output: t,
|
|
3766
|
-
signatures: c
|
|
3767
|
-
});
|
|
3768
|
-
break;
|
|
3769
|
-
}
|
|
3770
|
-
case "pubkey":
|
|
3771
|
-
r = Pn({
|
|
3772
|
-
output: t,
|
|
3773
|
-
signature: n[0].signature
|
|
3774
|
-
});
|
|
3775
|
-
break;
|
|
3776
|
-
case "pubkeyhash":
|
|
3777
|
-
r = we({
|
|
3778
|
-
output: t,
|
|
3779
|
-
pubkey: n[0].pubkey,
|
|
3780
|
-
signature: n[0].signature
|
|
3781
|
-
});
|
|
3782
|
-
break;
|
|
3783
|
-
case "witnesspubkeyhash":
|
|
3784
|
-
r = Xe({
|
|
3785
|
-
output: t,
|
|
3786
|
-
pubkey: n[0].pubkey,
|
|
3787
|
-
signature: n[0].signature
|
|
3788
|
-
});
|
|
3789
|
-
break;
|
|
3790
|
-
}
|
|
3791
|
-
return r;
|
|
3792
|
-
}
|
|
3793
|
-
function Ao(t, e, n) {
|
|
3794
|
-
const r = n.__TX, c = {
|
|
3795
|
-
script: null,
|
|
3796
|
-
isSegwit: !1,
|
|
3797
|
-
isP2SH: !1,
|
|
3798
|
-
isP2WSH: !1
|
|
3799
|
-
};
|
|
3800
|
-
if (c.isP2SH = !!e.redeemScript, c.isP2WSH = !!e.witnessScript, e.witnessScript)
|
|
3801
|
-
c.script = e.witnessScript;
|
|
3802
|
-
else if (e.redeemScript)
|
|
3803
|
-
c.script = e.redeemScript;
|
|
3804
|
-
else if (e.nonWitnessUtxo) {
|
|
3805
|
-
const s = Je(n, e, t), o = r.ins[t].index;
|
|
3806
|
-
c.script = s.outs[o].script;
|
|
3807
|
-
} else e.witnessUtxo && (c.script = e.witnessUtxo.script);
|
|
3808
|
-
if (e.witnessScript || $e(c.script))
|
|
3809
|
-
c.isSegwit = !0;
|
|
3810
|
-
else
|
|
3811
|
-
try {
|
|
3812
|
-
const s = c.script;
|
|
3813
|
-
if (!s) throw new TypeError("Invalid script for segwit address");
|
|
3814
|
-
c.isSegwit = Yn(s);
|
|
3815
|
-
} catch {
|
|
3816
|
-
}
|
|
3817
|
-
return c;
|
|
3818
|
-
}
|
|
3819
|
-
function Cn(t, e, n) {
|
|
3820
|
-
const r = x.checkForInput(e, t);
|
|
3821
|
-
if (!r.bip32Derivation || r.bip32Derivation.length === 0)
|
|
3822
|
-
throw new Error("Need bip32Derivation to sign with HD");
|
|
3823
|
-
const c = r.bip32Derivation.map((s) => {
|
|
3824
|
-
if (s.masterFingerprint.equals(n.fingerprint))
|
|
3825
|
-
return s;
|
|
3826
|
-
}).filter((s) => !!s);
|
|
3827
|
-
if (c.length === 0)
|
|
3828
|
-
throw new Error(
|
|
3829
|
-
"Need one bip32Derivation masterFingerprint to match the HDSigner fingerprint"
|
|
3830
|
-
);
|
|
3831
|
-
return c.map((s) => {
|
|
3832
|
-
const o = n.derivePath(s.path);
|
|
3833
|
-
if (!s.pubkey.equals(o.publicKey))
|
|
3834
|
-
throw new Error("pubkey did not match bip32Derivation");
|
|
3835
|
-
return o;
|
|
3836
|
-
});
|
|
3837
|
-
}
|
|
3838
|
-
function xo(t, e) {
|
|
3839
|
-
return De({ output: t }).pubkeys.map((r) => (e.filter((c) => c.pubkey.equals(r))[0] || {}).signature).filter((r) => !!r);
|
|
3840
|
-
}
|
|
3841
|
-
function yr(t) {
|
|
3842
|
-
let e = 0;
|
|
3843
|
-
function n(o) {
|
|
3844
|
-
return e += o, t.subarray(e - o, e);
|
|
3845
|
-
}
|
|
3846
|
-
function r() {
|
|
3847
|
-
const o = Tn(t, e);
|
|
3848
|
-
return e += Tn.bytes, o;
|
|
3849
|
-
}
|
|
3850
|
-
function c() {
|
|
3851
|
-
return n(r());
|
|
3852
|
-
}
|
|
3853
|
-
function s() {
|
|
3854
|
-
const o = r(), i = [];
|
|
3855
|
-
for (let a = 0; a < o; a++) i.push(c());
|
|
3856
|
-
return i;
|
|
3857
|
-
}
|
|
3858
|
-
return s();
|
|
3859
|
-
}
|
|
3860
|
-
function Co(t) {
|
|
3861
|
-
let e = t & v.SIGHASH_ANYONECANPAY ? "SIGHASH_ANYONECANPAY | " : "";
|
|
3862
|
-
switch (t & 31) {
|
|
3863
|
-
case v.SIGHASH_ALL:
|
|
3864
|
-
e += "SIGHASH_ALL";
|
|
3865
|
-
break;
|
|
3866
|
-
case v.SIGHASH_SINGLE:
|
|
3867
|
-
e += "SIGHASH_SINGLE";
|
|
3868
|
-
break;
|
|
3869
|
-
case v.SIGHASH_NONE:
|
|
3870
|
-
e += "SIGHASH_NONE";
|
|
3871
|
-
break;
|
|
3872
|
-
}
|
|
3873
|
-
return e;
|
|
3874
|
-
}
|
|
3875
|
-
function Et(t, e, n) {
|
|
3876
|
-
t.__NON_WITNESS_UTXO_BUF_CACHE[n] = e.nonWitnessUtxo, t.__NON_WITNESS_UTXO_TX_CACHE[n] = v.fromBuffer(e.nonWitnessUtxo);
|
|
3877
|
-
const r = t, c = n;
|
|
3878
|
-
delete e.nonWitnessUtxo, Object.defineProperty(e, "nonWitnessUtxo", {
|
|
3879
|
-
enumerable: !0,
|
|
3880
|
-
get() {
|
|
3881
|
-
const s = r.__NON_WITNESS_UTXO_BUF_CACHE[c], o = r.__NON_WITNESS_UTXO_TX_CACHE[c];
|
|
3882
|
-
if (s !== void 0)
|
|
3883
|
-
return s;
|
|
3884
|
-
{
|
|
3885
|
-
const i = o.toBuffer();
|
|
3886
|
-
return r.__NON_WITNESS_UTXO_BUF_CACHE[c] = i, i;
|
|
3887
|
-
}
|
|
3888
|
-
},
|
|
3889
|
-
set(s) {
|
|
3890
|
-
r.__NON_WITNESS_UTXO_BUF_CACHE[c] = s;
|
|
3891
|
-
}
|
|
3892
|
-
});
|
|
3893
|
-
}
|
|
3894
|
-
function Sr(t, e, n, r, c) {
|
|
3895
|
-
let s = 0;
|
|
3896
|
-
t.forEach((u, f) => {
|
|
3897
|
-
if (r && u.finalScriptSig && (e.ins[f].script = u.finalScriptSig), r && u.finalScriptWitness && (e.ins[f].witness = yr(u.finalScriptWitness)), u.witnessUtxo)
|
|
3898
|
-
s += u.witnessUtxo.value;
|
|
3899
|
-
else if (u.nonWitnessUtxo) {
|
|
3900
|
-
const h = Je(n, u, f), g = e.ins[f].index, y = h.outs[g];
|
|
3901
|
-
s += y.value;
|
|
3902
|
-
}
|
|
3903
|
-
});
|
|
3904
|
-
const o = e.outs.reduce((u, f) => u + f.value, 0), i = s - o;
|
|
3905
|
-
if (!c && i < 0)
|
|
3906
|
-
throw new Error(
|
|
3907
|
-
`Outputs are spending more than Inputs ${s} < ${o}`
|
|
3908
|
-
);
|
|
3909
|
-
const a = e.virtualSize();
|
|
3910
|
-
n.__FEE = i, n.__EXTRACTED_TX = e, n.__FEE_RATE = Math.floor(i / a);
|
|
3911
|
-
}
|
|
3912
|
-
function Je(t, e, n) {
|
|
3913
|
-
const r = t.__NON_WITNESS_UTXO_TX_CACHE;
|
|
3914
|
-
return r[n] || Et(t, e, n), r[n];
|
|
3915
|
-
}
|
|
3916
|
-
function wr(t, e, n) {
|
|
3917
|
-
const { script: r } = kt(t, e, n);
|
|
3918
|
-
return r;
|
|
3919
|
-
}
|
|
3920
|
-
function kt(t, e, n) {
|
|
3921
|
-
if (e.witnessUtxo !== void 0)
|
|
3922
|
-
return {
|
|
3923
|
-
script: e.witnessUtxo.script,
|
|
3924
|
-
value: e.witnessUtxo.value
|
|
3925
|
-
};
|
|
3926
|
-
if (e.nonWitnessUtxo !== void 0) {
|
|
3927
|
-
const c = Je(n, e, t).outs[n.__TX.ins[t].index];
|
|
3928
|
-
return { script: c.script, value: c.value };
|
|
3929
|
-
} else
|
|
3930
|
-
throw new Error("Can't find pubkey in input without Utxo data");
|
|
3931
|
-
}
|
|
3932
|
-
function Oo(t, e, n, r) {
|
|
3933
|
-
const c = wr(n, e, r), { meaningfulScript: s } = Qe(
|
|
3934
|
-
c,
|
|
3935
|
-
n,
|
|
3936
|
-
"input",
|
|
3937
|
-
e.redeemScript,
|
|
3938
|
-
e.witnessScript
|
|
3939
|
-
);
|
|
3940
|
-
return Ze(t, s);
|
|
3941
|
-
}
|
|
3942
|
-
function Po(t, e, n, r) {
|
|
3943
|
-
const c = r.__TX.outs[n].script, { meaningfulScript: s } = Qe(
|
|
3944
|
-
c,
|
|
3945
|
-
n,
|
|
3946
|
-
"output",
|
|
3947
|
-
e.redeemScript,
|
|
3948
|
-
e.witnessScript
|
|
3949
|
-
);
|
|
3950
|
-
return Ze(t, s);
|
|
3951
|
-
}
|
|
3952
|
-
function No(t) {
|
|
3953
|
-
if (!t) return;
|
|
3954
|
-
const e = ue(t);
|
|
3955
|
-
if (!e) return;
|
|
3956
|
-
const n = e[e.length - 1];
|
|
3957
|
-
if (!(!l.isBuffer(n) || Er(n) || Bo(n) || !ue(n)))
|
|
3958
|
-
return n;
|
|
3959
|
-
}
|
|
3960
|
-
function Uo(t) {
|
|
3961
|
-
if (!t) return;
|
|
3962
|
-
const e = yr(t), n = e[e.length - 1];
|
|
3963
|
-
if (!(Er(n) || !ue(n)))
|
|
3964
|
-
return n;
|
|
3965
|
-
}
|
|
3966
|
-
function Ho(t) {
|
|
3967
|
-
if (t.length === 65) {
|
|
3968
|
-
const e = t[64] & 1, n = l.from(t.subarray(0, 33));
|
|
3969
|
-
return n[0] = 2 | e, n;
|
|
3970
|
-
}
|
|
3971
|
-
return l.from(t);
|
|
3972
|
-
}
|
|
3973
|
-
function Er(t) {
|
|
3974
|
-
return t.length === 33 && kr(t);
|
|
3975
|
-
}
|
|
3976
|
-
function Bo(t) {
|
|
3977
|
-
return Un(t);
|
|
3978
|
-
}
|
|
3979
|
-
function Qe(t, e, n, r, c) {
|
|
3980
|
-
const s = or(t), o = s && r && Sn(r), i = Sn(t);
|
|
3981
|
-
if (s && r === void 0)
|
|
3982
|
-
throw new Error("scriptPubkey is P2SH but redeemScript missing");
|
|
3983
|
-
if ((i || o) && c === void 0)
|
|
3984
|
-
throw new Error("scriptPubkey or redeemScript is P2WSH but witnessScript missing");
|
|
3985
|
-
let a;
|
|
3986
|
-
return o ? (a = c, In(e, t, r, n), vn(e, r, c, n), Ge(a)) : i ? (a = c, vn(e, t, c, n), Ge(a)) : s ? (a = r, In(e, t, r, n)) : a = t, {
|
|
3987
|
-
meaningfulScript: a,
|
|
3988
|
-
type: o ? "p2sh-p2wsh" : s ? "p2sh" : i ? "p2wsh" : "raw"
|
|
3989
|
-
};
|
|
3990
|
-
}
|
|
3991
|
-
function Ge(t) {
|
|
3992
|
-
if ($e(t) || or(t))
|
|
3993
|
-
throw new Error("P2WPKH or P2SH can not be contained within P2WSH");
|
|
3994
|
-
}
|
|
3995
|
-
function br(t) {
|
|
3996
|
-
return $e(t) ? "witnesspubkeyhash" : $s(t) ? "pubkeyhash" : zs(t) ? "multisig" : Ys(t) ? "pubkey" : "nonstandard";
|
|
3997
|
-
}
|
|
3998
|
-
function le(t) {
|
|
3999
|
-
return [...Array(t).keys()];
|
|
4000
|
-
}
|
|
4001
|
-
export {
|
|
4002
|
-
ze as A,
|
|
4003
|
-
Ye as B,
|
|
4004
|
-
Yn as C,
|
|
4005
|
-
$n as D,
|
|
4006
|
-
Jn as E,
|
|
4007
|
-
_e as F,
|
|
4008
|
-
Is as G,
|
|
4009
|
-
Qn as H,
|
|
4010
|
-
er as I,
|
|
4011
|
-
tr as J,
|
|
4012
|
-
zs as K,
|
|
4013
|
-
Ys as L,
|
|
4014
|
-
$s as M,
|
|
4015
|
-
$e as N,
|
|
4016
|
-
Sn as O,
|
|
4017
|
-
St as P,
|
|
4018
|
-
or as Q,
|
|
4019
|
-
vt as R,
|
|
4020
|
-
Xo as S,
|
|
4021
|
-
Do as T,
|
|
4022
|
-
ye as U,
|
|
4023
|
-
ir as V,
|
|
4024
|
-
Ze as W,
|
|
4025
|
-
Zs as X,
|
|
4026
|
-
cr as Y,
|
|
4027
|
-
Qs as Z,
|
|
4028
|
-
Zn as _,
|
|
4029
|
-
_s as a,
|
|
4030
|
-
Ve as b,
|
|
4031
|
-
Go as c,
|
|
4032
|
-
K as d,
|
|
4033
|
-
Io as e,
|
|
4034
|
-
Kn as f,
|
|
4035
|
-
mo as g,
|
|
4036
|
-
wn as h,
|
|
4037
|
-
Fn as i,
|
|
4038
|
-
N as j,
|
|
4039
|
-
ct as k,
|
|
4040
|
-
En as l,
|
|
4041
|
-
bn as m,
|
|
4042
|
-
Wo as n,
|
|
4043
|
-
qo as o,
|
|
4044
|
-
ke as p,
|
|
4045
|
-
Vo as q,
|
|
4046
|
-
no as r,
|
|
4047
|
-
Re as s,
|
|
4048
|
-
ge as t,
|
|
4049
|
-
ro as u,
|
|
4050
|
-
io as v,
|
|
4051
|
-
me as w,
|
|
4052
|
-
Ie as x,
|
|
4053
|
-
zn as y,
|
|
4054
|
-
We as z
|
|
4055
|
-
};
|