Skip to content

Commit

Permalink
Fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Hrom131 committed Nov 15, 2024
1 parent bf58468 commit e4d58e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/core/dependencies/CircomFilesResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { getRealPath } from "hardhat/internal/util/fs-utils";

import { CircomFilesParser } from "./parser/CircomFilesParser";
import { CIRCOM_FILE_REG_EXP, NODE_MODULES, NODE_MODULES_REG_EXP, URI_SCHEME_REG_EXP } from "../../constants";
import { getSHA1Hash } from "../../utils";
import { getFileHash } from "../../utils";
import { HardhatZKitError } from "../../errors";

import {
Expand Down Expand Up @@ -385,8 +385,7 @@ export class CircomFilesResolver {
const stats = await fsExtra.stat(absolutePath);
const lastModificationDate = new Date(stats.ctime);

// Add await here
const contentHash = await getSHA1Hash(fsExtra.readFileSync(absolutePath));
const contentHash = await getFileHash(absolutePath);

const fileData = this._parser.parse(rawContent, absolutePath, contentHash);

Expand Down
23 changes: 14 additions & 9 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import * as snarkjs from "snarkjs";
import { ProvingSystemType } from "@solarity/zkit";

import { Reporter } from "../reporter";
import { HardhatZKitError } from "../errors";
import { BN128_CURVE_NAME } from "../constants";

import { ExecCallResult } from "../types/utils";

import { BN128_CURVE_NAME } from "../constants";

/**
* Downloads a file from the specified URL
*
Expand Down Expand Up @@ -108,14 +108,19 @@ export async function getFileHash(filePath: string): Promise<string> {
const hash = createHash("sha1");
const stream = fsExtra.createReadStream(filePath);

stream.on("data", (data) => hash.update(data));
stream.on("end", () => resolve(hash.digest("hex")));
stream.on("error", reject);
});
}
stream.on("data", (data: Buffer) => {
// Add data chunk to the hash object
hash.update(data);
});

stream.on("end", () => {
resolve(hash.digest("hex"));
});

export function getSHA1Hash(rawFileData: Buffer): string {
return createHash("sha1").update(rawFileData).digest().toString("hex");
stream.on("error", () => {
reject(new HardhatZKitError(`Failed to read ${filePath} file`));
});
});
}

export function getUniqueProvingSystems(provingSystems: ProvingSystemType | ProvingSystemType[]): ProvingSystemType[] {
Expand Down

0 comments on commit e4d58e1

Please sign in to comment.