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

100% Statements 9/9
100% Branches 2/2
100% Functions 0/0
100% Lines 9/9

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              108x       1x     51x     48x       51x 50x 11x   40x 40x      
import { request } from '@blockcerts/explorer-lookup';
import { VerifierError } from '../../../models';
import { SUB_STEPS } from '../entities/verificationSteps';
import { getText } from '../../i18n/useCases';
import type { RevocationList, RevokedAssertion } from '../../../models/RevokedAssertions';
import { safelyAppendUrlParameter } from '../../../helpers/url';
 
const ASSERTION_ID_NAME: string = 'assertionId';
 
export default async function getRevokedAssertions (revocationListUrl: string, assertionId?: string): Promise<RevokedAssertion[]> {
  if (!revocationListUrl) {
    return [];
  }
 
  const errorMessage: string = getText('errors', 'getRevokedAssertions');
 
  if (assertionId) {
    revocationListUrl = safelyAppendUrlParameter(revocationListUrl, ASSERTION_ID_NAME, encodeURIComponent(assertionId));
  }
 
  try {
    const response: any = await request({ url: revocationListUrl });
    const issuerRevocationJson: RevocationList = JSON.parse(response);
    return issuerRevocationJson.revokedAssertions ?? [];
  } catch (e) {
    console.error(e);
    throw new VerifierError(SUB_STEPS.checkRevokedStatus, errorMessage);
  }
}