Removes unnecessary SHA256 calculations
This commit is contained in:
parent
e82ffa5028
commit
669a58bbf8
2 changed files with 9 additions and 10 deletions
16
src/ecdsa.js
16
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;
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue