diff --git a/lib/handlers/peer-to-peer-message-handler.js b/lib/handlers/peer-to-peer-message-handler.js --- a/lib/handlers/peer-to-peer-message-handler.js +++ b/lib/handlers/peer-to-peer-message-handler.js @@ -1,5 +1,8 @@ // @flow +import _isEqual from 'lodash/fp/isEqual.js'; + +import { verifyAndGetDeviceList } from '../shared/device-list-utils.js'; import type { IdentityServiceClient, DeviceOlmInboundKeys, @@ -127,6 +130,38 @@ } catch (e) { console.log(`Error uploading one-time keys: ${e.message}`); } + } else if (message.type === peerToPeerMessageTypes.DEVICE_LIST_UPDATED) { + try { + const result = await verifyAndGetDeviceList( + identityClient, + message.userID, + null, + ); + if (result.valid) { + console.log( + `Received valid device list update for user ${message.userID}`, + ); + const receivedRawList = JSON.parse( + message.signedDeviceList.rawDeviceList, + ); + + // additional check for broadcasted and Identity device list equality + const listsAreEqual = _isEqual(result.deviceList)(receivedRawList); + console.log( + `Identity and received device lists are ${ + listsAreEqual ? '' : 'not' + } equal.`, + ); + } else { + console.log( + `Received invalid device list update for user ${message.userID}. Reason: ${result.reason}`, + ); + } + } catch (e) { + console.log( + `Error verifying device list for user ${message.userID}: ${e}`, + ); + } } }