From be6b7b496a95fa036161b6c600eadd733676e954 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 21 Nov 2016 19:18:46 -0800 Subject: [PATCH 1/5] Fixed account link test for ropsten network --- test/unit/account-link-test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/account-link-test.js b/test/unit/account-link-test.js index 39889b6be..08d190f71 100644 --- a/test/unit/account-link-test.js +++ b/test/unit/account-link-test.js @@ -3,8 +3,8 @@ var linkGen = require('../../ui/lib/account-link') describe('account-link', function() { - it('adds testnet prefix to morden test network', function() { - var result = linkGen('account', '2') + it('adds testnet prefix to ropsten test network', function() { + var result = linkGen('account', '3') assert.notEqual(result.indexOf('testnet'), -1, 'testnet injected') assert.notEqual(result.indexOf('account'), -1, 'account included') }) From ecfda5bcc54bc444f3620a18a561847d0d2634dd Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 21 Nov 2016 19:39:19 -0800 Subject: [PATCH 2/5] Revert premature link test fix --- test/unit/account-link-test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/account-link-test.js b/test/unit/account-link-test.js index 08d190f71..39889b6be 100644 --- a/test/unit/account-link-test.js +++ b/test/unit/account-link-test.js @@ -3,8 +3,8 @@ var linkGen = require('../../ui/lib/account-link') describe('account-link', function() { - it('adds testnet prefix to ropsten test network', function() { - var result = linkGen('account', '3') + it('adds testnet prefix to morden test network', function() { + var result = linkGen('account', '2') assert.notEqual(result.indexOf('testnet'), -1, 'testnet injected') assert.notEqual(result.indexOf('account'), -1, 'account included') }) From ced36eb20186b0f1bf0c744ac31a5b7804120065 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 21 Nov 2016 19:40:30 -0800 Subject: [PATCH 3/5] Improve Keyring organization Separated public & private methods. (Fixes #845) Made class method `type()` into a simple property. (Fixes #846) --- app/scripts/keyring-controller.js | 4 +- app/scripts/keyrings/hd.js | 77 +++++++++++++++++-------------- app/scripts/keyrings/simple.js | 21 +++++++-- test/unit/keyrings/hd-test.js | 6 +-- test/unit/keyrings/simple-test.js | 6 +-- 5 files changed, 67 insertions(+), 47 deletions(-) diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js index cf761c88c..fdef9d7b3 100644 --- a/app/scripts/keyring-controller.js +++ b/app/scripts/keyring-controller.js @@ -67,7 +67,7 @@ module.exports = class KeyringController extends EventEmitter { currentFiat: this.configManager.getCurrentFiat(), conversionRate: this.configManager.getConversionRate(), conversionDate: this.configManager.getConversionDate(), - keyringTypes: this.keyringTypes.map((krt) => krt.type()), + keyringTypes: this.keyringTypes.map(krt => krt.type), identities: this.identities, } } @@ -312,7 +312,7 @@ module.exports = class KeyringController extends EventEmitter { getKeyringClassForType (type) { const Keyring = this.keyringTypes.reduce((res, kr) => { - if (kr.type() === type) { + if (kr.type === type) { return kr } else { return res diff --git a/app/scripts/keyrings/hd.js b/app/scripts/keyrings/hd.js index b98f29187..a28ef6736 100644 --- a/app/scripts/keyrings/hd.js +++ b/app/scripts/keyrings/hd.js @@ -2,17 +2,17 @@ const EventEmitter = require('events').EventEmitter const hdkey = require('ethereumjs-wallet/hdkey') const bip39 = require('bip39') const ethUtil = require('ethereumjs-util') + +// *Internal Deps const sigUtil = require('../lib/sig-util') +// Options: +const hdPathString = `m/44'/60'/0'/0` const type = 'HD Key Tree' -const hdPathString = `m/44'/60'/0'/0` +class HdKeyring extends EventEmitter { -module.exports = class HdKeyring extends EventEmitter { - - static type () { - return type - } + /* PUBLIC METHODS */ constructor (opts = {}) { super() @@ -20,28 +20,6 @@ module.exports = class HdKeyring extends EventEmitter { this.deserialize(opts) } - deserialize (opts = {}) { - this.opts = opts || {} - this.wallets = [] - this.mnemonic = null - this.root = null - - if ('mnemonic' in opts) { - this.initFromMnemonic(opts.mnemonic) - } - - if ('numberOfAccounts' in opts) { - this.addAccounts(opts.numberOfAccounts) - } - } - - initFromMnemonic (mnemonic) { - this.mnemonic = mnemonic - const seed = bip39.mnemonicToSeed(mnemonic) - this.hdWallet = hdkey.fromMasterSeed(seed) - this.root = this.hdWallet.derivePath(hdPathString) - } - serialize () { return { mnemonic: this.mnemonic, @@ -49,14 +27,24 @@ module.exports = class HdKeyring extends EventEmitter { } } - exportAccount (address) { - const wallet = this.getWalletForAccount(address) - return wallet.getPrivateKey().toString('hex') + deserialize (opts = {}) { + this.opts = opts || {} + this.wallets = [] + this.mnemonic = null + this.root = null + + if ('mnemonic' in opts) { + this._initFromMnemonic(opts.mnemonic) + } + + if ('numberOfAccounts' in opts) { + this.addAccounts(opts.numberOfAccounts) + } } addAccounts (numberOfAccounts = 1) { if (!this.root) { - this.initFromMnemonic(bip39.generateMnemonic()) + this._initFromMnemonic(bip39.generateMnemonic()) } const oldLen = this.wallets.length @@ -76,7 +64,7 @@ module.exports = class HdKeyring extends EventEmitter { // tx is an instance of the ethereumjs-transaction class. signTransaction (address, tx) { - const wallet = this.getWalletForAccount(address) + const wallet = this._getWalletForAccount(address) var privKey = wallet.getPrivateKey() tx.sign(privKey) return tx @@ -84,7 +72,7 @@ module.exports = class HdKeyring extends EventEmitter { // For eth_sign, we need to sign transactions: signMessage (withAccount, data) { - const wallet = this.getWalletForAccount(withAccount) + const wallet = this._getWalletForAccount(withAccount) const message = ethUtil.removeHexPrefix(data) var privKey = wallet.getPrivateKey() var msgSig = ethUtil.ecsign(new Buffer(message, 'hex'), privKey) @@ -92,10 +80,29 @@ module.exports = class HdKeyring extends EventEmitter { return rawMsgSig } - getWalletForAccount (account) { + exportAccount (address) { + const wallet = this._getWalletForAccount(address) + return wallet.getPrivateKey().toString('hex') + } + + + /* PRIVATE METHODS */ + + _initFromMnemonic (mnemonic) { + this.mnemonic = mnemonic + const seed = bip39.mnemonicToSeed(mnemonic) + this.hdWallet = hdkey.fromMasterSeed(seed) + this.root = this.hdWallet.derivePath(hdPathString) + } + + + _getWalletForAccount (account) { return this.wallets.find((w) => { const address = w.getAddress().toString('hex') return ((address === account) || (sigUtil.normalize(address) === account)) }) } } + +HdKeyring.type = type +module.exports = HdKeyring diff --git a/app/scripts/keyrings/simple.js b/app/scripts/keyrings/simple.js index ee743bc03..4fdccc4f7 100644 --- a/app/scripts/keyrings/simple.js +++ b/app/scripts/keyrings/simple.js @@ -4,7 +4,9 @@ const ethUtil = require('ethereumjs-util') const type = 'Simple Key Pair' const sigUtil = require('../lib/sig-util') -module.exports = class SimpleKeyring extends EventEmitter { +class SimpleKeyring extends EventEmitter { + + /* PUBLIC METHODS */ static type () { return type @@ -44,7 +46,7 @@ module.exports = class SimpleKeyring extends EventEmitter { // tx is an instance of the ethereumjs-transaction class. signTransaction (address, tx) { - const wallet = this.getWalletForAccount(address) + const wallet = this._getWalletForAccount(address) var privKey = wallet.getPrivateKey() tx.sign(privKey) return tx @@ -52,7 +54,7 @@ module.exports = class SimpleKeyring extends EventEmitter { // For eth_sign, we need to sign transactions: signMessage (withAccount, data) { - const wallet = this.getWalletForAccount(withAccount) + const wallet = this._getWalletForAccount(withAccount) const message = ethUtil.removeHexPrefix(data) var privKey = wallet.getPrivateKey() var msgSig = ethUtil.ecsign(new Buffer(message, 'hex'), privKey) @@ -60,8 +62,19 @@ module.exports = class SimpleKeyring extends EventEmitter { return rawMsgSig } - getWalletForAccount (account) { + exportAccount (address) { + const wallet = this._getWalletForAccount(address) + return wallet.getPrivateKey().toString('hex') + } + + + /* PRIVATE METHODS */ + + _getWalletForAccount (account) { return this.wallets.find(w => w.getAddress().toString('hex') === account) } } + +SimpleKeyring.type = type +module.exports = SimpleKeyring diff --git a/test/unit/keyrings/hd-test.js b/test/unit/keyrings/hd-test.js index c22ffc913..b841cd194 100644 --- a/test/unit/keyrings/hd-test.js +++ b/test/unit/keyrings/hd-test.js @@ -27,9 +27,9 @@ describe('hd-keyring', function() { assert.equal(accounts[1], secondAcct) }) - describe('Keyring.type()', function() { - it('is a class method that returns the type string.', function() { - const type = HdKeyring.type() + describe('Keyring.type', function() { + it('is a class property that returns the type string.', function() { + const type = HdKeyring.type assert.equal(typeof type, 'string') }) }) diff --git a/test/unit/keyrings/simple-test.js b/test/unit/keyrings/simple-test.js index ba000a7a8..96a2fdcf0 100644 --- a/test/unit/keyrings/simple-test.js +++ b/test/unit/keyrings/simple-test.js @@ -13,9 +13,9 @@ describe('simple-keyring', function() { keyring = new SimpleKeyring() }) - describe('Keyring.type()', function() { - it('is a class method that returns the type string.', function() { - const type = SimpleKeyring.type() + describe('Keyring.type', function() { + it('is a class property that returns the type string.', function() { + const type = SimpleKeyring.type assert.equal(type, TYPE_STR) }) }) From 60afc41bb65547ace5e3a16b9c743a0dbf36d58a Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 21 Nov 2016 19:47:45 -0800 Subject: [PATCH 4/5] Fix keyring test --- test/unit/keyrings/hd-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/keyrings/hd-test.js b/test/unit/keyrings/hd-test.js index b841cd194..bec1a8134 100644 --- a/test/unit/keyrings/hd-test.js +++ b/test/unit/keyrings/hd-test.js @@ -37,7 +37,7 @@ describe('hd-keyring', function() { describe('#type', function() { it('returns the correct value', function() { const type = keyring.type - const correct = HdKeyring.type() + const correct = HdKeyring.type assert.equal(type, correct) }) }) From 17669e4af8538e4b37bad69ec64fefecb7b1ef4e Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Tue, 22 Nov 2016 10:20:59 -0800 Subject: [PATCH 5/5] Make ropsten faucet button point at the correct url. --- CHANGELOG.md | 1 + app/scripts/metamask-controller.js | 2 +- ui/app/components/buy-button-subview.js | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b8e7e216..d40ab5a74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Add support for the new, default Ropsten Test Network. - Fix bug that would cause MetaMask to occasionally lose its StreamProvider connection and drop requests. - Fix bug that would cause the Custom RPC menu item to not appear when Localhost 8545 was selected. +- Point ropsten faucet button to actual faucet. ## 2.13.8 2016-11-16 diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 951918460..168a1cf59 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -341,7 +341,7 @@ module.exports = class MetamaskController { var network = this.state.network var url = `https://buy.coinbase.com/?code=9ec56d01-7e81-5017-930c-513daa27bb6a&amount=${amount}&address=${address}&crypto_currency=ETH` - if (network === '2') { + if (network === '3') { url = 'https://faucet.metamask.io/' } diff --git a/ui/app/components/buy-button-subview.js b/ui/app/components/buy-button-subview.js index b564733b1..0dd8c4946 100644 --- a/ui/app/components/buy-button-subview.js +++ b/ui/app/components/buy-button-subview.js @@ -114,8 +114,8 @@ BuyButtonSubview.prototype.formVersionSubview = function () { width: '225px', }, }, 'In order to access this feature please switch to the Main Network'), - h('h3.text-transform-uppercase', 'or:'), - this.props.network === '2' ? h('button.text-transform-uppercase', { + this.props.network === '3' ? h('h3.text-transform-uppercase', 'or:') : null, + this.props.network === '3' ? h('button.text-transform-uppercase', { onClick: () => this.props.dispatch(actions.buyEth()), style: { marginTop: '15px',