-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add to_addr field in API (#48)
* feat: add to_addr * test: replace code test * fix tests change apis package.json change apis package.json
- Loading branch information
Showing
15 changed files
with
556 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
paths = ["./"] | ||
|
||
[target.x86_64-unknown-linux-gnu] | ||
rustflags = ["-Clink-arg=-Wl,--allow-multiple-definition"] |
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,20 @@ | ||
{ | ||
"parts": [ | ||
{ | ||
"is_public": false, | ||
"regex_def": "((\r\n)|^)to:" | ||
}, | ||
{ | ||
"is_public": false, | ||
"regex_def": "([^\r\n]+<)?" | ||
}, | ||
{ | ||
"is_public": true, | ||
"regex_def": "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|!|#|$|%|&|'|\\*|\\+|-|/|=|\\?|^|_|`|{|\\||}|~|\\.)+@(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|_|\\.|-)+" | ||
}, | ||
{ | ||
"is_public": false, | ||
"regex_def": ">?\r\n" | ||
} | ||
] | ||
} |
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,16 @@ | ||
{ | ||
"parts": [ | ||
{ | ||
"is_public": false, | ||
"regex_def": "((\r\n)|^)to:" | ||
}, | ||
{ | ||
"is_public": true, | ||
"regex_def": "[^\r\n]+" | ||
}, | ||
{ | ||
"is_public": false, | ||
"regex_def": "\r\n" | ||
} | ||
] | ||
} |
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 |
---|---|---|
@@ -1,9 +1,8 @@ | ||
use zk_regex_compiler::DecomposedRegexConfig; | ||
use fancy_regex::Regex; | ||
|
||
use neon::prelude::*; | ||
use serde_json; | ||
use thiserror::Error; | ||
use zk_regex_compiler::DecomposedRegexConfig; | ||
|
||
/// Error definitions of the compiler. | ||
#[derive(Error, Debug)] | ||
|
@@ -102,6 +101,17 @@ pub fn extract_from_addr_idxes( | |
extract_substr_idxes(input_str, ®ex_config) | ||
} | ||
|
||
pub fn extract_to_all_idxes(input_str: &str) -> Result<Vec<(usize, usize)>, ExtractSubstrssError> { | ||
let regex_config = serde_json::from_str(include_str!("./decomposed_defs/to_all.json")).unwrap(); | ||
extract_substr_idxes(input_str, ®ex_config) | ||
} | ||
|
||
pub fn extract_to_addr_idxes(input_str: &str) -> Result<Vec<(usize, usize)>, ExtractSubstrssError> { | ||
let regex_config = | ||
serde_json::from_str(include_str!("./decomposed_defs/to_addr.json")).unwrap(); | ||
extract_substr_idxes(input_str, ®ex_config) | ||
} | ||
|
||
pub fn extract_subject_all_idxes( | ||
input_str: &str, | ||
) -> Result<Vec<(usize, usize)>, ExtractSubstrssError> { | ||
|
@@ -247,6 +257,49 @@ pub fn extract_from_addr_idxes_node(mut cx: FunctionContext) -> JsResult<JsArray | |
Ok(js_array) | ||
} | ||
|
||
pub fn extract_to_all_idxes_node(mut cx: FunctionContext) -> JsResult<JsArray> { | ||
let input_str = cx.argument::<JsString>(0)?.value(&mut cx); | ||
|
||
let substr_idxes = match extract_to_all_idxes(&input_str) { | ||
Ok(substr_idxes) => substr_idxes, | ||
Err(e) => return cx.throw_error(e.to_string()), | ||
}; | ||
|
||
let js_array = JsArray::new(&mut cx, substr_idxes.len() as u32); | ||
|
||
for (i, (start_idx, end_idx)) in substr_idxes.iter().enumerate() { | ||
let start_end_array = JsArray::new(&mut cx, 2u32); | ||
|
||
let start_idx = cx.number(*start_idx as f64); | ||
start_end_array.set(&mut cx, 0, start_idx)?; | ||
|
||
let end_idx = cx.number(*end_idx as f64); | ||
start_end_array.set(&mut cx, 1, end_idx)?; | ||
|
||
js_array.set(&mut cx, i as u32, start_end_array)?; | ||
} | ||
|
||
Ok(js_array) | ||
} | ||
|
||
pub fn extract_to_addr_idxes_node(mut cx: FunctionContext) -> JsResult<JsArray> { | ||
let input_str = cx.argument::<JsString>(0)?.value(&mut cx); | ||
let substr_idxes = match extract_to_addr_idxes(&input_str) { | ||
Ok(substr_idxes) => substr_idxes, | ||
Err(e) => return cx.throw_error(e.to_string()), | ||
}; | ||
let js_array = JsArray::new(&mut cx, substr_idxes.len() as u32); | ||
for (i, (start_idx, end_idx)) in substr_idxes.iter().enumerate() { | ||
let start_end_array = JsArray::new(&mut cx, 2u32); | ||
let start_idx = cx.number(*start_idx as f64); | ||
start_end_array.set(&mut cx, 0, start_idx)?; | ||
let end_idx = cx.number(*end_idx as f64); | ||
start_end_array.set(&mut cx, 1, end_idx)?; | ||
js_array.set(&mut cx, i as u32, start_end_array)?; | ||
} | ||
Ok(js_array) | ||
} | ||
|
||
pub fn extract_subject_all_idxes_node(mut cx: FunctionContext) -> JsResult<JsArray> { | ||
let input_str = cx.argument::<JsString>(0)?.value(&mut cx); | ||
let substr_idxes = match extract_subject_all_idxes(&input_str) { | ||
|
@@ -369,13 +422,13 @@ mod test { | |
} | ||
|
||
#[test] | ||
fn test_code_in_subject_valid() { | ||
fn test_code_in_email_address_valid() { | ||
let code_regex = DecomposedRegexConfig { | ||
// max_byte_size: 1024, | ||
parts: vec![ | ||
RegexPartConfig { | ||
is_public: false, | ||
regex_def: "CODE:0x".to_string(), | ||
regex_def: "ACCOUNTKEY.0x".to_string(), | ||
// max_size: 7, | ||
// solidity: None | ||
}, | ||
|
@@ -387,9 +440,9 @@ mod test { | |
}, | ||
], | ||
}; | ||
let input_str = "subject:Email Wallet CODE:0x123abc"; | ||
let input_str = "[email protected]"; | ||
let idxes = extract_substr_idxes(input_str, &code_regex).unwrap(); | ||
assert_eq!(idxes, vec![(28, 34)]); | ||
assert_eq!(idxes, vec![(21, 27)]); | ||
} | ||
|
||
#[test] | ||
|
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,20 @@ | ||
{ | ||
"parts": [ | ||
{ | ||
"is_public": false, | ||
"regex_def": "((\r\n)|^)to:" | ||
}, | ||
{ | ||
"is_public": false, | ||
"regex_def": "([^\r\n]+<)?" | ||
}, | ||
{ | ||
"is_public": true, | ||
"regex_def": "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|!|#|$|%|&|'|\\*|\\+|-|/|=|\\?|^|_|`|{|\\||}|~|\\.)+@(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9|_|\\.|-)+" | ||
}, | ||
{ | ||
"is_public": false, | ||
"regex_def": ">?\r\n" | ||
} | ||
] | ||
} |
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,31 @@ | ||
pragma circom 2.1.5; | ||
|
||
include "@zk-email/zk-regex-circom/circuits/regex_helpers.circom"; | ||
include "@zk-email/zk-regex-circom/circuits/common/to_all_regex.circom"; | ||
include "@zk-email/zk-regex-circom/circuits/common/email_addr_regex.circom"; | ||
include "@zk-email/zk-regex-circom/circuits/common/email_addr_with_name_regex.circom"; | ||
|
||
|
||
template ToAddrRegex(msg_bytes) { | ||
signal input msg[msg_bytes]; | ||
signal output out; | ||
signal output reveal0[msg_bytes]; | ||
|
||
signal toOut; | ||
signal toReveal[msg_bytes]; | ||
(toOut, toReveal) <== ToAllRegex(msg_bytes)(msg); | ||
toOut === 1; | ||
|
||
signal emailNameOut; | ||
signal emailNameReveal[msg_bytes]; | ||
(emailNameOut, emailNameReveal) <== EmailAddrWithNameRegex(msg_bytes)(toReveal); | ||
|
||
signal emailAddrOut; | ||
signal emailAddrReveal[msg_bytes]; | ||
(emailAddrOut, emailAddrReveal) <== EmailAddrRegex(msg_bytes)(toReveal); | ||
|
||
out <== MultiOR(2)([emailNameOut, emailAddrOut]); | ||
for(var i=0; i<msg_bytes; i++) { | ||
reveal0[i] <== emailNameOut * (emailNameReveal[i] - emailAddrReveal[i]) + emailAddrReveal[i]; | ||
} | ||
} |
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,16 @@ | ||
{ | ||
"parts": [ | ||
{ | ||
"is_public": false, | ||
"regex_def": "((\r\n)|^)to:" | ||
}, | ||
{ | ||
"is_public": true, | ||
"regex_def": "[^\r\n]+" | ||
}, | ||
{ | ||
"is_public": false, | ||
"regex_def": "\r\n" | ||
} | ||
] | ||
} |
Oops, something went wrong.