diff --git a/src.rs/src/verkle_ffi_api.rs b/src.rs/src/verkle_ffi_api.rs index 3140bab..b9df7f8 100644 --- a/src.rs/src/verkle_ffi_api.rs +++ b/src.rs/src/verkle_ffi_api.rs @@ -1,7 +1,7 @@ use ffi_interface::Context as InnerContext; pub use ffi_interface::{CommitmentBytes, ScalarBytes, ZERO_POINT}; use ipa_multipoint::committer::Committer; -use js_sys::Uint8Array; +use js_sys::{Boolean, Uint8Array}; use wasm_bindgen::{prelude::wasm_bindgen, JsError, JsValue}; #[wasm_bindgen] @@ -197,6 +197,31 @@ impl Context { Ok(bytes_to_js_value(commitment).into()) } + + /// Create a proof from a serialized array of tuples + #[wasm_bindgen(js_name = "createProof")] + pub fn create_proof( + &self, + input: Uint8Array, + ) -> Result + { + let input_bytes = serde_wasm_bindgen::from_value(input.into()).unwrap(); + let proof = ffi_interface::create_proof(&self.inner, input_bytes).map_err(|err| JsError::new(&format!("could not create proof: {:?}", err)))?; + return Ok(Uint8Array::from(&proof[..])); + } + + /// Verify a proof created by `createProof` + #[wasm_bindgen(js_name = "verifyProof")] + pub fn verify_proof( + &self, + input: Uint8Array, + ) -> Result + { + let input_bytes = serde_wasm_bindgen::from_value(input.into()).unwrap(); + let result = ffi_interface::verify_proof(&self.inner, input_bytes).map(|_op |Boolean::from(true)) + .map_err(|err| JsError::new(&format!("proof verification failed]: {:?}", err))); + return result + } } /// This is the default commitment to use when nothing has been committed to diff --git a/src.ts/index.ts b/src.ts/index.ts index 1cd329f..bb8ced7 100644 --- a/src.ts/index.ts +++ b/src.ts/index.ts @@ -5,6 +5,8 @@ import { updateCommitment as updateCommitmentBase, zeroCommitment as zeroCommitmentBase, verifyExecutionWitnessPreState as verifyExecutionWitnessPreStateBase, + createProof as createProofBase, + verifyProof as verifyProofBase, } from './verkleFFIBindings/index.js' import { Context as VerkleFFI } from './wasm/rust_verkle_wasm.js' @@ -34,6 +36,8 @@ export const loadVerkleCrypto = async () => { const hashCommitment = (commitment: Uint8Array) => verkleFFI.hashCommitment(commitment) const serializeCommitment = (commitment: Uint8Array) => verkleFFI.serializeCommitment(commitment) + const createProof = (input: Uint8Array) => verkleFFI.createProof(input) + const verifyProof = (proofInput: Uint8Array) => verkleFFI.verifyProof(proofInput) return { getTreeKey, getTreeKeyHash, @@ -41,7 +45,9 @@ export const loadVerkleCrypto = async () => { zeroCommitment, verifyExecutionWitnessPreState, hashCommitment, - serializeCommitment + serializeCommitment, + createProof, + verifyProof } } diff --git a/src.ts/verkleFFIBindings/index.ts b/src.ts/verkleFFIBindings/index.ts index 10fb70f..256f9e1 100644 --- a/src.ts/verkleFFIBindings/index.ts +++ b/src.ts/verkleFFIBindings/index.ts @@ -1,6 +1,6 @@ import { initVerkleWasm, zeroCommitment, verifyExecutionWitnessPreState } from '../wasm/rust_verkle_wasm.js' -import { getTreeKey, getTreeKeyHash, updateCommitment } from './verkleFFI.js' +import { getTreeKey, getTreeKeyHash, updateCommitment, createProof, verifyProof } from './verkleFFI.js' export { initVerkleWasm, @@ -8,5 +8,7 @@ export { getTreeKeyHash, updateCommitment, zeroCommitment, - verifyExecutionWitnessPreState + verifyExecutionWitnessPreState, + createProof, + verifyProof } diff --git a/src.ts/verkleFFIBindings/verkleFFI.ts b/src.ts/verkleFFIBindings/verkleFFI.ts index 04a4058..d855c62 100644 --- a/src.ts/verkleFFIBindings/verkleFFI.ts +++ b/src.ts/verkleFFIBindings/verkleFFI.ts @@ -113,3 +113,11 @@ export function updateCommitment( ): Uint8Array { return verkleFFI.updateCommitment(commitment, commitmentIndex, oldScalarValue, newScalarValue) } + +export function createProof(verkleFFI: VerkleFFI, bytes: Uint8Array): Uint8Array { + return verkleFFI.createProof(bytes) +} + +export function verifyProof(verkleFFI: VerkleFFI, proof: Uint8Array): boolean { + return verkleFFI.verifyProof(proof) +} \ No newline at end of file