diff --git a/lib/index.js b/lib/index.js index 3d4fd42c..9e32308f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -635,10 +635,10 @@ export function _checkCredential({ } if(checkContextVersion({credential, version: 2.0})) { // check if 'validUntil' and 'validFrom' - if(mode === 'verify') { - let {validUntil, validFrom} = credential; - if(validUntil) { - assertDateString({credential, prop: 'validUntil'}); + let {validUntil, validFrom} = credential; + if(validUntil) { + assertDateString({credential, prop: 'validUntil'}); + if(mode === 'verify') { validUntil = new Date(credential.validUntil); if(now > validUntil) { throw new Error( @@ -646,9 +646,11 @@ export function _checkCredential({ `"validUntil" (${credential.validUntil}).`); } } - if(validFrom) { - assertDateString({credential, prop: 'validFrom'}); - // check if `now` is before `validFrom` + } + if(validFrom) { + assertDateString({credential, prop: 'validFrom'}); + if(mode === 'verify') { + // check if `now` is before `validFrom` validFrom = new Date(credential.validFrom); if(now < validFrom) { throw new Error(