From 2077d8487ff618d8f80546a55e3bbb7f59780f99 Mon Sep 17 00:00:00 2001 From: Mahrud Sayrafi Date: Thu, 1 Mar 2018 15:47:50 -0800 Subject: [PATCH] Wait for browser to finish ECC functions to make sure it succeeds --- src/crypto/public_key/elliptic/key.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/crypto/public_key/elliptic/key.js b/src/crypto/public_key/elliptic/key.js index 0d33787f..afa16432 100644 --- a/src/crypto/public_key/elliptic/key.js +++ b/src/crypto/public_key/elliptic/key.js @@ -47,7 +47,9 @@ KeyPair.prototype.sign = async function (message, hash_algo) { if (webCrypto && this.curve.web) { // If browser doesn't support a curve, we'll catch it try { - return webSign(this.curve, hash_algo, message, this.keyPair); + // need to await to make sure browser succeeds + const signature = await webSign(this.curve, hash_algo, message, this.keyPair); + return signature; } catch (err) { util.print_debug("Browser did not support signing: " + err.message); } @@ -62,7 +64,9 @@ KeyPair.prototype.verify = async function (message, signature, hash_algo) { if (webCrypto && this.curve.web) { // If browser doesn't support a curve, we'll catch it try { - return webVerify(this.curve, hash_algo, signature, message, this.keyPair.getPublic()); + // need to await to make sure browser succeeds + const result = await webVerify(this.curve, hash_algo, signature, message, this.keyPair.getPublic()); + return result; } catch (err) { util.print_debug("Browser did not support signing: " + err.message); }