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#
44 lines (43 loc) • 2.12 kB
TypeScript
import { Field, UInt8, Bytes } from 'o1js';
import { Bigint2048 } from 'o1js-rsa';
export { pkcs1v15Pad, bodyHashRegex, selectSubarray };
/**
* Creates a PKCS#1 v1.5 padded message for the given SHA-256 digest.
*
* @note This function follows the RFC3447 standard: https://datatracker.ietf.org/doc/html/rfc3447#section-9.2
*
* @param sha256Digest The SHA-256 digest to be padded.
* @param modulusLength The size of the RSA modulus in bytes.
* @returns The padded PKCS#1 v1.5 message.
*/
declare function pkcs1v15Pad(sha256Digest: Bytes, modulusLength: number): Bigint2048;
/**
* Scans the input ASCII bytes for a matching body hash pattern.
*
* @note This function is compiled using the o1js zk-regex compiler: https://github.com/Shigoto-dev19/zk-regex-o1js
* The regex pattern used is `bh=([a-zA-Z0-9]|\\+|/|=)+;`, revealing only base64 characters `([a-zA-Z0-9]|\\+|/|=)+` with `countEnabled` set to true.
*
* @param input The input array of UInt8 bytes to be scanned.
* @returns An object containing:
* - `out`: A Field representing the matching count (1 or more if found, 0 otherwise).
* - `reveal`: An array of Field arrays, revealing the base64 characters upon pattern match.
*/
declare function bodyHashRegex(input: UInt8[]): {
out: import("o1js/dist/node/lib/provable/field").Field;
reveal: import("o1js/dist/node/lib/provable/field").Field[][];
};
/**
* Provably select a subarray from an array of field elements.
*
* @notice The length of the output array can be reduced by setting `subarrayLength`.
* @notice Based on https://demo.hedgedoc.org/s/Le0R3xUhB.
* @notice Assumes field elements to be bytes in the input array.
*
* @param input - The input array of field elements.
* @param startIndex - The starting index for the subarray selection.
* @param subarrayLength - The length of the output subarray.
*
* @returns The selected subarray of bytes.
* @throws Will throw an error if `subarrayLength` is greater than the input array length.
*/
declare function selectSubarray(input: Field[], startIndex: Field, subarrayLength: number): UInt8[];