Skip to content

Commit

Permalink
Merge pull request #22 from blockchain-certificates/feat/verifiable-p…
Browse files Browse the repository at this point in the history
…resentation

Feat/verifiable presentation
  • Loading branch information
lemoustachiste authored Nov 28, 2024
2 parents 5e08ce4 + d1796a8 commit 473a51d
Show file tree
Hide file tree
Showing 14 changed files with 602 additions and 40 deletions.
77 changes: 40 additions & 37 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"homepage": "https://github.com/blockchain-certificates/cvjs-docker#readme",
"dependencies": {
"@blockcerts/cert-verifier-js": "^6.14.1",
"@blockcerts/cert-verifier-js": "^6.22.1",
"body-parser": "^1.20.2",
"express": "^4.18.2"
},
Expand Down
3 changes: 3 additions & 0 deletions src/middlewares/verbose-verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ export default async function verboseVerification (req: Request<{}, {}, APIPaylo

if (status === VERIFICATION_STATUSES.FAILURE) {
console.error(`The certificate ${req.body.verifiableCredential.id} is not valid. Error: ${message}`);
if (errors.length === 0) {
errors.push('credentialVerification: ' + message);
}
}
res.json(createResponseBody(req, status, message, verificationSteps, certificate, checks, errors));
}).catch(err => {
Expand Down
4 changes: 2 additions & 2 deletions src/models/APIPayload.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Blockcerts, CertificateOptions } from '@blockcerts/cert-verifier-js';
import type { Blockcerts, CertificateOptions, VerifiableCredential } from '@blockcerts/cert-verifier-js';

interface APIPayloadOptions extends CertificateOptions {
returnCredential?: boolean;
}

export interface APIPayload {
verifiableCredential: Blockcerts;
verifiableCredential: VerifiableCredential | Blockcerts;
options?: APIPayloadOptions;
}
7 changes: 7 additions & 0 deletions test/assertions/failing-signature-cert-verified-steps.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@
"parentStep": "statusCheck",
"status": "standby"
},
{
"code": "ensureValidityPeriodStarted",
"label": "Verify Validity Start Date",
"labelPending": "Verifying Validity Start Date",
"parentStep": "statusCheck",
"status": "standby"
},
{
"code": "checkExpiresDate",
"label": "Check Expiration Date",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"code": "formatValidation", "isLast": false, "label": "Format validation", "labelPending": "Validating format", "status": "success", "subSteps": [{"code": "validateDateFormat", "label": "Validating date format", "parentStep": "formatValidation", "status": "success"}]}, {"code": "proofVerification", "isLast": false, "label": "Proof Verification", "labelPending": "Verifying Proof", "status": "success", "subSteps": [], "suites": [{"proofType": "MerkleProof2019", "subSteps": [{"code": "computeLocalHash", "label": "Computing local hash", "parentStep": "proofVerification", "status": "success"}, {"code": "compareHashes", "label": "Comparing hashes", "parentStep": "proofVerification", "status": "success"}, {"code": "checkReceipt", "label": "Checking Receipt", "parentStep": "proofVerification", "status": "success"}]}]}, {"code": "statusCheck", "isLast": true, "label": "Status check", "labelPending": "Checking record status", "status": "success", "subSteps": [{"code": "checkRevokedStatus", "label": "Checking Revoked Status", "parentStep": "statusCheck", "status": "success"}, {"code": "checkExpiresDate", "label": "Checking Expiration Date", "parentStep": "statusCheck", "status": "success"}]}]
6 changes: 6 additions & 0 deletions test/assertions/multiple-signature-cert-verified-steps.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@
"parentStep": "statusCheck",
"label": "Checking Revoked Status"
},
{
"code": "ensureValidityPeriodStarted",
"label": "Verifying Validity Start Date",
"parentStep": "statusCheck",
"status": "success"
},
{
"code": "checkExpiresDate",
"status": "success",
Expand Down
6 changes: 6 additions & 0 deletions test/assertions/single-signature-cert-verified-steps.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
"parentStep": "statusCheck",
"status": "success"
},
{
"code": "ensureValidityPeriodStarted",
"label": "Verifying Validity Start Date",
"parentStep": "statusCheck",
"status": "success"
},
{
"code": "checkExpiresDate",
"label": "Checking Expiration Date",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"code": "formatValidation", "isLast": false, "label": "Format validation", "labelPending": "Validating format", "status": "success", "subSteps": [{"code": "validateDateFormat", "label": "Validating date format", "parentStep": "formatValidation", "status": "success"}]}, {"code": "proofVerification", "isLast": false, "label": "Proof Verification", "labelPending": "Verifying Proof", "status": "success", "subSteps": [], "suites": [{"proofType": "MerkleProof2019", "subSteps": [{"code": "computeLocalHash", "label": "Computing local hash", "parentStep": "proofVerification", "status": "success"}, {"code": "compareHashes", "label": "Comparing hashes", "parentStep": "proofVerification", "status": "success"}, {"code": "checkReceipt", "label": "Checking Receipt", "parentStep": "proofVerification", "status": "success"}]}]}, {"code": "statusCheck", "isLast": true, "label": "Status check", "labelPending": "Checking record status", "status": "success", "subSteps": [{"code": "checkRevokedStatus", "label": "Checking Revoked Status", "parentStep": "statusCheck", "status": "success"}, {"code": "checkExpiresDate", "label": "Checking Expiration Date", "parentStep": "statusCheck", "status": "success"}]}]
64 changes: 64 additions & 0 deletions test/contract/basic-verification.test.docker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import fetch from 'node-fetch-commonjs';
import singleSignatureCert from '../fixtures/single-signature-cert.json';
import failingSignatureCert from '../fixtures/failing-signature-cert.json';
import verifiablePresentationFixture from '../fixtures/mocknet-verifiable-presentation.json';
import failingVerifiablePresentationFixture from '../fixtures/mocknet-verifiable-presentation-failing-credential.json';
import type { APIPayload } from '../../src/models/APIPayload';

describe('basic verification docker endpoint test suite', function () {
Expand All @@ -27,6 +29,7 @@ describe('basic verification docker endpoint test suite', function () {
"checkAuthenticity",
"checkRevokedStatus",
"checkExpiresDate",
"ensureValidityPeriodStarted"
],
errors: [],
id: 'urn:uuid:bbba8553-8ec1-445f-82c9-a57251dd731c',
Expand Down Expand Up @@ -64,4 +67,65 @@ describe('basic verification docker endpoint test suite', function () {
});
});
});

describe('when the certificate is a verifiable presentation', function () {
describe('and it is valid', function () {
it('should return the expected payload', async function () {
const output = await fetch('http://localhost:9000/credentials/verify', {
body: JSON.stringify({
verifiableCredential: verifiablePresentationFixture as any
} as APIPayload),
method: 'POST',
headers: { 'Content-Type': 'application/json' }
}).then((res) => res.json());

expect(output).toEqual({
checks: [
"computeLocalHash",
"compareHashes",
"checkReceipt",
"checkRevokedStatus",
"checkExpiresDate",
"validateDateFormat"
],
errors: [],
id: 'urn:uuid:bbba9667-8ec1-445f-82c9-a57251dd731c',
status: 'success',
message: {
description: 'Mocknet credentials are used for test purposes only. They are not recorded on a blockchain, and they should not be considered verified Blockcerts.',
label: 'This Mocknet credential passed all checks',
}
});
});
});
});

describe('when the certificate is a verifiable presentation', function () {
describe('and it is not valid', function () {
it('should return the expected payload', async function () {
const output = await fetch('http://localhost:9000/credentials/verify', {
body: JSON.stringify({
verifiableCredential: failingVerifiablePresentationFixture as any
} as APIPayload),
method: 'POST',
headers: { 'Content-Type': 'application/json' }
}).then((res) => res.json());

expect(output).toEqual({
checks: [
"computeLocalHash",
"compareHashes",
"checkReceipt",
"checkRevokedStatus",
"checkExpiresDate",
"validateDateFormat"
],
errors: [],
id: 'urn:uuid:bbba9667-8ec1-445f-82c9-a57251dd731c',
status: 'failure',
message: 'Credential with id urn:uuid:4f5f0100-ccbf-4ca9-9cfc-4f5fc3052d28 failed verification. Error: This certificate does not conform with the provided credential schema'
});
});
});
});
});
1 change: 1 addition & 0 deletions test/contract/verbose-verification.test.docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ describe('verbose verification docker endpoint test suite', function () {
"checkAuthenticity",
"checkRevokedStatus",
"checkExpiresDate",
"ensureValidityPeriodStarted"
]);
});

Expand Down
Loading

0 comments on commit 473a51d

Please sign in to comment.