コード例 #1
0
ファイル: blocks.py プロジェクト: Mat001/cilantro
    def _compute_block_hash(cls, block_data: dict) -> str:
        """
        Computes the block's hash as a function of the block data. The process for computing the block hash follows:
        - Binarize all block_data values
        - Lexicographically sort block_data keys
        - Concatenate binarized block_data values in this lexicographical order
        - SHA3 hash this concatenated binary

        :param block_data: The dictionary of containing a key for each column in BLOCK_DATA_COLS
        (ie 'merkle_root', 'prev_block_hash', .. ect)
        :return: The block's hash, as a 64 character hex string
        """
        ordered_values = [block_data[key] for key in sorted(block_data.keys())]
        return Hasher.hash_iterable(ordered_values)
コード例 #2
0
 def verify_tree(nodes: list, tree_hash: bytes):
     """
     Attempts to verify merkle tree represented implicitly by the list 'nodes'. The tree is valid if it maintains
     the invariant that the value of each non-leaf node is the hash of its left child's value concatenated with
     its right child's value.
     :param nodes: The nodes in the tree, represented implicitly as a list
     :param tree_hash: The expected hash of the merkle tree formed from nodes (the 'hash of a merkle tree' is the
     value returned by the .hash_of_nodes method on this class)
     :return: True if the tree is valid; False otherwise
     """
     nodes = MerkleTree.merklize(nodes, hash_leaves=False)
     h = Hasher.hash_iterable(nodes,
                              algorithm=Hasher.Alg.SHA3_256,
                              return_bytes=True)
     return h == tree_hash
コード例 #3
0
ファイル: merkle_tree.py プロジェクト: sanko61/cilantro
 def hash_nodes(nodes: list):
     log.warning("HASH LEAVES API SHOULD BE DEPRECATED")
     return Hasher.hash_iterable(nodes,
                                 algorithm=Hasher.Alg.SHA3_256,
                                 return_bytes=True)
コード例 #4
0
 def hash_nodes(nodes: list):
     return Hasher.hash_iterable(nodes,
                                 algorithm=Hasher.Alg.SHA3_256,
                                 return_bytes=True)