Skip to content

Commit

Permalink
Fix \t issue in the email sent from apple mail.
Browse files Browse the repository at this point in the history
  • Loading branch information
SoraSuegami committed Dec 27, 2024
1 parent ff23fea commit 7727876
Show file tree
Hide file tree
Showing 12 changed files with 607 additions and 406 deletions.
575 changes: 207 additions & 368 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 1 addition & 6 deletions packages/circuits/helpers/email_auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ export async function genEmailCircuitInput(
const jsonStr = await relayerUtils.generateEmailCircuitInput(
emailRaw,
accountCode,
{
ignore_body_hash_check: options?.ignoreBodyHashCheck,
max_header_length: options?.maxHeaderLength,
max_body_length: options?.maxBodyLength,
sha_precompute_selector: options?.shaPrecomputeSelector,
}
options
);
return JSON.parse(jsonStr);
}
4 changes: 2 additions & 2 deletions packages/circuits/helpers/recipient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export async function genRecipientInputLegacy(emailFilePath: string): Promise<{
const emailRaw = await promisify(fs.readFile)(emailFilePath, "utf8");
const parsedEmail = await relayerUtils.parseEmail(emailRaw);
const subjectEmailIdxes = relayerUtils.extractSubjectAllIdxes(
parsedEmail.canonicalized_header
parsedEmail.canonicalizedHeader
)[0];
const subject = parsedEmail.canonicalized_header.slice(
const subject = parsedEmail.canonicalizedHeader.slice(
subjectEmailIdxes[0],
subjectEmailIdxes[1]
);
Expand Down
2 changes: 1 addition & 1 deletion packages/circuits/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"@zk-email/circuits": "=6.3.2",
"@zk-email/relayer-utils": "=0.4.59",
"@zk-email/relayer-utils": "=0.4.60",
"@zk-email/zk-regex-circom": "=2.3.1",
"commander": "^12.1.0",
"snarkjs": "=0.7.5"
Expand Down
14 changes: 7 additions & 7 deletions packages/circuits/tests/email_auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe("Email Auth", () => {
}

const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.public_key
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
Expand Down Expand Up @@ -122,7 +122,7 @@ describe("Email Auth", () => {
}

const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.public_key
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
Expand Down Expand Up @@ -189,7 +189,7 @@ describe("Email Auth", () => {
}

const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.public_key
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
Expand Down Expand Up @@ -256,7 +256,7 @@ describe("Email Auth", () => {
}

const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.public_key
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
Expand Down Expand Up @@ -324,7 +324,7 @@ describe("Email Auth", () => {
}

const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.public_key
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
Expand Down Expand Up @@ -392,7 +392,7 @@ describe("Email Auth", () => {
}

const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.public_key
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
Expand Down Expand Up @@ -460,7 +460,7 @@ describe("Email Auth", () => {
}

const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.public_key
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
Expand Down
12 changes: 6 additions & 6 deletions packages/circuits/tests/email_auth_legacy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("Email Auth Legacy", () => {
expect(BigInt(domainFields[idx])).toEqual(witness[1 + idx]);
}
const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.public_key
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
Expand Down Expand Up @@ -117,7 +117,7 @@ describe("Email Auth Legacy", () => {
expect(BigInt(domainFields[idx])).toEqual(witness[1 + idx]);
}
const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.public_key
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
Expand Down Expand Up @@ -181,7 +181,7 @@ describe("Email Auth Legacy", () => {
expect(BigInt(domainFields[idx])).toEqual(witness[1 + idx]);
}
const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.public_key
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
Expand Down Expand Up @@ -245,7 +245,7 @@ describe("Email Auth Legacy", () => {
expect(BigInt(domainFields[idx])).toEqual(witness[1 + idx]);
}
const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.public_key
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
Expand Down Expand Up @@ -310,7 +310,7 @@ describe("Email Auth Legacy", () => {
expect(BigInt(domainFields[idx])).toEqual(witness[1 + idx]);
}
const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.public_key
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
Expand Down Expand Up @@ -374,7 +374,7 @@ describe("Email Auth Legacy", () => {
expect(BigInt(domainFields[idx])).toEqual(witness[1 + idx]);
}
const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.public_key
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe("Email Auth Legacy with Recipient", () => {
expect(BigInt(domainFields[idx])).toEqual(witness[1 + idx]);
}
const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.public_key
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
Expand Down Expand Up @@ -139,7 +139,7 @@ describe("Email Auth Legacy with Recipient", () => {
expect(BigInt(domainFields[idx])).toEqual(witness[1 + idx]);
}
const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.public_key
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
Expand Down Expand Up @@ -222,7 +222,7 @@ describe("Email Auth Legacy with Recipient", () => {
expect(BigInt(domainFields[idx])).toEqual(witness[1 + idx]);
}
const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.public_key
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
Expand Down Expand Up @@ -303,7 +303,7 @@ describe("Email Auth Legacy with Recipient", () => {
expect(BigInt(domainFields[idx])).toEqual(witness[1 + idx]);
}
const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.public_key
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
Expand Down
79 changes: 75 additions & 4 deletions packages/circuits/tests/email_auth_production.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const option = {
output: path.join(__dirname, "../build"),
recompile: true,
};
const shaPrecomputeSelector = '<div id=3D\"[^"]*zkemail[^"]*\"[^>]*>[^<>/]+</div>';

jest.setTimeout(1440000);
describe("Email Auth Production", () => {
Expand Down Expand Up @@ -57,7 +58,7 @@ describe("Email Auth Production", () => {
}

const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.public_key
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
Expand Down Expand Up @@ -127,7 +128,7 @@ describe("Email Auth Production", () => {
}

const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.public_key
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
Expand Down Expand Up @@ -196,7 +197,7 @@ describe("Email Auth Production", () => {
}

const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.public_key
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
Expand Down Expand Up @@ -265,7 +266,7 @@ describe("Email Auth Production", () => {
}

const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.public_key
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
Expand Down Expand Up @@ -304,6 +305,76 @@ describe("Email Auth Production", () => {
);
});

it("Verify a production email for recovery sent from apple email mobile", async () => {
const emailFilePath = path.join(
__dirname,
"./emails/recovery_gmail_from_apple_mail.eml"
);

const emailRaw = readFileSync(emailFilePath, "utf8");
const parsedEmail = await relayerUtils.parseEmail(emailRaw);
const accountCode =
"0x1162ebff40918afe5305e68396f0283eb675901d0387f97d21928d423aaa0b20";

const circuitInputs =
await genEmailCircuitInput(emailFilePath, accountCode, {
maxHeaderLength: 1024,
maxBodyLength: 1024,
ignoreBodyHashCheck: false,
shaPrecomputeSelector
});
console.log(circuitInputs);

const witness = await circuit.calculateWitness(circuitInputs);
await circuit.checkConstraints(witness);

const domainName = "gmail.com";
const paddedDomain = relayerUtils.padString(domainName, 255);
const domainFields = await relayerUtils.bytesToFields(paddedDomain);
for (let idx = 0; idx < domainFields.length; ++idx) {
expect(BigInt(domainFields[idx])).toEqual(witness[1 + idx]);
}

const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
);

const expectedEmailNullifier = await relayerUtils.emailNullifier(
parsedEmail.signature
);
expect(BigInt(expectedEmailNullifier)).toEqual(
witness[1 + domainFields.length + 1]
);

const timestamp = BigInt(1735305312);
expect(timestamp).toEqual(witness[1 + domainFields.length + 2]);

const maskedCommand = "Accept guardian request for 0x952541bDfe8aae3805D5b9A37D5Ae5e1EE68346f";
const paddedMaskedCommand = relayerUtils.padString(maskedCommand, 605);
const maskedCommandFields =
await relayerUtils.bytesToFields(paddedMaskedCommand);
for (let idx = 0; idx < maskedCommandFields.length; ++idx) {
expect(BigInt(maskedCommandFields[idx])).toEqual(
witness[1 + domainFields.length + 3 + idx]
);
}

const fromAddr = "[email protected]";
const accountSalt = await relayerUtils.generateAccountSalt(fromAddr, accountCode);
expect(BigInt(accountSalt)).toEqual(
witness[1 + domainFields.length + 3 + maskedCommandFields.length]
);

expect(BigInt(1)).toEqual(
witness[
1 + domainFields.length + 3 + maskedCommandFields.length + 1
]
);
});

// it("Verify a production email for recovery sent from outlook pc with the English setting", async () => {
// const emailFilePath = path.join(
// __dirname,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe("Email Auth with Recipient", () => {
}

const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.public_key
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
Expand Down Expand Up @@ -160,7 +160,7 @@ describe("Email Auth with Recipient", () => {
}

const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.public_key
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
Expand Down
Loading

0 comments on commit 7727876

Please sign in to comment.