Skip to content

Commit

Permalink
some additional updates
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <[email protected]>
  • Loading branch information
TimoGlastra committed Jan 12, 2024
1 parent 82b53eb commit e210e09
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 93 deletions.
12 changes: 5 additions & 7 deletions demo-openid/src/Issuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
W3cIssuer,
w3cDate,
} from '@aries-framework/core'
import { OpenId4VcIssuerModule, OpenIdCredentialFormatProfile } from '@aries-framework/openid4vc'
import { OpenId4VcIssuerModule, OpenId4VciCredentialFormatProfile } from '@aries-framework/openid4vc'
import { SdJwtVcModule } from '@aries-framework/sd-jwt-vc'
import { ariesAskar } from '@hyperledger/aries-askar-nodejs'
import { Router } from 'express'
Expand All @@ -26,19 +26,19 @@ import { Output } from './OutputClass'

export const universityDegreeCredential = {
id: 'UniversityDegreeCredential',
format: OpenIdCredentialFormatProfile.JwtVcJson,
format: OpenId4VciCredentialFormatProfile.JwtVcJson,
types: ['VerifiableCredential', 'UniversityDegreeCredential'],
} satisfies OpenId4VciCredentialSupportedWithId

export const openBadgeCredential = {
id: 'OpenBadgeCredential',
format: OpenIdCredentialFormatProfile.JwtVcJson,
format: OpenId4VciCredentialFormatProfile.JwtVcJson,
types: ['VerifiableCredential', 'OpenBadgeCredential'],
} satisfies OpenId4VciCredentialSupportedWithId

export const universityDegreeCredentialSdJwt = {
id: 'UniversityDegreeCredential-sdjwt',
format: OpenIdCredentialFormatProfile.SdJwtVc,
format: OpenId4VciCredentialFormatProfile.SdJwtVc,
vct: 'UniversityDegreeCredential',
} satisfies OpenId4VciCredentialSupportedWithId

Expand All @@ -65,8 +65,6 @@ function getCredentialRequestToCredentialMapper({
issuer: new W3cIssuer({
id: issuerDidKey.did,
}),
// NOTE: credentialSubject will be set at lower level as well, but we can also set it here
// FIXME: we should also set cnf like we set credentialSubject.id
credentialSubject: new W3cCredentialSubject({
id: parseDid(holderBinding.didUrl).did,
}),
Expand Down Expand Up @@ -154,7 +152,7 @@ export class Issuer extends BaseAgent<{

public async createCredentialOffer(offeredCredentials: string[]) {
const { credentialOfferUri } = await this.agent.modules.openId4VcIssuer.createCredentialOffer({
issuerId: this.issuerRecord.id,
issuerId: this.issuerRecord.issuerId,
offeredCredentials,
scheme: 'openid-credential-offer',
preAuthorizedCodeFlowConfig: { userPinRequired: false },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import {
type SupportedCredentialFormats,
supportedCredentialFormats,
} from './OpenId4VciHolderServiceOptions'
import { OpenIdCredentialFormatProfile } from './utils'
import { OpenId4VciCredentialFormatProfile } from './utils'
import { getFormatForVersion, getUniformFormat } from './utils/Formats'
import {
getMetadataFromCredentialOffer,
Expand Down Expand Up @@ -243,9 +243,12 @@ export class OpenId4VciHolderService {
}

const locations = authDetailsLocation ? [authDetailsLocation] : undefined
if (format === OpenIdCredentialFormatProfile.JwtVcJson) {
if (format === OpenId4VciCredentialFormatProfile.JwtVcJson) {
return { type, format, types, locations }
} else if (format === OpenIdCredentialFormatProfile.LdpVc || format === OpenIdCredentialFormatProfile.JwtVcJsonLd) {
} else if (
format === OpenId4VciCredentialFormatProfile.LdpVc ||
format === OpenId4VciCredentialFormatProfile.JwtVcJsonLd
) {
// Inline Credential Offers come with no context so we cannot create the authorization_details
// This type of credentials can only be requested via scopes
if (offerType === OfferedCredentialType.InlineCredentialOffer) return undefined
Expand All @@ -257,7 +260,7 @@ export class OpenId4VciHolderService {
}

return { type, format, locations, credential_definition }
} else if (format === OpenIdCredentialFormatProfile.SdJwtVc) {
} else if (format === OpenId4VciCredentialFormatProfile.SdJwtVc) {
return {
type,
format,
Expand Down Expand Up @@ -618,14 +621,14 @@ export class OpenId4VciHolderService {
signatureAlgorithm = options.possibleProofOfPossessionSignatureAlgorithms[0]
} else {
switch (credentialsToRequest.format) {
case OpenIdCredentialFormatProfile.JwtVcJson:
case OpenIdCredentialFormatProfile.JwtVcJsonLd:
case OpenIdCredentialFormatProfile.SdJwtVc:
case OpenId4VciCredentialFormatProfile.JwtVcJson:
case OpenId4VciCredentialFormatProfile.JwtVcJsonLd:
case OpenId4VciCredentialFormatProfile.SdJwtVc:
signatureAlgorithm = options.possibleProofOfPossessionSignatureAlgorithms.find((signatureAlgorithm) =>
issuerSupportedCryptographicSuites.includes(signatureAlgorithm)
)
break
case OpenIdCredentialFormatProfile.LdpVc:
case OpenId4VciCredentialFormatProfile.LdpVc:
signatureAlgorithm = options.possibleProofOfPossessionSignatureAlgorithms.find((signatureAlgorithm) => {
const JwkClass = getJwkClassFromJwaSignatureAlgorithm(signatureAlgorithm)
if (!JwkClass) return false
Expand Down Expand Up @@ -674,11 +677,11 @@ export class OpenId4VciHolderService {
}

const format = getUniformFormat(credentialResponse.successBody.format)
if (format === OpenIdCredentialFormatProfile.SdJwtVc) {
if (format === OpenId4VciCredentialFormatProfile.SdJwtVc) {
if (typeof credentialResponse.successBody.credential !== 'string')
throw new AriesFrameworkError(
`Received a credential of format ${
OpenIdCredentialFormatProfile.SdJwtVc
OpenId4VciCredentialFormatProfile.SdJwtVc
}, but the credential is not a string. ${JSON.stringify(credentialResponse.successBody.credential)}`
)

Expand All @@ -697,8 +700,8 @@ export class OpenId4VciHolderService {

return sdJwtVc
} else if (
format === OpenIdCredentialFormatProfile.JwtVcJson ||
format === OpenIdCredentialFormatProfile.JwtVcJsonLd
format === OpenId4VciCredentialFormatProfile.JwtVcJson ||
format === OpenId4VciCredentialFormatProfile.JwtVcJsonLd
) {
const credential = W3cJwtVerifiableCredential.fromSerializedJwt(
credentialResponse.successBody.credential as string
Expand All @@ -713,7 +716,7 @@ export class OpenId4VciHolderService {
}

return credential
} else if (format === OpenIdCredentialFormatProfile.LdpVc) {
} else if (format === OpenId4VciCredentialFormatProfile.LdpVc) {
const credential = W3cJsonLdVerifiableCredential.fromJson(
credentialResponse.successBody.credential as Record<string, unknown>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import type {
AuthorizationDetails,
} from '@sphereon/oid4vci-common'

import { OpenIdCredentialFormatProfile } from './utils/claimFormatMapping'
import { OpenId4VciCredentialFormatProfile } from './utils/claimFormatMapping'

export type SupportedCredentialFormats =
| OpenIdCredentialFormatProfile.JwtVcJson
| OpenIdCredentialFormatProfile.JwtVcJsonLd
| OpenIdCredentialFormatProfile.SdJwtVc
| OpenId4VciCredentialFormatProfile.JwtVcJson
| OpenId4VciCredentialFormatProfile.JwtVcJsonLd
| OpenId4VciCredentialFormatProfile.SdJwtVc

export const supportedCredentialFormats: SupportedCredentialFormats[] = [
OpenIdCredentialFormatProfile.JwtVcJson,
OpenIdCredentialFormatProfile.JwtVcJsonLd,
OpenIdCredentialFormatProfile.SdJwtVc,
OpenId4VciCredentialFormatProfile.JwtVcJson,
OpenId4VciCredentialFormatProfile.JwtVcJsonLd,
OpenId4VciCredentialFormatProfile.SdJwtVc,
]

export type { OpenId4VCIVersion, EndpointMetadataResult, CredentialOfferPayloadV1_0_11, AuthorizationDetails }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ import type { CredentialFormat } from '@sphereon/ssi-types'
import { AriesFrameworkError } from '@aries-framework/core'
import { OpenId4VCIVersion } from '@sphereon/oid4vci-common'

import { OpenIdCredentialFormatProfile } from './claimFormatMapping'
import { OpenId4VciCredentialFormatProfile } from './claimFormatMapping'

// Based on https://github.com/Sphereon-Opensource/OID4VCI/pull/54/files

// check if a string is a valid enum value of OpenIdCredentialFormatProfile

const isUniformFormat = (format: string): format is OpenIdCredentialFormatProfile => {
return Object.values(OpenIdCredentialFormatProfile).includes(format as OpenIdCredentialFormatProfile)
const isUniformFormat = (format: string): format is OpenId4VciCredentialFormatProfile => {
return Object.values(OpenId4VciCredentialFormatProfile).includes(format as OpenId4VciCredentialFormatProfile)
}

export function getUniformFormat(
format: string | OpenIdCredentialFormatProfile | CredentialFormat
): OpenIdCredentialFormatProfile {
format: string | OpenId4VciCredentialFormatProfile | CredentialFormat
): OpenId4VciCredentialFormatProfile {
// Already valid format
if (isUniformFormat(format)) return format

// Older formats
if (format === 'jwt_vc' || format === 'jwt') {
return OpenIdCredentialFormatProfile.JwtVcJson
return OpenId4VciCredentialFormatProfile.JwtVcJson
}
if (format === 'ldp_vc' || format === 'ldp') {
return OpenIdCredentialFormatProfile.LdpVc
return OpenId4VciCredentialFormatProfile.LdpVc
}

throw new AriesFrameworkError(`Invalid format: ${format}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { MetadataClient } from '@sphereon/oid4vci-client'
import { OpenId4VCIVersion } from '@sphereon/oid4vci-common'

import { getUniformFormat, getFormatForVersion } from './Formats'
import { OpenIdCredentialFormatProfile } from './claimFormatMapping'
import { OpenId4VciCredentialFormatProfile } from './claimFormatMapping'

/**
* The type of a credential offer entry. For each item in `credentials` array, the type MUST be one of the following:
Expand All @@ -36,39 +36,39 @@ export enum OfferedCredentialType {
export type InlineOfferedCredentialWithMetadata =
| {
offerType: OfferedCredentialType.InlineCredentialOffer
format: OpenIdCredentialFormatProfile.JwtVcJson
format: OpenId4VciCredentialFormatProfile.JwtVcJson
credentialOffer: CredentialOfferFormatJwtVcJson
types: string[]
}
| {
offerType: OfferedCredentialType.InlineCredentialOffer
format: OpenIdCredentialFormatProfile.JwtVcJsonLd | OpenIdCredentialFormatProfile.LdpVc
format: OpenId4VciCredentialFormatProfile.JwtVcJsonLd | OpenId4VciCredentialFormatProfile.LdpVc
credentialOffer: CredentialOfferFormatJwtVcJsonLdAndLdpVc
types: string[]
}
| {
offerType: OfferedCredentialType.InlineCredentialOffer
format: OpenIdCredentialFormatProfile.SdJwtVc
format: OpenId4VciCredentialFormatProfile.SdJwtVc
credentialOffer: CredentialOfferFormatSdJwtVc
types: string[]
}

export type ReferencedOfferedCredentialWithMetadata =
| {
offerType: OfferedCredentialType.CredentialSupported
format: OpenIdCredentialFormatProfile.JwtVcJson
format: OpenId4VciCredentialFormatProfile.JwtVcJson
credentialSupported: CredentialSupportedJwtVcJson
types: string[]
}
| {
offerType: OfferedCredentialType.CredentialSupported
format: OpenIdCredentialFormatProfile.JwtVcJsonLd | OpenIdCredentialFormatProfile.LdpVc
format: OpenId4VciCredentialFormatProfile.JwtVcJsonLd | OpenId4VciCredentialFormatProfile.LdpVc
credentialSupported: CredentialSupportedJwtVcJsonLdAndLdpVc
types: string[]
}
| {
offerType: OfferedCredentialType.CredentialSupported
format: OpenIdCredentialFormatProfile.SdJwtVc
format: OpenId4VciCredentialFormatProfile.SdJwtVc
credentialSupported: CredentialSupportedSdJwtVc
types: string[]
}
Expand Down Expand Up @@ -113,7 +113,7 @@ export function getOfferedCredentialsWithMetadata(
offeredCredentialsWithMetadata.push({
offerType: OfferedCredentialType.CredentialSupported,
credentialSupported: foundSupportedCredential,
format: OpenIdCredentialFormatProfile.SdJwtVc,
format: OpenId4VciCredentialFormatProfile.SdJwtVc,
types: [foundSupportedCredential.vct],
})
} else {
Expand Down Expand Up @@ -225,17 +225,17 @@ export function credentialSupportedV8ToV11(

let credentialSupported: CredentialSupported
const v11Format = getUniformFormat(format)
if (v11Format === OpenIdCredentialFormatProfile.JwtVcJson) {
if (v11Format === OpenId4VciCredentialFormatProfile.JwtVcJson) {
credentialSupported = {
format: OpenIdCredentialFormatProfile.JwtVcJson,
format: OpenId4VciCredentialFormatProfile.JwtVcJson,
display: supportedV8.display,
...credentialSupportedV8,
credentialSubject: supportedV8.claims,
id,
}
} else if (
v11Format === OpenIdCredentialFormatProfile.JwtVcJsonLd ||
v11Format === OpenIdCredentialFormatProfile.LdpVc
v11Format === OpenId4VciCredentialFormatProfile.JwtVcJsonLd ||
v11Format === OpenId4VciCredentialFormatProfile.LdpVc
) {
credentialSupported = {
format: v11Format,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { AriesFrameworkError, ClaimFormat } from '@aries-framework/core'
import {
fromDifClaimFormatToOpenIdCredentialFormatProfile,
fromOpenIdCredentialFormatProfileToDifClaimFormat,
OpenIdCredentialFormatProfile,
OpenId4VciCredentialFormatProfile,
} from '../claimFormatMapping'

describe('claimFormatMapping', () => {
it('should convert from openid credential format profile to DIF claim format', () => {
expect(fromDifClaimFormatToOpenIdCredentialFormatProfile(ClaimFormat.LdpVc)).toStrictEqual(
OpenIdCredentialFormatProfile.LdpVc
OpenId4VciCredentialFormatProfile.LdpVc
)

expect(fromDifClaimFormatToOpenIdCredentialFormatProfile(ClaimFormat.JwtVc)).toStrictEqual(
OpenIdCredentialFormatProfile.JwtVcJson
OpenId4VciCredentialFormatProfile.JwtVcJson
)

expect(() => fromDifClaimFormatToOpenIdCredentialFormatProfile(ClaimFormat.Jwt)).toThrow(AriesFrameworkError)
Expand All @@ -26,15 +26,15 @@ describe('claimFormatMapping', () => {
})

it('should convert from DIF claim format to openid credential format profile', () => {
expect(fromOpenIdCredentialFormatProfileToDifClaimFormat(OpenIdCredentialFormatProfile.JwtVcJson)).toStrictEqual(
ClaimFormat.JwtVc
)
expect(
fromOpenIdCredentialFormatProfileToDifClaimFormat(OpenId4VciCredentialFormatProfile.JwtVcJson)
).toStrictEqual(ClaimFormat.JwtVc)

expect(fromOpenIdCredentialFormatProfileToDifClaimFormat(OpenIdCredentialFormatProfile.JwtVcJsonLd)).toStrictEqual(
ClaimFormat.JwtVc
)
expect(
fromOpenIdCredentialFormatProfileToDifClaimFormat(OpenId4VciCredentialFormatProfile.JwtVcJsonLd)
).toStrictEqual(ClaimFormat.JwtVc)

expect(fromOpenIdCredentialFormatProfileToDifClaimFormat(OpenIdCredentialFormatProfile.LdpVc)).toStrictEqual(
expect(fromOpenIdCredentialFormatProfileToDifClaimFormat(OpenId4VciCredentialFormatProfile.LdpVc)).toStrictEqual(
ClaimFormat.LdpVc
)
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AriesFrameworkError, ClaimFormat } from '@aries-framework/core'

export enum OpenIdCredentialFormatProfile {
export enum OpenId4VciCredentialFormatProfile {
JwtVcJson = 'jwt_vc_json',
JwtVcJsonLd = 'jwt_vc_json-ld',
LdpVc = 'ldp_vc',
Expand All @@ -9,12 +9,12 @@ export enum OpenIdCredentialFormatProfile {

export const fromDifClaimFormatToOpenIdCredentialFormatProfile = (
claimFormat: ClaimFormat
): OpenIdCredentialFormatProfile => {
): OpenId4VciCredentialFormatProfile => {
switch (claimFormat) {
case ClaimFormat.JwtVc:
return OpenIdCredentialFormatProfile.JwtVcJson
return OpenId4VciCredentialFormatProfile.JwtVcJson
case ClaimFormat.LdpVc:
return OpenIdCredentialFormatProfile.LdpVc
return OpenId4VciCredentialFormatProfile.LdpVc
default:
throw new AriesFrameworkError(
`Unsupported DIF claim format, ${claimFormat}, to map to an openid credential format profile`
Expand All @@ -23,14 +23,14 @@ export const fromDifClaimFormatToOpenIdCredentialFormatProfile = (
}

export const fromOpenIdCredentialFormatProfileToDifClaimFormat = (
openidCredentialFormatProfile: OpenIdCredentialFormatProfile
openidCredentialFormatProfile: OpenId4VciCredentialFormatProfile
): ClaimFormat => {
switch (openidCredentialFormatProfile) {
case OpenIdCredentialFormatProfile.JwtVcJson:
case OpenId4VciCredentialFormatProfile.JwtVcJson:
return ClaimFormat.JwtVc
case OpenIdCredentialFormatProfile.JwtVcJsonLd:
case OpenId4VciCredentialFormatProfile.JwtVcJsonLd:
return ClaimFormat.JwtVc
case OpenIdCredentialFormatProfile.LdpVc:
case OpenId4VciCredentialFormatProfile.LdpVc:
return ClaimFormat.LdpVc
default:
throw new AriesFrameworkError(
Expand Down
Loading

0 comments on commit e210e09

Please sign in to comment.