Skip to content

Commit

Permalink
Merge pull request #172 from identity-com/handling_presentations_from…
Browse files Browse the repository at this point in the history
…JSON

Handling presentations from json
  • Loading branch information
jpsantosbh authored May 26, 2021
2 parents 0e2462d + d9cd3af commit 9112667
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 23 deletions.
12 changes: 12 additions & 0 deletions __test__/creds/VerifiableCredential.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const credentialDefinitions = require('../../src/creds/definitions');
const SchemaGenerator = require('../../src/schemas/generator/SchemaGenerator');
const MiniCryptoManagerImpl = require('../../src/services/MiniCryptoManagerImpl');
const CredentialSignerVerifier = require('../../src/creds/CredentialSignerVerifier');
const filteredCredentialJson = require('./fixtures/filteredIdDocument-v2.json');

// eslint-disable-next-line max-len
const prvBase58 = 'xprv9s21ZrQH143K4aBUwUW6GVec7Y6oUEBqrt2WWaXyxjh2pjofNc1of44BLufn4p1t7Jq4EPzm5C9sRxCuBYJdHu62jhgfyPm544sNjtH7x8S';
Expand Down Expand Up @@ -390,6 +391,17 @@ describe('Unit tests for Verifiable Credentials', () => {
issueCountry, placeOfBirth, dateOfBirth, dateOfExpiry, nationality, evidences], '1',
);
expect(credential).toBeDefined();
const filtered = credential.filter(['claim-cvc:Document.dateOfBirth-v1']);
expect(filtered).toBeDefined();
});

it('Should hydrate a partial presentation', () => {
const presentation = VC.fromJSON(filteredCredentialJson, true);
expect(presentation).toBeDefined();

expect(() => {
VC.fromJSON(filteredCredentialJson);
}).toThrow();
});

it('Should create alt:Identity-v1 credential', () => {
Expand Down
53 changes: 53 additions & 0 deletions __test__/creds/fixtures/filteredIdDocument-v2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"id": "f471b5f8-6ad6-4782-968d-f2924145fa54",
"issuer": "",
"issuanceDate": "2021-05-26T20:11:12.082Z",
"identifier": "credential-cvc:IdDocument-v2",
"expirationDate": null,
"version": "1",
"type": [
"Credential",
"credential-cvc:IdDocument-v2"
],
"transient": false,
"claim": {
"document": {
"dateOfBirth": {
"day": 20,
"month": 3,
"year": 1978
}
}
},
"proof": {
"type": "CvcMerkleProof2018",
"merkleRoot": "9d424cbc30d418ed42f1b1031fa4fdef273e6b371637b4c8e5184a566b9d27cc",
"anchor": "TBD (Civic Blockchain Attestation)",
"leaves": [
{
"identifier": "claim-cvc:Document.dateOfBirth-v1",
"value": "urn:dateOfBirth.day:f0bbfa2a35fc0dfa27a2620691feedde6fff1c522817b546e730740f7339354d:20|urn:dateOfBirth.month:75e6e5fa1f03d6b985862e7ad1467405e0c482df64e6ed1692312aaba7d4d951:3|urn:dateOfBirth.year:c4d7200e945ef41009be24127cdd394d17a7bc0330d3b1b19270372543ff6517:1978|",
"claimPath": "document.dateOfBirth",
"targetHash": "3fdb18a8022d009da8eda7b353ebfdaad91ad4d6256f647e174ac16448d42f6d",
"node": [
{
"left": "72e6f2e8c817048bb82442371202c9c078cabbacb7739ce4781f68855b362ca8"
},
{
"right": "aae76d0dd2b272496a4ccc799cd60a329da4d78742b9e4f8792c4a3b4259d414"
},
{
"right": "9c4a9d7c1d1a76dd3c8aa274d6cf8de8cd5ed4658162c84db409e8c0dab422ea"
},
{
"left": "03024ff54437b7d65ad908229977e8603f3f5451a611ec88235775db23d522f5"
},
{
"right": "b8dc070cacd5d604ec328cfee7d396e3a6ba5011a616049126d37460f7280154"
}
]
}
]
},
"granted": null
}
78 changes: 59 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@identity.com/credential-commons",
"version": "1.2.6",
"version": "1.2.7",
"author": "Identity.com Community",
"license": "MIT",
"description": "Verifiable Credential and Attestation Library",
Expand Down Expand Up @@ -61,7 +61,7 @@
"jest-html-reporter": "^2.3.0",
"request-debug": "^0.2.0",
"rimraf": "^2.6.2",
"ajv": "^6.5.2"
"ajv": "^7.2.4"
},
"dependencies": {
"@identity.com/uca": "github:civicteam/uca",
Expand Down
6 changes: 4 additions & 2 deletions src/creds/VerifiableCredential.js
Original file line number Diff line number Diff line change
Expand Up @@ -746,11 +746,13 @@ VerifiableCredentialBaseConstructor.isMatchCredentialMeta = isMatchCredentialMet
* @param {*} verifiableCredentialJSON
* @returns VerifiableCredentialBaseConstructor
*/
VerifiableCredentialBaseConstructor.fromJSON = (verifiableCredentialJSON) => {
VerifiableCredentialBaseConstructor.fromJSON = (verifiableCredentialJSON, partialPresentation = false) => {
const definition = getCredentialDefinition(verifiableCredentialJSON.identifier,
verifiableCredentialJSON.version);

verifyRequiredClaimsFromJSON(definition, verifiableCredentialJSON);
if (!partialPresentation) {
verifyRequiredClaimsFromJSON(definition, verifiableCredentialJSON);
}

const newObj = new VerifiableCredentialBaseConstructor(verifiableCredentialJSON.identifier,
verifiableCredentialJSON.issuer);
Expand Down

0 comments on commit 9112667

Please sign in to comment.