Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@digitalbazaar/vc

Package Overview
Dependencies
Maintainers
5
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@digitalbazaar/vc - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

67

lib/index.js

@@ -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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc