Audit
Hash-chained audit trails for Weave Compliance — append-only event logs with cryptographic evidence IDs.
Purpose
Audit trails, regulatory reports, ethics checks, governance, evidence IDs, and compliance documentation.
This page follows the real source shape for Weave Compliance and explains the workflow a developer is likely to use first.
Developer workflow
Start from the smallest constructor or builder, perform one meaningful operation, inspect the returned state, then add the relevant policy, storage, or network integration. The examples below should be expanded whenever the crate API changes.
Audit entries are append-only and hash-chained. Once an entry is committed, modifying it breaks the chain and is detectable on any subsequent verification. Treat the audit log as evidence, not as mutable state.
Primary types to know
AIDecision— libs/weave-compliance/src/ethics.rsAIOperation— libs/weave-compliance/src/compliance.rsApiDocumentation— libs/weave-compliance/src/docs.rsAuditEvent— libs/weave-compliance/src/audit.rsAuditEventId— libs/weave-compliance/src/audit.rsAuditReport— libs/weave-compliance/src/audit.rsAuditReportCriteria— libs/weave-compliance/src/audit.rsBiasAnalysis— libs/weave-compliance/src/ethics.rsDataAsset— libs/weave-compliance/src/governance.rsDataGovernanceResult— libs/weave-compliance/src/governance.rsDataOperation— libs/weave-compliance/src/lib.rsDataOperationRecord— libs/weave-compliance/src/governance.rs
Example shape
use chrono::Utc;
use weave_compliance::audit::{
AuditEvent, AuditReportCriteria, AuditTrailManager, ProductionAuditTrailManager,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// ProductionAuditTrailManager is the in-memory AuditTrailManager. Replace
// with a persistent backend (e.g. Locus-backed) in production.
let manager = ProductionAuditTrailManager::new();
let event = AuditEvent {
event_type: "agent.start".into(),
actor: "did:l1fe:agent:audit-demo".into(),
target: "weave-compliance".into(),
details: serde_json::json!({"version": "0.1.0"}),
timestamp: Utc::now(),
compliance_context: Some("SOX_Section_404".into()),
};
let event_id = manager.record_audit_event(event).await?;
let report = manager
.generate_audit_report(AuditReportCriteria {
requester: "did:l1fe:agent:auditor".into(),
})
.await?;
println!(
"event_id={} events_analyzed={} integrity_verified={}",
event_id.0, report.events_analyzed, report.integrity_verified,
);
Ok(())
}