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() {