verity_verify_local/
merkle.rsuse rs_merkle::{ algorithms::Sha256, Hasher, MerkleTree };
pub fn generate_merkle_tree(leaves: &Vec<[u8; 32]>) -> MerkleTree<Sha256> {
let tree: MerkleTree<Sha256> = MerkleTree::<Sha256>::from_leaves(&leaves);
return tree;
}
pub fn validate_merkle_tree(leaves: &Vec<String>, root_hash: &String) -> bool {
let leaves: Vec<[u8; 32]> = leaves
.iter()
.map(|proof_response| {
let proof_byte_content = proof_response.as_bytes();
Sha256::hash(proof_byte_content)
})
.collect();
let merkle_tree = generate_merkle_tree(&leaves);
let root = merkle_tree.root().unwrap();
let derived_root_hash = hex::encode(root);
let root_hash = root_hash.to_owned();
return derived_root_hash == root_hash;
}