// The transparency log's lines in the Trust view (spec §5.12): what // `oxy tlog verify --json` proved, who cosigned it, or why it failed. No // vscode imports, so it is tested with plain Node. import { TlogInfo } from "./oxy"; /** The last check of a repository's hub log: its result or its error. */ export type TlogCheck = { info: TlogInfo; when_ms: number } | { error: string; when_ms: number }; export interface TlogLine { label: string; description?: string; tooltip?: string; icon: string; } /** The Trust view's lines for a log check; `ago` words a time (milliseconds since the epoch). */ export function tlogLines(check: TlogCheck | undefined, ago: (ms: number) => string): TlogLine[] { if (!check) { return [{ label: "Transparency log not checked", description: "click to verify the hub's log", icon: "shield", tooltip: "Runs oxy tlog verify: checks that the hub shows everyone the same history." }]; } if ("error" in check) { const first = check.error.trim().split("\n")[0] || "oxy tlog verify failed"; return [{ label: "Transparency log NOT verified", description: first, icon: "error", tooltip: check.error.trim() }]; } const { info } = check; const mine = info.entries.length; const lines: TlogLine[] = [ { label: `Transparency log verified up to checkpoint ${info.size}`, description: `${info.origin} · ${mine} entr${mine === 1 ? "y" : "ies"} for this repository · ${ago(check.when_ms)}`, icon: "verified", tooltip: `${info.hub}\nRoot ${info.root}\nEvery entry checks against the root its log key signed, and the log extends what you saw before.`, }, ]; if (info.witnesses.length === 0) { lines.push({ label: "Cosigned by no witness you trust", icon: "warning", tooltip: "Without a witness, only your own past checks show the hub has not forked its log." }); } else { for (const w of info.witnesses) { lines.push({ label: `Cosigned by ${w.name}`, description: ago(w.time_ms), icon: "key" }); } } return lines; }