/** * hmem-sync crypto layer * * Key derivation: scrypt (Node.js built-in crypto, memory-hard, no native deps) * Encryption: AES-256-GCM (authenticated, per-blob random IV) * Recovery key: Base58-encoded 16 random bytes (24 chars displayed as groups) * * Zero-knowledge design: * - The server never sees plaintext content, IDs, or the passphrase. * - Each blob has its own random 12-byte IV — reuse is impossible. * - The salt is stored server-side (public) — it protects against rainbow tables * but the server cannot derive the key without the passphrase. */ export interface EncryptedBlob { /** Base64-encoded: IV (12) + ciphertext + auth tag (16) */ data: string; /** ISO timestamp of when this blob was encrypted (for delta sync) */ updated_at: string; } export interface SyncKeyMaterial { /** Base64-encoded 32-byte salt — stored server-side, never secret */ salt: string; /** Human-readable recovery key (Base58, grouped with dashes) */ recoveryKey: string; } /** * Derive a 256-bit AES key from a passphrase + salt using scrypt. * The salt must be stored server-side and retrieved before any crypto operation. */ export declare function deriveKey(passphrase: string, saltBase64: string): Buffer; /** * Encrypt plaintext with AES-256-GCM. * Returns a single Base64 blob: IV + ciphertext + auth tag. */ export declare function encrypt(plaintext: string, key: Buffer): string; /** * Decrypt a blob produced by encrypt(). * Throws if the auth tag doesn't match (tampered or wrong key). */ export declare function decrypt(blobBase64: string, key: Buffer): string; /** * Generate a new random salt and recovery key for a fresh sync setup. * Call once per user — store salt server-side, give recovery key to user. */ export declare function generateKeyMaterial(): SyncKeyMaterial; export declare function base58Decode(str: string): Buffer; /** * Encrypt a single hmem entry's content fields into a blob. * The entry_id_hash (SHA-256 of entry ID) is stored unencrypted server-side * for delta detection — no plaintext ID leaks to the server. */ export declare function encryptEntry(entryId: string, payload: Record, key: Buffer, updatedAt: string): EncryptedBlob; export declare function decryptEntry(blob: EncryptedBlob, key: Buffer): Record;