From 4514134209404a5b1733b5adf3deeef3ce294b07 Mon Sep 17 00:00:00 2001 From: KiruthikaJeyashankar <81218987+KiruthikaJeyashankar@users.noreply.github.com> Date: Mon, 16 Sep 2024 16:29:22 +0530 Subject: [PATCH] [INJIMOB-1078] use constants for hardcoded vc formats Signed-off-by: KiruthikaJeyashankar <81218987+KiruthikaJeyashankar@users.noreply.github.com> --- components/VC/Views/VCDetailView.tsx | 5 +- components/VC/common/VCUtils.tsx | 11 ++-- mdoc.json | 94 ---------------------------- shared/VCMetadata.ts | 3 +- shared/openId4VCI/Utils.ts | 4 +- 5 files changed, 13 insertions(+), 104 deletions(-) delete mode 100644 mdoc.json diff --git a/components/VC/Views/VCDetailView.tsx b/components/VC/Views/VCDetailView.tsx index c4098fa1..140056e2 100644 --- a/components/VC/Views/VCDetailView.tsx +++ b/components/VC/Views/VCDetailView.tsx @@ -21,6 +21,7 @@ import { getTextColor, } from '../common/VCUtils'; import {ProfileIcon} from '../../ProfileIcon'; +import { VCFormat } from '../../../shared/VCFormat'; const getProfileImage = (face: any) => { if (face) { @@ -44,12 +45,12 @@ export const VCDetailView: React.FC = props => { const shouldShowHrLine = verifiableCredential => { let availableFieldNames: string[] = []; - if (props.verifiableCredentialData.vcMetadata.format === 'ldp_vc') { + if (props.verifiableCredentialData.vcMetadata.format === VCFormat.ldp_vc) { availableFieldNames = Object.keys( verifiableCredential?.credentialSubject, ); } else if ( - props.verifiableCredentialData.vcMetadata.format === 'mso_mdoc' + props.verifiableCredentialData.vcMetadata.format === VCFormat.mso_mdoc ) { const namespaces = verifiableCredential['issuerSigned']['nameSpaces']; Object.keys(namespaces).forEach(namespace => { diff --git a/components/VC/common/VCUtils.tsx b/components/VC/common/VCUtils.tsx index 99c0b1b2..956e6929 100644 --- a/components/VC/common/VCUtils.tsx +++ b/components/VC/common/VCUtils.tsx @@ -20,6 +20,7 @@ import { } from '../../../shared/openId4VCI/Utils'; import {parseJSON} from '../../../shared/Utils'; import {VCItemContentProps} from '../Views/VCCardViewContent'; +import { VCFormat } from '../../../shared/VCFormat'; export const CARD_VIEW_DEFAULT_FIELDS = ['fullName']; export const DETAIL_VIEW_DEFAULT_FIELDS = [ @@ -75,13 +76,13 @@ export const getFieldValue = ( getFullAddress(verifiableCredential?.credentialSubject), ); default: { - if (format === 'ldp_vc') { + if (format === VCFormat.ldp_vc) { const fieldValue = verifiableCredential?.credentialSubject[field]; if (Array.isArray(fieldValue) && typeof fieldValue[0] !== 'object') { return fieldValue.join(', '); } return getLocalizedField(fieldValue); - } else if (format === 'mso_mdoc') { + } else if (format === VCFormat.mso_mdoc) { const splitField = field.split('~'); if (splitField.length > 1) { console.log('splitField ', splitField); @@ -107,7 +108,7 @@ export const getFieldName = ( ): string => { //field = org.iso.18013.5.1~family_name if (wellknown) { - if (format === 'ldp_vc') { + if (format === VCFormat.ldp_vc) { const credentialDefinition = wellknown.credential_definition; if (!credentialDefinition) { console.error( @@ -122,7 +123,7 @@ export const getFieldName = ( }); return getLocalizedField(newFieldObj); } - } else if (format === 'mso_mdoc') { + } else if (format === VCFormat.mso_mdoc) { const splitField = field.split('~'); if (splitField.length > 1) { console.log('splitField ', splitField); @@ -320,7 +321,7 @@ export function DisplayName(props: VCItemContentProps): string | Object { 'props.verifiableCredentialData.format ', props.verifiableCredentialData.format, ); - if (props.verifiableCredentialData.format === 'mso_mdoc') { + if (props.verifiableCredentialData.format === VCFormat.mso_mdoc) { return props.credential['issuerSigned']['nameSpaces'][ 'org.iso.18013.5.1' ].find(element => element.elementIdentifier === 'given_name').elementValue; diff --git a/mdoc.json b/mdoc.json deleted file mode 100644 index a86195b4..00000000 --- a/mdoc.json +++ /dev/null @@ -1,94 +0,0 @@ -{ - "docType": "org.iso.18013.5.1.mDL", - "issuerSigned": { - "nameSpaces": { - "org.iso.18013.5.1": [ - { - "digestID": "1", - "random": "q��L����{��\u001c\u001eB�l", - "elementIdentifier": "issue_date", - "elementValue": "2024-01-12" - }, - { - "digestID": "2", - "random": "Q���T�\u0001sje���]�\u0013", - "elementIdentifier": "expiry_date", - "elementValue": "2025-01-12" - }, - { - "digestID": "3", - "random": "ܸ\u0018v�N��\u0010�\u0010#��}�", - "elementIdentifier": "family_name", - "elementValue": "Silverstone" - }, - { - "digestID": "4", - "random": "\u001e�E{ޠ%\u0001�5〽+�t", - "elementIdentifier": "given_name", - "elementValue": "Inga" - }, - { - "digestID": "5", - "random": "�����\u001f��XŅJ\u00190s�", - "elementIdentifier": "birth_date", - "elementValue": "1991-11-06" - }, - { - "digestID": "6", - "random": "\"e^�tP\fa�#}\u0007\u0004�-�", - "elementIdentifier": "issuing_country", - "elementValue": "US" - }, - { - "digestID": "7", - "random": "l��\u00051�ԚǿŨ,", - "elementIdentifier": "document_number", - "elementValue": "12345678" - }, - { - "digestID": "8", - "random": "[K\u0003��YL���r�Z��", - "elementIdentifier": "driving_privileges", - "elementValue": [ - { - "vehicle_category_code": "A", - "issue_date": "2023-01-01", - "expiry_date": "2043-01-01" - } - ] - } - ] - }, - "issuerAuth": [ - { - "1": null - }, - { - "33": "0�\u0001]0�\u0001\u0004�\u0003\u0002\u0001\u0002\u0002\u0006\u0001����\u00190\n\u0006\b*�H�=\u0004\u0003\u0002061402\u0006\u0003U\u0004\u0003\f+J1FwJP87C6-QN_WSIOmJAQc6n5CQ_bZdaFJ5GDnW1Rk0\u001e\u0017\r231222140656Z\u0017\r241017140656Z061402\u0006\u0003U\u0004\u0003\f+J1FwJP87C6-QN_WSIOmJAQc6n5CQ_bZdaFJ5GDnW1Rk0Y0\u0013\u0006\u0007*�H�=\u0002\u0001\u0006\b*�H�=\u0003\u0001\u0007\u0003B\u0000\u0004\u0002�Uy�\t��rs\rX*I\u00119w¤�\n��5`�a8h��86P��}��\u000e4qgn", - "3": "�8\u0019ᡑa�N���_u�������\u0017���-��\u0018�", - "4": "\u0011�_wU\u001d��i\bu#\"Z�fO�q�I�\u001f���u�&��", - "5": "(;���7����~��V�s@[���'\nl���6&kM\u001f", - "6": "\u0005g2p\u0002i��\u0007\fC\n��PЖc�N7��[���UZ�", - "7": "|\u0001\u001d\r��S�r��qHna���+�62&d\u0001m\u000f�v\u0011C", - "8": "r4�\u001d�$�\u0019�X��������w�G�E��:CZ�'��" - } - }, - "docType": "org.iso.18013.5.1.mDL", - "validityInfo": { - "signed": "2024-01-12T00:10:05Z", - "validFrom": "2024-01-12T00:10:05Z", - "validUntil": "2025-01-12T00:10:05Z" - } - }, - "qs\u0011�=4\\��>w�Q?�\u001fHڹ.�B�٪���u\u000b#�]e�^U�\tSW\u001f�\u0000��%�߯\\\u0019��C\u0014��\\|n�" - ] - } -} \ No newline at end of file diff --git a/shared/VCMetadata.ts b/shared/VCMetadata.ts index ccd77f57..961759ee 100644 --- a/shared/VCMetadata.ts +++ b/shared/VCMetadata.ts @@ -6,6 +6,7 @@ import { } from '../machines/VerifiableCredential/VCMetaMachine/vc'; import {CredentialIdForMsoMdoc, Protocols} from './openId4VCI/Utils'; import {getMosipIdentifier} from './commonUtil'; +import { VCFormat } from './VCFormat'; const VC_KEY_PREFIX = 'VC'; const VC_ITEM_STORE_KEY_REGEX = '^VC_[a-zA-Z0-9_-]+$'; @@ -54,7 +55,7 @@ export class VCMetadata { static fromVC(vc: Partial | VCMetadata | any) { return new VCMetadata({ idType: vc.idType, - format: vc.format || 'ldp_vc', + format: vc.format || VCFormat.ldp_vc requestId: vc.requestId, isPinned: vc.isPinned || false, id: vc.id, diff --git a/shared/openId4VCI/Utils.ts b/shared/openId4VCI/Utils.ts index d23e6f3e..4cda719a 100644 --- a/shared/openId4VCI/Utils.ts +++ b/shared/openId4VCI/Utils.ts @@ -431,10 +431,10 @@ export const constructIssuerMetaData = ( downloadTimeoutInMilliSeconds: downloadTimeout, credentialFormat: selectedCredentialType.format, }; - if (selectedCredentialType.format === 'ldp_vc') { + if (selectedCredentialType.format === VCFormat.ldp_vc) { issuerMeta['credentialType'] = selectedCredentialType?.credential_definition ?.type ?? ['VerifiableCredential']; - } else if (selectedCredentialType.format === 'mso_mdoc') { + } else if (selectedCredentialType.format === VCFormat.mso_mdoc) { issuerMeta['doctype'] = selectedCredentialType.doctype; issuerMeta['claims'] = selectedCredentialType.claims; }