diff --git a/lib/src/omemo/sessionmanager.dart b/lib/src/omemo/sessionmanager.dart index 640f53b..5df282d 100644 --- a/lib/src/omemo/sessionmanager.dart +++ b/lib/src/omemo/sessionmanager.dart @@ -48,7 +48,18 @@ class OmemoSessionManager { trustManager, ); } - + + /// Deserialise the OmemoSessionManager from JSON data [data] that does not contain + /// the ratchet sessions. + factory OmemoSessionManager.fromJsonWithoutSessions(Map data, Map ratchetMap, TrustManager trustManager) { + return OmemoSessionManager( + Device.fromJson(data['device']! as Map), + data['devices']! as Map>, + ratchetMap, + trustManager, + ); + } + /// Generate a new cryptographic identity. static Future generateNewIdentity(String jid, TrustManager trustManager, { int opkAmount = 100 }) async { assert(opkAmount > 0, 'opkAmount must be bigger than 0.'); @@ -439,4 +450,23 @@ class OmemoSessionManager { 'sessions': sessions, }; } + + /// Serialise the entire session manager into a JSON object. + Future> toJsonWithoutSessions() async { + /* + { + 'devices': { + 'alice@...': [1, 2, ...], + 'bob@...': [1], + ... + }, + 'device': { ... }, + } + */ + + return { + 'devices': _deviceMap, + 'device': await (await getDevice()).toJson(), + }; + } }