Skip to content

Commit 039b622

Browse files
committed
chore: match credential type on id as well when one value is passed in
1 parent 6099dea commit 039b622

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

packages/common/lib/functions/IssuerMetadataUtils.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ export function getSupportedCredential(opts?: {
5252
let credentialConfigurationsV13: Record<string, CredentialConfigurationSupportedV1_0_13> | undefined = undefined;
5353
if (version < OpenId4VCIVersion.VER_1_0_12 || issuerMetadata?.credentials_supported) {
5454
if (typeof issuerMetadata?.credentials_supported === 'object') {
55-
// The current code duplication and logic is such a mess, that we re-adjust the object to the proper type again
56-
credentialConfigurationsV11 = []
55+
// The current code duplication and logic is such a mess, that we re-adjust the object to the proper type again
56+
credentialConfigurationsV11 = [];
5757
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
58-
Object.entries(issuerMetadata.credentials_supported!).forEach(([id, supported]) => {
59-
if (!supported.id) {
60-
supported.id = id
61-
}
62-
credentialConfigurationsV11?.push(supported as CredentialConfigurationSupported)
63-
})
58+
Object.entries(issuerMetadata.credentials_supported!).forEach(([id, supported]) => {
59+
if (!supported.id) {
60+
supported.id = id;
61+
}
62+
credentialConfigurationsV11?.push(supported as CredentialConfigurationSupported);
63+
});
6464
} else {
6565
credentialConfigurationsV11 = (issuerMetadata?.credentials_supported as Array<CredentialConfigurationSupported>) ?? [];
6666
}
@@ -80,7 +80,9 @@ export function getSupportedCredential(opts?: {
8080
function filterMatchingConfig(config: CredentialConfigurationSupported): CredentialConfigurationSupported | undefined {
8181
let isTypeMatch = normalizedTypes.length === 0;
8282
if (!isTypeMatch) {
83-
if ('credential_definition' in config) {
83+
if (normalizedTypes.length === 1 && config.id === normalizedTypes[0]) {
84+
isTypeMatch = true;
85+
} else if ('credential_definition' in config) {
8486
isTypeMatch = normalizedTypes.some((type) => config.credential_definition.type?.includes(type));
8587
} else if ('type' in config && Array.isArray(config.type)) {
8688
// eslint-disable-next-line @typescript-eslint/ban-ts-comment

0 commit comments

Comments
 (0)