From 8f51d4884ed6b42ef2b832a370dbc83455c57449 Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Thu, 25 Feb 2016 19:03:39 +0300 Subject: [PATCH] Fix PrivateKey.toBuffer --- lib/privatekey.js | 2 +- test/privatekey.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/privatekey.js b/lib/privatekey.js index 9697bbf..636eb2d 100644 --- a/lib/privatekey.js +++ b/lib/privatekey.js @@ -336,7 +336,7 @@ PrivateKey.prototype.toBigNumber = function(){ * @returns {Buffer} A buffer of the private key */ PrivateKey.prototype.toBuffer = function(){ - return this.bn.toBuffer(); + return this.bn.toBuffer({ size: 32 }); }; /** diff --git a/test/privatekey.js b/test/privatekey.js index 6df0299..ffbaaf8 100644 --- a/test/privatekey.js +++ b/test/privatekey.js @@ -330,6 +330,13 @@ describe('PrivateKey', function() { var fromBuffer = PrivateKey.fromBuffer(toBuffer.toBuffer()); fromBuffer.toString().should.equal(privkey.toString()); }); + + it('should return buffer with length equal 32', function() { + var bn = BN.fromBuffer(buf.slice(0, 31)); + var privkey = new PrivateKey(bn, 'livenet'); + var expected = Buffer.concat([ new Buffer([0]), buf.slice(0, 31) ]); + privkey.toBuffer().toString('hex').should.equal(expected.toString('hex')); + }); }); describe('#toBigNumber', function() {