From 8a6c16f39fdee838d935edbc46c6842b628f08b7 Mon Sep 17 00:00:00 2001 From: sksadjad Date: Tue, 21 May 2024 12:24:38 +0200 Subject: [PATCH] fix: fixed some issue in the IssuerMetadataUtils --- .../lib/__tests__/AccessTokenClient.spec.ts | 4 +- packages/client/lib/__tests__/SdJwt.spec.ts | 4 +- .../lib/__tests__/data/VciDataFixtures.ts | 50 ++++++++++++++++++- .../lib/functions/IssuerMetadataUtils.ts | 24 +++++---- .../lib/functions/CredentialOfferUtils.ts | 5 +- 5 files changed, 69 insertions(+), 18 deletions(-) diff --git a/packages/client/lib/__tests__/AccessTokenClient.spec.ts b/packages/client/lib/__tests__/AccessTokenClient.spec.ts index 34e22660..7f289668 100644 --- a/packages/client/lib/__tests__/AccessTokenClient.spec.ts +++ b/packages/client/lib/__tests__/AccessTokenClient.spec.ts @@ -223,8 +223,8 @@ describe('AccessTokenClient should', () => { const response: OpenIDResponse = await accessTokenClient.acquireAccessToken({ credentialOffer: INITIATION_TEST, pin: '1234', - }) - expect(response.successBody).toBeDefined() + }); + expect(response.successBody).toBeDefined(); }); it('get error if no as, issuer and metadata values are present', async () => { diff --git a/packages/client/lib/__tests__/SdJwt.spec.ts b/packages/client/lib/__tests__/SdJwt.spec.ts index 29b1b607..64c7eea0 100644 --- a/packages/client/lib/__tests__/SdJwt.spec.ts +++ b/packages/client/lib/__tests__/SdJwt.spec.ts @@ -108,9 +108,9 @@ describe('sd-jwt vc', () => { 'urn:ietf:params:oauth:grant-type:pre-authorized_code': { 'pre-authorized_code': '123', tx_code: { - input_mode: "text", + input_mode: 'text', length: 3, - }, + }, }, }, }); diff --git a/packages/client/lib/__tests__/data/VciDataFixtures.ts b/packages/client/lib/__tests__/data/VciDataFixtures.ts index 505cb772..fefe49a8 100644 --- a/packages/client/lib/__tests__/data/VciDataFixtures.ts +++ b/packages/client/lib/__tests__/data/VciDataFixtures.ts @@ -869,12 +869,24 @@ const mockData: VciMockDataStructure = { text_color: '#00526e', }, { + background_color: '#e6f2f5', + background_image: { + alt_text: 'KvK gestylede achtergrond', + url: 'https://mijnkvk.acc.credenco.com/kvk_card_background.png', + }, locale: 'nl-NL', name: 'Bevoegdheid uittreksel', + text_color: '#00526e', }, { + background_color: '#e6f2f5', + background_image: { + alt_text: 'KvK styled card Background', + url: 'https://mijnkvk.acc.credenco.com/kvk_card_background.png', + }, locale: 'en-US', name: 'Authorized representative', + text_color: '#00526e', }, ], format: 'jwt_vc_json', @@ -976,12 +988,24 @@ const mockData: VciMockDataStructure = { text_color: '#00526e', }, { + background_color: '#e6f2f5', + background_image: { + alt_text: 'KvK gestylede achtergrond', + url: 'https://mijnkvk.acc.credenco.com/kvk_card_background.png', + }, locale: 'nl-NL', name: 'KVK Registratie', + text_color: '#00526e', }, { + background_color: '#e6f2f5', + background_image: { + alt_text: 'KvK styled card Background', + url: 'https://mijnkvk.acc.credenco.com/kvk_card_background.png', + }, locale: 'en-US', name: 'Chamber of Commerce Registration', + text_color: '#00526e', }, ], format: 'jwt_vc_json', @@ -1035,14 +1059,26 @@ const mockData: VciMockDataStructure = { text_color: '#00526e', }, { + background_color: '#e6f2f5', + background_image: { + alt_text: 'KvK gestylede achtergrond', + url: 'https://mijnkvk.acc.credenco.com/kvk_card_background.png', + }, description: 'Rechtspersonen en Samenwerkingsverbanden Identificatienummer', locale: 'nl-NL', name: 'RSIN', + text_color: '#00526e', }, { + background_color: '#e6f2f5', + background_image: { + alt_text: 'KvK styled card Background', + url: 'https://mijnkvk.acc.credenco.com/kvk_card_background.png', + }, description: 'Identification number for legal entities and associations', locale: 'en-US', name: 'RSIN', + text_color: '#00526e', }, ], format: 'jwt_vc_json', @@ -1331,12 +1367,24 @@ const mockData: VciMockDataStructure = { text_color: '#00526e', }, { + background_color: '#e6f2f5', + background_image: { + alt_text: 'KvK gestylede achtergrond', + url: 'https://mijnkvk.acc.credenco.com/kvk_card_background.png', + }, locale: 'nl-NL', name: 'Bevoegdheid uittreksel', + text_color: '#00526e', }, { + background_color: '#e6f2f5', + background_image: { + alt_text: 'KvK styled card Background', + url: 'https://mijnkvk.acc.credenco.com/kvk_card_background.png', + }, locale: 'en-US', - name: 'Power of Attorney', + name: 'Authorized representative', + text_color: '#00526e', }, ], format: 'jwt_vc_json', diff --git a/packages/common/lib/functions/IssuerMetadataUtils.ts b/packages/common/lib/functions/IssuerMetadataUtils.ts index 1ee5bcc0..32d16202 100644 --- a/packages/common/lib/functions/IssuerMetadataUtils.ts +++ b/packages/common/lib/functions/IssuerMetadataUtils.ts @@ -38,7 +38,7 @@ export function getSupportedCredential(opts?: { issuerMetadata?: CredentialIssuerMetadata | IssuerMetadata; version: OpenId4VCIVersion; types?: string | string[]; - format?: (OID4VCICredentialFormat | string) | (OID4VCICredentialFormat | string)[]; + format?: OID4VCICredentialFormat | string | (OID4VCICredentialFormat | string)[]; }): Record { const { issuerMetadata, types, format } = opts ?? {}; @@ -46,23 +46,25 @@ export function getSupportedCredential(opts?: { return {}; } - const configurations = issuerMetadata.credential_configurations_supported; - const formats = Array.isArray(format) ? format : format ? [format] : []; - const normalizedTypes = Array.isArray(types) ? types : types ? [types] : []; + const configurationIds: string[] = Object.keys(issuerMetadata.credential_configurations_supported); + const normalizedTypes: string[] = Array.isArray(types) ? types : types ? [types] : []; + const normalizedFormats: string[] = Array.isArray(format) ? format : format ? [format] : []; + + return configurationIds.reduce((filteredConfigs, id) => { + const config = (issuerMetadata.credential_configurations_supported as Record)[id]; - const filteredConfigs: Record = {}; - Object.entries(configurations).forEach(([key, value]) => { - const isTypeMatch = normalizedTypes.length === 0 || normalizedTypes.includes(key); - const isFormatMatch = formats.length === 0 || formats.includes(value.format); + const isTypeMatch = normalizedTypes.length === 0 || normalizedTypes.includes(id); + const isFormatMatch = normalizedFormats.length === 0 || normalizedFormats.includes(config.format); if (isTypeMatch && isFormatMatch) { - filteredConfigs[key] = value; + filteredConfigs[id] = config; } - }); - return filteredConfigs; + return filteredConfigs; + }, {} as Record); } + export function getTypesFromCredentialSupported( credentialSupported: CredentialConfigurationSupported, opts?: { filterVerifiableCredential: boolean }, diff --git a/packages/issuer/lib/functions/CredentialOfferUtils.ts b/packages/issuer/lib/functions/CredentialOfferUtils.ts index fe3329b8..5cd134ad 100644 --- a/packages/issuer/lib/functions/CredentialOfferUtils.ts +++ b/packages/issuer/lib/functions/CredentialOfferUtils.ts @@ -3,11 +3,12 @@ import { CredentialOfferPayloadV1_0_13, CredentialOfferSession, CredentialOfferV1_0_13, - Grant, GrantUrnIetf, + Grant, + GrantUrnIetf, IssuerMetadataV1_0_13, PIN_VALIDATION_ERROR, TxCode, - UniformCredentialOffer + UniformCredentialOffer, } from '@sphereon/oid4vci-common' import { v4 as uuidv4 } from 'uuid'