decentrl.
Event Store

Querying Events

Encrypted tags enable querying stored events without exposing any metadata to the mediator.

Tag Templates

Each event type declares tag templates that enable efficient querying:

chat.create    → tags: ["chat", "chat.${id}", "participant.${participants[0]}"]
chat.message   → tags: ["chat.${chatId}"]
chat.reaction  → tags: ["chat.${chatId}"]
chat.read      → tags: ["readmarker", "readmarker.${chatId}"]
chat.presence  → tags: []   // no tags = ephemeral

Template variables like ${chatId} are interpolated from the event data at publish time. The resulting tag strings are then encrypted before being stored on the mediator.

How Encrypted Tags Work

An encrypted tag is produced by signing the plaintext tag string with the identity's Ed25519 signing key:

encrypted_tag = Ed25519_sign("chat.abc", signing_private_key)

This is deterministic — the same key and tag string always produce the same output. This allows exact-match lookups. But without the private key, the tag is an opaque blob.

When Alice wants to query "all messages in chat abc":

  1. She computes Ed25519_sign("chat.abc", her_signing_key)
  2. She sends that as a tag filter to her mediator
  3. The mediator performs an exact-match lookup on opaque byte strings
  4. The mediator returns matching encrypted events
  5. Alice decrypts them with her storage key

The mediator has no idea what "chat.abc" means. It just matches blobs.

State Reconstruction

On application startup, the client rebuilds its entire state from the event stream:

1. Query all stored events from own mediator (using QUERY_EVENTS with tag filters)
2. Decrypt each event with storage key
3. Apply events in timestamp order through the reducers
4. State is now fully reconstructed — no backend database needed

This is pure event sourcing: the event log is the source of truth, and the current state is a derived projection. There is no server-side database. There is no API to query "current state." The client reconstructs everything locally from its encrypted event stream.