Skip to content

Commit

Permalink
[INJIMOB-1240] : Fix face auth consent for minified view share (mosip…
Browse files Browse the repository at this point in the history
…#1397)

* [INJIMOB-1240] Resolve conflicts

Signed-off-by: Abhishek Paul <[email protected]>

* [INJIMOB-1240] Refactor scan machine and QrLogin machine

Signed-off-by: Abhishek Paul <[email protected]>

* [INJIMOB-1240] Refactor scan machine and QrLogin machine

Signed-off-by: Abhishek Paul <[email protected]>

* [INJIMOB-1240] Refactor scan machine and QrLogin machine

Signed-off-by: Abhishek Paul <[email protected]>

* [INJIMOB-1240]: Fix.Share with selfie pop up bug

Signed-off-by: Abhishek Paul <[email protected]>

* [INJIMOB-1240]: Refactor. scanMachine and qrLoginMachine

Signed-off-by: Abhishek Paul <[email protected]>

* [INJIMOB-1240]: Refactor. scanMachine and qrLoginMachine

Signed-off-by: Abhishek Paul <[email protected]>

---------

Signed-off-by: Abhishek Paul <[email protected]>
  • Loading branch information
abhip2565 authored May 2, 2024
1 parent 8feff67 commit 5351a90
Show file tree
Hide file tree
Showing 35 changed files with 1,972 additions and 2,389 deletions.
2 changes: 1 addition & 1 deletion components/KebabPopUpController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {ScanEvents} from '../machines/bleShare/scan/scanMachine';
import {BOTTOM_TAB_ROUTES, ScanStackParamList} from '../routes/routesConstants';
import {NavigationProp, useNavigation} from '@react-navigation/native';
import {MainBottomTabParamList} from '../routes/main';
import {selectIsScanning} from '../machines/bleShare/scan/selectors';
import {selectIsScanning} from '../machines/bleShare/scan/scanSelectors';
import {
VCItemEvents,
VCItemMachine,
Expand Down
6 changes: 3 additions & 3 deletions machines/Issuers/IssuersMachine.typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
"verifyCredential": "done.invoke.issuersMachine.verifyingCredential:invocation[0]";
};
missingImplementations: {
actions: never;
actions: "getKeyPairFromStore" | "loadKeyPair" | "logDownloaded" | "resetError" | "resetLoadingReason" | "resetVerificationErrorMessage" | "sendBackupEvent" | "sendErrorEndEvent" | "sendImpressionEvent" | "sendSuccessEndEvent" | "setCredentialTypes" | "setCredentialWrapper" | "setError" | "setIssuers" | "setLoadingReasonAsDisplayIssuers" | "setLoadingReasonAsDownloadingCredentials" | "setLoadingReasonAsSettingUp" | "setMetadataInCredentialData" | "setNoInternet" | "setOIDCConfigError" | "setPrivateKey" | "setPublicKey" | "setSelectedCredentialType" | "setSelectedIssuerId" | "setSelectedIssuers" | "setTokenResponse" | "setVCMetadata" | "setVerifiableCredential" | "storeKeyPair" | "storeVcMetaContext" | "storeVcsContext" | "storeVerifiableCredentialData" | "storeVerifiableCredentialMeta" | "updateVerificationErrorMessage";
delays: never;
guards: never;
services: never;
guards: "canSelectIssuerAgain" | "hasKeyPair" | "hasUserCancelledBiometric" | "isCustomSecureKeystore" | "isInternetConnected" | "isMultipleCredentialsSupported" | "isOIDCConfigError" | "isOIDCflowCancelled" | "isSignedIn" | "shouldFetchIssuersAgain";
services: "checkInternet" | "downloadCredential" | "downloadCredentialTypes" | "downloadIssuerConfig" | "downloadIssuersList" | "generateKeyPair" | "invokeAuthorization" | "isUserSignedAlready" | "verifyCredential";
};
eventsCausingActions: {
"getKeyPairFromStore": "TRY_AGAIN" | "done.invoke.issuersMachine.performAuthorization:invocation[0]";
Expand Down
170 changes: 170 additions & 0 deletions machines/QrLogin/QrLoginActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import { assign, send, sendParent } from "xstate";
import i18n from "../../i18n";
import { VCShareFlowType } from "../../shared/Utils";
import { parseMetadatas } from "../../shared/VCMetadata";
import { SHOW_FACE_AUTH_CONSENT_QR_LOGIN_FLOW, MY_VCS_STORE_KEY } from "../../shared/constants";
import { getBindingCertificateConstant } from "../../shared/keystore/SecureKeystore";
import { VC, linkTransactionResponse } from "../VerifiableCredential/VCMetaMachine/vc";
import { StoreEvents } from "../store";



export const QrLoginActions=(model:any)=>{

return{
setShowFaceAuthConsent: model.assign({
showFaceAuthConsent: (_, event) => {
return !event.isDoNotAskAgainChecked;
},
}),

storeShowFaceAuthConsent: send(
(context, event) =>
StoreEvents.SET(SHOW_FACE_AUTH_CONSENT_QR_LOGIN_FLOW, !event.isDoNotAskAgainChecked),
{
to: context => context.serviceRefs.store,
},
),

forwardToParent: sendParent('DISMISS'),

setScanData: model.assign((context, event) => {
const linkCode = event.linkCode;
const flowType = event.flowType;
const selectedVc = event.selectedVc;
return {
...context,
linkCode: linkCode,
flowType: flowType,
selectedVc: selectedVc,
};
}),
getFaceAuthConsent: send(StoreEvents.GET(SHOW_FACE_AUTH_CONSENT_QR_LOGIN_FLOW), {
to: (context:any) => context.serviceRefs.store,
}),

updateShowFaceAuthConsent: model.assign({
showFaceAuthConsent: (_, event) => {
return event.response || event.response === null;
},
}),

// TODO: loaded VCMetadatas are not used anywhere. remove?
loadMyVcs: send(StoreEvents.GET(MY_VCS_STORE_KEY), {
to: context => context.serviceRefs.store,
}),

setMyVcs: model.assign({
myVcs: (_context, event) =>
parseMetadatas((event.response || []) as object[]),
}),

loadThumbprint: send(
context =>
StoreEvents.GET(
getBindingCertificateConstant(
context.selectedVc.walletBindingResponse?.walletBindingId,
),
),
{to: context => context.serviceRefs.store},
),
setThumbprint: assign({
thumbprint: (_context, event) => {
return (event.response || '') as string;
},
}),
resetLinkTransactionId: model.assign({
linkTransactionId: () => '',
}),

resetSelectedVoluntaryClaims: model.assign({
selectedVoluntaryClaims: () => [],
}),

setSelectedVc: assign({
selectedVc: (context, event) => {
return {...event.vc};
},
}),

resetSelectedVc: assign({
selectedVc: {} as VC,
}),

resetFlowType: assign({
flowType: VCShareFlowType.SIMPLE_SHARE,
}),

setlinkTransactionResponse: assign({
linkTransactionResponse: (context, event) =>
event.data as linkTransactionResponse,
}),

expandLinkTransResp: assign({
authFactors: context => context.linkTransactionResponse.authFactors,

authorizeScopes: context =>
context.linkTransactionResponse.authorizeScopes,

clientName: context => context.linkTransactionResponse.clientName,

configs: context => context.linkTransactionResponse.configs,

essentialClaims: context =>
context.linkTransactionResponse.essentialClaims,

linkTransactionId: context =>
context.linkTransactionResponse.linkTransactionId,

logoUrl: context => context.linkTransactionResponse.logoUrl,

voluntaryClaims: context =>
context.linkTransactionResponse.voluntaryClaims,
}),

setClaims: context => {
context.voluntaryClaims.map(claim => {
context.isSharing[claim] = false;
});
},

SetErrorMessage: assign({
errorMessage: (context, event) => {
const message = event.data.name;
const ID_ERRORS_MAP = {
invalid_link_code: 'invalidQR',
};
const errorMessage = ID_ERRORS_MAP[message]
? i18n.t(`errors.${ID_ERRORS_MAP[message]}`, {
ns: 'QrLogin',
})
: i18n.t(`errors.genericError`, {
ns: 'common',
});

return errorMessage;
},
}),

setConsentClaims: assign({
isSharing: (context, event) => {
context.isSharing[event.claim] = !event.enable;
if (!event.enable) {
context.selectedVoluntaryClaims.push(event.claim);
} else {
context.selectedVoluntaryClaims =
context.selectedVoluntaryClaims.filter(
eachClaim => eachClaim !== event.claim,
);
}
return {...context.isSharing};
},
}),
setLinkedTransactionId: assign({
linkedTransactionId: (context, event) =>
event.data.linkedTransactionId as string,
}),
}
}


13 changes: 13 additions & 0 deletions machines/QrLogin/QrLoginGuards.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { VCShareFlowType } from "../../shared/Utils";

export const QrLoginGuards={
showFaceAuthConsentScreen: context => {
return context.showFaceAuthConsent;
},

isConsentAlreadyCaptured: (_, event) =>
event.data?.consentAction === 'NOCAPTURE',

isSimpleShareFlow: (context, _event) =>
context.flowType === VCShareFlowType.SIMPLE_SHARE,
}
Loading

0 comments on commit 5351a90

Please sign in to comment.