mirror of
https://github.com/morluto/rea.git
synced 2026-11-28 23:28:35 +00:00
refactor(verifiers): share whole-file SHA-256 hashing (#14475)
* refactor(verifiers): share whole-file SHA-256 hashing * fix(verifiers): type the streamed digest input
This commit is contained in:
1 parent
a0390ba877
commit
60af9ef6b3
12 files changed
+41
-68
No files matched your search
@@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { sha256File } from "../../lib/verifier-file-sha256.mjs";
|
||||
import assert from "node:assert/strict";
|
||||
import { createHash, randomUUID } from "node:crypto";
|
||||
import { createReadStream } from "node:fs";
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { isAbsolute, join } from "node:path";
|
||||
import { performance } from "node:perf_hooks";
|
||||
@@ -104,11 +104,6 @@ const client = new Client({
|
||||
const serialize = (value) => JSON.stringify(value);
|
||||
const digest = (value) =>
|
||||
createHash("sha256").update(serialize(value)).digest("hex");
|
||||
const fileDigest = async (path) => {
|
||||
const hash = createHash("sha256");
|
||||
for await (const chunk of createReadStream(path)) hash.update(chunk);
|
||||
return hash.digest("hex");
|
||||
};
|
||||
const simulatedNativeEvidence = (path, sha256) =>
|
||||
createEvidence(
|
||||
{ path, sha256, format: "raw-binary" },
|
||||
@@ -151,11 +146,11 @@ const ownedCommand = async (command, arguments_, timeoutMs = 60_000) => {
|
||||
}
|
||||
};
|
||||
await withVerifierCleanup(async () => {
|
||||
const archiveSha256 = await fileDigest(values.artifact);
|
||||
const archiveSha256 = await sha256File(values.artifact);
|
||||
const companion = join(`${values.artifact}.unpacked`, values["addon-path"]);
|
||||
let companionSha256 = null;
|
||||
try {
|
||||
companionSha256 = await fileDigest(companion);
|
||||
companionSha256 = await sha256File(companion);
|
||||
} catch (cause) {
|
||||
if (cause?.code !== "ENOENT") throw cause;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { sha256File } from "../../lib/verifier-file-sha256.mjs";
|
||||
import assert from "node:assert/strict";
|
||||
import { constants } from "node:buffer";
|
||||
import { createHash } from "node:crypto";
|
||||
@@ -157,9 +158,7 @@ await withVerifierFixture(fixture, async () => {
|
||||
assert.equal(output.error, undefined);
|
||||
assert.equal(unexpectedOutputBytes, 0);
|
||||
|
||||
const actualHash = createHash("sha256");
|
||||
for await (const chunk of createReadStream(path)) actualHash.update(chunk);
|
||||
const digest = actualHash.digest("hex");
|
||||
const digest = await sha256File(path);
|
||||
assert.equal(digest, expectedHash.digest("hex"));
|
||||
assert.equal((await stat(path)).size, expectedBytes);
|
||||
let verifiedTokenCount;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { sha256File } from "../../lib/verifier-file-sha256.mjs";
|
||||
import assert from "node:assert/strict";
|
||||
import { createHash, randomUUID } from "node:crypto";
|
||||
import { createReadStream } from "node:fs";
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { isAbsolute, join } from "node:path";
|
||||
import { performance } from "node:perf_hooks";
|
||||
@@ -111,10 +111,7 @@ const resourceSnapshot = async () => {
|
||||
|
||||
await withVerifierCleanup(async () => {
|
||||
const start = performance.now();
|
||||
const artifactHash = createHash("sha256");
|
||||
for await (const chunk of createReadStream(values.artifact))
|
||||
artifactHash.update(chunk);
|
||||
const artifactSha256 = artifactHash.digest("hex");
|
||||
const artifactSha256 = await sha256File(values.artifact);
|
||||
temporary = await VerifierFixture.open({
|
||||
prefix: "rea-retained-facts-verifier-",
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user