aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
authorKevin Serrano <kevgagser@gmail.com>2016-11-02 02:25:38 +0800
committerKevin Serrano <kevgagser@gmail.com>2016-11-02 02:30:10 +0800
commitdb356a181a3fde4ad528c699f6da517053171866 (patch)
treeba339827fef6685e097d6fc247dae47f3d0a8f70 /app/scripts
parente2f67a2cb85552bd8fcf2f7929c14a9d028adccb (diff)
downloadtangerine-wallet-browser-db356a181a3fde4ad528c699f6da517053171866.tar.gz
tangerine-wallet-browser-db356a181a3fde4ad528c699f6da517053171866.tar.zst
tangerine-wallet-browser-db356a181a3fde4ad528c699f6da517053171866.zip
Made progress on parity for MultiVault
- Deleted some unused items - Renamed files and paths to match with new locations. - Modified keyring controller logic to separate concerns. - Fix account naming issues. - Enable creation of new vault with default HD keyring. - Formatting issues.
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/background.js2
-rw-r--r--app/scripts/keyring-controller.js65
-rw-r--r--app/scripts/keyrings/hd.js18
-rw-r--r--app/scripts/metamask-controller.js3
4 files changed, 60 insertions, 28 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index 27c9179a7..7cb25d8bf 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -30,7 +30,7 @@ function triggerUi () {
// On first install, open a window to MetaMask website to how-it-works.
extension.runtime.onInstalled.addListener(function (details) {
- if ((details.reason === 'install') && (!METAMASK_DEBUG)) {
+ if ((details.reason === 'install') && (!METAMASK_DEBUG)) {
extension.tabs.create({url: 'https://metamask.io/#how-it-works'})
}
})
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js
index ee6445121..f6e71b005 100644
--- a/app/scripts/keyring-controller.js
+++ b/app/scripts/keyring-controller.js
@@ -70,6 +70,23 @@ module.exports = class KeyringController extends EventEmitter {
this.ethStore = ethStore
}
+ createNewVaultAndKeychain(password, entropy, cb) {
+ this.createNewVault(password, entropy, (err, serialized) => {
+ if (err) return cb(err)
+ this.createFirstKeyTree(serialized, password, cb)
+ })
+ }
+
+ createNewVaultAndRestore(password, seed, cb) {
+ this.createNewVault(password, '', (err) => {
+ if (err) return cb(err)
+ this.addNewKeyring('HD Key Tree', {
+ mnemonic: seed,
+ n: 0,
+ }, cb)
+ })
+ }
+
createNewVault(password, entropy, cb) {
const salt = this.encryptor.generateSalt()
this.configManager.setSalt(salt)
@@ -89,22 +106,7 @@ module.exports = class KeyringController extends EventEmitter {
})
.then((encryptedString) => {
this.configManager.setVault(encryptedString)
-
- if (!serialized) {
- this.addNewKeyring('HD Key Tree', null, (err, newState) => {
- const firstKeyring = this.keyrings[0]
- const firstAccount = firstKeyring.getAccounts()[0]
- const hexAccount = ethUtil.addHexPrefix(firstAccount)
- const seedWords = firstKeyring.serialize().mnemonic
- this.configManager.setSelectedAccount(hexAccount)
- this.configManager.setSeedWords(seedWords)
- autoFaucet(hexAccount)
- cb(err, newState)
- })
- } else {
- return this.submitPassword(password, cb)
- }
-
+ cb(null, serialized)
// NORMAL BEHAVIOR:
// return cb(null, this.getState())
})
@@ -113,6 +115,23 @@ module.exports = class KeyringController extends EventEmitter {
})
}
+ createFirstKeyTree(serialized, password, cb) {
+ if (!serialized) {
+ this.addNewKeyring('HD Key Tree', {n: 1}, (err, newState) => {
+ const firstKeyring = this.keyrings[0]
+ const firstAccount = firstKeyring.getAccounts()[0]
+ const hexAccount = ethUtil.addHexPrefix(firstAccount)
+ const seedWords = firstKeyring.serialize().mnemonic
+ this.configManager.setSelectedAccount(hexAccount)
+ this.configManager.setSeedWords(seedWords)
+ autoFaucet(hexAccount)
+ cb(err, this.getState())
+ })
+ } else {
+ return this.submitPassword(password, cb)
+ }
+ }
+
submitPassword(password, cb) {
this.loadKey(password)
.then((key) => {
@@ -139,10 +158,10 @@ module.exports = class KeyringController extends EventEmitter {
addNewKeyring(type, opts, cb) {
const Keyring = this.getKeyringClassForType(type)
const keyring = new Keyring(opts)
- const accounts = keyring.addAccounts(1)
+ const accounts = keyring.getAccounts()
- this.setupAccounts(accounts)
this.keyrings.push(keyring)
+ this.setupAccounts(accounts)
this.persistAllKeyrings()
.then(() => {
cb(null, this.getState())
@@ -160,17 +179,21 @@ module.exports = class KeyringController extends EventEmitter {
}
setupAccounts(accounts) {
- const i = this.getAccounts().length
accounts.forEach((account) => {
- this.loadBalanceAndNickname(account, i)
+ this.loadBalanceAndNickname(account)
})
}
// Takes an account address and an iterator representing
// the current number of named accounts.
- loadBalanceAndNickname(account, i) {
+ loadBalanceAndNickname(account) {
const address = ethUtil.addHexPrefix(account)
this.ethStore.addAccount(address)
+ this.createNickname(address)
+ }
+
+ createNickname(address) {
+ var i = Object.keys(this.identities).length
const oldNickname = this.configManager.nicknameForWallet(address)
const name = oldNickname || `Account ${++i}`
this.identities[address] = {
diff --git a/app/scripts/keyrings/hd.js b/app/scripts/keyrings/hd.js
index 61df8f28e..69b8d25bc 100644
--- a/app/scripts/keyrings/hd.js
+++ b/app/scripts/keyrings/hd.js
@@ -17,13 +17,22 @@ module.exports = class HdKeyring extends EventEmitter {
super()
this.type = type
this.opts = opts || {}
+ this.deserialize(opts)
+ }
+
+ deserialize(opts) {
this.wallets = []
this.mnemonic = null
- }
+ this.root = null
+
+ if ('mnemonic' in opts) {
+ this.initFromMnemonic(opts.mnemonic)
+ }
+
+ if ('n' in opts) {
+ this.addAccounts(opts.n)
+ }
- deserialize({ mnemonic, n }) {
- this.initFromMnemonic(mnemonic || bip39.generateMnemonic())
- this.addAccounts(n)
}
initFromMnemonic(mnemonic) {
@@ -83,4 +92,3 @@ module.exports = class HdKeyring extends EventEmitter {
}
}
-
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 48c56d915..7ce22b642 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -59,7 +59,8 @@ module.exports = class MetamaskController {
setGasMultiplier: this.setGasMultiplier.bind(this),
// forward directly to keyringController
- createNewVault: keyringController.createNewVault.bind(keyringController),
+ createNewVaultAndKeychain: keyringController.createNewVaultAndKeychain.bind(keyringController),
+ createNewVaultAndRestore: keyringController.createNewVaultAndRestore.bind(keyringController),
clearSeedWordCache: keyringController.clearSeedWordCache.bind(keyringController),
addNewKeyring: keyringController.addNewKeyring.bind(keyringController),
addNewAccount: keyringController.addNewAccount.bind(keyringController),