Skip to main content

Module local

Module local 

Source
Expand description

File-based local ledger backend.

Persistent, hash-chained, tamper-evident. Each entry is one JSON line in an append-only file. On open, the file is replayed to reconstruct LCT state and verify the chain integrity (every prev_hash must match the previous entry’s entry_hash).

Suitable for solo dev, team-scoped accountability, regulated/air-gapped environments. Mirrors the design pattern used by Hardbound’s src/ledger/ (TypeScript) but in Rust.

§Format

One JSON object per line, no trailing comma, append-only:

{"index":0,"timestamp":"...","prev_hash":"00...00","entry_hash":"...","event":{"kind":"genesis",...}}
{"index":1,"timestamp":"...","prev_hash":"...","entry_hash":"...","event":{"kind":"mint","lct":{...}}}

§Example

use web4_core::{Lct, EntityType, LocalLedger, Ledger};

let mut ledger = LocalLedger::open("./team.jsonl").unwrap();
let (lct, _kp) = Lct::new(EntityType::Human, None);
ledger.mint(&lct).unwrap();

// Reopen — state is reconstructed from the file
let ledger2 = LocalLedger::open("./team.jsonl").unwrap();
assert_eq!(ledger2.lookup(lct.id).unwrap().map(|l| l.id), Some(lct.id));

Structs§

LocalLedger
File-based ledger backed by an append-only JSON-lines file.