From 878c3c5c5fbb89f050e80078538af093f858e4fd Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Mon, 3 Oct 2022 08:50:27 -0400 Subject: [PATCH] fix(rln-wasm): expose verify_rln_proof instead of verify (#58) --- rln-wasm/Cargo.toml | 2 +- rln-wasm/src/lib.rs | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/rln-wasm/Cargo.toml b/rln-wasm/Cargo.toml index 40e9ae9..1f74007 100644 --- a/rln-wasm/Cargo.toml +++ b/rln-wasm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rln-wasm" -version = "0.0.2" +version = "0.0.3" edition = "2021" license = "MIT or Apache2" diff --git a/rln-wasm/src/lib.rs b/rln-wasm/src/lib.rs index 19c64bf..a512a69 100644 --- a/rln-wasm/src/lib.rs +++ b/rln-wasm/src/lib.rs @@ -117,10 +117,10 @@ pub fn wasm_key_gen(ctx: *const RLNWrapper) -> Result { } #[allow(clippy::not_unsafe_ptr_arg_deref)] -#[wasm_bindgen(js_name = verifyProof)] -pub fn wasm_verify(ctx: *const RLNWrapper, proof: Uint8Array) -> bool { +#[wasm_bindgen(js_name = verifyRLNProof)] +pub fn wasm_verify_rln_proof(ctx: *const RLNWrapper, proof: Uint8Array) -> bool { let wrapper = unsafe { &*ctx }; - if match wrapper.instance.verify(&proof.to_vec()[..]) { + if match wrapper.instance.verify_rln_proof(&proof.to_vec()[..]) { Ok(verified) => verified, Err(_) => return false, } { @@ -167,7 +167,7 @@ mod tests { wasm_set_next_leaf(rln_instance, idcommitment).unwrap(); // Prepare the message - let mut signal = "Hello World".as_bytes().to_vec(); + let signal = "Hello World".as_bytes(); let signal_len: u64 = signal.len() as u64; // Setting up the epoch (With 0s for the test) @@ -182,7 +182,7 @@ mod tests { serialized_vec.append(&mut identity_index.to_le_bytes().to_vec()); serialized_vec.append(&mut epoch.to_vec()); serialized_vec.append(&mut signal_len.to_le_bytes().to_vec()); - serialized_vec.append(&mut signal); + serialized_vec.append(&mut signal.to_vec()); let serialized_message = Uint8Array::from(&serialized_vec[..]); let serialized_rln_witness = @@ -213,8 +213,14 @@ mod tests { ) .unwrap(); + // Add signal_len | signal + let mut proof_bytes = proof.to_vec(); + proof_bytes.append(&mut signal_len.to_le_bytes().to_vec()); + proof_bytes.append(&mut signal.to_vec()); + let proof_with_signal = Uint8Array::from(&proof_bytes[..]); + // Validate Proof - let is_proof_valid = wasm_verify(rln_instance, proof); + let is_proof_valid = wasm_verify_rln_proof(rln_instance, proof_with_signal); assert!( is_proof_valid,