diff --git a/src/components/renderer/SvgV2Adapter.tsx b/src/components/renderer/SvgV2Adapter.tsx index d167200..a8dea27 100644 --- a/src/components/renderer/SvgV2Adapter.tsx +++ b/src/components/renderer/SvgV2Adapter.tsx @@ -1,12 +1,13 @@ import React from "react"; -import { SvgRenderer, SvgRendererProps, v4OpenAttestationDocument } from "./SvgRenderer"; -import type { v2 } from "@govtechsg/open-attestation"; +import { SvgRenderer, SvgRendererProps } from "./SvgRenderer"; +import type { v2, v4 } from "@govtechsg/open-attestation"; type V2OpenAttestationDocumentWithSvgBase = v2.OpenAttestationDocument & Pick; -type V2OpenAttestationDocumentWithSvg = V2OpenAttestationDocumentWithSvgBase & { [k: string]: unknown }; +export type V2OpenAttestationDocumentWithSvg = V2OpenAttestationDocumentWithSvgBase & { [k: string]: unknown }; +type V2OpenAttestationDocumentWithSvgNoAttachments = Omit; -const mapV2toV4 = (document: V2OpenAttestationDocumentWithSvg): v4OpenAttestationDocument => { +const mapV2toV4 = (document: V2OpenAttestationDocumentWithSvg): v4.OpenAttestationDocument => { const clonedDocument = { ...document }; const propsToOmit: (keyof V2OpenAttestationDocumentWithSvgBase)[] = [ "$template", @@ -14,23 +15,29 @@ const mapV2toV4 = (document: V2OpenAttestationDocumentWithSvg): v4OpenAttestatio "issuers", "network", "renderMethod", + "attachments", ]; propsToOmit.forEach((v2Property) => delete clonedDocument[v2Property]); return { + "@context": [ + "https://www.w3.org/ns/credentials/v2", + "https://schemata.openattestation.com/com/openattestation/4.0/alpha-context.json", + ], + type: ["VerifiableCredential", "OpenAttestationCredential"], issuer: { id: document.issuers[0].id || "issuers[0].id not found", identityProof: { identifier: document.issuers[0].identityProof?.location || "issuers[0].identityProof.location not found", identityProofType: document.issuers[0].identityProof?.type || - ("DNS-DID" as v4OpenAttestationDocument["issuer"]["identityProof"]["identityProofType"]), + ("DNS-DID" as v4.OpenAttestationDocument["issuer"]["identityProof"]["identityProofType"]), }, name: document.issuers[0].name, type: "OpenAttestationIssuer", }, renderMethod: document.renderMethod, - credentialSubject: clonedDocument, + credentialSubject: clonedDocument as V2OpenAttestationDocumentWithSvgNoAttachments, // Need to cast due to mismatch in "attachments" typing }; }; diff --git a/src/components/renderer/fixtures/svgRendererSamples.ts b/src/components/renderer/fixtures/svgRendererSamples.ts index a574422..1dde7ef 100644 --- a/src/components/renderer/fixtures/svgRendererSamples.ts +++ b/src/components/renderer/fixtures/svgRendererSamples.ts @@ -1,5 +1,5 @@ -import { v2 } from "@govtechsg/open-attestation"; -import type { v4 } from "@govtechsg/open-attestation"; +import { v2, v4 } from "@govtechsg/open-attestation"; +import { V2OpenAttestationDocumentWithSvg } from "../SvgV2Adapter"; export const v4WithSvgUrlAndDigestMultibase: v4.OpenAttestationDocument = { "@context": [ @@ -171,7 +171,7 @@ export const v4MalformedEmbeddedSvg: v4.OpenAttestationDocument = { }, }; -export const v2WithSvgUrlAndDigestMultibase = { +export const v2WithSvgUrlAndDigestMultibase: V2OpenAttestationDocumentWithSvg = { issuers: [ { id: "did:ethr:0xB26B4941941C51a4885E5B7D3A1B861E54405f90",