Skip to content

Commit 0aaa2c6

Browse files
committed
Fix calcPubkeyRecoveryParam - must verify pubkey correctness.
1 parent de6cfd3 commit 0aaa2c6

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/ecdsa.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,11 +457,12 @@ Bitcoin.ECDSA = (function () {
457457
* This function simply tries all four cases and returns the value
458458
* that resulted in a successful pubkey recovery.
459459
*/
460-
calcPubkeyRecoveryParam: function (r, s, hash)
460+
calcPubkeyRecoveryParam: function (address, r, s, hash)
461461
{
462462
for (var i = 0; i < 4; i++) {
463463
try {
464-
if (Bitcoin.ECDSA.recoverPubKey(r, s, hash, i)) {
464+
var pubkey = Bitcoin.ECDSA.recoverPubKey(r, s, hash, i);
465+
if (pubkey.getBitcoinAddress().toString() == address) {
465466
return i;
466467
}
467468
} catch (e) {}

src/message.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ Bitcoin.Message = (function () {
3131

3232
var obj = Bitcoin.ECDSA.parseSig(sig);
3333

34-
var i = Bitcoin.ECDSA.calcPubkeyRecoveryParam(obj.r, obj.s, hash);
34+
var address = key.getBitcoinAddress().toString();
35+
var i = Bitcoin.ECDSA.calcPubkeyRecoveryParam(address, obj.r, obj.s, hash);
3536

3637
i += 27;
3738
if (compressed) i += 4;

0 commit comments

Comments
 (0)