diff --git a/rln-wasm/Cargo.toml b/rln-wasm/Cargo.toml index 69cebcf..781a6b2 100644 --- a/rln-wasm/Cargo.toml +++ b/rln-wasm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rln-wasm" -version = "0.0.5" +version = "0.0.6" edition = "2021" license = "MIT or Apache2" diff --git a/rln-wasm/src/lib.rs b/rln-wasm/src/lib.rs index ee94648..c77d8d9 100644 --- a/rln-wasm/src/lib.rs +++ b/rln-wasm/src/lib.rs @@ -116,6 +116,21 @@ pub fn wasm_key_gen(ctx: *const RLNWrapper) -> Result { } } +#[allow(clippy::not_unsafe_ptr_arg_deref)] +#[wasm_bindgen(js_name = generateExtendedMembershipKey)] +pub fn wasm_extended_key_gen(ctx: *const RLNWrapper) -> Result { + let wrapper = unsafe { &*ctx }; + let mut output_data: Vec = Vec::new(); + if wrapper.instance.extended_key_gen(&mut output_data).is_ok() { + let result = Uint8Array::from(&output_data[..]); + std::mem::forget(output_data); + Ok(result) + } else { + std::mem::forget(output_data); + Err("could not generate membership keys".into()) + } +} + #[allow(clippy::not_unsafe_ptr_arg_deref)] #[wasm_bindgen(js_name = generateSeededMembershipKey)] pub fn wasm_seeded_key_gen(ctx: *const RLNWrapper, seed: Uint8Array) -> Result { @@ -135,6 +150,55 @@ pub fn wasm_seeded_key_gen(ctx: *const RLNWrapper, seed: Uint8Array) -> Result Result { + let wrapper = unsafe { &*ctx }; + let mut output_data: Vec = Vec::new(); + if wrapper + .instance + .seeded_extended_key_gen(&seed.to_vec()[..], &mut output_data) + .is_ok() + { + let result = Uint8Array::from(&output_data[..]); + std::mem::forget(output_data); + Ok(result) + } else { + std::mem::forget(output_data); + Err("could not generate membership key".into()) + } +} + +#[allow(clippy::not_unsafe_ptr_arg_deref)] +#[wasm_bindgen(js_name = recovedIDSecret)] +pub fn wasm_recover_id_secret( + ctx: *const RLNWrapper, + input_proof_data_1: Uint8Array, + input_proof_data_2: Uint8Array, +) -> Result { + let wrapper = unsafe { &*ctx }; + let mut output_data: Vec = Vec::new(); + if wrapper + .instance + .recover_id_secret( + &input_proof_data_1.to_vec()[..], + &input_proof_data_2.to_vec()[..], + &mut output_data, + ) + .is_ok() + { + let result = Uint8Array::from(&output_data[..]); + std::mem::forget(output_data); + Ok(result) + } else { + std::mem::forget(output_data); + Err("could not recover id secret".into()) + } +} + #[allow(clippy::not_unsafe_ptr_arg_deref)] #[wasm_bindgen(js_name = verifyRLNProof)] pub fn wasm_verify_rln_proof(ctx: *const RLNWrapper, proof: Uint8Array) -> Result {