Skip to content

Commit

Permalink
Parse enveloped VCs in enveloped-VC status tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed May 23, 2024
1 parent 4686732 commit b0edac6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
11 changes: 7 additions & 4 deletions test/mocha/60-vc-jwt-issuer-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const serviceType = 'vc-issuer';
// https://www.w3.org/2018/credentials/examples/v1
const mockCredential = require('./mock-credential.json');

describe.skip('issue using VC-JWT format w/status list support', () => {
describe('issue using VC-JWT format w/status list support', () => {
let assertionMethodKeyId;
let capabilityAgent;
let did;
Expand Down Expand Up @@ -170,8 +170,6 @@ describe.skip('issue using VC-JWT format w/status list support', () => {
new TextDecoder().decode(base64url.decode(split[0])));
const payload = JSON.parse(
new TextDecoder().decode(base64url.decode(split[1])));
console.log('header', header);
console.log('payload', payload);
header.kid.should.equal(assertionMethodKeyId);
header.alg.should.equal('ES256');
payload.iss.should.equal(did);
Expand Down Expand Up @@ -201,12 +199,17 @@ describe.skip('issue using VC-JWT format w/status list support', () => {
// first issue VC
const credential = klona(mockCredential);
const zcapClient = helpers.createZcapClient({capabilityAgent});
const {data: {verifiableCredential}} = await zcapClient.write({
let {data: {verifiableCredential}} = await zcapClient.write({
url: `${issuerId}/credentials/issue`,
capability: issuerRootZcap,
json: {credential}
});

// parse enveloped VC as needed
if(verifiableCredential.type === 'EnvelopedVerifiableCredential') {
verifiableCredential = helpers.parseEnvelope({verifiableCredential});
}

// get VC status
const statusInfo = await helpers.getCredentialStatus(
{verifiableCredential});
Expand Down
25 changes: 24 additions & 1 deletion test/mocha/helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2019-2024 Digital Bazaar, Inc. All rights reserved.
*/
import * as base64url from 'base64url-universal';
import * as bedrock from '@bedrock/core';
import * as database from '@bedrock/mongodb';
import {importJWK, SignJWT} from 'jose';
Expand Down Expand Up @@ -362,9 +363,14 @@ export async function getCredentialStatus({
statusPurpose
};
}
const {data: slc} = await httpClient.get(
let {data: slc} = await httpClient.get(
statusListCredential, {agent: httpsAgent});

// parse enveloped VC as needed
if(slc.type === 'EnvelopedVerifiableCredential') {
slc = parseEnvelope({verifiableCredential: slc});
}

const {encodedList} = slc.credentialSubject;
let list;
if(slc.type.includes('StatusList2021Credential')) {
Expand Down Expand Up @@ -647,3 +653,20 @@ export function parseKeystoreId(keyId) {
}
return keyId.slice(0, idx);
}

export function parseEnvelope({verifiableCredential}) {
const {id} = verifiableCredential;
const commaIndex = id.indexOf(',');
const format = id.slice('data:'.length, commaIndex);

// VC-JWT envelope
if(format === 'application/jwt') {
const data = id.slice(commaIndex + 1);
// FIXME: consider adding verification of `data` (JWT)
const split = data.split('.');
const claimSet = JSON.parse(
new TextDecoder().decode(base64url.decode(split[1])));
return claimSet.vc;
}
throw new Error(`Unknown envelope format "${format}".`);
}
2 changes: 1 addition & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@bedrock/test": "^8.0.5",
"@bedrock/validation": "^7.0.0",
"@bedrock/vc-issuer": "file:..",
"@bedrock/vc-status": "digitalbazaar/bedrock-vc-status#initial",
"@bedrock/vc-status": "digitalbazaar/bedrock-vc-status#envelope",
"@bedrock/vc-status-list-context": "digitalbazaar/bedrock-vc-status-list-context#bitstring-status-list",
"@bedrock/veres-one-context": "^15.0.0",
"@bedrock/zcap-storage": "^8.0.0",
Expand Down

0 comments on commit b0edac6

Please sign in to comment.