UNPKG

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#

57 lines 2.1 kB
import { Field, Bytes } from 'o1js'; import { bodyHashRegex } from './bodyHash-regex'; import fs from 'fs'; function utf8BytesToString(bytes) { let utf8String = ''; let codepoint = 0; let remainingBytes = 0; for (const byte of bytes.map(Number)) { if (remainingBytes === 0) { if (byte <= 0x7f) { // Single byte character (ASCII) utf8String += String.fromCharCode(Number(byte)); } else if (byte >= 0xc0 && byte <= 0xdf) { // Two byte character codepoint = byte & 0x1f; remainingBytes = 1; } else if (byte >= 0xe0 && byte <= 0xef) { // Three byte character codepoint = byte & 0x0f; remainingBytes = 2; } else if (byte >= 0xf0 && byte <= 0xf7) { // Four byte character codepoint = byte & 0x07; remainingBytes = 3; } } else { // Continuation byte codepoint = (codepoint << 6) | (byte & 0x3f); remainingBytes--; if (remainingBytes === 0) { utf8String += String.fromCharCode(codepoint); } } } return utf8String; } function testBodyHashRegex(input, expectedCount, expectedSubstring) { const inputBytes = Bytes.fromString(input).bytes; const { out, reveal } = bodyHashRegex(inputBytes); const revealedBytes = reveal[0] .map((f) => f.toBigInt()) .filter((byte) => byte !== 0n); const revealedSubString = utf8BytesToString(revealedBytes); expect(revealedSubString).toEqual(expectedSubstring); expect(out).toEqual(Field(expectedCount)); } describe('Body Hash Regex Tests', () => { it('should reveal the correct body hash from an eml file', () => { const input = fs.readFileSync('./eml/email.eml', 'utf8'); testBodyHashRegex(input, 1, 'aeLbTnlUQQv2UFEWKHeiL5Q0NjOwj4ktNSInk8rN/P0='); }); }); //# sourceMappingURL=bodyHash-regex.test.js.map