You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-12-02 17:02:31 +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:
@@ -80,9 +80,9 @@ export default class VerificationBase extends EventEmitter {
|
|||||||
this._resetTimer();
|
this._resetTimer();
|
||||||
|
|
||||||
if (this.roomId) {
|
if (this.roomId) {
|
||||||
this._send = this._sendMessage;
|
this._sendWithTxnId = this._sendMessage;
|
||||||
} else {
|
} 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
|
/* send a message to the other participant, using to-device messages
|
||||||
*/
|
*/
|
||||||
_sendToDevice(type, content) {
|
_sendToDevice(type, content) {
|
||||||
if (this._done) {
|
if (this._done) {
|
||||||
return Promise.reject(new Error("Verification is already done"));
|
return Promise.reject(new Error("Verification is already done"));
|
||||||
}
|
}
|
||||||
content.transaction_id = this.transactionId;
|
|
||||||
return this._baseApis.sendToDevice(type, {
|
return this._baseApis.sendToDevice(type, {
|
||||||
[this.userId]: { [this.deviceId]: content },
|
[this.userId]: { [this.deviceId]: content },
|
||||||
});
|
});
|
||||||
@@ -124,12 +143,6 @@ export default class VerificationBase extends EventEmitter {
|
|||||||
if (this._done) {
|
if (this._done) {
|
||||||
return Promise.reject(new Error("Verification is already 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);
|
return this._baseApis.sendEvent(this.roomId, type, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ export default class SAS extends Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _doSendVerification() {
|
async _doSendVerification() {
|
||||||
const initialMessage = {
|
const initialMessage = this._contentWithTxnId({
|
||||||
method: SAS.NAME,
|
method: SAS.NAME,
|
||||||
from_device: this._baseApis.deviceId,
|
from_device: this._baseApis.deviceId,
|
||||||
key_agreement_protocols: KEY_AGREEMENT_LIST,
|
key_agreement_protocols: KEY_AGREEMENT_LIST,
|
||||||
@@ -213,10 +213,10 @@ export default class SAS extends Base {
|
|||||||
message_authentication_codes: MAC_LIST,
|
message_authentication_codes: MAC_LIST,
|
||||||
// FIXME: allow app to specify what SAS methods can be used
|
// FIXME: allow app to specify what SAS methods can be used
|
||||||
short_authentication_string: SAS_LIST,
|
short_authentication_string: SAS_LIST,
|
||||||
};
|
});
|
||||||
// NOTE: this._send will modify initialMessage to include the
|
// add the transaction id to the message beforehand because
|
||||||
// transaction_id field, or the m.relationship/m.relates_to field
|
// it needs to be included in the commitment hash later on
|
||||||
this._send("m.key.verification.start", initialMessage);
|
this._sendWithTxnId("m.key.verification.start", initialMessage);
|
||||||
|
|
||||||
|
|
||||||
let e = await this._waitForEvent("m.key.verification.accept");
|
let e = await this._waitForEvent("m.key.verification.accept");
|
||||||
|
|||||||
Reference in New Issue
Block a user