Skip to content

Commit

Permalink
chore: document remaining functions (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Jun 20, 2023
1 parent 3a4974a commit 4f1fed8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ use wasm_bindgen::prelude::wasm_bindgen;

use crate::JsWitnessMap;

#[wasm_bindgen(js_name = compressWitness)]
/// Compresses a `WitnessMap` into the binary format outputted by Nargo.
///
/// @param {Uint8Array} compressed_witness - A witness map.
/// @returns {WitnessMap} A compressed witness map
#[wasm_bindgen(js_name = compressWitness, skip_jsdoc)]
pub fn compress_witness(witness_map: JsWitnessMap) -> Result<Vec<u8>, JsString> {
console_error_panic_hook::set_once();

Expand All @@ -15,7 +19,11 @@ pub fn compress_witness(witness_map: JsWitnessMap) -> Result<Vec<u8>, JsString>
Ok(compressed_witness_map)
}

#[wasm_bindgen(js_name = decompressWitness)]
/// Decompresses a compressed witness as outputted by Nargo into a `WitnessMap`.
///
/// @param {Uint8Array} compressed_witness - A compressed witness.
/// @returns {WitnessMap} The decompressed witness map.
#[wasm_bindgen(js_name = decompressWitness, skip_jsdoc)]
pub fn decompress_witness(compressed_witness: Vec<u8>) -> Result<JsWitnessMap, JsString> {
console_error_panic_hook::set_once();

Expand Down
5 changes: 4 additions & 1 deletion src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ extern "C" {
pub type LogLevel;
}

#[wasm_bindgen(js_name = initLogLevel)]
/// Sets the package's logging level.
///
/// @param {LogLevel} level - The maximum level of logging to be emitted.
#[wasm_bindgen(js_name = initLogLevel, skip_jsdoc)]
pub fn init_log_level(level: LogLevel) {
// Set the static variable from Rust
use std::sync::Once;
Expand Down
19 changes: 17 additions & 2 deletions src/public_witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,31 @@ fn extract_indices(witness_map: &WitnessMap, indices: Vec<Witness>) -> Result<Wi
Ok(extracted_witness_map)
}

/// Extracts a `WitnessMap` containing the witness indices corresponding to the circuit's return values.
///
/// @param {Uint8Array} circuit - A serialized representation of an ACIR circuit
/// @param {WitnessMap} witness_map - The completed witness map after executing the circuit.
/// @returns {WitnessMap} A witness map containing the circuit's return values.
#[wasm_bindgen(js_name = getReturnWitness)]
pub fn get_return_witness(
circuit: Vec<u8>,
solved_witness: JsWitnessMap,
witness_map: JsWitnessMap,
) -> Result<JsWitnessMap, JsString> {
console_error_panic_hook::set_once();
let circuit: Circuit = Circuit::read(&*circuit).expect("Failed to deserialize circuit");
let witness_map = WitnessMap::from(solved_witness);
let witness_map = WitnessMap::from(witness_map);

let return_witness =
extract_indices(&witness_map, circuit.return_values.0.into_iter().collect())?;

Ok(JsWitnessMap::from(return_witness))
}

/// Extracts a `WitnessMap` containing the witness indices corresponding to the circuit's public parameters.
///
/// @param {Uint8Array} circuit - A serialized representation of an ACIR circuit
/// @param {WitnessMap} witness_map - The completed witness map after executing the circuit.
/// @returns {WitnessMap} A witness map containing the circuit's public parameters.
#[wasm_bindgen(js_name = getPublicParametersWitness)]
pub fn get_public_parameters_witness(
circuit: Vec<u8>,
Expand All @@ -49,6 +59,11 @@ pub fn get_public_parameters_witness(
Ok(JsWitnessMap::from(public_params_witness))
}

/// Extracts a `WitnessMap` containing the witness indices corresponding to the circuit's public inputs.
///
/// @param {Uint8Array} circuit - A serialized representation of an ACIR circuit
/// @param {WitnessMap} witness_map - The completed witness map after executing the circuit.
/// @returns {WitnessMap} A witness map containing the circuit's public inputs.
#[wasm_bindgen(js_name = getPublicWitness)]
pub fn get_public_witness(
circuit: Vec<u8>,
Expand Down

0 comments on commit 4f1fed8

Please sign in to comment.