Skip to content

Commit

Permalink
feat: add more info for credential selection
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Auer <martin.auer97@gmail.com>
  • Loading branch information
auer-martin committed Oct 26, 2023
1 parent 505399f commit 09d9837
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
25 changes: 21 additions & 4 deletions packages/openid4vc-holder/src/OpenId4VcHolderService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
CredentialToRequest,
GenerateAuthorizationUrlOptions,
ProofOfPossessionRequirements,
ProofOfPossessionVerificationMethodResolver,
Expand Down Expand Up @@ -210,9 +211,26 @@ export class OpenId4VcHolderService {
version
)

const credentialsToRequest = offeredCredentialsWithMetadata.map((offeredCredential) =>
this.getFormatAndTypesFromOfferedCredential(offeredCredential, version)
)
const credentialsToRequest: CredentialToRequest[] = offeredCredentialsWithMetadata.map((offeredCredential) => {
const { format, types } = this.getFormatAndTypesFromOfferedCredential(offeredCredential, version)
const offerType = offeredCredential.type

if (offerType === OfferedCredentialType.InlineCredentialOffer) {
return { offerType, types, format }
} else {
const { id, cryptographic_binding_methods_supported, cryptographic_suites_supported } =
offeredCredential.credentialSupported

return {
id,
offerType,
cryptographic_binding_methods_supported,
cryptographic_suites_supported,
types,
format,
}
}
})

return {
metadata,
Expand Down Expand Up @@ -248,7 +266,6 @@ export class OpenId4VcHolderService {

const allowedCredentialFormats = supportedCredentialFormats

// TODO: how to request specific credentials with the pre-auth flow?
// acquire the access token
// NOTE: only scope based flow is supported for authorized flow. However there's not clear mapping between
// the scope property and which credential to request (this is out of scope of the spec), so it will still
Expand Down
16 changes: 12 additions & 4 deletions packages/openid4vc-holder/src/OpenId4VcHolderServiceOptions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { OfferedCredentialType } from './OpenId4VcHolderService'
import type { JwaSignatureAlgorithm, KeyType, VerificationMethod } from '@aries-framework/core'
import type { CredentialOfferPayloadV1_0_11, EndpointMetadataResult, OpenId4VCIVersion } from '@sphereon/oid4vci-common'

Expand All @@ -13,10 +14,17 @@ export const supportedCredentialFormats = [
OpenIdCredentialFormatProfile.LdpVc,
] satisfies OpenIdCredentialFormatProfile[]

export interface CredentialToRequest {
format: string
types: string[]
}
export type CredentialToRequest = { format: string; types: string[] } & (
| {
offerType: OfferedCredentialType.InlineCredentialOffer
}
| {
offerType: OfferedCredentialType.CredentialSupported
id: string | undefined
cryptographic_binding_methods_supported: string[] | undefined
cryptographic_suites_supported: string[] | undefined
}
)

export interface ResolvedCredentialOffer {
metadata: EndpointMetadataResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ describe('OpenId4VcHolder', () => {
const w3cCredentialRecords = await agent.modules.openId4VcHolder.acceptCredentialOfferUsingPreAuthorizedCode(
resolvedCredentialOffer,
{
allowedCredentialFormats: [OpenIdCredentialFormatProfile.JwtVcJson],
allowedProofOfPossessionSignatureAlgorithms: [JwaSignatureAlgorithm.ES256],
proofOfPossessionVerificationMethodResolver: () => verificationMethod,
verifyCredentialStatus: false,
Expand Down

0 comments on commit 09d9837

Please sign in to comment.