principal_history_stages Client SQLite table
Provisional, locally authenticated verification work; never an app checkpoint. scopeId, touchedAt, and rootHash are retention hints, never authenticated recovery state.
Declared in packages/client-sdk/src/data/sqlite/schema/principalHistoryStageSchema.ts
Columns
idtext- primary key
- not null
Hex SHA-256 of the organization, the expected head (principal, version, key epoch, state hash, key fingerprint), and the history context. One stage per head being verified.
organization_idtext- not null
Organization the principal history belongs to.
scope_idtext- not null
Evidence scope of the principal history the stage belongs to, as in
principal_history_prefixes; an eviction hint.identity_bundle_formatinteger- not null
- default 1
Format of the principal identity data in this row. Always
1; restoring a backup row with any other value is refused.current_jsontext- not null
JSON of the head's current artifacts:
currentState,currentPayload,currentProjection,currentGrants, andcurrentMemberEnvelopes. A public history stores the canonical JSON of the newest cited authority group head, ornull.after_versioninteger- not null
Policy version verified through; the next history page is requested after it. A complete stage holds the head's version minus one.
completeinteger- not null
Whether the history is verified through the head.
touched_atinteger- not null
Epoch milliseconds when a writer last saved or used the stage; an eviction hint.
progresstext- not null
Sealed verifier progress,
v3.<iv>.<ciphertext>with base64 parts: AES-GCM under a key derived from the local key, bound to the row's id, organization, head,afterVersion,complete, andcurrentJson. A save fails when another writer replaced it after the load.root_hashtext- nullable
Hex root hash of the history index the stage has verified; the stage keeps that
principal_history_nodesrow live. A disposable liveness hint; null holds no reference.
Indexes
principal_history_stages_key_fingerprint_idx(json_extract(CASE WHEN json_valid("current_json") THEN "current_json" END, '$.currentState.keyFingerprint'), complete, "after_version" desc)principal_history_stages_organization_idx(organization_id)principal_history_stages_scope_idx(scope_id, organization_id, complete, "after_version" desc, "touched_at" desc, id)principal_history_stages_incomplete_idx(scope_id, organization_id, complete, "touched_at" desc, id)
DDL
The statements the client runs to create this table and its indexes.
CREATE TABLE IF NOT EXISTS "principal_history_stages" (
"id" TEXT NOT NULL PRIMARY KEY,
"organization_id" TEXT NOT NULL,
"scope_id" TEXT NOT NULL,
"identity_bundle_format" INTEGER NOT NULL DEFAULT 1,
"current_json" TEXT NOT NULL,
"after_version" INTEGER NOT NULL,
"complete" INTEGER NOT NULL,
"touched_at" INTEGER NOT NULL,
"progress" TEXT NOT NULL,
"root_hash" TEXT
);
CREATE INDEX IF NOT EXISTS "principal_history_stages_key_fingerprint_idx" ON "principal_history_stages" (json_extract(CASE WHEN json_valid("current_json") THEN "current_json" END, '$.currentState.keyFingerprint'), "complete", "after_version" desc);
CREATE INDEX IF NOT EXISTS "principal_history_stages_organization_idx" ON "principal_history_stages" ("organization_id");
CREATE INDEX IF NOT EXISTS "principal_history_stages_scope_idx" ON "principal_history_stages" ("scope_id", "organization_id", "complete", "after_version" desc, "touched_at" desc, "id");
CREATE INDEX IF NOT EXISTS "principal_history_stages_incomplete_idx" ON "principal_history_stages" ("scope_id", "organization_id", "complete", "touched_at" desc, "id");