Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3724387
D14090.id46578.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
11 KB
Referenced Files
None
Subscribers
None
D14090.id46578.diff
View Options
diff --git a/native/account/restore-backup-screen.react.js b/native/account/restore-backup-screen.react.js
--- a/native/account/restore-backup-screen.react.js
+++ b/native/account/restore-backup-screen.react.js
@@ -16,7 +16,7 @@
};
export type RestoreBackupScreenParams = {
- +username: string,
+ +userIdentifier: string,
+credentials:
| {
+type: 'password',
@@ -24,6 +24,7 @@
}
| {
+type: 'siwe',
+ +secret: string,
+message: string,
+signature: string,
},
diff --git a/native/account/restore-password-account-screen.react.js b/native/account/restore-password-account-screen.react.js
--- a/native/account/restore-password-account-screen.react.js
+++ b/native/account/restore-password-account-screen.react.js
@@ -31,7 +31,7 @@
const onProceed = React.useCallback(() => {
if (areCredentialsPresent) {
props.navigation.navigate(RestoreBackupScreenRouteName, {
- username,
+ userIdentifier: username,
credentials: {
type: 'password',
password,
diff --git a/native/account/restore-prompt-screen.react.js b/native/account/restore-prompt-screen.react.js
--- a/native/account/restore-prompt-screen.react.js
+++ b/native/account/restore-prompt-screen.react.js
@@ -3,6 +3,9 @@
import * as React from 'react';
import { Text, View } from 'react-native';
+import type { SIWEResult } from 'lib/types/siwe-types.js';
+import { getMessageForException } from 'lib/utils/errors.js';
+
import PromptButton from './prompt-button.react.js';
import RegistrationButtonContainer from './registration/registration-button-container.react.js';
import RegistrationContainer from './registration/registration-container.react.js';
@@ -10,9 +13,15 @@
import type { SignInNavigationProp } from './sign-in-navigator.react';
import { useSIWEPanelState } from './siwe-hooks.js';
import SIWEPanel from './siwe-panel.react.js';
+import { useClientBackup } from '../backup/use-client-backup.js';
import type { NavigationRoute } from '../navigation/route-names';
-import { RestorePasswordAccountScreenRouteName } from '../navigation/route-names.js';
+import {
+ RestoreSIWEBackupRouteName,
+ RestorePasswordAccountScreenRouteName,
+} from '../navigation/route-names.js';
import { useColors, useStyles } from '../themes/colors.js';
+import { unknownErrorAlertDetails } from '../utils/alert-messages.js';
+import Alert from '../utils/alert.js';
import RestoreIcon from '../vectors/restore-icon.react.js';
type Props = {
@@ -31,6 +40,49 @@
props.navigation.navigate(RestorePasswordAccountScreenRouteName);
}, [props.navigation]);
+ const { retrieveLatestBackupInfo } = useClientBackup();
+ const onSIWESuccess = React.useCallback(
+ async (result: SIWEResult) => {
+ try {
+ const { address, signature, message } = result;
+ const backupInfo = await retrieveLatestBackupInfo(address);
+ const { siweBackupData } = backupInfo;
+
+ if (!siweBackupData) {
+ throw new Error('Missing SIWE message for Wallet user backup');
+ }
+
+ const {
+ siweBackupMsgNonce,
+ siweBackupMsgIssuedAt,
+ siweBackupMsgStatement,
+ } = siweBackupData;
+
+ props.navigation.navigate(RestoreSIWEBackupRouteName, {
+ siweNonce: siweBackupMsgNonce,
+ siweStatement: siweBackupMsgStatement,
+ siweIssuedAt: siweBackupMsgIssuedAt,
+ userIdentifier: address,
+ signature,
+ message,
+ });
+ } catch (e) {
+ const messageForException = getMessageForException(e);
+ console.log(
+ `SIWE restore error: ${messageForException ?? 'unknown error'}`,
+ );
+ const alertDetails = unknownErrorAlertDetails;
+ Alert.alert(
+ alertDetails.title,
+ alertDetails.message,
+ [{ text: 'OK', onPress: props.navigation.goBack }],
+ { cancelable: false },
+ );
+ }
+ },
+ [props.navigation, retrieveLatestBackupInfo],
+ );
+
const {
panelState,
openPanel,
@@ -45,7 +97,7 @@
onClosing={onPanelClosing}
onClosed={onPanelClosed}
closing={panelState === 'closing'}
- onSuccessfulWalletSignature={() => {}}
+ onSuccessfulWalletSignature={onSIWESuccess}
siweSignatureRequestData={siweSignatureRequestData}
setLoading={siwePanelSetLoading}
/>
diff --git a/native/backup/restore-siwe-backup.react.js b/native/backup/restore-siwe-backup.react.js
--- a/native/backup/restore-siwe-backup.react.js
+++ b/native/backup/restore-siwe-backup.react.js
@@ -1,24 +1,23 @@
// @flow
import * as React from 'react';
-import { Alert } from 'react-native';
import { type SIWEResult } from 'lib/types/siwe-types.js';
-import { getMessageForException } from 'lib/utils/errors.js';
-import { useClientBackup } from './use-client-backup.js';
import { SignSIWEBackupMessageForRestore } from '../account/registration/siwe-backup-message-creation.react.js';
-import { commCoreModule } from '../native-modules.js';
import { type RootNavigationProp } from '../navigation/root-navigator.react.js';
-import { type NavigationRoute } from '../navigation/route-names.js';
-import { persistConfig } from '../redux/persist.js';
+import {
+ type NavigationRoute,
+ RestoreBackupScreenRouteName,
+} from '../navigation/route-names.js';
export type RestoreSIWEBackupParams = {
- +backupID: string,
+siweNonce: string,
+siweStatement: string,
+siweIssuedAt: string,
+userIdentifier: string,
+ +signature: string,
+ +message: string,
};
type Props = {
@@ -31,44 +30,28 @@
const { route } = props;
const {
params: {
- backupID,
siweStatement,
siweIssuedAt,
siweNonce,
userIdentifier,
+ signature,
+ message,
},
} = route;
- const { getBackupUserKeys } = useClientBackup();
-
const onSuccessfulWalletSignature = React.useCallback(
(result: SIWEResult) => {
- void (async () => {
- const { signature } = result;
- let message = 'success';
- try {
- const { backupDataKey, backupLogDataKey } = await getBackupUserKeys(
- userIdentifier,
- signature,
- backupID,
- );
- await commCoreModule.restoreBackupData(
- backupID,
- backupDataKey,
- backupLogDataKey,
- persistConfig.version.toString(),
- );
- } catch (e) {
- message = `Backup restore error: ${String(
- getMessageForException(e),
- )}`;
- console.error(message);
- }
- Alert.alert('Restore protocol result', message);
- goBack();
- })();
+ props.navigation.navigate(RestoreBackupScreenRouteName, {
+ userIdentifier,
+ credentials: {
+ type: 'siwe',
+ secret: result.signature,
+ message,
+ signature,
+ },
+ });
},
- [backupID, getBackupUserKeys, goBack, userIdentifier],
+ [message, props.navigation, signature, userIdentifier],
);
return (
diff --git a/native/profile/backup-menu.react.js b/native/profile/backup-menu.react.js
--- a/native/profile/backup-menu.react.js
+++ b/native/profile/backup-menu.react.js
@@ -1,12 +1,10 @@
// @flow
-import { useNavigation } from '@react-navigation/native';
import invariant from 'invariant';
import * as React from 'react';
import { Switch, Text, View } from 'react-native';
import { ScrollView } from 'react-native-gesture-handler';
-import { accountHasPassword } from 'lib/shared/account-utils.js';
import { IdentityClientContext } from 'lib/shared/identity-client-context.js';
import { getConfig } from 'lib/utils/config.js';
import { rawDeviceListFromSignedList } from 'lib/utils/device-list-utils.js';
@@ -19,9 +17,7 @@
import Button from '../components/button.react.js';
import { commCoreModule } from '../native-modules.js';
import type { NavigationRoute } from '../navigation/route-names.js';
-import { RestoreSIWEBackupRouteName } from '../navigation/route-names.js';
import { setLocalSettingsActionType } from '../redux/action-types.js';
-import { persistConfig } from '../redux/persist.js';
import { useSelector } from '../redux/redux-utils.js';
import { useColors, useStyles } from '../themes/colors.js';
import Alert from '../utils/alert.js';
@@ -36,7 +32,6 @@
const dispatch = useDispatch();
const colors = useColors();
const currentUserInfo = useSelector(state => state.currentUserInfo);
- const navigation = useNavigation();
const getBackupSecret = useGetBackupSecretForLoggedInUser();
const isBackupEnabled = useSelector(
@@ -81,37 +76,6 @@
Alert.alert('Upload User Keys result', message);
}, [createUserKeysBackup]);
- const testRestoreForPasswordUser = React.useCallback(async () => {
- let message = 'success';
- try {
- const [{ backupID }, backupSecret] = await Promise.all([
- retrieveLatestBackupInfo(userIdentifier),
- getBackupSecret(),
- ]);
- const { backupDataKey, backupLogDataKey } = await getBackupUserKeys(
- userIdentifier,
- backupSecret,
- backupID,
- );
- await commCoreModule.restoreBackupData(
- backupID,
- backupDataKey,
- backupLogDataKey,
- persistConfig.version.toString(),
- );
- console.info('Backup restored.');
- } catch (e) {
- message = `Backup restore error: ${String(getMessageForException(e))}`;
- console.error(message);
- }
- Alert.alert('Restore protocol result', message);
- }, [
- getBackupSecret,
- getBackupUserKeys,
- retrieveLatestBackupInfo,
- userIdentifier,
- ]);
-
const testLatestBackupInfo = React.useCallback(async () => {
let message;
try {
@@ -226,38 +190,6 @@
getBackupUserKeys,
]);
- const testRestoreForSIWEUser = React.useCallback(async () => {
- let message = 'success';
- try {
- const { siweBackupData, backupID } =
- await retrieveLatestBackupInfo(userIdentifier);
-
- if (!siweBackupData) {
- throw new Error('Missing SIWE message for Wallet user backup');
- }
-
- const {
- siweBackupMsgNonce,
- siweBackupMsgIssuedAt,
- siweBackupMsgStatement,
- } = siweBackupData;
-
- navigation.navigate<'RestoreSIWEBackup'>({
- name: RestoreSIWEBackupRouteName,
- params: {
- backupID,
- siweNonce: siweBackupMsgNonce,
- siweStatement: siweBackupMsgStatement,
- siweIssuedAt: siweBackupMsgIssuedAt,
- userIdentifier,
- },
- });
- } catch (e) {
- message = `Backup restore error: ${String(getMessageForException(e))}`;
- console.error(message);
- }
- }, [retrieveLatestBackupInfo, userIdentifier, navigation]);
-
const onBackupToggled = React.useCallback(
(value: boolean) => {
dispatch({
@@ -268,10 +200,6 @@
[dispatch],
);
- const onPressRestoreButton = accountHasPassword(currentUserInfo)
- ? testRestoreForPasswordUser
- : testRestoreForSIWEUser;
-
return (
<ScrollView
contentContainerStyle={styles.scrollViewContentContainer}
@@ -308,17 +236,6 @@
<Text style={styles.submenuText}>Test User Keys upload</Text>
</Button>
</View>
- <View style={styles.section}>
- <Button
- onPress={onPressRestoreButton}
- style={styles.row}
- iosFormat="highlight"
- iosHighlightUnderlayColor={colors.panelIosHighlightUnderlay}
- iosActiveOpacity={0.85}
- >
- <Text style={styles.submenuText}>Test backup restore protocol</Text>
- </Button>
- </View>
<View style={styles.section}>
<Button
onPress={testLatestBackupInfo}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jan 9, 5:11 PM (10 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2837353
Default Alt Text
D14090.id46578.diff (11 KB)
Attached To
Mode
D14090: [native] Navigate to a SIWE backup screen
Attached
Detach File
Event Timeline
Log In to Comment