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
| 1 | 0× | // The transparency log's lines in the Trust view (spec §5.12): what |
| 2 | 0× | // `oxy tlog verify --json` proved, who cosigned it, or why it failed. No |
| 3 | 0× | // vscode imports, so it is tested with plain Node. |
| 4 | 1× | |
| 5 | 0× | import { TlogInfo } from "./oxy"; |
| 6 | 1× | |
| 7 | 0× | /** 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 | 1× | |
| 10 | export interface TlogLine { | |
| 11 | label: string; | |
| 12 | description?: string; | |
| 13 | tooltip?: string; | |
| 14 | icon: string; | |
| 15 | } | |
| 16 | 1× | |
| 17 | 0× | /** The Trust view's lines for a log check; `ago` words a time (milliseconds since the epoch). */ |
| 18 | 4× | export function tlogLines(check: TlogCheck | undefined, ago: (ms: number) => string): TlogLine[] { |
| 19 | 4× | if (!check) { |
| 20 | 1× | 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 | 1× | } |
| 22 | 4× | if ("error" in check) { |
| 23 | 1× | const first = check.error.trim().split("\n")[0] || "oxy tlog verify failed"; |
| 24 | 1× | return [{ label: "Transparency log NOT verified", description: first, icon: "error", tooltip: check.error.trim() }]; |
| 25 | 1× | } |
| 26 | 2× | const { info } = check; |
| 27 | 2× | const mine = info.entries.length; |
| 28 | 2× | const lines: TlogLine[] = [ |
| 29 | 2× | { |
| 30 | 2× | label: `Transparency log verified up to checkpoint ${info.size}`, |
| 31 | 4× | description: `${info.origin} · ${mine} entr${mine === 1 ? "y" : "ies"} for this repository · ${ago(check.when_ms)}`, |
| 32 | 4× | icon: "verified", |
| 33 | 4× | 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 | 4× | }, |
| 35 | 4× | ]; |
| 36 | 4× | if (info.witnesses.length === 0) { |
| 37 | 1× | 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 | 1× | } else { |
| 39 | 1× | for (const w of info.witnesses) { |
| 40 | 2× | lines.push({ label: `Cosigned by ${w.name}`, description: ago(w.time_ms), icon: "key" }); |
| 41 | 2× | } |
| 42 | 1× | } |
| 43 | 4× | return lines; |
| 44 | 4× | } |