diff --git a/lib/types/identity-service-types.js b/lib/types/identity-service-types.js --- a/lib/types/identity-service-types.js +++ b/lib/types/identity-service-types.js @@ -187,7 +187,7 @@ deviceList: SignedDeviceList, siweSocialProof?: SignedMessage, backupSecret: string, - ) => Promise; + ) => Promise; // on native, publishing prekeys to Identity is called directly from C++, // there is no need to expose it to JS +publishWebPrekeys?: (prekeys: SignedPrekeys) => Promise; @@ -230,12 +230,23 @@ +username: string, +preRequestUserState?: ?CurrentUserInfo, }; +const identityAuthResultValidatorObject = { + userID: tUserID, + accessToken: t.String, + username: t.String, + preRequestUserState: t.maybe(currentUserInfoValidator), +}; export const identityAuthResultValidator: TInterface = - tShape({ - userID: tUserID, - accessToken: t.String, - username: t.String, - preRequestUserState: t.maybe(currentUserInfoValidator), + tShape(identityAuthResultValidatorObject); + +export type RestoreUserResult = { + ...IdentityAuthResult, + +backupID: string, +}; +export const restoreUserResultValidator: TInterface = + tShape({ + ...identityAuthResultValidatorObject, + backupID: t.String, }); export type IdentityNewDeviceKeyUpload = { diff --git a/native/account/restore.js b/native/account/restore.js --- a/native/account/restore.js +++ b/native/account/restore.js @@ -153,8 +153,9 @@ ); //8. Return the result + const { backupID: _, ...authResult } = result; return { - ...result, + ...authResult, preRequestUserState, deviceLists: { [userID]: initialDeviceList }, usersPlatformDetails: { diff --git a/native/identity-service/identity-service-context-provider.react.js b/native/identity-service/identity-service-context-provider.react.js --- a/native/identity-service/identity-service-context-provider.react.js +++ b/native/identity-service/identity-service-context-provider.react.js @@ -19,6 +19,7 @@ deviceOlmOutboundKeysValidator, farcasterUsersValidator, identityAuthResultValidator, + restoreUserResultValidator, type IdentityServiceClient, ONE_TIME_KEYS_NUMBER, type SignedDeviceList, @@ -627,10 +628,15 @@ backupSecret, ); - return await processAuthResult( + const { backupID } = assertWithValidator( + JSON.parse(restoreResult), + restoreUserResultValidator, + ); + const authResult = await processAuthResult( restoreResult, primaryIdentityPublicKeys.ed25519, ); + return { backupID, ...authResult }; }, uploadKeysForRegisteredDeviceAndLogIn: async ( userID: string, diff --git a/native/native_rust_library/src/identity.rs b/native/native_rust_library/src/identity.rs --- a/native/native_rust_library/src/identity.rs +++ b/native/native_rust_library/src/identity.rs @@ -169,6 +169,15 @@ username: String, } +#[derive(Serialize)] +#[serde(rename_all = "camelCase")] +pub struct RestoreUserResult { + #[serde(flatten)] + auth_result: IdentityAuthResult, + #[serde(rename = "backupID")] + backup_id: String, +} + impl From for IdentityAuthResult { fn from(value: AuthResponse) -> Self { let AuthResponse { diff --git a/native/native_rust_library/src/identity/login.rs b/native/native_rust_library/src/identity/login.rs --- a/native/native_rust_library/src/identity/login.rs +++ b/native/native_rust_library/src/identity/login.rs @@ -11,7 +11,7 @@ use super::{ IdentityAuthResult, LogInPasswordUserInfo, LogInWalletUserInfo, - RestoreUserInfo, PLATFORM_METADATA, + RestoreUserInfo, RestoreUserResult, PLATFORM_METADATA, }; use crate::backup::create_ephemeral_user_keys_compaction; use crate::utils::jsi_callbacks::handle_string_result_as_callback; @@ -294,13 +294,14 @@ Some(user_info.siwe_backup_msg) }; + let backup_id = user_info.backup_id; let restore_request = RestoreUserRequest { user_id: user_info.user_id, siwe_message: user_info.siwe_social_proof_message, siwe_signature: user_info.siwe_social_proof_signature, device_list: user_info.device_list, device_key_upload: Some(user_info.device_keys.into()), - new_backup_id: user_info.backup_id, + new_backup_id: backup_id.clone(), encrypted_user_keys: user_keys, siwe_backup_msg, }; @@ -315,7 +316,11 @@ .into_inner(); let auth_result = IdentityAuthResult::from(auth_response); - Ok(serde_json::to_string(&auth_result)?) + let result = RestoreUserResult { + auth_result, + backup_id, + }; + Ok(serde_json::to_string(&result)?) } async fn upload_secondary_device_keys_and_log_in_helper(