OXYGENHUB

Coverage / src/tlog.ts 86.4%

38 of 44 lines run, 1 of 1 functions, 11 of 12 branches · run #26 on main · run missed

10×
// The transparency log's lines in the Trust view (spec §5.12): what
20×
// `oxy tlog verify --json` proved, who cosigned it, or why it failed. No
30×
// vscode imports, so it is tested with plain Node.
41×
50×
import { TlogInfo } from "./oxy";
61×
70×
/** The last check of a repository's hub log: its result or its error. */
8
export type TlogCheck = { info: TlogInfo; when_ms: number } | { error: string; when_ms: number };
91×
10
export interface TlogLine {
11
  label: string;
12
  description?: string;
13
  tooltip?: string;
14
  icon: string;
15
}
161×
170×
/** The Trust view's lines for a log check; `ago` words a time (milliseconds since the epoch). */
184×
export function tlogLines(check: TlogCheck | undefined, ago: (ms: number) => string): TlogLine[] {
194×
  if (!check) {
201×
    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." }];
211×
  }
224×
  if ("error" in check) {
231×
    const first = check.error.trim().split("\n")[0] || "oxy tlog verify failed";
241×
    return [{ label: "Transparency log NOT verified", description: first, icon: "error", tooltip: check.error.trim() }];
251×
  }
262×
  const { info } = check;
272×
  const mine = info.entries.length;
282×
  const lines: TlogLine[] = [
292×
    {
302×
      label: `Transparency log verified up to checkpoint ${info.size}`,
314×
      description: `${info.origin} · ${mine} entr${mine === 1 ? "y" : "ies"} for this repository · ${ago(check.when_ms)}`,
324×
      icon: "verified",
334×
      tooltip: `${info.hub}\nRoot ${info.root}\nEvery entry checks against the root its log key signed, and the log extends what you saw before.`,
344×
    },
354×
  ];
364×
  if (info.witnesses.length === 0) {
371×
    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." });
381×
  } else {
391×
    for (const w of info.witnesses) {
402×
      lines.push({ label: `Cosigned by ${w.name}`, description: ago(w.time_ms), icon: "key" });
412×
    }
421×
  }
434×
  return lines;
444×
}