@digitalbazaar/vc
Advanced tools
Comparing version 3.0.0 to 4.0.0
@@ -110,2 +110,4 @@ /** | ||
* @param {object} [options.expansionMap] - An expansion map. | ||
* @param {string|Date} [options.now] - A string representing date time in | ||
* ISO 8601 format or an instance of Date. Defaults to current date time. | ||
* | ||
@@ -119,3 +121,4 @@ * @throws {Error} If missing required properties. | ||
purpose = new CredentialIssuancePurpose(), | ||
documentLoader = defaultDocumentLoader | ||
documentLoader = defaultDocumentLoader, | ||
now | ||
} = {}) { | ||
@@ -142,3 +145,3 @@ // check to make sure the `suite` has required params | ||
// run common credential checks | ||
_checkCredential(credential); | ||
_checkCredential({credential, now}); | ||
@@ -185,2 +188,4 @@ return jsigs.sign(credential, {purpose, documentLoader, suite, expansionMap}); | ||
* credential status if `credentialStatus` is present on the credential. | ||
* @param {string|Date} [options.now] - A string representing date time in | ||
* ISO 8601 format or an instance of Date. Defaults to current date time. | ||
* | ||
@@ -229,2 +234,4 @@ * @returns {Promise<VerifyPresentationResult>} The verification result. | ||
* credential status if `credentialStatus` is present on the credential. | ||
* @param {string|Date} [options.now] - A string representing date time in | ||
* ISO 8601 format or an instance of Date. Defaults to current date time. | ||
* | ||
@@ -259,2 +266,4 @@ * @returns {Promise<VerifyCredentialResult>} The verification result. | ||
* definition in the `verify()` docstring, for this param. | ||
* @param {string|Date} [options.now] - A string representing date time in | ||
* ISO 8601 format or an instance of Date. Defaults to current date time. | ||
* | ||
@@ -271,6 +280,6 @@ * @throws {Error} If required parameters are missing (in `_checkCredential`). | ||
async function _verifyCredential(options = {}) { | ||
const {credential, checkStatus} = options; | ||
const {credential, checkStatus, now} = options; | ||
// run common credential checks | ||
_checkCredential(credential); | ||
_checkCredential({credential, now}); | ||
@@ -317,2 +326,4 @@ // if credential status is provided, a `checkStatus` function must be given | ||
* @param {string} [options.holder] - Optional presentation holder url. | ||
* @param {string|Date} [options.now] - A string representing date time in | ||
* ISO 8601 format or an instance of Date. Defaults to current date time. | ||
* | ||
@@ -326,3 +337,5 @@ * @throws {TypeError} If verifiableCredential param is missing. | ||
*/ | ||
export function createPresentation({verifiableCredential, id, holder} = {}) { | ||
export function createPresentation({ | ||
verifiableCredential, id, holder, now | ||
} = {}) { | ||
const presentation = { | ||
@@ -336,3 +349,3 @@ '@context': [CREDENTIALS_CONTEXT_V1_URL], | ||
for(const credential of credentials) { | ||
_checkCredential(credential); | ||
_checkCredential({credential, now}); | ||
} | ||
@@ -418,2 +431,4 @@ presentation.verifiableCredential = credentials; | ||
* credential status if `credentialStatus` is present on the credential. | ||
* @param {string|Date} [options.now] - A string representing date time in | ||
* ISO 8601 format or an instance of Date. Defaults to current date time. | ||
* | ||
@@ -501,2 +516,3 @@ * @throws {Error} If presentation is missing required params. | ||
* @param {object} presentation - An object that could be a presentation. | ||
* | ||
* @throws {Error} | ||
@@ -527,7 +543,15 @@ * @private | ||
/** | ||
* @param {object} credential - An object that could be a VerifiableCredential. | ||
* @param {object} options - The options. | ||
* @param {object} options.credential - An object that could be a | ||
* VerifiableCredential. | ||
* @param {string|Date} [options.now] - A string representing date time in | ||
* ISO 8601 format or an instance of Date. Defaults to current date time. | ||
* | ||
* @throws {Error} | ||
* @private | ||
*/ | ||
export function _checkCredential(credential) { | ||
export function _checkCredential({credential, now = new Date()}) { | ||
if(typeof now === 'string') { | ||
now = new Date(now); | ||
} | ||
// ensure first context is 'https://www.w3.org/2018/credentials/v1' | ||
@@ -575,5 +599,12 @@ if(credential['@context'][0] !== CREDENTIALS_CONTEXT_V1_URL) { | ||
if('issuanceDate' in credential) { | ||
if(!dateRegex.test(credential.issuanceDate)) { | ||
let {issuanceDate} = credential; | ||
if(!dateRegex.test(issuanceDate)) { | ||
throw new Error(`"issuanceDate" must be a valid date: ${issuanceDate}`); | ||
} | ||
// check if `now` is before `issuanceDate` | ||
issuanceDate = new Date(issuanceDate); | ||
if(now < issuanceDate) { | ||
throw new Error( | ||
`"issuanceDate" must be a valid date: ${credential.issuanceDate}`); | ||
`The current date time (${now.toISOString()}) is before the ` + | ||
`"issuanceDate" (${issuanceDate.toISOString()}).`); | ||
} | ||
@@ -613,7 +644,13 @@ } | ||
// check expires is a date | ||
if('expirationDate' in credential && | ||
!dateRegex.test(credential.expirationDate)) { | ||
throw new Error( | ||
`"expirationDate" must be a valid date: ${credential.expirationDate}`); | ||
if('expirationDate' in credential) { | ||
const {expirationDate} = credential; | ||
// check if `expirationDate` property is a date | ||
if(!dateRegex.test(expirationDate)) { | ||
throw new Error( | ||
`"expirationDate" must be a valid date: ${expirationDate}`); | ||
} | ||
// check if `now` is after `expirationDate` | ||
if(now > new Date(expirationDate)) { | ||
throw new Error('Credential has expired.'); | ||
} | ||
} | ||
@@ -620,0 +657,0 @@ } |
{ | ||
"name": "@digitalbazaar/vc", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"description": "Verifiable Credentials JavaScript library.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/digitalbazaar/vc-js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
53812
939
0