mirror of https://github.com/vacp2p/zerokit.git
feat(rln-wasm): expose `set_leaves_from` and `init_tree_with_leaves`
This commit is contained in:
parent
005393d696
commit
92c431c98f
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "rln-wasm"
|
||||
version = "0.0.6"
|
||||
version = "0.0.7"
|
||||
edition = "2021"
|
||||
license = "MIT or Apache2"
|
||||
|
||||
|
|
|
@ -50,6 +50,40 @@ pub fn wasm_set_next_leaf(ctx: *mut RLNWrapper, input: Uint8Array) -> Result<(),
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::not_unsafe_ptr_arg_deref)]
|
||||
#[wasm_bindgen(js_name = setLeavesFrom)]
|
||||
pub fn wasm_set_leaves_from(
|
||||
ctx: *mut RLNWrapper,
|
||||
index: usize,
|
||||
input: Uint8Array,
|
||||
) -> Result<(), String> {
|
||||
let wrapper = unsafe { &mut *ctx };
|
||||
if wrapper
|
||||
.instance
|
||||
.set_leaves_from(index as usize, &input.to_vec()[..])
|
||||
.is_ok()
|
||||
{
|
||||
Ok(())
|
||||
} else {
|
||||
Err("could not set multiple leaves".into())
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::not_unsafe_ptr_arg_deref)]
|
||||
#[wasm_bindgen(js_name = initTreeWithLeaves)]
|
||||
pub fn wasm_init_tree_with_leaves(ctx: *mut RLNWrapper, input: Uint8Array) -> Result<(), String> {
|
||||
let wrapper = unsafe { &mut *ctx };
|
||||
if wrapper
|
||||
.instance
|
||||
.init_tree_with_leaves(&input.to_vec()[..])
|
||||
.is_ok()
|
||||
{
|
||||
Ok(())
|
||||
} else {
|
||||
Err("could not init merkle tree".into())
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::not_unsafe_ptr_arg_deref)]
|
||||
#[wasm_bindgen(js_name = RLNWitnessToJson)]
|
||||
pub fn rln_witness_to_json(ctx: *mut RLNWrapper, serialized_witness: Uint8Array) -> Object {
|
||||
|
|
Loading…
Reference in New Issue