hd key optimization

This commit is contained in:
Christopher Jeffrey 2016-02-23 13:14:58 -08:00
parent 1e1e214900
commit 00eba20c4e

View File

@ -707,9 +707,20 @@ HDPrivateKey.prototype._build = function _build(data) {
this.fingerPrint = fingerPrint; this.fingerPrint = fingerPrint;
this.publicKey = publicKey; this.publicKey = publicKey;
this.hdPublicKey = new HDPublicKey({ this.hdPrivateKey = this;
this.key = key;
};
HDPrivateKey.prototype.__defineGetter__('xpubkey', function() {
return this.hdPublicKey.xpubkey;
});
HDPrivateKey.prototype.__defineGetter__('hdPublicKey', function() {
if (!this._hdPublicKey) {
this._hdPublicKey = new HDPublicKey({
network: this.network, network: this.network,
data: { data: {
key: this.key,
version: network[this.network].prefixes.xpubkey, version: network[this.network].prefixes.xpubkey,
depth: this.depth, depth: this.depth,
parentFingerPrint: this.parentFingerPrint, parentFingerPrint: this.parentFingerPrint,
@ -719,11 +730,9 @@ HDPrivateKey.prototype._build = function _build(data) {
publicKey: this.publicKey publicKey: this.publicKey
} }
}); });
this.hdPrivateKey = this; }
return this._hdPublicKey;
this.xpubkey = this.hdPublicKey.xpubkey; });
this.key = key;
};
HDPrivateKey.prototype.derive = function derive(index, hardened) { HDPrivateKey.prototype.derive = function derive(index, hardened) {
var cached, data, hash, leftPart, chainCode, privateKey, child; var cached, data, hash, leftPart, chainCode, privateKey, child;
@ -1080,8 +1089,7 @@ HDPublicKey.prototype._build = function _build(data) {
this.xpubkey = xpubkey; this.xpubkey = xpubkey;
this.fingerPrint = fingerPrint; this.fingerPrint = fingerPrint;
this.xprivkey = data.xprivkey; this.key = data.key || bcoin.keypair({ publicKey: this.publicKey });
this.key = bcoin.keypair({ publicKey: this.publicKey });
}; };
HDPublicKey.prototype.derive = function derive(index, hardened) { HDPublicKey.prototype.derive = function derive(index, hardened) {