diff --git a/machines/QrLoginMachine.ts b/machines/QrLoginMachine.ts index 74909109cb..17f2441df5 100644 --- a/machines/QrLoginMachine.ts +++ b/machines/QrLoginMachine.ts @@ -359,7 +359,7 @@ export const qrLoginMachine = sendAuthenticate: async context => { let privateKey; - + const individualId = context.selectedVc.vcMetadata.id; if (!isCustomSecureKeystore()) { privateKey = await getPrivateKey( context.selectedVc.walletBindingResponse?.walletBindingId, @@ -367,11 +367,7 @@ export const qrLoginMachine = } var walletBindingResponse = context.selectedVc.walletBindingResponse; - var jwt = await getJwt( - privateKey, - context.selectedVc.id, - context.thumbprint, - ); + var jwt = await getJwt(privateKey, individualId, context.thumbprint); const response = await request( 'POST', @@ -380,7 +376,7 @@ export const qrLoginMachine = requestTime: String(new Date().toISOString()), request: { linkedTransactionId: context.linkTransactionId, - individualId: context.selectedVc.id, + individualId: individualId, challengeList: [ { authFactorType: 'WLA', @@ -397,6 +393,7 @@ export const qrLoginMachine = sendConsent: async context => { let privateKey; + const individualId = context.selectedVc.vcMetadata.id; if (!isCustomSecureKeystore()) { privateKey = await getPrivateKey( context.selectedVc.walletBindingResponse?.walletBindingId, @@ -405,7 +402,7 @@ export const qrLoginMachine = const jwt = await getJwt( privateKey, - context.selectedVc.id, + individualId, context.thumbprint, ); @@ -416,7 +413,7 @@ export const qrLoginMachine = requestTime: String(new Date().toISOString()), request: { linkedTransactionId: context.linkTransactionId, - individualId: context.selectedVc.id, + individualId: individualId, challengeList: [ { authFactorType: 'WLA', diff --git a/machines/VCItemMachine/EsignetMosipVCItem/EsignetMosipVCItemMachine.ts b/machines/VCItemMachine/EsignetMosipVCItem/EsignetMosipVCItemMachine.ts index 2d0f6f5a22..52a6af0ccf 100644 --- a/machines/VCItemMachine/EsignetMosipVCItem/EsignetMosipVCItemMachine.ts +++ b/machines/VCItemMachine/EsignetMosipVCItem/EsignetMosipVCItemMachine.ts @@ -104,7 +104,11 @@ export const EsignetMosipVCItemMachine = model.createMachine( on: { GET_VC_RESPONSE: [ { - actions: ['setVerifiableCredential', 'setGeneratedOn'], + actions: [ + 'setVerifiableCredential', + 'setContext', + 'setGeneratedOn', + ], cond: 'hasCredential', target: 'idle', }, @@ -514,7 +518,7 @@ export const EsignetMosipVCItemMachine = model.createMachine( ), updateVc: send( context => { - const {verifiableCredential} = context; + const {serviceRefs, ...verifiableCredential} = context; return { type: 'VC_DOWNLOADED_FROM_OPENID4VCI', vc: verifiableCredential, @@ -529,7 +533,9 @@ export const EsignetMosipVCItemMachine = model.createMachine( setVerifiableCredential: model.assign({ verifiableCredential: (_, event) => { if (event.type === 'GET_VC_RESPONSE') { - return event.vc.verifiableCredential; + return event.vc.verifiableCredential + ? event.vc.verifiableCredential + : event.vc; } return event.response.verifiableCredential; }, @@ -540,6 +546,10 @@ export const EsignetMosipVCItemMachine = model.createMachine( const {verifiableCredential, ...data} = event.response; return {...context, ...data}; } + if (event.type === 'GET_VC_RESPONSE') { + const {verifiableCredential, ...data} = event.vc; + return {...context, ...data}; + } return context; }), @@ -748,10 +758,7 @@ export const EsignetMosipVCItemMachine = model.createMachine( request: { authFactorType: 'WLA', format: 'jwt', - individualId: context.verifiableCredential.credential - .credentialSubject.VID - ? context.verifiableCredential.credential.credentialSubject.VID - : context.verifiableCredential.credential.credentialSubject.UIN, + individualId: VCMetadata.fromVC(context.vcMetadata).id, transactionId: context.transactionId, publicKey: context.publicKey, challengeList: [ diff --git a/machines/bleShare/request/requestMachine.ts b/machines/bleShare/request/requestMachine.ts index 5b12b9fa0d..8ccb26f34c 100644 --- a/machines/bleShare/request/requestMachine.ts +++ b/machines/bleShare/request/requestMachine.ts @@ -585,11 +585,12 @@ export const requestMachine = }), prependReceivedVc: send( - context => - StoreEvents.PREPEND( + context => { + return StoreEvents.PREPEND( RECEIVED_VCS_STORE_KEY, - VCMetadata.fromVC(context.incomingVc), - ), + VCMetadata.fromVC(context.incomingVc?.vcMetadata), + ); + }, {to: context => context.serviceRefs.store}, ), @@ -617,7 +618,7 @@ export const requestMachine = storeVc: send( context => StoreEvents.SET( - VCMetadata.fromVC(context.incomingVc).getVcKey(), + VCMetadata.fromVC(context.incomingVc?.vcMetadata).getVcKey(), context.incomingVc, ), {to: context => context.serviceRefs.store}, @@ -640,21 +641,27 @@ export const requestMachine = }), logReceived: send( - context => - ActivityLogEvents.LOG_ACTIVITY({ - _vcKey: VCMetadata.fromVC(context.incomingVc).getVcKey(), + context => { + const vcMetadata = VCMetadata.fromVC( + context.incomingVc?.vcMetadata, + ); + return ActivityLogEvents.LOG_ACTIVITY({ + _vcKey: vcMetadata.getVcKey(), type: context.receiveLogType, timestamp: Date.now(), deviceName: context.senderInfo.name || context.senderInfo.deviceName, - vcLabel: context.incomingVc.id, - }), + vcLabel: vcMetadata.id, + }); + }, {to: context => context.serviceRefs.activityLog}, ), sendVcReceived: send( context => { - return VcEvents.VC_RECEIVED(VCMetadata.fromVC(context.incomingVc)); + return VcEvents.VC_RECEIVED( + VCMetadata.fromVC(context.incomingVc?.vcMetadata), + ); }, {to: context => context.serviceRefs.vc}, ), diff --git a/machines/bleShare/scan/scanMachine.ts b/machines/bleShare/scan/scanMachine.ts index f299b4c168..eca84654fc 100644 --- a/machines/bleShare/scan/scanMachine.ts +++ b/machines/bleShare/scan/scanMachine.ts @@ -807,17 +807,19 @@ export const scanMachine = }), logShared: send( - context => - ActivityLogEvents.LOG_ACTIVITY({ - _vcKey: VCMetadata.fromVC(context.selectedVc).getVcKey(), + context => { + const vcMetadata = context.selectedVc?.vcMetadata; + return ActivityLogEvents.LOG_ACTIVITY({ + _vcKey: VCMetadata.fromVC(vcMetadata).getVcKey(), type: context.selectedVc.shouldVerifyPresence ? 'VC_SHARED_WITH_VERIFICATION_CONSENT' : context.shareLogType, timestamp: Date.now(), deviceName: context.receiverInfo.name || context.receiverInfo.deviceName, - vcLabel: context.selectedVc.id, - }), + vcLabel: vcMetadata.id, + }); + }, {to: context => context.serviceRefs.activityLog}, ), @@ -881,7 +883,7 @@ export const scanMachine = type: 'QRLOGIN_SUCCESFULL', timestamp: Date.now(), deviceName: '', - vcLabel: String(event.response.selectedVc.id), + vcLabel: String(event.response.selectedVc.vcMetadata.id), }), { to: context => context.serviceRefs.activityLog, diff --git a/machines/vc.ts b/machines/vc.ts index 6a18413515..1033ab1499 100644 --- a/machines/vc.ts +++ b/machines/vc.ts @@ -394,7 +394,9 @@ export function selectMyVcsMetadata(state: State): VCMetadata[] { export function selectShareableVcsMetadata(state: State): VCMetadata[] { return state.context.myVcs.filter( - vcMetadata => state.context.vcs[vcMetadata.getVcKey()]?.credential != null, + vcMetadata => + state.context.vcs[vcMetadata.getVcKey()]?.credential != null || + state.context.vcs[vcMetadata.getVcKey()]?.verifiableCredential != null, ); } diff --git a/screens/Home/HomeScreenMachine.ts b/screens/Home/HomeScreenMachine.ts index 49bc6b42cc..ce9faccd8d 100644 --- a/screens/Home/HomeScreenMachine.ts +++ b/screens/Home/HomeScreenMachine.ts @@ -125,6 +125,10 @@ export const HomeScreenMachine = model.createMachine( }, idle: { on: { + DOWNLOAD_ID: { + actions: 'sendAddEvent', + target: 'idle', + }, GOTO_ISSUERS: 'gotoIssuers', }, }, diff --git a/screens/Home/MyVcsTabMachine.ts b/screens/Home/MyVcsTabMachine.ts index b5b0539cbe..8a0ecf475d 100644 --- a/screens/Home/MyVcsTabMachine.ts +++ b/screens/Home/MyVcsTabMachine.ts @@ -108,6 +108,8 @@ export const MyVcsTabMachine = model.createMachine( entry: ['viewVcFromParent'], on: { DISMISS: 'idle', + VIEW_VC: 'viewingVc', + ADD_VC: 'addVc', }, }, addingVc: { diff --git a/screens/QrLogin/QrLoginController.ts b/screens/QrLogin/QrLoginController.ts index ba360c9620..114caec6bd 100644 --- a/screens/QrLogin/QrLoginController.ts +++ b/screens/QrLogin/QrLoginController.ts @@ -29,6 +29,7 @@ import {ExistingMosipVCItemMachine} from '../../machines/VCItemMachine/ExistingM import {GlobalContext} from '../../shared/GlobalContext'; import {VC} from '../../types/VC/ExistingMosipVC/vc'; import {QrLoginProps} from './QrLogin'; +import {EsignetMosipVCItemMachine} from '../../machines/VCItemMachine/EsignetMosipVCItem/EsignetMosipVCItemMachine'; export function useQrLogin({service}: QrLoginProps) { const {appService} = useContext(GlobalContext); @@ -46,7 +47,11 @@ export function useQrLogin({service}: QrLoginProps) { return { SELECT_VC_ITEM: (index: number) => - (vcRef: ActorRefFrom) => { + ( + vcRef: ActorRefFrom< + typeof EsignetMosipVCItemMachine | typeof EsignetMosipVCItemMachine + >, + ) => { setSelectedIndex(index); const vcData = vcRef.getSnapshot().context; SELECT_VC(vcData); diff --git a/screens/Scan/SendVcScreen.tsx b/screens/Scan/SendVcScreen.tsx index 576a1e8375..e9c97017a0 100644 --- a/screens/Scan/SendVcScreen.tsx +++ b/screens/Scan/SendVcScreen.tsx @@ -12,6 +12,8 @@ import {createExistingMosipVCItemMachine} from '../../machines/VCItemMachine/Exi import {GlobalContext} from '../../shared/GlobalContext'; import {useFocusEffect} from '@react-navigation/native'; import {VcItemContainer} from '../../components/VC/VcItemContainer'; +import {VCMetadata} from '../../shared/VCMetadata'; +import {createEsignetMosipVCItemMachine} from '../../machines/VCItemMachine/EsignetMosipVCItem/EsignetMosipVCItemMachine'; export const SendVcScreen: React.FC = () => { const {t} = useTranslation('SendVcScreen'); @@ -20,11 +22,17 @@ export const SendVcScreen: React.FC = () => { let service; if (controller.shareableVcsMetadata?.length > 0) { + const vcMetadata = controller.shareableVcsMetadata[0]; const firstVCMachine = useRef( - createExistingMosipVCItemMachine( - appService.getSnapshot().context.serviceRefs, - controller.shareableVcsMetadata[0], - ), + VCMetadata.fromVC(vcMetadata).isFromOpenId4VCI() + ? createEsignetMosipVCItemMachine( + appService.getSnapshot().context.serviceRefs, + vcMetadata, + ) + : createExistingMosipVCItemMachine( + appService.getSnapshot().context.serviceRefs, + vcMetadata, + ), ); service = useInterpret(firstVCMachine.current); diff --git a/screens/VerifyIdentityOverlay.tsx b/screens/VerifyIdentityOverlay.tsx index 90517c9605..9c13fc8177 100644 --- a/screens/VerifyIdentityOverlay.tsx +++ b/screens/VerifyIdentityOverlay.tsx @@ -8,11 +8,21 @@ import {VC} from '../types/VC/ExistingMosipVC/vc'; import {Modal} from '../components/ui/Modal'; import {t} from 'i18next'; import {useTranslation} from 'react-i18next'; +import {VCMetadata} from '../shared/VCMetadata'; export const VerifyIdentityOverlay: React.FC< VerifyIdentityOverlayProps > = props => { const {t} = useTranslation('VerifyIdentityOverlay'); + const isOpenId4VCI = + props.vc?.vcMetadata && + VCMetadata.fromVC(props.vc?.vcMetadata).isFromOpenId4VCI(); + const credential = isOpenId4VCI + ? props.vc?.verifiableCredential + : props.vc?.credential; + const vcImage = isOpenId4VCI + ? props.vc?.verifiableCredential.credential.credentialSubject.face + : props.vc?.credential?.biometrics.face; return ( - {props.vc?.credential != null && ( + {credential != null && (