HDKeys: add toBuffer/fromBuffer to HDPublicKey
This commit is contained in:
parent
0ff4c9a922
commit
7a73f582b4
@ -417,6 +417,25 @@ HDPublicKey.prototype.toJSON = function toJSON() {
|
||||
return JSON.stringify(this.toObject());
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a HDPublicKey from a buffer argument
|
||||
*
|
||||
* @param {Buffer} arg
|
||||
* @return {HDPublicKey}
|
||||
*/
|
||||
HDPublicKey.fromBuffer = function(arg) {
|
||||
return new HDPublicKey(arg);
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a buffer representation of the xpubkey
|
||||
*
|
||||
* @return {Buffer}
|
||||
*/
|
||||
HDPublicKey.prototype.toBuffer = function() {
|
||||
return this._buffers.xpubkey;
|
||||
};
|
||||
|
||||
HDPublicKey.Hardened = 0x80000000;
|
||||
HDPublicKey.RootElementAlias = ['m', 'M'];
|
||||
|
||||
|
||||
@ -262,7 +262,7 @@ describe('HDPrivate key interface', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe.only('conversion to/from buffer', function() {
|
||||
describe('conversion to/from buffer', function() {
|
||||
var str = 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi';
|
||||
it('should roundtrip to/from a buffer', function() {
|
||||
var priv = new HDPrivateKey(str);
|
||||
|
||||
@ -153,6 +153,17 @@ describe('HDPublicKey interface', function() {
|
||||
pubKey.inspect().should.equal('<HDPublicKey: ' + pubKey.xpubkey + '>');
|
||||
});
|
||||
|
||||
describe('conversion to/from buffer', function() {
|
||||
|
||||
it('should roundtrip to an equivalent object', function() {
|
||||
var pubKey = new HDPublicKey(xpubkey);
|
||||
var toBuffer = pubKey.toBuffer();
|
||||
var fromBuffer = HDPublicKey.fromBuffer(toBuffer);
|
||||
var roundTrip = new HDPublicKey(fromBuffer.toBuffer());
|
||||
roundTrip.xpubkey.should.equal(xpubkey);
|
||||
});
|
||||
});
|
||||
|
||||
describe('conversion to different formats', function() {
|
||||
var plainObject = {
|
||||
'network':'livenet',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user