# zk-email/circuits

The circuits package exports the circom circuits needed for building on ZK Email. All circuits in this package are libraries that can be imported to your circom project (i.e this package does not cont

### Installation

### EmailVerifier Circuit

`EmailVerifier`

is the primary circuit exported from `@zk-email/circuits`

which is used for proving the signature of the input email is valid.

#### Usage:

Import to your circuit file like below.

**Parameters**:`maxHeadersLength`

: Maximum length for the email header.`maxBodyLength`

: Maximum length for the email body.`n`

: Number of bits per chunk the RSA key is split into. Recommended to be 121.`k`

: Number of chunks the RSA key is split into. Recommended to be 17.`ignoreBodyHashCheck`

: Set 1 to skip body hash check in case data to prove/extract is only in the headers.

`Note`

: We use these values for n and k because their product (n * k) needs to be more than 2048 (RSA constraint) and n has to be less than half of 255 to fit in a circom signal.**Input Signals**:`emailHeader[maxHeadersLength]`

: Email headers that are signed (ones in`DKIM-Signature`

header) as ASCII int[], padded as per SHA-256 block size.`emailHeaderLength`

: Length of the email header including the SHA-256 padding.`pubkey[k]`

: RSA public key split into k chunks of n bits each.`signature[k]`

: RSA signature split into k chunks of n bits each.`emailBody[maxBodyLength]`

: Email body after the precomputed SHA as ASCII int[], padded as per SHA-256 block size.`emailBodyLength`

: Length of the email body including the SHA-256 padding.`bodyHashIndex`

: Index of the body hash`bh`

in the`emailHeader`

.`precomputedSHA[32]`

: Precomputed SHA-256 hash of the email body till the bodyHashIndex.

**Output Signal**`pubkeyHash`

: Poseidon hash of the pubkey - Poseidon(n/2)(n/2 chunks of pubkey with k*2 bits per chunk).

**Libraries**

**Libraries**

This section contains a template library located in the `@zk-email/circuits/lib`

directory. These templates are important for building your main circuit (EmailVerifier).

These templates are used in the `EmailVerifier`

circuit, and can also be used in a wide range of ZK projects, even those not directly related to ZK Email.

`lib/rsa.circom`

`lib/rsa.circom`

`lib/sha.circom`

`lib/sha.circom`

`lib/base64.circom`

`lib/base64.circom`

### Utils

This section provides an overview of utility circom templates available in the `@zk-email/circuits/utils`

directory. These templates assist in the construction of zk circuits for various applications beyond the core ZK Email functionalities.

`utils/array.circom`

`utils/array.circom`

`utils/bytes.circom`

`utils/bytes.circom`

`utils/constants.circom`

`utils/constants.circom`

`utils/functions.circom`

`utils/functions.circom`

`utils/hash.circom`

`utils/hash.circom`

`utils/regex.circom`

`utils/regex.circom`

### Helpers

This section contains helper circom templates in` @zk-email/circuits/helpers`

that you can use to build on top of ZK Email.

`helpers/email-nullifier.circom`

`helpers/email-nullifier.circom`

Last updated