Imports and restores an inbound group Olm session from a pickled string for decrypting messages from other users.
- Promise
- Creates a new
Olm.InboundGroupSessionand unpickles it using thepassword. - Stores the session in
this.groupInboundSessionsunder the givenkey. - Persists the session in IndexedDB under
groupInboundSessions. - Emits
TinyOlmEvents.ImportInboundGroupSession.
Commonly used when receiving encrypted messages from other users in group chats.
await tinyOlmInstance.importInboundGroupSession(senderKey, pickledInboundSession);Exports an inbound group session for a specific room and sender.
| Name | Type | Description |
|---|---|---|
roomId |
string |
The ID of the room. |
userId |
string |
The sender's userId or session owner. |
password |
string |
The password used to encrypt the pickle. Default is the current instance password. |
string: The pickled inbound group session.
Error: If the inbound group session is not found.
- Exports the inbound group session for the specified room and sender as a pickled string, encrypted with the specified password.
const pickledInboundGroupSession = tinyOlmInstance.exportInboundGroupSession('roomId123', '@user:domain.com', 'mySecurePassword');Imports an inbound group session using a provided session key.
- roomId (string): The ID of the room where the session will be imported.
- userId (string): The ID of the user to whom the session belongs.
- sessionKey (string): The session key to import the group session.
- void
await tinyOlmInstance.importGroupSessionId('room123', 'user456', 'sessionKey123');Returns all inbound group sessions.
- Map<string, Olm.InboundGroupSession>: A map of all inbound group sessions, indexed by session ID.
const allSessions = tinyOlmInstance.getAllInboundGroupSessions();
console.log(allSessions);Returns a specific inbound group session by room ID and userId.
- roomId (string): The ID of the room where the inbound group session exists.
- userId (string): The ID of the user whose inbound group session is to be retrieved.
- Olm.InboundGroupSession: The inbound group session for the specified room and user.
- Error: If no inbound session exists for the given room and userId.
const session = tinyOlmInstance.getInboundGroupSession('room123', 'user456');
console.log(session); // Olm.InboundGroupSessionRemoves a specific inbound group session by room ID and userId.
- roomId (string): The ID of the room whose inbound group session will be removed.
- userId (string): The ID of the user whose inbound group session will be removed.
- boolean: Returns
trueif the session was removed, otherwisefalse.
const success = await tinyOlmInstance.removeInboundGroupSession('room123', 'user456');
console.log(success); // true if removedClears all inbound group sessions.
- void
await tinyOlmInstance.clearInboundGroupSessions();
console.log('All inbound group sessions cleared.');Decrypts an encrypted group message using the inbound group session.
- roomId (string): The ID of the room where the message was sent.
- userId (string): The ID of the user who is decrypting the message.
- encryptedMessage (Object): An object containing:
body(string): The encrypted message body.session_id(string): The session ID for the encrypted message.message_index(number): The message index.
- Object: An object containing:
message_index(number): The message index of the decrypted message.plaintext(string): The decrypted plaintext message.
- Error: If no inbound session exists for the given room and userId.
const decryptedMessage = tinyOlmInstance.decryptGroupMessage('room123', 'user456', encryptedMessage);
console.log(decryptedMessage);Decrypts encrypted content using the inbound group session.
- roomId (string): The ID of the room where the content was sent.
- userId (string): The ID of the user who is decrypting the content.
- encryptedMessage (Object): An object containing:
body(string): The encrypted content body.session_id(string): The session ID for the encrypted content.message_index(number): The message index.
- expectedType (string|null): Optionally specify the expected type of the decrypted data. If provided, the method will validate the type of the deserialized value.
- Object: An object containing:
message_index(number): The message index of the decrypted content.content(any): The decrypted content.
- Error: If no inbound session exists for the given room and userId.
const decryptedContent = tinyOlmInstance.decryptGroupContent('room123', 'user456', encryptedContent);
console.log(decryptedContent);