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,24 +707,33 @@ HDPrivateKey.prototype._build = function _build(data) {
this.fingerPrint = fingerPrint;
this.publicKey = publicKey;
this.hdPublicKey = new HDPublicKey({
network: this.network,
data: {
version: network[this.network].prefixes.xpubkey,
depth: this.depth,
parentFingerPrint: this.parentFingerPrint,
childIndex: this.childIndex,
chainCode: this.chainCode,
checksum: this.checksum,
publicKey: this.publicKey
}
});
this.hdPrivateKey = this;
this.xpubkey = this.hdPublicKey.xpubkey;
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,
data: {
key: this.key,
version: network[this.network].prefixes.xpubkey,
depth: this.depth,
parentFingerPrint: this.parentFingerPrint,
childIndex: this.childIndex,
chainCode: this.chainCode,
checksum: this.checksum,
publicKey: this.publicKey
}
});
}
return this._hdPublicKey;
});
HDPrivateKey.prototype.derive = function derive(index, hardened) {
var cached, data, hash, leftPart, chainCode, privateKey, child;
var off = 0;
@ -1080,8 +1089,7 @@ HDPublicKey.prototype._build = function _build(data) {
this.xpubkey = xpubkey;
this.fingerPrint = fingerPrint;
this.xprivkey = data.xprivkey;
this.key = bcoin.keypair({ publicKey: this.publicKey });
this.key = data.key || bcoin.keypair({ publicKey: this.publicKey });
};
HDPublicKey.prototype.derive = function derive(index, hardened) {