separate MRZ data from userStore (#1187)

This commit is contained in:
Leszek Stachowski
2025-10-02 21:40:48 +02:00
committed by GitHub
parent 0c6a6cb2e6
commit c1d30d153a
9 changed files with 85 additions and 40 deletions

View File

@@ -8,6 +8,7 @@ import { notImplemented } from './errors';
import { extractMRZInfo as parseMRZInfo } from './processing/mrz';
import { ProofContext } from './proving/internal/logging';
import { useProvingStore } from './proving/provingMachine';
import { useMRZStore } from './stores/mrzStore';
import { useProtocolStore } from './stores/protocolStore';
import { useSelfAppStore } from './stores/selfAppStore';
import { SDKEvent, SDKEventMap, SdkEvents } from './types/events';
@@ -180,10 +181,14 @@ export function createSelfClient({
getProtocolState: () => {
return useProtocolStore.getState();
},
getMRZState: () => {
return useMRZStore.getState();
},
// for reactivity (if needed)
useProvingStore,
useSelfAppStore,
useProtocolStore,
useMRZStore,
};
}

View File

@@ -0,0 +1,60 @@
// SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc.
// SPDX-License-Identifier: BUSL-1.1
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
import { create } from 'zustand';
export interface MRZState {
// Fields needed for NFC scanning
passportNumber: string;
dateOfBirth: string;
dateOfExpiry: string;
countryCode: string;
documentType: string;
// Store actions
setMRZForNFC: (data: {
passportNumber: string;
dateOfBirth: string;
dateOfExpiry: string;
countryCode: string;
documentType: string;
}) => void;
clearMRZ: () => void;
update: (patch: Partial<MRZState>) => void;
}
// TODO: what about the defaults from @env?
const initialState = {
passportNumber: '',
dateOfBirth: '',
dateOfExpiry: '',
countryCode: '',
documentType: '',
};
/*
Never export outside of the mobile sdk. It can cause multiple instances of the store to be created.
interact with the store thru the self client
*/
export const useMRZStore = create<MRZState>(set => ({
...initialState,
setMRZForNFC: data => {
set({
passportNumber: data.passportNumber,
dateOfBirth: data.dateOfBirth,
dateOfExpiry: data.dateOfExpiry,
countryCode: data.countryCode,
documentType: data.documentType,
});
},
clearMRZ: () => {
set(initialState);
},
update: (patch: Partial<MRZState>) => {
set(state => ({ ...state, ...patch }));
},
}));

View File

@@ -8,6 +8,7 @@ import type { DocumentCatalog, IDDocument, PassportData } from '@selfxyz/common'
import type { ProofContext } from '../proving/internal/logging';
import { ProvingState } from '../proving/provingMachine';
import { MRZState } from '../stores/mrzStore';
import { ProtocolState } from '../stores/protocolStore';
import { SelfAppState } from '../stores/selfAppStore';
import { SDKEvent, SDKEventMap } from './events';
@@ -183,10 +184,12 @@ export interface SelfClient {
getProvingState: () => ProvingState;
getSelfAppState: () => SelfAppState;
getProtocolState: () => ProtocolState;
getMRZState: () => MRZState;
useProvingStore: ReturnType<typeof create<ProvingState, []>>;
useSelfAppStore: ReturnType<typeof create<SelfAppState, []>>;
useProtocolStore: ReturnType<typeof create<ProtocolState, []>>;
useMRZStore: ReturnType<typeof create<MRZState, []>>;
}
export type Unsubscribe = () => void;
export interface StorageAdapter {