Skip to content

Latest commit

 

History

History
46 lines (35 loc) · 2.63 KB

data-storage.md

File metadata and controls

46 lines (35 loc) · 2.63 KB

Data Storage and Retrieval

Profiles messages and identities are published and stored in a PostgreSQL database. The database is accessed through a REST API and a websocket API. The REST API is used for retrieving data and the websocket API is used for subscribing to data changes.

Participants

Participants are stored in the chat_participants table. The table has the following columns:

create table
  public.chat_participants (
    id bigint generated by default as identity,
    created_at timestamp with time zone not null default now(),
    profile text not null,
    payload jsonb null,
    constraint chat_participants_pkey primary key (id),
    constraint chat_participants_profile_key unique (profile),
    constraint chat_participants_profile_check check ((lower(profile) = profile))
  ) tablespace pg_default;

Each profile publishes its securely generated identity containing its public key. The identity is stored in the chat_participants table. The identity is used to negotiate a shared secret between two profiles. The shared secret is used to encrypt messages between the two profiles.

Messages

Messages are stored in the chat_topics table. The table has the following columns:

create table
  public.chat_topics (
    id bigint generated by default as identity,
    created_at timestamp with time zone not null default now(),
    from_profile text not null,
    to_profile text not null,
    payload jsonb null,
    constraint chats_pkey primary key (id),
    constraint chats_from_profile_check check ((lower(from_profile) = from_profile)),
    constraint chats_to_profile_check check ((lower(to_profile) = to_profile))
  ) tablespace pg_default;

A topic is a data broadcasted and exchanged between two profiles. A topic is identified by the from_profile and to_profile columns. The from_profile column is the profile that published the topic. The to_profile column is the profile that received the topic. The payload column contains the topic data.

The topic data may indicate new one-time and signed keys to provide forward secracy and deniability when establishing a shared secret between two profiles. The topic data may also contain an encrypted message.

Once a topic is received by a recipient profile, the recipient profile will acknowledge the topic which will delete the topic from the chat_topics table. The topic data may be stored in the database for a short period of time to allow the recipient profile to retrieve the topic data if the recipient profile was offline when the topic was published. After it is retrieved, the topic data cannot be decrypted by recipient and thus deleted from the databse.