diff --git a/src/SyncGate.tsx b/src/SyncGate.tsx index 03e0962..99ba966 100644 --- a/src/SyncGate.tsx +++ b/src/SyncGate.tsx @@ -43,8 +43,7 @@ const syncInfoSelector = createSelector( (props: PropsTypeInner) => props.userInfo, (etesync, journals, entries, userInfo) => { const derived = etesync.encryptionKey; - const keyPair = userInfo.getKeyPair(new EteSync.CryptoManager(derived, 'userInfo', userInfo.version)); - const asymmetricCryptoManager = new EteSync.AsymmetricCryptoManager(keyPair); + let asymmetricCryptoManager: EteSync.AsymmetricCryptoManager; return journals.reduce( (ret, journal) => { const journalEntries = entries.get(journal.uid); @@ -56,6 +55,10 @@ const syncInfoSelector = createSelector( let cryptoManager: EteSync.CryptoManager; if (journal.key) { + if (!asymmetricCryptoManager) { + const keyPair = userInfo.getKeyPair(new EteSync.CryptoManager(derived, 'userInfo', userInfo.version)); + asymmetricCryptoManager = new EteSync.AsymmetricCryptoManager(keyPair); + } const derivedJournalKey = asymmetricCryptoManager.decryptBytes(journal.key); cryptoManager = EteSync.CryptoManager.fromDerivedKey(derivedJournalKey, journal.version); } else {