Skip to content

Commit

Permalink
return request instead of verifier from verification methods
Browse files Browse the repository at this point in the history
as MSC2366 adds an extra interactive step to the verification process,
we can't wait for the verifier after sending the request.

This is a breaking change in the js-sdk as it changes the return type
of an existing method.
  • Loading branch information
bwindels committed Dec 10, 2019
1 parent 73887df commit 2ea6880
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -895,8 +895,8 @@ MatrixClient.prototype.acceptVerificationDM = function(event, method) {
* @param {Array} devices array of device IDs to send requests to. Defaults to
* all devices owned by the user
*
* @returns {Promise<module:crypto/verification/Base>} resolves to a verifier
* when the request is accepted by the other 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) {
if (this._crypto === null) {
Expand Down
29 changes: 4 additions & 25 deletions src/crypto/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1278,48 +1278,27 @@ Crypto.prototype.setDeviceVerification = async function(
return deviceObj;
};

Crypto.prototype.requestVerificationDM = async function(userId, roomId, methods) {
Crypto.prototype.requestVerificationDM = function(userId, roomId, methods) {
const channel = new InRoomChannel(this._baseApis, roomId, userId);
const request = await this._requestVerificationWithChannel(
return this._requestVerificationWithChannel(
userId,
methods,
channel,
this._inRoomVerificationRequests,
);
return await request.waitForVerifier();
};

Crypto.prototype.acceptVerificationDM = function(event, method) {
if(!InRoomChannel.validateEvent(event, this._baseApis)) {
return;
}

const sender = event.getSender();
const requestsByTxnId = this._inRoomVerificationRequests.get(sender);
if (!requestsByTxnId) {
return;
}
const transactionId = InRoomChannel.getTransactionId(event);
const request = requestsByTxnId.get(transactionId);
if (!request) {
return;
}

return request.beginKeyVerification(method);
};

Crypto.prototype.requestVerification = async function(userId, methods, devices) {
Crypto.prototype.requestVerification = function(userId, methods, devices) {
if (!devices) {
devices = Object.keys(this._deviceList.getRawStoredDevicesForUser(userId));
}
const channel = new ToDeviceChannel(this._baseApis, userId, devices);
const request = await this._requestVerificationWithChannel(
return this._requestVerificationWithChannel(
userId,
methods,
channel,
this._toDeviceVerificationRequests,
);
return await request.waitForVerifier();
};

Crypto.prototype._requestVerificationWithChannel = async function(
Expand Down

0 comments on commit 2ea6880

Please sign in to comment.