PersistentAuditTrail

class PersistentAuditTrail(context: Context, retentionProvider: () -> RetentionPolicy, clock: Clock = Clock.SYSTEM, attestationProvider: () -> DeviceAttestationProvider? = null)

Room-backed persistent audit trail with hash chain integrity.

Unlike the file-based AuditTrail, this implementation:

  • Persists the hash chain across app restarts

  • Supports signed audit entries with device attestation

  • Provides integrity verification API

Constructors

Link copied to clipboard
constructor(context: Context, retentionProvider: () -> RetentionPolicy, clock: Clock = Clock.SYSTEM, attestationProvider: () -> DeviceAttestationProvider? = null)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
suspend fun applyRetention()

Apply retention policy to delete old events.

Link copied to clipboard
suspend fun deleteEventsByUserId(userId: String): Int

Delete all events for a specific user.

Link copied to clipboard
suspend fun exportSignedAuditRange(fromTs: Long, toTs: Long): File

Export signed audit events to a file.

Link copied to clipboard

Get all events for a specific user.

Link copied to clipboard
suspend fun getEventsInRange(fromTs: Long, toTs: Long): List<AuditEventEntity>

Get all events in a time range.

Link copied to clipboard

Get statistics about the audit trail.

Link copied to clipboard
suspend fun record(name: String, fields: Map<String, String> = emptyMap(), sign: Boolean = false, userId: String? = null)

Record an audit event.

Link copied to clipboard
suspend fun verifyChainIntegrity(fromTs: Long? = null, toTs: Long? = null): ChainVerificationResult

Verify the integrity of the audit chain.