Skip to content

Commit

Permalink
fix(inji-420): refactoring esignet vc sharing and login cases. (#899)
Browse files Browse the repository at this point in the history
* fix(inji-423): vc details view is not opening sometimes.

* fix(inji-420): share esignet vc via BLE

* fix(inji-420 | inji-421): share vc via BLE with and without selfie, and perform esignet login

* fix(inji-420 | inji-421): log qr login successfull with ID

* fix(inji-420 | inji-421): refactor to use vcmetadata for both vc's

* fix(inji-420 | inji-421): remove unwanted loggers

* fix(inji-420 | inji-421): refactoring variables declarations
  • Loading branch information
vijay151096 authored Oct 10, 2023
1 parent 4ccc4de commit 16ef93e
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 41 deletions.
15 changes: 6 additions & 9 deletions machines/QrLoginMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,19 +359,15 @@ export const qrLoginMachine =

sendAuthenticate: async context => {
let privateKey;

const individualId = context.selectedVc.vcMetadata.id;
if (!isCustomSecureKeystore()) {
privateKey = await getPrivateKey(
context.selectedVc.walletBindingResponse?.walletBindingId,
);
}

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',
Expand All @@ -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',
Expand All @@ -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,
Expand All @@ -405,7 +402,7 @@ export const qrLoginMachine =

const jwt = await getJwt(
privateKey,
context.selectedVc.id,
individualId,
context.thumbprint,
);

Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ export const EsignetMosipVCItemMachine = model.createMachine(
on: {
GET_VC_RESPONSE: [
{
actions: ['setVerifiableCredential', 'setGeneratedOn'],
actions: [
'setVerifiableCredential',
'setContext',
'setGeneratedOn',
],
cond: 'hasCredential',
target: 'idle',
},
Expand Down Expand Up @@ -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,
Expand All @@ -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;
},
Expand All @@ -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;
}),

Expand Down Expand Up @@ -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: [
Expand Down
29 changes: 18 additions & 11 deletions machines/bleShare/request/requestMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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},
),

Expand Down Expand Up @@ -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},
Expand All @@ -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},
),
Expand Down
14 changes: 8 additions & 6 deletions machines/bleShare/scan/scanMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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},
),

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion machines/vc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

Expand Down
4 changes: 4 additions & 0 deletions screens/Home/HomeScreenMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ export const HomeScreenMachine = model.createMachine(
},
idle: {
on: {
DOWNLOAD_ID: {
actions: 'sendAddEvent',
target: 'idle',
},
GOTO_ISSUERS: 'gotoIssuers',
},
},
Expand Down
2 changes: 2 additions & 0 deletions screens/Home/MyVcsTabMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export const MyVcsTabMachine = model.createMachine(
entry: ['viewVcFromParent'],
on: {
DISMISS: 'idle',
VIEW_VC: 'viewingVc',
ADD_VC: 'addVc',
},
},
addingVc: {
Expand Down
7 changes: 6 additions & 1 deletion screens/QrLogin/QrLoginController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -46,7 +47,11 @@ export function useQrLogin({service}: QrLoginProps) {
return {
SELECT_VC_ITEM:
(index: number) =>
(vcRef: ActorRefFrom<typeof ExistingMosipVCItemMachine>) => {
(
vcRef: ActorRefFrom<
typeof EsignetMosipVCItemMachine | typeof EsignetMosipVCItemMachine
>,
) => {
setSelectedIndex(index);
const vcData = vcRef.getSnapshot().context;
SELECT_VC(vcData);
Expand Down
16 changes: 12 additions & 4 deletions screens/Scan/SendVcScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
Expand Down
14 changes: 12 additions & 2 deletions screens/VerifyIdentityOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Modal
isVisible={props.isVisible}
Expand All @@ -23,9 +33,9 @@ export const VerifyIdentityOverlay: React.FC<
fill
style={Theme.VerifyIdentityOverlayStyles.content}
align="center">
{props.vc?.credential != null && (
{credential != null && (
<FaceScanner
vcImage={props.vc.credential.biometrics.face}
vcImage={vcImage}
onValid={props.onFaceValid}
onInvalid={props.onFaceInvalid}
/>
Expand Down

0 comments on commit 16ef93e

Please sign in to comment.