From 0f40d78f9ea1cafead2dccc0beb61d9544d02e66 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 23 Feb 2016 17:27:07 -0800 Subject: [PATCH] this is faster for some reason. --- lib/bcoin/hd.js | 50 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/lib/bcoin/hd.js b/lib/bcoin/hd.js index 4cb6f7ff..692b45db 100644 --- a/lib/bcoin/hd.js +++ b/lib/bcoin/hd.js @@ -702,37 +702,29 @@ HDPrivateKey.prototype._build = function _build(data) { this.privateKey = data.privateKey; this.checksum = null; - this.xprivkey = xprivkey; this.fingerPrint = fingerPrint; this.publicKey = publicKey; + this.key = key; this.hdPrivateKey = this; - this.key = key; + this.xprivkey = xprivkey; + + 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 + } + }); + this.xpubkey = this.hdPublicKey.xpubkey; }; -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; @@ -1084,11 +1076,15 @@ HDPublicKey.prototype._build = function _build(data) { this.publicKey = publicKey; this.checksum = null; + this.fingerPrint = fingerPrint; + this.privateKey = null; + this.key = data.key || bcoin.keypair({ publicKey: this.publicKey }); + this.hdPublicKey = this; this.xpubkey = xpubkey; - this.fingerPrint = fingerPrint; - this.key = data.key || bcoin.keypair({ publicKey: this.publicKey }); + this.hdPrivateKey = null; + this.xprivkey = null; }; HDPublicKey.prototype.derive = function derive(index, hardened) {