A collection manager in KERI's Python implementation (KERIpy/KERIA) that organizes and manages multiple Hab (Habitat) keystores, where each Hab stores the cryptographic key material and associated data for a single AID (Autonomic Identifier).
Related Concepts
No related concepts available
Comprehensive Explanation
habery
Implementation Overview
Habery is a Python-based data structure and collection manager implemented in KERIpy and KERIA that serves as the organizational layer for managing multiple Hab (Habitat) instances. Each Hab functions as a keystore for a single AID (Autonomic Identifier), and the Habery provides the infrastructure to coordinate access, storage, and operations across multiple identifiers within a single KERI agent or controller instance.
The term "Hab" derives from "Habitat" - conceptually representing the environment where multi-signature schemes and AIDs are linked and managed. The Habery extends this metaphor to represent the ecosystem containing multiple such habitats.
Relationship to KERI Protocol
While the KERI protocol itself is implementation-agnostic and defines the cryptographic and event-based mechanisms for self-certifying identifiers, the Habery represents a specific architectural pattern in the Python reference implementation for managing the practical storage and operational requirements of KERI identifiers at scale.
The Habery does not appear in the core KERI protocol specifications but rather represents an implementation-level abstraction that enables:
Implementation Notes
Critical Implementation Details
LMDB Configuration
Database location: Each Hab's LMDB database should be stored in a dedicated directory
File permissions: Ensure proper file system permissions to prevent unauthorized access
Backup strategy: LMDB supports hot backups; implement regular backup schedules
Transaction management: Use LMDB transactions for atomic operations across multiple Habs
Habery Lifecycle Management
Initialization: Habery must be initialized with proper salt and passcode before creating Habs
Hab creation: Each new AID requires explicit Hab allocation within the Habery
Hab removal: Implement secure key material deletion when removing Habs
Migration: Plan for Habery migration strategies when upgrading KERI implementations
Multi-Tenant Considerations
Resource isolation: Implement proper resource limits per Hab to prevent denial-of-service
Access control: Enforce authentication before allowing Hab access
Audit logging: Log all Hab access and key operations for security monitoring
Rate limiting: Implement rate limits on Hab operations to prevent abuse
Performance Optimization
Connection pooling: Reuse LMDB connections across Hab operations
Caching: Cache frequently accessed key state data in memory
Lazy loading: Load Hab data only when needed to minimize memory footprint
Batch operations: Group multiple Hab operations into single transactions when possible
Python object model: Implemented as Python data structures (objects) that provide programmatic access to identifier operations
Storage Technology: LMDB
The choice of LMDB as the underlying storage engine provides several critical capabilities:
Memory-mapped file access: Extremely fast read operations through direct memory mapping
ACID transactions: Ensures consistency even in the face of crashes or concurrent access
Compact storage: Efficient B-tree structure minimizes disk space usage
Zero-copy reads: Data can be accessed directly from memory-mapped regions without copying
Multi-version concurrency control (MVCC): Readers never block writers, writers never block readers
This storage architecture is particularly well-suited for KERI's requirements:
Append-only KEL storage: LMDB's B-tree structure efficiently handles sequential writes
Fast signature verification: Quick access to public keys and key state data
Event log queries: Efficient retrieval of specific events or event ranges
Witness receipt storage: Compact storage of receipts and KERL data
Multi-AID Support
A critical architectural evolution documented in the 2022 KERI Community Meeting notes shows the Habery architecture enabling multiple AIDs per KERIpy instance:
November 29, 2022 Meeting Report:
"Habery changes propagated through command line utilities and agent. Architecture split: separated shared resources from AID-specific code. Support for multiple AIDs per KERIpy instance."
This architectural split represents a fundamental shift from single-identifier agents to multi-tenant systems, enabling:
Shared witness pools: Multiple identifiers can use the same witness infrastructure
Common network resources: Single network stack serves multiple identifiers
Unified agent interface: One agent process manages multiple identifiers
Resource efficiency: Reduced memory and process overhead compared to per-identifier agents
Integration with KERI Command Line Interface (KLI)
The Habery architecture directly supports the KLI (KERI Command Line Interface), as documented in the November 1, 2022 meeting:
"KLI now supports new Habery architecture"
This integration means that command-line operations can:
Reference specific Habs by name or identifier
Perform operations across multiple identifiers in a single command sequence
Manage keystore lifecycle (creation, backup, recovery) at the Habery level
"Uses the multisig-shell.sh interactive tool to configure the group multisig identifier. Adds local participant aliases and remote participant identifiers."
This workflow requires:
Each GAR maintains a local single-sig Hab
The Habery coordinates the multi-sig inception across participants
The resulting group identifier is stored in each participant's Habery
Subsequent operations reference both local and group Habs
"Import of DID Assets for Remote AIDs: Future functionality will enable importing CESR streams for remote AIDs, allowing the local dynamic DID asset generation system to securely handle external identifiers."
This suggests Habery evolution toward:
Remote Hab caching: Storing verified KELs for remote identifiers
Trust boundary management: Clear separation between local and remote Habs
Verification caching: Storing verification results for remote identifiers
Enhanced Access Control
"Strict Dynamic DID Asset Hosting for Remote AIDs: Plans to implement access controls on HTTP DID asset generation endpoints, restricting dynamic generation to only an explicitly allowed set of AIDs."
This implies Habery-level access control lists:
Allowlists: Explicit lists of AIDs authorized for dynamic generation
Role-based access: Different access levels for different Hab operations
Audit trails: Comprehensive logging of Hab access patterns
Implementation Notes
The Habery represents a pragmatic implementation choice in the Python KERI ecosystem that balances:
Performance: LMDB provides excellent performance for KERI's access patterns
Simplicity: Python object model makes Habery easy to use and extend
Security: Strong isolation between identifiers prevents cross-contamination
While the Habery is specific to KERIpy/KERIA, the architectural pattern it represents - separating shared infrastructure from identifier-specific storage - is likely to appear in other KERI implementations as they mature and support multi-identifier scenarios.
The Habery is not a protocol-level concept but rather an implementation best practice that has emerged from the reference implementation's evolution toward production-ready, multi-tenant agent architectures.
Key isolation: Never expose private keys outside their Hab context
Secure deletion: Implement cryptographic key zeroization when removing Habs
Access logging: Maintain comprehensive audit logs of all Hab access
Principle of least privilege: Grant minimal necessary permissions for Hab operations