1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-01 04:43:29 +03:00

Factor out a function for doing olm encryption

Make a library file with some constants and a function to pack olm-encrypted
events (which we are going to use from megolm)
This commit is contained in:
Richard van der Hoff
2016-08-19 16:52:04 +01:00
parent 4877edb79b
commit 0234410b43
5 changed files with 122 additions and 49 deletions

View File

@@ -294,6 +294,22 @@ OlmDevice.prototype.getSessionIdsForDevice = function(theirDeviceIdentityKey) {
return utils.keys(sessions);
};
/**
* Get the right olm session id for encrypting messages to the given identity key
*
* @param {string} theirDeviceIdentityKey Curve25519 identity key for the
* remote device
* @return {string?} session id, or null if no established session
*/
OlmDevice.prototype.getSessionIdForDevice = function(theirDeviceIdentityKey) {
var sessionIds = this.getSessionIdsForDevice(theirDeviceIdentityKey);
if (sessionIds.length === 0) {
return null;
}
// Use the session with the lowest ID.
sessionIds.sort();
return sessionIds[0];
};
/**
* Encrypt an outgoing message using an existing session