diff --git a/javascript/src/iframe/viamapi-iframe.js b/javascript/src/iframe/viamapi-iframe.js
index 981fa97de178948ebd5174d6d4792b7de911955a..2c832749c72284fde0bf5f910977aa79f527276b 100644
--- a/javascript/src/iframe/viamapi-iframe.js
+++ b/javascript/src/iframe/viamapi-iframe.js
@@ -1,4 +1,4 @@
-import {createDeviceHash} from '../utilities/appUtility';
+import {createDeviceHash, encodeResponse} from '../utilities/appUtility';
 import {LOGIN_MODES} from '../constants';
 
 const libmime = require('libmime');
@@ -2008,80 +2008,54 @@ const connection = Penpal.connectToParent({
         })
       });
     },
-    signEmail(passportUUID, emailArg, emailMessage) {
-      return new Penpal.Promise(result => {
-        const authenticationPublicKey = localStorage.getItem("authenticatedIdentity");
-        if (authenticationPublicKey === null) {
-          return {"data" : "",
-            "code" : "400",
-            "status" : "Identity not authenticated"
-          }
-        }
-        if (window.loadedIdentities[authenticationPublicKey] === null) {
-          return {"data" : "",
-            "code" : "400",
-            "status" : "Identity not authenticated"
-          }
-        }
+    signEmail: async (passportUUID, emailArg, emailMessage) => {
+      const authenticationPublicKey = localStorage.getItem("authenticatedIdentity");
 
-        var success = extendPinCodeTtl(authenticationPublicKey);
+      if (
+        !authenticationPublicKey ||
+        !window.loadedIdentities[authenticationPublicKey] ||
+        !extendPinCodeTtl(authenticationPublicKey)
+      ) {
+        return encodeResponse("400", "", "Identity not authenticated");
+      }
 
-        if(success === false) {
-          result({"data" : "",
-            "code" : "400",
-            "status" : "Identity not authenticated"
-          })
-        }
+      let response = await getCertificateForPassport(passportUUID, true);
 
-        getCertificateForPassport(passportUUID, true).then(certificateResult => {
-          if(certificateResult.code === "200") {
-            var passportCertificate = certificateResult.data["x509Certificate"];
-            var passportPrivateKey = certificateResult.data["privateKey"];
-            var passportChain = certificateResult.data["chain"];
+      if (response.code !== "200") {
+        return encodeResponse("400", "", response.status);
+      }
 
-            createOneTimePassportCertificate(makeid() + "-" + passportUUID, emailArg, passportPrivateKey, passportCertificate).then(function(keys){
-              var publicKeyOneTime = keys["publicKeyPEM"];
-              var privateKeyOneTime = keys["privateKeyPEM"];
-              var certificateOneTime = keys["certificatePEM"];
-              //download("certificateOneTime.crt", "text/plain", certificateOneTime)
+      const {
+        x509Certificate: passportCertificate,
+        privateKey: passportPrivateKey,
+        chain: passportChain
+      } = response.data;
 
-              passportChain.push(passportCertificate);
+      const keys =
+        await createOneTimePassportCertificate(
+          makeid() + "-" + passportUUID, emailArg, passportPrivateKey, passportCertificate);
 
-              executeRestfulFunction("private", viamApi, viamApi.passportGetEmailWithHeaderByPassport,
-                passportUUID, emailMessage).then(executeResult2 => {
-                var emailWithHeader = executeResult2.data;
-                //download("withheader.eml", "message/rfc822", emailWithHeader)
-                var signedEmailPromise = signEmail(emailWithHeader,
-                  certificateOneTime,
-                  passportChain,
-                  privateKeyOneTime);
-
-                signedEmailPromise.then(signedEmail => {
-                  executeRestfulFunction("private", viamApi, viamApi.signResignEmail,
-                    passportUUID, signedEmail).then(executeResult => {
-                    result({"data" : executeResult.data,
-                      "code" : "200",
-                      "status" : "Email signed"
-                    })
-                  });
-                  /*result({"data" : signedEmail,
-                      "code" : "200",
-                      "status" : "Email signed"
-                  })*/
-                });
-              });
-              // Prints PEM formatted signed certificate
-              // -----BEGIN CERTIFICATE-----MIID....7Hyg==-----END CERTIFICATE-----
+      const { privateKeyPEM: privateKeyOneTime, certificatePEM: certificateOneTime } = keys;
 
-            });
-          } else {
-            result({"data" : "",
-              "code" : "400",
-              "status" : "Can not sign email"
-            })
-          }
-        })
-      });
+      passportChain.push(passportCertificate);
+
+      response = await executeRestfulFunction(
+        "private", window.viamApi, window.viamApi.passportGetEmailWithHeaderByPassport, passportUUID, emailMessage);
+
+      if (response.code !== "200") {
+        return encodeResponse("400", "", response.status);
+      }
+
+      const signedEmail = await signEmail(response.data, certificateOneTime, passportChain, privateKeyOneTime);
+
+      response = await executeRestfulFunction(
+        "private", window.viamApi, window.viamApi.signResignEmail, passportUUID, signedEmail);
+
+      if (response.code !== "200") {
+        return encodeResponse("400", "", response.status);
+      }
+
+      return encodeResponse("200", response.data, "Email signed");
     },
     hasSession() {
       return new Penpal.Promise(result => {
diff --git a/javascript/src/utilities/appUtility.js b/javascript/src/utilities/appUtility.js
index 66cfaf8b37d46c8175b4393675dd008e9ff84b77..deeb54f4206de5ea7f79cd5f493067cf5a395d9e 100644
--- a/javascript/src/utilities/appUtility.js
+++ b/javascript/src/utilities/appUtility.js
@@ -11,3 +11,11 @@ export const createDeviceHash = async (publicKey) => {
     console.warn(error); // eslint-disable-line no-console
   }
 };
+
+export const encodeResponse = (code, data, status) => {
+  return {
+    code,
+    data,
+    status
+  };
+};
\ No newline at end of file