diff --git a/CHANGELOG.md b/CHANGELOG.md index a131005..2a32168 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # bedrock-web-wallet ChangeLog +## 14.6.1 - 2024-10-dd + +### Fixed +- Ensure VC 2.0 context is used when returning 2.0 VCs from OID4VCI. + ## 14.6.0 - 2024-10-01 ### Changed diff --git a/lib/exchanges/oid4vci.js b/lib/exchanges/oid4vci.js index b572602..63ff159 100644 --- a/lib/exchanges/oid4vci.js +++ b/lib/exchanges/oid4vci.js @@ -9,6 +9,9 @@ import {Exchange} from './Exchange.js'; import {getDIDAuthenticationOptions} from './util.js'; import {profileManager} from '../state.js'; +const VC_V1_CONTEXT_URL = 'https://www.w3.org/2018/credentials/v1'; +const VC_V2_CONTEXT_URL = 'https://www.w3.org/ns/credentials/v2'; + export class OID4VCIExchange extends Exchange { /** * Creates a new exchange for processing a CHAPI event. @@ -137,8 +140,10 @@ export class OID4VCIExchange extends Exchange { const credential_responses = result?.credential_responses ?? (result && [result]); const credentials = credential_responses?.map(r => r?.credential); + const contextUrl = _includesVersion2Context(credentials) ? + VC_V2_CONTEXT_URL : VC_V1_CONTEXT_URL; const vp = { - '@context': ['https://www.w3.org/2018/credentials/v1'], + '@context': [contextUrl], type: ['VerifiablePresentation'], verifiableCredential: credentials }; @@ -175,3 +180,8 @@ async function _getCredentialOffer({event} = {}) { } return null; } + +function _includesVersion2Context(credentials) { + return credentials.some(({'@context': ctx}) => ctx === VC_V2_CONTEXT_URL || + (Array.isArray(ctx) && ctx[0] === VC_V2_CONTEXT_URL)); +}