mirror of
https://github.com/zkemail/zk-email-verify.git
synced 2026-01-09 13:38:03 -05:00
chore: update sha precompute error message
This commit is contained in:
@@ -48,13 +48,12 @@ export function generatePartialSHA({
|
||||
}) {
|
||||
let selectorIndex = 0;
|
||||
|
||||
// TODO: See if this (no preselector) could be handled at the circuit level
|
||||
if (selectorString) {
|
||||
const selector = new TextEncoder().encode(selectorString);
|
||||
selectorIndex = findIndexInUint8Array(body, selector);
|
||||
|
||||
if (selectorIndex === -1) {
|
||||
throw new Error('Provider SHA precompute selector not found in the body');
|
||||
throw new Error(`SHA precompute selector "${selectorString}" not found in the body`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { generateEmailVerifierInputs } from '../src/input-generators';
|
||||
import { bytesToString } from '../src/binary-format';
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { generateEmailVerifierInputs } from "../src/input-generators";
|
||||
import { bytesToString } from "../src/binary-format";
|
||||
|
||||
jest.setTimeout(10000);
|
||||
|
||||
describe('Input generators', () => {
|
||||
it('should generate input from raw email', async () => {
|
||||
describe("Input generators", () => {
|
||||
it("should generate input from raw email", async () => {
|
||||
const email = fs.readFileSync(
|
||||
path.join(__dirname, 'test-data/email-good.eml'),
|
||||
path.join(__dirname, "test-data/email-good.eml")
|
||||
);
|
||||
|
||||
const inputs = await generateEmailVerifierInputs(email);
|
||||
@@ -22,9 +22,9 @@ describe('Input generators', () => {
|
||||
expect(inputs.bodyHashIndex).toBeDefined();
|
||||
});
|
||||
|
||||
it('should generate input without body params when ignoreBodyHash is true', async () => {
|
||||
it("should generate input without body params when ignoreBodyHash is true", async () => {
|
||||
const email = fs.readFileSync(
|
||||
path.join(__dirname, 'test-data/email-good.eml'),
|
||||
path.join(__dirname, "test-data/email-good.eml")
|
||||
);
|
||||
|
||||
const inputs = await generateEmailVerifierInputs(email, {
|
||||
@@ -40,37 +40,35 @@ describe('Input generators', () => {
|
||||
expect(inputs.bodyHashIndex).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should generate input with SHA precompute selector', async () => {
|
||||
it("should generate input with SHA precompute selector", async () => {
|
||||
const email = fs.readFileSync(
|
||||
path.join(__dirname, 'test-data/email-good-large.eml'),
|
||||
path.join(__dirname, "test-data/email-good-large.eml")
|
||||
);
|
||||
|
||||
const inputs = await generateEmailVerifierInputs(email, {
|
||||
shaPrecomputeSelector: 'thousands',
|
||||
shaPrecomputeSelector: "thousands",
|
||||
});
|
||||
|
||||
expect(inputs.emailBody).toBeDefined();
|
||||
|
||||
const strBody = bytesToString(
|
||||
Uint8Array.from(inputs.emailBody!.map((b) => Number(b))),
|
||||
Uint8Array.from(inputs.emailBody!.map((b) => Number(b)))
|
||||
);
|
||||
|
||||
const expected = 'h hundreds of thousands of blocks.'; // will round till previous 64x th byte
|
||||
const expected = "h hundreds of thousands of blocks."; // will round till previous 64x th byte
|
||||
|
||||
expect(strBody.startsWith(expected)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should throw if SHA precompute selector is invalid', async () => {
|
||||
it("should throw if SHA precompute selector is invalid", async () => {
|
||||
const email = fs.readFileSync(
|
||||
path.join(__dirname, 'test-data/email-good.eml'),
|
||||
path.join(__dirname, "test-data/email-good.eml")
|
||||
);
|
||||
|
||||
expect(async () => {
|
||||
await generateEmailVerifierInputs(email, {
|
||||
shaPrecomputeSelector: 'Bla Bla',
|
||||
});
|
||||
}).rejects.toThrow(
|
||||
'Provider SHA precompute selector not found in the body',
|
||||
);
|
||||
await expect(() =>
|
||||
generateEmailVerifierInputs(email, {
|
||||
shaPrecomputeSelector: "Bla Bla",
|
||||
})
|
||||
).rejects.toThrow('SHA precompute selector "Bla Bla" not found in the body');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user