From 21266570d49851b9c40577fb4c7f5322967c2d8f Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Mon, 16 Mar 2015 13:01:00 -0300 Subject: [PATCH] refactor code --- lib/hdprivatekey.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/hdprivatekey.js b/lib/hdprivatekey.js index a5e7b1e..08052ef 100644 --- a/lib/hdprivatekey.js +++ b/lib/hdprivatekey.js @@ -365,6 +365,15 @@ HDPrivateKey.fromSeed = function(hexa, network) { }); }; + + +HDPrivateKey.prototype._calcHDPublicKey = function() { + if (!this._hdPublicKey) { + var HDPublicKey = require('./hdpublickey'); + this._hdPublicKey = new HDPublicKey(this); + } +}; + /** * Receives a object with buffers in all the properties and populates the * internal structure @@ -424,14 +433,12 @@ HDPrivateKey.prototype._buildFromBuffers = function(arg) { }); 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); - } + this._calcHDPublicKey(); return this._hdPublicKey; } }); @@ -439,10 +446,7 @@ HDPrivateKey.prototype._buildFromBuffers = function(arg) { configurable: false, enumerable: true, get: function() { - if (!this._hdPublicKey) { - var HDPublicKey = require('./hdpublickey'); - this._hdPublicKey = new HDPublicKey(this); - } + this._calcHDPublicKey(); return this._hdPublicKey.xpubkey; } });