mirror of
https://github.com/vacp2p/zerokit.git
synced 2025-01-23 21:10:06 +00:00
call_bool_method_with_error_msg (#144)
Co-authored-by: tyshkor <tyshko1@gmail.com>
This commit is contained in:
parent
2e868d6cbf
commit
672287b77b
@ -79,6 +79,15 @@ macro_rules! call_with_error_msg {
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! call_bool_method_with_error_msg {
|
||||
($instance:expr, $method:ident, $error_msg:expr $(, $arg:expr)*) => {
|
||||
{
|
||||
let new_instance: &RLNWrapper = $instance.process();
|
||||
new_instance.instance.$method($($arg.process()),*).map_err(|err| format!("Msg: {:#?}, Error: {:#?}", $error_msg, err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
trait ProcessArg {
|
||||
type ReturnType;
|
||||
fn process(self) -> Self::ReturnType;
|
||||
@ -294,15 +303,12 @@ pub fn wasm_recover_id_secret(
|
||||
#[allow(clippy::not_unsafe_ptr_arg_deref)]
|
||||
#[wasm_bindgen(js_name = verifyRLNProof)]
|
||||
pub fn wasm_verify_rln_proof(ctx: *const RLNWrapper, proof: Uint8Array) -> Result<bool, String> {
|
||||
let wrapper = unsafe { &*ctx };
|
||||
if match wrapper.instance.verify_rln_proof(&proof.to_vec()[..]) {
|
||||
Ok(verified) => verified,
|
||||
Err(_) => return Err("error while verifying rln proof".into()),
|
||||
} {
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
Ok(false)
|
||||
call_bool_method_with_error_msg!(
|
||||
ctx,
|
||||
verify_rln_proof,
|
||||
"error while verifying rln proof".to_string(),
|
||||
&proof.to_vec()[..]
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(clippy::not_unsafe_ptr_arg_deref)]
|
||||
@ -312,18 +318,13 @@ pub fn wasm_verify_with_roots(
|
||||
proof: Uint8Array,
|
||||
roots: Uint8Array,
|
||||
) -> Result<bool, String> {
|
||||
let wrapper = unsafe { &*ctx };
|
||||
if match wrapper
|
||||
.instance
|
||||
.verify_with_roots(&proof.to_vec()[..], &roots.to_vec()[..])
|
||||
{
|
||||
Ok(verified) => verified,
|
||||
Err(_) => return Err("error while verifying proof with roots".into()),
|
||||
} {
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
Ok(false)
|
||||
call_bool_method_with_error_msg!(
|
||||
ctx,
|
||||
verify_with_roots,
|
||||
"error while verifying proof with roots".to_string(),
|
||||
&proof.to_vec()[..],
|
||||
&roots.to_vec()[..]
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(clippy::not_unsafe_ptr_arg_deref)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user