diff --git a/lib/crypto/ecdsa.js b/lib/crypto/ecdsa.js index a80ea71..842be38 100644 --- a/lib/crypto/ecdsa.js +++ b/lib/crypto/ecdsa.js @@ -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)) { @@ -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 = PublicKey.fromPoint(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())) diff --git a/lib/publickey.js b/lib/publickey.js index 4b9f611..71501fd 100644 --- a/lib/publickey.js +++ b/lib/publickey.js @@ -186,11 +186,11 @@ PublicKey.fromBuffer = function(buf) { * @param {Point} point - A Point instance * @returns {PublicKey} A new valid instance of PublicKey */ -PublicKey.fromPoint = function(point){ +PublicKey.fromPoint = function(point, compressed){ if (!(point instanceof Point)) { throw new TypeError('First argument must be an instance of Point.'); } - return new PublicKey(point); + return new PublicKey(point, compressed); }; /** diff --git a/test/crypto/ecdsa.js b/test/crypto/ecdsa.js index 52f5f63..5252a5f 100644 --- a/test/crypto/ecdsa.js +++ b/test/crypto/ecdsa.js @@ -8,7 +8,6 @@ var PrivateKey = bitcore.PrivateKey; var PublicKey = bitcore.PublicKey; var Signature = bitcore.Signature; var BN = bitcore.crypto.BN; -var point = bitcore.crypto.Point; describe('ECDSA', function() { @@ -105,17 +104,10 @@ describe('ECDSA', function() { ecdsa.sigError().should.equal('hashbuf must be a 32 byte buffer'); }); - it('should return an error if the pubkey is invalid', function() { - var ecdsa = new ECDSA(); - ecdsa.hashbuf = Hash.sha256(new Buffer('test')); - ecdsa.sigError().indexOf("Invalid pubkey").should.equal(0); - }); - it('should return an error if r, s are invalid', function() { var ecdsa = new ECDSA(); ecdsa.hashbuf = Hash.sha256(new Buffer('test')); - var pk = new PublicKey(); - pk.fromDER(new Buffer('041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341', 'hex')); + var pk = PublicKey.fromDER(new Buffer('041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341', 'hex')); ecdsa.pubkey = pk; ecdsa.sig = new Signature(); ecdsa.sig.r = BN(0);