mirror of
https://github.com/zkemail/zk-email-verify.git
synced 2026-01-09 13:38:03 -05:00
chore: minor change
This commit is contained in:
@@ -1,58 +1,57 @@
|
||||
import { wasm } from "circom_tester";
|
||||
import path from "path";
|
||||
|
||||
|
||||
describe("Base64 Lookup", () => {
|
||||
jest.setTimeout(10 * 60 * 1000); // 10 minutes
|
||||
jest.setTimeout(30 * 60 * 1000); // 30 minutes
|
||||
|
||||
let circuit: any;
|
||||
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"),
|
||||
}
|
||||
);
|
||||
});
|
||||
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], // =
|
||||
]
|
||||
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 })
|
||||
}
|
||||
});
|
||||
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];
|
||||
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");
|
||||
}
|
||||
}
|
||||
});
|
||||
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");
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@ import { generateEmailVerifierInputsFromDKIMResult } from "@zk-email/helpers/src
|
||||
import { verifyDKIMSignature } from "@zk-email/helpers/src/dkim";
|
||||
|
||||
describe("EmailVerifier : Without body check", () => {
|
||||
jest.setTimeout(10 * 60 * 1000); // 10 minutes
|
||||
jest.setTimeout(30 * 60 * 1000); // 30 minutes
|
||||
|
||||
let dkimResult: DKIMVerificationResult;
|
||||
let circuit: any;
|
||||
|
||||
@@ -6,7 +6,7 @@ import { generateEmailVerifierInputsFromDKIMResult } from "@zk-email/helpers/src
|
||||
import { verifyDKIMSignature } from "@zk-email/helpers/src/dkim";
|
||||
|
||||
describe("EmailVerifier : With body masking", () => {
|
||||
jest.setTimeout(10 * 60 * 1000); // 10 minutes
|
||||
jest.setTimeout(30 * 60 * 1000); // 30 minutes
|
||||
|
||||
let dkimResult: DKIMVerificationResult;
|
||||
let circuit: any;
|
||||
|
||||
@@ -6,7 +6,7 @@ import { generateEmailVerifierInputsFromDKIMResult } from "@zk-email/helpers/src
|
||||
import { verifyDKIMSignature } from "@zk-email/helpers/src/dkim";
|
||||
|
||||
describe("EmailVerifier : With header masking", () => {
|
||||
jest.setTimeout(10 * 60 * 1000); // 10 minutes
|
||||
jest.setTimeout(30 * 60 * 1000); // 30 minutes
|
||||
|
||||
let dkimResult: DKIMVerificationResult;
|
||||
let circuit: any;
|
||||
|
||||
@@ -6,7 +6,7 @@ import { generateEmailVerifierInputsFromDKIMResult } from "@zk-email/helpers/src
|
||||
import { verifyDKIMSignature } from "@zk-email/helpers/src/dkim";
|
||||
|
||||
describe("EmailVerifier : With soft line breaks", () => {
|
||||
jest.setTimeout(10 * 60 * 1000); // 10 minutes
|
||||
jest.setTimeout(30 * 60 * 1000); // 30 minutes
|
||||
|
||||
let dkimResult: DKIMVerificationResult;
|
||||
let circuit: any;
|
||||
|
||||
@@ -7,7 +7,7 @@ import { verifyDKIMSignature } from "@zk-email/helpers/src/dkim";
|
||||
import { poseidonLarge } from "@zk-email/helpers/src/hash";
|
||||
|
||||
describe("EmailVerifier", () => {
|
||||
jest.setTimeout(10 * 60 * 1000); // 10 minutes
|
||||
jest.setTimeout(30 * 60 * 1000); // 30 minutes
|
||||
|
||||
let dkimResult: DKIMVerificationResult;
|
||||
let circuit: any;
|
||||
|
||||
@@ -4,83 +4,142 @@ import { wasm as wasm_tester } from "circom_tester";
|
||||
import { generateEmailVerifierInputs } from "@zk-email/helpers/src/input-generators";
|
||||
import { toCircomBigIntBytes } from "@zk-email/helpers/src/binary-format";
|
||||
|
||||
|
||||
describe("RSA", () => {
|
||||
jest.setTimeout(10 * 60 * 1000); // 10 minutes
|
||||
jest.setTimeout(30 * 60 * 1000); // 30 minutes
|
||||
|
||||
let circuit: any;
|
||||
let rawEmail: Buffer;
|
||||
let circuit: any;
|
||||
let rawEmail: Buffer;
|
||||
|
||||
beforeAll(async () => {
|
||||
circuit = await wasm_tester(
|
||||
path.join(__dirname, "./test-circuits/rsa-test.circom"),
|
||||
{
|
||||
recompile: true,
|
||||
include: path.join(__dirname, "../../../node_modules"),
|
||||
// output: path.join(__dirname, "./compiled-test-circuits"),
|
||||
}
|
||||
);
|
||||
rawEmail = fs.readFileSync(path.join(__dirname, "./test-emails/test.eml"));
|
||||
});
|
||||
|
||||
it("should verify 2048 bit rsa signature correctly", async function () {
|
||||
const emailVerifierInputs = await generateEmailVerifierInputs(rawEmail, {
|
||||
maxHeadersLength: 640,
|
||||
maxBodyLength: 768,
|
||||
beforeAll(async () => {
|
||||
circuit = await wasm_tester(
|
||||
path.join(__dirname, "./test-circuits/rsa-test.circom"),
|
||||
{
|
||||
recompile: true,
|
||||
include: path.join(__dirname, "../../../node_modules"),
|
||||
// output: path.join(__dirname, "./compiled-test-circuits"),
|
||||
}
|
||||
);
|
||||
rawEmail = fs.readFileSync(
|
||||
path.join(__dirname, "./test-emails/test.eml")
|
||||
);
|
||||
});
|
||||
|
||||
it("should verify 2048 bit rsa signature correctly", async function () {
|
||||
const emailVerifierInputs = await generateEmailVerifierInputs(
|
||||
rawEmail,
|
||||
{
|
||||
maxHeadersLength: 640,
|
||||
maxBodyLength: 768,
|
||||
}
|
||||
);
|
||||
|
||||
const witness = await circuit.calculateWitness({
|
||||
signature: emailVerifierInputs.signature,
|
||||
modulus: emailVerifierInputs.pubkey,
|
||||
// TODO: generate this from the input
|
||||
message: ["1156466847851242602709362303526378170", "191372789510123109308037416804949834", "7204", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
|
||||
});
|
||||
await circuit.checkConstraints(witness);
|
||||
await circuit.assertOut(witness, {})
|
||||
});
|
||||
|
||||
it("should verify 1024 bit rsa signature correctly", async function () {
|
||||
const signature = toCircomBigIntBytes(
|
||||
BigInt(
|
||||
102386562682221859025549328916727857389789009840935140645361501981959969535413501251999442013082353139290537518086128904993091119534674934202202277050635907008004079788691412782712147797487593510040249832242022835902734939817209358184800954336078838331094308355388211284440290335887813714894626653613586546719n
|
||||
)
|
||||
);
|
||||
|
||||
const pubkey = toCircomBigIntBytes(
|
||||
BigInt(
|
||||
106773687078109007595028366084970322147907086635176067918161636756354740353674098686965493426431314019237945536387044259034050617425729739578628872957481830432099721612688699974185290306098360072264136606623400336518126533605711223527682187548332314997606381158951535480830524587400401856271050333371205030999n
|
||||
)
|
||||
);
|
||||
|
||||
const witness = await circuit.calculateWitness({
|
||||
signature: signature,
|
||||
modulus: pubkey,
|
||||
// TODO: generate this from the input
|
||||
message: ["1156466847851242602709362303526378170", "191372789510123109308037416804949834", "7204", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
|
||||
});
|
||||
await circuit.checkConstraints(witness);
|
||||
await circuit.assertOut(witness, {});
|
||||
});
|
||||
|
||||
it("should fail when verifying with an incorrect signature", async function () {
|
||||
const emailVerifierInputs = await generateEmailVerifierInputs(rawEmail, {
|
||||
maxHeadersLength: 640,
|
||||
maxBodyLength: 768,
|
||||
const witness = await circuit.calculateWitness({
|
||||
signature: emailVerifierInputs.signature,
|
||||
modulus: emailVerifierInputs.pubkey,
|
||||
// TODO: generate this from the input
|
||||
message: [
|
||||
"1156466847851242602709362303526378170",
|
||||
"191372789510123109308037416804949834",
|
||||
"7204",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
],
|
||||
});
|
||||
await circuit.checkConstraints(witness);
|
||||
await circuit.assertOut(witness, {});
|
||||
});
|
||||
|
||||
it("should verify 1024 bit rsa signature correctly", async function () {
|
||||
const signature = toCircomBigIntBytes(
|
||||
BigInt(
|
||||
102386562682221859025549328916727857389789009840935140645361501981959969535413501251999442013082353139290537518086128904993091119534674934202202277050635907008004079788691412782712147797487593510040249832242022835902734939817209358184800954336078838331094308355388211284440290335887813714894626653613586546719n
|
||||
)
|
||||
);
|
||||
|
||||
expect.assertions(1);
|
||||
try {
|
||||
const witness = await circuit.calculateWitness({
|
||||
signature: emailVerifierInputs.signature,
|
||||
modulus: emailVerifierInputs.pubkey,
|
||||
message: ["1156466847851242602709362303526378171", "191372789510123109308037416804949834", "7204", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
|
||||
});
|
||||
await circuit.checkConstraints(witness);
|
||||
await circuit.assertOut(witness, {})
|
||||
} catch (error) {
|
||||
expect((error as Error).message).toMatch("Assert Failed");
|
||||
}
|
||||
});
|
||||
const pubkey = toCircomBigIntBytes(
|
||||
BigInt(
|
||||
106773687078109007595028366084970322147907086635176067918161636756354740353674098686965493426431314019237945536387044259034050617425729739578628872957481830432099721612688699974185290306098360072264136606623400336518126533605711223527682187548332314997606381158951535480830524587400401856271050333371205030999n
|
||||
)
|
||||
);
|
||||
|
||||
const witness = await circuit.calculateWitness({
|
||||
signature: signature,
|
||||
modulus: pubkey,
|
||||
// TODO: generate this from the input
|
||||
message: [
|
||||
"1156466847851242602709362303526378170",
|
||||
"191372789510123109308037416804949834",
|
||||
"7204",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
],
|
||||
});
|
||||
await circuit.checkConstraints(witness);
|
||||
await circuit.assertOut(witness, {});
|
||||
});
|
||||
|
||||
it("should fail when verifying with an incorrect signature", async function () {
|
||||
const emailVerifierInputs = await generateEmailVerifierInputs(
|
||||
rawEmail,
|
||||
{
|
||||
maxHeadersLength: 640,
|
||||
maxBodyLength: 768,
|
||||
}
|
||||
);
|
||||
|
||||
expect.assertions(1);
|
||||
try {
|
||||
const witness = await circuit.calculateWitness({
|
||||
signature: emailVerifierInputs.signature,
|
||||
modulus: emailVerifierInputs.pubkey,
|
||||
message: [
|
||||
"1156466847851242602709362303526378171",
|
||||
"191372789510123109308037416804949834",
|
||||
"7204",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
],
|
||||
});
|
||||
await circuit.checkConstraints(witness);
|
||||
await circuit.assertOut(witness, {});
|
||||
} catch (error) {
|
||||
expect((error as Error).message).toMatch("Assert Failed");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
import { wasm } from "circom_tester";
|
||||
import path from "path";
|
||||
|
||||
|
||||
describe("Select Regex Reveal", () => {
|
||||
jest.setTimeout(10 * 60 * 1000); // 10 minutes
|
||||
jest.setTimeout(30 * 60 * 1000); // 30 minutes
|
||||
|
||||
let circuit: any;
|
||||
|
||||
beforeAll(async () => {
|
||||
circuit = await wasm(
|
||||
path.join(__dirname, "./test-circuits/select-regex-reveal-test.circom"),
|
||||
path.join(
|
||||
__dirname,
|
||||
"./test-circuits/select-regex-reveal-test.circom"
|
||||
),
|
||||
{
|
||||
recompile: true,
|
||||
include: path.join(__dirname, "../../../node_modules"),
|
||||
@@ -18,9 +20,14 @@ describe("Select Regex Reveal", () => {
|
||||
});
|
||||
|
||||
it("should reveal the substring with maximum revealed length", async function () {
|
||||
let input = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||
let input = [
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
const startIndex = Math.floor(Math.random() * 24);
|
||||
const revealed = Array.from("zk email").map(char => char.charCodeAt(0));
|
||||
const revealed = Array.from("zk email").map((char) =>
|
||||
char.charCodeAt(0)
|
||||
);
|
||||
for (let i = 0; i < revealed.length; i++) {
|
||||
input[startIndex + i] = revealed[i];
|
||||
}
|
||||
@@ -29,13 +36,16 @@ describe("Select Regex Reveal", () => {
|
||||
startIndex: startIndex,
|
||||
});
|
||||
await circuit.checkConstraints(witness);
|
||||
await circuit.assertOut(witness, { out: revealed })
|
||||
await circuit.assertOut(witness, { out: revealed });
|
||||
});
|
||||
|
||||
it("should reveal the substring with non-maximum revealed length", async function () {
|
||||
let input = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||
let input = [
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
const startIndex = 30;
|
||||
const revealed = Array.from("zk").map(char => char.charCodeAt(0));
|
||||
const revealed = Array.from("zk").map((char) => char.charCodeAt(0));
|
||||
for (let i = 0; i < revealed.length; i++) {
|
||||
input[startIndex + i] = revealed[i];
|
||||
}
|
||||
@@ -44,11 +54,16 @@ describe("Select Regex Reveal", () => {
|
||||
startIndex: startIndex,
|
||||
});
|
||||
await circuit.checkConstraints(witness);
|
||||
await circuit.assertOut(witness, { out: revealed.concat([0, 0, 0, 0, 0, 0]) })
|
||||
await circuit.assertOut(witness, {
|
||||
out: revealed.concat([0, 0, 0, 0, 0, 0]),
|
||||
});
|
||||
});
|
||||
|
||||
it("should fail when all zero", async function () {
|
||||
let input = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||
let input = [
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
const startIndex = Math.floor(Math.random() * 32);
|
||||
try {
|
||||
const witness = await circuit.calculateWitness({
|
||||
@@ -62,9 +77,14 @@ describe("Select Regex Reveal", () => {
|
||||
});
|
||||
|
||||
it("should fail when startIndex is 0", async function () {
|
||||
let input = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||
let input = [
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
const startIndex = 1 + Math.floor(Math.random() * 24);
|
||||
const revealed = Array.from("zk email").map(char => char.charCodeAt(0));
|
||||
const revealed = Array.from("zk email").map((char) =>
|
||||
char.charCodeAt(0)
|
||||
);
|
||||
for (let i = 0; i < revealed.length; i++) {
|
||||
input[startIndex + i] = revealed[i];
|
||||
}
|
||||
@@ -80,9 +100,14 @@ describe("Select Regex Reveal", () => {
|
||||
});
|
||||
|
||||
it("should fail when startIndex is not before 0", async function () {
|
||||
let input = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||
let input = [
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
const startIndex = Math.floor(Math.random() * 23);
|
||||
const revealed = Array.from("zk email").map(char => char.charCodeAt(0));
|
||||
const revealed = Array.from("zk email").map((char) =>
|
||||
char.charCodeAt(0)
|
||||
);
|
||||
for (let i = 0; i < revealed.length; i++) {
|
||||
input[startIndex + i] = revealed[i];
|
||||
}
|
||||
@@ -98,16 +123,21 @@ describe("Select Regex Reveal", () => {
|
||||
});
|
||||
|
||||
it("should fail when startIndex is larger than max length", async function () {
|
||||
let input = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||
let input = [
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
const startIndex = Math.floor(Math.random() * 24);
|
||||
const revealed = Array.from("zk email").map(char => char.charCodeAt(0));
|
||||
const revealed = Array.from("zk email").map((char) =>
|
||||
char.charCodeAt(0)
|
||||
);
|
||||
for (let i = 0; i < revealed.length; i++) {
|
||||
input[startIndex + i] = revealed[i];
|
||||
}
|
||||
try {
|
||||
const witness = await circuit.calculateWitness({
|
||||
in: input,
|
||||
startIndex: 32
|
||||
startIndex: 32,
|
||||
});
|
||||
await circuit.checkConstraints(witness);
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
import { wasm as wasm_tester } from "circom_tester";
|
||||
import path from "path";
|
||||
import { sha256Pad, shaHash } from "@zk-email/helpers/src/sha-utils";
|
||||
import { Uint8ArrayToCharArray, uint8ToBits } from "@zk-email/helpers/src/binary-format";
|
||||
|
||||
import {
|
||||
Uint8ArrayToCharArray,
|
||||
uint8ToBits,
|
||||
} from "@zk-email/helpers/src/binary-format";
|
||||
|
||||
describe("SHA256 for email header", () => {
|
||||
jest.setTimeout(10 * 60 * 1000); // 10 minutes
|
||||
jest.setTimeout(30 * 60 * 1000); // 30 minutes
|
||||
|
||||
let circuit: any;
|
||||
let circuit: any;
|
||||
|
||||
beforeAll(async () => {
|
||||
circuit = await wasm_tester(
|
||||
path.join(__dirname, "./test-circuits/sha-test.circom"),
|
||||
{
|
||||
recompile: true,
|
||||
include: path.join(__dirname, "../../../node_modules"),
|
||||
// output: path.join(__dirname, "./compiled-test-circuits"),
|
||||
}
|
||||
);
|
||||
});
|
||||
beforeAll(async () => {
|
||||
circuit = await wasm_tester(
|
||||
path.join(__dirname, "./test-circuits/sha-test.circom"),
|
||||
{
|
||||
recompile: true,
|
||||
include: path.join(__dirname, "../../../node_modules"),
|
||||
// output: path.join(__dirname, "./compiled-test-circuits"),
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it("should hash correctly", async function () {
|
||||
const inputs = [
|
||||
"0", "hello world", ""
|
||||
]
|
||||
for (const input of inputs) {
|
||||
const [
|
||||
paddedMsg,
|
||||
messageLen,
|
||||
] = sha256Pad(
|
||||
Buffer.from(input, "ascii"), 640
|
||||
)
|
||||
it("should hash correctly", async function () {
|
||||
const inputs = ["0", "hello world", ""];
|
||||
for (const input of inputs) {
|
||||
const [paddedMsg, messageLen] = sha256Pad(
|
||||
Buffer.from(input, "ascii"),
|
||||
640
|
||||
);
|
||||
|
||||
const witness = await circuit.calculateWitness({
|
||||
paddedIn: Uint8ArrayToCharArray(paddedMsg),
|
||||
paddedInLength: messageLen,
|
||||
});
|
||||
const witness = await circuit.calculateWitness({
|
||||
paddedIn: Uint8ArrayToCharArray(paddedMsg),
|
||||
paddedInLength: messageLen,
|
||||
});
|
||||
|
||||
await circuit.checkConstraints(witness);
|
||||
await circuit.assertOut(witness, { out: [...uint8ToBits(shaHash(Buffer.from(input, "ascii")))] })
|
||||
}
|
||||
});
|
||||
await circuit.checkConstraints(witness);
|
||||
await circuit.assertOut(witness, {
|
||||
out: [...uint8ToBits(shaHash(Buffer.from(input, "ascii")))],
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user