src/crypto/DeviceList.js
/*
 * Process a device in a /query response, and add it to the userStore
 *
 * returns true if a change was made, else false
 */
Process a device in a /query response, and add it to the userStore
returns true if a change was made, else false
Process a device in a / query response and add it to the userStore returns true if a change was made else false
function _storeDeviceKeys(_olmDevice, userStore, deviceResult) {
    if (!deviceResult.keys) {
        return false;
    }
    const deviceId = deviceResult.device_id;
    const userId = deviceResult.user_id;
    const signKeyId = "ed25519:" + deviceId;
    const signKey = deviceResult.keys[signKeyId];
    if (!signKey) {
        console.log("Device " + userId + ":" + deviceId +
            " has no ed25519 key");
        return false;
    }
    const unsigned = deviceResult.unsigned || {};
    try {
        olmlib.verifySignature(_olmDevice, deviceResult, userId, deviceId, signKey);
    } catch (e) {
        console.log("Unable to verify signature on device " +
            userId + ":" + deviceId + ":", e);
        return false;
    }
    let deviceStore;
    if (deviceId in userStore) {
        deviceStore = userStore[deviceId];
        if (deviceStore.getFingerprint() != signKey) {
             Should we warn the user about it somehow?
            console.warn("Ed25519 key for device" + userId + ": " +
               deviceId + " has changed");
            return false;
        }
    } else {
        userStore[deviceId] = deviceStore = new DeviceInfo(deviceId);
    }
    deviceStore.keys = deviceResult.keys || {};
    deviceStore.algorithms = deviceResult.algorithms || [];
    deviceStore.unsigned = unsigned;
    return true;
}
function _storeDeviceKeys ( _olmDevice , userStore , deviceResult ) { if ( ! deviceResult . keys ) { return false ; } const deviceId = deviceResult . device_id ; const userId = deviceResult . user_id ; const signKeyId = "ed25519:" + deviceId ; const signKey = deviceResult . keys [ signKeyId ] ; if ( ! signKey ) { console . log ( "Device " + userId + ":" + deviceId + " has no ed25519 key" ) ; return false ; } const unsigned = deviceResult . unsigned || { } ; try { olmlib . verifySignature ( _olmDevice , deviceResult , userId , deviceId , signKey ) ; } catch ( e ) { console . log ( "Unable to verify signature on device " + userId + ":" + deviceId + ":" , e ) ; return false ; } let deviceStore ; if ( deviceId in userStore ) { deviceStore = userStore [ deviceId ] ; if ( deviceStore . getFingerprint ( ) != signKey ) { console . warn ( "Ed25519 key for device" + userId + ": " + deviceId + " has changed" ) ; return false ; } } else { userStore [ deviceId ] = deviceStore = new DeviceInfo ( deviceId ) ; } deviceStore . keys = deviceResult . keys || { } ; deviceStore . algorithms = deviceResult . algorithms || [ ] ; deviceStore . unsigned = unsigned ; return true ; }
Process a device in a /query response, and add it to the userStore
 returns true if a change was made, else false
Process a device in a / query response and add it to the userStore returns true if a change was made else false
// no keys? // DeviceInfo // already have this device. // this should only happen if the list has been MITMed; we are // best off sticking with the original keys. // // Should we warn the user about it somehow?