From df0aa744836b2a97e0c809a41d52cb1c57705b20 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 12 Mar 2014 23:20:46 -0300 Subject: [PATCH 1/3] set default for compressed state --- Key.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Key.js b/Key.js index a6b4732..c78cc43 100644 --- a/Key.js +++ b/Key.js @@ -21,6 +21,7 @@ if (process.versions) { var kSpec = function() { this._pub = null; + this.compressed = true; // default }; From caa16713f1c5023009196eccce588cadf73ee250 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 12 Mar 2014 23:21:16 -0300 Subject: [PATCH 2/3] add broken test for verifing a signature (fails in browser) --- test/test.Key.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/test/test.Key.js b/test/test.Key.js index 3029008..01f41c4 100644 --- a/test/test.Key.js +++ b/test/test.Key.js @@ -73,7 +73,7 @@ describe('Key', function() { it('should create a signature without failling', function() { var k = Key.generateSync(); var pkshex = 'b7dafe35d7d1aab78b53982c8ba554584518f86d50af565c98e053613c8f15e0'; - k.private = buffertools.fromHex(new Buffer(pkshex)); + k.private = new Buffer(pkshex, 'hex'); k.regenerateSync(); k.compressed.should.be.ok; buffertools.toHex(k.private).should.equal(pkshex); @@ -92,4 +92,30 @@ describe('Key', function() { var ret= k2.verifySignatureSync(a_hash, sig); ret.should.equal(true); }); + it('should generate a hardcoded public key example', function() { + var k = new Key(); + k.private = new Buffer('876156ccb16bb1760ddda6ad3e561c026fc0d679ad7860b71dd11c30e42f6589','hex'); + k.regenerateSync(); + + k.compressed.should.equal(true); + var pHex = bitcore.buffertools.toHex(k.public); + pHex.should.equal('0394615227fd5ff4d4dfac88cf148e43d35a7a059788dd2479f60cea807b09d0c2'); + }); + it('should verify a hardcoded example', function() { + var k = new Key(); + k.private = new Buffer('876156ccb16bb1760ddda6ad3e561c026fc0d679ad7860b71dd11c30e42f6589','hex'); + k.regenerateSync(); + var pHex = bitcore.buffertools.toHex(k.public); + pHex.should.equal('0394615227fd5ff4d4dfac88cf148e43d35a7a059788dd2479f60cea807b09d0c2'); + var a_hash = new Buffer('ce42c5c7f405461c38ea849130f51e48531ab3188390a21a15aeaa1faedbf0b2','hex'); + var sig= new Buffer('304602210099f689f846a1590cf57f9cede2fe841d8552f114bc9e5f5603a333b00e69d3fa022100e83604ddd5f1ce6f5add3ac8da7dbf17f3ffe5b47205f3899caeaa54abdbcf07','hex'); + + var ret= k.verifySignatureSync(a_hash, sig); + ret.should.equal(true); + + var sig2= new Buffer('304602210099f689f846a1590cf57f9cede2fe841d8552f114bc9e5f5603a333b00e69d3fa022100e83604ddd5f1ce6f5add3ac8da7dbf17f3ffe5b47205f3899caeaa54abdbcf08', 'hex'); + var ret= k.verifySignatureSync(a_hash, sig2); + ret.should.equal(false); + }); + }); From 2a6f7155b3c2ff70629ec5ceaf33dbbab199a442 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Thu, 13 Mar 2014 00:27:50 -0300 Subject: [PATCH 3/3] fix sigatures and verifications on browser --- Key.js | 4 ++-- test/test.Key.js | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Key.js b/Key.js index c78cc43..aded6a7 100644 --- a/Key.js +++ b/Key.js @@ -71,7 +71,7 @@ if (process.versions) { } var eck = new ECKey(buffertools.toHex(this.private)); eck.setCompressed(this.compressed); - var signature = eck.sign(hash); + var signature = eck.sign(bufferToArray(hash)); // return it as a buffer to keep c++ compatibility return new Buffer(signature); }; @@ -93,7 +93,7 @@ if (process.versions) { eck.setPub(bufferToArray(self.public)); eck.setCompressed(self.compressed); var sigA = bufferToArray(sig); - var ret = eck.verify(hash,sigA); + var ret = eck.verify(bufferToArray(hash),sigA); return ret; }; diff --git a/test/test.Key.js b/test/test.Key.js index 01f41c4..fdac701 100644 --- a/test/test.Key.js +++ b/test/test.Key.js @@ -56,6 +56,16 @@ describe('Key', function() { buffertools.toHex(k.private).should.equal(pkshex); buffertools.toHex(k.public).should.equal(pubhex); }); + it('should generate a hardcoded public key example', function() { + var k = new Key(); + k.private = new Buffer('876156ccb16bb1760ddda6ad3e561c026fc0d679ad7860b71dd11c30e42f6589','hex'); + k.regenerateSync(); + + k.compressed.should.equal(true); + var pHex = bitcore.buffertools.toHex(k.public); + pHex.should.equal('0394615227fd5ff4d4dfac88cf148e43d35a7a059788dd2479f60cea807b09d0c2'); + }); + it('should not fail checking good signSync status', function() { var k = Key.generateSync(); var b = new Buffer(32); @@ -92,15 +102,7 @@ describe('Key', function() { var ret= k2.verifySignatureSync(a_hash, sig); ret.should.equal(true); }); - it('should generate a hardcoded public key example', function() { - var k = new Key(); - k.private = new Buffer('876156ccb16bb1760ddda6ad3e561c026fc0d679ad7860b71dd11c30e42f6589','hex'); - k.regenerateSync(); - k.compressed.should.equal(true); - var pHex = bitcore.buffertools.toHex(k.public); - pHex.should.equal('0394615227fd5ff4d4dfac88cf148e43d35a7a059788dd2479f60cea807b09d0c2'); - }); it('should verify a hardcoded example', function() { var k = new Key(); k.private = new Buffer('876156ccb16bb1760ddda6ad3e561c026fc0d679ad7860b71dd11c30e42f6589','hex');