SyncGate: only get asymmetricKey from UserInfo if needed.

master
Tom Hacohen 7 years ago
parent 719b0516f0
commit 8367767006

@ -43,8 +43,7 @@ const syncInfoSelector = createSelector(
(props: PropsTypeInner) => props.userInfo, (props: PropsTypeInner) => props.userInfo,
(etesync, journals, entries, userInfo) => { (etesync, journals, entries, userInfo) => {
const derived = etesync.encryptionKey; const derived = etesync.encryptionKey;
const keyPair = userInfo.getKeyPair(new EteSync.CryptoManager(derived, 'userInfo', userInfo.version)); let asymmetricCryptoManager: EteSync.AsymmetricCryptoManager;
const asymmetricCryptoManager = new EteSync.AsymmetricCryptoManager(keyPair);
return journals.reduce( return journals.reduce(
(ret, journal) => { (ret, journal) => {
const journalEntries = entries.get(journal.uid); const journalEntries = entries.get(journal.uid);
@ -56,6 +55,10 @@ const syncInfoSelector = createSelector(
let cryptoManager: EteSync.CryptoManager; let cryptoManager: EteSync.CryptoManager;
if (journal.key) { 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); const derivedJournalKey = asymmetricCryptoManager.decryptBytes(journal.key);
cryptoManager = EteSync.CryptoManager.fromDerivedKey(derivedJournalKey, journal.version); cryptoManager = EteSync.CryptoManager.fromDerivedKey(derivedJournalKey, journal.version);
} else { } else {

Loading…
Cancel
Save