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