Tearleads

principal_state_payloads API Postgres table

Encrypted payloads for signed principal state versions.

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

Description

principalStates stores only the signed public header: hashes, signer identity, key epoch, and projection commitments. This table stores the encrypted private payload for that same state. The server does not interpret the plaintext; it only verifies that the ciphertext hash matches both this row and the payloadCiphertextHash signed into the corresponding principalStates row.

There is one payload row per principal state hash. Storing it separately keeps principal-state history queryable by public header fields while allowing clients to retrieve the encrypted policy payload when reconstructing a principal policy bundle.

Indexes:

  • (principalType, principalId, stateHash) is unique because a state hash has exactly one encrypted payload. Replays must provide byte-for-byte matching payload data.

Columns

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

    Surrogate database primary key. Domain lookups use (principalType, principalId, stateHash).

  • principal_typetext
    • not null

    Managed principal kind, currently organization or group. Matches principalStates.principalType.

  • principal_iduuid
    • not null

    Stable id of the managed principal whose encrypted policy payload this is. Matches principalStates.principalId.

  • state_hashtext
    • not null

    Content address of the signed principal state header this payload belongs to. This joins the payload back to principalStates and is the value referenced by manifests and policy bundles.

  • ciphertexttext
    • not null

    The encrypted principal policy payload (AES-256-GCM, the only suite). The server stores and returns it opaquely; clients with the appropriate principal/member key material decrypt it. Its hash is the signed principalStates.payloadCiphertextHash, recomputed on write and by every reader, so the record keeps no copy of it (#2903 P23).

  • created_attimestamp
    • not null
    • default now()

    Server-side insertion timestamp. It is not part of the signed principal state header or payload hash.

Indexes

  • principal_state_payloads_principal_state_idx(principal_type, principal_id, state_hash)
    • unique