You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-29 16:43:09 +03:00
Add MatrixClient.getEventSenderDeviceInfo()
- a function to get information about the device which sent an event
This commit is contained in:
@@ -401,6 +401,21 @@ function _setDeviceVerification(client, userId, deviceId, verified, blocked) {
|
||||
client.emit("deviceVerificationChanged", userId, deviceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get e2e information on the device that sent an event
|
||||
*
|
||||
* @param {MatrixEvent} event event to be checked
|
||||
*
|
||||
* @return {module:crypto/deviceinfo?}
|
||||
*/
|
||||
MatrixClient.prototype.getEventSenderDeviceInfo = function(event) {
|
||||
if (!this._crypto) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this._crypto.getEventSenderDeviceInfo(event);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the sender of an event is verified
|
||||
*
|
||||
@@ -410,21 +425,11 @@ function _setDeviceVerification(client, userId, deviceId, verified, blocked) {
|
||||
* {@link module:client~MatrixClient#setDeviceVerified|setDeviceVerified}.
|
||||
*/
|
||||
MatrixClient.prototype.isEventSenderVerified = function(event) {
|
||||
if (!this._crypto) {
|
||||
var device = this.getEventSenderDeviceInfo(event);
|
||||
if (!device) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var sender_key = event.getSenderKey();
|
||||
|
||||
if (!sender_key) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var algorithm = event.getWireContent().algorithm;
|
||||
|
||||
return this._crypto.isSenderKeyVerified(
|
||||
event.getSender(), algorithm, sender_key
|
||||
);
|
||||
return device.isVerified();
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user