Merge branch 'feature/keys-interface-rename-tests' into feature/keys-interface-rename

This commit is contained in:
Braydon Fuller 2014-11-25 17:38:24 -05:00
commit a50655c7d3
3 changed files with 5 additions and 20 deletions

View File

@ -35,6 +35,7 @@ ECDSA.prototype.calci = function() {
try { try {
Qprime = this.sig2pubkey(); Qprime = this.sig2pubkey();
} catch (e) { } catch (e) {
console.log(e);
continue; continue;
} }
if (Qprime.point.eq(this.pubkey.point)) { 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.multiplyTwo(s, G, eNeg).mul(rInv);
var Q = R.mul(s).add(G.mul(eNeg)).mul(rInv); var Q = R.mul(s).add(G.mul(eNeg)).mul(rInv);
var pubkey = PublicKey.fromPoint(Q); var pubkey = PublicKey.fromPoint(Q, this.sig.compressed);
pubkey.compressed = this.sig.compressed;
pubkey.validate();
return pubkey; return pubkey;
}; };
@ -125,12 +124,6 @@ ECDSA.prototype.sigError = function() {
if (!Buffer.isBuffer(this.hashbuf) || this.hashbuf.length !== 32) if (!Buffer.isBuffer(this.hashbuf) || this.hashbuf.length !== 32)
return 'hashbuf must be a 32 byte buffer'; return 'hashbuf must be a 32 byte buffer';
try {
this.pubkey.validate();
} catch (e) {
return 'Invalid pubkey: ' + e;
}
var r = this.sig.r; var r = this.sig.r;
var s = this.sig.s; var s = this.sig.s;
if (!(r.gt(0) && r.lt(Point.getN())) if (!(r.gt(0) && r.lt(Point.getN()))

View File

@ -186,11 +186,11 @@ PublicKey.fromBuffer = function(buf) {
* @param {Point} point - A Point instance * @param {Point} point - A Point instance
* @returns {PublicKey} A new valid instance of PublicKey * @returns {PublicKey} A new valid instance of PublicKey
*/ */
PublicKey.fromPoint = function(point){ PublicKey.fromPoint = function(point, compressed){
if (!(point instanceof Point)) { if (!(point instanceof Point)) {
throw new TypeError('First argument must be an instance of Point.'); throw new TypeError('First argument must be an instance of Point.');
} }
return new PublicKey(point); return new PublicKey(point, compressed);
}; };
/** /**

View File

@ -8,7 +8,6 @@ var PrivateKey = bitcore.PrivateKey;
var PublicKey = bitcore.PublicKey; var PublicKey = bitcore.PublicKey;
var Signature = bitcore.Signature; var Signature = bitcore.Signature;
var BN = bitcore.crypto.BN; var BN = bitcore.crypto.BN;
var point = bitcore.crypto.Point;
describe('ECDSA', function() { describe('ECDSA', function() {
@ -105,17 +104,10 @@ describe('ECDSA', function() {
ecdsa.sigError().should.equal('hashbuf must be a 32 byte buffer'); 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() { it('should return an error if r, s are invalid', function() {
var ecdsa = new ECDSA(); var ecdsa = new ECDSA();
ecdsa.hashbuf = Hash.sha256(new Buffer('test')); ecdsa.hashbuf = Hash.sha256(new Buffer('test'));
var pk = new PublicKey(); var pk = PublicKey.fromDER(new Buffer('041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341', 'hex'));
pk.fromDER(new Buffer('041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341', 'hex'));
ecdsa.pubkey = pk; ecdsa.pubkey = pk;
ecdsa.sig = new Signature(); ecdsa.sig = new Signature();
ecdsa.sig.r = BN(0); ecdsa.sig.r = BN(0);