Skip to content

Commit

Permalink
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions packages/credential-sdk/src/vc/credentials.js
Original file line number Diff line number Diff line change
@@ -168,7 +168,7 @@ export function checkCredentialJSONLD(credential) {
* @param {object} credential - An object that could be a VerifiableCredential.
* @throws {Error}
*/
export function checkCredentialRequired(credential) {
export function checkCredentialRequired(credential, isJWT) {
// Ensure first context is DEFAULT_CONTEXT_V1_URL
if (credential['@context'][0] !== DEFAULT_CONTEXT_V1_URL) {
throw new Error(
@@ -186,21 +186,23 @@ export function checkCredentialRequired(credential) {
throw new Error('"credentialSubject" property is required.');
}

// Ensure issuer is valid
const issuer = getId(credential.issuer);
if (!issuer) {
throw new Error(
`"issuer" must be an object with ID property or a string. Got: ${credential.issuer}`,
);
} else if (!issuer.includes(':')) {
throw new Error('"issuer" id must be in URL format.');
}
// Ensure issuer and issue date is valid, only for non-jwt as that is defined in the header
if (!isJWT) {
const issuer = getId(credential.issuer);
if (!issuer) {
throw new Error(
`"issuer" must be an object with ID property or a string. Got: ${credential.issuer}`,
);
} else if (!issuer.includes(':')) {
throw new Error('"issuer" id must be in URL format.');
}

// Ensure there is an issuance date, if exists
if (!credential.issuanceDate) {
throw new Error('"issuanceDate" property is required.');
} else {
ensureValidDatetime(credential.issuanceDate);
// Ensure there is an issuance date, if exists
if (!credential.issuanceDate) {
throw new Error('"issuanceDate" property is required.');
} else {
ensureValidDatetime(credential.issuanceDate);
}
}
}

@@ -229,8 +231,8 @@ export function checkCredentialOptional(credential) {
* @param {object} credential - An object that could be a VerifiableCredential.
* @throws {Error}
*/
export function checkCredential(credential) {
checkCredentialRequired(credential);
export function checkCredential(credential, isJWT) {
checkCredentialRequired(credential, isJWT);
checkCredentialOptional(credential);
checkCredentialJSONLD(credential);
}
@@ -295,7 +297,7 @@ export async function verifyCredential(
}

// Check credential is valid
checkCredential(credential);
checkCredential(credential, isJWT);

// Check expiration date
if (verifyDates && 'expirationDate' in credential) {

0 comments on commit 4cd5eb0

Please sign in to comment.