diff --git a/native/account/resolve-invalidated-cookie.js b/native/account/resolve-invalidated-cookie.js index adcddb2de..d1d4f3468 100644 --- a/native/account/resolve-invalidated-cookie.js +++ b/native/account/resolve-invalidated-cookie.js @@ -1,46 +1,49 @@ // @flow import { logInActionTypes, logIn } from 'lib/actions/user-actions.js'; import type { LogInActionSource } from 'lib/types/account-types.js'; import type { DispatchRecoveryAttempt } from 'lib/utils/action-utils.js'; import type { CallServerEndpoint } from 'lib/utils/call-server-endpoint.js'; import { fetchNativeKeychainCredentials } from './native-credentials.js'; import { getGlobalNavContext } from '../navigation/icky-global.js'; import { store } from '../redux/redux-setup.js'; import { nativeLogInExtraInfoSelector } from '../selectors/account-selectors.js'; +import type { InitialNotifMessageOptions } from '../utils/crypto-utils.js'; async function resolveInvalidatedCookie( callServerEndpoint: CallServerEndpoint, dispatchRecoveryAttempt: DispatchRecoveryAttempt, logInActionSource: LogInActionSource, - getInitialNotificationsEncryptedMessage?: () => Promise, + getInitialNotificationsEncryptedMessage?: ( + ?InitialNotifMessageOptions, + ) => Promise, ) { const keychainCredentials = await fetchNativeKeychainCredentials(); if (!keychainCredentials) { return; } let extraInfo = await nativeLogInExtraInfoSelector({ redux: store.getState(), navContext: getGlobalNavContext(), })(); if (getInitialNotificationsEncryptedMessage) { const initialNotificationsEncryptedMessage = - await getInitialNotificationsEncryptedMessage(); + await getInitialNotificationsEncryptedMessage({ callServerEndpoint }); extraInfo = { ...extraInfo, initialNotificationsEncryptedMessage }; } const { calendarQuery } = extraInfo; await dispatchRecoveryAttempt( logInActionTypes, logIn(callServerEndpoint)({ ...keychainCredentials, ...extraInfo, logInActionSource, }), { calendarQuery }, ); } export { resolveInvalidatedCookie }; diff --git a/native/utils/crypto-utils.js b/native/utils/crypto-utils.js index 215ae0c0d..1c343a393 100644 --- a/native/utils/crypto-utils.js +++ b/native/utils/crypto-utils.js @@ -1,67 +1,74 @@ // @flow import * as React from 'react'; import { getOlmSessionInitializationData, getOlmSessionInitializationDataActionTypes, } from 'lib/actions/user-actions.js'; import { useServerCall, useDispatchActionPromise, } from 'lib/utils/action-utils.js'; -import type { CallServerEndpointOptions } from 'lib/utils/call-server-endpoint.js'; +import type { + CallServerEndpoint, + CallServerEndpointOptions, +} from 'lib/utils/call-server-endpoint.js'; import { commCoreModule } from '../native-modules.js'; -type InitialNotifMessageOptions = { +export type InitialNotifMessageOptions = { + +callServerEndpoint?: ?CallServerEndpoint, +callServerEndpointOptions?: ?CallServerEndpointOptions, }; function useInitialNotificationsEncryptedMessage(): ( options?: ?InitialNotifMessageOptions, ) => Promise { const callGetOlmSessionInitializationData = useServerCall( getOlmSessionInitializationData, ); const dispatchActionPromise = useDispatchActionPromise(); return React.useCallback( async options => { + const callServerEndpoint = options?.callServerEndpoint; const callServerEndpointOptions = options?.callServerEndpointOptions; - const olmSessionDataPromise = callGetOlmSessionInitializationData( - callServerEndpointOptions, - ); + + const initDataAction = callServerEndpoint + ? getOlmSessionInitializationData(callServerEndpoint) + : callGetOlmSessionInitializationData; + const olmSessionDataPromise = initDataAction(callServerEndpointOptions); dispatchActionPromise( getOlmSessionInitializationDataActionTypes, olmSessionDataPromise, ); const { signedIdentityKeysBlob, notifInitializationInfo } = await olmSessionDataPromise; const { notificationIdentityPublicKeys } = JSON.parse( signedIdentityKeysBlob.payload, ); const { prekey, prekeySignature, oneTimeKey } = notifInitializationInfo; return await commCoreModule.initializeNotificationsSession( JSON.stringify(notificationIdentityPublicKeys), prekey, prekeySignature, oneTimeKey, ); }, [callGetOlmSessionInitializationData, dispatchActionPromise], ); } async function getContentSigningKey(): Promise { await commCoreModule.initializeCryptoAccount(); const { primaryIdentityPublicKeys: { ed25519 }, } = await commCoreModule.getUserPublicKey(); return ed25519; } export { useInitialNotificationsEncryptedMessage, getContentSigningKey };