/** * E2EE Snapshot Manager - Handles encrypted snapshot requests and saves * for end-to-end encrypted documents. * * For E2EE documents, the server cannot process encrypted content, so clients * are responsible for saving periodic snapshots. When the server's * DOC_SAVE_INTERVAL is reached, it sends a "request_snapshot" message to * one of the write-capable clients. This module handles that request by: * * 1. Collecting the current document state (content, comments, bibliography) * 2. Encrypting each field with the document's AES-GCM key * 3. Sending an "e2ee_snapshot" message to the server for persistence * * The server stores the encrypted snapshot as opaque data and notifies * other clients via an "e2ee_snapshot_received" message. */ import type { Editor } from "../types.js"; interface SnapshotPayload { content: string; comments: string; bibliography: string; title: string; e2ee_salt?: string; e2ee_iterations?: number; v?: number; } export declare class E2EESnapshotManager { editor: Editor; pendingSave: boolean; key: CryptoKey | null; /** * @param editor - The Fidus Writer editor instance */ constructor(editor: Editor); /** * Set the encryption key for this document. * Called after the user enters the password and the key is derived. * * @param key - An AES-GCM key (from E2EEKeyManager.deriveKey) */ setKey(key: CryptoKey): void; /** * Clear the encryption key (e.g., when the document is closed). */ clearKey(): void; /** * Check whether the snapshot manager has a key set. * * @returns boolean */ get hasKey(): boolean; /** * Build an encrypted snapshot payload for the current document state. * * Returns the encrypted data without sending it. Used in * non-collaborative mode where snapshots are sent via REST instead * of WebSocket. * * @returns The encrypted snapshot payload or null if no key. */ getEncryptedSnapshot(): Promise; /** * Handle a "request_snapshot" message from the server. * * The server sends this message when it needs a client to save * an encrypted snapshot (typically after DOC_SAVE_INTERVAL diffs). * Only write-capable clients should respond. * * @param request - The request_snapshot message * @param request.v - The server's current document version */ handleRequestSnapshot(_request: { v?: number; }): Promise; /** * Handle an "e2ee_snapshot_received" message from the server. * * The server sends this to all clients (except the one that sent * the snapshot) to notify them that a new snapshot has been saved. * This is informational — clients don't need to take any action * since they already have the latest state from the diffs they've * been receiving. * * @param message - The e2ee_snapshot_received message * @param message.v - The version of the saved snapshot */ handleSnapshotReceived(message: { v?: number; e2ee_salt?: string; e2ee_iterations?: number; }): Promise; /** * Send an initial snapshot for a newly created E2EE document. * * When a new E2EE document is created, the initial content (from * the template) needs to be encrypted and saved as the first snapshot. * This method handles that initial save. * * @param content - The document content (ProseMirror JSON) * @param comments - The comments object (usually empty {}) * @param bibliography - The bibliography object (usually {}) * @param version - The document version (usually 0) */ sendInitialSnapshot(content: any, comments: any, bibliography: any, version: number): Promise; /** * Re-encrypt the document with a new key (for password changes). * * When the user changes the document password, a new key is derived * and the entire document must be re-encrypted. This method handles * that by collecting the current document state, encrypting it with * the new key, and sending a snapshot. * * @param newKey - The new AES-GCM key derived from the new password * @param newSaltBase64 - The new salt (Base64-encoded) to send to the server * @param newIterations - The new iteration count */ reEncryptWithNewKey(newKey: CryptoKey, newSaltBase64: string, newIterations: number): Promise; } export {}; //# sourceMappingURL=snapshot-manager.d.ts.map