From 8bb869462373c6dd0fddf3b242cb17151eb42c34 Mon Sep 17 00:00:00 2001 From: Paramet Kongjaroen Date: Tue, 6 Aug 2024 21:53:28 +0700 Subject: [PATCH] fix: resolve undefined credential_definition.type in credentialRequest Signed-off-by: Paramet Kongjaroen --- .../src/openid4vc-issuer/OpenId4VcIssuerService.ts | 11 +++++++++++ packages/openid4vc/src/shared/models/index.ts | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/openid4vc/src/openid4vc-issuer/OpenId4VcIssuerService.ts b/packages/openid4vc/src/openid4vc-issuer/OpenId4VcIssuerService.ts index b26b35952a..cbd246814a 100644 --- a/packages/openid4vc/src/openid4vc-issuer/OpenId4VcIssuerService.ts +++ b/packages/openid4vc/src/openid4vc-issuer/OpenId4VcIssuerService.ts @@ -468,6 +468,17 @@ export class OpenId4VcIssuerService { credentialRequest.format === OpenId4VciCredentialFormatProfile.JwtVcJson && offeredCredential.format === credentialRequest.format ) { + /* + Issue: https://github.com/openwallet-foundation/credo-ts/issues/1963 + Handling `credentialRequest.types` by checking if `credentialRequest.credential_definition` is not `undefined`. + `credentialRequest.credential_definition` requires a `type` attribute which does not currently exist. + Therefore, adding the `type` attribute at line 41 in `packages/openid4vc/src/shared/models/index.ts`. + */ + + credentialRequest.types = credentialRequest.credential_definition + ? credentialRequest.credential_definition.type + : credentialRequest.types + return equalsIgnoreOrder(offeredCredential.credential_definition.type ?? [], credentialRequest.types) } else if ( credentialRequest.format === OpenId4VciCredentialFormatProfile.JwtVcJsonLd && diff --git a/packages/openid4vc/src/shared/models/index.ts b/packages/openid4vc/src/shared/models/index.ts index 082a7f5720..254b0e389a 100644 --- a/packages/openid4vc/src/shared/models/index.ts +++ b/packages/openid4vc/src/shared/models/index.ts @@ -32,7 +32,7 @@ export type OpenId4VciIssuerMetadata = OpenId4VciIssuerMetadataV1Draft11 | OpenI export type OpenId4VciIssuerMetadataDisplay = MetadataDisplay export type OpenId4VciCredentialRequest = - | CredentialRequestJwtVcJson + | (CredentialRequestJwtVcJson & { credential_definition: { type: string[] } }) | CredentialRequestJwtVcJsonLdAndLdpVc | CredentialRequestSdJwtVc