Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Added Core ZkEmail Functionality #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

shreyas-londhe
Copy link
Member

Add DKIM Email Verification and Pattern Matching

Implements core functionality for verifying DKIM-signed emails and extracting patterns using zkVM-compatible regex matching.

Features

  • DKIM signature verification using RSA-SHA256
  • Email body hash validation
  • Pattern matching using pre-compiled DFAs for zkVM compatibility
  • Support for searching in both headers and body
  • Optional pattern match revelation

Implementation Details

  • Uses cfdkim for email canonicalization
  • Implements zkVM-friendly pattern matching using regex-automata
  • Supports both forward and reverse DFA matching
  • Handles UTF-8 encoded content

Testing

  • Verifies DKIM signatures on real email samples
  • Tests pattern matching for reset codes and usernames
  • Includes test email fixtures

Usage Example

let eml_content =
    fs::read("./test_emails/test.eml").context("Failed to read test email")?;
let verifier = EmailVerifier::from_eml(&eml_content).await?;

// Test for reset code
let pattern = r"t7bezzrn"; // The actual reset code from the email
let dfa = DfaRegex::new(pattern)?;
let fwd_bytes = dfa.forward().to_bytes_native_endian().0;
let rev_bytes = dfa.reverse().to_bytes_native_endian().0;

let result = verifier.verify_pattern(
    &fwd_bytes, &rev_bytes, false, // search in body
    true,  // reveal match
)?;

assert!(result.is_some(), "Reset code should be found");
assert_eq!(result.unwrap(), "t7bezzrn", "Should match exact reset code");

// Test for username
let pattern = r"@0xDMello"; // The username from the email
let dfa = DfaRegex::new(pattern)?;
let fwd_bytes = dfa.forward().to_bytes_native_endian().0;
let rev_bytes = dfa.reverse().to_bytes_native_endian().0;

let result = verifier.verify_pattern(
    &fwd_bytes, &rev_bytes, false, // search in body
    true,  // reveal match
)?;

assert!(result.is_some(), "Username should be found");
assert_eq!(result.unwrap(), "@0xDMello", "Should match exact username");

@shreyas-londhe shreyas-londhe changed the title Feat: Implemented Core ZkEmail Functionality Feat: Added Core ZkEmail Functionality Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant