private async Task HandleMismatchedDevices(CancellationToken token, PushServiceSocket socket, SignalServiceAddress recipient, MismatchedDevices mismatchedDevices) { try { foreach (uint extraDeviceId in mismatchedDevices.ExtraDevices) { store.DeleteSession(new SignalProtocolAddress(recipient.E164number, extraDeviceId)); } foreach (uint missingDeviceId in mismatchedDevices.MissingDevices) { PreKeyBundle preKey = await socket.GetPreKey(token, recipient, missingDeviceId); try { SessionBuilder sessionBuilder = new SessionBuilder(store, new SignalProtocolAddress(recipient.E164number, missingDeviceId)); sessionBuilder.process(preKey); } catch (libsignal.exceptions.UntrustedIdentityException) { throw new UntrustedIdentityException("Untrusted identity key!", recipient.E164number, preKey.getIdentityKey()); } } } catch (InvalidKeyException e) { throw new Exception(e.Message); } }