Skip to content

Commit

Permalink
WASM: add bindings for Scalar.zero() and Fr.from_bytes()
Browse files Browse the repository at this point in the history
  • Loading branch information
andiflabs committed Feb 13, 2025
1 parent 1484baa commit 820e9d3
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ironfish-rust-wasm/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ wasm_bindgen_wrapper! {

#[wasm_bindgen]
impl Scalar {
#[wasm_bindgen]
pub fn zero() -> Self {
Self(blstrs::Scalar::zero())
}

#[wasm_bindgen]
pub fn random() -> Self {
Self(blstrs::Scalar::random(thread_rng()))
Expand Down Expand Up @@ -45,6 +50,13 @@ impl Fr {
Self(ironfish_jubjub::Fr::random(thread_rng()))
}

#[wasm_bindgen(js_name = fromBytes)]
pub fn from_bytes(&self, bytes: &[u8]) -> Option<Self> {
let bytes: &[u8; 32] = bytes.try_into().ok()?;
let fr = Option::from(ironfish_jubjub::Fr::from_bytes(bytes))?;
Some(Self(fr))
}

#[wasm_bindgen(js_name = toBytes)]
pub fn to_bytes(&self) -> Vec<u8> {
self.0.to_bytes().to_vec()
Expand Down

0 comments on commit 820e9d3

Please sign in to comment.