1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-29 16:43:09 +03:00

Make a number of the crypto APIs asynchronous

Make the following return Promises:

* `MatrixClient.getStoredDevicesForUser`
* `MatrixClient.getStoredDevice`
* `MatrixClient.setDeviceVerified`
* `MatrixClient.setDeviceBlocked`
* `MatrixClient.setDeviceKnown`
* `MatrixClient.getEventSenderDeviceInfo`
* `MatrixClient.isEventSenderVerified`
* `MatrixClient.importRoomKeys`

Remove `listDeviceKeys` altogether: it's been deprecated for ages, and since
applications are going to have to be changed anyway, they might as well use its
replacement (`getStoredDevices`).
This commit is contained in:
Richard van der Hoff
2017-07-18 23:13:45 +01:00
parent d1e91cd702
commit 2ff9a36eed
3 changed files with 39 additions and 86 deletions

View File

@@ -427,31 +427,14 @@ MatrixClient.prototype.downloadKeys = function(userIds, forceDownload) {
return this._crypto.downloadKeys(userIds, forceDownload);
};
/**
* List the stored device keys for a user id
*
* @deprecated prefer {@link module:client#getStoredDevicesForUser}
*
* @param {string} userId the user to list keys for.
*
* @return {object[]} list of devices with "id", "verified", "blocked",
* "key", and "display_name" parameters.
*/
MatrixClient.prototype.listDeviceKeys = function(userId) {
if (this._crypto === null) {
throw new Error("End-to-end encryption disabled");
}
return this._crypto.listDeviceKeys(userId);
};
/**
* Get the stored device keys for a user id
*
* @param {string} userId the user to list keys for.
*
* @return {module:crypto-deviceinfo[]} list of devices
* @return {Promise<module:crypto-deviceinfo[]>} list of devices
*/
MatrixClient.prototype.getStoredDevicesForUser = function(userId) {
MatrixClient.prototype.getStoredDevicesForUser = async function(userId) {
if (this._crypto === null) {
throw new Error("End-to-end encryption disabled");
}
@@ -464,9 +447,9 @@ MatrixClient.prototype.getStoredDevicesForUser = function(userId) {
* @param {string} userId the user to list keys for.
* @param {string} deviceId unique identifier for the device
*
* @return {?module:crypto-deviceinfo} device or null
* @return {Promise<?module:crypto-deviceinfo>} device or null
*/
MatrixClient.prototype.getStoredDevice = function(userId, deviceId) {
MatrixClient.prototype.getStoredDevice = async function(userId, deviceId) {
if (this._crypto === null) {
throw new Error("End-to-end encryption disabled");
}
@@ -482,13 +465,15 @@ MatrixClient.prototype.getStoredDevice = function(userId, deviceId) {
* @param {boolean=} verified whether to mark the device as verified. defaults
* to 'true'.
*
* @returns {Promise}
*
* @fires module:client~event:MatrixClient"deviceVerificationChanged"
*/
MatrixClient.prototype.setDeviceVerified = function(userId, deviceId, verified) {
if (verified === undefined) {
verified = true;
}
_setDeviceVerification(this, userId, deviceId, verified, null);
return _setDeviceVerification(this, userId, deviceId, verified, null);
};
/**
@@ -500,13 +485,15 @@ MatrixClient.prototype.setDeviceVerified = function(userId, deviceId, verified)
* @param {boolean=} blocked whether to mark the device as blocked. defaults
* to 'true'.
*
* @returns {Promise}
*
* @fires module:client~event:MatrixClient"deviceVerificationChanged"
*/
MatrixClient.prototype.setDeviceBlocked = function(userId, deviceId, blocked) {
if (blocked === undefined) {
blocked = true;
}
_setDeviceVerification(this, userId, deviceId, null, blocked);
return _setDeviceVerification(this, userId, deviceId, null, blocked);
};
/**
@@ -518,16 +505,20 @@ MatrixClient.prototype.setDeviceBlocked = function(userId, deviceId, blocked) {
* @param {boolean=} known whether to mark the device as known. defaults
* to 'true'.
*
* @returns {Promise}
*
* @fires module:client~event:MatrixClient"deviceVerificationChanged"
*/
MatrixClient.prototype.setDeviceKnown = function(userId, deviceId, known) {
if (known === undefined) {
known = true;
}
_setDeviceVerification(this, userId, deviceId, null, null, known);
return _setDeviceVerification(this, userId, deviceId, null, null, known);
};
function _setDeviceVerification(client, userId, deviceId, verified, blocked, known) {
async function _setDeviceVerification(
client, userId, deviceId, verified, blocked, known,
) {
if (!client._crypto) {
throw new Error("End-to-End encryption disabled");
}
@@ -568,9 +559,9 @@ MatrixClient.prototype.getGlobalBlacklistUnverifiedDevices = function() {
*
* @param {MatrixEvent} event event to be checked
*
* @return {module:crypto/deviceinfo?}
* @return {Promise<module:crypto/deviceinfo?>}
*/
MatrixClient.prototype.getEventSenderDeviceInfo = function(event) {
MatrixClient.prototype.getEventSenderDeviceInfo = async function(event) {
if (!this._crypto) {
return null;
}
@@ -586,8 +577,8 @@ MatrixClient.prototype.getEventSenderDeviceInfo = function(event) {
* @return {boolean} true if the sender of this event has been verified using
* {@link module:client~MatrixClient#setDeviceVerified|setDeviceVerified}.
*/
MatrixClient.prototype.isEventSenderVerified = function(event) {
const device = this.getEventSenderDeviceInfo(event);
MatrixClient.prototype.isEventSenderVerified = async function(event) {
const device = await this.getEventSenderDeviceInfo(event);
if (!device) {
return false;
}
@@ -641,7 +632,7 @@ MatrixClient.prototype.exportRoomKeys = function() {
*
* @param {Object[]} keys a list of session export objects
*/
MatrixClient.prototype.importRoomKeys = function(keys) {
MatrixClient.prototype.importRoomKeys = async function(keys) {
if (!this._crypto) {
throw new Error("End-to-end encryption disabled");
}