Skip to content

Commit

Permalink
fix: fixed some issue in the IssuerMetadataUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
sksadjad committed May 21, 2024
1 parent 354e8ad commit 8a6c16f
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 18 deletions.
4 changes: 2 additions & 2 deletions packages/client/lib/__tests__/AccessTokenClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ describe('AccessTokenClient should', () => {
const response: OpenIDResponse<AccessTokenResponse> = 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 () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/client/lib/__tests__/SdJwt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
},
});
Expand Down
50 changes: 49 additions & 1 deletion packages/client/lib/__tests__/data/VciDataFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
24 changes: 13 additions & 11 deletions packages/common/lib/functions/IssuerMetadataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,33 @@ export function getSupportedCredential(opts?: {
issuerMetadata?: CredentialIssuerMetadata | IssuerMetadata;
version: OpenId4VCIVersion;
types?: string | string[];
format?: (OID4VCICredentialFormat | string) | (OID4VCICredentialFormat | string)[];
format?: OID4VCICredentialFormat | string | (OID4VCICredentialFormat | string)[];
}): Record<string, CredentialConfigurationSupportedV1_0_13> {
const { issuerMetadata, types, format } = opts ?? {};

if (!issuerMetadata || !issuerMetadata.credential_configurations_supported) {
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<string, CredentialConfigurationSupportedV1_0_13>)[id];

const filteredConfigs: Record<string, CredentialConfigurationSupportedV1_0_13> = {};
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<string, CredentialConfigurationSupportedV1_0_13>);
}


export function getTypesFromCredentialSupported(
credentialSupported: CredentialConfigurationSupported,
opts?: { filterVerifiableCredential: boolean },
Expand Down
5 changes: 3 additions & 2 deletions packages/issuer/lib/functions/CredentialOfferUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down

0 comments on commit 8a6c16f

Please sign in to comment.