Skip to content

Commit

Permalink
Updated getTypesFromCredentialSupported to support the id field
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderPostma committed Jan 12, 2024
1 parent b1e5a01 commit 83b86ae
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions packages/common/lib/functions/IssuerMetadataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,33 @@ export function getSupportedCredential(opts?: {
}

export function getTypesFromCredentialSupported(credentialSupported: CredentialSupported, opts?: { filterVerifiableCredential: boolean }) {
let types: string[] = [];
const typesSet = new Set<string>()

if (credentialSupported.id) {
typesSet.add(credentialSupported.id)
}

if (credentialSupported.format === 'jwt_vc_json' ||
credentialSupported.format === 'jwt_vc' ||
credentialSupported.format === 'jwt_vc_json-ld' ||
credentialSupported.format === 'ldp_vc') {
types = credentialSupported.credential_definition.type;
credentialSupported.format === 'jwt_vc' ||
credentialSupported.format === 'jwt_vc_json-ld' ||
credentialSupported.format === 'ldp_vc') {
credentialSupported.credential_definition.type.forEach(type => typesSet.add(type))
} else if (credentialSupported.format === 'vc+sd-jwt') {
types = [credentialSupported.vct];
typesSet.add(credentialSupported.vct)
}
if (!types || types.length === 0) {
throw Error('Could not deduce types from credential supported');

if (typesSet.size === 0) {
throw Error('Could not deduce types from credential supported')
}

if (opts?.filterVerifiableCredential) {
return types.filter((type) => type !== 'VerifiableCredential');
typesSet.delete('VerifiableCredential')
}
return types;

return Array.from(typesSet)
}


function arrayEqualsIgnoreOrder(a: string[], b: string[]) {
if (a.length !== b.length) return false;
const uniqueValues = new Set([...a, ...b]);
Expand Down

0 comments on commit 83b86ae

Please sign in to comment.