diff --git a/src/crypto.rs b/src/crypto.rs index aa5c315..972c658 100644 --- a/src/crypto.rs +++ b/src/crypto.rs @@ -1,4 +1,5 @@ use anyhow::Result; +use rs_merkle::{algorithms::Sha256, MerkleProof}; use sp_client::silentpayments::{ bitcoin_hashes::{sha256t_hash_newtype, Hash, HashEngine}, secp256k1::PublicKey, @@ -61,3 +62,8 @@ pub fn decrypt_with_key(key: &[u8; 32], ciphertext: &[u8]) -> Result> { Ok(plaintext) } + +pub fn verify_merkle_proof(proof: &[u8], root: &[u8; 32], index: usize, hash: &[u8; 32], total_leaves_count: usize) -> Result { + let proof = MerkleProof::::from_bytes(proof)?; + Ok(proof.verify(*root, &[index], &[*hash], total_leaves_count)) +}