Understanding Calimero Contexts
One of the key components of Calimero's architecture is the concept of contexts. In this article, we will break down what contexts are, how they work, and why they are essential for secure peer-to-peer communication and data ownership.
What are Contexts?
Contexts in Calimero Network are instances of deployed applications where members share a synchronized state. Each context is identified by a unique 32-byte key generated at creation. This key is crucial for ensuring that each context remains distinct and avoids collision with others.
Context Lifecycle
The lifecycle of a context includes several stages:
- 1. Creation: When a context is created, it is assigned a unique key, and the creator becomes its initial member.
- 2. Membership: The creator can invite other members to join. Members can leave at any time.
- 3. State Mutations: Any changes to the context's state by a member are broadcasted to all other members, ensuring synchronization.
- 4. Deletion: A context can only be effectively deleted when all members leave it.
Context State
The state of a context is stored as a key-value pair, where the key is a 32-byte identifier, and the value is a byte array. This structure ensures that data within the context is efficiently managed and synchronized across all members.
State Mutations
State mutations refer to changes in the context's state. These are represented as transactions that define which application method to call and what inputs to provide. All members execute these transactions on their local copies of the state to ensure consistency.
Context Membership
- Invitations: Members can invite others to join a context by sharing the context ID. The invitee can then request and receive all necessary transactions to catch up with the current state.
- Leaving: Members can leave a context by deleting it from their local storage. This action stops them from tracking the context's state but doesn't affect other members.
Encryption and Security
Currently, messages within contexts are sent in plaintext, but Calimero is working on implementing encryption using the double-ratchet algorithm. This will provide forward secrecy and post-compromise security, significantly enhancing the privacy and security of communications.
Contexts are a essential part of the Calimero Network, providing a secure, synchronized, and flexible environment for peer-to-peer SSApps. They ensure that data remains under user control, enhancing privacy and ownership in the digital space. For more detailed technical documentation, visit our GitHub repository.