mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
Linting to the max.
This commit is contained in:
parent
c664b8f11e
commit
23263bec7d
@ -6,7 +6,7 @@ const extension = require('./lib/extension')
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const inpageText = fs.readFileSync(path.join(__dirname + '/inpage.js')).toString()
|
||||
const inpageText = fs.readFileSync(path.join(__dirname, 'inpage.js')).toString()
|
||||
|
||||
// Eventually this streaming injection could be replaced with:
|
||||
// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.exportFunction
|
||||
@ -20,9 +20,8 @@ if (shouldInjectWeb3()) {
|
||||
setupStreams()
|
||||
}
|
||||
|
||||
function setupInjection(){
|
||||
function setupInjection () {
|
||||
try {
|
||||
|
||||
// inject in-page script
|
||||
var scriptTag = document.createElement('script')
|
||||
scriptTag.src = extension.extension.getURL('scripts/inpage.js')
|
||||
@ -31,14 +30,12 @@ function setupInjection(){
|
||||
var container = document.head || document.documentElement
|
||||
// append as first child
|
||||
container.insertBefore(scriptTag, container.children[0])
|
||||
|
||||
} catch (e) {
|
||||
console.error('Metamask injection failed.', e)
|
||||
}
|
||||
}
|
||||
|
||||
function setupStreams(){
|
||||
|
||||
function setupStreams () {
|
||||
// setup communication to page and plugin
|
||||
var pageStream = new LocalMessageDuplexStream({
|
||||
name: 'contentscript',
|
||||
@ -65,14 +62,13 @@ function setupStreams(){
|
||||
mx.ignoreStream('provider')
|
||||
mx.ignoreStream('publicConfig')
|
||||
mx.ignoreStream('reload')
|
||||
|
||||
}
|
||||
|
||||
function shouldInjectWeb3(){
|
||||
function shouldInjectWeb3 () {
|
||||
return isAllowedSuffix(window.location.href)
|
||||
}
|
||||
|
||||
function isAllowedSuffix(testCase) {
|
||||
function isAllowedSuffix (testCase) {
|
||||
var prohibitedTypes = ['xml', 'pdf']
|
||||
var currentUrl = window.location.href
|
||||
var currentRegex
|
||||
|
@ -43,7 +43,7 @@ reloadStream.once('data', triggerReload)
|
||||
var pingChannel = inpageProvider.multiStream.createStream('pingpong')
|
||||
var pingStream = new PingStream({ objectMode: true })
|
||||
// wait for first successful reponse
|
||||
metamaskStream.once('_data', function(){
|
||||
metamaskStream.once('_data', function () {
|
||||
pingStream.pipe(pingChannel).pipe(pingStream)
|
||||
})
|
||||
endOfStream(pingStream, triggerReload)
|
||||
|
@ -46,7 +46,7 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
})
|
||||
}
|
||||
|
||||
getState() {
|
||||
getState () {
|
||||
const configManager = this.configManager
|
||||
const address = configManager.getSelectedAccount()
|
||||
const wallet = configManager.getWallet() // old style vault
|
||||
@ -72,18 +72,18 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
setStore(ethStore) {
|
||||
setStore (ethStore) {
|
||||
this.ethStore = ethStore
|
||||
}
|
||||
|
||||
createNewVaultAndKeychain(password, entropy, cb) {
|
||||
createNewVaultAndKeychain (password, entropy, cb) {
|
||||
this.createNewVault(password, entropy, (err) => {
|
||||
if (err) return cb(err)
|
||||
this.createFirstKeyTree(password, cb)
|
||||
})
|
||||
}
|
||||
|
||||
createNewVaultAndRestore(password, seed, cb) {
|
||||
createNewVaultAndRestore (password, seed, cb) {
|
||||
if (typeof password !== 'string') {
|
||||
return cb('Password must be text.')
|
||||
}
|
||||
@ -114,7 +114,7 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
})
|
||||
}
|
||||
|
||||
migrateAndGetKey(password) {
|
||||
migrateAndGetKey (password) {
|
||||
let key
|
||||
const shouldMigrate = !!this.configManager.getWallet() && !this.configManager.getVault()
|
||||
|
||||
@ -134,7 +134,7 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
})
|
||||
}
|
||||
|
||||
createNewVault(password, entropy, cb) {
|
||||
createNewVault (password, entropy, cb) {
|
||||
const configManager = this.configManager
|
||||
const salt = this.encryptor.generateSalt()
|
||||
configManager.setSalt(salt)
|
||||
@ -151,7 +151,7 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
})
|
||||
}
|
||||
|
||||
createFirstKeyTree(password, cb) {
|
||||
createFirstKeyTree (password, cb) {
|
||||
this.clearKeyrings()
|
||||
this.addNewKeyring('HD Key Tree', {n: 1}, (err) => {
|
||||
const firstKeyring = this.keyrings[0]
|
||||
@ -179,7 +179,7 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
this.configManager.setSeedWords(seedWords)
|
||||
}
|
||||
|
||||
submitPassword(password, cb) {
|
||||
submitPassword (password, cb) {
|
||||
this.migrateAndGetKey(password)
|
||||
.then((key) => {
|
||||
return this.unlockKeyrings(key)
|
||||
@ -196,7 +196,7 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
})
|
||||
}
|
||||
|
||||
loadKey(password) {
|
||||
loadKey (password) {
|
||||
const salt = this.configManager.getSalt() || this.encryptor.generateSalt()
|
||||
return this.encryptor.keyFromPassword(password + salt)
|
||||
.then((key) => {
|
||||
@ -206,7 +206,7 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
})
|
||||
}
|
||||
|
||||
addNewKeyring(type, opts, cb) {
|
||||
addNewKeyring (type, opts, cb) {
|
||||
const Keyring = this.getKeyringClassForType(type)
|
||||
const keyring = new Keyring(opts)
|
||||
const accounts = keyring.getAccounts()
|
||||
@ -222,7 +222,7 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
})
|
||||
}
|
||||
|
||||
addNewAccount(keyRingNum = 0, cb) {
|
||||
addNewAccount (keyRingNum = 0, cb) {
|
||||
const ring = this.keyrings[keyRingNum]
|
||||
const accounts = ring.addAccounts(1)
|
||||
this.setupAccounts(accounts)
|
||||
@ -235,7 +235,7 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
})
|
||||
}
|
||||
|
||||
setupAccounts(accounts) {
|
||||
setupAccounts (accounts) {
|
||||
var arr = accounts || this.getAccounts()
|
||||
arr.forEach((account) => {
|
||||
this.loadBalanceAndNickname(account)
|
||||
@ -244,13 +244,13 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
|
||||
// Takes an account address and an iterator representing
|
||||
// the current number of named accounts.
|
||||
loadBalanceAndNickname(account) {
|
||||
loadBalanceAndNickname (account) {
|
||||
const address = normalize(account)
|
||||
this.ethStore.addAccount(address)
|
||||
this.createNickname(address)
|
||||
}
|
||||
|
||||
createNickname(address) {
|
||||
createNickname (address) {
|
||||
const hexAddress = normalize(address)
|
||||
var i = Object.keys(this.identities).length
|
||||
const oldNickname = this.configManager.nicknameForWallet(address)
|
||||
@ -274,7 +274,7 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
persistAllKeyrings() {
|
||||
persistAllKeyrings () {
|
||||
const serialized = this.keyrings.map((k) => {
|
||||
return {
|
||||
type: k.type,
|
||||
@ -289,7 +289,7 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
})
|
||||
}
|
||||
|
||||
unlockKeyrings(key) {
|
||||
unlockKeyrings (key) {
|
||||
const encryptedVault = this.configManager.getVault()
|
||||
return this.encryptor.decryptWithKey(key, encryptedVault)
|
||||
.then((vault) => {
|
||||
@ -298,7 +298,7 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
})
|
||||
}
|
||||
|
||||
restoreKeyring(serialized) {
|
||||
restoreKeyring (serialized) {
|
||||
const { type, data } = serialized
|
||||
const Keyring = this.getKeyringClassForType(type)
|
||||
const keyring = new Keyring()
|
||||
@ -311,7 +311,7 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
return keyring
|
||||
}
|
||||
|
||||
getKeyringClassForType(type) {
|
||||
getKeyringClassForType (type) {
|
||||
const Keyring = this.keyringTypes.reduce((res, kr) => {
|
||||
if (kr.type() === type) {
|
||||
return kr
|
||||
@ -322,7 +322,7 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
return Keyring
|
||||
}
|
||||
|
||||
getAccounts() {
|
||||
getAccounts () {
|
||||
const keyrings = this.keyrings || []
|
||||
return keyrings.map(kr => kr.getAccounts())
|
||||
.reduce((res, arr) => {
|
||||
@ -330,13 +330,13 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
}, [])
|
||||
}
|
||||
|
||||
setSelectedAddress(address, cb) {
|
||||
setSelectedAddress (address, cb) {
|
||||
var addr = normalize(address)
|
||||
this.configManager.setSelectedAccount(addr)
|
||||
cb(null, addr)
|
||||
}
|
||||
|
||||
addUnconfirmedTransaction(txParams, onTxDoneCb, cb) {
|
||||
addUnconfirmedTransaction (txParams, onTxDoneCb, cb) {
|
||||
var self = this
|
||||
const configManager = this.configManager
|
||||
|
||||
@ -369,7 +369,7 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
], didComplete)
|
||||
|
||||
// perform static analyis on the target contract code
|
||||
function analyzeForDelegateCall(cb){
|
||||
function analyzeForDelegateCall (cb) {
|
||||
if (txParams.to) {
|
||||
query.getCode(txParams.to, function (err, result) {
|
||||
if (err) return cb(err)
|
||||
@ -388,8 +388,8 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
function estimateGas(cb){
|
||||
query.estimateGas(txParams, function(err, result){
|
||||
function estimateGas (cb) {
|
||||
query.estimateGas(txParams, function (err, result) {
|
||||
if (err) return cb(err)
|
||||
txData.estimatedGas = self.addGasBuffer(result)
|
||||
cb()
|
||||
@ -406,7 +406,7 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
addUnconfirmedMessage(msgParams, cb) {
|
||||
addUnconfirmedMessage (msgParams, cb) {
|
||||
// create txData obj with parameters and meta data
|
||||
var time = (new Date()).getTime()
|
||||
var msgId = createId()
|
||||
@ -428,7 +428,7 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
return msgId
|
||||
}
|
||||
|
||||
approveTransaction(txId, cb) {
|
||||
approveTransaction (txId, cb) {
|
||||
const configManager = this.configManager
|
||||
var approvalCb = this._unconfTxCbs[txId] || noop
|
||||
|
||||
@ -441,7 +441,7 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
this.emit('update')
|
||||
}
|
||||
|
||||
cancelTransaction(txId, cb) {
|
||||
cancelTransaction (txId, cb) {
|
||||
const configManager = this.configManager
|
||||
var approvalCb = this._unconfTxCbs[txId] || noop
|
||||
|
||||
@ -456,7 +456,7 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
signTransaction(txParams, cb) {
|
||||
signTransaction (txParams, cb) {
|
||||
try {
|
||||
const address = normalize(txParams.from)
|
||||
const keyring = this.getKeyringForAccount(address)
|
||||
@ -492,7 +492,7 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
signMessage(msgParams, cb) {
|
||||
signMessage (msgParams, cb) {
|
||||
try {
|
||||
const keyring = this.getKeyringForAccount(msgParams.from)
|
||||
const address = normalize(msgParams.from)
|
||||
@ -503,7 +503,7 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
getKeyringForAccount(address) {
|
||||
getKeyringForAccount (address) {
|
||||
const hexed = normalize(address)
|
||||
return this.keyrings.find((ring) => {
|
||||
return ring.getAccounts()
|
||||
@ -512,19 +512,19 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
})
|
||||
}
|
||||
|
||||
cancelMessage(msgId, cb) {
|
||||
cancelMessage (msgId, cb) {
|
||||
if (cb && typeof cb === 'function') {
|
||||
cb()
|
||||
}
|
||||
}
|
||||
|
||||
setLocked(cb) {
|
||||
setLocked (cb) {
|
||||
this.key = null
|
||||
this.keyrings = []
|
||||
cb()
|
||||
}
|
||||
|
||||
exportAccount(address, cb) {
|
||||
exportAccount (address, cb) {
|
||||
try {
|
||||
const keyring = this.getKeyringForAccount(address)
|
||||
const privateKey = keyring.exportAccount(normalize(address))
|
||||
@ -534,19 +534,19 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
addGasBuffer(gas) {
|
||||
addGasBuffer (gas) {
|
||||
const gasBuffer = new BN('100000', 10)
|
||||
const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16)
|
||||
const correct = bnGas.add(gasBuffer)
|
||||
return ethUtil.addHexPrefix(correct.toString(16))
|
||||
}
|
||||
|
||||
clearSeedWordCache(cb) {
|
||||
clearSeedWordCache (cb) {
|
||||
this.configManager.setSeedWords(null)
|
||||
cb(null, this.configManager.getSelectedAccount())
|
||||
}
|
||||
|
||||
clearKeyrings() {
|
||||
clearKeyrings () {
|
||||
let accounts
|
||||
try {
|
||||
accounts = Object.keys(this.ethStore._currentState.accounts)
|
||||
@ -564,7 +564,7 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
|
||||
}
|
||||
|
||||
function normalize(address) {
|
||||
function normalize (address) {
|
||||
if (!address) return
|
||||
return ethUtil.addHexPrefix(address.toLowerCase())
|
||||
}
|
||||
|
@ -9,17 +9,17 @@ const hdPathString = `m/44'/60'/0'/0`
|
||||
|
||||
module.exports = class HdKeyring extends EventEmitter {
|
||||
|
||||
static type() {
|
||||
static type () {
|
||||
return type
|
||||
}
|
||||
|
||||
constructor(opts = {}) {
|
||||
constructor (opts = {}) {
|
||||
super()
|
||||
this.type = type
|
||||
this.deserialize(opts)
|
||||
}
|
||||
|
||||
deserialize(opts = {}) {
|
||||
deserialize (opts = {}) {
|
||||
this.opts = opts || {}
|
||||
this.wallets = []
|
||||
this.mnemonic = null
|
||||
@ -34,26 +34,26 @@ module.exports = class HdKeyring extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
initFromMnemonic(mnemonic) {
|
||||
initFromMnemonic (mnemonic) {
|
||||
this.mnemonic = mnemonic
|
||||
const seed = bip39.mnemonicToSeed(mnemonic)
|
||||
this.hdWallet = hdkey.fromMasterSeed(seed)
|
||||
this.root = this.hdWallet.derivePath(hdPathString)
|
||||
}
|
||||
|
||||
serialize() {
|
||||
serialize () {
|
||||
return {
|
||||
mnemonic: this.mnemonic,
|
||||
n: this.wallets.length,
|
||||
}
|
||||
}
|
||||
|
||||
exportAccount(address) {
|
||||
exportAccount (address) {
|
||||
const wallet = this.getWalletForAccount(address)
|
||||
return wallet.getPrivateKey().toString('hex')
|
||||
}
|
||||
|
||||
addAccounts(n = 1) {
|
||||
addAccounts (n = 1) {
|
||||
if (!this.root) {
|
||||
this.initFromMnemonic(bip39.generateMnemonic())
|
||||
}
|
||||
@ -69,12 +69,12 @@ module.exports = class HdKeyring extends EventEmitter {
|
||||
return newWallets.map(w => w.getAddress().toString('hex'))
|
||||
}
|
||||
|
||||
getAccounts() {
|
||||
getAccounts () {
|
||||
return this.wallets.map(w => w.getAddress().toString('hex'))
|
||||
}
|
||||
|
||||
// tx is an instance of the ethereumjs-transaction class.
|
||||
signTransaction(address, tx) {
|
||||
signTransaction (address, tx) {
|
||||
const wallet = this.getWalletForAccount(address)
|
||||
var privKey = wallet.getPrivateKey()
|
||||
tx.sign(privKey)
|
||||
@ -82,7 +82,7 @@ module.exports = class HdKeyring extends EventEmitter {
|
||||
}
|
||||
|
||||
// For eth_sign, we need to sign transactions:
|
||||
signMessage(withAccount, data) {
|
||||
signMessage (withAccount, data) {
|
||||
const wallet = this.getWalletForAccount(withAccount)
|
||||
const message = ethUtil.removeHexPrefix(data)
|
||||
var privKey = wallet.getPrivateKey()
|
||||
@ -91,17 +91,14 @@ module.exports = class HdKeyring extends EventEmitter {
|
||||
return rawMsgSig
|
||||
}
|
||||
|
||||
getWalletForAccount(account) {
|
||||
getWalletForAccount (account) {
|
||||
return this.wallets.find((w) => {
|
||||
const address = w.getAddress().toString('hex')
|
||||
return ((address === account) || (normalize(address) === account))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function normalize(address) {
|
||||
function normalize (address) {
|
||||
return ethUtil.addHexPrefix(address.toLowerCase())
|
||||
}
|
||||
|
@ -6,22 +6,22 @@ const sigUtil = require('../lib/sig-util')
|
||||
|
||||
module.exports = class SimpleKeyring extends EventEmitter {
|
||||
|
||||
static type() {
|
||||
static type () {
|
||||
return type
|
||||
}
|
||||
|
||||
constructor(opts) {
|
||||
constructor (opts) {
|
||||
super()
|
||||
this.type = type
|
||||
this.opts = opts || {}
|
||||
this.wallets = []
|
||||
}
|
||||
|
||||
serialize() {
|
||||
serialize () {
|
||||
return this.wallets.map(w => w.getPrivateKey().toString('hex'))
|
||||
}
|
||||
|
||||
deserialize(wallets = []) {
|
||||
deserialize (wallets = []) {
|
||||
this.wallets = wallets.map((w) => {
|
||||
var b = new Buffer(w, 'hex')
|
||||
const wallet = Wallet.fromPrivateKey(b)
|
||||
@ -29,7 +29,7 @@ module.exports = class SimpleKeyring extends EventEmitter {
|
||||
})
|
||||
}
|
||||
|
||||
addAccounts(n = 1) {
|
||||
addAccounts (n = 1) {
|
||||
var newWallets = []
|
||||
for (var i = 0; i < n; i++) {
|
||||
newWallets.push(Wallet.generate())
|
||||
@ -38,12 +38,12 @@ module.exports = class SimpleKeyring extends EventEmitter {
|
||||
return newWallets.map(w => w.getAddress().toString('hex'))
|
||||
}
|
||||
|
||||
getAccounts() {
|
||||
getAccounts () {
|
||||
return this.wallets.map(w => w.getAddress().toString('hex'))
|
||||
}
|
||||
|
||||
// tx is an instance of the ethereumjs-transaction class.
|
||||
signTransaction(address, tx) {
|
||||
signTransaction (address, tx) {
|
||||
const wallet = this.getWalletForAccount(address)
|
||||
var privKey = wallet.getPrivateKey()
|
||||
tx.sign(privKey)
|
||||
@ -51,7 +51,7 @@ module.exports = class SimpleKeyring extends EventEmitter {
|
||||
}
|
||||
|
||||
// For eth_sign, we need to sign transactions:
|
||||
signMessage(withAccount, data) {
|
||||
signMessage (withAccount, data) {
|
||||
const wallet = this.getWalletForAccount(withAccount)
|
||||
const message = ethUtil.removeHexPrefix(data)
|
||||
var privKey = wallet.getPrivateKey()
|
||||
@ -60,9 +60,8 @@ module.exports = class SimpleKeyring extends EventEmitter {
|
||||
return rawMsgSig
|
||||
}
|
||||
|
||||
getWalletForAccount(account) {
|
||||
getWalletForAccount (account) {
|
||||
return this.wallets.find(w => w.getAddress().toString('hex') === account)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -18,17 +18,16 @@ function setupDappAutoReload (web3) {
|
||||
|
||||
return handleResetRequest
|
||||
|
||||
function handleResetRequest() {
|
||||
function handleResetRequest () {
|
||||
resetWasRequested = true
|
||||
// ignore if web3 was not used
|
||||
if (!pageIsUsingWeb3) return
|
||||
// reload after short timeout
|
||||
setTimeout(triggerReset, 500)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// reload the page
|
||||
function triggerReset () {
|
||||
global.location.reload()
|
||||
}
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ ConfigManager.prototype.getSalt = function () {
|
||||
return ('salt' in data) && data.salt
|
||||
}
|
||||
|
||||
ConfigManager.prototype.setSalt = function(salt) {
|
||||
ConfigManager.prototype.setSalt = function (salt) {
|
||||
var data = this.getData()
|
||||
data.salt = salt
|
||||
this.setData(data)
|
||||
@ -358,7 +358,6 @@ ConfigManager.prototype.updateConversionRate = function () {
|
||||
this.setConversionPrice(0)
|
||||
this.setConversionDate('N/A')
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
ConfigManager.prototype.setConversionPrice = function (price) {
|
||||
|
@ -42,7 +42,7 @@ function encryptWithKey (key, dataObj) {
|
||||
return global.crypto.subtle.encrypt({
|
||||
name: 'AES-GCM',
|
||||
iv: vector,
|
||||
}, key, dataBuffer).then(function(buf){
|
||||
}, key, dataBuffer).then(function (buf) {
|
||||
var buffer = new Uint8Array(buf)
|
||||
var vectorStr = encodeBufferToBase64(vector)
|
||||
var vaultStr = encodeBufferToBase64(buffer)
|
||||
@ -63,13 +63,13 @@ function decryptWithKey (key, text) {
|
||||
const encryptedData = decodeBase64ToBuffer(parts[0])
|
||||
const vector = decodeBase64ToBuffer(parts[1])
|
||||
return crypto.subtle.decrypt({name: 'AES-GCM', iv: vector}, key, encryptedData)
|
||||
.then(function(result){
|
||||
.then(function (result) {
|
||||
const decryptedData = new Uint8Array(result)
|
||||
const decryptedStr = convertArrayBufferViewtoString(decryptedData)
|
||||
const decryptedObj = JSON.parse(decryptedStr)
|
||||
return decryptedObj
|
||||
})
|
||||
.catch(function(reason) {
|
||||
.catch(function (reason) {
|
||||
throw new Error('Incorrect password')
|
||||
})
|
||||
}
|
||||
@ -95,7 +95,7 @@ function convertArrayBufferViewtoString (buffer) {
|
||||
function keyFromPassword (password) {
|
||||
var passBuffer = convertStringToArrayBufferView(password)
|
||||
return global.crypto.subtle.digest('SHA-256', passBuffer)
|
||||
.then(function (passHash){
|
||||
.then(function (passHash) {
|
||||
return global.crypto.subtle.importKey('raw', passHash, {name: 'AES-GCM'}, false, ['encrypt', 'decrypt'])
|
||||
})
|
||||
}
|
||||
@ -135,7 +135,7 @@ function encodeBufferToBase64 (buf) {
|
||||
|
||||
function decodeBase64ToBuffer (base64) {
|
||||
var buf = new Uint8Array(atob(base64).split('')
|
||||
.map(function(c) {
|
||||
.map(function (c) {
|
||||
return c.charCodeAt(0)
|
||||
}))
|
||||
return buf
|
||||
|
@ -11,7 +11,7 @@ module.exports = class IdentityStoreMigrator {
|
||||
}
|
||||
}
|
||||
|
||||
oldSeedForPassword( password ) {
|
||||
oldSeedForPassword (password) {
|
||||
const hasOldVault = this.hasOldVault()
|
||||
const configManager = this.configManager
|
||||
|
||||
@ -35,7 +35,7 @@ module.exports = class IdentityStoreMigrator {
|
||||
})
|
||||
}
|
||||
|
||||
serializeVault() {
|
||||
serializeVault () {
|
||||
const mnemonic = this.idStore._idmgmt.getSeed()
|
||||
const n = this.idStore._getAddresses().length
|
||||
|
||||
@ -45,7 +45,7 @@ module.exports = class IdentityStoreMigrator {
|
||||
}
|
||||
}
|
||||
|
||||
hasOldVault() {
|
||||
hasOldVault () {
|
||||
const wallet = this.configManager.getWallet()
|
||||
return wallet
|
||||
}
|
||||
|
@ -243,7 +243,7 @@ IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDone
|
||||
], didComplete)
|
||||
|
||||
// perform static analyis on the target contract code
|
||||
function analyzeForDelegateCall(cb){
|
||||
function analyzeForDelegateCall (cb) {
|
||||
if (txParams.to) {
|
||||
query.getCode(txParams.to, (err, result) => {
|
||||
if (err) return cb(err)
|
||||
@ -256,16 +256,16 @@ IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDone
|
||||
}
|
||||
}
|
||||
|
||||
function estimateGas(cb){
|
||||
function estimateGas (cb) {
|
||||
var estimationParams = extend(txParams)
|
||||
// 1 billion gas for estimation
|
||||
var gasLimit = '0x3b9aca00'
|
||||
estimationParams.gas = gasLimit
|
||||
query.estimateGas(estimationParams, function(err, result){
|
||||
query.estimateGas(estimationParams, function (err, result) {
|
||||
if (err) return cb(err)
|
||||
if (result === estimationParams.gas) {
|
||||
txData.simulationFails = true
|
||||
query.getBlockByNumber('latest', true, function(err, block){
|
||||
query.getBlockByNumber('latest', true, function (err, block) {
|
||||
if (err) return cb(err)
|
||||
txData.estimatedGas = block.gasLimit
|
||||
txData.txParams.gas = block.gasLimit
|
||||
|
@ -39,7 +39,7 @@ function MetamaskInpageProvider (connectionStream) {
|
||||
|
||||
self.idMap = {}
|
||||
// handle sendAsync requests via asyncProvider
|
||||
self.sendAsync = function(payload, cb){
|
||||
self.sendAsync = function (payload, cb) {
|
||||
// rewrite request ids
|
||||
var request = eachJsonMessage(payload, (message) => {
|
||||
var newId = createRandomId()
|
||||
@ -48,7 +48,7 @@ function MetamaskInpageProvider (connectionStream) {
|
||||
return message
|
||||
})
|
||||
// forward to asyncProvider
|
||||
asyncProvider.sendAsync(request, function(err, res){
|
||||
asyncProvider.sendAsync(request, function (err, res) {
|
||||
if (err) return cb(err)
|
||||
// transform messages to original ids
|
||||
eachJsonMessage(res, (message) => {
|
||||
@ -119,7 +119,7 @@ function remoteStoreWithLocalStorageCache (storageKey) {
|
||||
return store
|
||||
}
|
||||
|
||||
function createRandomId(){
|
||||
function createRandomId () {
|
||||
const extraDigits = 3
|
||||
// 13 time digits
|
||||
const datePart = new Date().getTime() * Math.pow(10, extraDigits)
|
||||
@ -129,7 +129,7 @@ function createRandomId(){
|
||||
return datePart + extraPart
|
||||
}
|
||||
|
||||
function eachJsonMessage(payload, transformFn){
|
||||
function eachJsonMessage (payload, transformFn) {
|
||||
if (Array.isArray(payload)) {
|
||||
return payload.map(transformFn)
|
||||
} else {
|
||||
|
@ -1,4 +1,4 @@
|
||||
module.exports = function isPopupOrNotification() {
|
||||
module.exports = function isPopupOrNotification () {
|
||||
const url = window.location.href
|
||||
if (url.match(/popup.html$/)) {
|
||||
return 'popup'
|
||||
|
@ -15,12 +15,9 @@ function show () {
|
||||
if (err) throw err
|
||||
|
||||
if (popup) {
|
||||
|
||||
// bring focus to existing popup
|
||||
extension.windows.update(popup.id, { focused: true })
|
||||
|
||||
} else {
|
||||
|
||||
// create new popup
|
||||
extension.windows.create({
|
||||
url: 'notification.html',
|
||||
@ -29,12 +26,11 @@ function show () {
|
||||
width,
|
||||
height,
|
||||
})
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function getWindows(cb) {
|
||||
function getWindows (cb) {
|
||||
// Ignore in test environment
|
||||
if (!extension.windows) {
|
||||
return cb()
|
||||
@ -45,14 +41,14 @@ function getWindows(cb) {
|
||||
})
|
||||
}
|
||||
|
||||
function getPopup(cb) {
|
||||
function getPopup (cb) {
|
||||
getWindows((err, windows) => {
|
||||
if (err) throw err
|
||||
cb(null, getPopupIn(windows))
|
||||
})
|
||||
}
|
||||
|
||||
function getPopupIn(windows) {
|
||||
function getPopupIn (windows) {
|
||||
return windows ? windows.find((win) => {
|
||||
return (win && win.type === 'popup' &&
|
||||
win.height === height &&
|
||||
@ -60,7 +56,7 @@ function getPopupIn(windows) {
|
||||
}) : null
|
||||
}
|
||||
|
||||
function closePopup() {
|
||||
function closePopup () {
|
||||
getPopup((err, popup) => {
|
||||
if (err) throw err
|
||||
if (!popup) return
|
||||
|
@ -87,23 +87,6 @@ module.exports = class MetamaskController {
|
||||
}
|
||||
|
||||
onRpcRequest (stream, originDomain, request) {
|
||||
|
||||
/* Commented out for Parity compliance
|
||||
* Parity does not permit additional keys, like `origin`,
|
||||
* and Infura is not currently filtering this key out.
|
||||
var payloads = Array.isArray(request) ? request : [request]
|
||||
payloads.forEach(function (payload) {
|
||||
// Append origin to rpc payload
|
||||
payload.origin = originDomain
|
||||
// Append origin to signature request
|
||||
if (payload.method === 'eth_sendTransaction') {
|
||||
payload.params[0].origin = originDomain
|
||||
} else if (payload.method === 'eth_sign') {
|
||||
payload.params.push({ origin: originDomain })
|
||||
}
|
||||
})
|
||||
*/
|
||||
|
||||
// handle rpc request
|
||||
this.provider.sendAsync(request, function onPayloadHandled (err, response) {
|
||||
logger(err, request, response)
|
||||
@ -217,7 +200,7 @@ module.exports = class MetamaskController {
|
||||
newUnsignedTransaction (txParams, onTxDoneCb) {
|
||||
const keyringController = this.keyringController
|
||||
|
||||
let err = this.enforceTxValidations(txParams)
|
||||
const err = this.enforceTxValidations(txParams)
|
||||
if (err) return onTxDoneCb(err)
|
||||
keyringController.addUnconfirmedTransaction(txParams, onTxDoneCb, (err, txData) => {
|
||||
if (err) return onTxDoneCb(err)
|
||||
@ -291,7 +274,6 @@ module.exports = class MetamaskController {
|
||||
} catch (e) {
|
||||
console.error('Error in checking TOS change.')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
agreeToDisclaimer (cb) {
|
||||
@ -373,7 +355,7 @@ module.exports = class MetamaskController {
|
||||
this.configManager.createShapeShiftTx(depositAddress, depositType)
|
||||
}
|
||||
|
||||
getNetwork(err) {
|
||||
getNetwork (err) {
|
||||
if (err) {
|
||||
this.state.network = 'loading'
|
||||
this.sendUpdate()
|
||||
@ -405,4 +387,3 @@ module.exports = class MetamaskController {
|
||||
return this.state.network
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
|
||||
module.exports = initializePopup
|
||||
|
||||
|
||||
function initializePopup(connectionStream){
|
||||
function initializePopup (connectionStream) {
|
||||
// setup app
|
||||
connectToAccountManager(connectionStream, setupApp)
|
||||
}
|
||||
@ -32,7 +32,7 @@ function setupWeb3Connection (connectionStream) {
|
||||
}
|
||||
|
||||
function setupControllerConnection (connectionStream, cb) {
|
||||
// this is a really sneaky way of adding EventEmitter api
|
||||
// this is a really sneaky way of adding EventEmitter api
|
||||
// to a bi-directional dnode instance
|
||||
var eventEmitter = new EventEmitter()
|
||||
var accountManagerDnode = Dnode({
|
||||
|
@ -18,7 +18,7 @@ var portStream = new PortStream(pluginPort)
|
||||
|
||||
startPopup(portStream)
|
||||
|
||||
function closePopupIfOpen(name) {
|
||||
function closePopupIfOpen (name) {
|
||||
if (name !== 'notification') {
|
||||
notification.closePopup()
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ var actions = {
|
||||
module.exports = actions
|
||||
|
||||
var background = null
|
||||
function _setBackgroundConnection(backgroundConnection) {
|
||||
function _setBackgroundConnection (backgroundConnection) {
|
||||
background = backgroundConnection
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,6 @@ App.prototype.render = function () {
|
||||
}
|
||||
|
||||
App.prototype.renderAppBar = function () {
|
||||
|
||||
if (window.METAMASK_UI_TYPE === 'notification') {
|
||||
return null
|
||||
}
|
||||
@ -367,7 +366,6 @@ App.prototype.renderPrimary = function () {
|
||||
|
||||
// show initialize screen
|
||||
if (!props.isInitialized || props.forgottenPassword) {
|
||||
|
||||
// show current view
|
||||
switch (props.currentView.name) {
|
||||
|
||||
|
@ -7,7 +7,7 @@ const actions = require('../actions')
|
||||
const isValidAddress = require('../util').isValidAddress
|
||||
module.exports = connect(mapStateToProps)(CoinbaseForm)
|
||||
|
||||
function mapStateToProps(state) {
|
||||
function mapStateToProps (state) {
|
||||
return {
|
||||
selectedAccount: state.selectedAccount,
|
||||
warning: state.appState.warning,
|
||||
@ -16,7 +16,7 @@ function mapStateToProps(state) {
|
||||
|
||||
inherits(CoinbaseForm, Component)
|
||||
|
||||
function CoinbaseForm() {
|
||||
function CoinbaseForm () {
|
||||
Component.call(this)
|
||||
}
|
||||
|
||||
@ -124,7 +124,6 @@ CoinbaseForm.prototype.toCoinbase = function () {
|
||||
}
|
||||
|
||||
CoinbaseForm.prototype.renderLoading = function () {
|
||||
|
||||
return h('img', {
|
||||
style: {
|
||||
width: '27px',
|
||||
@ -134,9 +133,8 @@ CoinbaseForm.prototype.renderLoading = function () {
|
||||
})
|
||||
}
|
||||
|
||||
function isValidAmountforCoinBase(amount) {
|
||||
function isValidAmountforCoinBase (amount) {
|
||||
amount = parseFloat(amount)
|
||||
|
||||
if (amount) {
|
||||
if (amount <= 5 && amount > 0) {
|
||||
return {
|
||||
|
@ -50,12 +50,10 @@ CopyButton.prototype.render = function () {
|
||||
])
|
||||
}
|
||||
|
||||
CopyButton.prototype.debounceRestore = function() {
|
||||
|
||||
CopyButton.prototype.debounceRestore = function () {
|
||||
this.setState({ copied: true })
|
||||
clearTimeout(this.timeout)
|
||||
this.timeout = setTimeout(() => {
|
||||
this.setState({ copied: false })
|
||||
}, 850)
|
||||
|
||||
}
|
||||
|
@ -32,9 +32,9 @@ DropMenuItem.prototype.render = function () {
|
||||
}
|
||||
|
||||
DropMenuItem.prototype.activeNetworkRender = function () {
|
||||
let activeNetwork = this.props.activeNetworkRender
|
||||
let { provider } = this.props
|
||||
let providerType = provider ? provider.type : null
|
||||
const activeNetwork = this.props.activeNetworkRender
|
||||
const { provider } = this.props
|
||||
const providerType = provider ? provider.type : null
|
||||
if (activeNetwork === undefined) return
|
||||
|
||||
switch (this.props.label) {
|
||||
|
@ -22,7 +22,6 @@ Network.prototype.render = function () {
|
||||
let iconName, hoverText
|
||||
|
||||
if (networkNumber === 'loading') {
|
||||
|
||||
return h('img.network-indicator', {
|
||||
title: 'Attempting to connect to blockchain.',
|
||||
onClick: (event) => this.props.onClick(event),
|
||||
@ -32,7 +31,6 @@ Network.prototype.render = function () {
|
||||
},
|
||||
src: 'images/loading.svg',
|
||||
})
|
||||
|
||||
} else if (providerName === 'mainnet') {
|
||||
hoverText = 'Main Ethereum Network'
|
||||
iconName = 'ethereum-network'
|
||||
|
@ -30,22 +30,22 @@ PendingTx.prototype.render = function () {
|
||||
}
|
||||
`),
|
||||
|
||||
txData.simulationFails ?
|
||||
h('.error', {
|
||||
style: {
|
||||
marginLeft: 50,
|
||||
fontSize: '0.9em',
|
||||
},
|
||||
}, 'Transaction Error. Exception thrown in contract code.')
|
||||
txData.simulationFails
|
||||
? h('.error', {
|
||||
style: {
|
||||
marginLeft: 50,
|
||||
fontSize: '0.9em',
|
||||
},
|
||||
}, 'Transaction Error. Exception thrown in contract code.')
|
||||
: null,
|
||||
|
||||
state.insufficientBalance ?
|
||||
h('span.error', {
|
||||
style: {
|
||||
marginLeft: 50,
|
||||
fontSize: '0.9em',
|
||||
},
|
||||
}, 'Insufficient balance for transaction')
|
||||
state.insufficientBalance
|
||||
? h('span.error', {
|
||||
style: {
|
||||
marginLeft: 50,
|
||||
fontSize: '0.9em',
|
||||
},
|
||||
}, 'Insufficient balance for transaction')
|
||||
: null,
|
||||
|
||||
// send + cancel
|
||||
@ -57,10 +57,10 @@ PendingTx.prototype.render = function () {
|
||||
},
|
||||
}, [
|
||||
|
||||
state.insufficientBalance ?
|
||||
h('button.btn-green', {
|
||||
onClick: state.buyEth,
|
||||
}, 'Buy Ether')
|
||||
state.insufficientBalance
|
||||
? h('button.btn-green', {
|
||||
onClick: state.buyEth,
|
||||
}, 'Buy Ether')
|
||||
: null,
|
||||
|
||||
h('button.confirm', {
|
||||
|
@ -8,7 +8,7 @@ const Qr = require('./qr-code')
|
||||
const isValidAddress = require('../util').isValidAddress
|
||||
module.exports = connect(mapStateToProps)(ShapeshiftForm)
|
||||
|
||||
function mapStateToProps(state) {
|
||||
function mapStateToProps (state) {
|
||||
return {
|
||||
selectedAccount: state.selectedAccount,
|
||||
warning: state.appState.warning,
|
||||
@ -25,7 +25,6 @@ function ShapeshiftForm () {
|
||||
}
|
||||
|
||||
ShapeshiftForm.prototype.render = function () {
|
||||
|
||||
return h(ReactCSSTransitionGroup, {
|
||||
className: 'css-transition-group',
|
||||
transitionName: 'main',
|
||||
@ -34,7 +33,6 @@ ShapeshiftForm.prototype.render = function () {
|
||||
}, [
|
||||
this.props.qrRequested ? h(Qr, {key: 'qr'}) : this.renderMain(),
|
||||
])
|
||||
|
||||
}
|
||||
|
||||
ShapeshiftForm.prototype.renderMain = function () {
|
||||
|
@ -26,7 +26,6 @@ function ShiftListItem () {
|
||||
}
|
||||
|
||||
ShiftListItem.prototype.render = function () {
|
||||
|
||||
return (
|
||||
h('.transaction-list-item.flex-row', {
|
||||
style: {
|
||||
|
@ -11,7 +11,6 @@ function Tooltip () {
|
||||
}
|
||||
|
||||
Tooltip.prototype.render = function () {
|
||||
|
||||
const props = this.props
|
||||
const { position, title, children } = props
|
||||
|
||||
@ -20,5 +19,4 @@ Tooltip.prototype.render = function () {
|
||||
title,
|
||||
fixed: false,
|
||||
}, children)
|
||||
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ TransactionListItem.prototype.render = function () {
|
||||
style: {
|
||||
fontSize: '27px',
|
||||
},
|
||||
}) : h( '.pop-hover', {
|
||||
}) : h('.pop-hover', {
|
||||
onClick: (event) => {
|
||||
event.stopPropagation()
|
||||
if (!isTx || isPending) return
|
||||
|
@ -41,7 +41,7 @@ function rootReducer (state, action) {
|
||||
return state
|
||||
}
|
||||
|
||||
window.logState = function() {
|
||||
window.logState = function () {
|
||||
var stateString = JSON.stringify(window.METAMASK_CACHED_LOG_STATE, null, 2)
|
||||
console.log(stateString)
|
||||
}
|
||||
|
@ -278,7 +278,6 @@ function reduceApp (state, action) {
|
||||
warning: null,
|
||||
})
|
||||
} else {
|
||||
|
||||
notification.closePopup()
|
||||
|
||||
return extend(appState, {
|
||||
|
@ -1,4 +1,4 @@
|
||||
module.exports = function(address, network) {
|
||||
module.exports = function (address, network) {
|
||||
const net = parseInt(network)
|
||||
let link
|
||||
|
||||
|
@ -8,23 +8,22 @@
|
||||
// Nickname keys must be stored in lower case.
|
||||
const nicknames = {}
|
||||
|
||||
module.exports = function(addr, identities = {}) {
|
||||
|
||||
module.exports = function (addr, identities = {}) {
|
||||
const address = addr.toLowerCase()
|
||||
const ids = hashFromIdentities(identities)
|
||||
|
||||
return addrFromHash(address, ids) || addrFromHash(address, nicknames)
|
||||
}
|
||||
|
||||
function hashFromIdentities(identities) {
|
||||
function hashFromIdentities (identities) {
|
||||
const result = {}
|
||||
for (let key in identities) {
|
||||
for (const key in identities) {
|
||||
result[key] = identities[key].name
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
function addrFromHash(addr, hash) {
|
||||
function addrFromHash (addr, hash) {
|
||||
const address = addr.toLowerCase()
|
||||
return hash[address] || null
|
||||
}
|
||||
|
@ -55,6 +55,6 @@ function jsNumberForAddress (address) {
|
||||
return seed
|
||||
}
|
||||
|
||||
function toDataUri(identiconSrc){
|
||||
function toDataUri (identiconSrc) {
|
||||
return 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(identiconSrc)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user