-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into phated/lsp-wasm
* master: chore: refactor integration test (#2901) feat(acvm_js): export black box solver functions (#2812) chore: add standard linting setup to all crates (#2900) chore: use Noir number in release PR (#2905) chore: clippy fixes (#2897) chore: use workspace rust version in `backend-interface` crate (#2896)
- Loading branch information
Showing
35 changed files
with
706 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
use js_sys::JsString; | ||
use wasm_bindgen::prelude::*; | ||
|
||
use crate::js_witness_map::{field_element_to_js_string, js_value_to_field_element}; | ||
use acvm::FieldElement; | ||
|
||
/// Performs a bitwise AND operation between `lhs` and `rhs` | ||
#[wasm_bindgen] | ||
pub fn and(lhs: JsString, rhs: JsString) -> JsString { | ||
let lhs = js_value_to_field_element(lhs.into()).unwrap(); | ||
let rhs = js_value_to_field_element(rhs.into()).unwrap(); | ||
let result = lhs.and(&rhs, FieldElement::max_num_bits()); | ||
field_element_to_js_string(&result) | ||
} | ||
|
||
/// Performs a bitwise XOR operation between `lhs` and `rhs` | ||
#[wasm_bindgen] | ||
pub fn xor(lhs: JsString, rhs: JsString) -> JsString { | ||
let lhs = js_value_to_field_element(lhs.into()).unwrap(); | ||
let rhs = js_value_to_field_element(rhs.into()).unwrap(); | ||
let result = lhs.xor(&rhs, FieldElement::max_num_bits()); | ||
field_element_to_js_string(&result) | ||
} | ||
|
||
/// Calculates the SHA256 hash of the input bytes | ||
#[wasm_bindgen] | ||
pub fn sha256(inputs: &[u8]) -> Vec<u8> { | ||
acvm::blackbox_solver::sha256(inputs).unwrap().into() | ||
} | ||
|
||
/// Calculates the Blake2s256 hash of the input bytes | ||
#[wasm_bindgen] | ||
pub fn blake2s256(inputs: &[u8]) -> Vec<u8> { | ||
acvm::blackbox_solver::blake2s(inputs).unwrap().into() | ||
} | ||
|
||
/// Calculates the Keccak256 hash of the input bytes | ||
#[wasm_bindgen] | ||
pub fn keccak256(inputs: &[u8]) -> Vec<u8> { | ||
acvm::blackbox_solver::keccak256(inputs).unwrap().into() | ||
} | ||
|
||
/// Calculates the Blake2s256 hash of the input bytes and represents these as a single field element. | ||
// #[wasm_bindgen] | ||
// pub fn hash_to_field_128_security(inputs: Vec<JsString>) -> JsString { | ||
// let input_bytes: Vec<u8> = inputs | ||
// .into_iter() | ||
// .flat_map(|field_string| { | ||
// let field_element = js_value_to_field_element(field_string.into()).unwrap(); | ||
// witness_assignment.fetch_nearest_bytes(FieldElement::max_num_bits()); | ||
// }) | ||
// .collect(); | ||
// field_element_to_js_string( | ||
// &acvm::blackbox_solver::hash_to_field_128_security(&input_bytes).unwrap(), | ||
// ) | ||
// } | ||
|
||
/// Verifies a ECDSA signature over the secp256k1 curve. | ||
#[wasm_bindgen] | ||
pub fn ecdsa_secp256k1_verify( | ||
hashed_msg: &[u8], | ||
public_key_x_bytes: &[u8], | ||
public_key_y_bytes: &[u8], | ||
signature: &[u8], | ||
) -> bool { | ||
let public_key_x_bytes: &[u8; 32] = public_key_x_bytes.try_into().unwrap(); | ||
let public_key_y_bytes: &[u8; 32] = public_key_y_bytes.try_into().unwrap(); | ||
let signature: &[u8; 64] = signature.try_into().unwrap(); | ||
|
||
acvm::blackbox_solver::ecdsa_secp256k1_verify( | ||
hashed_msg, | ||
public_key_x_bytes, | ||
public_key_y_bytes, | ||
signature, | ||
) | ||
.unwrap() | ||
.into() | ||
} | ||
|
||
/// Verifies a ECDSA signature over the secp256r1 curve. | ||
#[wasm_bindgen] | ||
pub fn ecdsa_secp256r1_verify( | ||
hashed_msg: &[u8], | ||
public_key_x_bytes: &[u8], | ||
public_key_y_bytes: &[u8], | ||
signature: &[u8], | ||
) -> bool { | ||
let public_key_x_bytes: &[u8; 32] = public_key_x_bytes.try_into().unwrap(); | ||
let public_key_y_bytes: &[u8; 32] = public_key_y_bytes.try_into().unwrap(); | ||
let signature: &[u8; 64] = signature.try_into().unwrap(); | ||
|
||
acvm::blackbox_solver::ecdsa_secp256r1_verify( | ||
hashed_msg, | ||
public_key_x_bytes, | ||
public_key_y_bytes, | ||
signature, | ||
) | ||
.unwrap() | ||
.into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.