You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
Make OlmDevice olmSession methods asynchronous
* OlmDevice.encryptMessage * OlmDevice.decryptMessage * OlmDevice.matchesSession
This commit is contained in:
@@ -435,9 +435,9 @@ OlmDevice.prototype.getSessionInfoForDevice = async function(deviceIdentityKey)
|
|||||||
* @param {string} sessionId the id of the active session
|
* @param {string} sessionId the id of the active session
|
||||||
* @param {string} payloadString payload to be encrypted and sent
|
* @param {string} payloadString payload to be encrypted and sent
|
||||||
*
|
*
|
||||||
* @return {string} ciphertext
|
* @return {Promise<string>} ciphertext
|
||||||
*/
|
*/
|
||||||
OlmDevice.prototype.encryptMessage = function(
|
OlmDevice.prototype.encryptMessage = async function(
|
||||||
theirDeviceIdentityKey, sessionId, payloadString,
|
theirDeviceIdentityKey, sessionId, payloadString,
|
||||||
) {
|
) {
|
||||||
const self = this;
|
const self = this;
|
||||||
@@ -460,9 +460,9 @@ OlmDevice.prototype.encryptMessage = function(
|
|||||||
* @param {number} message_type message_type field from the received message
|
* @param {number} message_type message_type field from the received message
|
||||||
* @param {string} ciphertext base64-encoded body from the received message
|
* @param {string} ciphertext base64-encoded body from the received message
|
||||||
*
|
*
|
||||||
* @return {string} decrypted payload.
|
* @return {Promise<string>} decrypted payload.
|
||||||
*/
|
*/
|
||||||
OlmDevice.prototype.decryptMessage = function(
|
OlmDevice.prototype.decryptMessage = async function(
|
||||||
theirDeviceIdentityKey, sessionId, message_type, ciphertext,
|
theirDeviceIdentityKey, sessionId, message_type, ciphertext,
|
||||||
) {
|
) {
|
||||||
const self = this;
|
const self = this;
|
||||||
@@ -484,10 +484,10 @@ OlmDevice.prototype.decryptMessage = function(
|
|||||||
* @param {number} message_type message_type field from the received message
|
* @param {number} message_type message_type field from the received message
|
||||||
* @param {string} ciphertext base64-encoded body 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<boolean>} true if the received message is a prekey message which matches
|
||||||
* the given session.
|
* the given session.
|
||||||
*/
|
*/
|
||||||
OlmDevice.prototype.matchesSession = function(
|
OlmDevice.prototype.matchesSession = async function(
|
||||||
theirDeviceIdentityKey, sessionId, message_type, ciphertext,
|
theirDeviceIdentityKey, sessionId, message_type, ciphertext,
|
||||||
) {
|
) {
|
||||||
if (message_type !== 0) {
|
if (message_type !== 0) {
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ OlmDecryption.prototype._decryptMessage = async function(
|
|||||||
for (let i = 0; i < sessionIds.length; i++) {
|
for (let i = 0; i < sessionIds.length; i++) {
|
||||||
const sessionId = sessionIds[i];
|
const sessionId = sessionIds[i];
|
||||||
try {
|
try {
|
||||||
const payload = this._olmDevice.decryptMessage(
|
const payload = await this._olmDevice.decryptMessage(
|
||||||
theirDeviceIdentityKey, sessionId, message.type, message.body,
|
theirDeviceIdentityKey, sessionId, message.type, message.body,
|
||||||
);
|
);
|
||||||
console.log(
|
console.log(
|
||||||
@@ -260,7 +260,7 @@ OlmDecryption.prototype._decryptMessage = async function(
|
|||||||
);
|
);
|
||||||
return payload;
|
return payload;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const foundSession = this._olmDevice.matchesSession(
|
const foundSession = await this._olmDevice.matchesSession(
|
||||||
theirDeviceIdentityKey, sessionId, message.type, message.body,
|
theirDeviceIdentityKey, sessionId, message.type, message.body,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ module.exports.encryptMessageForDevice = async function(
|
|||||||
|
|
||||||
utils.extend(payload, payloadFields);
|
utils.extend(payload, payloadFields);
|
||||||
|
|
||||||
resultsObject[deviceKey] = olmDevice.encryptMessage(
|
resultsObject[deviceKey] = await olmDevice.encryptMessage(
|
||||||
deviceKey, sessionId, JSON.stringify(payload),
|
deviceKey, sessionId, JSON.stringify(payload),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user