WeaveDocs
Weave Compliance

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.

Note

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.rs
  • AIOperation — libs/weave-compliance/src/compliance.rs
  • ApiDocumentation — libs/weave-compliance/src/docs.rs
  • AuditEvent — libs/weave-compliance/src/audit.rs
  • AuditEventId — libs/weave-compliance/src/audit.rs
  • AuditReport — libs/weave-compliance/src/audit.rs
  • AuditReportCriteria — libs/weave-compliance/src/audit.rs
  • BiasAnalysis — libs/weave-compliance/src/ethics.rs
  • DataAsset — libs/weave-compliance/src/governance.rs
  • DataGovernanceResult — libs/weave-compliance/src/governance.rs
  • DataOperation — libs/weave-compliance/src/lib.rs
  • DataOperationRecord — 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(())
}