(txTo, spent_utxos, hash_type, input_index=0, *, scriptpath=False, leaf_script=None, codeseparator_pos=-1, annex=None, leaf_ver=LEAF_VERSION_TAPSCRIPT)
| 815 | return sha256(b"".join(o.serialize() for o in txTo.vout)) |
| 816 | |
| 817 | def TaprootSignatureMsg(txTo, spent_utxos, hash_type, input_index=0, *, scriptpath=False, leaf_script=None, codeseparator_pos=-1, annex=None, leaf_ver=LEAF_VERSION_TAPSCRIPT): |
| 818 | assert_equal(len(txTo.vin), len(spent_utxos)) |
| 819 | assert input_index < len(txTo.vin) |
| 820 | out_type = SIGHASH_ALL if hash_type == 0 else hash_type & 3 |
| 821 | in_type = hash_type & SIGHASH_ANYONECANPAY |
| 822 | spk = spent_utxos[input_index].scriptPubKey |
| 823 | ss = bytes([0, hash_type]) # epoch, hash_type |
| 824 | ss += txTo.version.to_bytes(4, "little") |
| 825 | ss += txTo.nLockTime.to_bytes(4, "little") |
| 826 | if in_type != SIGHASH_ANYONECANPAY: |
| 827 | ss += BIP341_sha_prevouts(txTo) |
| 828 | ss += BIP341_sha_amounts(spent_utxos) |
| 829 | ss += BIP341_sha_scriptpubkeys(spent_utxos) |
| 830 | ss += BIP341_sha_sequences(txTo) |
| 831 | if out_type == SIGHASH_ALL: |
| 832 | ss += BIP341_sha_outputs(txTo) |
| 833 | spend_type = 0 |
| 834 | if annex is not None: |
| 835 | spend_type |= 1 |
| 836 | if scriptpath: |
| 837 | spend_type |= 2 |
| 838 | ss += bytes([spend_type]) |
| 839 | if in_type == SIGHASH_ANYONECANPAY: |
| 840 | ss += txTo.vin[input_index].prevout.serialize() |
| 841 | ss += spent_utxos[input_index].nValue.to_bytes(8, "little", signed=True) |
| 842 | ss += ser_string(spk) |
| 843 | ss += txTo.vin[input_index].nSequence.to_bytes(4, "little") |
| 844 | else: |
| 845 | ss += input_index.to_bytes(4, "little") |
| 846 | if (spend_type & 1): |
| 847 | ss += sha256(ser_string(annex)) |
| 848 | if out_type == SIGHASH_SINGLE: |
| 849 | if input_index < len(txTo.vout): |
| 850 | ss += sha256(txTo.vout[input_index].serialize()) |
| 851 | else: |
| 852 | ss += bytes(0 for _ in range(32)) |
| 853 | if scriptpath: |
| 854 | ss += TaggedHash("TapLeaf", bytes([leaf_ver]) + ser_string(leaf_script)) |
| 855 | ss += bytes([0]) |
| 856 | ss += codeseparator_pos.to_bytes(4, "little", signed=False) |
| 857 | assert_equal(len(ss), 175 - (in_type == SIGHASH_ANYONECANPAY) * 49 - (out_type != SIGHASH_ALL and out_type != SIGHASH_SINGLE) * 32 + (annex is not None) * 32 + scriptpath * 37) |
| 858 | return ss |
| 859 | |
| 860 | def TaprootSignatureHash(*args, **kwargs): |
| 861 | return TaggedHash("TapSighash", TaprootSignatureMsg(*args, **kwargs)) |
no test coverage detected