1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-29 16:43:09 +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

@@ -24,11 +24,10 @@ var anotherjson = require('another-json');
var q = require("q");
var OlmDevice = require("./OlmDevice");
var olmlib = require("./olmlib");
var algorithms = require("./crypto-algorithms");
var OLM_ALGORITHM = "m.olm.v1.curve25519-aes-sha2";
var DeviceInfo = require("./crypto-deviceinfo");
var DeviceVerification = DeviceInfo.DeviceVerification;
@@ -69,7 +68,7 @@ function Crypto(baseApis, sessionStore, userId, deviceId) {
// add our own deviceinfo to the sessionstore
var deviceInfo = {
keys: this._deviceKeys,
algorithms: [OLM_ALGORITHM],
algorithms: [olmlib.OLM_ALGORITHM],
verified: DeviceVerification.VERIFIED,
};
var myDevices = this._sessionStore.getEndToEndDevicesForUser(
@@ -122,7 +121,7 @@ function _uploadDeviceKeys(crypto) {
var deviceId = crypto._deviceId;
var deviceKeys = {
algorithms: [OLM_ALGORITHM],
algorithms: [olmlib.OLM_ALGORITHM],
device_id: deviceId,
keys: crypto._deviceKeys,
user_id: userId,
@@ -411,7 +410,7 @@ Crypto.prototype.listDeviceKeys = function(userId) {
* @return {module:crypto-deviceinfo?}
*/
Crypto.prototype.getDeviceByIdentityKey = function(userId, algorithm, sender_key) {
if (algorithm !== OLM_ALGORITHM) {
if (algorithm !== olmlib.OLM_ALGORITHM) {
// we only deal in olm keys
return null;
}