(log: SignedAuditLog, key?: string)
| 193 | * and (when a key is available) the HMAC signature. PURE. `ok` = everything checkable passed. |
| 194 | */ |
| 195 | export function verifyAuditLog(log: SignedAuditLog, key?: string): AuditVerifyResult { |
| 196 | const entries = Array.isArray(log?.entries) ? log.entries : []; |
| 197 | const chain = verifyAuditChain(entries); |
| 198 | const recomputedHead = chainHead(entries); |
| 199 | const headMatches = recomputedHead === log?.head; |
| 200 | const signaturePresent = !!log?.signature; |
| 201 | let signatureValid: boolean | undefined; |
| 202 | if (signaturePresent && key) signatureValid = verifyChainSignature(log.head, log.signature!, key); |
| 203 | const ok = chain.valid && headMatches && (!signaturePresent || signatureValid === true); |
| 204 | return { |
| 205 | ok, |
| 206 | chainValid: chain.valid, |
| 207 | brokenAt: chain.brokenAt, |
| 208 | reason: chain.reason, |
| 209 | signaturePresent, |
| 210 | signatureValid, |
| 211 | headMatches, |
| 212 | count: entries.length, |
| 213 | }; |
| 214 | } |
no test coverage detected