Skip to content

Commit

Permalink
Merge pull request #293 from Sphereon-Opensource/feature/SPRIND-136
Browse files Browse the repository at this point in the history
feat/SPRIND-136
  • Loading branch information
BtencateSphereon authored Dec 6, 2024
2 parents 5c5a4bc + c8ce2ad commit 9e92b48
Show file tree
Hide file tree
Showing 10 changed files with 436 additions and 193 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ test/*.js
/packages/oidf-client/plugin.schema.json
/packages/anomaly-detection/plugin.schema.json
/packages/geolocation-store/plugin.schema.json
/packages/oidf-metadata-server/plugin.schema.json

**/.env.energyshr
**/.env.local
Expand Down
6 changes: 3 additions & 3 deletions packages/oid4vci-holder/src/agent/OID4VCIHolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export class OID4VCIHolder implements IAgentPlugin {
oid4vciHolderStart: this.oid4vciHolderStart.bind(this),
oid4vciHolderGetIssuerMetadata: this.oid4vciHolderGetIssuerMetadata.bind(this),
oid4vciHolderGetMachineInterpreter: this.oid4vciHolderGetMachineInterpreter.bind(this),
oid4vciHolderCreateCredentialsToSelectFrom: this.oid4vciHoldercreateCredentialsToSelectFrom.bind(this),
oid4vciHolderCreateCredentialsToSelectFrom: this.oid4vciHolderCreateCredentialsToSelectFrom.bind(this),
oid4vciHolderGetContact: this.oid4vciHolderGetContact.bind(this),
oid4vciHolderGetCredentials: this.oid4vciHolderGetCredentials.bind(this),
oid4vciHolderGetCredential: this.oid4vciHolderGetCredential.bind(this),
Expand Down Expand Up @@ -315,7 +315,7 @@ export class OID4VCIHolder implements IAgentPlugin {
},
context,
),
createCredentialsToSelectFrom: (args: createCredentialsToSelectFromArgs) => this.oid4vciHoldercreateCredentialsToSelectFrom(args, context),
createCredentialsToSelectFrom: (args: createCredentialsToSelectFromArgs) => this.oid4vciHolderCreateCredentialsToSelectFrom(args, context),
getContact: (args: GetContactArgs) => this.oid4vciHolderGetContact(args, context),
getCredentials: (args: GetCredentialsArgs) =>
this.oid4vciHolderGetCredentials({ accessTokenOpts: args.accessTokenOpts ?? opts.accessTokenOpts, ...args }, context),
Expand Down Expand Up @@ -461,7 +461,7 @@ export class OID4VCIHolder implements IAgentPlugin {
}
}

private async oid4vciHoldercreateCredentialsToSelectFrom(
private async oid4vciHolderCreateCredentialsToSelectFrom(
args: createCredentialsToSelectFromArgs,
context: RequiredContext,
): Promise<Array<CredentialToSelectFromResult>> {
Expand Down
43 changes: 33 additions & 10 deletions packages/oid4vci-holder/src/agent/OID4VCIHolderService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { LOG } from '@sphereon/oid4vci-client'
import {
CredentialConfigurationSupported,
CredentialSupportedSdJwtVc,
CredentialConfigurationSupportedSdJwtVcV1_0_13,
CredentialOfferFormatV1_0_11,
CredentialResponse,
getSupportedCredentials,
Expand Down Expand Up @@ -30,6 +32,7 @@ import {
OriginalVerifiableCredential,
sdJwtDecodedCredentialToUniformCredential,
SdJwtDecodedVerifiableCredential,
SdJwtTypeMetadata,
W3CVerifiableCredential,
WrappedVerifiableCredential,
} from '@sphereon/ssi-types'
Expand All @@ -54,31 +57,51 @@ import {
VerificationResult,
VerifyCredentialToAcceptArgs,
} from '../types/IOID4VCIHolder'
import { getCredentialBrandingFrom, issuerLocaleBrandingFrom } from './OIDC4VCIBrandingMapper'
import {
oid4vciGetCredentialBrandingFrom,
sdJwtGetCredentialBrandingFrom,
issuerLocaleBrandingFrom
} from './OIDC4VCIBrandingMapper'

export const getCredentialBranding = async (args: GetCredentialBrandingArgs): Promise<Record<string, Array<IBasicCredentialLocaleBranding>>> => {
const { credentialsSupported, context } = args
const credentialBranding: Record<string, Array<IBasicCredentialLocaleBranding>> = {}
await Promise.all(
Object.entries(credentialsSupported).map(async ([configId, credentialsConfigSupported]) => {
const mappedLocaleBranding = await getCredentialBrandingFrom({
credentialDisplay: credentialsConfigSupported.display,
issuerCredentialSubject:
Object.entries(credentialsSupported).map(async ([configId, credentialsConfigSupported]): Promise<void> => {
let sdJwtTypeMetadata: SdJwtTypeMetadata | undefined
if (credentialsConfigSupported.format === 'vc+sd-jwt') {
const vct = (<CredentialSupportedSdJwtVc | CredentialConfigurationSupportedSdJwtVcV1_0_13>credentialsConfigSupported).vct
if (vct.startsWith('http')) {
try {
sdJwtTypeMetadata = await context.agent.fetchSdJwtTypeMetadataFromVctUrl({ vct })
} catch {
// For now, we are just going to ignore and continue without any branding as we still have a fallback
}
}
}
let mappedLocaleBranding: Array<IBasicCredentialLocaleBranding> = []
if (sdJwtTypeMetadata) {
mappedLocaleBranding = await sdJwtGetCredentialBrandingFrom({
credentialDisplay: sdJwtTypeMetadata.display,
claimsMetadata: sdJwtTypeMetadata.claims
})
} else {
mappedLocaleBranding = await oid4vciGetCredentialBrandingFrom({
credentialDisplay: credentialsConfigSupported.display,
issuerCredentialSubject:
// @ts-ignore // FIXME SPRIND-123 add proper support for type recognition as claim display can be located elsewhere for v13
credentialsSupported.claims !== undefined ? credentialsConfigSupported.claims : credentialsConfigSupported.credentialSubject,
})

})
}
// TODO we should make the mapper part of the plugin, so that the logic for getting the branding becomes more clear and easier to use
const localeBranding = await Promise.all(
(mappedLocaleBranding ?? []).map(
mappedLocaleBranding.map(
async (localeBranding): Promise<IBasicCredentialLocaleBranding> => await context.agent.ibCredentialLocaleBrandingFrom({ localeBranding }),
),
)

const defaultCredentialType = 'VerifiableCredential'
const configSupportedTypes = getTypesFromCredentialSupported(credentialsConfigSupported)
const credentialTypes: Array<string> = configSupportedTypes.length === 0 ? asArray(defaultCredentialType) : configSupportedTypes

const filteredCredentialTypes = credentialTypes.filter((type: string): boolean => type !== defaultCredentialType)
credentialBranding[filteredCredentialTypes[0]] = localeBranding // TODO for now taking the first type
}),
Expand Down
Loading

0 comments on commit 9e92b48

Please sign in to comment.