diff --git a/test/test.Key.js b/test/test.Key.js index 302900830..01f41c472 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); + }); + });