Removes unnecessary SHA256 calculations

This commit is contained in:
Daniel Cousens 2014-03-29 04:26:19 +11:00
parent e82ffa5028
commit 669a58bbf8
2 changed files with 9 additions and 10 deletions

View file

@ -289,20 +289,18 @@ var ECDSA = {
* This function simply tries all four cases and returns the value * This function simply tries all four cases and returns the value
* that resulted in a successful pubkey recovery. * that resulted in a successful pubkey recovery.
*/ */
calcPubkeyRecoveryParam: function (origPubkey, r, s, hash) calcPubKeyRecoveryParam: function (origPubKey, r, s, hash) {
{
var address = origPubkey.getAddress().toString();
for (var i = 0; i < 4; i++) { for (var i = 0; i < 4; i++) {
var pubkey = ECDSA.recoverPubKey(r, s, hash, i); var pubKey = ECDSA.recoverPubKey(r, s, hash, i)
pubkey.compressed = origPubkey.compressed; pubKey.compressed = origPubKey.compressed
if (pubkey.getAddress().toString() == address) {
return i; 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; module.exports = ECDSA;

View file

@ -31,7 +31,8 @@ Message.signMessage = function (key, message) {
var hash = Message.getHash(message) var hash = Message.getHash(message)
var sig = key.sign(hash) var sig = key.sign(hash)
var obj = ecdsa.parseSig(sig) 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 i += 27
if (key.compressed) { if (key.compressed) {