Skip to content

Commit 978bd28

Browse files
committed
WASM: change Witness to use MerkleNoteHash instead of Scalar
This provides better type safety.
1 parent 50ddd7c commit 978bd28

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

ironfish-rust-wasm/src/witness.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@ wasm_bindgen_wrapper! {
1414
#[wasm_bindgen]
1515
impl Witness {
1616
#[wasm_bindgen(constructor)]
17-
pub fn new(tree_size: usize, root_hash: Scalar, auth_path: Vec<WitnessNode>) -> Self {
17+
pub fn new(tree_size: usize, root_hash: MerkleNoteHash, auth_path: Vec<WitnessNode>) -> Self {
1818
Self(ironfish::witness::Witness {
1919
tree_size,
20-
root_hash: root_hash.into(),
20+
root_hash: root_hash.value().into(),
2121
auth_path: auth_path.into_iter().map(WitnessNode::into).collect(),
2222
})
2323
}
2424

25-
#[wasm_bindgen(getter)]
25+
#[wasm_bindgen(getter, js_name = treeSize)]
2626
pub fn tree_size(&self) -> usize {
2727
self.0.tree_size
2828
}
2929

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

35-
#[wasm_bindgen(getter)]
35+
#[wasm_bindgen(getter, js_name = authPath)]
3636
pub fn auth_path(&self) -> Vec<WitnessNode> {
3737
self.0
3838
.auth_path
@@ -79,12 +79,13 @@ impl WitnessNode {
7979
}
8080

8181
#[wasm_bindgen(getter)]
82-
pub fn hash(&self) -> Scalar {
83-
match self.0 {
82+
pub fn hash(&self) -> MerkleNoteHash {
83+
let value = match self.0 {
8484
ironfish::witness::WitnessNode::Left(ref hash) => hash,
8585
ironfish::witness::WitnessNode::Right(ref hash) => hash,
8686
}
8787
.to_owned()
88-
.into()
88+
.into();
89+
MerkleNoteHash::from_value(value)
8990
}
9091
}

0 commit comments

Comments
 (0)