HDKeys: add toBuffer/fromBuffer to HDPrivateKey
This commit is contained in:
parent
2c00c87198
commit
28a1eae0be
|
@ -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;
|
||||
|
|
|
@ -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…
Reference in New Issue