Fix receipt hash script idempotency
This commit is contained in:
@@ -1,17 +1,35 @@
|
||||
import { hashBlake3Hex, hashSha256Hex } from "../src/lib/hash.js";
|
||||
import fs from "fs";
|
||||
|
||||
const body = JSON.parse(fs.readFileSync("outputs/receipts/test-receipt.json", "utf8"));
|
||||
const path = "outputs/receipts/test-receipt.json";
|
||||
const env = JSON.parse(fs.readFileSync(path, "utf8"));
|
||||
|
||||
const {
|
||||
hash_alg: _hash_alg,
|
||||
blake3: _blake3,
|
||||
sha256: _sha256,
|
||||
sig_alg: _sig_alg,
|
||||
signer_pub: _signer_pub,
|
||||
signature: _signature,
|
||||
signed_at: _signed_at,
|
||||
...body
|
||||
} = env;
|
||||
|
||||
const blake3 = hashBlake3Hex(body);
|
||||
const sha256 = hashSha256Hex(body);
|
||||
|
||||
const envelope = {
|
||||
const envelope: typeof env = {
|
||||
...body,
|
||||
hash_alg: "blake3+sha256",
|
||||
blake3,
|
||||
sha256
|
||||
};
|
||||
|
||||
fs.writeFileSync("outputs/receipts/test-receipt.json", JSON.stringify(envelope, null, 2));
|
||||
if (_sig_alg !== undefined) envelope.sig_alg = _sig_alg;
|
||||
if (_signer_pub !== undefined) envelope.signer_pub = _signer_pub;
|
||||
if (_signature !== undefined) envelope.signature = _signature;
|
||||
if (_signed_at !== undefined) envelope.signed_at = _signed_at;
|
||||
|
||||
fs.writeFileSync(path, JSON.stringify(envelope, null, 2));
|
||||
console.log("blake3:", blake3);
|
||||
console.log("sha256:", sha256);
|
||||
|
||||
Reference in New Issue
Block a user