Fix calcPubkeyRecoveryParam - must verify pubkey correctness.
This commit is contained in:
parent
de6cfd37db
commit
0aaa2c6347
2 changed files with 5 additions and 3 deletions
|
@ -457,11 +457,12 @@ Bitcoin.ECDSA = (function () {
|
||||||
* 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 (r, s, hash)
|
calcPubkeyRecoveryParam: function (address, r, s, hash)
|
||||||
{
|
{
|
||||||
for (var i = 0; i < 4; i++) {
|
for (var i = 0; i < 4; i++) {
|
||||||
try {
|
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;
|
return i;
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
|
@ -31,7 +31,8 @@ Bitcoin.Message = (function () {
|
||||||
|
|
||||||
var obj = Bitcoin.ECDSA.parseSig(sig);
|
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;
|
i += 27;
|
||||||
if (compressed) i += 4;
|
if (compressed) i += 4;
|
||||||
|
|
Loading…
Add table
Reference in a new issue