diff --git a/__test__/creds/VerifiableCredential.test.js b/__test__/creds/VerifiableCredential.test.js index 2ef2bbeb..9f73d75f 100644 --- a/__test__/creds/VerifiableCredential.test.js +++ b/__test__/creds/VerifiableCredential.test.js @@ -347,38 +347,42 @@ describe('Unit tests for Verifiable Credentials', () => { expect(filtered.claim.contact.phoneNumber.number).toBeUndefined(); }); - it('Should create DocumentId credential', () => { - const typeValue = 'passport'; - const type = new Claim('claim-cvc:Document.type-v1', typeValue, '1'); - const numberValue = 'FP12345'; - const number = new Claim('claim-cvc:Document.number-v1', numberValue, '1'); - const nameValue = { - givenNames: 'e8qhs4Iak1', - familyNames: 'e8qak1', - otherNames: 'qhs4I', - }; + it('Should create IdDocument-v1 credential', () => { + const type = new Claim('claim-cvc:Document.type-v1', 'passport', '1'); + const number = new Claim('claim-cvc:Document.number-v1', 'FP12345', '1'); + const nameValue = { givenNames: 'e8qhs4Iak1', familyNames: 'e8qak1', otherNames: 'qhs4I' }; const name = new Claim('claim-cvc:Document.name-v1', nameValue, '1'); - const genderValue = 'M'; - const gender = new Claim('claim-cvc:Document.gender-v1', genderValue, '1'); - const issueCountryValue = 'Brazil'; - const issueCountry = new Claim('claim-cvc:Document.issueCountry-v1', issueCountryValue, '1'); - const placeOfBirthValue = 'Belo Horizonte'; - const placeOfBirth = new Claim('claim-cvc:Document.placeOfBirth-v1', placeOfBirthValue, '1'); - const dateOfBirthValue = { - day: 20, - month: 3, - year: 1978, - }; + const gender = new Claim('claim-cvc:Document.gender-v1', 'M', '1'); + const issueCountry = new Claim('claim-cvc:Document.issueCountry-v1', 'Brazil', '1'); + const placeOfBirth = new Claim('claim-cvc:Document.placeOfBirth-v1', 'Belo Horizonte', '1'); + const dateOfBirthValue = { day: 20, month: 3, year: 1978 }; const dateOfBirth = new Claim('claim-cvc:Document.dateOfBirth-v1', dateOfBirthValue, '1'); - const dateOfExpiryValue = { - day: 12, - month: 2, - year: 2025, - }; + const dateOfExpiryValue = { day: 12, month: 2, year: 2025 }; const dateOfExpiry = new Claim('claim-cvc:Document.dateOfExpiry-v1', dateOfExpiryValue, '1'); - const nationalityValue = 'Brazilian'; - const nationality = new Claim('claim-cvc:Document.nationality-v1', nationalityValue, '1'); - const evidences = new Claim('claim-cvc:Document.evidences-v1', { + const nationality = new Claim('claim-cvc:Document.nationality-v1', 'Brazilian', '1'); + + const credential = new VC( + 'credential-cvc:IdDocument-v1', '', null, [type, number, name, gender, + issueCountry, placeOfBirth, dateOfBirth, dateOfExpiry, nationality], '1', + ); + expect(credential).toBeDefined(); + }); + + it('Should create IdDocument-v2 credential', () => { + const type = new Claim('claim-cvc:Document.type-v1', 'passport', '1'); + const number = new Claim('claim-cvc:Document.number-v1', 'FP12345', '1'); + const nameValue = { givenNames: 'e8qhs4Iak1', familyNames: 'e8qak1', otherNames: 'qhs4I' }; + const name = new Claim('claim-cvc:Document.name-v1', nameValue, '1'); + const gender = new Claim('claim-cvc:Document.gender-v1', 'M', '1'); + const issueCountry = new Claim('claim-cvc:Document.issueCountry-v1', 'Brazil', '1'); + const placeOfBirth = new Claim('claim-cvc:Document.placeOfBirth-v1', 'Belo Horizonte', '1'); + const dateOfBirthValue = { day: 20, month: 3, year: 1978 }; + const dateOfBirth = new Claim('claim-cvc:Document.dateOfBirth-v1', dateOfBirthValue, '1'); + const dateOfExpiryValue = { day: 12, month: 2, year: 2025 }; + const dateOfExpiry = new Claim('claim-cvc:Document.dateOfExpiry-v1', dateOfExpiryValue, '1'); + const nationality = new Claim('claim-cvc:Document.nationality-v1', 'Brazilian', '1'); + + const evidencesValue = { idDocumentFront: { algorithm: 'sha256', data: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', @@ -391,9 +395,11 @@ describe('Unit tests for Verifiable Credentials', () => { algorithm: 'sha256', data: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', }, - }, '1'); + }; + const evidences = new Claim('claim-cvc:Document.evidences-v1', evidencesValue, '1'); + const credential = new VC( - 'credential-cvc:IdDocument-v1', '', null, [type, number, name, gender, + 'credential-cvc:IdDocument-v2', '', null, [type, number, name, gender, issueCountry, placeOfBirth, dateOfBirth, dateOfExpiry, nationality, evidences], '1', ); expect(credential).toBeDefined(); @@ -1413,11 +1419,14 @@ describe('Unit tests for Verifiable Credentials', () => { const name = new Claim('claim-cvc:Document.name-v1', { givenNames: 'Lucas' }, '1'); const issueCountry = new Claim('claim-cvc:Document.issueCountry-v1', 'Brazil', '1'); - const ucas = [type, name, issueCountry]; // dateOfBirth is missing - + const ucas = [type, name, issueCountry]; expect(() => { new VC('credential-cvc:IdDocument-v1', '', null, ucas, '1'); // eslint-disable-line no-new - }).toThrow(); + }).toThrowError('Missing required claim(s): claim-cvc:Document.dateOfBirth-v1'); + + expect(() => { + new VC('credential-cvc:IdDocument-v2', '', null, ucas, '1'); // eslint-disable-line no-new + }).toThrowError('Missing required claim(s): claim-cvc:Document.dateOfBirth-v1, claim-cvc:Document.evidences-v1'); }); it('Should verify a VC without non-required claims', () => { diff --git a/package-lock.json b/package-lock.json index 46f14702..66848a90 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@identity.com/credential-commons", - "version": "1.0.24", + "version": "1.0.25", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -164,6 +164,23 @@ "integrity": "sha512-ATz6yX/L8LEnC3dtLQnIx4ydcPxhLcoy9Vl6re00zb2w5lG6itY6Vhnr1KFRPq/FHNsgl/gh2mjNN20f9iJTTA==", "dev": true }, + "@babel/runtime": { + "version": "7.5.5", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.5.5.tgz", + "integrity": "sha512-28QvEGyQyNkB0/m2B4FU7IEZGK2NUrcMtT6BZEFALTguLk+AUT6ofsHtPk5QyjAdUkpMJ+/Em+quwz4HOt30AQ==", + "dev": true, + "requires": { + "regenerator-runtime": "^0.13.2" + }, + "dependencies": { + "regenerator-runtime": { + "version": "0.13.3", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz", + "integrity": "sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw==", + "dev": true + } + } + }, "@babel/template": { "version": "7.2.2", "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.2.2.tgz", @@ -294,9 +311,9 @@ "dev": true }, "ajv": { - "version": "6.10.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.0.tgz", - "integrity": "sha512-nffhOpkymDECQyR0mnsUtoCE8RlX38G0rYP+wgLWFyZuUyuuojSSvi/+euOiQBIn63whYwYVIIH1TvE3tu4OEg==", + "version": "6.10.2", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.2.tgz", + "integrity": "sha512-TXtUUEYHuaTEbLZWIKUr5pmBuhDLy+8KYtPYdcV8qC+pOZL+NKqYwvWSRrVXHn+ZmRRAu8vJTAznH7Oag6RVRw==", "requires": { "fast-deep-equal": "^2.0.1", "fast-json-stable-stringify": "^2.0.0", @@ -1579,9 +1596,9 @@ } }, "base-x": { - "version": "3.0.5", - "resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.5.tgz", - "integrity": "sha512-C3picSgzPSLE+jW3tcBzJoGwitOtazb5B+5YmAxZm2ybmTi9LNgAtDO/jjVEBZwHoXmDBZ9m/IELj3elJVRBcA==", + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.6.tgz", + "integrity": "sha512-4PaF8u2+AlViJxRVjurkLTxpp7CaFRD/jo5rPT9ONnKxyhQ8f59yzamEvq7EkriG56yn5On4ONyaG75HLqr46w==", "requires": { "safe-buffer": "^5.0.1" } @@ -1652,9 +1669,9 @@ } }, "bluebird": { - "version": "3.5.4", - "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.4.tgz", - "integrity": "sha512-FG+nFEZChJrbQ9tIccIfZJBz3J7mLrAhxakAbnrJWn8d7aKOC+LWifa0G+p4ZqKp4y13T7juYvdhq9NzKdsrjw==" + "version": "3.5.5", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.5.tgz", + "integrity": "sha512-5am6HnnfN+urzt4yfg7IgTbotDjIT/u8AJpEt0sIU9FtXfVeezXAPKswrG+xKUCOYAINpSdgZVDU6QFh+cuH3w==" }, "bottlejs": { "version": "1.7.2", @@ -2110,6 +2127,12 @@ } } }, + "confusing-browser-globals": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/confusing-browser-globals/-/confusing-browser-globals-1.0.7.tgz", + "integrity": "sha512-cgHI1azax5ATrZ8rJ+ODDML9Fvu67PimB6aNxBrc/QwSaDaM9eTfIEUHx3bBLJJ82ioSb+/5zfsMCCEJax3ByQ==", + "dev": true + }, "contains-path": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/contains-path/-/contains-path-0.1.0.tgz", @@ -2232,9 +2255,9 @@ } }, "damerau-levenshtein": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/damerau-levenshtein/-/damerau-levenshtein-1.0.4.tgz", - "integrity": "sha1-AxkcQyy27qFou3fzpV/9zLiXhRQ=", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/damerau-levenshtein/-/damerau-levenshtein-1.0.5.tgz", + "integrity": "sha512-CBCRqFnpu715iPmw1KrdOrzRqbdFwQTwAWyyyYS42+iAgHCuXZ+/TdMgQkUENPomxEz9z1BEzuQU2Xw0kUuAgA==", "dev": true }, "dashdash": { @@ -2725,25 +2748,25 @@ } }, "eslint-config-airbnb": { - "version": "17.1.0", - "resolved": "https://registry.npmjs.org/eslint-config-airbnb/-/eslint-config-airbnb-17.1.0.tgz", - "integrity": "sha512-R9jw28hFfEQnpPau01NO5K/JWMGLi6aymiF6RsnMURjTk+MqZKllCqGK/0tOvHkPi/NWSSOU2Ced/GX++YxLnw==", + "version": "17.1.1", + "resolved": "https://registry.npmjs.org/eslint-config-airbnb/-/eslint-config-airbnb-17.1.1.tgz", + "integrity": "sha512-xCu//8a/aWqagKljt+1/qAM62BYZeNq04HmdevG5yUGWpja0I/xhqd6GdLRch5oetEGFiJAnvtGuTEAese53Qg==", "dev": true, "requires": { - "eslint-config-airbnb-base": "^13.1.0", + "eslint-config-airbnb-base": "^13.2.0", "object.assign": "^4.1.0", - "object.entries": "^1.0.4" + "object.entries": "^1.1.0" } }, "eslint-config-airbnb-base": { - "version": "13.1.0", - "resolved": "https://registry.npmjs.org/eslint-config-airbnb-base/-/eslint-config-airbnb-base-13.1.0.tgz", - "integrity": "sha512-XWwQtf3U3zIoKO1BbHh6aUhJZQweOwSt4c2JrPDg9FP3Ltv3+YfEv7jIDB8275tVnO/qOHbfuYg3kzw6Je7uWw==", + "version": "13.2.0", + "resolved": "https://registry.npmjs.org/eslint-config-airbnb-base/-/eslint-config-airbnb-base-13.2.0.tgz", + "integrity": "sha512-1mg/7eoB4AUeB0X1c/ho4vb2gYkNH8Trr/EgCT/aGmKhhG+F6vF5s8+iRBlWAzFIAphxIdp3YfEKgEl0f9Xg+w==", "dev": true, "requires": { - "eslint-restricted-globals": "^0.1.1", + "confusing-browser-globals": "^1.0.5", "object.assign": "^4.1.0", - "object.entries": "^1.0.4" + "object.entries": "^1.1.0" } }, "eslint-import-resolver-node": { @@ -2757,9 +2780,9 @@ } }, "eslint-loader": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/eslint-loader/-/eslint-loader-2.1.2.tgz", - "integrity": "sha512-rA9XiXEOilLYPOIInvVH5S/hYfyTPyxag6DZhoQOduM+3TkghAEQ3VcFO8VnX4J4qg/UIBzp72aOf/xvYmpmsg==", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/eslint-loader/-/eslint-loader-2.2.1.tgz", + "integrity": "sha512-RLgV9hoCVsMLvOxCuNjdqOrUqIj9oJg8hF44vzJaYqsAHuY9G2YAeN3joQ9nxP0p5Th9iFSIpKo+SD8KISxXRg==", "dev": true, "requires": { "loader-fs-cache": "^1.0.0", @@ -2770,9 +2793,9 @@ } }, "eslint-module-utils": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.3.0.tgz", - "integrity": "sha512-lmDJgeOOjk8hObTysjqH7wyMi+nsHwwvfBykwfhjR1LNdd7C2uFJBvx4OpWYpXOw4df1yE1cDEVd1yLHitk34w==", + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.4.1.tgz", + "integrity": "sha512-H6DOj+ejw7Tesdgbfs4jeS4YMFrT8uI8xwd1gtQqXssaR0EQ26L+2O/w6wkYFy2MymON0fTwHmXBvvfLNZVZEw==", "dev": true, "requires": { "debug": "^2.6.8", @@ -2791,21 +2814,22 @@ } }, "eslint-plugin-import": { - "version": "2.16.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.16.0.tgz", - "integrity": "sha512-z6oqWlf1x5GkHIFgrSvtmudnqM6Q60KM4KvpWi5ubonMjycLjndvd5+8VAZIsTlHC03djdgJuyKG6XO577px6A==", + "version": "2.18.2", + "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.18.2.tgz", + "integrity": "sha512-5ohpsHAiUBRNaBWAF08izwUGlbrJoJJ+W9/TBwsGoR1MnlgfwMIKrFeSjWbt6moabiXW9xNvtFz+97KHRfI4HQ==", "dev": true, "requires": { + "array-includes": "^3.0.3", "contains-path": "^0.1.0", "debug": "^2.6.9", "doctrine": "1.5.0", "eslint-import-resolver-node": "^0.3.2", - "eslint-module-utils": "^2.3.0", + "eslint-module-utils": "^2.4.0", "has": "^1.0.3", - "lodash": "^4.17.11", "minimatch": "^3.0.4", + "object.values": "^1.1.0", "read-pkg-up": "^2.0.0", - "resolve": "^1.9.0" + "resolve": "^1.11.0" }, "dependencies": { "doctrine": { @@ -2860,6 +2884,15 @@ "read-pkg": "^2.0.0" } }, + "resolve": { + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.11.1.tgz", + "integrity": "sha512-vIpgF6wfuJOZI7KKKSP+HmiKggadPQAdsp5HiC1mvqnfp0gF1vdwgBWZIdrVft9pgqoMFQN+R7BSWZiBxx+BBw==", + "dev": true, + "requires": { + "path-parse": "^1.0.6" + } + }, "strip-bom": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", @@ -2869,11 +2902,12 @@ } }, "eslint-plugin-jsx-a11y": { - "version": "6.2.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-6.2.1.tgz", - "integrity": "sha512-cjN2ObWrRz0TTw7vEcGQrx+YltMvZoOEx4hWU8eEERDnBIU00OTq7Vr+jA7DFKxiwLNv4tTh5Pq2GUNEa8b6+w==", + "version": "6.2.3", + "resolved": "https://registry.npmjs.org/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-6.2.3.tgz", + "integrity": "sha512-CawzfGt9w83tyuVekn0GDPU9ytYtxyxyFZ3aSWROmnRRFQFT2BiPJd7jvRdzNDi6oLWaS2asMeYSNMjWTV4eNg==", "dev": true, "requires": { + "@babel/runtime": "^7.4.5", "aria-query": "^3.0.0", "array-includes": "^3.0.3", "ast-types-flow": "^0.0.7", @@ -2881,36 +2915,43 @@ "damerau-levenshtein": "^1.0.4", "emoji-regex": "^7.0.2", "has": "^1.0.3", - "jsx-ast-utils": "^2.0.1" + "jsx-ast-utils": "^2.2.1" } }, "eslint-plugin-no-only-tests": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-no-only-tests/-/eslint-plugin-no-only-tests-2.3.0.tgz", - "integrity": "sha512-5YZvazTJLWrGU8WUq3xp0Eot02zK/yUT9GoVjrFdXP8flVqH6YBdC6PsAKBRIpcs48WvSfSYrmdwAj3a4d/Iyg==", + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-no-only-tests/-/eslint-plugin-no-only-tests-2.3.1.tgz", + "integrity": "sha512-LzCzeQrlkNjEwUWEoGhfjz+Kgqe0080W6qC8I8eFwSMXIsr1zShuIQnRuSZc4Oi7k1vdUaNGDc+/GFvg6IHSHA==", "dev": true }, "eslint-plugin-react": { - "version": "7.12.4", - "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.12.4.tgz", - "integrity": "sha512-1puHJkXJY+oS1t467MjbqjvX53uQ05HXwjqDgdbGBqf5j9eeydI54G3KwiJmWciQ0HTBacIKw2jgwSBSH3yfgQ==", + "version": "7.14.3", + "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.14.3.tgz", + "integrity": "sha512-EzdyyBWC4Uz2hPYBiEJrKCUi2Fn+BJ9B/pJQcjw5X+x/H2Nm59S4MJIvL4O5NEE0+WbnQwEBxWY03oUk+Bc3FA==", "dev": true, "requires": { "array-includes": "^3.0.3", "doctrine": "^2.1.0", "has": "^1.0.3", - "jsx-ast-utils": "^2.0.1", + "jsx-ast-utils": "^2.1.0", + "object.entries": "^1.1.0", "object.fromentries": "^2.0.0", - "prop-types": "^15.6.2", - "resolve": "^1.9.0" + "object.values": "^1.1.0", + "prop-types": "^15.7.2", + "resolve": "^1.10.1" + }, + "dependencies": { + "resolve": { + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.11.1.tgz", + "integrity": "sha512-vIpgF6wfuJOZI7KKKSP+HmiKggadPQAdsp5HiC1mvqnfp0gF1vdwgBWZIdrVft9pgqoMFQN+R7BSWZiBxx+BBw==", + "dev": true, + "requires": { + "path-parse": "^1.0.6" + } + } } }, - "eslint-restricted-globals": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/eslint-restricted-globals/-/eslint-restricted-globals-0.1.1.tgz", - "integrity": "sha1-NfDVy8ZMLj7WLpO0saevBbp+1Nc=", - "dev": true - }, "eslint-scope": { "version": "3.7.3", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-3.7.3.tgz", @@ -3062,9 +3103,9 @@ } }, "external-editor": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.0.3.tgz", - "integrity": "sha512-bn71H9+qWoOQKyZDo25mOMVpSmXROAsTJVVVYzrrtol3d4y+AsKjf4Iwl2Q+IuT0kFSQ1qo166UuIwqYq7mGnA==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.1.0.tgz", + "integrity": "sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew==", "requires": { "chardet": "^0.7.0", "iconv-lite": "^0.4.24", @@ -3121,9 +3162,9 @@ "integrity": "sha512-lUGBnIamTAwk4znq5BcqsDaxSmZ9nDVJaij6NvRt/Tg4R69gERA+otPKbS86ROw9nxVMw2/mp1fnaiWqbs6Sdg==" }, "figlet": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/figlet/-/figlet-1.2.1.tgz", - "integrity": "sha512-qc8gycfnnfOmfvPl7Fi3JeTbcvdmbZkckyUVGGAM02je7Ookvu+bBfKy1I4FKqTsQHCs3ARJ76ip/k98r+OQuQ==" + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/figlet/-/figlet-1.2.3.tgz", + "integrity": "sha512-+F5zdvZ66j77b8x2KCPvWUHC0UCKUMWrewxmewgPlagp3wmDpcrHMbyv/ygq/6xoxBPGQA+UJU3SMoBzKoROQQ==" }, "figures": { "version": "2.0.0", @@ -4323,9 +4364,9 @@ "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" }, "inquirer": { - "version": "6.2.2", - "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-6.2.2.tgz", - "integrity": "sha512-Z2rREiXA6cHRR9KBOarR3WuLlFzlIfAEIiB45ll5SSadMg7WqOh1MKEjjndfuH5ewXdixWCxqnVfGOQzPeiztA==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-6.5.0.tgz", + "integrity": "sha512-scfHejeG/lVZSpvCXpsB4j/wQNPM5JC8kiElOI0OUTwmc1RTpXr4H32/HOlQHcZiYl2z2VElwuCVDRG8vFmbnA==", "requires": { "ansi-escapes": "^3.2.0", "chalk": "^2.4.2", @@ -4333,12 +4374,12 @@ "cli-width": "^2.0.0", "external-editor": "^3.0.3", "figures": "^2.0.0", - "lodash": "^4.17.11", + "lodash": "^4.17.12", "mute-stream": "0.0.7", "run-async": "^2.2.0", "rxjs": "^6.4.0", "string-width": "^2.1.0", - "strip-ansi": "^5.0.0", + "strip-ansi": "^5.1.0", "through": "^2.3.6" } }, @@ -5333,12 +5374,13 @@ } }, "jsx-ast-utils": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-2.0.1.tgz", - "integrity": "sha1-6AGxs5mF4g//yHtA43SAgOLcrH8=", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-2.2.1.tgz", + "integrity": "sha512-v3FxCcAf20DayI+uxnCuw795+oOIkVu6EnJ1+kSzhqqTZHNkTZ7B66ZgLp4oLJ/gbA64cI0B7WRoHZMSRdyVRQ==", "dev": true, "requires": { - "array-includes": "^3.0.3" + "array-includes": "^3.0.3", + "object.assign": "^4.1.0" } }, "kind-of": { @@ -5465,9 +5507,9 @@ } }, "lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==" + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" }, "lodash.isplainobject": { "version": "4.0.6", @@ -5795,9 +5837,9 @@ "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==" }, "node-fetch": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.3.0.tgz", - "integrity": "sha512-MOd8pV3fxENbryESLgVIeaGKrdl+uaYhCSSVkjeOb/31/njTpcis5aWfdqgNlHIrKOLRbMnfPINPOML2CIFeXA==" + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", + "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==" }, "node-int64": { "version": "0.4.0", @@ -5995,6 +6037,18 @@ } } }, + "object.values": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/object.values/-/object.values-1.1.0.tgz", + "integrity": "sha512-8mf0nKLAoFX6VlNVdhGj31SVYpaNFtUnuoOXWyFEstsWRgU837AK+JYM0iAxwkSzGRbwn8cbFmgbyxj1j4VbXg==", + "dev": true, + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.12.0", + "function-bind": "^1.1.1", + "has": "^1.0.3" + } + }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -6349,13 +6403,14 @@ } }, "prop-types": { - "version": "15.6.2", - "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.6.2.tgz", - "integrity": "sha512-3pboPvLiWD7dkI3qf3KbUe6hKFKa52w+AE0VCqECtf+QHAKgOL37tTaNCnuX1nAAQ4ZhyP+kYVKf8rLmJ/feDQ==", + "version": "15.7.2", + "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.7.2.tgz", + "integrity": "sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==", "dev": true, "requires": { - "loose-envify": "^1.3.1", - "object-assign": "^4.1.1" + "loose-envify": "^1.4.0", + "object-assign": "^4.1.1", + "react-is": "^16.8.1" } }, "pseudomap": { @@ -6447,6 +6502,12 @@ "array-uniq": "1.0.2" } }, + "react-is": { + "version": "16.8.6", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.8.6.tgz", + "integrity": "sha512-aUk3bHfZ2bRSVFFbbeVS4i+lNPZr3/WM5jT2J5omUVV1zzcs1nAaf3l51ctA5FFvCRbhrH0bdAsRRQddFJZPtA==", + "dev": true + }, "read-pkg": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-1.1.0.tgz", @@ -7149,9 +7210,9 @@ } }, "rxjs": { - "version": "6.4.0", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.4.0.tgz", - "integrity": "sha512-Z9Yfa11F6B9Sg/BK9MnqnQ+aQYicPLtilXBp2yUtDt2JRCE0h26d33EnfO3ZxoNxG0T92OUucP3Ct7cpfkdFfw==", + "version": "6.5.2", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.5.2.tgz", + "integrity": "sha512-HUb7j3kvb7p7eCUHE3FqjoDsC1xfZQ4AHFWfTKSpZ+sAhhz5X1WX0ZuUqWbzB2QhSLp3DoLUG+hMdEDKqWo2Zg==", "requires": { "tslib": "^1.9.0" } @@ -8146,9 +8207,9 @@ "integrity": "sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==" }, "tslib": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", - "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==" + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz", + "integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==" }, "tunnel-agent": { "version": "0.6.0", diff --git a/package.json b/package.json index 12462fa3..7ed2b715 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@identity.com/credential-commons", - "version": "1.0.24", + "version": "1.0.25", "author": "Identity.com Community", "license": "MIT", "description": "Verifiable Credential and Attestation Library", @@ -46,13 +46,13 @@ "babel-plugin-transform-runtime": "^6.23.0", "babel-preset-env": "^1.6.1", "eslint": "^4.19.1", - "eslint-config-airbnb": "^17.0.0", - "eslint-config-airbnb-base": "^13.0.0", - "eslint-loader": "^2.1.2", - "eslint-plugin-import": "^2.16.0", - "eslint-plugin-jsx-a11y": "^6.2.1", - "eslint-plugin-no-only-tests": "^2.3.0", - "eslint-plugin-react": "^7.10.0", + "eslint-config-airbnb": "^17.1.1", + "eslint-config-airbnb-base": "^13.2.0", + "eslint-loader": "^2.2.1", + "eslint-plugin-import": "^2.18.2", + "eslint-plugin-jsx-a11y": "^6.2.3", + "eslint-plugin-no-only-tests": "^2.3.1", + "eslint-plugin-react": "^7.14.3", "husky": "^1.1.2", "jest": "^23.6.0", "jest-html-reporter": "^2.5.0", @@ -61,24 +61,24 @@ }, "dependencies": { "@identity.com/uca": "1.0.14", - "ajv": "^6.10.0", + "ajv": "^6.10.2", "babel-runtime": "^6.26.0", "bitcoinjs-lib": "git+https://github.com/dabura667/bitcoinjs-lib.git#bcash330", - "bluebird": "^3.5.4", + "bluebird": "^3.5.5", "bottlejs": "^1.7.2", "bson": "^3.0.0", "chalk": "^2.4.1", "clear": "^0.1.0", "cross-env": "^5.1.6", "dotenv": "^6.0.0", - "figlet": "^1.2.0", + "figlet": "^1.2.3", "flat": "^4.1.0", - "inquirer": "^6.2.2", + "inquirer": "^6.5.0", "json-format": "^1.0.1", - "lodash": "^4.17.11", + "lodash": "^4.17.15", "md5": "^2.2.1", "merkle-tools": "^1.4.0", - "node-fetch": "^2.1.2", + "node-fetch": "^2.6.0", "randexp": "^0.4.9", "randomstring": "^1.1.5", "request": "^2.87.0", diff --git a/src/creds/VerifiableCredential.js b/src/creds/VerifiableCredential.js index 25b8cff2..213f33ed 100644 --- a/src/creds/VerifiableCredential.js +++ b/src/creds/VerifiableCredential.js @@ -270,8 +270,7 @@ const VERIFY_LEVELS = { }; /** - * Returns true if the definition has no required claims or if it has required claims - * and the provided ucas meet the requirements. Returns false otherwise. + * Throws exception if the definition has missing required claims * @param {*} definition - the credential definition * @param {*} ucas - the list of ucas */ @@ -279,14 +278,14 @@ function verifyRequiredClaims(definition, ucas) { if (!_.isEmpty(definition.required)) { const identifiers = ucas.map(uca => uca.identifier); const missings = _.difference(definition.required, identifiers); - return _.isEmpty(missings); + if (!_.isEmpty(missings)) { + throw new Error(`Missing required claim(s): ${_.join(missings, ', ')}`); + } } - return true; } /** - * Returns true if the definition has no required claims or if it has required claims - * and the verifiable credential JSON meets the requirements. Returns false otherwise. + * Throws exception if the definition has missing required claims * @param {*} definition - the credential definition * @param {*} verifiableCredentialJSON - the verifiable credential JSON */ @@ -296,9 +295,10 @@ function verifyRequiredClaimsFromJSON(definition, verifiableCredentialJSON) { if (!_.isEmpty(definition.required) && leaves) { const identifiers = leaves.map(leave => leave.identifier); const missings = _.difference(definition.required, identifiers); - return _.isEmpty(missings); + if (!_.isEmpty(missings)) { + throw new Error(`Missing required claim(s): ${_.join(missings, ', ')}`); + } } - return true; } /** @@ -354,9 +354,7 @@ function VerifiableCredentialBaseConstructor(identifier, issuer, expiryIn, ucas, // ucas can be empty here if it is been constructed from JSON if (!_.isEmpty(ucas)) { - if (!verifyRequiredClaims(definition, ucas)) { - throw new Error('Missing required(s) UCA'); - } + verifyRequiredClaims(definition, ucas); this.claim = new ClaimModel(ucas); const claimsPathRef = paths(this.claim); const deepKeys = _.keys(flatten(this.claim, { safe: true })); @@ -738,9 +736,7 @@ VerifiableCredentialBaseConstructor.fromJSON = (verifiableCredentialJSON) => { const definition = getCredentialDefinition(verifiableCredentialJSON.identifier, verifiableCredentialJSON.version); - if (!verifyRequiredClaimsFromJSON(definition, verifiableCredentialJSON)) { - throw new Error('Missing required(s) claims'); - } + verifyRequiredClaimsFromJSON(definition, verifiableCredentialJSON); const newObj = new VerifiableCredentialBaseConstructor(verifiableCredentialJSON.identifier, verifiableCredentialJSON.issuer); diff --git a/src/creds/definitions.js b/src/creds/definitions.js index db203f62..3faaa7df 100644 --- a/src/creds/definitions.js +++ b/src/creds/definitions.js @@ -59,6 +59,29 @@ const definitions = [ 'claim-cvc:Document.issueCountry-v1', ], }, + { + identifier: 'credential-cvc:IdDocument-v2', + version: '1', + depends: [ + 'claim-cvc:Document.type-v1', + 'claim-cvc:Document.number-v1', + 'claim-cvc:Document.name-v1', + 'claim-cvc:Document.gender-v1', + 'claim-cvc:Document.issueCountry-v1', + 'claim-cvc:Document.placeOfBirth-v1', + 'claim-cvc:Document.dateOfBirth-v1', + 'claim-cvc:Document.dateOfExpiry-v1', + 'claim-cvc:Document.nationality-v1', + 'claim-cvc:Document.evidences-v1', + ], + required: [ + 'claim-cvc:Document.type-v1', + 'claim-cvc:Document.name-v1', + 'claim-cvc:Document.dateOfBirth-v1', + 'claim-cvc:Document.issueCountry-v1', + 'claim-cvc:Document.evidences-v1', + ], + }, { identifier: 'credential-cvc:Address-v1', version: '1',