-
Notifications
You must be signed in to change notification settings - Fork 18
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
f736c19
commit 608b0d0
Showing
7 changed files
with
1,505 additions
and
1,526 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,19 +5,25 @@ const emailWalletUtils = require("@zk-email/relayer-utils"); | |
const option = { | ||
include: path.join(__dirname, "../../../node_modules"), | ||
}; | ||
import { genAccountCreationInput } from "../helpers/account_creation"; | ||
import { genEmailSenderInput } from "../helpers/email_sender"; | ||
import { readFileSync } from "fs"; | ||
import { hash_to_curve, point_scalar_mul } from "circom-grumpkin"; | ||
|
||
jest.setTimeout(2080000); | ||
describe("Account Initialization", () => { | ||
let circuit: any; | ||
beforeAll(async () => { | ||
circuit = await wasm_tester(path.join(__dirname, "../src/email_sender.circom"), option); | ||
|
||
}); | ||
|
||
it("init an account", async () => { | ||
const emailFilePath = path.join(__dirname, "./emails/account_creation_test1.eml"); | ||
const emailRaw = readFileSync(emailFilePath, "utf8"); | ||
const parsedEmail = await emailWalletUtils.parseEmail(emailRaw); | ||
const relayerRand = emailWalletUtils.genRelayerRand(); | ||
const circuitInputs = await genAccountCreationInput(emailFilePath, relayerRand); | ||
const circuit = await wasm_tester(path.join(__dirname, "../src/account_creation.circom"), option); | ||
const accountCode = "0x01eb9b204cc24c3baee11accc37d253a9c53e92b1a2cc07763475c135d575b76"; | ||
const circuitInputs = await genEmailSenderInput(emailFilePath, accountCode); | ||
const witness = await circuit.calculateWitness(circuitInputs); | ||
await circuit.checkConstraints(witness); | ||
const domainName = "gmail.com"; | ||
|
@@ -27,18 +33,29 @@ describe("Account Initialization", () => { | |
expect(BigInt(domainFields[idx])).toEqual(witness[1 + idx]); | ||
} | ||
const expectedPubKeyHash = emailWalletUtils.publicKeyHash(parsedEmail.publicKey); | ||
expect(BigInt(expectedPubKeyHash)).toEqual(witness[10]); | ||
expect(BigInt(expectedPubKeyHash)).toEqual(witness[1 + domainFields.length]); | ||
const expectedEmailNullifier = emailWalletUtils.emailNullifier(parsedEmail.signature); | ||
expect(BigInt(expectedEmailNullifier)).toEqual(witness[11]); | ||
expect(BigInt(expectedEmailNullifier)).toEqual(witness[1 + domainFields.length + 1]); | ||
const timestamp = 1707866192n; | ||
expect(timestamp).toEqual(witness[12]); | ||
const emailAddr = "[email protected]"; | ||
const accountCode = "0x01eb9b204cc24c3baee11accc37d253a9c53e92b1a2cc07763475c135d575b76"; | ||
const expectedAccountSalt = emailWalletUtils.accountSalt(emailAddr, accountCode); | ||
expect(BigInt(expectedAccountSalt)).toEqual(witness[13]); | ||
const hashedPoint = hash_to_curve(emailWalletUtils.padEmailAddr(emailAddr)); | ||
const expectedPsiPoint = point_scalar_mul(hashedPoint.x, hashedPoint.y, BigInt(relayerRand)); | ||
expect(expectedPsiPoint.x).toEqual(witness[14]); | ||
expect(expectedPsiPoint.y).toEqual(witness[15]); | ||
expect(timestamp).toEqual(witness[1 + domainFields.length + 2]); | ||
const maskedSubject = "Send 0.12 ETH to "; | ||
const paddedMaskedSubject = emailWalletUtils.padString(maskedSubject, 605); | ||
const maskedSubjectFields = emailWalletUtils.bytes2Fields(paddedMaskedSubject); | ||
for (let idx = 0; idx < maskedSubjectFields.length; ++idx) { | ||
expect(BigInt(maskedSubjectFields[idx])).toEqual(witness[1 + domainFields.length + 3 + idx]); | ||
} | ||
const senderEmailAddr = "[email protected]"; | ||
const accountSalt = emailWalletUtils.accountSalt(senderEmailAddr, accountCode); | ||
expect(BigInt(accountSalt)).toEqual(witness[1 + domainFields.length + 3 + maskedSubjectFields.length]); | ||
expect(1n).toEqual(witness[1 + domainFields.length + 3 + maskedSubjectFields.length + 1]); | ||
expect(1n).toEqual(witness[1 + domainFields.length + 3 + maskedSubjectFields.length + 2]); | ||
const recipientEmailAddr = "[email protected]"; | ||
const expectedRecipientEmailAddrCommit = emailWalletUtils.emailAddrCommitWithSignature( | ||
recipientEmailAddr, | ||
parsedEmail.signature, | ||
); | ||
expect(BigInt(expectedRecipientEmailAddrCommit)).toEqual( | ||
witness[1 + domainFields.length + 3 + maskedSubjectFields.length + 3], | ||
); | ||
}); | ||
}); |
3 changes: 0 additions & 3 deletions
3
packages/circuits/tests/circuits/test_invitation_code_regex.circom
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -19,10 +19,8 @@ describe("Email Sender", () => { | |
const emailFilePath = path.join(__dirname, "./emails/email_sender_test1.eml"); | ||
const emailRaw = readFileSync(emailFilePath, "utf8"); | ||
const parsedEmail = await emailWalletUtils.parseEmail(emailRaw); | ||
console.log(parsedEmail.canonicalizedHeader); | ||
const accountCode = await emailWalletUtils.genAccountCode(); | ||
const circuitInputs = await genEmailSenderInput(emailFilePath, accountCode); | ||
console.log(circuitInputs); | ||
const witness = await circuit.calculateWitness(circuitInputs); | ||
await circuit.checkConstraints(witness); | ||
const domainName = "gmail.com"; | ||
|
@@ -182,7 +180,7 @@ describe("Email Sender", () => { | |
const emailRaw = readFileSync(emailFilePath, "utf8"); | ||
const parsedEmail = await emailWalletUtils.parseEmail(emailRaw); | ||
console.log(parsedEmail.canonicalizedHeader); | ||
const accountCode = await emailWalletUtils.genAccountCode(); | ||
const accountCode = "0x01eb9b204cc24c3baee11accc37d253a9c53e92b1a2cc07763475c135d575b76"; | ||
const circuitInputs = await genEmailSenderInput(emailFilePath, accountCode); | ||
const witness = await circuit.calculateWitness(circuitInputs); | ||
await circuit.checkConstraints(witness); | ||
|
@@ -207,7 +205,7 @@ describe("Email Sender", () => { | |
const senderEmailAddr = "[email protected]"; | ||
const accountSalt = emailWalletUtils.accountSalt(senderEmailAddr, accountCode); | ||
expect(BigInt(accountSalt)).toEqual(witness[1 + domainFields.length + 3 + maskedSubjectFields.length]); | ||
expect(0n).toEqual(witness[1 + domainFields.length + 3 + maskedSubjectFields.length + 1]); | ||
expect(1n).toEqual(witness[1 + domainFields.length + 3 + maskedSubjectFields.length + 1]); | ||
expect(1n).toEqual(witness[1 + domainFields.length + 3 + maskedSubjectFields.length + 2]); | ||
const recipientEmailAddr = "[email protected]"; | ||
const expectedRecipientEmailAddrCommit = emailWalletUtils.emailAddrCommitWithSignature( | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,51 @@ | ||
const ff = require("ffjavascript"); | ||
const emailWalletUtils = require("@zk-email/relayer-utils"); | ||
import { hash_to_curve, point_scalar_mul } from "circom-grumpkin"; | ||
import { genPsiPointsInput } from "../helpers/psi_points"; | ||
const circom_tester = require("circom_tester"); | ||
const wasm_tester = circom_tester.wasm; | ||
import * as path from "path"; | ||
const option = { | ||
include: path.join(__dirname, "../../../node_modules"), | ||
}; | ||
|
||
jest.setTimeout(120000); | ||
describe("PSI point", () => { | ||
let circuit: any; | ||
beforeAll(async () => { | ||
circuit = await wasm_tester(path.join(__dirname, "../src/psi_points.circom"), option); | ||
}); | ||
|
||
it("psi point calculation test", async () => { | ||
const emailAddr = "[email protected]"; | ||
const paddedEmailAddr = emailWalletUtils.padEmailAddr(emailAddr); | ||
const hashedPoint = hash_to_curve(paddedEmailAddr); | ||
const relayerRand = emailWalletUtils.genRelayerRand(); | ||
const clientRand = emailWalletUtils.genRelayerRand(); | ||
const requestPoint = point_scalar_mul(hashedPoint.x, hashedPoint.y, BigInt(clientRand)); | ||
const responsePoint = point_scalar_mul(requestPoint.x, requestPoint.y, BigInt(relayerRand)); | ||
const scalarField = new ff.F1Field("21888242871839275222246405745257275088696311157297823662689037894645226208583"); | ||
const invClientRand = scalarField.inv(BigInt(clientRand)); | ||
const invedPoint = point_scalar_mul(responsePoint.x, responsePoint.y, invClientRand); | ||
const psiPoint = point_scalar_mul(hashedPoint.x, hashedPoint.y, BigInt(relayerRand)); | ||
expect(psiPoint.x).toEqual(invedPoint.x); | ||
expect(psiPoint.y).toEqual(invedPoint.y); | ||
}); | ||
|
||
it("psi circuits test", async () => { | ||
const emailAddr = "[email protected]"; | ||
const accountCode = emailWalletUtils.genAccountCode(); | ||
const relayerRand = emailWalletUtils.genRelayerRand(); | ||
const circuitInputs = await genPsiPointsInput(emailAddr, accountCode, relayerRand); | ||
const witness = await circuit.calculateWitness(circuitInputs); | ||
await circuit.checkConstraints(witness); | ||
const expectedAccountSalt = emailWalletUtils.accountSalt(emailAddr, accountCode); | ||
expect(BigInt(expectedAccountSalt)).toEqual(witness[1]); | ||
const paddedEmailAddr = emailWalletUtils.padEmailAddr(emailAddr); | ||
const hashedPoint = hash_to_curve(paddedEmailAddr); | ||
const psiPoint = point_scalar_mul(hashedPoint.x, hashedPoint.y, BigInt(relayerRand)); | ||
expect(psiPoint.x).toEqual(witness[2]); | ||
expect(psiPoint.y).toEqual(witness[3]); | ||
}); | ||
|
||
}); |
Oops, something went wrong.