Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions app/src/screens/prove/ConfirmBelongingScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { ActivityIndicator, View } from 'react-native';
import type { StaticScreenProps } from '@react-navigation/native';
import { usePreventRemove } from '@react-navigation/native';

import { useSelfClient } from '@selfxyz/mobile-sdk-alpha';

import successAnimation from '@/assets/animations/loading/success.json';
import { PrimaryButton } from '@/components/buttons/PrimaryButton';
import Description from '@/components/typography/Description';
Expand Down Expand Up @@ -37,11 +39,11 @@ const ConfirmBelongingScreen: React.FC<ConfirmBelongingScreenProps> = () => {
const setFcmToken = useProvingStore(state => state.setFcmToken);
const setUserConfirmed = useProvingStore(state => state.setUserConfirmed);
const isReadyToProve = currentState === 'ready_to_prove';

const selfClient = useSelfClient();
useEffect(() => {
notificationSuccess();
init('dsc');
}, [init]);
init(selfClient, 'dsc');
}, [init, selfClient]);

const onOkPress = async () => {
try {
Expand Down
7 changes: 4 additions & 3 deletions app/src/screens/prove/ProveScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Eye, EyeOff } from '@tamagui/lucide-icons';

import type { SelfAppDisclosureConfig } from '@selfxyz/common/utils/appType';
import { formatEndpoint } from '@selfxyz/common/utils/scope';
import { useSelfClient } from '@selfxyz/mobile-sdk-alpha';

import miscAnimation from '@/assets/animations/loading/misc.json';
import { HeldPrimaryButtonProveScreen } from '@/components/buttons/HeldPrimaryButtonProveScreen';
Expand Down Expand Up @@ -56,7 +57,7 @@ const ProveScreen: React.FC = () => {
() => scrollViewContentHeight <= scrollViewHeight,
[scrollViewContentHeight, scrollViewHeight],
);

const selfClient = useSelfClient();
const provingStore = useProvingStore();
const currentState = useProvingStore(state => state.currentState);
const isReadyToProve = currentState === 'ready_to_prove';
Expand Down Expand Up @@ -94,10 +95,10 @@ const ProveScreen: React.FC = () => {
setDefaultDocumentTypeIfNeeded();

if (selectedAppRef.current?.sessionId !== selectedApp.sessionId) {
provingStore.init('disclose');
provingStore.init(selfClient, 'disclose');
}
selectedAppRef.current = selectedApp;
}, [selectedApp, isFocused, provingStore]);
}, [selectedApp, isFocused, provingStore, selfClient]);

const disclosureOptions = useMemo(() => {
return (selectedApp?.disclosures as SelfAppDisclosureConfig) || [];
Expand Down
30 changes: 20 additions & 10 deletions app/src/utils/proving/provingMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ import {
getCircuitNameFromPassportData,
getSolidityPackedUserContextData,
} from '@selfxyz/common/utils';
import { SelfClient } from '@selfxyz/mobile-sdk-alpha';

import { PassportEvents, ProofEvents } from '@/consts/analytics';
//
import { navigationRef } from '@/navigation';
// this will be pass as property of from selfClient
import { unsafe_getPrivateKey } from '@/providers/authProvider';
// will need to be passed in from selfClient
import {
clearPassportData,
loadSelectedDocument,
Expand Down Expand Up @@ -177,14 +181,15 @@ interface ProvingState {
env: 'prod' | 'stg' | null;
setFcmToken: (token: string) => void;
init: (
selfClient: SelfClient,
circuitType: 'dsc' | 'disclose' | 'register',
userConfirmed?: boolean,
) => Promise<void>;
startFetchingData: () => Promise<void>;
validatingDocument: () => Promise<void>;
validatingDocument: (selfClient: SelfClient) => Promise<void>;
initTeeConnection: () => Promise<boolean>;
startProving: () => Promise<void>;
postProving: () => void;
postProving: (selfClient: SelfClient) => void;
setUserConfirmed: () => void;
_closeConnections: () => void;
_generatePayload: () => Promise<unknown>;
Expand All @@ -202,7 +207,10 @@ interface ProvingState {
export const useProvingStore = create<ProvingState>((set, get) => {
let actor: AnyActorRef | null = null;

function setupActorSubscriptions(newActor: AnyActorRef) {
function setupActorSubscriptions(
newActor: AnyActorRef,
selfClient: SelfClient,
) {
newActor.subscribe((state: StateFrom<typeof provingMachine>) => {
console.log(`State transition: ${state.value}`);
trackEvent(ProofEvents.PROVING_STATE_CHANGE, { state: state.value });
Expand All @@ -212,7 +220,7 @@ export const useProvingStore = create<ProvingState>((set, get) => {
get().startFetchingData();
}
if (state.value === 'validating_document') {
get().validatingDocument();
get().validatingDocument(selfClient);
}

if (state.value === 'init_tee_connexion') {
Expand All @@ -224,7 +232,7 @@ export const useProvingStore = create<ProvingState>((set, get) => {
}

if (state.value === 'post_proving') {
get().postProving();
get().postProving(selfClient);
}
if (
get().circuitType !== 'disclose' &&
Expand Down Expand Up @@ -416,7 +424,6 @@ export const useProvingStore = create<ProvingState>((set, get) => {
try {
// TODO: call hasAnyValidRegisteredDocument(selfClient) from @selfxyz/mobile-sdk-alpha
const hasValid = await hasAnyValidRegisteredDocument();

if (navigationRef.isReady()) {
if (hasValid) {
navigationRef.navigate('Home');
Expand Down Expand Up @@ -590,6 +597,7 @@ export const useProvingStore = create<ProvingState>((set, get) => {
},

init: async (
selfClient: SelfClient,
circuitType: 'dsc' | 'disclose' | 'register',
userConfirmed: boolean = false,
) => {
Expand Down Expand Up @@ -620,10 +628,11 @@ export const useProvingStore = create<ProvingState>((set, get) => {
});

actor = createActor(provingMachine);
setupActorSubscriptions(actor);
setupActorSubscriptions(actor, selfClient);
actor.start();

trackEvent(ProofEvents.DOCUMENT_LOAD_STARTED);
// TODO call on self client
const selectedDocument = await loadSelectedDocument();
if (!selectedDocument) {
console.error('No document found for proving');
Expand All @@ -634,6 +643,7 @@ export const useProvingStore = create<ProvingState>((set, get) => {

const { data: passportData } = selectedDocument;

// TODO call on self client
const secret = await unsafe_getPrivateKey();
if (!secret) {
console.error('Could not load secret');
Expand Down Expand Up @@ -676,7 +686,7 @@ export const useProvingStore = create<ProvingState>((set, get) => {
}
},

validatingDocument: async () => {
validatingDocument: async (selfClient: SelfClient) => {
_checkActorInitialized(actor);
// TODO: for the disclosure, we could check that the selfApp is a valid one.
trackEvent(ProofEvents.VALIDATION_STARTED);
Expand Down Expand Up @@ -919,7 +929,7 @@ export const useProvingStore = create<ProvingState>((set, get) => {
}
},

postProving: () => {
postProving: (selfClient: SelfClient) => {
_checkActorInitialized(actor);
const { circuitType } = get();
trackEvent(ProofEvents.POST_PROVING_STARTED);
Expand All @@ -929,7 +939,7 @@ export const useProvingStore = create<ProvingState>((set, get) => {
from: 'dsc',
to: 'register',
});
get().init('register', true);
get().init(selfClient, 'register', true);
}, 1500);
} else if (circuitType === 'register') {
trackEvent(ProofEvents.POST_PROVING_COMPLETED);
Expand Down
Loading