Skip to content

Commit 16c8958

Browse files
committed
Default to VC 2.0 context in VPs.
- If only 1.x VCs are selected, then the VC 1.x context will be used on the presentation to support backwards compatibility.
1 parent 2b5846c commit 16c8958

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

components/ShareCredentials.vue

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070

7171
<script>
7272
/*!
73-
* Copyright (c) 2015-2023 Digital Bazaar, Inc. All rights reserved.
73+
* Copyright (c) 2015-2024 Digital Bazaar, Inc. All rights reserved.
7474
*/
7575
import {computed, ref, toRaw, toRef, unref} from 'vue';
7676
import {
@@ -83,6 +83,9 @@ import ShareReview from './ShareReview.vue';
8383
8484
const {createCapabilities} = helpers;
8585
86+
const VC_V1_CONTEXT_URL = 'https://www.w3.org/2018/credentials/v1';
87+
const VC_V2_CONTEXT_URL = 'https://www.w3.org/ns/credentials/v2';
88+
8689
/**
8790
* This component is generally rendered inside a CHAPI window. It is used
8891
* to select credentials/capabilities to share with a relying party.
@@ -264,7 +267,7 @@ export default {
264267
// TODO: implement
265268
const {verifiableCredential} = this;
266269
const presentation = {
267-
'@context': ['https://www.w3.org/2018/credentials/v1'],
270+
'@context': [VC_V2_CONTEXT_URL],
268271
type: ['VerifiablePresentation'],
269272
holder: this.selectedProfile.id
270273
};
@@ -274,6 +277,11 @@ export default {
274277
// only send the VCs selected
275278
presentation.verifiableCredential = vcs.filter(
276279
vc => selections.includes(vc.id));
280+
if(!_includesVersion2Context(presentation.verifiableCredential)) {
281+
// for backwards compatibility, use VC 1.x context if no VC 2.0
282+
// VCs were selected
283+
presentation['@context'][0] = VC_V1_CONTEXT_URL;
284+
}
277285
}
278286
const capabilities = await this.generateCapabilities();
279287
// Presentations with out capabilities will result
@@ -335,6 +343,11 @@ async function createContainers({credentialStore, records}) {
335343
}
336344
return credentials;
337345
}
346+
347+
function _includesVersion2Context(credentials) {
348+
return credentials.some(({'@context': ctx}) => ctx === VC_V2_CONTEXT_URL ||
349+
(Array.isArray(ctx) && ctx[0] === VC_V2_CONTEXT_URL));
350+
}
338351
</script>
339352
340353
<style lang="scss" scoped>

0 commit comments

Comments
 (0)