Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface IStorage

This is the class you must implement to store and retrieve important data for the key exchange and messaging processes if you want to replace the Database class, for example, if you wanted to port this library to mobile or browser or another platform that doesn't support knex.js

Hierarchy

  • EventEmitter
    • IStorage

Index

Constructors

constructor

  • new IStorage(options?: EventEmitterOptions): IStorage
  • Parameters

    • Optional options: EventEmitterOptions

    Returns IStorage

Events

on

  • on(event: "ready", callback: () => void): this
  • on(event: "error", callback: (error: Error) => void): this
  • Emit this event when init has complete.

    Parameters

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

    Returns this

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

    Parameters

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

          • error: Error

          Returns void

    Returns this

Properties

close

close: () => Promise<void>

Closes the database. You must close any open connections so the sqlite database is available to be opened again.

Type declaration

    • (): Promise<void>
    • Returns Promise<void>

deleteMessage

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

Deletes a message. Remove it entirely.

param

The message to delete.

Type declaration

    • (mailID: string): Promise<void>
    • Parameters

      • mailID: string

      Returns Promise<void>

deleteOneTimeKey

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

Deletes a set of one time keys by index number.

param

The index number of the prekey to delete.

Type declaration

    • (index: number): Promise<void>
    • Parameters

      • index: number

      Returns Promise<void>

getAllSessions

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

Gets all encryption sessions.

Type declaration

getGroupHistory

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

Gets the group message history of a channel by its channelID, in descending temporal order.

param

the channelID to retrieve history for.

Type declaration

    • (channelID: string): Promise<IMessage[]>
    • Parameters

      • channelID: string

      Returns Promise<IMessage[]>

getMessageHistory

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

Gets the direct message history of a user by their userID, in descending temporal order.

param

the userID to retrieve history for.

Type declaration

    • Parameters

      • userID: string

      Returns Promise<IMessage[]>

getOneTimeKey

getOneTimeKey: (index: number) => Promise<IPreKeys | null>

Gets a set of one time keys by index number.

param

The index number of the prekey to fetch.

Type declaration

    • (index: number): Promise<IPreKeys | null>
    • Parameters

      • index: number

      Returns Promise<IPreKeys | null>

getPreKeys

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

Gets your set of main prekeys. You only have one at a time. Returns null if the prekeys have not been saved yet.

param

the set of prekeys to save.

param

whether or not the set of prekeys is a one time set.

Type declaration

    • (): Promise<IPreKeys | null>
    • Returns Promise<IPreKeys | null>

getSessionByPublicKey

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

Gets an encryption session by its public key.

param

the public key of the session to fetch.

Type declaration

    • (publicKey: Uint8Array): Promise<ISession | null>
    • Parameters

      • publicKey: Uint8Array

      Returns Promise<ISession | null>

getSessionByUserID

getSessionByUserID: (userID: string) => Promise<ISession | null>

Gets the most recently used (active) session (by lastUsed key) by userID.

param

The userID to retrieve the active session for.

Type declaration

    • (userID: string): Promise<ISession | null>
    • Parameters

      • userID: string

      Returns Promise<ISession | null>

init

init: () => Promise<void>

Any initializing you may need to do before the class is used. For example, you could initialize the database schema here.

Type declaration

    • (): Promise<void>
    • Returns Promise<void>

markSessionUsed

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

Updates the "lastUsed" timestamp key of a session to the current time. This will be called each time the session is used to encrypt or decrypt a message.

param

the sessionID to mark used.

Type declaration

    • (sessionID: string): Promise<void>
    • Parameters

      • sessionID: string

      Returns Promise<void>

markSessionVerified

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

Marks a session as "verified" which means the user has compared the mnemonic fingerprint with the other user and indicated it matches.

param

the sessionID to mark verified.

Type declaration

    • (sessionID: string): Promise<void>
    • Parameters

      • sessionID: string

      Returns Promise<void>

ready

ready: boolean

Set this to "true" when init has complete.

saveMessage

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

Saves a single message to a database.

param

The message to save.

Type declaration

    • Parameters

      Returns Promise<void>

savePreKeys

savePreKeys: (preKeys: IPreKeys, oneTime: boolean) => Promise<number>

Saves a main set of prekeys or a onetime set of prekeys, as indicated by the oneTime parameter.

Type declaration

    • (preKeys: IPreKeys, oneTime: boolean): Promise<number>
    • Parameters

      • preKeys: IPreKeys
      • oneTime: boolean

      Returns Promise<number>

saveSession

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

Saves an encryption session.

param

The ISession object to save.

Type declaration

    • Parameters

      Returns Promise<void>

Static defaultMaxListeners

defaultMaxListeners: number

Static Readonly errorMonitor

errorMonitor: unique symbol

This symbol shall be used to install a listener for only monitoring 'error' events. Listeners installed using this symbol are called before the regular 'error' listeners are called.

Installing a listener using this symbol does not change the behavior once an 'error' event is emitted, therefore the process will still crash if no regular 'error' listener is installed.

Methods

addListener

  • addListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

getMaxListeners

  • getMaxListeners(): number

listenerCount

  • listenerCount(event: string | symbol): number
  • Parameters

    • event: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

off

  • off(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

once

  • once(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependListener

  • prependListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Parameters

    • Optional event: string | symbol

    Returns this

removeListener

  • removeListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Generated using TypeDoc