Skip to content

Commit

Permalink
remove methods arg to requestVerification(DM)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bwindels committed Feb 11, 2020
1 parent f4d335c commit 00c003e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 27 deletions.
2 changes: 1 addition & 1 deletion spec/unit/crypto/verification/sas.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 4 additions & 8 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<module:crypto/verification/request/VerificationRequest>} 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<module:crypto/verification/request/VerificationRequest>} 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);
};

/**
Expand Down
22 changes: 4 additions & 18 deletions src/crypto/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 00c003e

Please sign in to comment.