OXYGENHUB
# dac6876e4d08 oxygen-vscode / src / tlog.ts
2.0 KiB · last changed Withdraw tags, verify the transparency log, shallow clones, keep a side or both sides of a conflict, commit and amend by paths, merge remote bookmarks (closes #11) 7 days ago source blame history raw
dac6876e Andy McCall ↶ 1
// The transparency log's lines in the Trust view (spec §5.12): what
2
// `oxy tlog verify --json` proved, who cosigned it, or why it failed. No
3
// vscode imports, so it is tested with plain Node.
4
5
import { TlogInfo } from "./oxy";
6
7
/** 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 };
9
10
export interface TlogLine {
11
  label: string;
12
  description?: string;
13
  tooltip?: string;
14
  icon: string;
15
}
16
17
/** The Trust view's lines for a log check; `ago` words a time (milliseconds since the epoch). */
18
export function tlogLines(check: TlogCheck | undefined, ago: (ms: number) => string): TlogLine[] {
19
  if (!check) {
20
    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." }];
21
  }
22
  if ("error" in check) {
23
    const first = check.error.trim().split("\n")[0] || "oxy tlog verify failed";
24
    return [{ label: "Transparency log NOT verified", description: first, icon: "error", tooltip: check.error.trim() }];
25
  }
26
  const { info } = check;
27
  const mine = info.entries.length;
28
  const lines: TlogLine[] = [
29
    {
30
      label: `Transparency log verified up to checkpoint ${info.size}`,
31
      description: `${info.origin} · ${mine} entr${mine === 1 ? "y" : "ies"} for this repository · ${ago(check.when_ms)}`,
32
      icon: "verified",
33
      tooltip: `${info.hub}\nRoot ${info.root}\nEvery entry checks against the root its log key signed, and the log extends what you saw before.`,
34
    },
35
  ];
36
  if (info.witnesses.length === 0) {
37
    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." });
38
  } else {
39
    for (const w of info.witnesses) {
40
      lines.push({ label: `Cosigned by ${w.name}`, description: ago(w.time_ms), icon: "key" });
41
    }
42
  }
43
  return lines;
44
}