|
|
@ -25,7 +25,7 @@ ECDSA.prototype.set = function(obj) { |
|
|
|
}; |
|
|
|
|
|
|
|
ECDSA.prototype.privkey2pubkey = function(){ |
|
|
|
this.pubkey = PublicKey().fromPrivateKey(this.privkey); |
|
|
|
this.pubkey = PublicKey.fromPrivateKey(this.privkey); |
|
|
|
}; |
|
|
|
|
|
|
|
ECDSA.prototype.calci = function() { |
|
|
@ -35,6 +35,7 @@ ECDSA.prototype.calci = function() { |
|
|
|
try { |
|
|
|
Qprime = this.sig2pubkey(); |
|
|
|
} catch (e) { |
|
|
|
console.log(e); |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (Qprime.point.eq(this.pubkey.point)) { |
|
|
@ -52,9 +53,9 @@ ECDSA.prototype.fromString = function(str) { |
|
|
|
if (obj.hashbuf) |
|
|
|
this.hashbuf = new Buffer(obj.hashbuf, 'hex'); |
|
|
|
if (obj.pubkey) |
|
|
|
this.pubkey = PublicKey().fromString(obj.pubkey); |
|
|
|
this.pubkey = PublicKey.fromString(obj.pubkey); |
|
|
|
if (obj.privkey) |
|
|
|
this.privkey = PrivateKey().fromString(obj.privkey); |
|
|
|
this.privkey = PrivateKey.fromString(obj.privkey); |
|
|
|
if (obj.sig) |
|
|
|
this.sig = Signature().fromString(obj.sig); |
|
|
|
if (obj.k) |
|
|
@ -114,9 +115,7 @@ ECDSA.prototype.sig2pubkey = function() { |
|
|
|
//var Q = R.multiplyTwo(s, G, eNeg).mul(rInv);
|
|
|
|
var Q = R.mul(s).add(G.mul(eNeg)).mul(rInv); |
|
|
|
|
|
|
|
var pubkey = new PublicKey({point: Q}); |
|
|
|
pubkey.compressed = this.sig.compressed; |
|
|
|
pubkey.validate(); |
|
|
|
var pubkey = PublicKey.fromPoint(Q, this.sig.compressed); |
|
|
|
|
|
|
|
return pubkey; |
|
|
|
}; |
|
|
@ -125,12 +124,6 @@ ECDSA.prototype.sigError = function() { |
|
|
|
if (!Buffer.isBuffer(this.hashbuf) || this.hashbuf.length !== 32) |
|
|
|
return 'hashbuf must be a 32 byte buffer'; |
|
|
|
|
|
|
|
try { |
|
|
|
this.pubkey.validate(); |
|
|
|
} catch (e) { |
|
|
|
return 'Invalid pubkey: ' + e; |
|
|
|
} |
|
|
|
|
|
|
|
var r = this.sig.r; |
|
|
|
var s = this.sig.s; |
|
|
|
if (!(r.gt(0) && r.lt(Point.getN())) |
|
|
|