From 45cb8e16bc07378e76a1569b8e2a713b91b1b929 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Fri, 8 Dec 2023 19:45:43 +0000 Subject: [PATCH] Check validUntil & validFrom format on issue. --- lib/index.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) 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(