use js_export_macro::js_export;
use miden_client::crypto::SparseMerklePath as NativeSparseMerklePath;
use super::word::Word;
use crate::platform::{js_u64_to_u64, u64_to_js_u64};
#[derive(Clone)]
#[js_export]
pub struct SparseMerklePath(NativeSparseMerklePath);
#[js_export]
impl SparseMerklePath {
#[js_export(js_name = "emptyNodesMask")]
pub fn empty_nodes_mask(&self) -> JsU64 {
let (mask, _siblings) = self.0.clone().into_parts();
u64_to_js_u64(mask)
}
pub fn nodes(&self) -> Vec<Word> {
let (_mask, siblings) = self.0.clone().into_parts();
siblings.into_iter().map(Into::into).collect()
}
pub fn verify(&self, index: JsU64, node: &Word, root: &Word) -> bool {
self.0
.verify(js_u64_to_u64(index), node.clone().into(), &root.clone().into())
.is_ok()
}
}
impl From<NativeSparseMerklePath> for SparseMerklePath {
fn from(native_path: NativeSparseMerklePath) -> Self {
SparseMerklePath(native_path)
}
}
impl From<&NativeSparseMerklePath> for SparseMerklePath {
fn from(native_path: &NativeSparseMerklePath) -> Self {
SparseMerklePath(native_path.clone())
}
}