From 83677670067f9a8cc06fa15b1149fdfcafc52d72 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Sat, 30 Dec 2017 15:34:26 +0000 Subject: [PATCH] SyncGate: only get asymmetricKey from UserInfo if needed. --- src/SyncGate.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 {