Skip to content

Commit 820e9d3

Browse files
committed
WASM: add bindings for Scalar.zero() and Fr.from_bytes()
1 parent 1484baa commit 820e9d3

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

ironfish-rust-wasm/src/primitives.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ wasm_bindgen_wrapper! {
1717

1818
#[wasm_bindgen]
1919
impl Scalar {
20+
#[wasm_bindgen]
21+
pub fn zero() -> Self {
22+
Self(blstrs::Scalar::zero())
23+
}
24+
2025
#[wasm_bindgen]
2126
pub fn random() -> Self {
2227
Self(blstrs::Scalar::random(thread_rng()))
@@ -45,6 +50,13 @@ impl Fr {
4550
Self(ironfish_jubjub::Fr::random(thread_rng()))
4651
}
4752

53+
#[wasm_bindgen(js_name = fromBytes)]
54+
pub fn from_bytes(&self, bytes: &[u8]) -> Option<Self> {
55+
let bytes: &[u8; 32] = bytes.try_into().ok()?;
56+
let fr = Option::from(ironfish_jubjub::Fr::from_bytes(bytes))?;
57+
Some(Self(fr))
58+
}
59+
4860
#[wasm_bindgen(js_name = toBytes)]
4961
pub fn to_bytes(&self) -> Vec<u8> {
5062
self.0.to_bytes().to_vec()

0 commit comments

Comments
 (0)