lazy calc for xpubkey in HDPrivateKey
This commit is contained in:
parent
1a0cb73add
commit
7da4c7925a
|
@ -423,14 +423,29 @@ HDPrivateKey.prototype._buildFromBuffers = function(arg) {
|
|||
fingerPrint: fingerPrint
|
||||
});
|
||||
|
||||
var HDPublicKey = require('./hdpublickey');
|
||||
var hdPublicKey = new HDPublicKey(this);
|
||||
|
||||
JSUtil.defineImmutable(this, {
|
||||
hdPublicKey: hdPublicKey,
|
||||
xpubkey: hdPublicKey.xpubkey
|
||||
this._hdPublicKey = null;
|
||||
Object.defineProperty(this, 'hdPublicKey', {
|
||||
configurable: false,
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
if (!this._hdPublicKey) {
|
||||
var HDPublicKey = require('./hdpublickey');
|
||||
this._hdPublicKey = new HDPublicKey(this);
|
||||
}
|
||||
return this._hdPublicKey;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(this, 'xpubkey', {
|
||||
configurable: false,
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
if (!this._hdPublicKey) {
|
||||
var HDPublicKey = require('./hdpublickey');
|
||||
this._hdPublicKey = new HDPublicKey(this);
|
||||
}
|
||||
return this._hdPublicKey.xpubkey;
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
|
|
|
@ -76,6 +76,11 @@ describe('BIP32 compliance', function() {
|
|||
publicKey.toString().should.equal(publicKey.xpubkey);
|
||||
});
|
||||
|
||||
it('cache for xpubkey works for test vector 1', function() {
|
||||
var pk = HDPrivateKey(vector1_m_private);
|
||||
pk.xpubkey.should.equal(pk.xpubkey);
|
||||
});
|
||||
|
||||
it('should get the extended public key from the extended private key for test vector 1', function() {
|
||||
HDPrivateKey(vector1_m_private).xpubkey.should.equal(vector1_m_public);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue