From 0a03483aaf82def2db5a7aa41cdbd6cb95aaad88 Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Thu, 18 Aug 2022 15:02:17 +0200 Subject: [PATCH] feat: Allow regenerating one's device identity --- lib/src/omemo/sessionmanager.dart | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/src/omemo/sessionmanager.dart b/lib/src/omemo/sessionmanager.dart index 35b2a02..0969790 100644 --- a/lib/src/omemo/sessionmanager.dart +++ b/lib/src/omemo/sessionmanager.dart @@ -457,6 +457,15 @@ class OmemoSessionManager { _eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet)); }); } + + /// Generates an entirely new device. May be useful when the user wants to reset their cryptographic + /// identity. Triggers an event to commit it to storage. + Future regenerateDevice({ int opkAmount = 100 }) async { + await _deviceLock.synchronized(() async { + _device = await Device.generateNewDevice(_device.jid, opkAmount: opkAmount); + _eventStreamController.add(DeviceModifiedEvent(_device)); + }); + } @visibleForTesting OmemoDoubleRatchet getRatchet(String jid, int deviceId) => _ratchetMap[RatchetMapKey(jid, deviceId)]!;