-
Notifications
You must be signed in to change notification settings - Fork 77
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 #216 from zkemail/feat/header-masking
Feat: Added Header Masking
- Loading branch information
Showing
21 changed files
with
573 additions
and
340 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,57 @@ | ||
import { wasm } from "circom_tester"; | ||
import path from "path"; | ||
|
||
|
||
describe("Base64 Lookup", () => { | ||
jest.setTimeout(10 * 60 * 1000); // 10 minutes | ||
|
||
let circuit: any; | ||
|
||
beforeAll(async () => { | ||
circuit = await wasm( | ||
path.join(__dirname, "./test-circuits/base64-test.circom"), | ||
{ | ||
recompile: true, | ||
include: path.join(__dirname, "../../../node_modules"), | ||
// output: path.join(__dirname, "./compiled-test-circuits"), | ||
} | ||
); | ||
}); | ||
|
||
it("should decode valid base64 chars", async function () { | ||
const inputs = [ | ||
[65, 0], // A | ||
[90, 25], // Z | ||
[97, 26], // a | ||
[122, 51], // z | ||
[48, 52], // 0 | ||
[57, 61], // 9 | ||
[43, 62], // + | ||
[47, 63], // / | ||
[61, 0], // = | ||
] | ||
|
||
for (const [input, output] of inputs) { | ||
const witness = await circuit.calculateWitness({ | ||
in: input | ||
}); | ||
await circuit.checkConstraints(witness); | ||
await circuit.assertOut(witness, { out: output }) | ||
} | ||
}); | ||
|
||
it("should fail with invalid chars", async function () { | ||
const inputs = [34, 64, 91, 44]; | ||
|
||
expect.assertions(inputs.length); | ||
for (const input of inputs) { | ||
try { | ||
const witness = await circuit.calculateWitness({ | ||
in: input | ||
}); | ||
await circuit.checkConstraints(witness); | ||
} catch (error) { | ||
expect((error as Error).message).toMatch("Assert Failed"); | ||
} | ||
} | ||
}); | ||
jest.setTimeout(30 * 60 * 1000); // 30 minutes | ||
|
||
let circuit: any; | ||
|
||
beforeAll(async () => { | ||
circuit = await wasm( | ||
path.join(__dirname, "./test-circuits/base64-test.circom"), | ||
{ | ||
recompile: true, | ||
include: path.join(__dirname, "../../../node_modules"), | ||
// output: path.join(__dirname, "./compiled-test-circuits"), | ||
} | ||
); | ||
}); | ||
|
||
it("should decode valid base64 chars", async function () { | ||
const inputs = [ | ||
[65, 0], // A | ||
[90, 25], // Z | ||
[97, 26], // a | ||
[122, 51], // z | ||
[48, 52], // 0 | ||
[57, 61], // 9 | ||
[43, 62], // + | ||
[47, 63], // / | ||
[61, 0], // = | ||
]; | ||
|
||
for (const [input, output] of inputs) { | ||
const witness = await circuit.calculateWitness({ | ||
in: input, | ||
}); | ||
await circuit.checkConstraints(witness); | ||
await circuit.assertOut(witness, { out: output }); | ||
} | ||
}); | ||
|
||
it("should fail with invalid chars", async function () { | ||
const inputs = [34, 64, 91, 44]; | ||
|
||
expect.assertions(inputs.length); | ||
for (const input of inputs) { | ||
try { | ||
const witness = await circuit.calculateWitness({ | ||
in: input, | ||
}); | ||
await circuit.checkConstraints(witness); | ||
} catch (error) { | ||
expect((error as Error).message).toMatch("Assert Failed"); | ||
} | ||
} | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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 : Without body check", () => { | ||
jest.setTimeout(30 * 60 * 1000); // 30 minutes | ||
|
||
let dkimResult: DKIMVerificationResult; | ||
let circuit: any; | ||
|
||
beforeAll(async () => { | ||
const rawEmail = fs.readFileSync( | ||
path.join(__dirname, "./test-emails/test.eml"), | ||
"utf8" | ||
); | ||
dkimResult = await verifyDKIMSignature(rawEmail); | ||
|
||
circuit = await wasm_tester( | ||
path.join( | ||
__dirname, | ||
"./test-circuits/email-verifier-no-body-test.circom" | ||
), | ||
{ | ||
recompile: true, | ||
include: path.join(__dirname, "../../../node_modules"), | ||
// output: path.join(__dirname, "./compiled-test-circuits"), | ||
} | ||
); | ||
}); | ||
|
||
it("should verify email when ignore_body_hash_check is true", async function () { | ||
// The result wont have shaPrecomputeSelector, maxHeadersLength, maxBodyLength, ignoreBodyHashCheck | ||
const emailVerifierInputs = generateEmailVerifierInputsFromDKIMResult( | ||
dkimResult, | ||
{ | ||
maxHeadersLength: 640, | ||
maxBodyLength: 768, | ||
ignoreBodyHashCheck: true, | ||
} | ||
); | ||
|
||
const witness = await circuit.calculateWitness(emailVerifierInputs); | ||
await circuit.checkConstraints(witness); | ||
}); | ||
}); |
Oops, something went wrong.