Skip to content

Commit

Permalink
fix(noir_wasm): Update wasm ACIR serialization (#898)
Browse files Browse the repository at this point in the history
* switch wasm acir serialization methods to use write and read instead of to_bytes and from_bytes

* add deprecated flag to acir_from_bytes and acir_to_bytes
  • Loading branch information
vezenovm authored Feb 22, 2023
1 parent 8cafa34 commit 575436f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions crates/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,45 @@ pub fn compile(src: String) -> JsValue {
let compiled_program = noirc_driver::Driver::compile_file(path, language);
<JsValue as JsValueSerdeExt>::from_serde(&compiled_program).unwrap()
}

// Deserializes bytes into ACIR structure
#[deprecated(
note = "we have moved away from this serialization strategy. Call `acir_read_bytes` instead"
)]
#[wasm_bindgen]
pub fn acir_from_bytes(bytes: Vec<u8>) -> JsValue {
console_error_panic_hook::set_once();
let circuit = Circuit::from_bytes(&bytes);
<JsValue as JsValueSerdeExt>::from_serde(&circuit).unwrap()
}

#[deprecated(
note = "we have moved away from this serialization strategy. Call `acir_write_bytes` instead"
)]
#[wasm_bindgen]
pub fn acir_to_bytes(acir: JsValue) -> Vec<u8> {
console_error_panic_hook::set_once();
let circuit: Circuit = JsValueSerdeExt::into_serde(&acir).unwrap();
circuit.to_bytes()
}

// Deserializes bytes into ACIR structure
#[wasm_bindgen]
pub fn acir_read_bytes(bytes: Vec<u8>) -> JsValue {
console_error_panic_hook::set_once();
let circuit = Circuit::read(&*bytes).unwrap();
<JsValue as JsValueSerdeExt>::from_serde(&circuit).unwrap()
}

#[wasm_bindgen]
pub fn acir_write_bytes(acir: JsValue) -> Vec<u8> {
console_error_panic_hook::set_once();
let circuit: Circuit = JsValueSerdeExt::into_serde(&acir).unwrap();
let mut bytes = Vec::new();
circuit.write(&mut bytes).unwrap();
bytes
}

#[wasm_bindgen]
pub fn build_info() -> JsValue {
console_error_panic_hook::set_once();
Expand Down

0 comments on commit 575436f

Please sign in to comment.