Skip to content

Commit

Permalink
Merge pull request #150 from identity-com/CIV-2525_HealthKeyCredentials
Browse files Browse the repository at this point in the history
CIV-2525 HealthKey credential and claims support
  • Loading branch information
jpsantosbh authored Jan 25, 2021
2 parents cbf598c + 28015a5 commit caa0ed9
Show file tree
Hide file tree
Showing 13 changed files with 645 additions and 107 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ npm-debug.log
build
.DS_Store
dist
.history/

.history
118 changes: 116 additions & 2 deletions __test__/claim/Claim.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,127 @@ describe('Claim Constructions tests', () => {
expect(v.value.year.value).toBe(value.year);
});

test('Construct by NameGivenNames must result successfuly', () => {
test('Construct Vaccination.Records successfully', () => {
const identifier = 'claim-cvc:Vaccination.records-v1';
const value = [{
vaccinationId: 'vid15',
dateOfAdministration: '150000001',
name: 'Pfizer',
manufacturer: {
name: 'Pfizer',
code: {
name: 'codeName',
code: 'codeCode',
codeSystem: 'codeCodeSystem',
codeSystemName: 'codeCodeSystemName',
},
},
detail: {
createdAt: {
day: 2,
month: 2,
year: 1945,
},
updatedAt: {
day: 2,
month: 2,
year: 1945,
},
},
organization: {
name: 'CVS',
},
codes: [
{
name: 'codeName1',
code: 'codeCode1',
codeSystem: 'codeCodeSystem1',
codeSystemName: 'codeCodeSystemName1',
},
{
name: 'codeName2',
code: 'codeCode2',
codeSystem: 'codeCodeSystem3',
codeSystemName: 'codeCodeSystemName3',
},
],
},
{
vaccinationId: 'vid12',
dateOfAdministration: '150000002',
name: 'Pfizer',
organization: {
name: 'CVS',
},
},
];
const claim = new Claim(identifier, value);
expect(claim).toBeDefined();
expect(claim.getAttestableValue());
expect(claim.getAttestableValues());
});

test('Construct Tests.Records successfully', () => {
const identifier = 'claim-cvc:Test.records-v1';
const value = [
{
testId: 'tid99',
testDate: '150000008',
resultDate: '150000010',
type: 'testType',
result: 'negative',
codes: [
{
name: 'codeName21',
code: 'codeCode21',
codeSystem: 'codeCodeSystem21',
codeSystemName: 'codeCodeSystemName21',
},
{
name: 'codeName22',
code: 'codeCode22',
codeSystem: 'codeCodeSystem23',
codeSystemName: 'codeCodeSystemName23',
},
],
},
{
testId: 'tid95',
testDate: '150000028',
resultDate: '150000020',
type: 'testType',
result: 'negative',
},
];
const claim = new Claim(identifier, value);
expect(claim).toBeDefined();
expect(claim.getAttestableValue());
expect(claim.getAttestableValues());
});

test('Construct Patient successfully', () => {
const identifier = 'claim-cvc:Type.patient-v1';
const value = {
fullName: 'Patient Name',
dateOfBirth: {
day: 2,
month: 2,
year: 1945,
},
};
const claim = new Claim(identifier, value);
expect(claim).toBeDefined();
expect(claim.getAttestableValue());
expect(claim.getAttestableValues());
});

test('Construct by NameGivenNames must result successfully', () => {
const v = new Claim.NameGivenNames('Joao');
expect(v).toBeDefined();
expect(v.value).toBe('Joao');
});

test('Construct IdentityName must result successfuly', () => {
test('Construct IdentityName must result successfully', () => {
const value = { givenNames: 'Joao', otherNames: 'Barbosa', familyNames: 'Santos' };
const v = new Claim.IdentityName(value);
expect(v).toBeDefined();
Expand Down
105 changes: 104 additions & 1 deletion __test__/creds/VerifiableCredential.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,109 @@ describe('Unit tests for Verifiable Credentials', () => {
expect(credential).toBeDefined();
});

it('Should create and verify a credential with an array of clains ', () => {
const covidDetails = {
patient: {
fullName: 'Patient Name',
dateOfBirth: {
day: 2,
month: 2,
year: 1945,
},
},
vaccinations: [
{
vaccinationId: 'vID-123',
dateOfAdministration: '150000001',
name: 'Pfizer',
manufacturer: {
name: 'Pfizer',
code: {
name: 'codeName',
code: 'codeCode',
codeSystem: 'codeCodeSystem',
codeSystemName: 'codeCodeSystemName',
},
},
detail: {
createdAt: {
day: 2,
month: 2,
year: 1945,
},
updatedAt: {
day: 2,
month: 2,
year: 1945,
},
},
organization: {
name: 'CVS',
},
codes: [
{
name: 'codeName1',
code: 'codeCode1',
codeSystem: 'codeCodeSystem1',
codeSystemName: 'codeCodeSystemName1',
},
{
name: 'codeName2',
code: 'codeCode2',
codeSystem: 'codeCodeSystem3',
codeSystemName: 'codeCodeSystemName3',
},
],
},
{
vaccinationId: 'vID-124',
dateOfAdministration: '150000002',
name: 'Pfizer',
organization: {
name: 'CVS',
},
},
],
tests: [
{
testId: 'tID-23',
testDate: '150000008',
resultDate: '150000010',
type: 'testType',
result: 'negative',
codes: [
{
name: 'codeName21',
code: 'codeCode21',
codeSystem: 'codeCodeSystem21',
codeSystemName: 'codeCodeSystemName21',
},
{
name: 'codeName22',
code: 'codeCode22',
codeSystem: 'codeCodeSystem23',
codeSystemName: 'codeCodeSystemName23',
},
],
},
{
testId: 'tID-25',
testDate: '150000028',
resultDate: '150000020',
type: 'testType',
result: 'negative',
},
],
};
const covidClaim = new Claim('claim-cvc:Medical.covid19-v1', covidDetails);

const credential = new VC(
'credential-cvc:Covid19-v1', '', null, [covidClaim], '1',
);
expect(credential).toBeDefined();
expect(credential.verifyProofs()).toBeTruthy();
});

it('Should filter claims for GenericDocumentId asking for cvc:Document:Type and return only that claim', () => {
const typeValue = 'passport';
const type = new Claim('claim-cvc:Document.type-v1', typeValue, '1');
Expand Down Expand Up @@ -1362,7 +1465,7 @@ describe('Unit tests for Verifiable Credentials', () => {
));
const ucaJson = SchemaGenerator.buildSampleJson(ucaDefinition);
let value = ucaJson;
if (Object.keys(ucaJson).length === 1) {
if (Object.keys(ucaJson).length === 1 && ucaDefinition.type !== 'Array') {
[value] = Object.values(ucaJson);
}
const dependentUca = new Claim(ucaDefinition.identifier, value, ucaDefinition.version);
Expand Down
2 changes: 1 addition & 1 deletion __test__/creds/VerifiableCredentialSchema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('VerifiableCredentials SchemaGenerator validation', () => {
));
const ucaJson = SchemaGenerator.buildSampleJson(ucaDefinition);
let value = ucaJson;
if (Object.keys(ucaJson).length === 1) {
if (Object.keys(ucaJson).length === 1 && ucaDefinition.type !== 'Array') {
[value] = Object.values(ucaJson);
}
const dependentUca = new Claim(ucaDefinition.identifier, value, ucaDefinition.version);
Expand Down
35 changes: 7 additions & 28 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.1.1",
"version": "1.1.2",
"author": "Identity.com Community",
"license": "MIT",
"description": "Verifiable Credential and Attestation Library",
Expand Down Expand Up @@ -61,7 +61,7 @@
"rimraf": "^3.0.2"
},
"dependencies": {
"@identity.com/uca": "^1.0.16",
"@identity.com/uca": "^1.0.19",
"ajv": "^7.0.3",
"babel-runtime": "^6.26.0",
"bitcoinjs-lib": "git+https://github.com/dabura667/bitcoinjs-lib.git#bcash330",
Expand Down
Loading

0 comments on commit caa0ed9

Please sign in to comment.