chore: update sha precompute error message

This commit is contained in:
Saleel
2024-06-27 19:40:05 +04:00
parent 29d5c87316
commit 384851a541
2 changed files with 22 additions and 25 deletions

View File

@@ -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`);
}
}

View File

@@ -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');
});
});