A Rust implementation of the KERI (Key Event Receipt Infrastructure) protocol for decentralized identity management. Supports identity creation, key rotation, event verification, and witness-backed integrity in direct mode communication.
IMPORTANT: affinidi-keri-rs crates are provided "as is" without any warranties or guarantees, and by using this framework, users agree to assume all risks associated with its deployment and use including implementing security and privacy measures in their applications. Affinidi assumes no liability for any issues arising from the use or modification of the project.
The workspace contains four crates that build on each other in layers:
┌─────────────────────────────────────────────────────┐
│ affinidi-keri │
│ High-level identity management & direct mode │
└────────┬────────────────────┬───────────────────────┘
│ │
┌────────▼─────────┐ ┌──────▼───────────┐
│ affinidi-keri-db│ │affinidi-keri-core│
│ Storage (LMDB) │ │ Protocol logic │
└────────┬─────────┘ └───────┬──────────┘
│ │
└────────┬───────────┘
│
┌──────────▼────────────┐
│ affinidi-keri-crypto │
│ Cryptographic prims │
└───────────────────────┘
| Crate | Description |
|---|---|
| affinidi-keri-crypto | Cryptographic primitives — signing (Ed25519, secp256k1, P-256), digests (Blake2/3, SHA2/3), key derivation (Argon2), and verification. CESR encoding is provided by affinidi-cesr |
| affinidi-keri-core | Core KERI protocol — event structures (inception, rotation, interaction, delegation, receipts), KEL verification, serialization, and parsing |
| affinidi-keri-db | Storage layer — LMDB-backed persistence for events, key event logs, signatures, witness receipts, key state, and escrow |
| affinidi-keri | High-level identity management — Hab (single identifier), Habery (multi-identifier registry), direct mode message processing, Judge (duplicity detection), and configuration |
- Rust 1.90.0+ (2024 Edition)
git clone https://github.com/affinidi/affinidi-keri-rs.git
cd affinidi-keri-rs
# Build all crates
cargo build
# Build release version
cargo build --release# Run all tests
cargo test
# Run a specific integration test
cargo test --package affinidi-keri witness_full_lifecycle
# Run tests with output
cargo test -- --nocaptureThe integration tests in crates/affinidi-keri/tests/witness_integration.rs
demonstrate the full KERI lifecycle and serve as runnable examples.
This test walks through the complete KERI workflow with two witnesses:
cargo test --package affinidi-keri test_witness_full_lifecycle -- --nocaptureWhat it demonstrates:
-
Create witnesses — Two non-transferable witness identifiers are created with deterministic key derivation:
let w1_config = InceptionConfig::builder() .transferable(false) .salt(vec![0x10u8; 16]) .build(); let (w1, _) = Hab::incept("witness1", &w1_config, &w1_store).unwrap();
-
Create controller with witnesses — A transferable controller identifier is created with a backer threshold of 2 and both witnesses as backers:
let ctrl_config = InceptionConfig::builder() .salt(vec![0x30u8; 16]) .backer_threshold(2) .backers(vec![w1_prefix, w2_prefix]) .build(); let (mut ctrl, icp_msg) = Hab::incept("controller", &ctrl_config, &ctrl_store).unwrap();
-
Inception with witness receipts — The inception event is receipted by both witnesses and verified by a third-party verifier:
let icp_full = compose_witnessed_message(&icp_msg, &[&w1, &w2]); let result = direct::process_message(&icp_full, &verifier_store, &mut kevers).unwrap();
-
Key rotation — The controller rotates its signing keys, with witnesses receipting the rotation event:
let rot_msg = ctrl.rotate(&RotationConfig::default(), &ctrl_store).unwrap();
-
Interaction (data anchoring) — External data is anchored to the identifier via an interaction event:
let anchor = serde_json::json!({"d": "ETestDigest_____________________________"}); let ixn_msg = ctrl.interact(&[anchor], &ctrl_store).unwrap();
-
KEL verification — The full Key Event Log is retrieved and verified in the verifier's store.
cargo test --package affinidi-keri test_witness_receipt_message_stored -- --nocaptureDemonstrates a witness generating and storing a receipt message for a controller's inception event, verifying the receipt is persisted and parseable.
cargo run -p affinidi-keri --example demo_judgeDemonstrates the KERI Judge role that enforces the first-seen policy and
detects duplicity — when a controller publishes two different valid events
at the same (prefix, sn).
What it demonstrates:
-
The problem — Two separate verifiers each accept a different interaction event at sn=1 from the same controller. Neither detects the conflict because each only sees its own stream of events.
-
The solution — A Judge remembers the first valid event at each
(prefix, sn). When a second, conflicting event arrives:- The Judge verifies it is cryptographically valid (not just corrupt)
- Records
DuplicityEvidencewith both SAIDs and event bytes - Flags the prefix as
Duplicitousin its verdict - Stores evidence in the Duplicitous Event Log (DEL)
-
Idempotent replay — Replaying the same event returns
DuplicateAcceptedwithout triggering duplicity. -
Verdict transitions —
Unknown→Trusted(after first valid event) →Duplicitous(after conflicting event detected).
cargo run -p affinidi-keri --example demo_witnessDemonstrates the full witness lifecycle: creating non-transferable witness identifiers, receipting controller events, and verifying that a threshold of witness receipts is required for event acceptance.
cargo test --package affinidi-keri test_inception_without_witnesses_still_works -- --nocaptureDemonstrates creating and verifying identifiers without any witness infrastructure (backer threshold of 0), including inception and rotation.
If you face any issues or have suggestions, please don't hesitate to contact us using this link.
If you have a technical issue with the Affinidi KERI-RS codebase, you can also create an issue directly in GitHub.
-
Ensure the bug was not already reported by searching on GitHub under Issues.
-
If you're unable to find an open issue addressing the problem, open a new one. Be sure to include a title and clear description, as much relevant information as possible, and a code sample or an executable test case demonstrating the expected behaviour that is not occurring.
Want to contribute?
Head over to our CONTRIBUTING guidelines.