Skip to content

Commit

Permalink
add passportMetadata in keychain and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
remicolin committed Jan 12, 2025
1 parent c0f96f9 commit 457c891
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 33 deletions.
4 changes: 2 additions & 2 deletions app/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 6 additions & 12 deletions app/ios/OpenPassport.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -615,7 +615,7 @@
"$(PROJECT_DIR)",
"$(PROJECT_DIR)/MoproKit/Libs",
);
MARKETING_VERSION = 2.0.0;
MARKETING_VERSION = 2.0.1;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
Expand All @@ -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 = (
Expand Down Expand Up @@ -753,7 +753,7 @@
"$(PROJECT_DIR)",
"$(PROJECT_DIR)/MoproKit/Libs",
);
MARKETING_VERSION = 2.0.0;
MARKETING_VERSION = 2.0.1;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions app/src/screens/SplashScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
37 changes: 22 additions & 15 deletions app/src/stores/userStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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<UserState>((set, get) => ({
Expand All @@ -61,8 +64,9 @@ const useUserStore = create<UserState>((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) => {
Expand All @@ -74,16 +78,16 @@ const useUserStore = create<UserState>((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,
});
Expand All @@ -93,27 +97,25 @@ const useUserStore = create<UserState>((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:
Expand Down Expand Up @@ -158,6 +160,11 @@ const useUserStore = create<UserState>((set, get) => ({
dateOfBirth: '',
dateOfExpiry: '',
}),

clearPassportMetadataFromStorage: async () => {
await resetGenericPassword({ service: 'passportMetadata' });
set({ passportMetadata: null });
},
}));

export default useUserStore;
16 changes: 16 additions & 0 deletions app/src/utils/keychain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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' },
);
}
4 changes: 2 additions & 2 deletions app/src/utils/nfcScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 457c891

Please sign in to comment.