#!/usr/bin/env python3 import sys; assert sys.version_info[0] >= 3, "Python 3 required." from hashlib import blake2b import struct from .transaction import ( LegacyTransaction, MAX_MONEY, OVERWINTER_TX_VERSION, Script, ) from .output import render_args, render_tv, Some from .rand import Rand SIGHASH_ALL = 1 SIGHASH_NONE = 2 SIGHASH_SINGLE = 3 SIGHASH_ANYONECANPAY = 0x80 NOT_AN_INPUT = -1 # For portability of the test vectors; replaced with None for Rust def getHashPrevouts(tx, person=b'ZcashPrevoutHash'): digest = blake2b(digest_size=32, person=person) for x in tx.vin: digest.update(bytes(x.prevout)) return digest.digest() def getHashSequence(tx, person=b'ZcashSequencHash'): digest = blake2b(digest_size=32, person=person) for x in tx.vin: digest.update(struct.pack(' 0: hashJoinSplits = getHashJoinSplits(tx) digest = blake2b( digest_size=32, person=b'ZcashSigHash' + struct.pack('', 'bitcoin_flavoured': False}), ('script_code', 'Vec'), ('transparent_input', { 'rust_type': 'Option', 'rust_fmt': lambda x: None if x == -1 else Some(x), }), ('hash_type', 'u32'), ('amount', 'i64'), ('consensus_branch_id', 'u32'), ('sighash', '[u8; 32]'), ), test_vectors, ) if __name__ == '__main__': main()