From 457c891de7c241b7e7bdd510d81c4ded665078ef Mon Sep 17 00:00:00 2001 From: turnoffthiscomputer Date: Sun, 12 Jan 2025 12:11:14 +0100 Subject: [PATCH] add passportMetadata in keychain and bump version --- app/android/app/build.gradle | 4 +- .../OpenPassport.xcodeproj/project.pbxproj | 18 +++------ app/src/screens/SplashScreen.tsx | 5 ++- app/src/stores/userStore.ts | 37 +++++++++++-------- app/src/utils/keychain.ts | 16 ++++++++ app/src/utils/nfcScanner.ts | 4 +- 6 files changed, 51 insertions(+), 33 deletions(-) diff --git a/app/android/app/build.gradle b/app/android/app/build.gradle index b3a3e7f4..8876720e 100644 --- a/app/android/app/build.gradle +++ b/app/android/app/build.gradle @@ -85,8 +85,8 @@ android { applicationId "com.proofofpassportapp" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 16 - versionName "1.5" + versionCode 17 + versionName "1.6" externalNativeBuild { cmake { cppFlags += "-fexceptions -frtti -std=c++11" diff --git a/app/ios/OpenPassport.xcodeproj/project.pbxproj b/app/ios/OpenPassport.xcodeproj/project.pbxproj index f089636d..4f64c422 100644 --- a/app/ios/OpenPassport.xcodeproj/project.pbxproj +++ b/app/ios/OpenPassport.xcodeproj/project.pbxproj @@ -500,7 +500,7 @@ CODE_SIGN_ENTITLEMENTS = OpenPassport/OpenPassportDebug.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 67; + CURRENT_PROJECT_VERSION = 68; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = 5B29R5LYHQ; ENABLE_BITCODE = NO; @@ -615,7 +615,7 @@ "$(PROJECT_DIR)", "$(PROJECT_DIR)/MoproKit/Libs", ); - MARKETING_VERSION = 2.0.0; + MARKETING_VERSION = 2.0.1; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", @@ -639,7 +639,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = OpenPassport/OpenPassport.entitlements; - CURRENT_PROJECT_VERSION = 67; + CURRENT_PROJECT_VERSION = 68; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = 5B29R5LYHQ; FRAMEWORK_SEARCH_PATHS = ( @@ -753,7 +753,7 @@ "$(PROJECT_DIR)", "$(PROJECT_DIR)/MoproKit/Libs", ); - MARKETING_VERSION = 2.0.0; + MARKETING_VERSION = 2.0.1; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", @@ -857,10 +857,7 @@ "-DFOLLY_MOBILE=1", "-DFOLLY_USE_LIBCPP=1", ); - OTHER_LDFLAGS = ( - "$(inherited)", - " ", - ); + OTHER_LDFLAGS = "$(inherited) "; REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; SDKROOT = iphoneos; SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG"; @@ -950,10 +947,7 @@ "-DFOLLY_MOBILE=1", "-DFOLLY_USE_LIBCPP=1", ); - OTHER_LDFLAGS = ( - "$(inherited)", - " ", - ); + OTHER_LDFLAGS = "$(inherited) "; REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; SDKROOT = iphoneos; USE_HERMES = false; diff --git a/app/src/screens/SplashScreen.tsx b/app/src/screens/SplashScreen.tsx index 624fe623..d81f9507 100644 --- a/app/src/screens/SplashScreen.tsx +++ b/app/src/screens/SplashScreen.tsx @@ -7,11 +7,12 @@ import useUserStore from '../stores/userStore'; import { textBlack } from '../utils/colors'; const SplashScreen = () => { - const { userLoaded, passportData } = useUserStore(); + const { userLoaded, passportData, passportMetadata } = useUserStore(); const { setSelectedTab } = useNavigationStore(); useEffect(() => { if (userLoaded) { - if (passportData && passportData.dg2Hash && !passportData.mockUser) { + console.log('passportMetadata', passportMetadata); + if (passportData && passportMetadata && passportData.dg2Hash && !passportData.mockUser) { setSelectedTab('app'); } else { setSelectedTab('start'); diff --git a/app/src/stores/userStore.ts b/app/src/stores/userStore.ts index fee5396e..21962ffd 100644 --- a/app/src/stores/userStore.ts +++ b/app/src/stores/userStore.ts @@ -6,8 +6,10 @@ import { generateDscSecret } from '../../../common/src/utils/csca'; import { PassportData, Proof } from '../../../common/src/utils/types'; import { loadPassportData, + loadPassportMetadata, loadSecretOrCreateIt, storePassportData, + storePassportMetadata, } from '../utils/keychain'; import { PassportMetadata } from '../../../common/src/utils/parsePassportData'; @@ -34,9 +36,10 @@ interface UserState { setRegistered: (registered: boolean) => void; setDscSecret: (dscSecret: string) => void; setUserLoaded: (userLoaded: boolean) => void; - setPassportMetadata: (passportMetadata: PassportMetadata) => void; proofVerificationResult: string; setProofVerificationResult: (proofVerificationResult: string) => void; + setPassportMetadata: (metadata: PassportMetadata) => void; + clearPassportMetadataFromStorage: () => void; } const useUserStore = create((set, get) => ({ @@ -61,8 +64,9 @@ const useUserStore = create((set, get) => ({ setUserLoaded: (userLoaded: boolean) => { set({ userLoaded }); }, - setPassportMetadata: (passportMetadata: PassportMetadata) => { - set({ passportMetadata }); + setPassportMetadata: async (metadata: PassportMetadata) => { + await storePassportMetadata(metadata); + set({ passportMetadata: metadata }); }, proofVerificationResult: 'null', setProofVerificationResult: (proofVerificationResult: string) => { @@ -74,16 +78,16 @@ const useUserStore = create((set, get) => ({ // - If the commitment is present in the tree, proceed to main screen // - If the commitment is not present in the tree, proceed to main screen AND try registering it in the background initUserStore: async () => { - // download zkeys if they are not already downloaded - const secret = await loadSecretOrCreateIt(); set({ secret }); const dscSecret = await generateDscSecret(); set({ dscSecret }); const passportDataString = await loadPassportData(); - if (!passportDataString) { - console.log('No passport data found, starting onboarding flow'); + const passportMetadataString = await loadPassportMetadata(); + + if (!passportDataString || !passportMetadataString) { + console.log('No passport data or metadata found, starting onboarding flow'); set({ userLoaded: true, }); @@ -93,27 +97,25 @@ const useUserStore = create((set, get) => ({ // const isAlreadyRegistered = await isCommitmentRegistered(secret, JSON.parse(passportData)); const isAlreadyRegistered = true; const passportData: PassportData = JSON.parse(passportDataString); + const passportMetadata: PassportMetadata = JSON.parse(passportMetadataString); if (!isAlreadyRegistered) { - console.log( - 'not registered but passport data found, skipping to nextScreen', - ); + console.log('not registered but passport data found, skipping to nextScreen'); set({ passportData: passportData, + passportMetadata: passportMetadata, userLoaded: true, }); - return; } - console.log( - 'registered and passport data found, skipping to app selection screen', - ); + console.log('registered and passport data found, skipping to app selection screen'); set({ passportData: passportData, + passportMetadata: passportMetadata, registered: true, + userLoaded: true, }); - set({ userLoaded: true }); }, // When reading passport for the first time: @@ -158,6 +160,11 @@ const useUserStore = create((set, get) => ({ dateOfBirth: '', dateOfExpiry: '', }), + + clearPassportMetadataFromStorage: async () => { + await resetGenericPassword({ service: 'passportMetadata' }); + set({ passportMetadata: null }); + }, })); export default useUserStore; diff --git a/app/src/utils/keychain.ts b/app/src/utils/keychain.ts index c04ef1af..2894eed9 100644 --- a/app/src/utils/keychain.ts +++ b/app/src/utils/keychain.ts @@ -2,6 +2,7 @@ import { ethers } from 'ethers'; import * as Keychain from 'react-native-keychain'; import { PassportData } from '../../../common/src/utils/types'; +import { PassportMetadata } from '../../../common/src/utils/parsePassportData'; export async function loadSecretOrCreateIt() { const secret = await loadSecret(); @@ -35,3 +36,18 @@ export async function storePassportData(passportData: PassportData) { { service: 'passportData' }, ); } + +export async function loadPassportMetadata() { + const metadataCreds = await Keychain.getGenericPassword({ + service: 'passportMetadata', + }); + return metadataCreds === false ? false : metadataCreds.password; +} + +export async function storePassportMetadata(metadata: PassportMetadata) { + await Keychain.setGenericPassword( + 'passportMetadata', + JSON.stringify(metadata), + { service: 'passportMetadata' }, + ); +} diff --git a/app/src/utils/nfcScanner.ts b/app/src/utils/nfcScanner.ts index 4f8c1b8c..670c2ffd 100644 --- a/app/src/utils/nfcScanner.ts +++ b/app/src/utils/nfcScanner.ts @@ -210,7 +210,7 @@ const handleResponseIOS = async ( mockUser: false, }; const parsedPassportData = parsePassportData(passportData); - useUserStore.getState().setPassportMetadata(parsedPassportData); + await useUserStore.getState().setPassportMetadata(parsedPassportData); amplitude.track('nfc_response_parsed', parsedPassportData); try { @@ -319,7 +319,7 @@ const handleResponseAndroid = async ( try { await useUserStore.getState().registerPassportData(passportData); - useUserStore.getState().setPassportMetadata(parsedPassportData); + await useUserStore.getState().setPassportMetadata(parsedPassportData); useNavigationStore.getState().setSelectedTab('next'); } catch (e: any) { console.log('error during parsing:', e);