Browse Source

Add toBufferNoPadding method to private key

patch-2
Braydon Fuller 8 years ago
parent
commit
e9d1237228
  1. 9
      lib/privatekey.js
  2. 14
      test/privatekey.js

9
lib/privatekey.js

@ -339,6 +339,15 @@ PrivateKey.prototype.toBuffer = function(){
return this.bn.toBuffer({ size: 32 });
};
/**
* Will return the private key as a BN buffer without leading zero padding
*
* @returns {Buffer} A buffer of the private key
*/
PrivateKey.prototype.toBufferNoPadding = function() {
return this.bn.toBuffer();
};
/**
* Will return the corresponding public key
*

14
test/privatekey.js

@ -331,6 +331,20 @@ describe('PrivateKey', function() {
fromBuffer.toString().should.equal(privkey.toString());
});
it('will output a 32 byte buffer', function() {
var bn = BN.fromBuffer(new Buffer('9b5a0e8fee1835e21170ce1431f9b6f19b487e67748ed70d8a4462bc031915', 'hex'));
var privkey = new PrivateKey(bn);
var buffer = privkey.toBuffer();
buffer.length.should.equal(32);
});
it('will output a 31 byte buffer', function() {
var bn = BN.fromBuffer(new Buffer('9b5a0e8fee1835e21170ce1431f9b6f19b487e67748ed70d8a4462bc031915', 'hex'));
var privkey = new PrivateKey(bn);
var buffer = privkey.toBufferNoPadding();
buffer.length.should.equal(31);
});
it('should return buffer with length equal 32', function() {
var bn = BN.fromBuffer(buf.slice(0, 31));
var privkey = new PrivateKey(bn, 'livenet');

Loading…
Cancel
Save