Skip to content

Commit

Permalink
Merge pull request #1398 from blockchain-certificates/feat/hashlink-v…
Browse files Browse the repository at this point in the history
…erify-when-needed

feat(Verification): only add checkImagesIntegrity verification step when necessary
  • Loading branch information
lemoustachiste authored Jul 13, 2022
2 parents 00ec45f + 8d39e8e commit 631dc1d
Show file tree
Hide file tree
Showing 15 changed files with 172 additions and 172 deletions.
14 changes: 7 additions & 7 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 @@ -56,7 +56,7 @@
"@babel/runtime": "^7.11.2",
"@babel/runtime-corejs3": "^7.8.7",
"@blockcerts/explorer-lookup": "^1.2.1",
"@blockcerts/hashlink-verifier": "^1.2.1",
"@blockcerts/hashlink-verifier": "^1.3.0",
"@blockcerts/schemas": "^3.0.5",
"@decentralized-identity/did-common-typescript": "^0.1.19",
"@digitalbazaar/did-method-key": "github:lemoustachiste/did-method-key#convert-to-module",
Expand Down
10 changes: 7 additions & 3 deletions src/domain/certificates/useCases/getVerificationMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import { removeEntry } from '../../../helpers/array';
import type VerificationSubstep from '../../verifier/valueObjects/VerificationSubstep';
import type { IVerificationMapItem } from '../../../models/VerificationMap';

export function getVerificationStepsForCurrentCase (hasDid: boolean): SUB_STEPS[] {
export function getVerificationStepsForCurrentCase (hasDid: boolean, hasHashlinks: boolean): SUB_STEPS[] {
const verificationSteps = Object.values(SUB_STEPS);

if (!hasDid) {
removeEntry(verificationSteps, SUB_STEPS.controlVerificationMethod);
}

if (!hasHashlinks) {
removeEntry(verificationSteps, SUB_STEPS.checkImagesIntegrity);
}

return verificationSteps;
}

Expand Down Expand Up @@ -47,11 +51,11 @@ function getFullStepsWithSubSteps (verificationSubStepsList: SUB_STEPS[]): IVeri
}

// TODO: move this method to domain.verifier
export default function getVerificationMap (hasDid: boolean = false): {
export default function getVerificationMap (hasDid: boolean = false, hasHashlinks: boolean = false): {
verificationMap: IVerificationMapItem[];
verificationProcess: SUB_STEPS[];
} {
const verificationProcess: SUB_STEPS[] = getVerificationStepsForCurrentCase(hasDid);
const verificationProcess: SUB_STEPS[] = getVerificationStepsForCurrentCase(hasDid, hasHashlinks);
return {
verificationProcess,
verificationMap: getFullStepsWithSubSteps(verificationProcess)
Expand Down
5 changes: 4 additions & 1 deletion src/verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ export default class Verifier {
}

private prepareVerificationProcess (): void {
const verificationModel = domain.certificates.getVerificationMap(!!this.issuer.didDocument);
const verificationModel = domain.certificates.getVerificationMap(
!!this.issuer.didDocument,
this.hashlinkVerifier.hasHashlinksToVerify()
);
this.verificationSteps = verificationModel.verificationMap;
this.verificationProcess = verificationModel.verificationProcess;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@ const mainnetStepMapAssertion: IVerificationMapItem[] = [
code: VerificationSteps.formatValidation,
label: defaultLanguageSet.steps.formatValidationLabel,
labelPending: defaultLanguageSet.steps.formatValidationLabelPending,
subSteps: [
{
code: SUB_STEPS.checkImagesIntegrity,
label: defaultLanguageSet.subSteps.checkImagesIntegrityLabel,
labelPending: defaultLanguageSet.subSteps.checkImagesIntegrityLabelPending,
parentStep: VerificationSteps.formatValidation,
status: VERIFICATION_STATUSES.DEFAULT
}
]
subSteps: []
},
{
code: VerificationSteps.proofVerification,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import domain from '../../../../../src/domain';
import mocknetMapAssertion from './assertions/mocknetMapAssertion';
import mainnetMapAssertion from './assertions/mainnetMapAssertion';
import verificationMapAssertion from './assertions/verificationMapAssertion';
import { SUB_STEPS, VerificationSteps } from '../../../../../src/constants/verificationSteps';
import i18n from '../../../../../src/data/i18n.json';
import currentLocale from '../../../../../src/constants/currentLocale';
Expand All @@ -10,31 +9,16 @@ import { VERIFICATION_STATUSES } from '../../../../../src';
const defaultLanguageSet = i18n[currentLocale.locale];

describe('domain certificates get verification map use case test suite', function () {
describe('given it is called with the mocknet chain', function () {
it('should return a mocknet verification map', function () {
describe('given it is called', function () {
it('should return a verification map', function () {
const result: IVerificationMapItem[] = domain.certificates.getVerificationMap().verificationMap;
expect(result).toEqual(mocknetMapAssertion);
});
});

describe('given it is called with the bitcoin chain', function () {
it('should return a mainnet verification map', function () {
const result: IVerificationMapItem[] = domain.certificates.getVerificationMap().verificationMap;
expect(result).toEqual(mainnetMapAssertion);
});

describe('and the blockcerts version is v3', function () {
it('should return a mainnet verification map without the getIssuerProfile step', function () {
const result: IVerificationMapItem[] = domain.certificates.getVerificationMap().verificationMap;
const expectedOutput: IVerificationMapItem[] = JSON.parse(JSON.stringify(mainnetMapAssertion));
expect(result).toEqual(expectedOutput);
});
expect(result).toEqual(verificationMapAssertion);
});

describe('and the blockcerts issuer shared their DID', function () {
it('should add the identityVerification step', function () {
const result: IVerificationMapItem[] = domain.certificates.getVerificationMap(true).verificationMap;
const expectedOutput: IVerificationMapItem[] = JSON.parse(JSON.stringify(mainnetMapAssertion));
const expectedOutput: IVerificationMapItem[] = JSON.parse(JSON.stringify(verificationMapAssertion));

// add because did
expectedOutput.find(step => step.code === VerificationSteps.identityVerification).subSteps = [
Expand All @@ -50,5 +34,26 @@ describe('domain certificates get verification map use case test suite', functio
expect(result).toEqual(expectedOutput);
});
});

describe('and the certificate has hashlinks', function () {
it('should add the checkImageIntegrity step', function () {
const result: IVerificationMapItem[] = domain.certificates
.getVerificationMap(false, true).verificationMap;
const expectedOutput: IVerificationMapItem[] = JSON.parse(JSON.stringify(verificationMapAssertion));

// add because did
expectedOutput.find(step => step.code === VerificationSteps.formatValidation).subSteps = [
{
code: SUB_STEPS.checkImagesIntegrity,
label: defaultLanguageSet.subSteps.checkImagesIntegrityLabel,
labelPending: defaultLanguageSet.subSteps.checkImagesIntegrityLabelPending,
parentStep: VerificationSteps.formatValidation,
status: VERIFICATION_STATUSES.DEFAULT
}
];

expect(result).toEqual(expectedOutput);
});
});
});
});
7 changes: 3 additions & 4 deletions test/application/verifier/verifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('Verifier entity test suite', function () {

describe('when the issuer profile URN is a DID', function () {
it('should add the issuer identity verification to the verification steps', async function () {
const fixture = JSON.parse(JSON.stringify(verifierParamFixture));
const fixture = deepCopy<any>(verifierParamFixture);
fixture.certificateJson = FIXTURES.BlockcertsV3;
fixture.issuer = {
...issuerProfileAssertion,
Expand All @@ -113,7 +113,7 @@ describe('Verifier entity test suite', function () {
const verifierInstance = new Verifier(fixture);
const expectedStepIndex = verifierInstance.verificationSteps
.findIndex(parentStep => parentStep.code === VerificationSteps.identityVerification);
expect(expectedStepIndex).toBe(2);
expect(expectedStepIndex).toBe(1);
});
});
});
Expand Down Expand Up @@ -143,11 +143,10 @@ describe('Verifier entity test suite', function () {
});

describe('verificationProcess property', function () {
describe('when the process is for a mainnet v2 certs with no DID', function () {
describe('when the process is for a mainnet v2 certs with no DID and no hashlinks', function () {
it('should be set accordingly', function () {
verifierInstance = new Verifier(verifierParamFixture);
const expectedOutput = [
SUB_STEPS.checkImagesIntegrity,
SUB_STEPS.checkRevokedStatus,
SUB_STEPS.checkExpiresDate
];
Expand Down
14 changes: 0 additions & 14 deletions test/assertions/verification-steps-v2-mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@ import { VERIFICATION_STATUSES } from '../../src';
const defaultLanguageSet = i18n[currentLocale.locale];

export default [
{
code: VerificationSteps.formatValidation,
label: defaultLanguageSet.steps.formatValidationLabel,
labelPending: defaultLanguageSet.steps.formatValidationLabelPending,
subSteps: [
{
code: SUB_STEPS.checkImagesIntegrity,
label: defaultLanguageSet.subSteps.checkImagesIntegrityLabel,
labelPending: defaultLanguageSet.subSteps.checkImagesIntegrityLabelPending,
parentStep: VerificationSteps.formatValidation,
status: VERIFICATION_STATUSES.DEFAULT
}
]
},
{
code: VerificationSteps.proofVerification,
label: defaultLanguageSet.steps.signatureVerificationLabel,
Expand Down
14 changes: 0 additions & 14 deletions test/assertions/verification-steps-v2-regtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@ import { VERIFICATION_STATUSES } from '../../src';
const defaultLanguageSet = i18n[currentLocale.locale];

export default [
{
code: VerificationSteps.formatValidation,
label: defaultLanguageSet.steps.formatValidationLabel,
labelPending: defaultLanguageSet.steps.formatValidationLabelPending,
subSteps: [
{
code: SUB_STEPS.checkImagesIntegrity,
label: defaultLanguageSet.subSteps.checkImagesIntegrityLabel,
labelPending: defaultLanguageSet.subSteps.checkImagesIntegrityLabelPending,
parentStep: VerificationSteps.formatValidation,
status: VERIFICATION_STATUSES.DEFAULT
}
]
},
{
code: VerificationSteps.proofVerification,
label: defaultLanguageSet.steps.signatureVerificationLabel,
Expand Down
Loading

0 comments on commit 631dc1d

Please sign in to comment.