All files / src/domain/verifier/useCases getVerificationMap.ts

100% Statements 20/20
100% Branches 10/10
100% Functions 4/4
100% Lines 18/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88                                                        133x     93x       131x       55x       120x       91x       92x     532x   133x       532x 1064x   532x 482x         133x 133x 532x                   133x 133x          
import getParentVerificationSteps, {
  SUB_STEPS,
  verificationMap,
  VerificationSteps
} from '../entities/verificationSteps'; // TODO: circular dependency
import domain from '../../index';
import { removeEntry } from '../../../helpers/array';
import type VerificationSubstep from '../valueObjects/VerificationSubstep';
import type { IVerificationMapItem } from '../../../models/VerificationMap';
 
export interface VerificationMapFilters {
  hasDid?: boolean;
  hasHashlinks?: boolean;
  hasValidFrom?: boolean;
  hasCredentialSchema?: boolean;
  isVCV2?: boolean;
  isVerifiablePresentation?: boolean;
  isIssuerProfileSigned?: boolean;
}
export function getVerificationStepsForCurrentCase ({
  hasDid = false,
  hasHashlinks = false,
  hasValidFrom = false,
  hasCredentialSchema = false,
  isVCV2 = false,
  isVerifiablePresentation = false,
  isIssuerProfileSigned = false
}: VerificationMapFilters): SUB_STEPS[] {
  const baseMap = JSON.parse(JSON.stringify(verificationMap));
 
  if (!hasDid) {
    removeEntry(baseMap[VerificationSteps.identityVerification], SUB_STEPS.controlVerificationMethod);
  }
 
  if (!hasHashlinks) {
    removeEntry(baseMap[VerificationSteps.formatValidation], SUB_STEPS.checkImagesIntegrity);
  }
 
  if (!hasValidFrom || isVerifiablePresentation) {
    removeEntry(baseMap[VerificationSteps.statusCheck], SUB_STEPS.ensureValidityPeriodStarted);
  }
 
  if (!hasCredentialSchema) {
    removeEntry(baseMap[VerificationSteps.formatValidation], SUB_STEPS.checkCredentialSchemaConformity);
  }
 
  if (!isVCV2) {
    removeEntry(baseMap[VerificationSteps.formatValidation], SUB_STEPS.validateDateFormat);
  }
 
  if (!isIssuerProfileSigned) {
    removeEntry(baseMap[VerificationSteps.identityVerification], SUB_STEPS.verifyIssuerProfile);
  }
 
  const verificationSteps = Object.keys(baseMap).map(parentStep => baseMap[parentStep]).flat();
 
  return verificationSteps;
}
 
function filterSubStepsForParentStep (parentStepKey: VerificationSteps, substepsList: SUB_STEPS[]): VerificationSubstep[] {
  const childSteps: SUB_STEPS[] = verificationMap[parentStepKey];
  const filteredChildSteps: SUB_STEPS[] = childSteps.filter(childStep => substepsList.includes(childStep));
 
  return filteredChildSteps.map(childStepKey =>
    domain.verifier.convertToVerificationSubsteps(parentStepKey, childStepKey)
  );
}
 
function getFullStepsWithSubSteps (verificationSubStepsList: SUB_STEPS[]): IVerificationMapItem[] {
  const steps = getParentVerificationSteps();
  return Object.keys(steps)
    .map(parentStepKey => ({
      ...steps[parentStepKey],
      subSteps: filterSubStepsForParentStep((parentStepKey as VerificationSteps), verificationSubStepsList)
    }));
}
 
export default function getVerificationMap (filters: VerificationMapFilters = {}): {
  verificationMap: IVerificationMapItem[];
  verificationProcess: SUB_STEPS[];
} {
  const verificationProcess: SUB_STEPS[] = getVerificationStepsForCurrentCase(filters);
  return {
    verificationProcess,
    verificationMap: getFullStepsWithSubSteps(verificationProcess)
  };
}