Tearleads

principal_member_envelopes API Postgres table

Wrapped principal key material for the current direct members of a principal.

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

Description

Principal state defines who the direct members are, and principalMembershipProjection makes that membership queryable. This table stores the encrypted key envelopes that let each direct member open the managed principal's current key material. User members use their row in users as the recipient key source; group members use the key of their current principalStates row.

Envelopes are immutable and scoped to an exact stateHash. Their canonical exact root is signed into that state. Initial insertion verifies that every direct member is covered exactly once and that each submitted fingerprint matches the expected recipient key; exact retries are idempotent.

Indexes:

  • (principalType, principalId, stateHash, userId) is unique so one state has at most one envelope per direct member. It also serves loading current envelopes after the current state hash is resolved.

Columns

  • iduuid
    • primary key
    • not null
    • default gen_random_uuid()

    Surrogate database primary key. Domain identity is (principalType, principalId, stateHash, userId).

  • principal_typetext
    • not null

    Managed principal kind whose key material is wrapped, currently organization or group.

  • principal_iduuid
    • not null

    Stable id of the managed principal whose key is being distributed.

  • state_hashtext
    • not null

    Current principal state hash these envelopes target. The row set must match the direct members projected for this state.

  • epochbigint
    • not null

    Principal key epoch being wrapped. This is the owning principal's epoch, not the member recipient's epoch.

  • user_iduuid
    • not null

    Stable id of the direct member recipient, always a user.

  • user_device_state_hashtext
    • not null

    The member's signed device-chain state (userDeviceStates.stateHash) whose user encryption key this envelope encrypts to.

  • user_key_epochbigint
    • not null

    User key epoch of that key at the cited state.

  • member_key_fingerprinttext
    • not null

    Fingerprint of the member's user encryption key, from the current state of their user_device_states chain.

  • kem_cipher_texttext
    • not null

    KEM ciphertext/capsule produced while encrypting to the member recipient key.

  • wrapped_keytext
    • not null

    Encrypted principal key material for the member recipient.

  • created_attimestamp
    • not null
    • default now()

    Server-side insertion timestamp. The row timestamp is not signed, but every cryptographic envelope field is.

Keys and constraints

  • Check principal_member_envelopes_epoch_range
    "epoch" >= 1 AND "epoch" <= 9007199254740991 AND "epoch" = CAST("epoch" AS BIGINT)
  • Check principal_member_envelopes_user_key_epoch_range
    "user_key_epoch" >= 1 AND "user_key_epoch" <= 9007199254740991 AND "user_key_epoch" = CAST("user_key_epoch" AS BIGINT)

Indexes

  • principal_member_envelopes_state_member_idx(principal_type, principal_id, state_hash, user_id)
    • unique