Skip to content

Commit

Permalink
Ensure VC 2.0 context is used when returning 2.0 VCs from OID4VCI.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Oct 2, 2024
1 parent c03d475 commit b3a2473
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 11 additions & 1 deletion lib/exchanges/oid4vci.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
};
Expand Down Expand Up @@ -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));
}

0 comments on commit b3a2473

Please sign in to comment.