From 4ed4386b5e9acf6572e7aba1a285da631e47675c Mon Sep 17 00:00:00 2001
From: Damyan Mitev <damyan.mitev@vereign.com>
Date: Fri, 3 Apr 2020 19:10:39 +0300
Subject: [PATCH] Add new constructor to ImageData

---
 javascript/src/utilities/signingUtilities.js | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/javascript/src/utilities/signingUtilities.js b/javascript/src/utilities/signingUtilities.js
index ec25529..20f64f0 100644
--- a/javascript/src/utilities/signingUtilities.js
+++ b/javascript/src/utilities/signingUtilities.js
@@ -1495,6 +1495,9 @@ export class ImageData {
     this.content = null; // Uint8Array: decoded content
     this.contentBase64 = null; // string: base64 encoded content
 
+    if (typeof parameters === "string" || parameters instanceof String) {
+      this.fromDataURL(parameters);
+    } else
     if (typeof parameters === "object") {
       this.fromParameters(parameters);
     }
@@ -1517,13 +1520,24 @@ export class ImageData {
     this.getContentBase64();
   }
 
-  //fromDataURL()
+  fromDataURL(dataURL) {
+    if (dataURL.startsWith("data:")) {
+      const idx = dataURL.indexOf(";base64,");
+      if (idx > 0) {
+        this.contentType = dataURL.substring(5, idx); // 5 = len("data:")
+        this.contentBase64 = dataURL.substring(idx + 8); // 8 = len(";base64,")
+      }
+    }
+  }
   //fromContentTypeAndContentAsByteArray()
 
   toDataURL() {
     return "data:" + this.contentType + ";base64," + this.getContentBase64();
   }
 
+  /**
+   * @returns {ByteArray}
+   */
   getContent() {
     if (!this.content) {
       if (this.contentBase64) {
@@ -1533,6 +1547,9 @@ export class ImageData {
     return this.content;
   }
 
+  /**
+   * @returns {String}
+   */
   getContentBase64() {
     if (!this.contentBase64) {
       if (this.content) {
-- 
GitLab