Skip to main content

Trailproof Class

The Trailproof class is the main entry point. It manages the hash chain, store, and optional signer.

Constructor

emit()

Record a new event in the audit trail.
Returns: TrailEvent — the complete event with auto-generated fields. Throws: ValidationError if required fields are missing or empty. Behavior:
  • Auto-generates event_id (UUID v4) and timestamp (ISO-8601 UTC)
  • Computes hash using the hash chain engine
  • Sets prev_hash to the previous event’s hash (or genesis hash for the first event)
  • If a signing key is configured, computes and sets signature
  • Appends the event to the store

query()

Search events with filters and pagination.
Returns: QueryResult { events, next_cursor }. All filters are optional. No filters returns all events up to limit. Filters use exact match except from_time and to_time which are range filters.

verify()

Walk the hash chain and check every event’s hash.
Returns: VerifyResult { intact, total, broken }. Empty chain returns { intact: true, total: 0, broken: [] }.
Verification does not throw on broken chains — it returns the result. Check result.intact to determine if the chain is valid.

get_trace() / getTrace()

Get all events for a specific trace ID, ordered by timestamp.
Returns: List of TrailEvent objects matching the trace ID, ordered by timestamp.

flush()

Ensure all buffered events are persisted to disk.
No-op for the memory store. For the JSONL store, ensures all buffered writes are flushed to disk.