Skip to content

Commit

Permalink
fix: updated vci package and fixed getSupportedCredential function
Browse files Browse the repository at this point in the history
  • Loading branch information
sksadjad committed May 21, 2024
1 parent f0cf34b commit 780a377
Show file tree
Hide file tree
Showing 8 changed files with 12,215 additions and 8,636 deletions.
4 changes: 2 additions & 2 deletions packages/oid4vci-holder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"build:clean": "tsc --build --clean && tsc --build"
},
"dependencies": {
"@sphereon/oid4vci-client": "0.10.4-unstable.37+b8bb359",
"@sphereon/oid4vci-common": "0.10.4-unstable.37+b8bb359",
"@sphereon/oid4vci-client": "0.10.4-unstable.39+8a6c16f",
"@sphereon/oid4vci-common": "0.10.4-unstable.39+8a6c16f",
"@sphereon/ssi-sdk-ext.did-utils": "0.18.0",
"@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.18.0",
"@sphereon/ssi-sdk.contact-manager": "workspace:*",
Expand Down
6 changes: 3 additions & 3 deletions packages/oid4vci-holder/src/agent/OID4VCIHolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,11 @@ export class OID4VCIHolder implements IAgentPlugin {
const callbacks: ProofOfPossessionCallbacks<DIDDocument> = {
signCallback: (jwt: Jwt, kid?: string) => {
let iss = jwt.payload.iss
/*
if (client.isEBSI()) { FIXME

if (client.isEBSI()) {
iss = jwt.header.kid?.split('#')[0]
}
*/

if (!iss) {
iss = jwt.header.kid?.split('#')[0]
}
Expand Down
56 changes: 20 additions & 36 deletions packages/oid4vci-holder/src/agent/OID4VCIHolderService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
CredentialConfigurationSupported,
CredentialOfferFormat,
CredentialOfferPayloadV1_0_11,
CredentialOfferPayloadV1_0_13,
CredentialResponse,
CredentialsSupportedDisplay,
OpenId4VCIVersion,
Expand Down Expand Up @@ -329,44 +328,29 @@ export const createIdentifier = async (args: CreateIdentifierArgs): Promise<IIde

export const getCredentialsSupported = async (args: GetCredentialsSupportedArgs): Promise<Record<string, CredentialConfigurationSupported>> => {
const { client, vcFormatPreferences } = args
// todo: remove format here. This is just a temp hack for V11+ issuance of only one credential. Having a single array with formats for multiple credentials will not work. This should be handled in VCI itself
let format: string[] | undefined = undefined
if (
client.version() > OpenId4VCIVersion.VER_1_0_09 &&
client.version() < OpenId4VCIVersion.VER_1_0_13 &&
typeof client.credentialOffer?.credential_offer === 'object'
) {
const credentialOffer = client.credentialOffer.credential_offer as CredentialOfferPayloadV1_0_11
format = credentialOffer.credentials
.filter((format: string | CredentialOfferFormat): boolean => typeof format !== 'string')
.map((format: string | CredentialOfferFormat) => (format as CredentialOfferFormat).format)
if (format.length === 0) {
format = undefined // Otherwise we would match nothing
}

if (client.version() < OpenId4VCIVersion.VER_1_0_13 || typeof client.credentialOffer?.credential_offer !== 'object') {
throw new Error(`Unsupported client version: ${client.version()}. Upgrade to OID4VCI library version >= 1.0.13.`)
}

// This restricts to initiation types when there is an offer
const supportedCredentials = client.getCredentialsSupported() as Record<string, CredentialConfigurationSupported>
let credentialsSupported = await getPreferredCredentialFormats({ credentials: supportedCredentials, vcFormatPreferences })
if (!credentialsSupported || Object.keys(credentialsSupported).length === 0) {
credentialsSupported = client.getCredentialsSupported() as Record<string, CredentialConfigurationSupported>
/* FIXME we don't have credential_offer.credentials anymore in v13
credentialsSupported =
client.credentialOffer?.credential_offer.credentials
.filter((format: string | CredentialOfferFormat): boolean => typeof format !== 'string')
.map((credential: string | CredentialOfferFormat) => {
return {
format: (<CredentialOfferFormat>credential).format,
// todo: Move this to VCI lib. A function to get the types from an offer format, including older versions of the spec
types:
(<CredentialOfferFormatJwtVcJsonLdAndLdpVc>credential).credential_definition?.types ??
(<CredentialOfferFormatJwtVcJson>credential).types,
} as CredentialSupported
}) ?? [] // todo check if this addition is ok ?? []
*/
const allSupportedCredentialConfigs = client.getCredentialsSupported() as Record<string, CredentialConfigurationSupported>
let credentialConfigsSupported = await getPreferredCredentialFormats({
credentials: allSupportedCredentialConfigs,
vcFormatPreferences,
})

// Fallback to all configurations if getPreferredCredentialFormats returns none
if (Object.keys(credentialConfigsSupported).length === 0) {
credentialConfigsSupported = allSupportedCredentialConfigs
}

return credentialsSupported
// Filter configurations based on the credential offer IDs
const credentialOffer = client.credentialOffer.credential_offer as CredentialOfferPayloadV1_0_13
const credentialsToOffer = Object.fromEntries(
Object.entries(credentialConfigsSupported).filter(([key]) => credentialOffer.credential_configuration_ids.includes(key)),
)

return Object.keys(credentialsToOffer).length > 0 ? credentialsToOffer : credentialConfigsSupported
}

export const getIssuanceOpts = async (args: GetIssuanceOptsArgs): Promise<Array<IssuanceOpts>> => {
Expand Down
6 changes: 3 additions & 3 deletions packages/oid4vci-issuer-rest-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"start:dev": "ts-node __tests__/RestAPI.ts"
},
"dependencies": {
"@sphereon/oid4vci-common": "0.10.4-unstable.37+b8bb359",
"@sphereon/oid4vci-issuer": "0.10.4-unstable.37+b8bb359",
"@sphereon/oid4vci-issuer-server": "0.10.4-unstable.37+b8bb359",
"@sphereon/oid4vci-common": "0.10.4-unstable.39+8a6c16f",
"@sphereon/oid4vci-issuer": "0.10.4-unstable.39+8a6c16f",
"@sphereon/oid4vci-issuer-server": "0.10.4-unstable.39+8a6c16f",
"@sphereon/ssi-express-support": "workspace:*",
"@sphereon/ssi-sdk.kv-store-temp": "workspace:*",
"@sphereon/ssi-sdk.oid4vci-issuer": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/oid4vci-issuer-rest-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"generate-plugin-schema": "ts-node ../../packages/dev/bin/sphereon.js dev generate-plugin-schema"
},
"dependencies": {
"@sphereon/oid4vci-common": "0.10.4-unstable.37+b8bb359",
"@sphereon/oid4vci-common": "0.10.4-unstable.39+8a6c16f",
"@sphereon/ssi-types": "workspace:*",
"@veramo/core": "4.2.0",
"cross-fetch": "^3.1.8"
Expand Down
2 changes: 1 addition & 1 deletion packages/oid4vci-issuer-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"build:clean": "tsc --build --clean && tsc --build"
},
"dependencies": {
"@sphereon/oid4vci-common": "0.10.4-unstable.37+b8bb359",
"@sphereon/oid4vci-common": "0.10.4-unstable.39+8a6c16f",
"@sphereon/ssi-sdk-ext.did-utils": "0.19.0",
"@sphereon/ssi-sdk.kv-store-temp": "workspace:*",
"@veramo/core": "4.2.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/oid4vci-issuer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"build:clean": "tsc --build --clean && tsc --build"
},
"dependencies": {
"@sphereon/oid4vci-common": "0.10.4-unstable.37+b8bb359",
"@sphereon/oid4vci-issuer": "0.10.4-unstable.37+b8bb359",
"@sphereon/oid4vci-common": "0.10.4-unstable.39+8a6c16f",
"@sphereon/oid4vci-issuer": "0.10.4-unstable.39+8a6c16f",
"@sphereon/ssi-sdk-ext.did-utils": "0.19.0",
"@sphereon/ssi-sdk.core": "workspace:*",
"@sphereon/ssi-sdk.kv-store-temp": "workspace:*",
Expand Down
Loading

0 comments on commit 780a377

Please sign in to comment.