(runs: AuditableRun[])
| 63 | |
| 64 | /** Build a tamper-evident chain from runs (chronological, oldest first). PURE. */ |
| 65 | export function buildAuditChain(runs: AuditableRun[]): AuditEntry[] { |
| 66 | const ordered = [...runs].sort((a, b) => Date.parse(a.at || '') - Date.parse(b.at || '') || 0); |
| 67 | const entries: AuditEntry[] = []; |
| 68 | let prevHash = AUDIT_GENESIS; |
| 69 | ordered.forEach((r, seq) => { |
| 70 | const base = { |
| 71 | seq, at: r.at || '', scope: r.scope, status: r.status, |
| 72 | filesChanged: Number.isFinite(r.filesChanged) ? r.filesChanged : 0, |
| 73 | prUrl: r.prUrl || '', |
| 74 | verification: (r.verification ?? []).map(v => ({ command: String(v.command), passed: !!v.passed })), |
| 75 | prevHash, |
| 76 | }; |
| 77 | const hash = sha256(entryContent(base)); |
| 78 | entries.push({ ...base, hash }); |
| 79 | prevHash = hash; |
| 80 | }); |
| 81 | return entries; |
| 82 | } |
| 83 | |
| 84 | /** The chain head — what a signature commits to. PURE. */ |
| 85 | export function chainHead(entries: AuditEntry[]): string { |
no test coverage detected