Creates a new TinyOlmInstance instance bound to a specific user and device.
| Name | Type | Description |
|---|---|---|
userId |
string |
The user ID to associate with this account and its cryptographic sessions. |
deviceId |
string |
The device ID representing this instance of the user. |
password |
string |
(Optional) A password linked to this account and its sessions. |
| Property | Type | Description |
|---|---|---|
this.userId |
string |
The user's unique identifier. |
this.deviceId |
string |
The identifier for this specific device. |
this.password |
string |
Password used in this session (optional). |
this.account |
Olm.Account | null |
The associated Olm account (or null if unset). |
this.sessions |
Map<string, Olm.Session> |
Direct peer-to-peer sessions by user/device. |
this.groupSessions |
Map<string, Olm.OutboundGroupSession> |
Group encryption sessions (outbound). |
this.groupInboundSessions |
Map<string, Olm.InboundGroupSession> |
Group decryption sessions (inbound). |
Initializes the Olm library and creates a new account.
- Promise: Resolves when the Olm library is initialized and the account is created.
await tinyOlmInstance.init();
console.log('Olm library initialized and account created.');Initializes the IndexedDB database for this TinyOlmInstance and attempts to restore all saved cryptographic state (account, sessions, group sessions).
| Name | Type | Default | Description |
|---|---|---|---|
dbName |
string |
'TinyOlmInstance' |
(Optional) The name of the database. |
Promise<IDBDatabase>: Resolves once the database is fully initialized and restored.
Error:- If not running in a browser.
- If
dbNameis not a string. - If the database has already been initialized.
- Ensures the environment is a browser and that Olm is loaded.
- Opens or upgrades the IndexedDB database with object stores:
accountsessionsgroupSessionsgroupInboundSessions
- Emits internal setup events for password, userId, and deviceId.
- Loads and restores:
- Your account from storage.
- All direct sessions.
- All group sessions (outbound and inbound).
- Starts watching for any future pickle updates.
Checks whether the current environment supports IndexedDB — meaning it's running in a web browser.
Error: If not running in a browser or ifindexedDBis unavailable.
This method ensures that the TinyOlm instance is being used in an environment compatible with browser-based storage.
Returns the name of the IndexedDB database used by the TinyOlmInstance.
string: The name of the current IndexedDB database.
Error: If the internal database name (#dbName) is not set correctly (i.e., not a string).
This method relies on an internal private field #dbName and is used to access the database identifier safely.
Returns the active IndexedDB database instance currently used by TinyOlmInstance.
IDBDatabase: The open and initialized IndexedDB database instance.
Error: If the database hasn't been initialized yet.
(Hint: Make sure to callinitIndexedDb()before using this method.)
This method accesses the internal private field #db and ensures that the database is ready before continuing.
(Internal method)
Used for debugging purposes: logs all entries currently stored in the database's object stores.
Promise<void>— Logs the contents of:accountsessionsgroupSessionsgroupInboundSessions
Exports the entire TinyOlmInstance as a serial structure.
| Name | Type | Description |
|---|---|---|
password |
string |
The password used to pickle the instance. Default is the current instance password. |
ExportedOlmInstance: A serial structure containing the pickled account, sessions, group sessions, and inbound group sessions.
- Exports the full instance, including account, sessions, group sessions, and inbound group sessions, all pickled with the specified password.
const exportedInstance = tinyOlmInstance.exportInstance('mySecurePassword');Restores a full exported TinyOlmInstance, including account, sessions, and group sessions.
- Promise
- Restores the account via
importAccount(). - Iterates over
data.sessions, callingimportSession()on each. - Iterates over
data.groupSessions, callingimportGroupSession()on each. - Iterates over
data.groupInboundSessions, callingimportInboundGroupSession()on each.
This is the high-level method used to restore the entire cryptographic state, e.g., after logging in from another device.
await tinyOlmInstance.importInstance(exportedData, 'secure-password');Disposes the TinyOlmInstance by clearing all Olm sessions (both individual and group) and releasing the account from memory.
- Promise
- Clears all 1:1 Olm sessions via
clearSessions(). - Frees and nullifies the Olm account, emitting
TinyOlmEvents.ResetAccount. - Clears all outbound group sessions.
- Clears all inbound group sessions.
This should be called when the instance is no longer needed, to ensure that memory is properly released and cryptographic material is not kept in memory unnecessarily.
await tinyOlmInstance.dispose();Checks whether the internal IndexedDB instance has been initialized and is currently available.
- boolean:
trueif the database instance exists and is ready for use, otherwisefalse.
- Verifies if the private
#dbproperty has been set (i.e., the database has been opened). - Returns
trueif an activeIDBDatabaseinstance is present.
This is a lightweight check that does not open or interact with the database—only verifies internal state.
if (tinyOlmInstance.existsDb()) {
console.log('Database is ready!');
} else {
console.warn('Database is not initialized.');
}Returns the internal TinyPromiseQueue (from tiny-essentials module) used to manage asynchronous task queuing and execution order.
This queue ensures that encryption and decryption operations — or any session-related activities — are executed sequentially, avoiding race conditions.
TinyPromiseQueue: A queue manager instance that controls promise execution order.
const queue = tinyOlm.getQueue();
queue.enqueue(() => someAsyncTask());
queue.enqueuePoint(() => someAsyncTask());