import { existsSync } from "node:fs"; import { sha256File } from "./hash"; import { BUNDLE_SPECS } from "./manifest"; import { getBundledBinaryPath } from "./paths"; import { getRuntimeTarget } from "./platform"; import type { BinaryVerification, TargetKey, ToolName } from "./types"; export function verifyBundledBinary(tool: ToolName, targetKey = getRuntimeTarget().key): BinaryVerification { const spec = BUNDLE_SPECS[tool][targetKey]; const path = getBundledBinaryPath(tool, targetKey, spec.binaryName); if (!existsSync(path)) { return { ok: false, path, expected: spec.sha256, reason: "missing" }; } const actual = sha256File(path); if (actual !== spec.sha256) { return { ok: false, path, expected: spec.sha256, actual, reason: "sha256-mismatch" }; } return { ok: true, path, expected: spec.sha256, actual }; }