MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / buildAuditChain

Function buildAuditChain

src/cli/maintain-audit.ts:65–82  ·  view source on GitHub ↗
(runs: AuditableRun[])

Source from the content-addressed store, hash-verified

63
64/** Build a tamper-evident chain from runs (chronological, oldest first). PURE. */
65export 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. */
85export function chainHead(entries: AuditEntry[]): string {

Callers 3

historyHeadFunction · 0.85
buildSignedAuditLogFunction · 0.85

Calls 3

sha256Function · 0.85
entryContentFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected