-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #240 from zkemail/feat/qp-precompute-selector
feat: Add SHA precompute for QP-encoded selectors
- Loading branch information
Showing
3 changed files
with
165 additions
and
12 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
packages/circuits/tests/email-verifier-with-qp-encoded-sha-precompute-selector.test.ts
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,49 @@ | ||
import fs from "fs"; | ||
import { wasm as wasm_tester } from "circom_tester"; | ||
import path from "path"; | ||
import { DKIMVerificationResult } from "@zk-email/helpers/src/dkim"; | ||
import { generateEmailVerifierInputsFromDKIMResult } from "@zk-email/helpers/src/input-generators"; | ||
import { verifyDKIMSignature } from "@zk-email/helpers/src/dkim"; | ||
|
||
describe("EmailVerifier : With soft line breaks", () => { | ||
jest.setTimeout(30 * 60 * 1000); // 30 minutes | ||
|
||
let dkimResult: DKIMVerificationResult; | ||
let circuit: any; | ||
|
||
beforeAll(async () => { | ||
const rawEmail = fs.readFileSync( | ||
path.join(__dirname, "./test-emails/lorem_ipsum.eml"), | ||
"utf8" | ||
); | ||
dkimResult = await verifyDKIMSignature(rawEmail); | ||
|
||
circuit = await wasm_tester( | ||
path.join( | ||
__dirname, | ||
"./test-circuits/email-verifier-with-soft-line-breaks-test.circom" | ||
), | ||
{ | ||
recompile: true, | ||
include: path.join(__dirname, "../../../node_modules"), | ||
output: path.join(__dirname, "./compiled-test-circuits"), | ||
} | ||
); | ||
}); | ||
|
||
it("should verify email with soft line break in sha precompute selector", async function () { | ||
const emailVerifierInputs = generateEmailVerifierInputsFromDKIMResult( | ||
dkimResult, | ||
{ | ||
maxHeadersLength: 640, | ||
maxBodyLength: 1408, | ||
ignoreBodyHashCheck: false, | ||
removeSoftLineBreaks: true, | ||
shaPrecomputeSelector: "imperdiet neque.", | ||
} | ||
); | ||
|
||
const witness = await circuit.calculateWitness(emailVerifierInputs); | ||
await circuit.checkConstraints(witness); | ||
}); | ||
}); |
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