Exemple #1
0
def compute_digest_from_filelike_and_callback(filelike, h:_hashlib.HASH, bufferSize=STATIC_DEFAULT_BUFFER_SIZE, cback=None):
	"""
	Accessory method used to compute the digest of an input file-like object
	"""
	
	buf = filelike.read(bufferSize)
	while len(buf) > 0:
		h.update(buf)
		if cback:
			cback(buf)
		buf = filelike.read(bufferSize)
		
	return h.digest()
Exemple #2
0
    def calculate_hash2(self, part1: HASH) -> bytes:
        """Return the hash of the transaction, starting from a partial hash

        The hash of the transactions is the `sha256(sha256(bytes(tx))`.

        :param part1: A partial hash of the transaction, usually from `calculate_hash1`
        :type part1: :py:class:`_hashlib.HASH`

        :return: The transaction hash
        :rtype: bytes
        """
        part1.update(
            self.nonce.to_bytes(self.HASH_NONCE_SIZE,
                                byteorder='big',
                                signed=False))
        # SHA256D gets the hash in littlean format. Reverse the bytes to get the big-endian representation.
        return hashlib.sha256(part1.digest()).digest()[::-1]