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 */
7575import {computed , ref , toRaw , toRef , unref } from ' vue' ;
7676import {
@@ -83,6 +83,9 @@ import ShareReview from './ShareReview.vue';
8383
8484const {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