use risc0_zkvm::sha::Impl as Sha256Impl;
use risc0_zkvm::sha::Sha256;
use taproot_assets_core::verify::tx::{MerkleHasher, verify_tx_merkle_proof_input_with_hasher};
pub type VerifyMerkleProofInput = taproot_assets_core::verify::tx::VerifyMerkleProofInput;
pub type AnchorClaimInput = taproot_assets_core::verify::tx::AnchorClaimInput;
pub type AnchorClaimOutput = taproot_assets_core::verify::tx::AnchorClaimOutput;
#[derive(Debug, Clone, Copy, Default)]
pub struct Risc0MerkleHasher;
impl MerkleHasher for Risc0MerkleHasher {
fn hash_nodes(&self, left: [u8; 32], right: [u8; 32]) -> [u8; 32] {
let mut buf = [0u8; 64];
buf[..32].copy_from_slice(&left);
buf[32..].copy_from_slice(&right);
let h = Sha256Impl::hash_bytes(&Sha256Impl::hash_bytes(&buf).as_bytes());
h.as_bytes().try_into().unwrap()
}
}
pub fn verify_tx_merkle_proof(input: &VerifyMerkleProofInput) -> bool {
verify_tx_merkle_proof_input_with_hasher(input, &Risc0MerkleHasher).is_ok()
}
pub fn verify_anchor_claim(
input: &AnchorClaimInput,
) -> Result<AnchorClaimOutput, taproot_assets_core::verify::tx::Error> {
taproot_assets_core::verify::tx::verify_anchor_claim_with_hasher(input, &Risc0MerkleHasher)
}