(runs: AuditableRun[], opts: { exportedAt: string; key?: string })
| 123 | |
| 124 | /** Assemble the exportable log, signing the head when a key is provided. PURE (pass `exportedAt`). */ |
| 125 | export function buildSignedAuditLog(runs: AuditableRun[], opts: { exportedAt: string; key?: string }): SignedAuditLog { |
| 126 | const entries = buildAuditChain(runs); |
| 127 | const head = chainHead(entries); |
| 128 | const base: SignedAuditLog = { |
| 129 | kind: 'qodex-maintain-audit', |
| 130 | version: MAINTAIN_AUDIT_VERSION, |
| 131 | exportedAt: opts.exportedAt, |
| 132 | count: entries.length, |
| 133 | head, |
| 134 | entries, |
| 135 | algo: 'sha256-chain', |
| 136 | }; |
| 137 | if (opts.key) { |
| 138 | return { ...base, algo: 'sha256-chain+hmac-sha256', keyId: keyIdFor(opts.key), signature: signChainHead(head, opts.key) }; |
| 139 | } |
| 140 | return base; |
| 141 | } |
| 142 | |
| 143 | /** Serialize to pretty JSON. PURE. */ |
| 144 | export function serializeAuditLog(log: SignedAuditLog): string { |
no test coverage detected