mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-22 17:33:23 +01:00
Merge branch 'dev' into dev-cleanup
This commit is contained in:
commit
8261cf232d
@ -5,6 +5,7 @@
|
|||||||
- Add support for the new, default Ropsten Test Network.
|
- 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 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.
|
- 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
|
## 2.13.8 2016-11-16
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
currentFiat: this.configManager.getCurrentFiat(),
|
currentFiat: this.configManager.getCurrentFiat(),
|
||||||
conversionRate: this.configManager.getConversionRate(),
|
conversionRate: this.configManager.getConversionRate(),
|
||||||
conversionDate: this.configManager.getConversionDate(),
|
conversionDate: this.configManager.getConversionDate(),
|
||||||
keyringTypes: this.keyringTypes.map((krt) => krt.type()),
|
keyringTypes: this.keyringTypes.map(krt => krt.type),
|
||||||
identities: this.identities,
|
identities: this.identities,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -310,7 +310,7 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
|
|
||||||
getKeyringClassForType (type) {
|
getKeyringClassForType (type) {
|
||||||
const Keyring = this.keyringTypes.reduce((res, kr) => {
|
const Keyring = this.keyringTypes.reduce((res, kr) => {
|
||||||
if (kr.type() === type) {
|
if (kr.type === type) {
|
||||||
return kr
|
return kr
|
||||||
} else {
|
} else {
|
||||||
return res
|
return res
|
||||||
|
@ -2,17 +2,17 @@ const EventEmitter = require('events').EventEmitter
|
|||||||
const hdkey = require('ethereumjs-wallet/hdkey')
|
const hdkey = require('ethereumjs-wallet/hdkey')
|
||||||
const bip39 = require('bip39')
|
const bip39 = require('bip39')
|
||||||
const ethUtil = require('ethereumjs-util')
|
const ethUtil = require('ethereumjs-util')
|
||||||
|
|
||||||
|
// *Internal Deps
|
||||||
const sigUtil = require('../lib/sig-util')
|
const sigUtil = require('../lib/sig-util')
|
||||||
|
|
||||||
|
// Options:
|
||||||
|
const hdPathString = `m/44'/60'/0'/0`
|
||||||
const type = 'HD Key Tree'
|
const type = 'HD Key Tree'
|
||||||
|
|
||||||
const hdPathString = `m/44'/60'/0'/0`
|
class HdKeyring extends EventEmitter {
|
||||||
|
|
||||||
module.exports = class HdKeyring extends EventEmitter {
|
/* PUBLIC METHODS */
|
||||||
|
|
||||||
static type () {
|
|
||||||
return type
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor (opts = {}) {
|
constructor (opts = {}) {
|
||||||
super()
|
super()
|
||||||
@ -20,28 +20,6 @@ module.exports = class HdKeyring extends EventEmitter {
|
|||||||
this.deserialize(opts)
|
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 () {
|
serialize () {
|
||||||
return {
|
return {
|
||||||
mnemonic: this.mnemonic,
|
mnemonic: this.mnemonic,
|
||||||
@ -49,14 +27,24 @@ module.exports = class HdKeyring extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exportAccount (address) {
|
deserialize (opts = {}) {
|
||||||
const wallet = this.getWalletForAccount(address)
|
this.opts = opts || {}
|
||||||
return wallet.getPrivateKey().toString('hex')
|
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) {
|
addAccounts (numberOfAccounts = 1) {
|
||||||
if (!this.root) {
|
if (!this.root) {
|
||||||
this.initFromMnemonic(bip39.generateMnemonic())
|
this._initFromMnemonic(bip39.generateMnemonic())
|
||||||
}
|
}
|
||||||
|
|
||||||
const oldLen = this.wallets.length
|
const oldLen = this.wallets.length
|
||||||
@ -76,7 +64,7 @@ module.exports = class HdKeyring extends EventEmitter {
|
|||||||
|
|
||||||
// tx is an instance of the ethereumjs-transaction class.
|
// tx is an instance of the ethereumjs-transaction class.
|
||||||
signTransaction (address, tx) {
|
signTransaction (address, tx) {
|
||||||
const wallet = this.getWalletForAccount(address)
|
const wallet = this._getWalletForAccount(address)
|
||||||
var privKey = wallet.getPrivateKey()
|
var privKey = wallet.getPrivateKey()
|
||||||
tx.sign(privKey)
|
tx.sign(privKey)
|
||||||
return tx
|
return tx
|
||||||
@ -84,7 +72,7 @@ module.exports = class HdKeyring extends EventEmitter {
|
|||||||
|
|
||||||
// For eth_sign, we need to sign transactions:
|
// For eth_sign, we need to sign transactions:
|
||||||
signMessage (withAccount, data) {
|
signMessage (withAccount, data) {
|
||||||
const wallet = this.getWalletForAccount(withAccount)
|
const wallet = this._getWalletForAccount(withAccount)
|
||||||
const message = ethUtil.removeHexPrefix(data)
|
const message = ethUtil.removeHexPrefix(data)
|
||||||
var privKey = wallet.getPrivateKey()
|
var privKey = wallet.getPrivateKey()
|
||||||
var msgSig = ethUtil.ecsign(new Buffer(message, 'hex'), privKey)
|
var msgSig = ethUtil.ecsign(new Buffer(message, 'hex'), privKey)
|
||||||
@ -92,10 +80,29 @@ module.exports = class HdKeyring extends EventEmitter {
|
|||||||
return rawMsgSig
|
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) => {
|
return this.wallets.find((w) => {
|
||||||
const address = w.getAddress().toString('hex')
|
const address = w.getAddress().toString('hex')
|
||||||
return ((address === account) || (sigUtil.normalize(address) === account))
|
return ((address === account) || (sigUtil.normalize(address) === account))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HdKeyring.type = type
|
||||||
|
module.exports = HdKeyring
|
||||||
|
@ -4,7 +4,9 @@ const ethUtil = require('ethereumjs-util')
|
|||||||
const type = 'Simple Key Pair'
|
const type = 'Simple Key Pair'
|
||||||
const sigUtil = require('../lib/sig-util')
|
const sigUtil = require('../lib/sig-util')
|
||||||
|
|
||||||
module.exports = class SimpleKeyring extends EventEmitter {
|
class SimpleKeyring extends EventEmitter {
|
||||||
|
|
||||||
|
/* PUBLIC METHODS */
|
||||||
|
|
||||||
static type () {
|
static type () {
|
||||||
return type
|
return type
|
||||||
@ -44,7 +46,7 @@ module.exports = class SimpleKeyring extends EventEmitter {
|
|||||||
|
|
||||||
// tx is an instance of the ethereumjs-transaction class.
|
// tx is an instance of the ethereumjs-transaction class.
|
||||||
signTransaction (address, tx) {
|
signTransaction (address, tx) {
|
||||||
const wallet = this.getWalletForAccount(address)
|
const wallet = this._getWalletForAccount(address)
|
||||||
var privKey = wallet.getPrivateKey()
|
var privKey = wallet.getPrivateKey()
|
||||||
tx.sign(privKey)
|
tx.sign(privKey)
|
||||||
return tx
|
return tx
|
||||||
@ -52,7 +54,7 @@ module.exports = class SimpleKeyring extends EventEmitter {
|
|||||||
|
|
||||||
// For eth_sign, we need to sign transactions:
|
// For eth_sign, we need to sign transactions:
|
||||||
signMessage (withAccount, data) {
|
signMessage (withAccount, data) {
|
||||||
const wallet = this.getWalletForAccount(withAccount)
|
const wallet = this._getWalletForAccount(withAccount)
|
||||||
const message = ethUtil.removeHexPrefix(data)
|
const message = ethUtil.removeHexPrefix(data)
|
||||||
var privKey = wallet.getPrivateKey()
|
var privKey = wallet.getPrivateKey()
|
||||||
var msgSig = ethUtil.ecsign(new Buffer(message, 'hex'), privKey)
|
var msgSig = ethUtil.ecsign(new Buffer(message, 'hex'), privKey)
|
||||||
@ -60,8 +62,19 @@ module.exports = class SimpleKeyring extends EventEmitter {
|
|||||||
return rawMsgSig
|
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)
|
return this.wallets.find(w => w.getAddress().toString('hex') === account)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SimpleKeyring.type = type
|
||||||
|
module.exports = SimpleKeyring
|
||||||
|
@ -347,7 +347,7 @@ module.exports = class MetamaskController {
|
|||||||
var network = this.state.network
|
var network = this.state.network
|
||||||
var url = `https://buy.coinbase.com/?code=9ec56d01-7e81-5017-930c-513daa27bb6a&amount=${amount}&address=${address}&crypto_currency=ETH`
|
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/'
|
url = 'https://faucet.metamask.io/'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,9 +27,9 @@ describe('hd-keyring', function() {
|
|||||||
assert.equal(accounts[1], secondAcct)
|
assert.equal(accounts[1], secondAcct)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Keyring.type()', function() {
|
describe('Keyring.type', function() {
|
||||||
it('is a class method that returns the type string.', function() {
|
it('is a class property that returns the type string.', function() {
|
||||||
const type = HdKeyring.type()
|
const type = HdKeyring.type
|
||||||
assert.equal(typeof type, 'string')
|
assert.equal(typeof type, 'string')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -37,7 +37,7 @@ describe('hd-keyring', function() {
|
|||||||
describe('#type', function() {
|
describe('#type', function() {
|
||||||
it('returns the correct value', function() {
|
it('returns the correct value', function() {
|
||||||
const type = keyring.type
|
const type = keyring.type
|
||||||
const correct = HdKeyring.type()
|
const correct = HdKeyring.type
|
||||||
assert.equal(type, correct)
|
assert.equal(type, correct)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -13,9 +13,9 @@ describe('simple-keyring', function() {
|
|||||||
keyring = new SimpleKeyring()
|
keyring = new SimpleKeyring()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Keyring.type()', function() {
|
describe('Keyring.type', function() {
|
||||||
it('is a class method that returns the type string.', function() {
|
it('is a class property that returns the type string.', function() {
|
||||||
const type = SimpleKeyring.type()
|
const type = SimpleKeyring.type
|
||||||
assert.equal(type, TYPE_STR)
|
assert.equal(type, TYPE_STR)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -114,8 +114,8 @@ BuyButtonSubview.prototype.formVersionSubview = function () {
|
|||||||
width: '225px',
|
width: '225px',
|
||||||
},
|
},
|
||||||
}, 'In order to access this feature please switch to the Main Network'),
|
}, 'In order to access this feature please switch to the Main Network'),
|
||||||
h('h3.text-transform-uppercase', 'or:'),
|
this.props.network === '3' ? h('h3.text-transform-uppercase', 'or:') : null,
|
||||||
this.props.network === '2' ? h('button.text-transform-uppercase', {
|
this.props.network === '3' ? h('button.text-transform-uppercase', {
|
||||||
onClick: () => this.props.dispatch(actions.buyEth()),
|
onClick: () => this.props.dispatch(actions.buyEth()),
|
||||||
style: {
|
style: {
|
||||||
marginTop: '15px',
|
marginTop: '15px',
|
||||||
|
Loading…
Reference in New Issue
Block a user