Creating a New Pattern
Before we dive into using the SDK, it's crucial to understand the concept of "patterns" in the context of ZK Email.
What is a Pattern?
A pattern is a template that defines:
What information you want to extract from an email
How to locate this information within the email structure
Which parts of this information should be made public and which should remain private
Think of a pattern as a set of instructions for the ZK Email system to follow when processing an email. It tells the system:
Where to look in the email (header, body, etc.)
What to look for (sender email, subject line, specific content, etc.)
What to reveal and what to keep hidden
Why Create a Pattern?
Creating a pattern is essential because:
Creating a New Pattern
Now that we understand what patterns are and why they're important, let's create one.
Visit the ZK Regex Registry: Go to https://sdk.prove.email/
Click on "Submit a new pattern" to create a new pattern.

Fill in the Pattern Details:
Pattern Title: A descriptive name (e.g., "Email Verification")
Description: Explain what your pattern verifies (e.g., "Verifies the sender and subject of an email")
Slug: A unique identifier in the format (e.g., "your-name/email-verification")
Tags: Categories related to the pattern (comma-delimited)
Email Query: Define how to find relevant emails (e.g., "from:[email protected]")
Circuit Name: Name for the generated circuit (e.g., "EmailVerifier")
Skip Body Hash Check: Set to
trueif the information you want can fully be retrieved from the headersSHA Precompute Selector: A unique string that is before the extracted data in the email body
Use new ZK Regex SDK for circuit generation: Set to true to use the new SDK
Define Fields to Extract: For each piece of information you want to extract, add a field:
Field Name: Name of the data you're extracting (e.g., "SenderEmail", "Subject")
Data Location: Choose whether the data is in the email header or body
Parts: Define the regex pattern to match the data. For example:
Submit Your Pattern: Click "Submit" to register your pattern.
Wait for Processing: The system will process your pattern and generate the necessary circuits. This may take a few minutes.
Once your pattern is registered and processed, you can use it in your application with the ZK Email SDK.
Pattern Parameters
You can define multiple fields to extract different pieces of information from the email. Each field has the following properties:
Field Name
A unique identifier for this field within your pattern. Use CamelCase and make it descriptive of the data it extracts.
Property
Description
Type
field_name
Pattern name
String
Data Location
Specifies where in the email to look for this information:
"header": For information in the email headers (From, To, Subject, etc.)
"body": For information in the main content of the email
Parts
An array of objects that define the regex pattern for extracting information. Each part has two properties:
Property
Description
Type
is_public
Indicates if the matched part is public or private
Boolean
regex_def
Regular expression defining what to match
Regular Expression
Advanced Regex Tips
Use
.*to match any character (except newline) any number of timesUse
\s*to match any whitespace charactersUse
?after a character or group to make it optionalUse parentheses
()to create capture groups for more complex matchesUse
\bfor word boundaries to ensure you're matching whole words
Best Practices
Privacy First: Always consider what information needs to be public and what should remain private. Reveal only what's absolutely necessary.
Be Specific: The more specific your regex, the more efficient and secure your pattern will be. Avoid overly broad patterns that might accidentally reveal too much.
Test Thoroughly: Before submitting, test your regex patterns with sample emails to ensure they work as expected. Use online regex testers for quick iterations.
Document Well: Use clear names and descriptions to make your pattern understandable to others (and your future self).
Version Control: If you're updating an existing pattern, consider creating a new version rather than modifying the original. This helps maintain backwards compatibility.
Use Cases Examples
Last updated