diff --git a/lib/src/omemo/device.dart b/lib/src/omemo/device.dart index f74c2e2..11d6a83 100644 --- a/lib/src/omemo/device.dart +++ b/lib/src/omemo/device.dart @@ -163,6 +163,23 @@ class Device { ); } + /// Returns a new device that is equal to this one with the exception that the new + /// device's id is a new number between 0 and 2**32 - 1. + @internal + Device withNewId() { + return Device( + jid, + generateRandom32BitNumber(), + ik, + spk, + spkId, + spkSignature, + oldSpk, + oldSpkId, + opks, + ); + } + /// Converts this device into an OmemoBundle that could be used for publishing. Future toBundle() async { final encodedOpks = {}; diff --git a/lib/src/omemo/sessionmanager.dart b/lib/src/omemo/sessionmanager.dart index 0969790..8190caf 100644 --- a/lib/src/omemo/sessionmanager.dart +++ b/lib/src/omemo/sessionmanager.dart @@ -463,6 +463,19 @@ class OmemoSessionManager { Future regenerateDevice({ int opkAmount = 100 }) async { await _deviceLock.synchronized(() async { _device = await Device.generateNewDevice(_device.jid, opkAmount: opkAmount); + + // Commit it + _eventStreamController.add(DeviceModifiedEvent(_device)); + }); + } + + /// Make our device have a new identifier. Only useful before publishing it as a bundle + /// to make sure that our device has a id that is account unique. + Future regenerateDeviceId() async { + await _deviceLock.synchronized(() async { + _device = _device.withNewId(); + + // Commit it _eventStreamController.add(DeviceModifiedEvent(_device)); }); }