Skip to content

Commit

Permalink
Refactor(inji-429) : standardize issuers configuration (#937)
Browse files Browse the repository at this point in the history
* refactor(inji-429): standardize the issuers configuration

Signed-off-by: Vijay <[email protected]>

* refactor(inji-249): optimise the issuers protocols implementations

Signed-off-by: Vijay <[email protected]>

* refactor(inji-249): remove unnecessary states and unused icons

Signed-off-by: Vijay <[email protected]>

---------

Signed-off-by: Vijay <[email protected]>
  • Loading branch information
vijay151096 authored Oct 18, 2023
1 parent 2bb82ba commit ad76243
Show file tree
Hide file tree
Showing 24 changed files with 338 additions and 460 deletions.
3 changes: 0 additions & 3 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,3 @@ DEBUG_MODE=false

#supported languages( en, fil, ar, hi, kn, ta)
APPLICATION_LANGUAGE=en

#Toggle for openID for VC
ENABLE_OPENID_FOR_VC=true
Binary file removed assets/digit-icon.png
Binary file not shown.
8 changes: 5 additions & 3 deletions components/VC/MosipVCItem/MosipVCItemContent.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react';
import {useTranslation} from 'react-i18next';
import {Image, ImageBackground, View} from 'react-native';
import {Image, ImageBackground} from 'react-native';
import {getLocalizedField} from '../../../i18n';
import {VerifiableCredential} from '../../../types/VC/ExistingMosipVC/vc';
import VerifiedIcon from '../../VerifiedIcon';
import {Column, Row, Text} from '../../ui';
import {Theme} from '../../ui/styleUtils';
import {CheckBox, Icon} from 'react-native-elements';
import testIDProps from '../../../shared/commonUtil';
import {logoType} from '../../../machines/issuersMachine';

const getDetails = (arg1, arg2, verifiableCredential) => {
if (arg1 === 'Status') {
Expand Down Expand Up @@ -87,11 +88,12 @@ function getIdNumber(id: string) {
return '*'.repeat(id.length - 4) + id.slice(-4);
}

const getIssuerLogo = (isOpenId4VCI: boolean, issuerLogo: string) => {
const getIssuerLogo = (isOpenId4VCI: boolean, issuerLogo: logoType) => {
if (isOpenId4VCI) {
return (
<Image
src={issuerLogo}
src={issuerLogo?.url}
alt={issuerLogo?.alt_text}
style={Theme.Styles.issuerLogo}
resizeMethod="scale"
resizeMode="contain"
Expand Down
13 changes: 10 additions & 3 deletions components/VC/MosipVCItem/MosipVCItemDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as DateFnsLocale from 'date-fns/locale';
import {useTranslation} from 'react-i18next';
import {Dimensions, Image, ImageBackground, View} from 'react-native';
import {Icon} from 'react-native-elements';
import {VC, CredentialSubject} from '../../../types/VC/ExistingMosipVC/vc';
import {CredentialSubject, VC} from '../../../types/VC/ExistingMosipVC/vc';
import {Button, Column, Row, Text} from '../../ui';
import {Theme} from '../../ui/styleUtils';
import {TextItem} from '../../ui/TextItem';
Expand All @@ -20,10 +20,17 @@ import {
VerifiablePresentation,
} from '../../../types/VC/EsignetMosipVC/vc';
import {WalletBindingResponse} from '../../../shared/cryptoutil/cryptoUtil';
import {logoType} from '../../../machines/issuersMachine';

const getIssuerLogo = (isOpenId4VCI: boolean, issuerLogo: string) => {
const getIssuerLogo = (isOpenId4VCI: boolean, issuerLogo: logoType) => {
if (isOpenId4VCI) {
return <Image src={issuerLogo} style={Theme.Styles.issuerLogo} />;
return (
<Image
src={issuerLogo?.url}
alt={issuerLogo?.alt_text}
style={Theme.Styles.issuerLogo}
/>
);
}
return <Image source={Theme.MosipLogo} style={Theme.Styles.vcDetailsLogo} />;
};
Expand Down
3 changes: 1 addition & 2 deletions components/openId4VCI/Issuer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ export const Issuer: React.FC<IssuerProps> = (props: IssuerProps) => {
const {t} = useTranslation('IssuersScreen');

function getIssuerLogo() {
if (props.logoUrl) return {uri: props.logoUrl};
return Theme.DigitIcon;
return {uri: props.logoUrl};
}

return (
Expand Down
1 change: 0 additions & 1 deletion components/ui/themes/DefaultTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,6 @@ export const DefaultTheme = {
protectPrivacy: require('../../../assets/intro-unlock-method.png'),
NoInternetConnection: require('../../../assets/no-internet-connection.png'),
SomethingWentWrong: require('../../../assets/something-went-wrong.png'),
DigitIcon: require('../../../assets/digit-icon.png'),

elevation(level: ElevationLevel): ViewStyle {
// https://ethercreative.github.io/react-native-shadow-generator/
Expand Down
1 change: 0 additions & 1 deletion components/ui/themes/PurpleTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,6 @@ export const PurpleTheme = {
protectPrivacy: require('../../../assets/intro-unlock-method.png'),
NoInternetConnection: require('../../../assets/no-internet-connection.png'),
SomethingWentWrong: require('../../../assets/something-went-wrong.png'),
DigitIcon: require('../../../assets/digit-icon.png'),

elevation(level: ElevationLevel): ViewStyle {
// https://ethercreative.github.io/react-native-shadow-generator/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
WalletBindingResponse,
} from '../../../shared/cryptoutil/cryptoUtil';
import {log} from 'xstate/lib/actions';
import {OpenId4VCIProtocol} from '../../../shared/openId4VCI/Utils';
import {Protocols} from '../../../shared/openId4VCI/Utils';
import {StoreEvents} from '../../../machines/store';
import {MIMOTO_BASE_URL, MY_VCS_STORE_KEY} from '../../../shared/constants';
import {VcEvents} from '../../../machines/vc';
Expand Down Expand Up @@ -500,7 +500,7 @@ export const EsignetMosipVCItemMachine = model.createMachine(
context => ({
type: 'GET_VC_ITEM',
vcMetadata: context.vcMetadata,
protocol: OpenId4VCIProtocol,
protocol: Protocols.OpenId4VCI,
}),
{
to: context => context.serviceRefs.vc,
Expand Down
109 changes: 46 additions & 63 deletions machines/auth.typegen.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,47 @@
// This file was automatically generated. Edits will be overwritten

export interface Typegen0 {
'@@xstate/typegen': true;
internalEvents: {
'': {type: ''};
'done.invoke.auth.authorized:invocation[0]': {
type: 'done.invoke.auth.authorized:invocation[0]';
data: unknown;
__tip: 'See the XState TS docs to learn how to strongly type this.';
};
'done.invoke.auth.introSlider:invocation[0]': {
type: 'done.invoke.auth.introSlider:invocation[0]';
data: unknown;
__tip: 'See the XState TS docs to learn how to strongly type this.';
};
'xstate.init': {type: 'xstate.init'};
};
invokeSrcNameMap: {
downloadFaceSdkModel: 'done.invoke.auth.authorized:invocation[0]';
generatePasscodeSalt: 'done.invoke.auth.introSlider:invocation[0]';
};
missingImplementations: {
actions: never;
delays: never;
guards: never;
services: never;
};
eventsCausingActions: {
requestStoredContext: 'xstate.init';
setBiometrics: 'SETUP_BIOMETRICS';
setContext: 'STORE_RESPONSE';
setLanguage: 'SETUP_BIOMETRICS' | 'SETUP_PASSCODE';
setPasscode: 'SETUP_PASSCODE';
setPasscodeSalt: 'done.invoke.auth.introSlider:invocation[0]';
storeContext:
| 'SETUP_BIOMETRICS'
| 'SETUP_PASSCODE'
| 'STORE_RESPONSE'
| 'done.invoke.auth.authorized:invocation[0]'
| 'done.invoke.auth.introSlider:invocation[0]';
};
eventsCausingDelays: {};
eventsCausingGuards: {
hasBiometricSet: '';
hasData: 'STORE_RESPONSE';
hasLanguageset: '';
hasPasscodeSet: '';
};
eventsCausingServices: {
downloadFaceSdkModel: 'LOGIN' | 'SETUP_PASSCODE';
generatePasscodeSalt: 'SELECT';
};
matchesStates:
| 'authorized'
| 'checkingAuth'
| 'init'
| 'introSlider'
| 'languagesetup'
| 'savingDefaults'
| 'settingUp'
| 'unauthorized';
tags: never;
}
// This file was automatically generated. Edits will be overwritten

export interface Typegen0 {
'@@xstate/typegen': true;
internalEvents: {
"": { type: "" };
"done.invoke.auth.authorized:invocation[0]": { type: "done.invoke.auth.authorized:invocation[0]"; data: unknown; __tip: "See the XState TS docs to learn how to strongly type this." };
"done.invoke.auth.introSlider:invocation[0]": { type: "done.invoke.auth.introSlider:invocation[0]"; data: unknown; __tip: "See the XState TS docs to learn how to strongly type this." };
"xstate.init": { type: "xstate.init" };
};
invokeSrcNameMap: {
"downloadFaceSdkModel": "done.invoke.auth.authorized:invocation[0]";
"generatePasscodeSalt": "done.invoke.auth.introSlider:invocation[0]";
};
missingImplementations: {
actions: never;
delays: never;
guards: never;
services: never;
};
eventsCausingActions: {
"requestStoredContext": "xstate.init";
"setBiometrics": "SETUP_BIOMETRICS";
"setContext": "STORE_RESPONSE";
"setLanguage": "SETUP_BIOMETRICS" | "SETUP_PASSCODE";
"setPasscode": "SETUP_PASSCODE";
"setPasscodeSalt": "done.invoke.auth.introSlider:invocation[0]";
"storeContext": "SETUP_BIOMETRICS" | "SETUP_PASSCODE" | "STORE_RESPONSE" | "done.invoke.auth.authorized:invocation[0]" | "done.invoke.auth.introSlider:invocation[0]";
};
eventsCausingDelays: {

};
eventsCausingGuards: {
"hasBiometricSet": "";
"hasData": "STORE_RESPONSE";
"hasLanguageset": "";
"hasPasscodeSet": "";
};
eventsCausingServices: {
"downloadFaceSdkModel": "LOGIN" | "SETUP_PASSCODE";
"generatePasscodeSalt": "SELECT";
};
matchesStates: "authorized" | "checkingAuth" | "init" | "introSlider" | "languagesetup" | "savingDefaults" | "settingUp" | "unauthorized";
tags: never;
}

71 changes: 38 additions & 33 deletions machines/issuersMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import {
vcDownloadTimeout,
OIDCErrors,
ErrorMessage,
updateCredentialInformation,
constructAuthorizationConfiguration,
getVCMetadata,
} from '../shared/openId4VCI/Utils';
import {NETWORK_REQUEST_FAILED, REQUEST_TIMEOUT} from '../shared/constants';
import {VCMetadata} from '../shared/VCMetadata';
Expand Down Expand Up @@ -68,7 +71,7 @@ const model = createModel(
export const IssuerScreenTabEvents = model.events;
export const Issuer_Tab_Ref_Id = 'issuersMachine';

export const Issuers_Key_Ref = 'OpenId4VCI';
export const Issuers_Key_Ref = 'OpenId4VCI_KeyPair';
export const IssuersMachine = model.createMachine(
{
/** @xstate-layout N4IgpgJg5mDOIC5QEtawK5gE6wLIEMBjAC2QDswA6CVABwBt8BPASTUxwGIIB7Cy8gDceAayqoM2PEVL8asBszaScCIT0L4ALsj4BtAAwBdQ0cShaPWMh19zIAB6IALAEYA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4wVmyVnRkzJvWJsQC3IFOQNqJkKPmG4uZMiXF1JSTYhZ0i7DGReBsTYbwqCLUauMu4iRUh+pmIUG0km2gGQURMqNNibTzTg6UNS6LST0lAHt4TEDGJcoWWhI6xreACGSXNyKcmNQSs1S6+0tBrtjGGgZU6XqsqSMEc0ZJtwFRNAUHeGYz7Hvzae3a-V2oQ1aAka9VCwVROhS3PKfhlwFA+mNZMjxcgORskkI9IkUU8xzonPOpthb-LCW0gSoofB+C8GNFaLd4zLhjmMq+qCx5gYsoehcMcbi7g2imVW5H0yqrGjcPwlo6pzueZQfhMjGNYGY1-PwhISQFGeoJlILCwJeHWhmBVFahK-vnchCZBTSXYvjco4tCAch9LU7Va48ZHSUjORc4lUAsUlJk+sQZyYqrrgNFrZ9VrKR3uMR5TWZGf5tq0AzZsbnSO+0NNkNwbhHKQsEv7bcar8pgW8FsUI2r6zRZRhmNIMdVy5Dyuqyz84AhPXsqqlI0aSL5ZgjawdXSR26NOCmX2WxHS6k-Xxs+JQgA */
Expand Down Expand Up @@ -171,7 +174,8 @@ export const IssuersMachine = model.createMachine(
},
],
onError: {
actions: () => console.log('checkInternet error caught'),
actions: () =>
console.log('Error Occurred while checking Internet'),
target: 'error',
},
},
Expand Down Expand Up @@ -205,7 +209,11 @@ export const IssuersMachine = model.createMachine(
actions: [
'setError',
'resetLoadingReason',
(_, event) => console.log('error in invokeAuth - ', event.data),
(_, event) =>
console.log(
'Error Occurred while invoking Auth - ',
event.data,
),
],
target: 'error',
},
Expand Down Expand Up @@ -499,7 +507,7 @@ export const IssuersMachine = model.createMachine(
const downloadTimeout = await vcDownloadTimeout();
let credential = await request(
'POST',
context.selectedIssuer.serviceConfiguration.credentialEndpoint,
context.selectedIssuer.credential_endpoint,
body,
'',
{
Expand All @@ -518,10 +526,12 @@ export const IssuersMachine = model.createMachine(
sendImpressionEvent(
getImpressionEventData(
'VC Download',
context.selectedIssuer.id + ' Web View Page',
context.selectedIssuer.credential_issuer + ' Web View Page',
),
);
return await authorize(context.selectedIssuer);
return await authorize(
constructAuthorizationConfiguration(context.selectedIssuer),
);
},
generateKeyPair: async context => {
if (!isCustomSecureKeystore()) {
Expand Down Expand Up @@ -607,32 +617,27 @@ export function selectStoring(state: State) {
return state.matches('storing');
}

interface issuerType {
id: string;
displayName: string;
logoUrl: string;
export interface logoType {
url: string;
alt_text: string;
}

const updateCredentialInformation = (context, credential) => {
let credentialWrapper: CredentialWrapper = {};
credentialWrapper.verifiableCredential = credential;
credentialWrapper.verifiableCredential.issuerLogo =
context.selectedIssuer.logoUrl;
credentialWrapper.identifier = getIdentifier(context, credential);
credentialWrapper.generatedOn = new Date();
credentialWrapper.issuerLogo = context.selectedIssuer.logoUrl;
return credentialWrapper;
};

const getVCMetadata = context => {
const [issuer, protocol, requestId] =
context.credentialWrapper?.identifier.split(':');
return VCMetadata.fromVC({
requestId: requestId ? requestId : null,
issuer: issuer,
protocol: protocol,
id: context.verifiableCredential?.credential.credentialSubject.UIN
? context.verifiableCredential?.credential.credentialSubject.UIN
: context.verifiableCredential?.credential.credentialSubject.VID,
});
};
export interface displayType {
name: string;
logo: logoType;
language: string;
}
export interface issuerType {
credential_issuer: string;
protocol: string;
client_id: string;
'.well-known': string;
redirect_uri: string;
scopes_supported: [string];
additional_headers: object;
authorization_endpoint: string;
token_endpoint: string;
credential_endpoint: string;
credential_audience: string;
display: [displayType];
}
Loading

0 comments on commit ad76243

Please sign in to comment.