Browse Source

HDKeys: add toBuffer/fromBuffer to HDPrivateKey

patch-2
Esteban Ordano 10 years ago
parent
commit
28a1eae0be
  1. 8
      lib/hdprivatekey.js
  2. 11
      test/hdprivatekey.js

8
lib/hdprivatekey.js

@ -484,6 +484,14 @@ HDPrivateKey.prototype.toJSON = function toJSON() {
return JSON.stringify(this.toObject());
};
HDPrivateKey.fromBuffer = function(arg) {
return new HDPrivateKey(arg);
};
HDPrivateKey.prototype.toBuffer = function() {
return this._buffers.xprivkey;
};
HDPrivateKey.DefaultDepth = 0;
HDPrivateKey.DefaultFingerprint = 0;
HDPrivateKey.DefaultChildIndex = 0;

11
test/hdprivatekey.js

@ -262,6 +262,17 @@ describe('HDPrivate key interface', function() {
});
});
describe.only('conversion to/from buffer', function() {
var str = 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi';
it('should roundtrip to/from a buffer', function() {
var priv = new HDPrivateKey(str);
var toBuffer = priv.toBuffer();
var fromBuffer = HDPrivateKey.fromBuffer(toBuffer);
var roundTrip = new HDPrivateKey(fromBuffer.toBuffer());
roundTrip.xprivkey.should.equal(str);
});
});
describe('conversion to plain object/json', function() {
var plainObject = {
'network':'livenet',

Loading…
Cancel
Save