Skip to content

Commit

Permalink
fix: support credential request v1_0_11 and v1_0_13
Browse files Browse the repository at this point in the history
Signed-off-by: Paramet Kongjaroen <parametprame2@gmail.com>
  • Loading branch information
Paramet Kongjaroen authored and parametprame committed Aug 14, 2024
1 parent 8bb8694 commit 1aa1623
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
38 changes: 18 additions & 20 deletions packages/openid4vc/src/openid4vc-issuer/OpenId4VcIssuerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,34 +468,32 @@ 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)
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 & { credential_definition: { type: string[] } })
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 1aa1623

Please sign in to comment.