import type { NoydbStore, EncryptedEnvelope, ExportStreamOptions, ExportChunk } from '../kernel/types.js'; import type { LedgerStore } from '../with-commit/history/ledger/store.js'; /** Everything the moving backup methods touched on the vault's `this.*`. */ export interface BackupContext { /** The ciphertext store. */ readonly adapter: NoydbStore; /** Vault namespace name. */ readonly vault: string; /** The invoking keyring's user id (read fresh per call). */ userId(): string; /** The vault's ledger store, or null when history is off. */ getLedgerOrNull(): LedgerStore | null; /** Recompute an envelope's `payloadHash` (bound `historyStrategy.envelopePayloadHash`). */ envelopePayloadHash(envelope: EncryptedEnvelope): Promise; /** * Refresh the in-memory keyring from the freshly-loaded keyring file and * rebuild the DEK resolver. No-op when the vault has no `reloadKeyring` * callback (plaintext vaults / test constructions). */ reloadKeyringAndRebuildDEK(): Promise; /** Clear the vault's collection cache (post-load). */ clearCollectionCache(): void; /** Reset the ledger store so the next `ledger()` rebuilds its head cache. */ resetLedgerStore(): void; /** The vault's decrypt+ACL export stream (used by `exportJSON`). */ exportStream(opts: ExportStreamOptions): AsyncIterableIterator; } /** Result of {@link verifyBackupIntegrity}. */ export type VerifyBackupResult = { readonly ok: true; readonly head: string; readonly length: number; } | { readonly ok: false; readonly kind: 'chain'; readonly divergedAt: number; readonly message: string; } | { readonly ok: false; readonly kind: 'data'; readonly collection: string; readonly id: string; readonly message: string; }; /** * Dump vault as a verifiable encrypted JSON backup string. * * backups embed the current ledger head and the full `_ledger` + * `_ledger_deltas` internal collections so the receiver can run * `verifyBackupIntegrity()` after `load()` and detect any tampering between * dump and restore. Backups produced without a ledger skip the integrity check * with a warning — both modes round-trip cleanly. */ export declare function dumpVault(ctx: BackupContext): Promise; /** * Restore a vault from a verifiable backup. After loading, runs * `verifyBackupIntegrity()` to confirm the hash chain, the embedded head, and * every data envelope's payload hash. Legacy backups (no `ledgerHead`) load * with a console warning and skip the integrity check. */ export declare function loadVault(ctx: BackupContext, backupJson: string): Promise; /** * End-to-end backup integrity check: `ledger.verify()` (hash chain) plus a data * envelope cross-check (every current record's `_data` hash must match the * latest `put` entry's `payloadHash`). Returns a discriminated union so callers * can distinguish chain vs data failures. */ export declare function verifyBackupIntegrity(ctx: BackupContext): Promise; /** * Plaintext per-collection export, built on the vault's `exportStream`. Forces * collection granularity (record-by-record output makes no sense in a single * string) and merges dictionary snapshots across collections. */ export declare function exportVaultJSON(ctx: BackupContext, opts?: ExportStreamOptions): Promise;