aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Serrano <kevgagser@gmail.com>2016-11-12 07:40:12 +0800
committerKevin Serrano <kevgagser@gmail.com>2016-11-12 07:40:12 +0800
commitbfeaae69f2a0c845d8ebfa907a90049f53ba3aea (patch)
tree79d2415b1cd5b0e3853b0204448fb770e462ab89
parent7012747fb546bc1a95ce65b71bd3f74075150b77 (diff)
downloadtangerine-wallet-browser-bfeaae69f2a0c845d8ebfa907a90049f53ba3aea.tar
tangerine-wallet-browser-bfeaae69f2a0c845d8ebfa907a90049f53ba3aea.tar.gz
tangerine-wallet-browser-bfeaae69f2a0c845d8ebfa907a90049f53ba3aea.tar.bz2
tangerine-wallet-browser-bfeaae69f2a0c845d8ebfa907a90049f53ba3aea.tar.lz
tangerine-wallet-browser-bfeaae69f2a0c845d8ebfa907a90049f53ba3aea.tar.xz
tangerine-wallet-browser-bfeaae69f2a0c845d8ebfa907a90049f53ba3aea.tar.zst
tangerine-wallet-browser-bfeaae69f2a0c845d8ebfa907a90049f53ba3aea.zip
Clarify functions names. Package normalize inside util file. Fix require headers.
-rw-r--r--app/scripts/keyrings/hd.js19
1 files 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())
-}