Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve undefined credential_definition.type in credentialRequest #1989

Conversation

parametprame
Copy link
Contributor

This fixes the issue reported in (#1963).

  • Added logic to set credentialRequest.types based on credentialRequest.credential_definition.type if credential_definition is defined.
  • This ensures that the types attribute is correctly populated from credential_definition when available, preventing potential issues with undefined credential_definition.type.
  • The change is applied at line 41 in packages/openid4vc/src/shared/models/index.ts.

Copy link

changeset-bot bot commented Aug 6, 2024

⚠️ No Changeset found

Latest commit: 1aa1623

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@@ -32,7 +32,7 @@ export type OpenId4VciIssuerMetadata = OpenId4VciIssuerMetadataV1Draft11 | OpenI
export type OpenId4VciIssuerMetadataDisplay = MetadataDisplay

export type OpenId4VciCredentialRequest =
| CredentialRequestJwtVcJson
| (CredentialRequestJwtVcJson & { credential_definition: { type: string[] } })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we forgot to update the credential request type when adding support for V13.

I think we can do:

export type OpenId4VciCredentialRequest = UniformCredentialRequest

UniformCredentialRequest contains both draft 11 and draft 13 types. And for the others we can then do:

export type OpenId4VciCredentialRequestJwtVcJson = CredentialRequestJwtVcJson | CredentialRequestJwtVcJsonV1_0_13

and also for all the other format specific ones

Comment on lines 471 to 482
/*
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/*
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)
// credential_definition.type is draft 13 and .types is draft 11
const types = credentialRequest.credential_definition
? credentialRequest.credential_definition.type
: credentialRequest.types
return equalsIgnoreOrder(offeredCredential.credential_definition.type ?? [], types)

TimoGlastra

This comment was marked as outdated.

Copy link
Contributor

@TimoGlastra TimoGlastra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @parametprame! I left some comments / suggestions, as we can use the types form the sphereon library

@Patrik-Stas
Copy link

hi @parametprame @TimoGlastra

I run into same problem playing with the demo, however although this PR seem to fix the original problem, it seems I am still hitting some subsequent outstanding issue.

Didn't have time to investigate, so I am just reporting this finding.

ISSUER:

  Restart 2024-08-14T07:35:25.603Z-(sphereon:events) Emitting 'OID4VCI_CREDENTIAL_ISSUED' event [
  {
    eventName: 'OID4VCI_CREDENTIAL_ISSUED',
    id: 'c23eb450-abbf-4045-83bd-9a6a7cd17cd1',
    data: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFZERTQSIsImtpZCI6ImRpZDprZXk6ejZNa3RpUVFFcW0yeWFwWEJEdDFXRVZCM2RxZ3Z5emk5NkZ1RkFOWW1yZ1RyS1Y5I3o2TWt0aVFRRXFtMnlhcFhCRHQxV0VWQjNkcWd2eXppOTZGdUZBTlltcmdUcktWOSJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSJdLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiY3JlZGVudGlhbFN1YmplY3QiOnt9fSwiaXNzIjoiZGlkOmtleTp6Nk1rdGlRUUVxbTJ5YXBYQkR0MVdFVkIzZHFndnl6aTk2RnVGQU5ZbXJnVHJLVjkiLCJzdWIiOiJkaWQ6a2V5Ono2TWtwR1I0Z3M0UmMzWnBoNHZqOHdSbmpuQXhnQVBTeGNSOE1BVkt1dFdzcFF6YyIsIm5iZiI6MTcyMzYyMDkyNX0.kF41ImYqM3Do8UZrV_AGBLurjPCu0tkI4Q7fE2FGoTD83oPRigx3bGqnV2urTDY5feD0m7OGLCUDylmSnu45DQ',
    initiator: 'did:key:z6MktiQQEqm2yapXBDt1WEVB3dqgvyzi96FuFANYmrgTrKV9',
    initiatorType: 'external',
    system: 'oid4vci',
    subsystem: 'vc_issuer'
  }
]

Error: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (node:_http_outgoing:659:11)
    at ServerResponse.header (/Users/patrik/dev/project/experiment/credo-ts/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/response.js:795:10)
    at ServerResponse.header (/Users/patrik/dev/project/experiment/credo-ts/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/response.js:798:12)
    at /Users/patrik/dev/project/experiment/credo-ts/packages/openid4vc/src/openid4vc-issuer/router/accessTokenEndpoint.ts:115:14
    at Layer.handle [as handle_request] (/Users/patrik/dev/project/experiment/credo-ts/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/patrik/dev/project/experiment/credo-ts/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/route.js:149:13)
    at /Users/patrik/dev/project/experiment/credo-ts/packages/openid4vc/src/openid4vc-issuer/router/accessTokenEndpoint.ts:222:5 {
  code: 'ERR_HTTP_HEADERS_SENT'
}

HOLDER:

Options: Accept the credential offer.

Options: UniversityDegreeCredential
Requesting the following credential 'UniversityDegreeCredential'
/Users/patrik/dev/project/experiment/credo-ts/packages/openid4vc/src/openid4vc-holder/OpenId4VciHolderService.ts:356
      throw new CredoError(
            ^
CredoError: could not acquire access token from 'http://localhost:2000/oid4vci/832ea2c6-ffcf-4b27-8432-9d6d72de74a2'. invalid_request: Access token has already been retrieved
    at OpenId4VciHolderService.requestAccessToken (/Users/patrik/dev/project/experiment/credo-ts/packages/openid4vc/src/openid4vc-holder/OpenId4VciHolderService.ts:356:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async OpenId4VcHolderApi.requestToken (/Users/patrik/dev/project/experiment/credo-ts/packages/openid4vc/src/openid4vc-holder/OpenId4VcHolderApi.ts:153:9)
    at async Holder.requestAndStoreCredentials (/Users/patrik/dev/project/experiment/credo-ts/demo-openid/src/Holder.ts:42:27)
    at async HolderInquirer.requestCredential (/Users/patrik/dev/project/experiment/credo-ts/demo-openid/src/HolderInquirer.ts:115:25)
    at async HolderInquirer.processAnswer (/Users/patrik/dev/project/experiment/credo-ts/demo-openid/src/HolderInquirer.ts:61:9)
    at async HolderInquirer.processAnswer (/Users/patrik/dev/project/experiment/credo-ts/demo-openid/src/HolderInquirer.ts:76:5)
    at async HolderInquirer.processAnswer (/Users/patrik/dev/project/experiment/credo-ts/demo-openid/src/HolderInquirer.ts:76:5)
    at async runHolder (/Users/patrik/dev/project/experiment/credo-ts/demo-openid/src/HolderInquirer.ts:17:3) {
  [cause]: undefined
}
 ELIFECYCLE  Command failed with exit code 1.
 ```

@parametprame
Copy link
Contributor Author

hi @parametprame @TimoGlastra

I run into same problem playing with the demo, however although this PR seem to fix the original problem, it seems I am still hitting some subsequent outstanding issue.

Didn't have time to investigate, so I am just reporting this finding.

ISSUER:

  Restart 2024-08-14T07:35:25.603Z-(sphereon:events) Emitting 'OID4VCI_CREDENTIAL_ISSUED' event [
  {
    eventName: 'OID4VCI_CREDENTIAL_ISSUED',
    id: 'c23eb450-abbf-4045-83bd-9a6a7cd17cd1',
    data: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFZERTQSIsImtpZCI6ImRpZDprZXk6ejZNa3RpUVFFcW0yeWFwWEJEdDFXRVZCM2RxZ3Z5emk5NkZ1RkFOWW1yZ1RyS1Y5I3o2TWt0aVFRRXFtMnlhcFhCRHQxV0VWQjNkcWd2eXppOTZGdUZBTlltcmdUcktWOSJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSJdLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiY3JlZGVudGlhbFN1YmplY3QiOnt9fSwiaXNzIjoiZGlkOmtleTp6Nk1rdGlRUUVxbTJ5YXBYQkR0MVdFVkIzZHFndnl6aTk2RnVGQU5ZbXJnVHJLVjkiLCJzdWIiOiJkaWQ6a2V5Ono2TWtwR1I0Z3M0UmMzWnBoNHZqOHdSbmpuQXhnQVBTeGNSOE1BVkt1dFdzcFF6YyIsIm5iZiI6MTcyMzYyMDkyNX0.kF41ImYqM3Do8UZrV_AGBLurjPCu0tkI4Q7fE2FGoTD83oPRigx3bGqnV2urTDY5feD0m7OGLCUDylmSnu45DQ',
    initiator: 'did:key:z6MktiQQEqm2yapXBDt1WEVB3dqgvyzi96FuFANYmrgTrKV9',
    initiatorType: 'external',
    system: 'oid4vci',
    subsystem: 'vc_issuer'
  }
]

Error: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (node:_http_outgoing:659:11)
    at ServerResponse.header (/Users/patrik/dev/project/experiment/credo-ts/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/response.js:795:10)
    at ServerResponse.header (/Users/patrik/dev/project/experiment/credo-ts/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/response.js:798:12)
    at /Users/patrik/dev/project/experiment/credo-ts/packages/openid4vc/src/openid4vc-issuer/router/accessTokenEndpoint.ts:115:14
    at Layer.handle [as handle_request] (/Users/patrik/dev/project/experiment/credo-ts/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/patrik/dev/project/experiment/credo-ts/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/route.js:149:13)
    at /Users/patrik/dev/project/experiment/credo-ts/packages/openid4vc/src/openid4vc-issuer/router/accessTokenEndpoint.ts:222:5 {
  code: 'ERR_HTTP_HEADERS_SENT'
}

HOLDER:

Options: Accept the credential offer.

Options: UniversityDegreeCredential
Requesting the following credential 'UniversityDegreeCredential'
/Users/patrik/dev/project/experiment/credo-ts/packages/openid4vc/src/openid4vc-holder/OpenId4VciHolderService.ts:356
      throw new CredoError(
            ^
CredoError: could not acquire access token from 'http://localhost:2000/oid4vci/832ea2c6-ffcf-4b27-8432-9d6d72de74a2'. invalid_request: Access token has already been retrieved
    at OpenId4VciHolderService.requestAccessToken (/Users/patrik/dev/project/experiment/credo-ts/packages/openid4vc/src/openid4vc-holder/OpenId4VciHolderService.ts:356:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async OpenId4VcHolderApi.requestToken (/Users/patrik/dev/project/experiment/credo-ts/packages/openid4vc/src/openid4vc-holder/OpenId4VcHolderApi.ts:153:9)
    at async Holder.requestAndStoreCredentials (/Users/patrik/dev/project/experiment/credo-ts/demo-openid/src/Holder.ts:42:27)
    at async HolderInquirer.requestCredential (/Users/patrik/dev/project/experiment/credo-ts/demo-openid/src/HolderInquirer.ts:115:25)
    at async HolderInquirer.processAnswer (/Users/patrik/dev/project/experiment/credo-ts/demo-openid/src/HolderInquirer.ts:61:9)
    at async HolderInquirer.processAnswer (/Users/patrik/dev/project/experiment/credo-ts/demo-openid/src/HolderInquirer.ts:76:5)
    at async HolderInquirer.processAnswer (/Users/patrik/dev/project/experiment/credo-ts/demo-openid/src/HolderInquirer.ts:76:5)
    at async runHolder (/Users/patrik/dev/project/experiment/credo-ts/demo-openid/src/HolderInquirer.ts:17:3) {
  [cause]: undefined
}
 ELIFECYCLE  Command failed with exit code 1.
 ```

@Patrik-Stas Did you selected Accept the credential offer. more than once?

@TimoGlastra
Copy link
Contributor

Hey @parametprame it seems your commit hasn't been signed off.

Can you follow https://github.com/hyperledger/aries-rfcs/blob/main/contributing.md#signing-off-commits-dco?

Paramet Kongjaroen added 2 commits August 14, 2024 16:36
Signed-off-by: Paramet Kongjaroen <parametprame2@gmail.com>
Signed-off-by: Paramet Kongjaroen <parametprame2@gmail.com>
@parametprame parametprame force-pushed the fix/1963-receive-credential-error branch from ee50738 to 1aa1623 Compare August 14, 2024 09:36
@parametprame
Copy link
Contributor Author

Hey @parametprame it seems your commit hasn't been signed off.

Can you follow https://github.com/hyperledger/aries-rfcs/blob/main/contributing.md#signing-off-commits-dco?

@TimoGlastra I've signed it. Thanks for letting me know.

@TimoGlastra TimoGlastra merged commit 69b75bd into openwallet-foundation:main Aug 14, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants