HDKeys: add toBuffer/fromBuffer to HDPrivateKey

This commit is contained in:
Esteban Ordano 2015-01-27 11:59:20 -03:00
parent 2c00c87198
commit 28a1eae0be
2 changed files with 19 additions and 0 deletions

View File

@ -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;

View File

@ -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',