Tearleads

user_device_states API Postgres table

A user's signed device chain (#3503): one row per state, append-only.

Declared in packages/api-shared/src/schema/userDeviceStates.ts

Description

The API verifies every state against the user's registered root identity and the stored predecessor before inserting it, so a stored row is a state the chain rules accepted. Clients still verify what they are served.

Columns

  • user_iduuid
    • not null
    • references users (id)

    The chain position.

  • versionbigint
    • not null

    The chain position.

  • state_hashtext
    • not null

    The chain position.

  • prev_state_hashtext
    • nullable

    The chain position.

  • key_epochbigint
    • not null

    The state's key epoch, and the fingerprint of that epoch's user encryption public key, set on every state of the epoch.

  • user_encryption_key_fingerprinttext
    • not null

    The state's key epoch, and the fingerprint of that epoch's user encryption public key, set on every state of the epoch.

  • user_encryption_public_keytext
    • nullable

    The epoch's public key, on the state that opens the epoch and null on every other.

  • statejsonb
    • not null

    The signed state verbatim, signature included.

  • key_envelopesjsonb
    • nullable

    What only the user's own devices need. Kept on the head alone and cleared when a successor is stored, since a superseded state's envelopes wrap nothing a device should still fetch.

  • sealed_user_keyringjsonb
    • nullable

    What only the user's own devices need. Kept on the head alone and cleared when a successor is stored, since a superseded state's envelopes wrap nothing a device should still fetch.

  • created_attimestamp
    • not null
    • default now()

    Server-side insertion timestamp; not part of the signed state.

Keys and constraints

  • Primary key(user_id, version)
  • Foreign key(user_id)references users (id)

    on delete cascade

  • Check user_device_states_version_range
    "version" >= 1 AND "version" <= 9007199254740991
  • Check user_device_states_key_epoch_range
    "key_epoch" >= 1 AND "key_epoch" <= "version"

Indexes

  • user_device_states_user_state_hash_idx(user_id, state_hash)
    • unique