From 00c003ec6517098a2a84455b4345cb89193fcf70 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 11 Feb 2020 17:42:49 +0100 Subject: [PATCH] remove methods arg to requestVerification(DM) as it's easy to have this argument be out of sync from all the places this is called from the js-sdk. There is also little point, as you can already specify the methods a consumer of the js-sdk wants to provide through the verificationMethods option when creating the client object. --- spec/unit/crypto/verification/sas.spec.js | 2 +- src/client.js | 12 ++++-------- src/crypto/index.js | 22 ++++------------------ 3 files changed, 9 insertions(+), 27 deletions(-) diff --git a/spec/unit/crypto/verification/sas.spec.js b/spec/unit/crypto/verification/sas.spec.js index 0a65083c3..c67a11846 100644 --- a/spec/unit/crypto/verification/sas.spec.js +++ b/spec/unit/crypto/verification/sas.spec.js @@ -448,7 +448,7 @@ describe("SAS verification", function() { }); const aliceRequest = await alice.client.requestVerificationDM( - bob.client.getUserId(), "!room_id", [verificationMethods.SAS], + bob.client.getUserId(), "!room_id", ); await aliceRequest.waitFor(r => r.started); aliceVerifier = aliceRequest.verifier; diff --git a/src/client.js b/src/client.js index c64b92b68..4fecc69d5 100644 --- a/src/client.js +++ b/src/client.js @@ -907,36 +907,32 @@ async function _setDeviceVerification( * * @param {string} userId the user to request verification with * @param {string} roomId the room to use for verification - * @param {Array} methods array of verification methods to use. Defaults to - * all known methods * * @returns {Promise} resolves to a VerificationRequest * when the request has been sent to the other party. */ -MatrixClient.prototype.requestVerificationDM = function(userId, roomId, methods) { +MatrixClient.prototype.requestVerificationDM = function(userId, roomId) { if (this._crypto === null) { throw new Error("End-to-end encryption disabled"); } - return this._crypto.requestVerificationDM(userId, roomId, methods); + return this._crypto.requestVerificationDM(userId, roomId); }; /** * Request a key verification from another user. * * @param {string} userId the user to request verification with - * @param {Array} methods array of verification methods to use. Defaults to - * all known methods * @param {Array} devices array of device IDs to send requests to. Defaults to * all devices owned by the user * * @returns {Promise} resolves to a VerificationRequest * when the request has been sent to the other party. */ -MatrixClient.prototype.requestVerification = function(userId, methods, devices) { +MatrixClient.prototype.requestVerification = function(userId, devices) { if (this._crypto === null) { throw new Error("End-to-end encryption disabled"); } - return this._crypto.requestVerification(userId, methods, devices); + return this._crypto.requestVerification(userId, devices); }; /** diff --git a/src/crypto/index.js b/src/crypto/index.js index 78af9b1d1..043c4eb37 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -1619,46 +1619,32 @@ Crypto.prototype.setDeviceVerification = async function( return deviceObj; }; -Crypto.prototype.requestVerificationDM = function(userId, roomId, methods) { +Crypto.prototype.requestVerificationDM = function(userId, roomId) { const channel = new InRoomChannel(this._baseApis, roomId, userId); return this._requestVerificationWithChannel( userId, - methods, channel, this._inRoomVerificationRequests, ); }; -Crypto.prototype.requestVerification = function(userId, methods, devices) { +Crypto.prototype.requestVerification = function(userId, devices) { if (!devices) { devices = Object.keys(this._deviceList.getRawStoredDevicesForUser(userId)); } const channel = new ToDeviceChannel(this._baseApis, userId, devices); return this._requestVerificationWithChannel( userId, - methods, channel, this._toDeviceVerificationRequests, ); }; Crypto.prototype._requestVerificationWithChannel = async function( - userId, methods, channel, requestsMap, + userId, channel, requestsMap, ) { - let verificationMethods = this._verificationMethods; - if (methods) { - verificationMethods = methods.reduce((map, name) => { - const method = this._verificationMethods.get(name); - if (!method) { - throw new Error(`Verification method ${name} is not supported.`); - } else { - map.set(name, method); - } - return map; - }, new Map()); - } let request = new VerificationRequest( - channel, verificationMethods, this._baseApis); + channel, this._verificationMethods, this._baseApis); await request.sendRequest(); // don't replace the request created by a racing remote echo const racingRequest = requestsMap.getRequestByChannel(channel);