Merge pull request #844 from eordano/feature/G7/hdpubkey

Add G7 methods to HDPublicKey
This commit is contained in:
Yemel Jardi 2014-12-23 12:58:24 -03:00
commit 08ad29f89a
2 changed files with 28 additions and 0 deletions

View File

@ -344,6 +344,10 @@ HDPublicKey._validateBufferArguments = function (arg) {
}
};
HDPublicKey.fromString = HDPublicKey.fromObject = HDPublicKey.fromJSON = function(arg) {
return new HDPublicKey(arg);
};
/**
* Returns the base58 checked representation of the public key
* @return {string} a string starting with "xpub..." in livenet

View File

@ -153,6 +153,30 @@ describe('HDPublicKey interface', function() {
pubKey.inspect().should.equal('<HDPublicKey: ' + pubKey.xpubkey + '>');
});
describe('conversion to different formats', function() {
var plainObject = {
'network':'livenet',
'depth':0,
'fingerPrint':876747070,
'parentFingerPrint':0,
'childIndex':0,
'chainCode':'873dff81c02f525623fd1fe5167eac3a55a049de3d314bb42ee227ffed37d508',
'publicKey':'0339a36013301597daef41fbe593a02cc513d0b55527ec2df1050e2e8ff49c85c2',
'checksum':-1421395167,
'xpubkey':'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8'
};
it('roundtrips to JSON and to Object', function() {
var pubkey = new HDPublicKey(xpubkey);
expect(HDPublicKey.fromJSON(pubkey.toJSON()).xpubkey).to.equal(xpubkey);
});
it('recovers state from JSON', function() {
new HDPublicKey(JSON.stringify(plainObject)).xpubkey.should.equal(xpubkey);
});
it('recovers state from Object', function() {
new HDPublicKey(plainObject).xpubkey.should.equal(xpubkey);
});
});
describe('derivation', function() {
it('derivation is the same whether deriving with number or string', function() {
var pubkey = new HDPublicKey(xpubkey);