diff --git a/src/crypto/OlmDevice.js b/src/crypto/OlmDevice.js index 894d958e8..8d1817998 100644 --- a/src/crypto/OlmDevice.js +++ b/src/crypto/OlmDevice.js @@ -435,9 +435,9 @@ OlmDevice.prototype.getSessionInfoForDevice = async function(deviceIdentityKey) * @param {string} sessionId the id of the active session * @param {string} payloadString payload to be encrypted and sent * - * @return {string} ciphertext + * @return {Promise} ciphertext */ -OlmDevice.prototype.encryptMessage = function( +OlmDevice.prototype.encryptMessage = async function( theirDeviceIdentityKey, sessionId, payloadString, ) { const self = this; @@ -460,9 +460,9 @@ OlmDevice.prototype.encryptMessage = function( * @param {number} message_type message_type field from the received message * @param {string} ciphertext base64-encoded body from the received message * - * @return {string} decrypted payload. + * @return {Promise} decrypted payload. */ -OlmDevice.prototype.decryptMessage = function( +OlmDevice.prototype.decryptMessage = async function( theirDeviceIdentityKey, sessionId, message_type, ciphertext, ) { const self = this; @@ -484,10 +484,10 @@ OlmDevice.prototype.decryptMessage = function( * @param {number} message_type message_type field from the received message * @param {string} ciphertext base64-encoded body from the received message * - * @return {boolean} true if the received message is a prekey message which matches + * @return {Promise} true if the received message is a prekey message which matches * the given session. */ -OlmDevice.prototype.matchesSession = function( +OlmDevice.prototype.matchesSession = async function( theirDeviceIdentityKey, sessionId, message_type, ciphertext, ) { if (message_type !== 0) { diff --git a/src/crypto/algorithms/olm.js b/src/crypto/algorithms/olm.js index 36ba16384..495b125e5 100644 --- a/src/crypto/algorithms/olm.js +++ b/src/crypto/algorithms/olm.js @@ -251,7 +251,7 @@ OlmDecryption.prototype._decryptMessage = async function( for (let i = 0; i < sessionIds.length; i++) { const sessionId = sessionIds[i]; try { - const payload = this._olmDevice.decryptMessage( + const payload = await this._olmDevice.decryptMessage( theirDeviceIdentityKey, sessionId, message.type, message.body, ); console.log( @@ -260,7 +260,7 @@ OlmDecryption.prototype._decryptMessage = async function( ); return payload; } catch (e) { - const foundSession = this._olmDevice.matchesSession( + const foundSession = await this._olmDevice.matchesSession( theirDeviceIdentityKey, sessionId, message.type, message.body, ); diff --git a/src/crypto/olmlib.js b/src/crypto/olmlib.js index 317f27955..161d762f9 100644 --- a/src/crypto/olmlib.js +++ b/src/crypto/olmlib.js @@ -102,7 +102,7 @@ module.exports.encryptMessageForDevice = async function( utils.extend(payload, payloadFields); - resultsObject[deviceKey] = olmDevice.encryptMessage( + resultsObject[deviceKey] = await olmDevice.encryptMessage( deviceKey, sessionId, JSON.stringify(payload), ); };