import * as Domain from "../domain"; import Agent from "./Agent"; import { Version } from "../domain/backup"; /** * define Agent requirements for Backup */ type BackupAgent = Pick; type BackupExclude = "messages" | "mediators" | "link_secret"; type MasterKey = Domain.PrivateKey & Domain.ExportableKey.Common & Domain.ExportableKey.JWK & Domain.ExportableKey.PEM; export type BackupOptions = { version?: Version; key?: MasterKey; compress?: boolean; excludes?: BackupExclude[]; }; export declare class AgentBackup { readonly Agent: BackupAgent; private _jwe; constructor(Agent: BackupAgent); /** * Creates a JWE (JSON Web Encryption) containing the backup data stored in Pluto. * The data can optionally be encrypted using a custom master key, compressed, * and filtered to exclude specified fields. * * @param {BackupOptions} [options] - Optional settings for the backup. * @param {Version} [options.version] - Specifies the version of the backup data. * @param {MasterKey} [options.key] - Custom master key used for encrypting the backup. * @param {boolean} [options.compress] - If true, compresses the JWE using DEFLATE. * @param {BackupExclude[]} [options.excludes] - Keys to exclude from the backup data * (e.g., "messages", "mediators", "link_secret"). Arrays are cleared, and strings are set to empty strings. * * @returns {Promise} - A promise that resolves to the JWE string. * * @see restore - Method to restore data from a JWE string. */ createJWE(options?: BackupOptions): Promise; /** * Decodes a JWE (JSON Web Encryption) string and restores the backup data to the store. * If the JWE is compressed (Base64-encoded), it will attempt to decompress it first. * * @param {string} jwe - The JWE string containing the encrypted backup data. * @param {BackupOptions} [options] - Optional settings for the backup. * @param {Version} [options.version] - Specifies the version of the restore data. * @param {MasterKey} [options.key] - Custom master key used for decrypting the backup. * @param {boolean} [options.compress] - If true, compresses the JWE using INFLATE. * * @returns {Promise} - A promise that resolves when the data is successfully restored. * * @see createJWE - Method to create a JWE from the stored backup data. */ restore(jwe: string, options?: BackupOptions): Promise; private parseBackupJson; /** * Compresses a JSON object into a Base64-encoded string using DEFLATE. * * - Uses `level: 9` for maximum compression and `strategy: Z_FILTERED` * (optimized for repetitive patterns, common in JSON data). * - Converts the JSON to a string, compresses it, and encodes it in Base64. * * @param {unknown} json - The JSON object to compress. * @returns {string} - The Base64-encoded compressed string. */ private compress; /** * Decompresses a Base64-encoded string into its original JSON representation. * * - Decodes the Base64 string to a binary buffer. * - Uses DEFLATE to decompress the data and converts it back to a JSON string. * - Parses and returns the JSON object. * * @param {string} data - The Base64-encoded compressed string. * @returns {string} - The decompressed JSON string. */ private decompress; /** * create a JWK for the MasterKey (X25519) * @returns JWK */ private masterSk; /** * Modifies the backup object by applying exclusions. * Sets excluded array values to empty arrays and string values to empty strings. * * @param {Domain.Backup.Schema} backup - The backup object to be modified. * @param {BackupExclude[]} excludes - An array of keys to exclude from the backup. * @returns {Domain.Backup.Schema} The modified backup object. */ private applyExclusions; private getJWE; } export {};