mirror of
https://github.com/zkemail/zk-email-verify.git
synced 2026-01-10 14:08:19 -05:00
feat: added body masking template
This commit is contained in:
11
packages/circuits/helpers/body-masker.circom
Normal file
11
packages/circuits/helpers/body-masker.circom
Normal file
@@ -0,0 +1,11 @@
|
||||
pragma circom 2.1.6;
|
||||
|
||||
template BodyMasker(maxBodyLength) {
|
||||
signal input body[maxBodyLength];
|
||||
signal input mask[maxBodyLength];
|
||||
signal output masked_body[maxBodyLength];
|
||||
|
||||
for (var i = 0; i < maxBodyLength; i++) {
|
||||
masked_body[i] <== body[i] * mask[i];
|
||||
}
|
||||
}
|
||||
30
packages/circuits/tests/body-masker.test.ts
Normal file
30
packages/circuits/tests/body-masker.test.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { wasm as wasm_tester } from "circom_tester";
|
||||
import path from "path";
|
||||
|
||||
describe("BodyMasker Circuit", () => {
|
||||
let circuit: any;
|
||||
|
||||
beforeAll(async () => {
|
||||
circuit = await wasm_tester(
|
||||
path.join(__dirname, "./test-circuits/body-masker-test.circom"),
|
||||
{
|
||||
recompile: true,
|
||||
include: path.join(__dirname, "../../../node_modules"),
|
||||
output: path.join(__dirname, "./compiled-test-circuits"),
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it("should mask the body correctly", async () => {
|
||||
const input = {
|
||||
body: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
mask: [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],
|
||||
};
|
||||
|
||||
const witness = await circuit.calculateWitness(input);
|
||||
await circuit.checkConstraints(witness);
|
||||
await circuit.assertOut(witness, {
|
||||
masked_body: [1, 0, 3, 0, 5, 0, 7, 0, 9, 0],
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
pragma circom 2.1.6;
|
||||
|
||||
include "../../helpers/body-masker.circom";
|
||||
|
||||
component main = BodyMasker(10);
|
||||
Reference in New Issue
Block a user