diff --git a/lib/types/crypto-types.js b/lib/types/crypto-types.js index d2c1cf09a..2c2fab9ac 100644 --- a/lib/types/crypto-types.js +++ b/lib/types/crypto-types.js @@ -1,11 +1,18 @@ // @flow export type OLMIdentityKeys = { +ed25519: string, +curve25519: string, }; +export type PickledOLMAccount = { + +picklingKey: string, + +pickledAccount: string, +}; + export type CryptoStore = { + +primaryAccount: ?PickledOLMAccount, +primaryIdentityKeys: ?OLMIdentityKeys, + +notificationAccount: ?PickledOLMAccount, +notificationIdentityKeys: ?OLMIdentityKeys, }; diff --git a/web/redux/crypto-store-reducer.js b/web/redux/crypto-store-reducer.js index 91b1856b6..4d0430dba 100644 --- a/web/redux/crypto-store-reducer.js +++ b/web/redux/crypto-store-reducer.js @@ -1,44 +1,46 @@ // @flow import { logOutActionTypes, deleteAccountActionTypes, } from 'lib/actions/user-actions.js'; import type { CryptoStore } from 'lib/types/crypto-types.js'; import { setNewSessionActionType } from 'lib/utils/action-utils.js'; import type { Action } from './redux-setup.js'; const setPrimaryIdentityKeys = 'SET_PRIMARY_IDENTITY_KEYS'; const setNotificationIdentityKeys = 'SET_NOTIFICATION_IDENTITY_KEYS'; function reduceCryptoStore(state: CryptoStore, action: Action): CryptoStore { if (action.type === setPrimaryIdentityKeys) { return { ...state, primaryIdentityKeys: action.payload, }; } else if (action.type === setNotificationIdentityKeys) { return { ...state, notificationIdentityKeys: action.payload, }; } else if ( action.type === logOutActionTypes.success || action.type === deleteAccountActionTypes.success || (action.type === setNewSessionActionType && action.payload.sessionChange.cookieInvalidated) ) { return { + primaryAccount: null, primaryIdentityKeys: null, + notificationAccount: null, notificationIdentityKeys: null, }; } return state; } export { setPrimaryIdentityKeys, setNotificationIdentityKeys, reduceCryptoStore, }; diff --git a/web/root.js b/web/root.js index a5f7048ed..6cf64d1ea 100644 --- a/web/root.js +++ b/web/root.js @@ -1,69 +1,71 @@ // @flow import * as React from 'react'; import { Provider } from 'react-redux'; import { Router, Route } from 'react-router'; import { createStore, applyMiddleware, type Store } from 'redux'; import { composeWithDevTools } from 'redux-devtools-extension/logOnlyInProduction.js'; import { createMigrate, persistReducer, persistStore } from 'redux-persist'; import { PersistGate } from 'redux-persist/es/integration/react.js'; import storage from 'redux-persist/es/storage/index.js'; import thunk from 'redux-thunk'; import { reduxLoggerMiddleware } from 'lib/utils/action-logger.js'; import { isDev } from 'lib/utils/dev-utils.js'; import App from './app.react.js'; import ErrorBoundary from './error-boundary.react.js'; import Loading from './loading.react.js'; import { reducer } from './redux/redux-setup.js'; import type { AppState, Action } from './redux/redux-setup.js'; import history from './router-history.js'; import Socket from './socket.react.js'; const migrations = { [1]: state => { const { primaryIdentityPublicKey, ...stateWithoutPrimaryIdentityPublicKey } = state; return { ...stateWithoutPrimaryIdentityPublicKey, cryptoStore: { + primaryAccount: null, primaryIdentityKeys: null, + notificationAccount: null, notificationIdentityKeys: null, }, }; }, }; const persistConfig = { key: 'root', storage, whitelist: ['enabledApps', 'deviceID', 'draftStore'], migrate: (createMigrate(migrations, { debug: isDev }): any), version: 1, }; declare var preloadedState: AppState; const persistedReducer = persistReducer(persistConfig, reducer); const store: Store = createStore( persistedReducer, preloadedState, composeWithDevTools({})(applyMiddleware(thunk, reduxLoggerMiddleware)), ); const persistor = persistStore(store); const RootProvider = (): React.Node => ( }> ); export default RootProvider;