Browse Source

Fix PrivateKey.toBuffer

patch-2
Kirill Fomichev 9 years ago
committed by Braydon Fuller
parent
commit
8f51d4884e
  1. 2
      lib/privatekey.js
  2. 7
      test/privatekey.js

2
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 });
};
/**

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

Loading…
Cancel
Save