Files
vm-cloud/scripts/hash-receipt.ts
2025-12-26 22:56:00 +00:00

36 lines
923 B
TypeScript

import { hashBlake3Hex, hashSha256Hex } from "../src/lib/hash.js";
import fs from "fs";
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: typeof env = {
...body,
hash_alg: "blake3+sha256",
blake3,
sha256
};
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);