diff --git a/lib/keyserver-conn/recovery-utils.js b/lib/keyserver-conn/recovery-utils.js --- a/lib/keyserver-conn/recovery-utils.js +++ b/lib/keyserver-conn/recovery-utils.js @@ -47,7 +47,6 @@ recoveryActionSource: RecoveryActionSource, keyserverID: string, getInitialNotificationsEncryptedMessage?: ( - keyserverID: string, options?: ?InitialNotifMessageOptions, ) => Promise, ): Promise { diff --git a/lib/selectors/socket-selectors.js b/lib/selectors/socket-selectors.js --- a/lib/selectors/socket-selectors.js +++ b/lib/selectors/socket-selectors.js @@ -96,9 +96,7 @@ ) => ( calendarActive: boolean, getSignedIdentityKeysBlob: () => Promise, - getInitialNotificationsEncryptedMessage: ?( - keyserverID: string, - ) => Promise, + getInitialNotificationsEncryptedMessage: () => Promise, serverRequests: $ReadOnlyArray, ) => Promise<$ReadOnlyArray> = createSelector( boundStateSyncSpecsSelector, @@ -112,9 +110,7 @@ return async ( calendarActive: boolean, getSignedIdentityKeysBlob: () => Promise, - getInitialNotificationsEncryptedMessage: ?( - keyserverID: string, - ) => Promise, + getInitialNotificationsEncryptedMessage: () => Promise, serverRequests: $ReadOnlyArray, ): Promise<$ReadOnlyArray> => { const clientResponses = []; @@ -202,11 +198,10 @@ }); } else if ( serverRequest.type === - serverRequestTypes.INITIAL_NOTIFICATIONS_ENCRYPTED_MESSAGE && - getInitialNotificationsEncryptedMessage + serverRequestTypes.INITIAL_NOTIFICATIONS_ENCRYPTED_MESSAGE ) { const initialNotificationsEncryptedMessage = - await getInitialNotificationsEncryptedMessage(keyserverID); + await getInitialNotificationsEncryptedMessage(); clientResponses.push({ type: serverRequestTypes.INITIAL_NOTIFICATIONS_ENCRYPTED_MESSAGE, initialNotificationsEncryptedMessage, diff --git a/lib/shared/crypto-utils.js b/lib/shared/crypto-utils.js --- a/lib/shared/crypto-utils.js +++ b/lib/shared/crypto-utils.js @@ -1,17 +1,15 @@ // @flow +import invariant from 'invariant'; import * as React from 'react'; import { getOlmSessionInitializationData, getOlmSessionInitializationDataActionTypes, } from '../actions/user-actions.js'; -import type { - OLMIdentityKeys, - OLMOneTimeKeys, - OLMPrekey, -} from '../types/crypto-types'; -import type { OlmSessionInitializationInfo } from '../types/request-types'; +import { cookieSelector } from '../selectors/keyserver-selectors.js'; +import { OlmSessionCreatorContext } from '../shared/olm-session-creator-context.js'; +import type { OLMOneTimeKeys, OLMPrekey } from '../types/crypto-types.js'; import { useLegacyAshoatKeyserverCall } from '../utils/action-utils.js'; import type { CallSingleKeyserverEndpointOptions, @@ -19,6 +17,7 @@ } from '../utils/call-single-keyserver-endpoint.js'; import { values } from '../utils/objects.js'; import { useDispatchActionPromise } from '../utils/redux-promise-utils.js'; +import { useSelector } from '../utils/redux-utils.js'; export type InitialNotifMessageOptions = { +callSingleKeyserverEndpoint?: ?CallSingleKeyserverEndpoint, @@ -30,22 +29,21 @@ }; function useInitialNotificationsEncryptedMessage( - platformSpecificSessionCreator: ( - notificationsIdentityKeys: OLMIdentityKeys, - notificationsInitializationInfo: OlmSessionInitializationInfo, - keyserverID: string, - ) => Promise, -): ( keyserverID: string, - options?: ?InitialNotifMessageOptions, -) => Promise { +): (options?: ?InitialNotifMessageOptions) => Promise { const callGetOlmSessionInitializationData = useLegacyAshoatKeyserverCall( getOlmSessionInitializationData, ); const dispatchActionPromise = useDispatchActionPromise(); + const cookie = useSelector(cookieSelector(keyserverID)); + + const olmSessionCreator = React.useContext(OlmSessionCreatorContext); + invariant(olmSessionCreator, 'Olm session creator should be set'); + const { notificationsSessionCreator } = olmSessionCreator; + return React.useCallback( - async (keyserverID, options) => { + async options => { const callSingleKeyserverEndpoint = options?.callSingleKeyserverEndpoint; const callSingleKeyserverEndpointOptions = options?.callSingleKeyserverEndpointOptions; @@ -69,7 +67,8 @@ signedIdentityKeysBlob.payload, ); - return await platformSpecificSessionCreator( + return await notificationsSessionCreator( + cookie, notificationIdentityPublicKeys, notifInitializationInfo, keyserverID, @@ -78,7 +77,9 @@ [ callGetOlmSessionInitializationData, dispatchActionPromise, - platformSpecificSessionCreator, + notificationsSessionCreator, + cookie, + keyserverID, ], ); } diff --git a/lib/utils/config.js b/lib/utils/config.js --- a/lib/utils/config.js +++ b/lib/utils/config.js @@ -20,7 +20,6 @@ recoveryActionSource: RecoveryActionSource, keyserverID: string, getInitialNotificationsEncryptedMessage?: ( - keyserverID: string, options?: ?InitialNotifMessageOptions, ) => Promise, ) => Promise, diff --git a/native/account/legacy-recover-keyserver-session.js b/native/account/legacy-recover-keyserver-session.js --- a/native/account/legacy-recover-keyserver-session.js +++ b/native/account/legacy-recover-keyserver-session.js @@ -20,7 +20,6 @@ recoveryActionSource: RecoveryActionSource, keyserverID: string, getInitialNotificationsEncryptedMessage?: ( - keyserverID: string, ?InitialNotifMessageOptions, ) => Promise, ) { @@ -32,7 +31,7 @@ if (getInitialNotificationsEncryptedMessage) { const initialNotificationsEncryptedMessage = - await getInitialNotificationsEncryptedMessage(keyserverID, { + await getInitialNotificationsEncryptedMessage({ callSingleKeyserverEndpoint, }); extraInfo = { ...extraInfo, initialNotificationsEncryptedMessage }; diff --git a/native/account/log-in-panel.react.js b/native/account/log-in-panel.react.js --- a/native/account/log-in-panel.react.js +++ b/native/account/log-in-panel.react.js @@ -54,7 +54,6 @@ UserNotFoundAlertDetails, } from '../utils/alert-messages.js'; import Alert from '../utils/alert.js'; -import { nativeNotificationsSessionCreator } from '../utils/crypto-utils.js'; import type { StateContainer } from '../utils/state-container.js'; export type LogInState = { @@ -76,9 +75,7 @@ username: string, password: string, ) => Promise, - +getInitialNotificationsEncryptedMessage: ( - keyserverID: string, - ) => Promise, + +getInitialNotificationsEncryptedMessage: () => Promise, }; class LogInPanel extends React.PureComponent { usernameInput: ?TextInput; @@ -253,9 +250,7 @@ Keyboard.dismiss(); const extraInfo = await this.props.logInExtraInfo(); const initialNotificationsEncryptedMessage = - await this.props.getInitialNotificationsEncryptedMessage( - authoritativeKeyserverID, - ); + await this.props.getInitialNotificationsEncryptedMessage(); if (usingCommServicesAccessToken) { void this.props.dispatchActionPromise( @@ -444,9 +439,7 @@ const callLegacyLogIn = useLogIn(); const callIdentityPasswordLogIn = useIdentityPasswordLogIn(); const getInitialNotificationsEncryptedMessage = - useInitialNotificationsEncryptedMessage( - nativeNotificationsSessionCreator, - ); + useInitialNotificationsEncryptedMessage(authoritativeKeyserverID); return ( Promise, - +getInitialNotificationsEncryptedMessage: ( - keyserverID: string, - ) => Promise, + +getInitialNotificationsEncryptedMessage: () => Promise, }; type State = { +confirmPasswordFocused: boolean, @@ -311,9 +308,7 @@ Keyboard.dismiss(); const extraInfo = await this.props.logInExtraInfo(); const initialNotificationsEncryptedMessage = - await this.props.getInitialNotificationsEncryptedMessage( - authoritativeKeyserverID, - ); + await this.props.getInitialNotificationsEncryptedMessage(); void this.props.dispatchActionPromise( keyserverRegisterActionTypes, this.registerAction({ @@ -492,9 +487,7 @@ const dispatchActionPromise = useDispatchActionPromise(); const callRegister = useLegacyAshoatKeyserverCall(keyserverRegister); const getInitialNotificationsEncryptedMessage = - useInitialNotificationsEncryptedMessage( - nativeNotificationsSessionCreator, - ); + useInitialNotificationsEncryptedMessage(authoritativeKeyserverID); return ( { const extraInfo = await logInExtraInfo(); const initialNotificationsEncryptedMessage = - await getInitialNotificationsEncryptedMessage( - authoritativeKeyserverID, - { - callSingleKeyserverEndpointOptions, - }, - ); + await getInitialNotificationsEncryptedMessage({ + callSingleKeyserverEndpointOptions, + }); const siwePromise = callSIWE( message, diff --git a/native/data/sqlite-data-handler.js b/native/data/sqlite-data-handler.js --- a/native/data/sqlite-data-handler.js +++ b/native/data/sqlite-data-handler.js @@ -31,7 +31,6 @@ import { setStoreLoadedActionType } from '../redux/action-types.js'; import { useSelector } from '../redux/redux-utils.js'; import Alert from '../utils/alert.js'; -import { nativeNotificationsSessionCreator } from '../utils/crypto-utils.js'; import { isTaskCancelledError } from '../utils/error-handling.js'; import { useStaffCanSee } from '../utils/staff-utils.js'; @@ -62,7 +61,7 @@ ); const mediaCacheContext = React.useContext(MediaCacheContext); const getInitialNotificationsEncryptedMessage = - useInitialNotificationsEncryptedMessage(nativeNotificationsSessionCreator); + useInitialNotificationsEncryptedMessage(authoritativeKeyserverID); const callFetchNewCookieFromNativeCredentials = React.useCallback( async (source: RecoveryActionSource) => { diff --git a/native/selectors/socket-selectors.js b/native/selectors/socket-selectors.js --- a/native/selectors/socket-selectors.js +++ b/native/selectors/socket-selectors.js @@ -49,10 +49,8 @@ type NativeGetClientResponsesSelectorInputType = $ReadOnly<{ ...NavPlusRedux, - getInitialNotificationsEncryptedMessage: ( - keyserverID: string, - ) => Promise, - keyserverID: string, + +getInitialNotificationsEncryptedMessage: () => Promise, + +keyserverID: string, }>; const nativeGetClientResponsesSelector: ( @@ -70,15 +68,11 @@ getClientResponsesFunc: ( calendarActive: boolean, getSignedIdentityKeysBlob: () => Promise, - getInitialNotificationsEncryptedMessage: ?( - keyserverID: string, - ) => Promise, + getInitialNotificationsEncryptedMessage: () => Promise, serverRequests: $ReadOnlyArray, ) => Promise<$ReadOnlyArray>, calendarActive: boolean, - getInitialNotificationsEncryptedMessage: ( - keyserverID: string, - ) => Promise, + getInitialNotificationsEncryptedMessage: () => Promise, ) => (serverRequests: $ReadOnlyArray) => getClientResponsesFunc( diff --git a/native/socket.react.js b/native/socket.react.js --- a/native/socket.react.js +++ b/native/socket.react.js @@ -32,7 +32,6 @@ nativeSessionStateFuncSelector, } from './selectors/socket-selectors.js'; import Alert from './utils/alert.js'; -import { nativeNotificationsSessionCreator } from './utils/crypto-utils.js'; import { decompressMessage } from './utils/decompress.js'; const NativeSocket: React.ComponentType = @@ -63,9 +62,7 @@ ); const getInitialNotificationsEncryptedMessage = - useInitialNotificationsEncryptedMessage( - nativeNotificationsSessionCreator, - ); + useInitialNotificationsEncryptedMessage(keyserverID); const getClientResponses = useSelector(state => nativeGetClientResponsesSelector({ diff --git a/web/account/account-hooks.js b/web/account/account-hooks.js --- a/web/account/account-hooks.js +++ b/web/account/account-hooks.js @@ -409,23 +409,10 @@ ); } -function useWebNotificationsSessionCreator(): ( - cookie: ?string, - notificationsIdentityKeys: OLMIdentityKeys, - notificationsInitializationInfo: OlmSessionInitializationInfo, - keyserverID: string, -) => Promise { - const context = React.useContext(OlmSessionCreatorContext); - invariant(context, 'WebNotificationsSessionCreator not found.'); - - return context.notificationsSessionCreator; -} - export { useGetSignedIdentityKeysBlob, useGetOrCreateCryptoStore, OlmSessionCreatorProvider, - useWebNotificationsSessionCreator, GetOrCreateCryptoStoreProvider, useGetDeviceKeyUpload, }; diff --git a/web/selectors/socket-selectors.js b/web/selectors/socket-selectors.js --- a/web/selectors/socket-selectors.js +++ b/web/selectors/socket-selectors.js @@ -44,9 +44,7 @@ type WebGetClientResponsesSelectorInputType = { +state: AppState, +getSignedIdentityKeysBlob: () => Promise, - +getInitialNotificationsEncryptedMessage: ( - keyserverID: string, - ) => Promise, + +getInitialNotificationsEncryptedMessage: () => Promise, +keyserverID: string, }; @@ -67,16 +65,12 @@ getClientResponsesFunc: ( calendarActive: boolean, getSignedIdentityKeysBlob: () => Promise, - getInitialNotificationsEncryptedMessage: ( - keyserverID: string, - ) => Promise, + getInitialNotificationsEncryptedMessage: () => Promise, serverRequests: $ReadOnlyArray, ) => Promise<$ReadOnlyArray>, getSignedIdentityKeysBlob: () => Promise, calendarActive: boolean, - getInitialNotificationsEncryptedMessage: ( - keyserverID: string, - ) => Promise, + getInitialNotificationsEncryptedMessage: () => Promise, ) => (serverRequests: $ReadOnlyArray) => getClientResponsesFunc( diff --git a/web/socket.react.js b/web/socket.react.js --- a/web/socket.react.js +++ b/web/socket.react.js @@ -12,15 +12,10 @@ import { openSocketSelector } from 'lib/selectors/socket-selectors.js'; import { useInitialNotificationsEncryptedMessage } from 'lib/shared/crypto-utils.js'; import Socket, { type BaseSocketProps } from 'lib/socket/socket.react.js'; -import type { OLMIdentityKeys } from 'lib/types/crypto-types.js'; -import type { OlmSessionInitializationInfo } from 'lib/types/request-types.js'; import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js'; import { useDispatch } from 'lib/utils/redux-utils.js'; -import { - useGetSignedIdentityKeysBlob, - useWebNotificationsSessionCreator, -} from './account/account-hooks.js'; +import { useGetSignedIdentityKeysBlob } from './account/account-hooks.js'; import { useSelector } from './redux/redux-utils.js'; import { activeThreadSelector, @@ -56,22 +51,8 @@ preRequestUserStateForSingleKeyserverSelector(keyserverID), ); const getSignedIdentityKeysBlob = useGetSignedIdentityKeysBlob(); - const webNotificationsSessionCreator = useWebNotificationsSessionCreator(); - const webNotifsSessionCreatorForCookie = React.useCallback( - async ( - notificationsIdentityKeys: OLMIdentityKeys, - notificationsInitializationInfo: OlmSessionInitializationInfo, - ) => - webNotificationsSessionCreator( - cookie, - notificationsIdentityKeys, - notificationsInitializationInfo, - keyserverID, - ), - [webNotificationsSessionCreator, cookie, keyserverID], - ); const getInitialNotificationsEncryptedMessage = - useInitialNotificationsEncryptedMessage(webNotifsSessionCreatorForCookie); + useInitialNotificationsEncryptedMessage(keyserverID); const getClientResponses = useSelector(state => webGetClientResponsesSelector({ state,