code: def calc_root(key: bytes, value: bytes, branch: Sequence[Hash32]) -> Hash32:
      
      validate_is_bytes(key)
      validate_is_bytes(value)
      validate_length(branch, len(key)*8)
  
      path = to_int(key)
      target_bit = 1
      # traverse the path in leaf->root order
      # branch is in root->leaf order (key is in MSB to LSB order)
      node_hash = keccak(value)
      for sibling_node in reversed(branch):
          if path & target_bit:
              node_hash = keccak(sibling_node + node_hash)
          else:
              node_hash = keccak(node_hash + sibling_node)
          target_bit <<= 1
  
      return node_hash
docs: Obtain the merkle root of a given key/value/branch set.
      Can be used to validate a merkle proof or compute it's value from data.
  
      :param key: the keypath to decide the ordering of the sibling nodes in the branch
      :param value: the value (or leaf) that starts the merkle proof computation
      :param branch: the sequence of sibling nodes used to recursively perform the computation
  
      :return: the root hash of the merkle proof computation
  
      .. doctest::
  
          >>> key = b'\x02'  # Keypath
          >>> value = b''  # Value (or leaf)
          >>> branch = tuple([b'\x00'] * 8)  # Any list of hashes
          >>> calc_root(key, value, branch)
          b'.+4IKt[\xd2\x14\xe4).\xf5\xc6\n\x11=\x01\xe89\xa1Z\x07#\xfd~(;\xfb\xb8\x8a\x0e'