mirror of
https://github.com/mosip/inji-wallet.git
synced 2026-01-08 21:18:14 -05:00
* [INJIMOB-1629] add an api to fetch the trusted verifiers list for vp sharing flow Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-1629] add screens for showing vcs matching openId4vp authorization request and selecting VCs Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-1629] add states in scan machine to show loader screen when vp sharing is started Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-1629] send events to parent machine from openId4vp machine to update UI when performing vp sharing Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-1629] change the position of check box in vc container in vp sharing flow Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-1629] add styles to send vp screen elements to match wireframe and add context variable to store vp sharing purpose Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-1629] show error screen if no credential in wallet matches with authorization request Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-1629] show confirmation pop up when user decline the consent for sharing vp Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-1629] show error screen if the verifier authentication is failed after scanning vp sharing qr code Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-1629] move error and overlay details assigning logic to send vp screen controller Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-1629] add translations for vp sharing flow texts in all languages Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-1629] make changes in card skeleton component to show vc card loader in vp sharing flow Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-1629] fix issues with reject button in sharing vp screen Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-1629] add support for sharing vp with out selfie from kebab menu Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-1629] add support for sharing vp with selfie from kebab menu Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-1629] add missing translations for error and overlay screen texts of vp sharing flow Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-1629] add logic in scan screen to show error screens in vp sharing from kebab menu flow Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-1629] add logic to filter the VCs based on the type of the VC in vp sharing flow Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812]: generate proof for vp token and send vp Signed-off-by: adityankannan-tw <adityan410pm@gmail.com> * [INJIMOB-1629] show generic error message if any error occured while validating vp qr code Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-1629] add logic to allow user retry vp sharing 3 times if any technical error occurred Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-1629] add react method in native module to send the generated vp response metadata and make changes to show any errors occured after sharing vp Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-1629] show success screen if vp is shared successfully to the verifier Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812]: refactor proof generation and integrate remote openid4vp package Signed-off-by: adityankannan-tw <adityan410pm@gmail.com> * [INJIMOB-812]: refactor proof generation and integrate remote openid4vp package Signed-off-by: adityankannan-tw <adityan410pm@gmail.com> * [INJIMOB-812] make changes in the code to fetch the VCs properly if scope is present in the authorization code Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812] fix the logic of checking if order field value in issuer wellknown is null and empty or not Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812] move qr login and openid4vp red id's to scan actions Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812] remove unnecessary logs Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812] rename openid4vp actions to make them more meaningful and remove unnecessary events in send vp screen controller Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812] show error screen if none of the selected VC has image but user chosen share with selfie option Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812] add guard logic for checking if any of the selected VC has image or not Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812]: update package resolved with openid4vp library Signed-off-by: adityankannan-tw <adityan410pm@gmail.com> * [INJIMOB-812] fix the logic of retry button in technical error screen and perform the vp sharing again when user click on retry button Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812] show specific error screen if required info is missing in qr code Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812]: refactor native module and wrapper with updated library name Signed-off-by: adityankannan-tw <adityan410pm@gmail.com> * [INJIMOB-1709]: Integrate VC verifier aar for Vc verification of Mosip VC (#1624) * [INJIMOB-1709]: integrate VC verifier aar for Vc verification of Mosip VC Signed-off-by: Alka Prasad <prasadalka1998@gmail.com> * [INJIMOB-1709]: Handling Response from Vc Verifier Library Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-1709]: Removed mavenLocal from build.gradle Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-1709]: Updated build.gradle Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-1709]: Removed Certify from isMosipVC Condition. Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-1709]: Adding isAndroid check and verifying using digital bazaar for iOs. Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> --------- Signed-off-by: Alka Prasad <prasadalka1998@gmail.com> Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> Co-authored-by: Alka Prasad <prasadalka1998@gmail.com> * [INJIMOB-1629] rename openId4VP to openID4VP in all files and address pr comments Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812] fetch trusted verifiers list from mimoto end point Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812] rename openId4VP to openID4VP in all files Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812] make trusted verifier api call cache preferred Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812] rename openId4VP to openID4VP in all places Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812]: refactor and update openid4vp swift library Signed-off-by: adityankannan-tw <adityan410pm@gmail.com> * [INJIMOB-812] remove code related to scope in openid4vp flow Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812] remove code related to type in openid4vp actions Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812] rename response_uri to response_uris in openid4vp native wrappers Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812] rename typegen file in openid4vp machine Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812] change target state of checkFaceAuthConsent to getTrustedVerifiersList Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812]: update openid4vp swift package Signed-off-by: adityankannan-tw <adityan410pm@gmail.com> * [INJIMOB-2097]: bump up app version to 0.15.0 (#1631) Signed-off-by: adityankannan-tw <adityan410pm@gmail.com> Co-authored-by: adityankannan-tw <adityan410pm@gmail.com> * [INJIMOB-1884] remove SetupKeySelectionScreen (#1632) Signed-off-by: Abhishek Paul <paul.apaul.abhishek.ap@gmail.com> * [INJIMOB-812] change the conditional logic for checking if downloading error is generic or not in issuer guards and selectors Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812] fetch the trusted verifiers list properly from api response Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812] send the list of selected vcs images to face scanner machine only if face is available Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812] fix home button navigation issue in error screen of vp sharing flow Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812] move openid4vp machine to showError state if there is any occurred in vp sharing flow and reset error when user navigates to home screen Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812] fix some flows in vp sharing flow Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> * [INJIMOB-812] fix the logic for showing the error screen as part of scan screen in vp sharing flow Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> --------- Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com> Signed-off-by: adityankannan-tw <adityan410pm@gmail.com> Signed-off-by: Alka Prasad <prasadalka1998@gmail.com> Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> Signed-off-by: Abhishek Paul <paul.apaul.abhishek.ap@gmail.com> Co-authored-by: adityankannan-tw <adityan410pm@gmail.com> Co-authored-by: balachandarg-tw <115633327+balachandarg-tw@users.noreply.github.com> Co-authored-by: Alka Prasad <prasadalka1998@gmail.com> Co-authored-by: adityankannan-tw <109274996+adityankannan-tw@users.noreply.github.com> Co-authored-by: abhip2565 <74866247+abhip2565@users.noreply.github.com>
279 lines
8.4 KiB
TypeScript
279 lines
8.4 KiB
TypeScript
import {Camera, CameraCapturedPicture, PermissionResponse} from 'expo-camera';
|
|
import {ImageType} from 'expo-camera/build/Camera.types';
|
|
import {Linking} from 'react-native';
|
|
import {assign, EventFrom, StateFrom} from 'xstate';
|
|
import {createModel} from 'xstate/lib/model';
|
|
|
|
import {faceCompare} from '@iriscan/biometric-sdk-react-native';
|
|
|
|
const model = createModel(
|
|
{
|
|
cameraRef: {} as Camera,
|
|
faceBounds: {
|
|
minWidth: 280,
|
|
minHeight: 280,
|
|
},
|
|
capturedImage: {} as CameraCapturedPicture,
|
|
captureError: '',
|
|
},
|
|
{
|
|
events: {
|
|
READY: (cameraRef: Camera) => ({cameraRef}),
|
|
CAPTURE: () => ({}),
|
|
DENIED: (response: PermissionResponse) => ({response}),
|
|
GRANTED: () => ({}),
|
|
OPEN_SETTINGS: () => ({}),
|
|
APP_FOCUSED: () => ({}),
|
|
},
|
|
},
|
|
);
|
|
|
|
export const FaceScannerEvents = model.events;
|
|
|
|
export const createFaceScannerMachine = (vcImages: string[]) =>
|
|
/** @xstate-layout N4IgpgJg5mDOIC5QDMCGBjMBldqB2eYATgHQCWeZALiegBZjoDWFUACsQLZmyxkD2eAMQARAKIA5AJJiRiUAAd+fKgLzyQAD0QBaAIwAmAyQMBWAJwBmABzWADHoAslywfOOANCACeu0wHYANhJ-R389SzC3QJjLAF84rzRMHHxCUgpqWgZmVg4ibl41IQBxACUAQQkAFVkNJRU1DW0EHUc7YxtA6z09c2sza3NzQK9fVtdjO0s7fqHrAL1-U0CEpIxsXAJickoaBS4ePkERMEpIIQB5NkkAfSwxauqpCRKseuVqJqQtXW6Q6aGbrWGymIzWMa6AwzEiOCwrZwzbp6QL+NYgZKbNI7TL7Q5FE5nMgXCpsNi3ABilwAwgBVB5yH4NL6CZpQ-zGazhQKmUwdSIGVGQiZGEjTWahIYGOx2azOdGY1LbDJ7EhEMAARwArnBVHh2PjjsJylVaozFJ9VKyfi03I4TJFHI4YqYFkEucL9JY9LC9GDxX7zAYQQqNkr0rssurtbq8obiuJpHUmZbvqAWkt7Y5g45ek7A4EnZ7JmLvQ4ZbKrI5zGjEhiw1sI7ihGUxBURABND6Na3pvzBfwclzWQs80y9CE+RBTexcwWy8eFlyhlKNnawRusEiYin8LV4CBCCCCMC7ABu-CYp8Va9IG7SW53e4PCAoF9wVrwAG07ABdbssuoNq6JY5gkN6gSGCiIJ6HYoTLMKrrGMssH2P4lj+HYzp6CuWLKiQ94EI+Gy7vuh7EEQ-CkAoAA2qBUMgVGcNuDbYnem76ixmCkS+b78B+ag-v+KY9kBfYINKpgkCMrpOg42auIEljCu0PqymEMyyoEBi5qsdY3mxBEcVAQgUgAMlI5LUhUACyYiVABn5sggegLCE-gDCCBiDjWIL+MKM6yhygQLiiiK4eG67GaZFTUmItziLU1Jmo5aa-BMIUkNpMzOOYQUYaMU4SWY0lBiM3qWK6qKOAkdZ4PwEBwBoBn4bi2SMCw+r5IURqpb26VtHYwQYUOSlWEYNieiF1ghGEhg1g47jLvprGtaqBwFEcainOcEB9WJA3mD6fIVQYfozNKLjFsGJCmDMIxLTl47xCtq6GW1G09WoJREPgVCQPtzmDfaGEYQMvJOpYSmehE-jSX6rmQdM7gRNYEW3pGNDRjqsB6gam0EgdzJOcBLkeSE0odIO-go3B-lFTorqWCYc2RA4yxBAY6PvXsgOk20MIjdCY2TJNDPIrN4TBpB0puOY3P4YRlCcU+ZF8+JjMzbYjhcjW7TmHyQTCjYM2yehMojjpKIKxGSvEZgEj8FQPF7SJgFA5l2aonK4Rgk43mmAF2awmVmGVa5zpwjbUUPvq6sDTY9rZVhoH5UbRVOHYpXRNmZgebMXOvXhTacKgMDUqgChUFq6quxaolA+0YoxAjbgjrYRjCuhUlmO0Osophzq1usb3KvHLRtKYIODsLoGi5O4w6Ms9rwYYyxGL0ha1XEQA */
|
|
model.createMachine(
|
|
{
|
|
predictableActionArguments: true,
|
|
preserveActionOrder: true,
|
|
tsTypes: {} as import('./faceScanner.typegen').Typegen0,
|
|
schema: {
|
|
context: model.initialContext,
|
|
events: {} as EventFrom<typeof model>,
|
|
services: {} as {
|
|
captureImage: {
|
|
data: CameraCapturedPicture;
|
|
};
|
|
verifyImage: {
|
|
data: boolean;
|
|
};
|
|
},
|
|
},
|
|
id: 'faceScanner',
|
|
initial: 'init',
|
|
states: {
|
|
init: {
|
|
initial: 'checkingPermission',
|
|
states: {
|
|
checkingPermission: {
|
|
invoke: {
|
|
src: 'checkPermission',
|
|
},
|
|
on: {
|
|
DENIED: [
|
|
{
|
|
cond: 'canRequestPermission',
|
|
target: 'requestingPermission',
|
|
},
|
|
{
|
|
target: 'permissionDenied',
|
|
},
|
|
],
|
|
GRANTED: {
|
|
target: 'permissionGranted',
|
|
},
|
|
},
|
|
},
|
|
permissionDenied: {
|
|
on: {
|
|
OPEN_SETTINGS: {
|
|
actions: 'openSettings',
|
|
},
|
|
APP_FOCUSED: {
|
|
target: 'checkingPermission',
|
|
},
|
|
},
|
|
},
|
|
permissionGranted: {},
|
|
requestingPermission: {
|
|
invoke: {
|
|
src: 'requestPermission',
|
|
},
|
|
on: {
|
|
GRANTED: {
|
|
target: 'permissionGranted',
|
|
},
|
|
DENIED: {
|
|
target: 'permissionDenied',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
on: {
|
|
READY: {
|
|
actions: 'setCameraRef',
|
|
target: 'scanning',
|
|
},
|
|
},
|
|
},
|
|
scanning: {
|
|
on: {
|
|
CAPTURE: {
|
|
target: 'capturing',
|
|
},
|
|
},
|
|
},
|
|
capturing: {
|
|
invoke: {
|
|
src: 'captureImage',
|
|
onDone: [
|
|
{
|
|
actions: 'setCapturedImage',
|
|
target: '#faceScanner.verifying',
|
|
},
|
|
],
|
|
onError: [
|
|
{
|
|
actions: 'setCaptureError',
|
|
target: 'scanning',
|
|
},
|
|
],
|
|
},
|
|
},
|
|
verifying: {
|
|
invoke: {
|
|
src: 'verifyImage',
|
|
onDone: [
|
|
{
|
|
cond: 'doesFaceMatch',
|
|
target: 'valid',
|
|
},
|
|
{
|
|
target: 'invalid',
|
|
},
|
|
],
|
|
onError: {
|
|
target: 'invalid',
|
|
},
|
|
},
|
|
},
|
|
valid: {
|
|
type: 'final',
|
|
},
|
|
invalid: {
|
|
type: 'final',
|
|
},
|
|
},
|
|
},
|
|
{
|
|
actions: {
|
|
setCameraRef: model.assign({
|
|
cameraRef: (_context, event) => event.cameraRef,
|
|
}),
|
|
|
|
setCapturedImage: assign({
|
|
capturedImage: (_context, event) => event.data,
|
|
}),
|
|
|
|
setCaptureError: assign({
|
|
captureError: '',
|
|
}),
|
|
|
|
openSettings: () => Linking.openSettings(),
|
|
},
|
|
|
|
services: {
|
|
checkPermission: () => async callback => {
|
|
const result = await Camera.getCameraPermissionsAsync();
|
|
if (result.granted) {
|
|
callback(FaceScannerEvents.GRANTED());
|
|
} else {
|
|
callback(FaceScannerEvents.DENIED(result));
|
|
}
|
|
},
|
|
|
|
requestPermission: () => async callback => {
|
|
const result = await Camera.requestCameraPermissionsAsync();
|
|
if (result.granted) {
|
|
callback(FaceScannerEvents.GRANTED());
|
|
} else {
|
|
callback(FaceScannerEvents.DENIED(result));
|
|
}
|
|
},
|
|
|
|
captureImage: context => {
|
|
return context.cameraRef.takePictureAsync({
|
|
base64: true,
|
|
imageType: ImageType.jpg,
|
|
});
|
|
},
|
|
|
|
verifyImage: async context => {
|
|
context.cameraRef.pausePreview();
|
|
const rxDataURI =
|
|
/data:(?<mime>[\w/\-.]+);(?<encoding>\w+),(?<data>.*)/;
|
|
|
|
let isMatchFound = false;
|
|
for (const vcImage of vcImages) {
|
|
const matches = rxDataURI.exec(vcImage).groups;
|
|
|
|
try {
|
|
isMatchFound = await faceCompare(
|
|
context.capturedImage.base64,
|
|
matches.data,
|
|
);
|
|
if (isMatchFound) {
|
|
break;
|
|
}
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
return isMatchFound;
|
|
},
|
|
|
|
checkNetworkStatus: async () => {
|
|
const state = await NetInfo.fetch();
|
|
return state.isConnected;
|
|
},
|
|
},
|
|
|
|
guards: {
|
|
canRequestPermission: (_context, event) => {
|
|
return event.response.canAskAgain;
|
|
},
|
|
|
|
doesFaceMatch: (_context, event) => event.data,
|
|
},
|
|
},
|
|
);
|
|
|
|
type State = StateFrom<ReturnType<typeof createFaceScannerMachine>>;
|
|
|
|
export function selectCameraRef(state: State) {
|
|
return state.context.cameraRef;
|
|
}
|
|
|
|
export function selectCapturedImage(state: State) {
|
|
return state.context.capturedImage;
|
|
}
|
|
|
|
export function selectIsCheckingPermission(state: State) {
|
|
return state.matches('init.checkingPermission');
|
|
}
|
|
|
|
export function selectIsPermissionDenied(state: State) {
|
|
return state.matches('init.permissionDenied');
|
|
}
|
|
|
|
export function selectIsScanning(state: State) {
|
|
return state.matches('scanning');
|
|
}
|
|
|
|
export function selectIsCapturing(state: State) {
|
|
return state.matches('capturing');
|
|
}
|
|
|
|
export function selectIsVerifying(state: State) {
|
|
return state.matches('verifying');
|
|
}
|
|
|
|
export function selectIsValid(state: State) {
|
|
return state.matches('valid');
|
|
}
|
|
|
|
export function selectIsInvalid(state: State) {
|
|
return state.matches('invalid');
|
|
}
|