Skip to content

Commit

Permalink
fix: resolve undefined credential_definition.type in credentialRequest (
Browse files Browse the repository at this point in the history
#1989)

Signed-off-by: Paramet Kongjaroen <parametprame2@gmail.com>
  • Loading branch information
parametprame authored Aug 14, 2024
1 parent 3ef3f10 commit 69b75bd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
27 changes: 18 additions & 9 deletions packages/openid4vc/src/openid4vc-issuer/OpenId4VcIssuerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,23 +468,32 @@ export class OpenId4VcIssuerService {
credentialRequest.format === OpenId4VciCredentialFormatProfile.JwtVcJson &&
offeredCredential.format === credentialRequest.format
) {
return equalsIgnoreOrder(offeredCredential.credential_definition.type ?? [], credentialRequest.types)
const types =
'credential_definition' in credentialRequest
? credentialRequest.credential_definition.type
: credentialRequest.types

return equalsIgnoreOrder(offeredCredential.credential_definition.type ?? [], types)
} else if (
credentialRequest.format === OpenId4VciCredentialFormatProfile.JwtVcJsonLd &&
offeredCredential.format === credentialRequest.format
) {
return equalsIgnoreOrder(
offeredCredential.credential_definition.type ?? [],
credentialRequest.credential_definition.types
)
const types =
'type' in credentialRequest.credential_definition
? credentialRequest.credential_definition.type
: credentialRequest.credential_definition.types

return equalsIgnoreOrder(offeredCredential.credential_definition.type ?? [], types)
} else if (
credentialRequest.format === OpenId4VciCredentialFormatProfile.LdpVc &&
offeredCredential.format === credentialRequest.format
) {
return equalsIgnoreOrder(
offeredCredential.credential_definition.type ?? [],
credentialRequest.credential_definition.types
)
const types =
'type' in credentialRequest.credential_definition
? credentialRequest.credential_definition.type
: credentialRequest.credential_definition.types

return equalsIgnoreOrder(offeredCredential.credential_definition.type ?? [], types)
} else if (
credentialRequest.format === OpenId4VciCredentialFormatProfile.SdJwtVc &&
offeredCredential.format === credentialRequest.format
Expand Down
14 changes: 9 additions & 5 deletions packages/openid4vc/src/shared/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ import type {
CredentialOfferPayloadV1_0_13,
CredentialRequestJwtVcJson,
CredentialRequestJwtVcJsonLdAndLdpVc,
CredentialRequestJwtVcJsonLdAndLdpVcV1_0_13,
CredentialRequestJwtVcJsonV1_0_13,
CredentialRequestSdJwtVc,
CredentialsSupportedLegacy,
MetadataDisplay,
TxCode,
UniformCredentialRequest,
} from '@sphereon/oid4vci-common'

export type OpenId4VciCredentialSupportedWithId = OpenId4VciCredentialSupported & { id: string }
Expand All @@ -31,13 +34,14 @@ export type OpenId4VciIssuerMetadata = OpenId4VciIssuerMetadataV1Draft11 | OpenI

export type OpenId4VciIssuerMetadataDisplay = MetadataDisplay

export type OpenId4VciCredentialRequest =
| CredentialRequestJwtVcJson
export type OpenId4VciCredentialRequest = UniformCredentialRequest

export type OpenId4VciCredentialRequestJwtVcJson = CredentialRequestJwtVcJson | CredentialRequestJwtVcJsonV1_0_13

export type OpenId4VciCredentialRequestJwtVcJsonLdAndLdpVc =
| CredentialRequestJwtVcJsonLdAndLdpVc
| CredentialRequestSdJwtVc
| CredentialRequestJwtVcJsonLdAndLdpVcV1_0_13

export type OpenId4VciCredentialRequestJwtVcJson = CredentialRequestJwtVcJson
export type OpenId4VciCredentialRequestJwtVcJsonLdAndLdpVc = CredentialRequestJwtVcJsonLdAndLdpVc
export type OpenId4VciCredentialRequestSdJwtVc = CredentialRequestSdJwtVc
export type OpenId4VciCredentialOffer = AssertedUniformCredentialOffer
export type OpenId4VciCredentialOfferPayload = CredentialOfferPayloadV1_0_11 | CredentialOfferPayloadV1_0_13
Expand Down

0 comments on commit 69b75bd

Please sign in to comment.