-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ccdbfd
commit a4a45c8
Showing
14 changed files
with
5,537 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ const option = { | |
output: path.join(__dirname, "../build"), | ||
recompile: true, | ||
}; | ||
const shaPrecomputeSelector = '\\\[zkemail-begin\\\]'; | ||
|
||
|
||
jest.setTimeout(1440000); | ||
describe("Email Auth with Recipient", () => { | ||
|
@@ -36,18 +38,17 @@ describe("Email Auth with Recipient", () => { | |
|
||
const emailRaw = readFileSync(emailFilePath, "utf8"); | ||
const parsedEmail = await relayerUtils.parseEmail(emailRaw); | ||
console.log(parsedEmail); | ||
const accountCode = await relayerUtils.generateAccountCode(); | ||
|
||
const { | ||
subject_idx, | ||
...emailAuthInput | ||
} = | ||
await genEmailCircuitInput(emailFilePath, accountCode, { | ||
maxHeaderLength: 640, | ||
maxHeaderLength: 768, | ||
maxBodyLength: 768, | ||
ignoreBodyHashCheck: false, | ||
shaPrecomputeSelector: '(<(=\r\n)?d(=\r\n)?i(=\r\n)?v(=\r\n)? (=\r\n)?i(=\r\n)?d(=\r\n)?=3D(=\r\n)?"(=\r\n)?[^"]*(=\r\n)?z(=\r\n)?k(=\r\n)?e(=\r\n)?m(=\r\n)?a(=\r\n)?i(=\r\n)?l(=\r\n)?[^"]*(=\r\n)?"(=\r\n)?[^>]*(=\r\n)?>(=\r\n)?)(=\r\n)?([^<>/]+)(<(=\r\n)?/(=\r\n)?d(=\r\n)?i(=\r\n)?v(=\r\n)?>(=\r\n)?)', | ||
shaPrecomputeSelector | ||
}); | ||
const command = "Send 0.1 ETH to [email protected]"; | ||
const recipientInput = await genRecipientInput(command, parsedEmail.signature); | ||
|
@@ -67,7 +68,7 @@ describe("Email Auth with Recipient", () => { | |
} | ||
|
||
const expectedPubKeyHash = await relayerUtils.publicKeyHash( | ||
parsedEmail.public_key | ||
parsedEmail.publicKey | ||
); | ||
expect(BigInt(expectedPubKeyHash)).toEqual( | ||
witness[1 + domainFields.length] | ||
|
@@ -80,7 +81,7 @@ describe("Email Auth with Recipient", () => { | |
witness[1 + domainFields.length + 1] | ||
); | ||
|
||
const timestamp = BigInt(1729865810); | ||
const timestamp = BigInt(1734798639); | ||
expect(timestamp).toEqual(witness[1 + domainFields.length + 2]); | ||
|
||
const maskedCommand = "Send 0.1 ETH to "; | ||
|
@@ -130,18 +131,17 @@ describe("Email Auth with Recipient", () => { | |
|
||
const emailRaw = readFileSync(emailFilePath, "utf8"); | ||
const parsedEmail = await relayerUtils.parseEmail(emailRaw); | ||
console.log(parsedEmail); | ||
const accountCode = await relayerUtils.generateAccountCode(); | ||
|
||
const { | ||
subject_idx, | ||
...emailAuthInput | ||
} = | ||
await genEmailCircuitInput(emailFilePath, accountCode, { | ||
maxHeaderLength: 640, | ||
maxHeaderLength: 768, | ||
maxBodyLength: 768, | ||
ignoreBodyHashCheck: false, | ||
shaPrecomputeSelector: '(<(=\r\n)?d(=\r\n)?i(=\r\n)?v(=\r\n)? (=\r\n)?i(=\r\n)?d(=\r\n)?=3D(=\r\n)?"(=\r\n)?[^"]*(=\r\n)?z(=\r\n)?k(=\r\n)?e(=\r\n)?m(=\r\n)?a(=\r\n)?i(=\r\n)?l(=\r\n)?[^"]*(=\r\n)?"(=\r\n)?[^>]*(=\r\n)?>(=\r\n)?)(=\r\n)?([^<>/]+)(<(=\r\n)?/(=\r\n)?d(=\r\n)?i(=\r\n)?v(=\r\n)?>(=\r\n)?)', | ||
shaPrecomputeSelector | ||
}); | ||
const command = "Swap 1 ETH to DAI"; | ||
const recipientInput = await genRecipientInput(command, parsedEmail.signature); | ||
|
@@ -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] | ||
|
@@ -173,7 +173,7 @@ describe("Email Auth with Recipient", () => { | |
witness[1 + domainFields.length + 1] | ||
); | ||
|
||
const timestamp = BigInt(1729865832); | ||
const timestamp = BigInt(1734798636); | ||
expect(timestamp).toEqual(witness[1 + domainFields.length + 2]); | ||
|
||
const maskedCommand = "Swap 1 ETH to DAI"; | ||
|
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 |
---|---|---|
|
@@ -12,8 +12,7 @@ const option = { | |
recompile: true, | ||
}; | ||
|
||
const shaPrecomputeSelector = '\\\[zkemail-begin\\\][^<>/\\\[\\\]]+\\\[zkemail-end\\\]'; | ||
console.log("shaPrecomputeSelector: ", shaPrecomputeSelector); | ||
const shaPrecomputeSelector = '\\\[zkemail-begin\\\]'; | ||
jest.setTimeout(1440000); | ||
describe("Email Auth", () => { | ||
let circuit; | ||
|
@@ -36,6 +35,7 @@ describe("Email Auth", () => { | |
|
||
const emailRaw = readFileSync(emailFilePath, "utf8"); | ||
const parsedEmail = await relayerUtils.parseEmail(emailRaw); | ||
console.log(parsedEmail); | ||
const accountCode = await relayerUtils.generateAccountCode(); | ||
|
||
const circuitInputs = | ||
|
@@ -55,7 +55,7 @@ describe("Email Auth", () => { | |
} | ||
|
||
const expectedPubKeyHash = await relayerUtils.publicKeyHash( | ||
parsedEmail.public_key | ||
parsedEmail.publicKey | ||
); | ||
expect(BigInt(expectedPubKeyHash)).toEqual( | ||
witness[1 + domainFields.length] | ||
|
@@ -68,7 +68,7 @@ describe("Email Auth", () => { | |
witness[1 + domainFields.length + 1] | ||
); | ||
|
||
const timestamp = BigInt(1734798640); | ||
const timestamp = BigInt(1734798639); | ||
expect(timestamp).toEqual(witness[1 + domainFields.length + 2]); | ||
|
||
const maskedCommand = "Send 0.1 ETH to "; | ||
|
@@ -120,7 +120,7 @@ describe("Email Auth", () => { | |
} | ||
|
||
const expectedPubKeyHash = await relayerUtils.publicKeyHash( | ||
parsedEmail.public_key | ||
parsedEmail.publicKey | ||
); | ||
expect(BigInt(expectedPubKeyHash)).toEqual( | ||
witness[1 + domainFields.length] | ||
|
@@ -186,7 +186,7 @@ describe("Email Auth", () => { | |
} | ||
|
||
const expectedPubKeyHash = await relayerUtils.publicKeyHash( | ||
parsedEmail.public_key | ||
parsedEmail.publicKey | ||
); | ||
expect(BigInt(expectedPubKeyHash)).toEqual( | ||
witness[1 + domainFields.length] | ||
|
@@ -252,7 +252,7 @@ describe("Email Auth", () => { | |
} | ||
|
||
const expectedPubKeyHash = await relayerUtils.publicKeyHash( | ||
parsedEmail.public_key | ||
parsedEmail.publicKey | ||
); | ||
expect(BigInt(expectedPubKeyHash)).toEqual( | ||
witness[1 + domainFields.length] | ||
|
@@ -319,7 +319,7 @@ describe("Email Auth", () => { | |
} | ||
|
||
const expectedPubKeyHash = await relayerUtils.publicKeyHash( | ||
parsedEmail.public_key | ||
parsedEmail.publicKey | ||
); | ||
expect(BigInt(expectedPubKeyHash)).toEqual( | ||
witness[1 + domainFields.length] | ||
|
@@ -386,7 +386,7 @@ describe("Email Auth", () => { | |
} | ||
|
||
const expectedPubKeyHash = await relayerUtils.publicKeyHash( | ||
parsedEmail.public_key | ||
parsedEmail.publicKey | ||
); | ||
expect(BigInt(expectedPubKeyHash)).toEqual( | ||
witness[1 + domainFields.length] | ||
|
@@ -441,7 +441,6 @@ describe("Email Auth", () => { | |
ignoreBodyHashCheck: false, | ||
shaPrecomputeSelector, | ||
}); | ||
console.log(circuitInputs.padded_header.length); | ||
const witness = await circuit.calculateWitness(circuitInputs); | ||
await circuit.checkConstraints(witness); | ||
|
||
|
@@ -453,7 +452,7 @@ describe("Email Auth", () => { | |
} | ||
|
||
const expectedPubKeyHash = await relayerUtils.publicKeyHash( | ||
parsedEmail.public_key | ||
parsedEmail.publicKey | ||
); | ||
expect(BigInt(expectedPubKeyHash)).toEqual( | ||
witness[1 + domainFields.length] | ||
|
@@ -492,6 +491,139 @@ describe("Email Auth", () => { | |
); | ||
}); | ||
|
||
it("Verify a sent email whose subject has Ynt:", async () => { | ||
const emailFilePath = path.join( | ||
__dirname, | ||
"./emails/email_auth_test8.eml" | ||
); | ||
const emailRaw = readFileSync(emailFilePath, "utf8"); | ||
const parsedEmail = await relayerUtils.parseEmail(emailRaw); | ||
const accountCode = | ||
"0x01eb9b204cc24c3baee11accc37d253a9c53e92b1a2cc07763475c135d575b76"; | ||
|
||
const circuitInputs = | ||
await genEmailCircuitInput(emailFilePath, accountCode, { | ||
maxHeaderLength: 768, maxBodyLength: 768, | ||
ignoreBodyHashCheck: false, | ||
shaPrecomputeSelector, | ||
}); | ||
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(1734798629); | ||
expect(timestamp).toEqual(witness[1 + domainFields.length + 2]); | ||
|
||
const maskedCommand = | ||
"Accept guardian request for 0x04884491560f38342C56E26BDD0fEAbb68E2d2FC"; | ||
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 sent email whose body has html tags", async () => { | ||
const emailFilePath = path.join( | ||
__dirname, | ||
"./emails/email_auth_test9.eml" | ||
); | ||
const emailRaw = readFileSync(emailFilePath, "utf8"); | ||
const parsedEmail = await relayerUtils.parseEmail(emailRaw); | ||
const accountCode = | ||
"0x01eb9b204cc24c3baee11accc37d253a9c53e92b1a2cc07763475c135d575b76"; | ||
|
||
const circuitInputs = | ||
await genEmailCircuitInput(emailFilePath, accountCode, { | ||
maxHeaderLength: 768, maxBodyLength: 768, | ||
ignoreBodyHashCheck: false, | ||
shaPrecomputeSelector, | ||
}); | ||
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(1734798617); | ||
expect(timestamp).toEqual(witness[1 + domainFields.length + 2]); | ||
|
||
const maskedCommand = | ||
"Accept guardian request for 0x04884491560f38342C56E26BDD0fEAbb68E2d2FC"; | ||
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 sent email with a too large from_addr_idx", async () => { | ||
const emailFilePath = path.join( | ||
__dirname, | ||
|
@@ -590,7 +722,7 @@ describe("Email Auth", () => { | |
it("Verify a sent email without the forced subject", async () => { | ||
const emailFilePath = path.join( | ||
__dirname, | ||
"./emails/email_auth_invalid_test1.eml" | ||
"./emails/email_auth_test10_invalid.eml" | ||
); | ||
|
||
const accountCode = | ||
|
@@ -612,7 +744,7 @@ describe("Email Auth", () => { | |
it("Verify a sent email with a non-utf8 character", async () => { | ||
const emailFilePath = path.join( | ||
__dirname, | ||
"./emails/email_auth_invalid_test2.eml" | ||
"./emails/email_auth_test11_invalid.eml" | ||
); | ||
|
||
const accountCode = | ||
|
Oops, something went wrong.