@@ -15,23 +15,14 @@ import { detectImageMimeType, formatDate, getHostNameFromUrl, isDateString, sani
1515import { getOpenId4VcCredentialMetadata } from './metadata'
1616import { Jwk } from '@credo-ts/core/build/modules/kms/jwk/jwk.mjs'
1717import { OpenIDCredentialRecord } from './credentialRecord'
18-
19- function findDisplay < Display extends { locale ?: string } > ( display ?: Display [ ] ) : Display | undefined {
20- if ( ! display ) return undefined
21-
22- let item = display . find ( ( d ) => d . locale ?. startsWith ( 'en-' ) )
23- if ( ! item ) item = display . find ( ( d ) => ! d . locale )
24- if ( ! item ) item = display [ 0 ]
25-
26- return item
27- }
18+ import { findLocalizedDisplay } from '../../utils/localizedDisplay'
2819
2920function getOpenId4VcIssuerDisplay ( openId4VcMetadata ?: OpenId4VcCredentialMetadata | null ) : CredentialIssuerDisplay {
3021 const issuerDisplay : Partial < CredentialIssuerDisplay > = { }
3122
3223 // Try to extract from openid metadata first
3324 if ( openId4VcMetadata ) {
34- const openidIssuerDisplay = findDisplay ( openId4VcMetadata . issuer . display )
25+ const openidIssuerDisplay = findLocalizedDisplay ( openId4VcMetadata . issuer . display )
3526
3627 if ( openidIssuerDisplay ) {
3728 issuerDisplay . name = openidIssuerDisplay . name
@@ -45,7 +36,7 @@ function getOpenId4VcIssuerDisplay(openId4VcMetadata?: OpenId4VcCredentialMetada
4536 }
4637
4738 // If the credentialDisplay contains a logo, and the issuerDisplay does not, use the logo from the credentialDisplay
48- const openidCredentialDisplay = findDisplay ( openId4VcMetadata . credential . display )
39+ const openidCredentialDisplay = findLocalizedDisplay ( openId4VcMetadata . credential . display )
4940 if ( openidCredentialDisplay && ! issuerDisplay . logo && openidCredentialDisplay . logo ) {
5041 issuerDisplay . logo = {
5142 uri : openidCredentialDisplay . logo ?. uri ,
@@ -72,7 +63,7 @@ function getOpenId4VcIssuerDisplay(openId4VcMetadata?: OpenId4VcCredentialMetada
7263function getIssuerDisplay ( metadata : OpenId4VcCredentialMetadata | null | undefined ) : Partial < CredentialIssuerDisplay > {
7364 const issuerDisplay : Partial < CredentialIssuerDisplay > = { }
7465 // Try to extract from openid metadata first
75- const openidIssuerDisplay = findDisplay ( metadata ?. issuer . display )
66+ const openidIssuerDisplay = findLocalizedDisplay ( metadata ?. issuer . display )
7667 issuerDisplay . name = openidIssuerDisplay ?. name
7768 issuerDisplay . logo = openidIssuerDisplay ?. logo
7869 ? {
@@ -82,7 +73,7 @@ function getIssuerDisplay(metadata: OpenId4VcCredentialMetadata | null | undefin
8273 : undefined
8374
8475 // If the credentialDisplay contains a logo, and the issuerDisplay does not, use the logo from the credentialDisplay
85- const openidCredentialDisplay = findDisplay ( metadata ?. credential . display )
76+ const openidCredentialDisplay = findLocalizedDisplay ( metadata ?. credential . display )
8677 if ( openidCredentialDisplay && ! issuerDisplay . logo && openidCredentialDisplay . logo ) {
8778 issuerDisplay . logo = {
8879 uri : openidCredentialDisplay . logo ?. uri ,
@@ -142,7 +133,7 @@ function getCredentialDisplay(
142133 const credentialDisplay : Partial < CredentialDisplay > = { }
143134
144135 if ( openId4VcMetadata ) {
145- const openidCredentialDisplay = findDisplay ( openId4VcMetadata . credential . display )
136+ const openidCredentialDisplay = findLocalizedDisplay ( openId4VcMetadata . credential . display )
146137 credentialDisplay . name = openidCredentialDisplay ?. name
147138 credentialDisplay . description = openidCredentialDisplay ?. description
148139 credentialDisplay . textColor = openidCredentialDisplay ?. textColor
@@ -217,7 +208,7 @@ function getMdocCredentialDisplay(
217208 const credentialDisplay : Partial < CredentialDisplay > = { }
218209
219210 if ( openId4VcMetadata ) {
220- const openidCredentialDisplay = findDisplay ( openId4VcMetadata . credential . display )
211+ const openidCredentialDisplay = findLocalizedDisplay ( openId4VcMetadata . credential . display )
221212
222213 if ( openidCredentialDisplay ) {
223214 credentialDisplay . name = openidCredentialDisplay . name
@@ -323,6 +314,10 @@ export function filterAndMapSdJwtKeys(sdJwtVcPayload: Record<string, unknown>) {
323314 }
324315}
325316
317+ function getCredentialAttributeOrder ( openId4VcMetadata ?: OpenId4VcCredentialMetadata | null ) : string [ ] | undefined {
318+ return openId4VcMetadata ?. credential . order
319+ }
320+
326321export function getCredentialForDisplay ( credentialRecord : OpenIDCredentialRecord ) : W3cCredentialDisplay {
327322 if ( credentialRecord instanceof SdJwtVcRecord ) {
328323 const { disclosures, jwt } = decodeSdJwtSync ( credentialRecord . firstCredential . compact , ( data , alg ) =>
@@ -351,6 +346,7 @@ export function getCredentialForDisplay(credentialRecord: OpenIDCredentialRecord
351346 validUntil : mapped . raw . validUntil ,
352347 validFrom : mapped . raw . validFrom ,
353348 credentialSubject : openId4VcMetadata ?. credential . credential_subject ,
349+ attributeOrder : getCredentialAttributeOrder ( openId4VcMetadata ) ,
354350 }
355351 }
356352
@@ -384,6 +380,7 @@ export function getCredentialForDisplay(credentialRecord: OpenIDCredentialRecord
384380 validUntil : mdocInstance . validityInfo . validUntil ,
385381 validFrom : mdocInstance . validityInfo . validFrom ,
386382 credentialSubject : openId4VcMetadata ?. credential . credential_subject ,
383+ attributeOrder : getCredentialAttributeOrder ( openId4VcMetadata ) ,
387384 }
388385 }
389386
@@ -431,6 +428,7 @@ export function getCredentialForDisplay(credentialRecord: OpenIDCredentialRecord
431428 validUntil : credential . expiryDate ? new Date ( credential . expiryDate ) : undefined ,
432429 validFrom : credential . issuanceDate ? new Date ( credential . issuanceDate ) : undefined ,
433430 credentialSubject : openId4VcMetadata ?. credential . credential_subject ,
431+ attributeOrder : getCredentialAttributeOrder ( openId4VcMetadata ) ,
434432 }
435433}
436434
0 commit comments