adding support to read from byte buffers

This commit is contained in:
Dmitriy Ryajov 2024-01-20 15:27:45 -06:00
parent 170b10fc9e
commit 2bb54b79e7
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4
2 changed files with 17 additions and 1 deletions

View File

@ -1,5 +1,5 @@
use ark_ec::pairing::Pairing;
use std::{fs::File, path::Path};
use std::{fs::File, path::Path, io::Cursor};
use super::{CircomCircuit, R1CS};
@ -34,6 +34,16 @@ impl<E: Pairing> CircomConfig<E> {
sanity_check: false,
})
}
pub fn new_from_bytes(wtns: &[u8], r1cs: &[u8]) -> Result<Self> {
let wtns = WitnessCalculator::from_bytes(wtns).unwrap();
let r1cs = R1CSFile::new(Cursor::new(r1cs))?.into();
Ok(Self {
wtns,
r1cs,
sanity_check: false,
})
}
}
impl<E: Pairing> CircomBuilder<E> {

View File

@ -57,6 +57,12 @@ impl WitnessCalculator {
Self::from_file(path)
}
pub fn from_bytes(bytes: &[u8]) -> Result<Self> {
let store = Store::default();
let module = Module::new(&store, bytes)?;
Self::from_module(module)
}
pub fn from_file(path: impl AsRef<std::path::Path>) -> Result<Self> {
let store = Store::default();
let module = Module::from_file(&store, path)?;