All files / src/parsers parseV2.ts

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

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              27x 27x 27x   27x 27x 27x 27x 27x 27x 26x   26x                                  
import domain from '../domain';
import getSignatureImages from './helpers/getSignatureImage';
import type { BlockcertsV2 } from '../models/BlockcertsV2';
import type { ParsedCertificate } from './index';
import type { Issuer } from '../models/Issuer';
 
export default async function parseV2 (certificateJson: BlockcertsV2): Promise<ParsedCertificate> {
  const { id, expires, badge } = certificateJson;
  const { image: certificateImage, name, description, subtitle, issuer: issuerProfileUrl } = badge;
  const recipientProfile = certificateJson.recipientProfile ?? certificateJson.recipient.recipientProfile;
 
  const issuedOn = certificateJson.issuedOn;
  const metadataJson = certificateJson.metadataJson;
  const recipientFullName = recipientProfile.name;
  const revocationKey = null;
  const signatureImage = getSignatureImages(badge.signatureLines);
  const issuer: Issuer = await domain.verifier.getIssuerProfile(issuerProfileUrl);
  const sealImage = issuer.image;
 
  return {
    certificateImage,
    description,
    expires,
    id,
    issuedOn,
    issuer,
    metadataJson,
    name,
    recipientFullName,
    recordLink: id,
    revocationKey,
    sealImage,
    signatureImage,
    subtitle
  };
}