From e5802d2855522ca2b67db286cc8ed5cf5537ac27 Mon Sep 17 00:00:00 2001 From: Sosthene Date: Mon, 30 Jun 2025 19:41:23 +0200 Subject: [PATCH] Add verify_merkle_proof() --- src/crypto.rs | 6 ++++++ 1 file changed, 6 insertions(+) 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)) +}