diff --git a/src/Pim/index.tsx b/src/Pim/index.tsx
index f68dc3c..dcb08c5 100644
--- a/src/Pim/index.tsx
+++ b/src/Pim/index.tsx
@@ -26,7 +26,7 @@ import PimMain from './PimMain';
import { routeResolver } from '../App';
-import { store, CredentialsData } from '../store';
+import { store, CredentialsData, UserInfoData } from '../store';
import { SyncInfo } from '../SyncGate';
@@ -193,6 +193,7 @@ const CollectionRoutes = withRouter(
class Pim extends React.PureComponent {
props: {
etesync: CredentialsData;
+ userInfo: UserInfoData;
syncInfo: SyncInfo;
history: History;
};
@@ -215,7 +216,8 @@ class Pim extends React.PureComponent {
let action = (originalEvent === undefined) ? EteSync.SyncEntryAction.Add : EteSync.SyncEntryAction.Change;
let saveEvent = store.dispatch(
- createJournalEntry(this.props.etesync, journal, syncJournal.journalEntries, action, item.toIcal()));
+ createJournalEntry(
+ this.props.etesync, this.props.userInfo, journal, syncJournal.journalEntries, action, item.toIcal()));
(saveEvent as any).then(() => {
this.props.history.goBack();
});
@@ -232,7 +234,8 @@ class Pim extends React.PureComponent {
let action = EteSync.SyncEntryAction.Delete;
let deleteItem = store.dispatch(
- createJournalEntry(this.props.etesync, journal, syncJournal.journalEntries, action, item.toIcal()));
+ createJournalEntry(
+ this.props.etesync, this.props.userInfo, journal, syncJournal.journalEntries, action, item.toIcal()));
(deleteItem as any).then(() => {
this.props.history.push(routeResolver.getRoute('pim'));
});
diff --git a/src/SyncGate.tsx b/src/SyncGate.tsx
index 90b1bd7..08e1e02 100644
--- a/src/SyncGate.tsx
+++ b/src/SyncGate.tsx
@@ -157,6 +157,7 @@ class SyncGate extends React.PureComponent {
render={({match, history}) => (
diff --git a/src/etesync-helpers.ts b/src/etesync-helpers.ts
index dfb3c9c..c60e879 100644
--- a/src/etesync-helpers.ts
+++ b/src/etesync-helpers.ts
@@ -2,11 +2,12 @@ import { List } from 'immutable';
import * as EteSync from './api/EteSync';
-import { CredentialsData } from './store';
+import { CredentialsData, UserInfoData } from './store';
import { createEntries } from './store/actions';
export function createJournalEntry(
etesync: CredentialsData,
+ userInfo: UserInfoData,
journal: EteSync.Journal,
existingEntries: List,
action: EteSync.SyncEntryAction,
@@ -26,7 +27,15 @@ export function createJournalEntry(
prevUid = last.uid;
}
- const cryptoManager = new EteSync.CryptoManager(derived, journal.uid, journal.version);
+ let cryptoManager: EteSync.CryptoManager;
+ if (journal.key) {
+ const keyPair = userInfo.getKeyPair(new EteSync.CryptoManager(derived, 'userInfo', userInfo.version));
+ const asymmetricCryptoManager = new EteSync.AsymmetricCryptoManager(keyPair);
+ const derivedJournalKey = asymmetricCryptoManager.decryptBytes(journal.key);
+ cryptoManager = EteSync.CryptoManager.fromDerivedKey(derivedJournalKey, journal.version);
+ } else {
+ cryptoManager = new EteSync.CryptoManager(derived, journal.uid, journal.version);
+ }
let entry = new EteSync.Entry();
entry.setSyncEntry(cryptoManager, syncEntry, prevUid);