mirror of
https://github.com/zkemail/zk-email-verify.git
synced 2026-01-09 21:48:14 -05:00
fix(helper): updated input gneration function for bodyhash circuits
This commit is contained in:
@@ -15,6 +15,8 @@
|
|||||||
"src"
|
"src"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@zk-email/zk-regex-circom": "2.2.1-alpha.0",
|
||||||
|
"@zk-email/zk-regex-compiler": "2.2.0-alpha.0",
|
||||||
"addressparser": "^1.0.1",
|
"addressparser": "^1.0.1",
|
||||||
"atob": "^2.1.2",
|
"atob": "^2.1.2",
|
||||||
"circomlibjs": "^0.1.7",
|
"circomlibjs": "^0.1.7",
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import { Uint8ArrayToCharArray, toCircomBigIntBytes } from './binary-format';
|
|||||||
import { MAX_BODY_PADDED_BYTES, MAX_HEADER_PADDED_BYTES } from './constants';
|
import { MAX_BODY_PADDED_BYTES, MAX_HEADER_PADDED_BYTES } from './constants';
|
||||||
import { DKIMVerificationResult, verifyDKIMSignature } from './dkim';
|
import { DKIMVerificationResult, verifyDKIMSignature } from './dkim';
|
||||||
import { generatePartialSHA, sha256Pad } from './sha-utils';
|
import { generatePartialSHA, sha256Pad } from './sha-utils';
|
||||||
|
import { genCircuitInputs, ProvingFramework } from '@zk-email/zk-regex-compiler';
|
||||||
|
import bodyHashJson from '@zk-email/zk-regex-circom/circuits/common/body_hash_graph.json';
|
||||||
|
|
||||||
type CircuitInput = {
|
type CircuitInput = {
|
||||||
emailHeader: string[];
|
emailHeader: string[];
|
||||||
@@ -15,6 +17,13 @@ type CircuitInput = {
|
|||||||
decodedEmailBodyIn?: string[];
|
decodedEmailBodyIn?: string[];
|
||||||
headerMask?: number[];
|
headerMask?: number[];
|
||||||
bodyMask?: number[];
|
bodyMask?: number[];
|
||||||
|
bodyHashMatchStart?: number;
|
||||||
|
bodyHashMatchLength?: number;
|
||||||
|
bodyHashCurrStates?: number[];
|
||||||
|
bodyHashNextStates?: number[];
|
||||||
|
bodyHashCaptureGroup1Id?: number[];
|
||||||
|
bodyHashCaptureGroup1Start?: number[];
|
||||||
|
bodyHashCaptureGroupStartIndices?: number[];
|
||||||
};
|
};
|
||||||
|
|
||||||
type InputGenerationArgs = {
|
type InputGenerationArgs = {
|
||||||
@@ -246,6 +255,26 @@ export function generateEmailVerifierInputsFromDKIMResult(
|
|||||||
if (params.enableBodyMasking) {
|
if (params.enableBodyMasking) {
|
||||||
circuitInputs.bodyMask = params.bodyMask;
|
circuitInputs.bodyMask = params.bodyMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate bodyHashRegex circuit inputs
|
||||||
|
const { type, ...bodyHashCircuitInputs } = JSON.parse(
|
||||||
|
genCircuitInputs(
|
||||||
|
JSON.stringify(bodyHashJson),
|
||||||
|
headers.toString(),
|
||||||
|
(params.maxHeadersLength || MAX_HEADER_PADDED_BYTES),
|
||||||
|
(params.maxHeadersLength || MAX_HEADER_PADDED_BYTES) - 1,
|
||||||
|
ProvingFramework.Circom
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Flatten body hash inputs into direct circuit inputs
|
||||||
|
circuitInputs.bodyHashMatchStart = bodyHashCircuitInputs.matchStart;
|
||||||
|
circuitInputs.bodyHashMatchLength = bodyHashCircuitInputs.matchLength;
|
||||||
|
circuitInputs.bodyHashCurrStates = bodyHashCircuitInputs.currStates?.map((s: any) => Number(s));
|
||||||
|
circuitInputs.bodyHashNextStates = bodyHashCircuitInputs.nextStates?.map((s: any) => Number(s));
|
||||||
|
circuitInputs.bodyHashCaptureGroup1Id = bodyHashCircuitInputs.captureGroupIds?.[0]?.map((s: any) => Number(s));
|
||||||
|
circuitInputs.bodyHashCaptureGroup1Start = bodyHashCircuitInputs.captureGroupStarts?.[0]?.map((s: any) => Number(s));
|
||||||
|
circuitInputs.bodyHashCaptureGroupStartIndices = bodyHashCircuitInputs.captureGroupStartIndices?.map((s: any) => Number(s) - bodyHashCircuitInputs.matchStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
return circuitInputs;
|
return circuitInputs;
|
||||||
|
|||||||
Reference in New Issue
Block a user