Skip to content

Commit 3f8c7ed

Browse files
committed
add proof functions to ffi
1 parent ee0c7b8 commit 3f8c7ed

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src.rs/src/verkle_ffi_api.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use ffi_interface::Context as InnerContext;
22
pub use ffi_interface::{CommitmentBytes, ScalarBytes, ZERO_POINT};
33
use ipa_multipoint::committer::Committer;
4-
use js_sys::Uint8Array;
4+
use js_sys::{Boolean, Uint8Array};
55
use wasm_bindgen::{prelude::wasm_bindgen, JsError, JsValue};
66

77
#[wasm_bindgen]
@@ -197,6 +197,31 @@ impl Context {
197197

198198
Ok(bytes_to_js_value(commitment).into())
199199
}
200+
201+
/// Create a proof from a serialized array of tuples
202+
#[wasm_bindgen(js_name = "createProof")]
203+
pub fn create_proof(
204+
&self,
205+
input: Uint8Array,
206+
) -> Result<Uint8Array, JsError>
207+
{
208+
let input_bytes = serde_wasm_bindgen::from_value(input.into()).unwrap();
209+
let proof = ffi_interface::create_proof(&self.inner, input_bytes).map_err(|err| JsError::new(&format!("could not create proof: {:?}", err)))?;
210+
return Ok(Uint8Array::from(&proof[..]));
211+
}
212+
213+
/// Verify a proof created by `createProof`
214+
#[wasm_bindgen(js_name = "verifyProof")]
215+
pub fn verify_proof(
216+
&self,
217+
input: Uint8Array,
218+
) -> Result<Boolean, Boolean>
219+
{
220+
let input_bytes = serde_wasm_bindgen::from_value(input.into()).unwrap();
221+
let result = ffi_interface::verify_proof(&self.inner, input_bytes).map(|_op |Boolean::from(true))
222+
.map_err(|_err| Boolean::from(false));
223+
return result
224+
}
200225
}
201226

202227
/// This is the default commitment to use when nothing has been committed to

src.ts/verkleFFIBindings/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { initVerkleWasm, zeroCommitment, verifyExecutionWitnessPreState } from '../wasm/rust_verkle_wasm.js'
22

3-
import { getTreeKey, getTreeKeyHash, updateCommitment } from './verkleFFI.js'
3+
import { getTreeKey, getTreeKeyHash, updateCommitment, createProof, verifyProof } from './verkleFFI.js'
44

55
export {
66
initVerkleWasm,
77
getTreeKey,
88
getTreeKeyHash,
99
updateCommitment,
1010
zeroCommitment,
11-
verifyExecutionWitnessPreState
11+
verifyExecutionWitnessPreState,
12+
createProof,
13+
verifyProof
1214
}

src.ts/verkleFFIBindings/verkleFFI.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,11 @@ export function updateCommitment(
113113
): Uint8Array {
114114
return verkleFFI.updateCommitment(commitment, commitmentIndex, oldScalarValue, newScalarValue)
115115
}
116+
117+
export function createProof(verkleFFI: VerkleFFI, bytes: Uint8Array): Uint8Array {
118+
return verkleFFI.createProof(bytes)
119+
}
120+
121+
export function verifyProof(verkleFFI: VerkleFFI, proof: Uint8Array): boolean {
122+
return verkleFFI.verifyProof(proof)
123+
}

0 commit comments

Comments
 (0)