/** * Persistence helpers for per-principal user envelopes stored at * `_users/` (logically: `_meta/user/`). * * Unlike `_meta/policy` and `_meta/handle` which are plaintext, user * envelopes carry user data and are encrypted with a dedicated * {@link USER_ENVELOPE_COLLECTION} DEK (provisioned at vault open and * propagated to every keyring via the system-collection DEK path in * `team/keyring.ts`). * * This module is the **storage primitive** layer. The public API * (`vault.user.*`) sits on top of this; permission gates, own-only * write enforcement, and presence-channel propagation live there. * * @see docs/superpowers/specs/2026-05-05-user-envelope-design.md * * @module */ import type { NoydbStore, UserEnvelope } from '../../../kernel/types.js'; import { type EnclaveKey } from '../../../kernel/enclave/index.js'; /** * Read and decrypt the user envelope for `keyringId`. Returns `null` * when no envelope has been persisted (either the principal has never * called `updateMe`, or the keyring predates this feature). * * Decryption errors propagate — a tampered or wrong-keyed envelope * surfaces as the underlying crypto error rather than masquerading as * "not found". */ export declare function loadUserEnvelope(store: NoydbStore, vault: string, keyringId: string, dek: EnclaveKey): Promise | null>; /** * Encrypt and persist the user envelope for `keyringId`. The new * version is `(prior._v ?? 0) + 1`. Pass `expectedVersion` to enable * optimistic-concurrency checks: a mismatch with the stored version * throws {@link ConflictError} with the actual stored version. * * `expectedVersion: 0` means "expect no prior envelope"; the write * succeeds only if no envelope exists yet. * * Soft-caps the JSON-serialized payload at {@link USER_ENVELOPE_MAX_BYTES}; * larger payloads throw {@link UserEnvelopeOversizedError}. */ export declare function saveUserEnvelope(store: NoydbStore, vault: string, keyringId: string, payload: T, dek: EnclaveKey, expectedVersion?: number): Promise>; /** * Delete the user envelope for `keyringId`. Idempotent — no error if * the envelope is already absent. Called from the keyring revoke path * (cascade-delete) and is a no-op for keyrings that never wrote. */ export declare function deleteUserEnvelope(store: NoydbStore, vault: string, keyringId: string): Promise; /** * List the keyring ids that have a user envelope persisted in `vault`. * Order is store-defined — callers that need a stable order should sort. */ export declare function listUserEnvelopeIds(store: NoydbStore, vault: string): Promise;