import { TypedEventTarget } from 'typescript-event-target'; import type { PlatformProviders } from './interfaces/PlatformProviders.mjs'; import type { DevicePublicKeys, DeviceSecretKeys, EncryptedSecretKeys, EncryptedSymmetricKey, KdfParameters, MacKey, Salt, SymmetricKey } from './interfaces/CryptoLib.mjs'; import type { DeviceFriendlyName, DeviceId, DeviceType } from './interfaces/SyncTypes.mjs'; import type { FavaLibEventMapEvents } from './interfaces/Events.mjs'; import type { PasswordExtraDict } from './interfaces/PasswordExtraDict.js'; import type { ServerSecret } from './interfaces/BrandedTypes.mjs'; import type { Vault, VaultSyncState } from './interfaces/Vault.mjs'; import type { SaveFunction } from './interfaces/SaveFunction.mjs'; import type { FavaMeta } from './interfaces/FavaMeta.mjs'; import SyncManager from './subclasses/SyncManager.mjs'; import ExportImportManager from './subclasses/ExportImportManager.mjs'; import VaultOperationsManager from './subclasses/VaultOperationsManager.mjs'; import StorageOperationsManager from './subclasses/StorageOperationsManager.mjs'; /** * The Two-Factor Library, this is the main entry point. */ declare class FavaLib extends TypedEventTarget { static readonly version = "0.0.24"; private readonly favaMeta; readonly deviceType: DeviceType; private mediator; private readonly publicKeys; private readonly secretKeys; readonly ready: Promise; /** * @returns The meta info for this device. */ get meta(): { deviceId: DeviceId; deviceFriendlyName: string | DeviceFriendlyName; deviceType: DeviceType; }; /** * Constructs a new instance of FavaLib. If a serverUrl is provided, the library will use it for its sync operations. * @param deviceType - The identifier for this device type (e.g. 2fa-cli). * @param platformProviders - The platform-specific providers containing CryptoLib and other providers. * @param passwordExtraDict - Additional words to be used for password strength evaluation. * @param secretKeys - The device's X25519 and Ed25519 secret keys. * @param symmetricKey - The symmetric key used for cryptographic operations. * @param encryptedSecretKeys - The sealed device secret keys * @param encryptedSymmetricKey - The encrypted symmetric key * @param salt - The salt used for key derivation. * @param macKey - The envelope MAC key, derived from the password hash. * @param kdf - The argon2id parameters this vault's keys were derived with. * @param publicKeys - The device's two public keys, as its peers know it. * @param favaMeta - Meta info about this device containing at least a unique identifier for this device. * @param vault - The vault data (entries) * @param saveFunction - The function to save the data. * @param syncState - The state of the sync, includes the serverUrl * @param connectToSyncServer - Whether to connect to the configured sync server during initialization. * @returns A promise that resolves when initialization is complete. * @throws {InitializationError} If some parameter has an invalid value * @throws {AuthenticationError} If the provided password is incorrect. */ constructor(deviceType: DeviceType, platformProviders: PlatformProviders, passwordExtraDict: PasswordExtraDict, secretKeys: DeviceSecretKeys, symmetricKey: SymmetricKey, encryptedSecretKeys: EncryptedSecretKeys, encryptedSymmetricKey: EncryptedSymmetricKey, salt: Salt, macKey: MacKey, kdf: KdfParameters, publicKeys: DevicePublicKeys, favaMeta: FavaMeta, vault?: Vault, saveFunction?: SaveFunction, syncState?: VaultSyncState, connectToSyncServer?: boolean); /** * @returns The persistent storage manager instance which can be used to store data. */ private get persistentStorageManager(); /** * Gives access to vault operations. * @returns The vault operations manager instance which can be used to perform operations on the vault. */ get vault(): VaultOperationsManager; /** * Gives access to storage operations. * @returns The storage operations manager instance which can be used to perform operations on the vault. */ get storage(): StorageOperationsManager; /** * Gives access to export/import operations. * @returns The export/import manager instance which can be used to export and import vaults. */ get exportImport(): ExportImportManager; /** * Gives access to sync operations. * @returns The sync manager instance which can be used to sync the vault with a server or null if none was initialized. */ get sync(): SyncManager | null; /** * Sets a sync server, this will allow syncing with the server. * * The two arguments are one setting. A sync server will not accept a socket * without its shared secret, so a url on its own configures nothing, and * there is no way to supply the secret afterwards -- which is why this * replaces the whole sync state rather than patching a url into an existing * one. * * What "connected" means here changed with the secret: the promise below * resolves on the CONNECTED event, and a client only reports that once the * server has accepted its proof. So a wrong secret surfaces here, as a * refusal to set the server, rather than as a connection that quietly never * works. * @param serverUrl - The server url. * @param serverSecret - The static secret the server is configured with. * @param force - Force setting the sync server, even if no connection can be made */ setSyncServerUrl(serverUrl: string, serverSecret: ServerSecret, force?: boolean): Promise; /** * Set a friendly name for this vault (used in syncing) * @param deviceFriendlyName Human readable name for the device */ setDeviceFriendlyName(deviceFriendlyName: DeviceFriendlyName): Promise; /** * Remove a sync device from the vault. Synced to all other devices. * @param deviceId The id of the device to remove * @throws {FavaLibError} If trying to remove the current device. */ removeSyncDevice(deviceId: DeviceId): Promise; /** * Dispatches a library event. * @param eventType - The type of the event to dispatch, uses the FavaLibEvent enum. * @param data - Optional data to include with the event. */ private dispatchLibEvent; /** * Log a message * * Sanitised here rather than at each of the fifty-odd call sites, because * almost every one of them interpolates something a peer or the server chose * -- a deviceId, a command id, a WebSocket close reason, the message of an * error raised while parsing a remote frame -- and a consumer may write the * result straight to a terminal, where an ANSI sequence repaints the line and * a bidi override reorders the fingerprint it was printed to be compared * against. One boundary is also the only version of this that stays true: the * next log call added anywhere gets it without being told, and this is the * only place a Log event is dispatched from. * @param severity - The severity of the message, either 'info' or 'warning'. * @param message - The message to log. */ private log; } export default FavaLib;