From 0d00247db42832ba592a01e93162b6325e3d5144 Mon Sep 17 00:00:00 2001
From: Damyan Mitev <damyan.mitev@vereign.com>
Date: Fri, 6 Dec 2019 19:07:43 +0200
Subject: [PATCH] add validateVCard

---
 javascript/src/iframe/viamapi-iframe.js | 71 +++++++++++++++++++++++++
 1 file changed, 71 insertions(+)

diff --git a/javascript/src/iframe/viamapi-iframe.js b/javascript/src/iframe/viamapi-iframe.js
index 58b6e00..2c94611 100644
--- a/javascript/src/iframe/viamapi-iframe.js
+++ b/javascript/src/iframe/viamapi-iframe.js
@@ -1575,6 +1575,77 @@ const connection = Penpal.connectToParent({
         messageUUID: messageUUID,
       }, "vCard signed");
     },
+    // vCardImageData = {
+    //   contentType: "image/png",
+    //   contentBase64: base 64 encoded image
+    // };
+    // text, html - the text and html part of the email
+    // related, attachments - array of objects, containing hashes of images/objects, related to the html in format:
+    // {
+    //   headers: {
+    //     "Content-Type": "application/hash; algorithm=SHA-256",
+    //     "Original-Content-Type": "image/jpeg", //original content type
+    //     "Content-Disposition": "inline" or "attachment",
+    //     ... //other headers
+    //   },
+    //   body: "base64 encoded hash"
+    // }
+    validateVCard: async (vCardImageData, text, html, parts = null) => {
+      const authenticationPublicKey = localStorage.getItem(
+        "authenticatedIdentity"
+      );
+
+      if (
+        !authenticationPublicKey ||
+        !window.loadedIdentities[authenticationPublicKey] ||
+        !extendPinCodeTtl(authenticationPublicKey)
+      ) {
+        return encodeResponse("400", "", "Identity not authenticated");
+      }
+
+      //vCardImageData = new ImageData(vCardImageData);
+
+      if (!parts) {
+        parts = [];
+      }
+
+      if (html) {
+        const htmlPart = {
+          headers: {
+            "Content-Type": "text/html"
+          },
+          body: stringToUtf8Base64(html)
+        };
+        parts.unshift(htmlPart);
+      }
+
+      if (text) {
+        const textPart = {
+          headers: {
+            "Content-Type": "text/plain"
+          },
+          body: stringToUtf8Base64(text)
+        };
+        parts.unshift(textPart);
+      }
+
+
+      const validateVCardResponse = await executeRestfulFunction(
+        "private",
+        window.viamApi,
+        window.viamApi.signValidateVCard,
+        null,
+        parts
+      );
+      if (validateVCardResponse.code !== "200") {
+        return encodeResponse("400", "", validateVCardResponse.status);
+      }
+
+      //TODO - what will be the response?
+
+      const signedVCardImageData = new ImageData(validateVCardResponse.data);
+      return encodeResponse("200", signedVCardImageData, "vCard signed");
+    },
     generateQrCode,
     documentCreateDocument: async (passportUUID, path, contentType, title) => {
       const authenticationPublicKey = localStorage.getItem(
-- 
GitLab