diff --git a/src/ecdsa.js b/src/ecdsa.js index 668555a..f721185 100644 --- a/src/ecdsa.js +++ b/src/ecdsa.js @@ -289,20 +289,18 @@ var ECDSA = { * This function simply tries all four cases and returns the value * that resulted in a successful pubkey recovery. */ - calcPubkeyRecoveryParam: function (origPubkey, r, s, hash) - { - var address = origPubkey.getAddress().toString(); + calcPubKeyRecoveryParam: function (origPubKey, r, s, hash) { for (var i = 0; i < 4; i++) { - var pubkey = ECDSA.recoverPubKey(r, s, hash, i); - pubkey.compressed = origPubkey.compressed; - if (pubkey.getAddress().toString() == address) { - return i; + var pubKey = ECDSA.recoverPubKey(r, s, hash, i) + pubKey.compressed = origPubKey.compressed + + if (pubKey.pub.equals(origPubKey.pub)) { + return i } } - throw new Error("Unable to find valid recovery factor"); + throw new Error("Unable to find valid recovery factor") } }; module.exports = ECDSA; - diff --git a/src/message.js b/src/message.js index 998c751..7e52b95 100644 --- a/src/message.js +++ b/src/message.js @@ -31,7 +31,8 @@ Message.signMessage = function (key, message) { var hash = Message.getHash(message) var sig = key.sign(hash) var obj = ecdsa.parseSig(sig) - var i = ecdsa.calcPubkeyRecoveryParam(key, obj.r, obj.s, hash) + + var i = ecdsa.calcPubKeyRecoveryParam(key.getPub(key.compressed), obj.r, obj.s, hash) i += 27 if (key.compressed) {