diff --git a/lib/shared/device-list-utils.js b/lib/shared/device-list-utils.js --- a/lib/shared/device-list-utils.js +++ b/lib/shared/device-list-utils.js @@ -194,10 +194,35 @@ await updateDeviceList(signedDeviceList); } +async function removeDeviceFromDeviceList( + identityClient: IdentityServiceClient, + userID: string, + deviceIDToRemove: string, +): Promise { + const { updateDeviceList } = identityClient; + invariant( + updateDeviceList, + 'updateDeviceList() should be defined on native. ' + + 'Are you calling it on a non-primary device?', + ); + + const { devices } = await fetchLatestDeviceList(identityClient, userID); + const newDevices = devices.filter(it => it !== deviceIDToRemove); + if (devices.length === newDevices.length) { + // the device wasn't on the device list + return; + } + + const newDeviceList = composeRawDeviceList(newDevices); + const signedDeviceList = await signDeviceListUpdate(newDeviceList); + await updateDeviceList(signedDeviceList); +} + export { verifyAndGetDeviceList, createAndSignInitialDeviceList, fetchLatestDeviceList, addDeviceToDeviceList, + removeDeviceFromDeviceList, signDeviceListUpdate, };