Merge pull request #4 from shesek/fix-compressed-signature
Fix signing with compressed keys
This commit is contained in:
commit
2a16cd9391
2 changed files with 4 additions and 3 deletions
|
@ -275,10 +275,12 @@ var ECDSA = {
|
||||||
* 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 (address, r, s, hash)
|
calcPubkeyRecoveryParam: function (origPubkey, r, s, hash)
|
||||||
{
|
{
|
||||||
|
var address = origPubkey.getBitcoinAddress().toString();
|
||||||
for (var i = 0; i < 4; i++) {
|
for (var i = 0; i < 4; i++) {
|
||||||
var pubkey = ECDSA.recoverPubKey(r, s, hash, i);
|
var pubkey = ECDSA.recoverPubKey(r, s, hash, i);
|
||||||
|
pubkey.compressed = origPubkey.compressed;
|
||||||
if (pubkey.getBitcoinAddress().toString() == address) {
|
if (pubkey.getBitcoinAddress().toString() == address) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,7 @@ Message.signMessage = function (key, message, compressed) {
|
||||||
|
|
||||||
var obj = ecdsa.parseSig(sig);
|
var obj = ecdsa.parseSig(sig);
|
||||||
|
|
||||||
var address = key.getBitcoinAddress().toString();
|
var i = ecdsa.calcPubkeyRecoveryParam(key, obj.r, obj.s, hash);
|
||||||
var i = ecdsa.calcPubkeyRecoveryParam(address, obj.r, obj.s, hash);
|
|
||||||
|
|
||||||
i += 27;
|
i += 27;
|
||||||
if (compressed) i += 4;
|
if (compressed) i += 4;
|
||||||
|
|
Loading…
Reference in a new issue