Tearleads

document_content_write_headers API Postgres table

Verified write headers for encrypted document updates.

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

Description

Loro update bytes are stored in the imported documentUpdates table, while this table stores the keying write header that authorizes and describes the ciphertext. The header binds an update to a document, content-key epoch, access manifest, target set, encryption suite, content record id, nonce domain, writer, ciphertext hash, and a metadata hash that commits the update's domain-separated, record-key-derived plaintext HMAC. Replays for the same updateId are accepted only when the computed headerHash matches the stored value, and every write fails unless the stored header equals the signed header verbatim.

Indexes:

  • (organizationId, updateId) lists an organization's write headers, for data usage and for scoping and running an organization purge.
  • headerHash is unique because it content-addresses the write header.
  • (documentId, contentKeyEpoch, contentRecordId) prevents duplicate content record ids for an epoch.
  • (documentId, contentKeyEpoch, nonceDomainHash) prevents nonce-domain reuse for an epoch.

Columns

  • update_iduuid
    • primary key
    • not null

    Primary key matching the live document update id.

  • document_iduuid
    • not null

    Document whose encrypted update this header describes.

  • organization_iduuid
    • not null

    Organization boundary from the verified header.

  • content_key_epochinteger
    • not null

    Document content-key epoch used for the update.

  • content_record_idtext
    • not null

    Client content record id inside the header. For document updates this is unique within (documentId, contentKeyEpoch).

  • nonce_domain_hashtext
    • not null

    Nonce-domain commitment; uniqueness prevents reusing a nonce domain within the same document content-key epoch.

  • header_hashtext
    • not null

    Hash of the canonical write header.

  • headerjsonb
    • not null

    Full canonical write header JSON returned with sync results.

  • authorization_targetsjsonb
    • not null

    Exact verified KEK target references committed by targetHash when the write was accepted. Required for every stored write.

  • created_attimestamp
    • not null
    • default now()

    Server-side insertion timestamp.

Indexes

  • document_content_write_headers_organization_update_idx(organization_id, update_id)
    • document_content_write_headers_header_hash_idx(header_hash)
      • unique
    • document_content_write_headers_content_record_idx(document_id, content_key_epoch, content_record_id)
      • unique
    • document_content_write_headers_nonce_domain_idx(document_id, content_key_epoch, nonce_domain_hash)
      • unique