principal_policy_bundles Client SQLite table
Every verified policy bundle kept per managed principal: the one current head, and older bundles retained for exact-reference verification and epoch key unwrapping. Promotion flips isCurrent instead of copying bundles.
Declared in packages/client-sdk/src/data/sqlite/schema/principalPolicySchema.ts
Columns
principal_typetext- not null
Managed principal kind:
groupororganization.principal_idtext- not null
Managed principal id.
state_hashtext- not null
Hex SHA-256 state hash of the bundle's head state.
is_currentinteger- not null
Whether the bundle is the principal's current head; at most one row per principal is current, and older bundles stay as retained rows.
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_state_jsontext- not null
JSON of the head's signed policy state, including
version,keyEpoch,keyFingerprint,stateHash, andsignature. The key-fingerprint index reads$.keyFingerprint.current_payload_jsontext- not null
JSON of the head's encrypted payload,
{ ciphertext }, which readers check against the state's signedpayloadCiphertextHash.current_projection_jsontext- not null
JSON array of the head's members:
userId,role(memberoradmin), andidentityBundleFingerprint.current_grants_jsontext- not null
current_member_envelopes_jsontext- not null
JSON of the head's member envelopes: the principal secret key wrapped to each member key for the head's key epoch.
previous_states_jsontext- not null
JSON array of earlier state chain entries stored with the bundle, each with
state,projection, andgrants; may be empty.updated_attext- not null
ISO-8601 time the bundle was stored or last made current. Key candidate lookups take the newest by it.
Keys and constraints
- Primary key
(principal_type, principal_id, state_hash)
Indexes
principal_policy_bundles_current_idx(principal_type, principal_id)- unique
- partial:
where "is_current" = 1
principal_policy_bundles_key_fingerprint_idx(json_extract(CASE WHEN json_valid("current_state_json") THEN "current_state_json" END, '$.keyFingerprint'), is_current, "updated_at" desc)
DDL
The statements the client runs to create this table and its indexes.
CREATE TABLE IF NOT EXISTS "principal_policy_bundles" (
"principal_type" TEXT NOT NULL,
"principal_id" TEXT NOT NULL,
"state_hash" TEXT NOT NULL,
"is_current" INTEGER NOT NULL,
"identity_bundle_format" INTEGER NOT NULL DEFAULT 1,
"current_state_json" TEXT NOT NULL,
"current_payload_json" TEXT NOT NULL,
"current_projection_json" TEXT NOT NULL,
"current_grants_json" TEXT NOT NULL,
"current_member_envelopes_json" TEXT NOT NULL,
"previous_states_json" TEXT NOT NULL,
"updated_at" TEXT NOT NULL,
PRIMARY KEY ("principal_type", "principal_id", "state_hash")
);
CREATE UNIQUE INDEX IF NOT EXISTS "principal_policy_bundles_current_idx" ON "principal_policy_bundles" ("principal_type", "principal_id") WHERE "is_current" = 1;
CREATE INDEX IF NOT EXISTS "principal_policy_bundles_key_fingerprint_idx" ON "principal_policy_bundles" (json_extract(CASE WHEN json_valid("current_state_json") THEN "current_state_json" END, '$.keyFingerprint'), "is_current", "updated_at" desc);