Tearleads

principal_states API Postgres table

Signed state history for managed recipient principals.

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

Description

Public headers are joined to payloads, membership, and epoch-key rows by (principalType, principalId, stateHash). User keys live in users.

Indexes:

  • (principalType, principalId, version) is unique so a version cannot be reused for conflicting state. It also serves loading a principal's state history and current state.
  • (principalType, principalId, stateHash) is unique because state hashes are the content-addressed references used by the rest of the access system.

Columns

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

    Surrogate row id; domain identity is the principal and stateHash.

  • principal_typetext
    • not null

    Managed principal kind, currently organization or group.

  • principal_iduuid
    • not null

    The stable id of the organization/group whose policy this state describes.

  • versionbigint
    • not null

    Monotonic signed version for this principal. Version 1 must have prevStateHash = null; later versions must point to the previous current state's hash.

  • prev_state_hashtext
    • nullable

    Hash-chain pointer to the previous signed state header, or null for the initial state.

  • key_epochbigint
    • not null

    Principal wrapping-key epoch referenced by this state. It may stay unchanged with the same key material. Genesis uses 1; rotation, membership shrink and grant removal require exactly one new epoch.

  • encapsulation_public_keytext
    • not null

    Public KEM key for the principal at keyEpoch. Members encrypt/rewrap principal key material to this public key.

  • key_fingerprinttext
    • not null

    Fingerprint of encapsulationPublicKey; verified before storage. The current state's key is the recipient key; the transition rule (a key change requires a new epoch and a new epoch requires new key material) on this linear chain keeps one key per epoch.

  • membership_modetext
    • not null

    How direct members are represented. Only projection is currently supported.

  • membership_roottext
    • not null

    Canonical hash of the normalized direct member list that was signed by the principal state.

  • member_envelopes_roottext
    • not null

    Canonical hash of the exact member key-envelope set signed by the principal state.

  • projection_roottext
    • not null

    Canonical hash of the normalized query projection entries, including member roles. It must match principalMembershipProjection rows for this stateHash.

  • grant_roottext
    • not null

    Canonical hash of the state's direct-container grant set, signed into the header. It must match containerGrants.

  • payload_ciphertext_hashtext
    • not null

    Hash of the encrypted policy payload ciphertext in principalStatePayloads; binds the private payload to the signed header.

  • member_countinteger
    • not null

    Number of projected members signed into this state. Used as a cheap consistency check against principalMembershipProjection.

  • grant_countinteger
    • not null

    Number of direct-container grants signed into this state.

  • container_grantsjsonb
    • not null

    The state's complete direct-container grant set, normalized and sorted by container id. Like the membership projection it is unsigned storage; stored-policy verification recomputes grantRoot from it. It is only ever read with its own state, never by container, so it lives on the state row rather than in a projection table.

  • external_authorityjsonb
    • nullable

    Signed head of the external group policy whose admin signed this state, when the signer is not a direct admin of the principal; organization-scoped group policies cite the reserved Admins group. null when a direct admin signed.

  • state_hashtext
    • not null

    Hash of the normalized unsigned state header. This excludes signature and is the stable content address used by manifests, payload rows, projection rows, and epoch-key rows.

  • signed_attimestamp
    • not null

    Client-supplied timestamp included in the signed header.

  • signer_device_idtext
    • not null

    Signer device name (device:<deviceId>:<stateHash> for device-signed states, or a non-device name for root-signed states).

  • signer_user_iduuid
    • not null

    User who signed this state. Initial states require this user to be an admin in the new projection; successor states require the user to have been an admin in the previous projection.

  • signer_user_key_fingerprinttext
    • not null

    Signing key fingerprint for signerUserId (root signing key or active device signing key matching signerDeviceId).

  • signaturetext
    • not null

    Signature over the normalized unsigned state header.

  • created_attimestamp
    • not null
    • default now()

    Server-side insertion timestamp; not part of the signed header or stateHash.

Keys and constraints

  • Check principal_states_key_epoch_range
    "key_epoch" >= 1 AND "key_epoch" <= 9007199254740991 AND "key_epoch" = CAST("key_epoch" AS BIGINT)
  • Check principal_states_version_range
    "version" >= 1 AND "version" <= 9007199254740991

Indexes

  • principal_states_principal_version_idx(principal_type, principal_id, version)
    • unique
  • principal_states_principal_state_hash_idx(principal_type, principal_id, state_hash)
    • unique