diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..caa0452 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +packages/helpers/src/lib diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..28d58de --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "semi": true, + "tabWidth": 2, + "printWidth": 120 +} diff --git a/package.json b/package.json index 300d1fe..3db33fb 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "license": "MIT", "private": true, "scripts": { + "lint": "yarn prettier --write packages/**/**.ts", "test": "jest" }, "workspaces": [ @@ -12,5 +13,8 @@ "packageManager": "yarn@3.2.3", "engines": { "node": ">=14.0.0" + }, + "devDependencies": { + "prettier": "^3.3.3" } } diff --git a/packages/circuits/tests/byte-mask.test.ts b/packages/circuits/tests/byte-mask.test.ts index bafbfc4..dbfa8b3 100644 --- a/packages/circuits/tests/byte-mask.test.ts +++ b/packages/circuits/tests/byte-mask.test.ts @@ -43,5 +43,7 @@ describe("ByteMask Circuit", () => { } catch (error) { expect(error).toBeTruthy(); } + + expect.assertions(1); }); }); diff --git a/packages/circuits/tests/remove-soft-line-breaks.test.ts b/packages/circuits/tests/remove-soft-line-breaks.test.ts index 9b2d0ed..5d14f7d 100644 --- a/packages/circuits/tests/remove-soft-line-breaks.test.ts +++ b/packages/circuits/tests/remove-soft-line-breaks.test.ts @@ -2,6 +2,8 @@ import { wasm as wasm_tester } from 'circom_tester'; import path from 'path'; describe('RemoveSoftLineBreaks', () => { + jest.setTimeout(20_1000); + let circuit: any; beforeAll(async () => { diff --git a/packages/circuits/tests/select-regex-reveal.test.ts b/packages/circuits/tests/select-regex-reveal.test.ts index cd3f3b8..c18cfd6 100644 --- a/packages/circuits/tests/select-regex-reveal.test.ts +++ b/packages/circuits/tests/select-regex-reveal.test.ts @@ -20,10 +20,7 @@ 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 = new Array(34).fill(0); const startIndex = Math.floor(Math.random() * 24); const revealed = Array.from("zk email").map((char) => char.charCodeAt(0) @@ -40,10 +37,7 @@ describe("Select Regex Reveal", () => { }); 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 = new Array(34).fill(0); const startIndex = 30; const revealed = Array.from("zk").map((char) => char.charCodeAt(0)); for (let i = 0; i < revealed.length; i++) { @@ -60,11 +54,8 @@ describe("Select Regex Reveal", () => { }); 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, - ]; - const startIndex = Math.floor(Math.random() * 32); + let input = new Array(34).fill(0); + const startIndex = Math.floor(Math.random() * 34); try { const witness = await circuit.calculateWitness({ in: input, @@ -74,13 +65,12 @@ describe("Select Regex Reveal", () => { } catch (error) { expect((error as Error).message).toMatch("Assert Failed"); } + + expect.assertions(1); }); 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 = new Array(34).fill(0); const startIndex = 1 + Math.floor(Math.random() * 24); const revealed = Array.from("zk email").map((char) => char.charCodeAt(0) @@ -97,13 +87,12 @@ describe("Select Regex Reveal", () => { } catch (error) { expect((error as Error).message).toMatch("Assert Failed"); } + + expect.assertions(1); }); 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 = new Array(34).fill(0); const startIndex = Math.floor(Math.random() * 23); const revealed = Array.from("zk email").map((char) => char.charCodeAt(0) @@ -120,28 +109,7 @@ describe("Select Regex Reveal", () => { } catch (error) { expect((error as Error).message).toMatch("Assert Failed"); } - }); - 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, - ]; - const startIndex = Math.floor(Math.random() * 24); - 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, - }); - await circuit.checkConstraints(witness); - } catch (error) { - expect((error as Error).message).toMatch("Assert Failed"); - } + expect.assertions(1); }); }); diff --git a/packages/circuits/tests/splitBytesToWords.test.ts b/packages/circuits/tests/split-bytes-to-words.test.ts similarity index 93% rename from packages/circuits/tests/splitBytesToWords.test.ts rename to packages/circuits/tests/split-bytes-to-words.test.ts index 93019ab..99fc83e 100644 --- a/packages/circuits/tests/splitBytesToWords.test.ts +++ b/packages/circuits/tests/split-bytes-to-words.test.ts @@ -9,7 +9,7 @@ describe("SplitBytesToWords Helper unit test", () => { beforeAll(async () => { circuit = await wasm_tester( - path.join(__dirname, "./test-circuits/splitBytesToWords-test.circom"), + path.join(__dirname, "./test-circuits/split-bytes-to-words-test.circom"), { recompile: true, include: path.join(__dirname, "../../../node_modules"), diff --git a/packages/circuits/tests/test-circuits/select-regex-reveal-test.circom b/packages/circuits/tests/test-circuits/select-regex-reveal-test.circom index 1ae9a8c..2477371 100644 --- a/packages/circuits/tests/test-circuits/select-regex-reveal-test.circom +++ b/packages/circuits/tests/test-circuits/select-regex-reveal-test.circom @@ -2,4 +2,4 @@ pragma circom 2.1.6; include "../../utils/regex.circom"; -component main = SelectRegexReveal(32,8); \ No newline at end of file +component main = SelectRegexReveal(34, 8); \ No newline at end of file diff --git a/packages/circuits/tests/test-circuits/splitBytesToWords-test.circom b/packages/circuits/tests/test-circuits/split-bytes-to-words-test.circom similarity index 100% rename from packages/circuits/tests/test-circuits/splitBytesToWords-test.circom rename to packages/circuits/tests/test-circuits/split-bytes-to-words-test.circom diff --git a/packages/circuits/utils/regex.circom b/packages/circuits/utils/regex.circom index dd7ef74..1745a6f 100644 --- a/packages/circuits/utils/regex.circom +++ b/packages/circuits/utils/regex.circom @@ -27,10 +27,6 @@ template SelectRegexReveal(maxArrayLen, maxRevealLen) { signal isPreviousZero[maxArrayLen]; signal isAboveMaxRevealLen[maxArrayLen]; - // Assert startIndex < maxArrayLen - signal isValidStartIndex <== LessThan(bitLength)([startIndex, maxArrayLen]); - isValidStartIndex === 1; - isPreviousZero[0] <== 1; for(var i = 0; i < maxArrayLen; i++) { isStartIndex[i] <== IsEqual()([i, startIndex]); diff --git a/yarn.lock b/yarn.lock index d144c86..6a20f56 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7168,6 +7168,15 @@ __metadata: languageName: node linkType: hard +"prettier@npm:^3.3.3": + version: 3.3.3 + resolution: "prettier@npm:3.3.3" + bin: + prettier: bin/prettier.cjs + checksum: bc8604354805acfdde6106852d14b045bb20827ad76a5ffc2455b71a8257f94de93f17f14e463fe844808d2ccc87248364a5691488a3304f1031326e62d9276e + languageName: node + linkType: hard + "pretty-format@npm:^29.0.0, pretty-format@npm:^29.7.0": version: 29.7.0 resolution: "pretty-format@npm:29.7.0" @@ -7455,6 +7464,8 @@ __metadata: "root-workspace-0b6124@workspace:.": version: 0.0.0-use.local resolution: "root-workspace-0b6124@workspace:." + dependencies: + prettier: ^3.3.3 languageName: unknown linkType: soft