Skip to content

Commit

Permalink
WASM: add bindings for Proof
Browse files Browse the repository at this point in the history
  • Loading branch information
andiflabs committed Jan 23, 2025
1 parent 9aea07d commit d4746d4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ironfish-rust-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ blstrs = "0.6.0"
getrandom = { version = "0.2.8", features = ["js"] } # need to explicitly enable the `js` feature in order to run in a browser
group = "0.12.0"
ironfish = { version = "0.3.0", path = "../ironfish-rust", default-features = false }
ironfish-bellperson = { version = "0.1.0", features = ["groth16"] }
ironfish-jubjub = "0.1.0"
ironfish_zkp = { version = "0.2.0", path = "../ironfish-zkp" }
rand = "0.8.5"
Expand Down
21 changes: 21 additions & 0 deletions ironfish-rust-wasm/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,24 @@ impl Signature {
buf
}
}

wasm_bindgen_wrapper! {
#[derive(Clone, PartialEq, Debug)]
pub struct Proof(ironfish_bellperson::groth16::Proof<blstrs::Bls12>);
}

#[wasm_bindgen]
impl Proof {
#[wasm_bindgen(constructor)]
pub fn deserialize(bytes: &[u8]) -> Result<Self, IronfishError> {
let s = ironfish_bellperson::groth16::Proof::read(bytes)?;
Ok(Self::from(s))
}

#[wasm_bindgen]
pub fn serialize(&self) -> Vec<u8> {
let mut buf = Vec::new();
self.0.write(&mut buf).expect("serialization failed");
buf
}
}

0 comments on commit d4746d4

Please sign in to comment.