fix(helper): updated input gneration function for bodyhash circuits

This commit is contained in:
Yogesh Shahi
2025-07-17 17:56:12 +05:30
parent 33ddc964b4
commit c27609f31f
2 changed files with 31 additions and 0 deletions

View File

@@ -15,6 +15,8 @@
"src"
],
"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",
"atob": "^2.1.2",
"circomlibjs": "^0.1.7",

View File

@@ -2,6 +2,8 @@ import { Uint8ArrayToCharArray, toCircomBigIntBytes } from './binary-format';
import { MAX_BODY_PADDED_BYTES, MAX_HEADER_PADDED_BYTES } from './constants';
import { DKIMVerificationResult, verifyDKIMSignature } from './dkim';
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 = {
emailHeader: string[];
@@ -15,6 +17,13 @@ type CircuitInput = {
decodedEmailBodyIn?: string[];
headerMask?: number[];
bodyMask?: number[];
bodyHashMatchStart?: number;
bodyHashMatchLength?: number;
bodyHashCurrStates?: number[];
bodyHashNextStates?: number[];
bodyHashCaptureGroup1Id?: number[];
bodyHashCaptureGroup1Start?: number[];
bodyHashCaptureGroupStartIndices?: number[];
};
type InputGenerationArgs = {
@@ -246,6 +255,26 @@ export function generateEmailVerifierInputsFromDKIMResult(
if (params.enableBodyMasking) {
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;