From d4746d4883275b87f22c042c482f52054a89edd9 Mon Sep 17 00:00:00 2001 From: andrea Date: Wed, 22 Jan 2025 19:41:25 -0800 Subject: [PATCH] WASM: add bindings for `Proof` --- Cargo.lock | 1 + ironfish-rust-wasm/Cargo.toml | 1 + ironfish-rust-wasm/src/primitives.rs | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 4f1a872265..69df6f7ed1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1649,6 +1649,7 @@ dependencies = [ "group 0.12.1", "hex-literal", "ironfish", + "ironfish-bellperson", "ironfish-jubjub", "ironfish_zkp", "rand", diff --git a/ironfish-rust-wasm/Cargo.toml b/ironfish-rust-wasm/Cargo.toml index 470159046b..b3beac8387 100644 --- a/ironfish-rust-wasm/Cargo.toml +++ b/ironfish-rust-wasm/Cargo.toml @@ -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" diff --git a/ironfish-rust-wasm/src/primitives.rs b/ironfish-rust-wasm/src/primitives.rs index adea5f3995..2d8360821d 100644 --- a/ironfish-rust-wasm/src/primitives.rs +++ b/ironfish-rust-wasm/src/primitives.rs @@ -196,3 +196,24 @@ impl Signature { buf } } + +wasm_bindgen_wrapper! { + #[derive(Clone, PartialEq, Debug)] + pub struct Proof(ironfish_bellperson::groth16::Proof); +} + +#[wasm_bindgen] +impl Proof { + #[wasm_bindgen(constructor)] + pub fn deserialize(bytes: &[u8]) -> Result { + let s = ironfish_bellperson::groth16::Proof::read(bytes)?; + Ok(Self::from(s)) + } + + #[wasm_bindgen] + pub fn serialize(&self) -> Vec { + let mut buf = Vec::new(); + self.0.write(&mut buf).expect("serialization failed"); + buf + } +}