Skip to content

Commit

Permalink
fix: build
Browse files Browse the repository at this point in the history
  • Loading branch information
yapyuyou committed May 17, 2024
1 parent ffe7880 commit 902fe68
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
19 changes: 13 additions & 6 deletions src/components/renderer/SvgV2Adapter.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@
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<SvgRendererProps["document"], "renderMethod">;
type V2OpenAttestationDocumentWithSvg = V2OpenAttestationDocumentWithSvgBase & { [k: string]: unknown };
export type V2OpenAttestationDocumentWithSvg = V2OpenAttestationDocumentWithSvgBase & { [k: string]: unknown };
type V2OpenAttestationDocumentWithSvgNoAttachments = Omit<V2OpenAttestationDocumentWithSvg, "attachments">;

const mapV2toV4 = (document: V2OpenAttestationDocumentWithSvg): v4OpenAttestationDocument => {
const mapV2toV4 = (document: V2OpenAttestationDocumentWithSvg): v4.OpenAttestationDocument => {
const clonedDocument = { ...document };
const propsToOmit: (keyof V2OpenAttestationDocumentWithSvgBase)[] = [
"$template",
"id",
"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
};
};

Expand Down
6 changes: 3 additions & 3 deletions src/components/renderer/fixtures/svgRendererSamples.ts
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down Expand Up @@ -171,7 +171,7 @@ export const v4MalformedEmbeddedSvg: v4.OpenAttestationDocument = {
},
};

export const v2WithSvgUrlAndDigestMultibase = {
export const v2WithSvgUrlAndDigestMultibase: V2OpenAttestationDocumentWithSvg = {
issuers: [
{
id: "did:ethr:0xB26B4941941C51a4885E5B7D3A1B861E54405f90",
Expand Down

0 comments on commit 902fe68

Please sign in to comment.