Skip to content

Commit

Permalink
parse passportMetadata and store them in userStore
Browse files Browse the repository at this point in the history
  • Loading branch information
remicolin committed Jan 11, 2025
1 parent 70854be commit 1e2c28a
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 19 deletions.
7 changes: 5 additions & 2 deletions app/src/screens/MockDataScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import CustomButton from '../components/CustomButton';
import useNavigationStore from '../stores/navigationStore';
import useUserStore from '../stores/userStore';
import { borderColor, textBlack } from '../utils/colors';
import { parsePassportData } from '../../../common/src/utils/parsePassportData';

interface MockDataScreenProps {
onCountryPress: () => void;
Expand Down Expand Up @@ -70,7 +71,7 @@ const MockDataScreen: React.FC<MockDataScreenProps> = ({
selectedAlgorithm == 'rsa sha1' ? 'sha1' : 'sha256',
selectedAlgorithm == 'rsa sha1' ? 'sha1' : 'sha256',
signatureAlgorithmToStrictSignatureAlgorithm[
selectedAlgorithm as keyof typeof signatureAlgorithmToStrictSignatureAlgorithm
selectedAlgorithm as keyof typeof signatureAlgorithmToStrictSignatureAlgorithm
],
selectedCountry as keyof typeof countryCodes,
castDate(-age),
Expand All @@ -84,7 +85,7 @@ const MockDataScreen: React.FC<MockDataScreenProps> = ({
selectedAlgorithm == 'rsa sha1' ? 'sha1' : 'sha256',
selectedAlgorithm == 'rsa sha1' ? 'sha1' : 'sha256',
signatureAlgorithmToStrictSignatureAlgorithm[
selectedAlgorithm as keyof typeof signatureAlgorithmToStrictSignatureAlgorithm
selectedAlgorithm as keyof typeof signatureAlgorithmToStrictSignatureAlgorithm
],
selectedCountry as keyof typeof countryCodes,
castDate(-age),
Expand All @@ -93,6 +94,8 @@ const MockDataScreen: React.FC<MockDataScreenProps> = ({
);
}
useUserStore.getState().registerPassportData(mockPassportData);
const parsedPassportData = parsePassportData(mockPassportData);
useUserStore.getState().setPassportMetadata(parsedPassportData);
useUserStore.getState().setRegistered(true);
resolve(null);
}, 0),
Expand Down
12 changes: 6 additions & 6 deletions app/src/screens/NextScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ const NextScreen: React.FC = () => {
h={height > 750 ? 190 : 130}
borderRadius={height > 750 ? '$7' : '$6'}
source={{
uri: passportData.mockUser
uri: passportData?.mockUser
? USER_PROFILE
: passportData.photoBase64 ?? USER_PROFILE,
: passportData?.photoBase64 ?? USER_PROFILE,
}}
/>
)}
Expand All @@ -64,8 +64,8 @@ const NextScreen: React.FC = () => {
}}
>
{hideData
? maskString(getFirstName(passportData.mrz))
: getFirstName(passportData.mrz)}
? maskString(getFirstName(passportData?.mrz ?? ''))
: getFirstName(passportData?.mrz ?? '')}
</Text>
</Text>

Expand All @@ -79,11 +79,11 @@ const NextScreen: React.FC = () => {
.split(' ')
.map((word: string) => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ');
const mrzAttribute = passportData.mrz.slice(
const mrzAttribute = passportData?.mrz?.slice(
indexes[0],
indexes[1] + 1,
);
const mrzAttributeFormatted = formatAttribute(key_, mrzAttribute);
const mrzAttributeFormatted = formatAttribute(key_, mrzAttribute ?? '');

return (
<Fieldset horizontal key={key} gap="$3" alignItems="center">
Expand Down
2 changes: 1 addition & 1 deletion app/src/stores/navigationStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface NavigationState {
}

const useNavigationStore = create<NavigationState>((set, get) => ({
zkeyDownloadedPercentage: 100,
zkeyDownloadedPercentage: 0,
setZkeyDownloadedPercentage: (percentage: number) =>
set({ zkeyDownloadedPercentage: percentage }),
isZkeyDownloading: {
Expand Down
7 changes: 7 additions & 0 deletions app/src/stores/userStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
loadSecretOrCreateIt,
storePassportData,
} from '../utils/keychain';
import { PassportMetadata } from '../../../common/src/utils/parsePassportData';

interface UserState {
passportNumber: string;
Expand All @@ -17,6 +18,7 @@ interface UserState {
countryCode: string;
registered: boolean;
passportData: PassportData | null;
passportMetadata: PassportMetadata | null;
secret: string;
cscaProof: Proof | null;
localProof: Proof | null;
Expand All @@ -32,6 +34,7 @@ interface UserState {
setRegistered: (registered: boolean) => void;
setDscSecret: (dscSecret: string) => void;
setUserLoaded: (userLoaded: boolean) => void;
setPassportMetadata: (passportMetadata: PassportMetadata) => void;
proofVerificationResult: string;
setProofVerificationResult: (proofVerificationResult: string) => void;
}
Expand All @@ -45,6 +48,7 @@ const useUserStore = create<UserState>((set, get) => ({
dscSecret: null,
registered: false,
passportData: null,
passportMetadata: null,
secret: '',
cscaProof: null,
localProof: null,
Expand All @@ -57,6 +61,9 @@ const useUserStore = create<UserState>((set, get) => ({
setUserLoaded: (userLoaded: boolean) => {
set({ userLoaded });
},
setPassportMetadata: (passportMetadata: PassportMetadata) => {
set({ passportMetadata });
},
proofVerificationResult: 'null',
setProofVerificationResult: (proofVerificationResult: string) => {
set({ proofVerificationResult });
Expand Down
2 changes: 2 additions & 0 deletions app/src/utils/nfcScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ const handleResponseIOS = async (
mockUser: false,
};
const parsedPassportData = parsePassportData(passportData);
useUserStore.getState().setPassportMetadata(parsedPassportData);
amplitude.track('nfc_response_parsed', parsedPassportData);

try {
Expand Down Expand Up @@ -318,6 +319,7 @@ const handleResponseAndroid = async (

try {
await useUserStore.getState().registerPassportData(passportData);
useUserStore.getState().setPassportMetadata(parsedPassportData);
useNavigationStore.getState().setSelectedTab('next');
} catch (e: any) {
console.log('error during parsing:', e);
Expand Down
14 changes: 6 additions & 8 deletions app/src/utils/qrCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { getCircuitNameOld } from '../../../common/src/utils/certificate_parsing
import useNavigationStore from '../stores/navigationStore';
import useUserStore from '../stores/userStore';
import { downloadZkey } from './zkeyDownload';
import { parsePassportData } from '../../../common/src/utils/parsePassportData';

const parseUrlParams = (url: string): Map<string, string> => {
const [, queryString] = url.split('?');
Expand Down Expand Up @@ -109,8 +108,8 @@ const handleQRCodeScan = (
setSelectedTab: any,
) => {
try {
const passportData = useUserStore.getState().passportData;
if (passportData) {
const { passportData, passportMetadata } = useUserStore.getState();
if (passportData && passportMetadata) {
const decodedResult = atob(result);
const uint8Array = new Uint8Array(
decodedResult.split('').map(char => char.charCodeAt(0)),
Expand All @@ -119,16 +118,15 @@ const handleQRCodeScan = (
const unpackedData = msgpack.decode(decompressedData);
const openPassportApp: OpenPassportApp = unpackedData;
setSelectedApp(openPassportApp);
const passportMetadata = parsePassportData(passportData);

const circuitName =
openPassportApp.mode === 'vc_and_disclose'
? 'vc_and_disclose'
: getCircuitNameOld(
'prove' as Mode,
passportMetadata.signatureAlgorithm,
passportMetadata.signedAttrHashFunction,
);
'prove' as Mode,
passportMetadata.signatureAlgorithm,
passportMetadata.signedAttrHashFunction,
);
downloadZkey(circuitName as any);

setSelectedTab('prove');
Expand Down
4 changes: 2 additions & 2 deletions app/src/utils/zkeyDownload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ export async function fetchZkeyAndDat(circuit: CircuitName) {

console.log(
'zkey and dat download succeeded, took ' +
(Date.now() - startTime) / 1000 +
' seconds',
(Date.now() - startTime) / 1000 +
' seconds',
);

await saveFileSize(circuit, 'zkey');
Expand Down

0 comments on commit 1e2c28a

Please sign in to comment.