Skip to content

Commit

Permalink
feat(Verification): add VC check when parsing document
Browse files Browse the repository at this point in the history
  • Loading branch information
lemoustachiste committed Nov 13, 2024
1 parent 63805b2 commit c7ab064
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/domain/verifier/useCases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import getVerificationMap from './getVerificationMap';
import lookForTx from './lookForTx';
import parseIssuerKeys from './parseIssuerKeys';
import parseRevocationKey from './parseRevocationKey';
import validateVerifiableCredential from './validateVerifiableCredential';

export {
convertToVerificationSubsteps,
Expand All @@ -17,5 +18,6 @@ export {
getVerificationMap,
lookForTx,
parseIssuerKeys,
parseRevocationKey
parseRevocationKey,
validateVerifiableCredential
};
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export default function validateVerifiableCredential (credential: BlockcertsV3):
validateDateRFC3339StringFormat(credential.validFrom, 'validFrom');
}
if (credential.validUntil) {
validateDateRFC3339StringFormat(credential.validUntil, 'validUntil')
validateDateRFC3339StringFormat(credential.validUntil, 'validUntil');
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/parsers/parseV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export default async function parseV3 (certificateJson: BlockcertsV3, locale: st
description,
credentialSubject
} = certificateJson;
try {
domain.verifier.validateVerifiableCredential(certificateJson);
} catch (error) {
throw new Error(`Document presented is not a valid Verifiable Credential: ${error.message}`);
}
let { validFrom } = certificateJson;
const certificateMetadata = metadata ?? metadataJson;
const issuer: Issuer = await domain.verifier.getIssuerProfile(issuerProfileUrl);
Expand Down
10 changes: 10 additions & 0 deletions test/application/parsers/parser-v3.0.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ describe('Parser v3 test suite', function () {
const parsedCertificate = await parseJSON(fixtureCopy);
expect(parsedCertificate.isFormatValid).toBe(false);
});

describe('when the certificate is not a valid Verifiable Credential', function () {
it('should throw an error', async function () {
const fixtureCopy = JSON.parse(JSON.stringify(fixture));
fixtureCopy.issuanceDate = '2022-05-22';
const parsedCertificate = await parseJSON(fixtureCopy);
expect(parsedCertificate.isFormatValid).toBe(false);
expect(parsedCertificate.error).toBe('Document presented is not a valid Verifiable Credential: issuanceDate must be a valid RFC3339 string. Received: `2022-05-22`');
});
});
});

describe('given it is called with valid v3 certificate data', function () {
Expand Down

0 comments on commit c7ab064

Please sign in to comment.