diff --git a/js/src/utils.ts b/js/src/utils.ts index 2a65f1a..17189ff 100644 --- a/js/src/utils.ts +++ b/js/src/utils.ts @@ -8,7 +8,7 @@ export type BoundedVec = { len: string; }; /** - * Transforms a u32 array to a u8 array + * Transforms a u32 array to a u8 array in big-endian format * @dev sha-utils in zk-email-verify encodes partial hash as u8 array but noir expects u32 * transform back to keep upstream code but not have noir worry about transformation * @@ -111,6 +111,7 @@ export function getAddressHeaderSequence( /** * Build a ROM table for allowable email characters + * === This function is used to generate a table to reference in Noir code === */ export function makeEmailAddressCharTable(): string { // max value: z = 122 @@ -119,7 +120,7 @@ export function makeEmailAddressCharTable(): string { const emailChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-@"; const precedingChars = "<: "; - const procedingChars = ">\r\n"; + const proceedingChars = ">\r\n"; // set valid email chars for (let i = 0; i < emailChars.length; i++) { table[emailChars.charCodeAt(i)] = 1; @@ -129,11 +130,10 @@ export function makeEmailAddressCharTable(): string { table[precedingChars.charCodeAt(i)] = 2; } // set valid proceding chars - for (let i = 0; i < procedingChars.length; i++) { - table[procedingChars.charCodeAt(i)] = 3; + for (let i = 0; i < proceedingChars.length; i++) { + table[proceedingChars.charCodeAt(i)] = 3; } let tableStr = `global EMAIL_ADDRESS_CHAR_TABLE: [u8; ${tableLength}] = [\n`; - console.log(); for (let i = 0; i < table.length; i += 10) { const end = i + 10 < table.length ? i + 10 : table.length; tableStr += ` ${table.slice(i, end).join(", ")},\n`; @@ -141,7 +141,3 @@ export function makeEmailAddressCharTable(): string { tableStr += "];"; return tableStr; } - -// export function computeStandardOutputs(email: Buffer): Promise<[bigint, bigint]> { - -// } diff --git a/lib/src/headers/body_hash.nr b/lib/src/headers/body_hash.nr index eb24fc8..c70e494 100644 --- a/lib/src/headers/body_hash.nr +++ b/lib/src/headers/body_hash.nr @@ -46,7 +46,8 @@ pub fn get_body_hash( } /** - * Get the body hash from the header without validating the access index + * Get the body hash from the header without validating the access index. Does not validate body + * hash is valid base64 sequence (https://github.com/noir-lang/noir_base64/blob/4431d08ac661ada9d8d18b115487ff0190b43856/src/lib.nr#L209-L232) * * @param MAX_HEADER_LENGTH - The maximum length of the email header * @param header - The email header as validated in the DKIM signature diff --git a/lib/src/lib.nr b/lib/src/lib.nr index bee5976..b7b1a2d 100644 --- a/lib/src/lib.nr +++ b/lib/src/lib.nr @@ -16,7 +16,7 @@ global BODY_HASH_BASE64_LENGTH: u32 = 44; global CR: u8 = 0x0D; global LF: u8 = 0x0A; global MAX_DKIM_HEADER_FIELD_LENGTH: u32 = 300; // kinda arbitrary but gives > 100 chars for selector and domain -global MAX_EMAIL_ADDRESS_LENGTH: u32 = 320; +global MAX_EMAIL_ADDRESS_LENGTH: u32 = 320; // derived via (https://datatracker.ietf.org/doc/html/rfc5321#section-4.5.3.1.1) pub struct Sequence { index: u32, diff --git a/lib/src/partial_hash.nr b/lib/src/partial_hash.nr index c4784d1..d718631 100644 --- a/lib/src/partial_hash.nr +++ b/lib/src/partial_hash.nr @@ -74,7 +74,7 @@ global BLOCK_SIZE = 64; * @notice can be used for post-partial hashing where client proves part of hash and relies on server to finish * * - * @param N: the maximum length of the message to hash. + * @param N: the length of the message to hash. * --- WARNING: N must be divisible by BLOCK_SIZE such that N % BLOCK_SIZE == 0 * otherwise the remaining bytes will not be inputted when computing the initial hash * @param msg: the preimage to begin hashing