diff --git a/src/circuit.rs b/src/circuit.rs index 6b4622b..afbbf08 100644 --- a/src/circuit.rs +++ b/src/circuit.rs @@ -1,5 +1,6 @@ use anyhow::{anyhow, Result}; use num_bigint::BigInt; +use regex::Regex; use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; use std::{cmp, collections::VecDeque}; @@ -176,7 +177,9 @@ fn find_selector_in_clean_content( position_map: &[usize], ) -> Result<(String, usize)> { let clean_string = String::from_utf8_lossy(clean_content); - if let Some(selector_index) = clean_string.find(selector) { + let re = Regex::new(selector).unwrap(); + if let Some(m) = re.find(&clean_string) { + let selector_index = m.start(); // Map this cleaned index back to original if selector_index < position_map.len() { let original_index = position_map[selector_index]; @@ -647,6 +650,7 @@ pub fn compute_signal_length(max_length: usize) -> usize { #[cfg(test)] mod tests { + use super::*; use std::path::PathBuf; diff --git a/src/wasm.rs b/src/wasm.rs index 4ee7f9d..64dee1e 100644 --- a/src/wasm.rs +++ b/src/wasm.rs @@ -480,13 +480,15 @@ pub async fn bytesToFields(bytes: JsValue) -> Promise { /// # Returns /// /// A `Promise` that resolves with the email nullifier as a hexadecimal string, or rejects with an error message. -pub async fn emailNullifier(signautre: Vec) -> Promise { +pub async fn emailNullifier(mut signautre: Vec) -> Promise { use js_sys::Promise; use crate::field_to_hex; console_error_panic_hook::set_once(); + // Reverse the bytes for little-endian format + signautre.reverse(); match email_nullifier(&signautre) { Ok(field) => Promise::resolve(&JsValue::from_str(&field_to_hex(&field))), Err(_) => Promise::reject(&JsValue::from_str("Failed to compute email nullifier")),