diff --git a/packages/common/lib/types/Generic.types.ts b/packages/common/lib/types/Generic.types.ts index 398a4abc..a965b299 100644 --- a/packages/common/lib/types/Generic.types.ts +++ b/packages/common/lib/types/Generic.types.ts @@ -35,21 +35,21 @@ export type Display = NameAndLocale & LogoAndColor; export interface IssuerMetadata { credential_endpoint: string; batch_credential_endpoint?: string; - credentials_supported: CredentialIssuerMetadataSupportedCredentials[]; + credentials_supported: CredentialSupported[]; credential_issuer: string; // REQUIRED. The URL of the Credential Issuer, the Wallet is requested to obtain one or more Credentials from. authorization_server?: string; token_endpoint?: string; display?: Display[]; } -export interface CredentialIssuerMetadataSupportedCredentials { +export interface CredentialSupported { format: CredentialFormatEnum | string; id?: string; cryptographic_binding_methods_supported?: string[]; cryptographic_suites_supported?: string[]; } -export interface SupportedCredentialIssuerMetadataJwtVcJsonLdAndLdpVc extends CredentialIssuerMetadataSupportedCredentials { +export interface SupportedCredentialIssuerMetadataJwtVcJsonLdAndLdpVc extends CredentialSupported { format: CredentialFormatEnum.ldp_vc; '@context': ICredentialContextType[]; types: string[]; @@ -57,7 +57,7 @@ export interface SupportedCredentialIssuerMetadataJwtVcJsonLdAndLdpVc extends Cr display?: Display[]; } -export interface SupportedCredentialIssuerMetadataJwtVcJson extends CredentialIssuerMetadataSupportedCredentials { +export interface SupportedCredentialIssuerMetadataJwtVcJson extends CredentialSupported { types: string[]; credentialSubject?: IssuerCredentialSubject; display?: Display[]; diff --git a/packages/issuer-rest/lib/api.ts b/packages/issuer-rest/lib/api.ts index 6469cc49..f373a4aa 100644 --- a/packages/issuer-rest/lib/api.ts +++ b/packages/issuer-rest/lib/api.ts @@ -1,7 +1,7 @@ import { CredentialFormatEnum, - CredentialIssuerMetadataSupportedCredentials, CredentialRequest, + CredentialSupported, Display, IssuerCredentialSubjectDisplay, IssuerMetadata, @@ -14,7 +14,7 @@ import express, { Express, Response } from 'express' import { v4 as uuidv4 } from 'uuid' function buildVCIFromEnvironment() { - const credentialsSupported: CredentialIssuerMetadataSupportedCredentials = new CredentialSupportedV1_11Builder() + const credentialsSupported: CredentialSupported = new CredentialSupportedV1_11Builder() .withCryptographicSuitesSupported(process.env.cryptographic_suites_supported as string) .withCryptographicBindingMethod(process.env.cryptographic_binding_methods_supported as string) .withFormat(process.env.credential_supported_format as unknown as CredentialFormatEnum) diff --git a/packages/issuer/lib/__test__/VcIssuerBuilder.spec.ts b/packages/issuer/lib/__test__/VcIssuerBuilder.spec.ts index bdcab716..ff7909f2 100644 --- a/packages/issuer/lib/__test__/VcIssuerBuilder.spec.ts +++ b/packages/issuer/lib/__test__/VcIssuerBuilder.spec.ts @@ -1,16 +1,10 @@ -import { - CredentialFormatEnum, - CredentialIssuerMetadataSupportedCredentials, - Display, - IssuerCredentialSubjectDisplay, - TokenErrorResponse, -} from '@sphereon/openid4vci-common' +import { CredentialFormatEnum, CredentialSupported, Display, IssuerCredentialSubjectDisplay, TokenErrorResponse } from '@sphereon/openid4vci-common' import { CredentialSupportedV1_11Builder, VcIssuerBuilder } from '../index' describe('VcIssuer builder should', () => { it('generate a VcIssuer', () => { - const credentialsSupported: CredentialIssuerMetadataSupportedCredentials = new CredentialSupportedV1_11Builder() + const credentialsSupported: CredentialSupported = new CredentialSupportedV1_11Builder() .withCryptographicSuitesSupported('ES256K') .withCryptographicBindingMethod('did') .withFormat(CredentialFormatEnum.jwt_vc_json) @@ -47,7 +41,7 @@ describe('VcIssuer builder should', () => { }) it('fail to generate a VcIssuer', () => { - const credentialsSupported: CredentialIssuerMetadataSupportedCredentials = new CredentialSupportedV1_11Builder() + const credentialsSupported: CredentialSupported = new CredentialSupportedV1_11Builder() .withCryptographicSuitesSupported('ES256K') .withCryptographicBindingMethod('did') .withFormat(CredentialFormatEnum.jwt_vc_json) diff --git a/packages/issuer/lib/builder/CredentialSupportedV1_11Builder.ts b/packages/issuer/lib/builder/CredentialSupportedV1_11Builder.ts index eca5cc4b..7f2dd895 100644 --- a/packages/issuer/lib/builder/CredentialSupportedV1_11Builder.ts +++ b/packages/issuer/lib/builder/CredentialSupportedV1_11Builder.ts @@ -1,6 +1,6 @@ import { CredentialFormatEnum, - CredentialIssuerMetadataSupportedCredentials, + CredentialSupported, Display, IssuerCredentialSubject, IssuerCredentialSubjectDisplay, @@ -101,11 +101,11 @@ export class CredentialSupportedV1_11Builder { return this } - public build(): CredentialIssuerMetadataSupportedCredentials { + public build(): CredentialSupported { if (!this.format) { throw new Error(TokenErrorResponse.invalid_request) } - const credentialSupported: CredentialIssuerMetadataSupportedCredentials = { + const credentialSupported: CredentialSupported = { format: this.format, } if (this.credentialSubject) { diff --git a/packages/issuer/lib/builder/VcIssuerBuilder.ts b/packages/issuer/lib/builder/VcIssuerBuilder.ts index e78ded77..ade35b52 100644 --- a/packages/issuer/lib/builder/VcIssuerBuilder.ts +++ b/packages/issuer/lib/builder/VcIssuerBuilder.ts @@ -1,4 +1,4 @@ -import { CredentialIssuerMetadataSupportedCredentials, Display, IssuerMetadata, TokenErrorResponse } from '@sphereon/openid4vci-common' +import { CredentialSupported, Display, IssuerMetadata, TokenErrorResponse } from '@sphereon/openid4vci-common' import { VcIssuer } from '../VcIssuer' @@ -9,7 +9,7 @@ export class VcIssuerBuilder { batchCredentialEndpoint?: string tokenEndpoint?: string issuerDisplay?: Display[] - credentialsSupported?: CredentialIssuerMetadataSupportedCredentials[] + credentialsSupported?: CredentialSupported[] userPinRequired?: boolean public withCredentialIssuer(issuer: string): VcIssuerBuilder { @@ -49,16 +49,12 @@ export class VcIssuerBuilder { return this } - public withCredentialsSupported( - credentialSupported: CredentialIssuerMetadataSupportedCredentials | CredentialIssuerMetadataSupportedCredentials[] - ): VcIssuerBuilder { + public withCredentialsSupported(credentialSupported: CredentialSupported | CredentialSupported[]): VcIssuerBuilder { this.credentialsSupported = Array.isArray(credentialSupported) ? credentialSupported : [credentialSupported] return this } - public addCredentialsSupported( - credentialSupported: CredentialIssuerMetadataSupportedCredentials | CredentialIssuerMetadataSupportedCredentials[] - ): VcIssuerBuilder { + public addCredentialsSupported(credentialSupported: CredentialSupported | CredentialSupported[]): VcIssuerBuilder { if (!Array.isArray(credentialSupported)) this.credentialsSupported = this.credentialsSupported ? [...this.credentialsSupported, credentialSupported] : [credentialSupported] else { diff --git a/packages/issuer/lib/functions/CredentialOffer.ts b/packages/issuer/lib/functions/CredentialOffer.ts index bd78b94f..5d2a16a4 100644 --- a/packages/issuer/lib/functions/CredentialOffer.ts +++ b/packages/issuer/lib/functions/CredentialOffer.ts @@ -1,10 +1,4 @@ -import { - CredentialFormatEnum, - CredentialIssuerMetadataSupportedCredentials, - encodeJsonAsURI, - IssuerMetadata, - TokenErrorResponse, -} from '@sphereon/openid4vci-common' +import { CredentialFormatEnum, CredentialSupported, encodeJsonAsURI, IssuerMetadata, TokenErrorResponse } from '@sphereon/openid4vci-common' import { v4 as uuidv4 } from 'uuid' export function createCredentialOfferDeeplink(preAuthorizedCode: string, issuerMetadata: IssuerMetadata): string { @@ -18,7 +12,7 @@ export function createCredentialOfferDeeplink(preAuthorizedCode: string, issuerM const types: string[] = [] issuerMetadata.credentials_supported.map((cs) => { - if (cs.format != CredentialFormatEnum.mso_mdoc) types.push(...(cs['types' as keyof CredentialIssuerMetadataSupportedCredentials] as string[])) + if (cs.format != CredentialFormatEnum.mso_mdoc) types.push(...(cs['types' as keyof CredentialSupported] as string[])) }) return `openid-credential-offer://?credential_offer=${encodeJsonAsURI({ credential_issuer: issuerMetadata.credential_issuer,