From 10f46515178cf5e5078db13069d06189a295f8f9 Mon Sep 17 00:00:00 2001 From: sander Date: Wed, 10 Jan 2024 15:04:08 +0100 Subject: [PATCH] Merged with latest develop --- .../lib/CredentialRequestClientBuilder.ts | 2 +- packages/client/lib/OpenID4VCIClient.ts | 8 ++-- .../lib/functions/IssuerMetadataUtils.ts | 9 ++-- .../CredentialSupportedBuilderV1_12.ts | 42 ++++++++++++------- 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/packages/client/lib/CredentialRequestClientBuilder.ts b/packages/client/lib/CredentialRequestClientBuilder.ts index 1f1b5346..59945319 100644 --- a/packages/client/lib/CredentialRequestClientBuilder.ts +++ b/packages/client/lib/CredentialRequestClientBuilder.ts @@ -35,7 +35,7 @@ export class CredentialRequestClientBuilder { }): CredentialRequestClientBuilder { const issuer = credentialIssuer; const builder = new CredentialRequestClientBuilder(); - builder.withVersion(version ?? OpenId4VCIVersion.VER_1_0_11); + builder.withVersion(version ?? OpenId4VCIVersion.VER_1_0_12); builder.withCredentialEndpoint(metadata?.credential_endpoint ?? (issuer.endsWith('/') ? `${issuer}credential` : `${issuer}/credential`)); builder.withCredentialType(credentialTypes); return builder; diff --git a/packages/client/lib/OpenID4VCIClient.ts b/packages/client/lib/OpenID4VCIClient.ts index ae3c7ec9..4a10f72c 100644 --- a/packages/client/lib/OpenID4VCIClient.ts +++ b/packages/client/lib/OpenID4VCIClient.ts @@ -8,8 +8,6 @@ import { CredentialSupported, EndpointMetadataResult, getIssuerFromCredentialOfferPayload, - getSupportedCredentials, - getTypesFromCredentialSupported, JsonURIMode, JWK, KID_JWK_X5C_ERROR, @@ -136,7 +134,7 @@ export class OpenID4VCIClient { if (this.credentialOffer) { this._endpointMetadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(this.credentialOffer); } else if (this._credentialIssuer) { - this._endpointMetadata = await MetadataClient.retrieveAllMetadata(this._credentialIssuer); + this._endpointMetadata = await MetadataClient.retrieveAllMetadata([this._credentialIssuer]); // TODO multi-server support? } else { throw Error(`Cannot retrieve issuer metadata without either a credential offer, or issuer value`); } @@ -412,7 +410,7 @@ export class OpenID4VCIClient { } else if (metadata.credentials_supported && !Array.isArray(metadata.credentials_supported)) { const credentialsSupported = metadata.credentials_supported as CredentialSupported; if (credentialsSupported.format === 'vc+sd-jwt') { - if (types.some((type) => !metadata.credentials_supported || credentialsSupported.credential_definition.vct === type)) { // TODO why are we doing iterating types and not using them? + if (types.some((type) => !metadata.credentials_supported || credentialsSupported.vct === type)) { throw Error(`Not all credential types ${JSON.stringify(credentialTypes)} are supported by issuer ${this.getIssuer()}`); } } else { @@ -509,7 +507,7 @@ export class OpenID4VCIClient { } public version(): OpenId4VCIVersion { - return this.credentialOffer?.version ?? OpenId4VCIVersion.VER_1_0_11; + return this.credentialOffer?.version ?? OpenId4VCIVersion.VER_1_0_12; } public get endpointMetadata(): EndpointMetadataResult { diff --git a/packages/common/lib/functions/IssuerMetadataUtils.ts b/packages/common/lib/functions/IssuerMetadataUtils.ts index b871c20f..2bffead7 100644 --- a/packages/common/lib/functions/IssuerMetadataUtils.ts +++ b/packages/common/lib/functions/IssuerMetadataUtils.ts @@ -91,14 +91,13 @@ export function getSupportedCredential(opts?: { export function getTypesFromCredentialSupported(credentialSupported: CredentialSupported, opts?: { filterVerifiableCredential: boolean }) { let types: string[] = []; - if (credentialSupported.format !== 'vc+sd-jwt') { - credentialSupported.format === 'jwt_vc_json' || + if (credentialSupported.format === 'jwt_vc_json' || credentialSupported.format === 'jwt_vc' || credentialSupported.format === 'jwt_vc_json-ld' || - credentialSupported.format === 'ldp_vc' + credentialSupported.format === 'ldp_vc') { types = credentialSupported.credential_definition.type; - } else { - types = [credentialSupported.credential_definition.vct]; + } else if (credentialSupported.format === 'vc+sd-jwt') { + types = [credentialSupported.vct]; } if (!types || types.length === 0) { throw Error('Could not deduce types from credential supported'); diff --git a/packages/issuer/lib/builder/CredentialSupportedBuilderV1_12.ts b/packages/issuer/lib/builder/CredentialSupportedBuilderV1_12.ts index 3f401d70..28d32f33 100644 --- a/packages/issuer/lib/builder/CredentialSupportedBuilderV1_12.ts +++ b/packages/issuer/lib/builder/CredentialSupportedBuilderV1_12.ts @@ -1,12 +1,12 @@ import { CredentialsSupportedDisplay, CredentialSupported, - isFormat, IssuerCredentialSubject, IssuerCredentialSubjectDisplay, OID4VCICredentialFormat, TokenErrorResponse, } from '@sphereon/oid4vci-common' +import { ICredentialContextType } from '@sphereon/ssi-types'; export class CredentialSupportedBuilderV1_12 { format?: OID4VCICredentialFormat @@ -112,26 +112,40 @@ export class CredentialSupportedBuilderV1_12 { if (!this.format) { throw new Error(TokenErrorResponse.invalid_request) } - const credentialSupported: Partial = { - format: this.format, - } + let credentialSupported: CredentialSupported; // Partial does not work in the v12 situation for some reason if (!this.types) { throw new Error('types are required') } + if (!this.types || this.types.length === 0) { + throw new Error('No type specified') + } // SdJwtVc has a different format - if (isFormat(credentialSupported, 'vc+sd-jwt')) { + if (this.format === 'vc+sd-jwt') { if (this.types.length > 1) { - throw new Error('Only one type is allowed for vc+sd-jwt') - } - credentialSupported.vct = this.types[0] - } - // And else would work here, but this way we get the correct typing - else { - credentialSupported.credential_definition = { - type: this.types, - ...this.credentialSubject ? { credentialSubject: this.credentialSubject } : {} + throw new Error('Only one type is allowed for vc+sd-jwt'); } + credentialSupported = { + format: this.format, + vct: this.types[0] + }; + } else if (this.format === 'ldp_vc' || this.format === 'jwt_vc_json-ld') { + credentialSupported = { + format: this.format, + credential_definition: { + type: this.types as string[], + ...this.credentialSubject ? { credentialSubject: this.credentialSubject } : {}, + '@context': [] as ICredentialContextType[] + } + }; + } else { + credentialSupported = { + format: this.format, + credential_definition: { + type: this.types as string[], + ...this.credentialSubject ? { credentialSubject: this.credentialSubject } : {} + } + }; } if (this.cryptographicSuitesSupported) {