-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add js interface and compressed r computation
- Loading branch information
Showing
8 changed files
with
145 additions
and
43 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "remove_soft_line_breaks" | ||
type = "bin" | ||
authors = ["Mach 34"] | ||
compiler_version = ">=0.35.0" | ||
|
||
[dependencies] | ||
zkemail = { path = "../../lib"} |
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,64 @@ | ||
use zkemail::{ | ||
KEY_LIMBS_2048, dkim::RSAPubkey, headers::body_hash::get_body_hash, | ||
standard_outputs, Sequence, remove_soft_line_breaks::remove_soft_line_breaks | ||
}; | ||
use std::hash::sha256_var; | ||
|
||
global MAX_EMAIL_HEADER_LENGTH: u32 = 512; | ||
global MAX_EMAIL_BODY_LENGTH: u32 = 1024; | ||
|
||
/** | ||
* Verify an arbitrary email signed by a 2048-bit RSA DKIM signature | ||
* @dev TOTAL CONSTRAINTS: ~222,783 | ||
* | ||
* @param header - The email header, 0-padded at end to the MAX_EMAIL_HEADER_LENGTH | ||
* @param body - The email body, 0-padded at end to the MAX_EMAIL_BODY_LENGTH | ||
* @param pubkey - The DKIM RSA Public Key modulus and reduction parameter | ||
* @param signature - The DKIM RSA Signature | ||
* @param body_hash_index - The index of the body hash in the partial hash array | ||
* @param dkim_header_sequence - The index and length of the DKIM header field | ||
* @return - | ||
* 0: Pedersen hash of DKIM public key (root of trust) | ||
* 1: Pedersen hash of DKIM signature (email nullifier) | ||
*/ | ||
fn main( | ||
header: BoundedVec<u8, MAX_EMAIL_HEADER_LENGTH>, | ||
body: BoundedVec<u8, MAX_EMAIL_BODY_LENGTH>, | ||
decoded_body: BoundedVec<u8, MAX_EMAIL_BODY_LENGTH>, | ||
pubkey: RSAPubkey<KEY_LIMBS_2048>, | ||
signature: [Field; KEY_LIMBS_2048], | ||
body_hash_index: u32, | ||
dkim_header_sequence: Sequence | ||
) -> pub [Field; 2] { | ||
// check the body and header lengths are within bounds | ||
assert(header.len() <= MAX_EMAIL_HEADER_LENGTH); | ||
assert(body.len() <= MAX_EMAIL_BODY_LENGTH); | ||
|
||
// // ~ 86,553 constraints | ||
// // verify the dkim signature over the header | ||
// pubkey.verify_dkim_signature(header, signature); | ||
|
||
// // ~ 6,289 constraints | ||
// // extract the body hash from the header | ||
// let signed_body_hash = get_body_hash(header, dkim_header_sequence, body_hash_index); | ||
|
||
// // ~ 113,962 constraints | ||
// // hash the asserted body | ||
// let computed_body_hash: [u8; 32] = sha256_var(body.storage(), body.len() as u64); | ||
|
||
// // compare the body hashes | ||
// assert( | ||
// signed_body_hash == computed_body_hash, "SHA256 hash computed over body does not match body hash found in DKIM-signed header" | ||
// ); | ||
|
||
// ensure the decoded body is the same as the original body | ||
assert( | ||
remove_soft_line_breaks(body.storage(), decoded_body.storage()), | ||
"Decoded body does not properly remove soft line breaks" | ||
); | ||
|
||
// // ~ 10,255 constraints | ||
// // hash the pubkey and signature for the standard outputs | ||
// standard_outputs(pubkey.modulus, signature) | ||
[0, 0] | ||
} |
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 was deleted.
Oops, something went wrong.