o1js-email-verify
Version:
Implemented using [o1js](https://github.com/o1-labs/o1js), this project is a reimplementation of [zk-email](https://github.com/zkemail/zk-email-verify), leveraging the Mina proving system [Kimchi](https://o1-labs.github.io/proof-systems/specs/kimchi.html#
33 lines • 1.55 kB
JavaScript
import { Field } from 'o1js';
import { Bigint2048 } from 'o1js-rsa';
import { verifyDKIMSignature } from '@zk-email/helpers/dist/dkim/index.js';
import { dynamicSHA256Pad, generatePartialSHA256Inputs } from 'dynamic-sha256';
export { generateInputs };
/**
* Generates inputs required for email verification from a raw email string.
*
* @param rawEmail The raw email string.
* @returns The email verification inputs.
*/
async function generateInputs(rawEmail, maxHeaderLength = 1024, maxRemainingBodyLength = 1536, shaPrecomputeSelector) {
// Parse raw email and retrieve public key of the domain in header
const dkimResult = await verifyDKIMSignature(Buffer.from(rawEmail));
const [paddedHeader, headerHashIndex] = dynamicSHA256Pad(dkimResult.headers, maxHeaderLength);
const signature = Bigint2048.from(dkimResult.signature);
const publicKey = Bigint2048.from(dkimResult.publicKey);
const modulusLength = dkimResult.modulusLength;
const { precomputedHash, messageRemainingBytes: paddedBodyRemainingBytes, digestIndex: bodyHashIndex, } = generatePartialSHA256Inputs(dkimResult.body, maxRemainingBodyLength, shaPrecomputeSelector);
const headerBodyHashIndex = Field(dkimResult.headers.toString().indexOf(dkimResult.bodyHash) - 1);
return {
paddedHeader,
headerHashIndex,
signature,
publicKey,
modulusLength,
paddedBodyRemainingBytes,
precomputedHash,
bodyHashIndex,
headerBodyHashIndex,
};
}
//# sourceMappingURL=generate-inputs.js.map