Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src.rs/src/verkle_ffi_api.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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<Uint8Array, JsError>
{
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<Boolean, Boolean>
{
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| Boolean::from(false));
return result
}
}

/// This is the default commitment to use when nothing has been committed to
Expand Down
6 changes: 4 additions & 2 deletions src.ts/verkleFFIBindings/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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,
getTreeKey,
getTreeKeyHash,
updateCommitment,
zeroCommitment,
verifyExecutionWitnessPreState
verifyExecutionWitnessPreState,
createProof,
verifyProof
}
8 changes: 8 additions & 0 deletions src.ts/verkleFFIBindings/verkleFFI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}