Exemplo n.º 1
0
    def preimage_hash(self, coin: CoinInfo, tx: SignTx, txi: TxInputType,
                      pubkeyhash: bytes, sighash: int) -> bytes:
        h_preimage = HashWriter(
            blake2b, b'', 32,
            b'ZcashSigHash\x19\x1b\xa8\x5b')  # BRANCH_ID = 0x5ba81b19

        assert tx.overwintered

        write_uint32(h_preimage,
                     tx.version | OVERWINTERED)  # 1. nVersion | fOverwintered
        write_uint32(h_preimage, coin.version_group_id)  # 2. nVersionGroupId
        write_bytes(h_preimage,
                    bytearray(self.get_prevouts_hash()))  # 3. hashPrevouts
        write_bytes(h_preimage,
                    bytearray(self.get_sequence_hash()))  # 4. hashSequence
        write_bytes(h_preimage,
                    bytearray(self.get_outputs_hash()))  # 5. hashOutputs
        write_bytes(h_preimage, b'\x00' * 32)  # 6. hashJoinSplits
        write_uint32(h_preimage, tx.lock_time)  # 7. nLockTime
        write_uint32(h_preimage, tx.expiry)  # 8. expiryHeight
        write_uint32(h_preimage, sighash)  # 9. nHashType

        write_bytes_rev(h_preimage, txi.prev_hash)  # 10a. outpoint
        write_uint32(h_preimage, txi.prev_index)

        script_code = self.derive_script_code(txi,
                                              pubkeyhash)  # 10b. scriptCode
        write_varint(h_preimage, len(script_code))
        write_bytes(h_preimage, script_code)

        write_uint64(h_preimage, txi.amount)  # 10c. value

        write_uint32(h_preimage, txi.sequence)  # 10d. nSequence

        return get_tx_hash(h_preimage)
Exemplo n.º 2
0
    def preimage_hash(
        self,
        coin: CoinInfo,
        tx: SignTx,
        txi: TxInputType,
        pubkeyhash: bytes,
        sighash: int,
    ) -> bytes:
        h_preimage = HashWriter(sha256)

        assert not tx.overwintered

        write_uint32(h_preimage, tx.version)  # nVersion
        write_bytes(h_preimage,
                    bytearray(self.get_prevouts_hash(coin)))  # hashPrevouts
        write_bytes(h_preimage,
                    bytearray(self.get_sequence_hash(coin)))  # hashSequence

        write_bytes_rev(h_preimage, txi.prev_hash)  # outpoint
        write_uint32(h_preimage, txi.prev_index)  # outpoint

        script_code = self.derive_script_code(txi, pubkeyhash)  # scriptCode
        write_varint(h_preimage, len(script_code))
        write_bytes(h_preimage, script_code)

        write_uint64(h_preimage, txi.amount)  # amount
        write_uint32(h_preimage, txi.sequence)  # nSequence
        write_bytes(h_preimage,
                    bytearray(self.get_outputs_hash(coin)))  # hashOutputs
        write_uint32(h_preimage, tx.lock_time)  # nLockTime
        write_uint32(h_preimage, sighash)  # nHashType

        return get_tx_hash(h_preimage, double=coin.sign_hash_double)
Exemplo n.º 3
0
 def add_prevouts(self, txi: TxInputType):
     write_bytes_rev(self.h_prevouts, txi.prev_hash)
     write_uint32(self.h_prevouts, txi.prev_index)