From bfeaae69f2a0c845d8ebfa907a90049f53ba3aea Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Fri, 11 Nov 2016 15:40:12 -0800 Subject: [PATCH] Clarify functions names. Package normalize inside util file. Fix require headers. --- app/scripts/keyrings/hd.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/app/scripts/keyrings/hd.js b/app/scripts/keyrings/hd.js index 6df78555d..b98f29187 100644 --- a/app/scripts/keyrings/hd.js +++ b/app/scripts/keyrings/hd.js @@ -2,9 +2,10 @@ const EventEmitter = require('events').EventEmitter const hdkey = require('ethereumjs-wallet/hdkey') const bip39 = require('bip39') const ethUtil = require('ethereumjs-util') -const type = 'HD Key Tree' const sigUtil = require('../lib/sig-util') +const type = 'HD Key Tree' + const hdPathString = `m/44'/60'/0'/0` module.exports = class HdKeyring extends EventEmitter { @@ -29,8 +30,8 @@ module.exports = class HdKeyring extends EventEmitter { this.initFromMnemonic(opts.mnemonic) } - if ('n' in opts) { - this.addAccounts(opts.n) + if ('numberOfAccounts' in opts) { + this.addAccounts(opts.numberOfAccounts) } } @@ -44,7 +45,7 @@ module.exports = class HdKeyring extends EventEmitter { serialize () { return { mnemonic: this.mnemonic, - n: this.wallets.length, + numberOfAccounts: this.wallets.length, } } @@ -53,14 +54,14 @@ module.exports = class HdKeyring extends EventEmitter { return wallet.getPrivateKey().toString('hex') } - addAccounts (n = 1) { + addAccounts (numberOfAccounts = 1) { if (!this.root) { this.initFromMnemonic(bip39.generateMnemonic()) } const oldLen = this.wallets.length const newWallets = [] - for (let i = oldLen; i < n + oldLen; i++) { + for (let i = oldLen; i < numberOfAccounts + oldLen; i++) { const child = this.root.deriveChild(i) const wallet = child.getWallet() newWallets.push(wallet) @@ -94,11 +95,7 @@ module.exports = class HdKeyring extends EventEmitter { getWalletForAccount (account) { return this.wallets.find((w) => { const address = w.getAddress().toString('hex') - return ((address === account) || (normalize(address) === account)) + return ((address === account) || (sigUtil.normalize(address) === account)) }) } } - -function normalize (address) { - return ethUtil.addHexPrefix(address.toLowerCase()) -}