validate_merkle_proof takes a JsValue

This commit is contained in:
Sosthene 2025-07-11 13:49:08 +02:00
parent 58dfe53408
commit bb5fb5e75f

View File

@ -1809,17 +1809,19 @@ pub fn get_merkle_proof(process_state: JsValue, attribute_name: String) -> ApiRe
/// leads to the claimed root when combined with the attribute hash.
///
/// # Arguments
/// * `proof_result` - The MerkleProofResult containing the proof and metadata
/// * `proof_result` - a JsValue expected to contain a MerkleProofResult with the proof and metadata
/// * `hash` - The hash of the attribute data as a hex string (the leaf value)
///
/// # Returns
/// A boolean indicating whether the proof is valid
///
/// # Errors
/// * "serde_wasm_bindgen deserialization error" - If the proof is not a valid MerkleProofResult
/// * "Invalid proof format" - If the proof cannot be parsed
/// * "Invalid hash format" - If the hash is not a valid 32-byte hex string
/// * "Invalid root format" - If the root is not a valid 32-byte hex string
pub fn validate_merkle_proof(proof_result: MerkleProofResult, hash: String) -> ApiResult<bool> {
pub fn validate_merkle_proof(proof_result: JsValue, hash: String) -> ApiResult<bool> {
let proof_result: MerkleProofResult = serde_wasm_bindgen::from_value(proof_result)?;
let root_bytes: [u8; 32] = Vec::from_hex(&proof_result.root)?
.try_into()
.map_err(|_| ApiError::new("Invalid root format".to_owned()))?;