merge
This commit is contained in:
commit
6edea532ba
4 changed files with 104 additions and 5 deletions
|
@ -50,7 +50,7 @@ BIP32key.prototype.deserialize = function(str) {
|
|||
i: util.bytesToNum(bytes.slice(9,13).reverse()),
|
||||
chaincode: bytes.slice(13,45),
|
||||
key: type == 'priv' ? new ECKey(bytes.slice(46,78).concat([1]),true)
|
||||
: new ECPubKey(bytes.slice(45,78))
|
||||
: new ECPubKey(bytes.slice(45,78),true)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ BIP32key.prototype.ckd = function(i) {
|
|||
else pub = this.key.export('bytes')
|
||||
|
||||
if (i >= 2147483648) {
|
||||
if (this.priv) throw new Error("Can't do private derivation on public key!")
|
||||
if (!priv) throw new Error("Can't do private derivation on public key!")
|
||||
blob = [0].concat(priv.slice(0,32),util.numToBytes(i,4).reverse())
|
||||
}
|
||||
else blob = pub.concat(util.numToBytes(i,4).reverse())
|
||||
|
|
|
@ -285,10 +285,12 @@ var ECDSA = {
|
|||
* This function simply tries all four cases and returns the value
|
||||
* 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++) {
|
||||
var pubkey = ECDSA.recoverPubKey(r, s, hash, i);
|
||||
pubkey.compressed = origPubkey.compressed;
|
||||
if (pubkey.getBitcoinAddress().toString() == address) {
|
||||
return i;
|
||||
}
|
||||
|
|
|
@ -34,8 +34,7 @@ Message.signMessage = function (key, message, compressed) {
|
|||
|
||||
var obj = ecdsa.parseSig(sig);
|
||||
|
||||
var address = key.getBitcoinAddress().toString();
|
||||
var i = ecdsa.calcPubkeyRecoveryParam(address, obj.r, obj.s, hash);
|
||||
var i = ecdsa.calcPubkeyRecoveryParam(key, obj.r, obj.s, hash);
|
||||
|
||||
i += 27;
|
||||
if (compressed) i += 4;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue