Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,17 +674,18 @@ export function _checkCredential({
_validateUriId({id: issuer, propertyName: 'issuer'});
}

if('credentialStatus' in credential) {
const {credentialStatus} = credential;
if(Array.isArray(credentialStatus) ?
credentialStatus.some(cs => !cs.id) : !credentialStatus.id) {
throw new Error('"credentialStatus" must include an id.');
// check credentialStatus
jsonld.getValues(credential, 'credentialStatus').forEach(cs => {
// check if optional "id" is a URL
if('id' in cs) {
_validateUriId({id: cs.id, propertyName: 'credentialStatus.id'});
}
if(Array.isArray(credentialStatus) ?
credentialStatus.some(cs => !cs.type) : !credentialStatus.type) {

// check "type" present
if(!cs.type) {
throw new Error('"credentialStatus" must include a type.');
}
}
});

// check evidences are URLs
jsonld.getValues(credential, 'evidence').forEach(evidence => {
Expand Down
34 changes: 34 additions & 0 deletions test/10-verify.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,40 @@ for(const [version, mockCredential] of versionedCredentials) {
.contain('"issuer" must be a URI');
});

it('should reject credentialStatus that is not a URI', () => {
const credential = mockCredential();
credential.credentialStatus = {
id: 'not-a-url',
type: 'urn:type'
};
let error;
try {
vc._checkCredential({credential});
} catch(e) {
error = e;
}
should.exist(error,
'Should throw error when "evidence" is not a URI');
error.should.be.instanceof(TypeError);
error.message.should
.contain('"credentialStatus.id" must be a URI');
});

it('should accept "credentialStatus" with no "id"', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this 1.0 or 2.0? in 2.0 I'm showing: https://w3c.github.io/vc-data-model/#status

credentialStatus
If present, the value of the credentialStatus property MUST include the following:
id property, which MUST be a URL which MAY be dereferenced.
type property, which expresses the credential status type.

so it should not accept a credentialStatus with no id. @davidlehn

@aljones15 aljones15 Jan 4, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also checked and in 1.1 credentialStatus.id must be a url and present:

https://www.w3.org/TR/vc-data-model/#status

credentialStatus
If present, the value of the credentialStatus property MUST include the following:
id property, which MUST be a URI.
type property, which expresses the credential status type (also referred to as the credential status method). It is expected that the value will provide enough information to determine the current status of the credential and that machine readable information needs to be retrievable from the URI. For example, the object could contain a link to an external document noting whether or not the credential is suspended or revoked.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to summarize: in vc 2.0 credential status id is becoming optional because specs that define credential status(es) don't necessarily want to make information like id available. So in the higher level spec (VC 2.0) id will become optional and then depending on the credential status spec id will be required or not.

const credential = mockCredential();
credential.credentialStatus = {
type: 'urn:type'
};
let error;
try {
vc._checkCredential({credential});
} catch(e) {
error = e;
}
should.not.exist(error,
'Should not throw error when "credentialStatus.id" is absent');
});

it('should reject an evidence id that is not a URI', () => {
const credential = mockCredential();
credential.issuer = 'did:example:12345';
Expand Down