Browse Source

Fix calcPubkeyRecoveryParam - must verify pubkey correctness.

hk-custom-address
Stefan Thomas 13 years ago
parent
commit
0aaa2c6347
  1. 5
      src/ecdsa.js
  2. 3
      src/message.js

5
src/ecdsa.js

@ -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) {}

3
src/message.js

@ -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;

Loading…
Cancel
Save