Skip to content

Commit

Permalink
[native] Save the correct backup credentials
Browse files Browse the repository at this point in the history
Summary:
These credentials are used e.g. to create a new backup, and they should match the result returned from the SIWE panel.

https://linear.app/comm/issue/ENG-10099/sometimes-backup-restoration-cant-be-completed-due-to-a-cryptokit

Test Plan: Register a new SIWE user, log out, restore (this creates a new backup), log out, restore (this tests whether the new backup is correct). Confirm that the 2nd restoration works.

Reviewers: kamil, bartek

Reviewed By: kamil

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D14220
  • Loading branch information
palys-swm committed Jan 21, 2025
1 parent 0333f39 commit 56bb03f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/types/siwe-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export type SIWESignatureRequestData =
+siweIssuedAt: string,
};

export type SIWEBackupSecrets = {
export type SignedMessage = {
+message: string,
+signature: string,
};
Expand Down
4 changes: 2 additions & 2 deletions native/account/registration/registration-terms.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import invariant from 'invariant';
import * as React from 'react';
import { Text, View, Image, Linking } from 'react-native';

import type { SIWEBackupSecrets } from 'lib/types/siwe-types.js';
import type { SignedMessage } from 'lib/types/siwe-types.js';

import type { AuthNavigationProp } from './auth-navigator.react.js';
import { RegistrationContext } from './registration-context.js';
Expand All @@ -30,7 +30,7 @@ export type RegistrationTermsParams = {
+farcasterID: ?string,
+accountSelection: AccountSelection,
+avatarData: ?AvatarData,
+siweBackupSecrets?: ?SIWEBackupSecrets,
+siweBackupSecrets?: ?SignedMessage,
+farcasterAvatarURL: ?string,
},
};
Expand Down
6 changes: 3 additions & 3 deletions native/account/registration/registration-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
ClientAvatar,
} from 'lib/types/avatar-types.js';
import type { NativeMediaSelection } from 'lib/types/media-types.js';
import type { SIWEResult, SIWEBackupSecrets } from 'lib/types/siwe-types.js';
import type { SIWEResult, SignedMessage } from 'lib/types/siwe-types.js';

export type CoolOrNerdMode = 'cool' | 'nerd';

Expand Down Expand Up @@ -43,7 +43,7 @@ export type RegistrationServerCallInput = {
+farcasterID: ?string,
+accountSelection: AccountSelection,
+avatarData: ?AvatarData,
+siweBackupSecrets?: ?SIWEBackupSecrets,
+siweBackupSecrets?: ?SignedMessage,
+farcasterAvatarURL: ?string,
+clearCachedSelections: () => void,
+onNonceExpired: () => mixed,
Expand All @@ -58,7 +58,7 @@ export type CachedUserSelections = {
+avatarData?: ?AvatarData,
+ethereumAccount?: ?EthereumAccountSelection,
+farcasterID?: string,
+siweBackupSecrets?: ?SIWEBackupSecrets,
+siweBackupSecrets?: ?SignedMessage,
+farcasterAvatarURL?: ?string,
};

Expand Down
17 changes: 7 additions & 10 deletions native/account/restore-backup-screen.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as React from 'react';
import { Text, View } from 'react-native';
import * as Progress from 'react-native-progress';

import type { SignedMessage } from 'lib/types/siwe-types.js';
import { getMessageForException } from 'lib/utils/errors.js';

import AuthContainer from './auth-components/auth-container.react.js';
Expand Down Expand Up @@ -35,9 +36,8 @@ export type RestoreBackupScreenParams = {
}
| {
+type: 'siwe',
+secret: string,
+message: string,
+signature: string,
+socialProof: SignedMessage,
+backup: SignedMessage,
},
};

Expand All @@ -60,14 +60,11 @@ function RestoreBackupScreen(props: Props): React.Node {
} else {
await restore(
userIdentifier,
credentials.secret,
credentials.message,
credentials.signature,
credentials.backup.signature,
credentials.socialProof.message,
credentials.socialProof.signature,
);
await commCoreModule.setSIWEBackupSecrets({
message: credentials.message,
signature: credentials.signature,
});
await commCoreModule.setSIWEBackupSecrets(credentials.backup);
}
} catch (e) {
const messageForException = getMessageForException(e);
Expand Down
11 changes: 8 additions & 3 deletions native/backup/restore-siwe-backup.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ function RestoreSIWEBackup(props: Props): React.Node {
userIdentifier,
credentials: {
type: 'siwe',
secret: result.signature,
message,
signature,
socialProof: {
message,
signature,
},
backup: {
message: result.message,
signature: result.signature,
},
},
});
},
Expand Down
8 changes: 3 additions & 5 deletions native/schema/CommCoreModuleSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type {
OutboundSessionCreationResult,
} from 'lib/types/crypto-types.js';
import type { ClientDBMessageInfo } from 'lib/types/message-types.js';
import type { SIWEBackupSecrets } from 'lib/types/siwe-types.js';
import type { SignedMessage } from 'lib/types/siwe-types.js';
import type {
InboundP2PMessage,
OutboundP2PMessage,
Expand Down Expand Up @@ -231,10 +231,8 @@ export interface CoreModuleSpec extends Spec {
sessionVersion: number,
overwrite: boolean,
) => Promise<string>;
+setSIWEBackupSecrets: (
siweBackupSecrets: SIWEBackupSecrets,
) => Promise<void>;
+getSIWEBackupSecrets: () => Promise<?SIWEBackupSecrets>;
+setSIWEBackupSecrets: (siweBackupSecrets: SignedMessage) => Promise<void>;
+getSIWEBackupSecrets: () => Promise<?SignedMessage>;
+processDBStoreOperations: (
operations: ClientDBStoreOperations,
) => Promise<void>;
Expand Down

0 comments on commit 56bb03f

Please sign in to comment.