Fix calcPubkeyRecoveryParam - must verify pubkey correctness.

This commit is contained in:
Stefan Thomas 2012-08-17 01:50:29 +02:00
parent de6cfd37db
commit 0aaa2c6347
2 changed files with 5 additions and 3 deletions

View file

@ -457,11 +457,12 @@ Bitcoin.ECDSA = (function () {
* This function simply tries all four cases and returns the value
* that resulted in a successful pubkey recovery.
*/
calcPubkeyRecoveryParam: function (r, s, hash)
calcPubkeyRecoveryParam: function (address, r, s, hash)
{
for (var i = 0; i < 4; i++) {
try {
if (Bitcoin.ECDSA.recoverPubKey(r, s, hash, i)) {
var pubkey = Bitcoin.ECDSA.recoverPubKey(r, s, hash, i);
if (pubkey.getBitcoinAddress().toString() == address) {
return i;
}
} catch (e) {}

View file

@ -31,7 +31,8 @@ Bitcoin.Message = (function () {
var obj = Bitcoin.ECDSA.parseSig(sig);
var i = Bitcoin.ECDSA.calcPubkeyRecoveryParam(obj.r, obj.s, hash);
var address = key.getBitcoinAddress().toString();
var i = Bitcoin.ECDSA.calcPubkeyRecoveryParam(address, obj.r, obj.s, hash);
i += 27;
if (compressed) i += 4;