1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-01 04:43:29 +03:00

make it explicit that the transaction id is added for the start event

as it should included in the commitment hash
This commit is contained in:
Bruno Windels
2019-11-18 18:33:11 +01:00
parent cd735ef459
commit 24ae787736
2 changed files with 27 additions and 14 deletions

View File

@@ -80,9 +80,9 @@ export default class VerificationBase extends EventEmitter {
this._resetTimer();
if (this.roomId) {
this._send = this._sendMessage;
this._sendWithTxnId = this._sendMessage;
} else {
this._send = this._sendToDevice;
this._sendWithTxnId = this._sendToDevice;
}
}
@@ -106,13 +106,32 @@ export default class VerificationBase extends EventEmitter {
}
}
/* creates a content object with the transaction id added to it */
_contentWithTxnId(content) {
const copy = Object.assign({}, content);
if (this.roomId) { // verification as timeline event
copy["m.relates_to"] = {
rel_type: "m.reference",
event_id: this.transactionId,
};
} else { // verification as to_device event
copy.transaction_id = this.transactionId;
}
return copy;
}
_send(type, contentWithoutTxnId) {
const content = this._contentWithTxnId(contentWithoutTxnId);
return this._sendWithTxnId(type, content);
}
/* send a message to the other participant, using to-device messages
*/
_sendToDevice(type, content) {
if (this._done) {
return Promise.reject(new Error("Verification is already done"));
}
content.transaction_id = this.transactionId;
return this._baseApis.sendToDevice(type, {
[this.userId]: { [this.deviceId]: content },
});
@@ -124,12 +143,6 @@ export default class VerificationBase extends EventEmitter {
if (this._done) {
return Promise.reject(new Error("Verification is already done"));
}
// FIXME: if MSC1849 decides to use m.relationship instead of
// m.relates_to, we should follow suit here
content["m.relates_to"] = {
rel_type: "m.reference",
event_id: this.transactionId,
};
return this._baseApis.sendEvent(this.roomId, type, content);
}

View File

@@ -205,7 +205,7 @@ export default class SAS extends Base {
}
async _doSendVerification() {
const initialMessage = {
const initialMessage = this._contentWithTxnId({
method: SAS.NAME,
from_device: this._baseApis.deviceId,
key_agreement_protocols: KEY_AGREEMENT_LIST,
@@ -213,10 +213,10 @@ export default class SAS extends Base {
message_authentication_codes: MAC_LIST,
// FIXME: allow app to specify what SAS methods can be used
short_authentication_string: SAS_LIST,
};
// NOTE: this._send will modify initialMessage to include the
// transaction_id field, or the m.relationship/m.relates_to field
this._send("m.key.verification.start", initialMessage);
});
// add the transaction id to the message beforehand because
// it needs to be included in the commitment hash later on
this._sendWithTxnId("m.key.verification.start", initialMessage);
let e = await this._waitForEvent("m.key.verification.accept");