@vex-chat/libvex
    Preparing search index...

    Interface IStorage

    Storage contract used by Client for local persistence.

    Implement this interface when you want to replace the built-in sqlite-backed Storage class (for example on mobile, web, or any custom environment).

    A custom implementation is responsible for:

    • Persisting encrypted/decrypted message history
    • Storing device records and cryptographic sessions
    • Managing prekeys / one-time keys used for session setup
    • Emitting lifecycle events (ready, error)
    interface IStorage {
        close: () => Promise<void>;
        deleteHistory: (
            channelOrUserID: string,
            olderThan?: string,
        ) => Promise<void>;
        deleteMessage: (mailID: string) => Promise<void>;
        deleteOneTimeKey: (index: number) => Promise<void>;
        getAllSessions: () => Promise<ISession[]>;
        getDevice: (deviceID: string) => Promise<IDevice | null>;
        getGroupHistory: (channelID: string) => Promise<IMessage[]>;
        getMessageHistory: (userID: string) => Promise<IMessage[]>;
        getOneTimeKey: (index: number) => Promise<IPreKeysCrypto | null>;
        getPreKeys: () => Promise<IPreKeysCrypto | null>;
        getSessionByDeviceID: (deviceID: string) => Promise<ISessionCrypto | null>;
        getSessionByPublicKey: (
            publicKey: Uint8Array,
        ) => Promise<ISessionCrypto | null>;
        init: () => Promise<void>;
        markSessionUsed: (sessionID: string) => Promise<void>;
        markSessionVerified: (sessionID: string) => Promise<void>;
        purgeHistory: () => Promise<void>;
        purgeKeyData: () => Promise<void>;
        ready: boolean;
        saveDevice: (device: IDevice) => Promise<void>;
        saveMessage: (message: IMessage) => Promise<void>;
        savePreKeys: (
            preKeys: IPreKeysCrypto[],
            oneTime: boolean,
        ) => Promise<IPreKeysSQL[]>;
        saveSession: (session: ISession) => Promise<void>;
        on(event: "ready", callback: () => void): this;
        on(event: "error", callback: (error: Error) => void): this;
    }

    Hierarchy

    • EventEmitter
      • IStorage
    Index

    Properties

    close: () => Promise<void>

    Closes storage resources (connections, handles, transactions, etc.).

    deleteHistory: (channelOrUserID: string, olderThan?: string) => Promise<void>

    Deletes history for a direct conversation or group channel.

    If olderThan is omitted, the full history for that thread is removed.

    Type Declaration

      • (channelOrUserID: string, olderThan?: string): Promise<void>
      • Parameters

        • channelOrUserID: string

          Channel ID or user ID whose history should be deleted.

        • OptionalolderThan: string

          Relative duration such as 1h, 7d, or 30m.

        Returns Promise<void>

    deleteMessage: (mailID: string) => Promise<void>

    Deletes one message by mailID.

    deleteOneTimeKey: (index: number) => Promise<void>

    Deletes one one-time key by index.

    getAllSessions: () => Promise<ISession[]>

    Returns all known encryption sessions.

    getDevice: (deviceID: string) => Promise<IDevice | null>

    Gets one device record by ID.

    getGroupHistory: (channelID: string) => Promise<IMessage[]>

    Returns group-message history for a channel.

    getMessageHistory: (userID: string) => Promise<IMessage[]>

    Returns direct-message history for a user.

    const history = await storage.getMessageHistory(userID);
    
    getOneTimeKey: (index: number) => Promise<IPreKeysCrypto | null>

    Fetches one one-time key by index.

    getPreKeys: () => Promise<IPreKeysCrypto | null>

    Returns the local signed prekey pair, or null when it has not been created yet.

    getSessionByDeviceID: (deviceID: string) => Promise<ISessionCrypto | null>

    Returns the active session for a device ID (typically the most recently used).

    getSessionByPublicKey: (publicKey: Uint8Array) => Promise<ISessionCrypto | null>

    Fetches an encryption session using the session public key bytes.

    init: () => Promise<void>

    Performs storage initialization (schema creation, migrations, warmup, etc.).

    Implementations should set ready = true and emit ready after completion.

    markSessionUsed: (sessionID: string) => Promise<void>

    Updates a session's lastUsed timestamp to "now".

    markSessionVerified: (sessionID: string) => Promise<void>

    Marks an encryption session as verified.

    This usually means the user has compared safety words / fingerprint out of band and confirmed the session.

    purgeHistory: () => Promise<void>

    Deletes all message history.

    purgeKeyData: () => Promise<void>

    Deletes all local key/session state.

    ready: boolean

    Set this to "true" when init has complete.

    saveDevice: (device: IDevice) => Promise<void>

    Saves a device record.

    saveMessage: (message: IMessage) => Promise<void>

    Persists one chat message.

    await storage.saveMessage(message);
    
    savePreKeys: (
        preKeys: IPreKeysCrypto[],
        oneTime: boolean,
    ) => Promise<IPreKeysSQL[]>

    Saves signed prekeys.

    Type Declaration

      • (preKeys: IPreKeysCrypto[], oneTime: boolean): Promise<IPreKeysSQL[]>
      • Parameters

        • preKeys: IPreKeysCrypto[]

          Prekeys to persist.

        • oneTime: boolean

          true for one-time keys, false for the long-lived signed prekey.

        Returns Promise<IPreKeysSQL[]>

    saveSession: (session: ISession) => Promise<void>

    Persists an encryption session.

    Events

    • Emit this event when init has complete.

      Parameters

      • event: "ready"
      • callback: () => void

      Returns this

    • Emit this event if there is an error in opening the database.

      Parameters

      • event: "error"
      • callback: (error: Error) => void

      Returns this