Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

WASM: change Witness to use MerkleNoteHash instead of Scalar #5736

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions ironfish-rust-wasm/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ wasm_bindgen_wrapper! {
#[wasm_bindgen]
impl Witness {
#[wasm_bindgen(constructor)]
pub fn new(tree_size: usize, root_hash: Scalar, auth_path: Vec<WitnessNode>) -> Self {
pub fn new(tree_size: usize, root_hash: MerkleNoteHash, auth_path: Vec<WitnessNode>) -> Self {
Self(ironfish::witness::Witness {
tree_size,
root_hash: root_hash.into(),
root_hash: root_hash.value().into(),
auth_path: auth_path.into_iter().map(WitnessNode::into).collect(),
})
}

#[wasm_bindgen(getter)]
#[wasm_bindgen(getter, js_name = treeSize)]
pub fn tree_size(&self) -> usize {
self.0.tree_size
}

#[wasm_bindgen(getter)]
#[wasm_bindgen(getter, js_name = rootHash)]
pub fn root_hash(&self) -> Scalar {
self.0.root_hash.into()
}

#[wasm_bindgen(getter)]
#[wasm_bindgen(getter, js_name = authPath)]
pub fn auth_path(&self) -> Vec<WitnessNode> {
self.0
.auth_path
Expand Down Expand Up @@ -79,12 +79,13 @@ impl WitnessNode {
}

#[wasm_bindgen(getter)]
pub fn hash(&self) -> Scalar {
match self.0 {
pub fn hash(&self) -> MerkleNoteHash {
let value = match self.0 {
ironfish::witness::WitnessNode::Left(ref hash) => hash,
ironfish::witness::WitnessNode::Right(ref hash) => hash,
}
.to_owned()
.into()
.into();
MerkleNoteHash::from_value(value)
}
}
Loading