From 1481a3ef8e3352eb74fa11c4f578d15d84c76de7 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Sat, 15 Oct 2016 10:48:12 -0700 Subject: Initial work on UI side --- app/scripts/lib/config-manager.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index ecc9bc5f7..d775e73fd 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -110,6 +110,16 @@ ConfigManager.prototype.setWallet = function (wallet) { this.setData(data) } +ConfigManager.prototype.getKeychains = function () { + return this.migrator.getData().keychains || [] +} + +ConfigManager.prototype.setKeychains = function (keychains) { + var data = this.migrator.getData() + data.keychains = keychains + this.setData(data) +} + ConfigManager.prototype.getSelectedAccount = function () { var config = this.getConfig() return config.selectedAccount @@ -249,6 +259,17 @@ ConfigManager.prototype.setNicknameForWallet = function (account, nickname) { // observable +ConfigManager.prototype.getSalt = function () { + var data = this.getData() + return ('salt' in data) && data.salt +} + +ConfigManager.prototype.setSalt = function(salt) { + var data = this.getData() + data.salt = salt + this.setData(data) +} + ConfigManager.prototype.subscribe = function (fn) { this._subs.push(fn) var unsubscribe = this.unsubscribe.bind(this, fn) -- cgit v1.2.3 From 17506fe14f84680bc6b5421eff4c797154a513bd Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Wed, 19 Oct 2016 11:17:29 -0700 Subject: Merge in crypto. --- app/scripts/lib/encryptor.js | 119 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 app/scripts/lib/encryptor.js (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/encryptor.js b/app/scripts/lib/encryptor.js new file mode 100644 index 000000000..91d6ed5ce --- /dev/null +++ b/app/scripts/lib/encryptor.js @@ -0,0 +1,119 @@ +var ethUtil = require('ethereumjs-util') + +module.exports = { + + // Simple encryption methods: + encrypt, + decrypt, + + // More advanced encryption methods: + keyFromPassword, + encryptWithKey, + decryptWithKey, + + // Buffer <-> String methods + convertArrayBufferViewtoString, + convertStringToArrayBufferView, + + // Buffer <-> Hex string methods + serializeBufferForStorage, + serializeBufferFromStorage, +} + +// Takes a Pojo, returns encrypted text. +function encrypt (password, dataObj) { + return keyFromPassword(password) + .then(function (passwordDerivedKey) { + return encryptWithKey(passwordDerivedKey, dataObj) + }) +} + +function encryptWithKey (key, dataObj) { + var data = JSON.stringify(dataObj) + var dataBuffer = convertStringToArrayBufferView(data) + var vector = global.crypto.getRandomValues(new Uint8Array(16)) + + return global.crypto.subtle.encrypt({ + name: 'AES-GCM', + iv: vector, + }, key, dataBuffer).then(function(buf){ + var buffer = new Uint8Array(buf) + var vectorStr = serializeBufferForStorage(vector) + return serializeBufferForStorage(buffer) + vectorStr + }) +} + +// Takes encrypted text, returns the restored Pojo. +function decrypt (password, text) { + return keyFromPassword(password) + .then(function (key) { + return decryptWithKey(key, text) + }) +} + +function decryptWithKey (key, text) { + const parts = text.split('0x') + const encryptedData = serializeBufferFromStorage(parts[1]) + const vector = serializeBufferFromStorage(parts[2]) + return crypto.subtle.decrypt({name: 'AES-GCM', iv: vector}, key, encryptedData) + .then(function(result){ + const decryptedData = new Uint8Array(result) + const decryptedStr = convertArrayBufferViewtoString(decryptedData) + const decryptedObj = JSON.parse(decryptedStr) + return decryptedObj + }) +} + +function convertStringToArrayBufferView (str) { + var bytes = new Uint8Array(str.length) + for (var i = 0; i < str.length; i++) { + bytes[i] = str.charCodeAt(i) + } + + return bytes +} + +function convertArrayBufferViewtoString (buffer) { + var str = '' + for (var i = 0; i < buffer.byteLength; i++) { + str += String.fromCharCode(buffer[i]) + } + + return str +} + +function keyFromPassword (password) { + var passBuffer = convertStringToArrayBufferView(password) + return global.crypto.subtle.digest('SHA-256', passBuffer) + .then(function (passHash){ + return global.crypto.subtle.importKey('raw', passHash, {name: 'AES-GCM'}, false, ['encrypt', 'decrypt']) + }) +} + +function serializeBufferFromStorage (str) { + str = ethUtil.stripHexPrefix(str) + var buf = new Uint8Array(str.length / 2) + for (var i = 0; i < str.length; i += 2) { + var seg = str.substr(i, 2) + buf[i / 2] = parseInt(seg, 16) + } + return buf +} + +// Should return a string, ready for storage, in hex format. +function serializeBufferForStorage (buffer) { + var result = '0x' + var len = buffer.length || buffer.byteLength + for (var i = 0; i < len; i++) { + result += unprefixedHex(buffer[i]) + } + return result +} + +function unprefixedHex (num) { + var hex = num.toString(16) + while (hex.length < 2) { + hex = '0' + hex + } + return hex +} -- cgit v1.2.3 From ad3fa24a28c0ec45dca43a257005626a4027487a Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Wed, 19 Oct 2016 14:55:08 -0700 Subject: Intermediary commit. --- app/scripts/lib/config-manager.js | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index d775e73fd..1c0e3b696 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -110,6 +110,17 @@ ConfigManager.prototype.setWallet = function (wallet) { this.setData(data) } +ConfigManager.prototype.setVault = function (encryptedString) { + var data = this.getData() + data.vault = encryptedString + this.setData(data) +} + +ConfigManager.prototype.getVault = function () { + var data = this.getData() + return ('vault' in data) && data.vault +} + ConfigManager.prototype.getKeychains = function () { return this.migrator.getData().keychains || [] } -- cgit v1.2.3 From 383f8ea7dc4a264613cfe92b257878eb78438ce7 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 20 Oct 2016 11:33:18 -0700 Subject: Linted & added salting to vault --- app/scripts/lib/config-manager.js | 2 +- app/scripts/lib/encryptor.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index d12304c46..ae4a84082 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -118,7 +118,7 @@ ConfigManager.prototype.setVault = function (encryptedString) { ConfigManager.prototype.getVault = function () { var data = this.getData() - return ('vault' in data) && data.vault + return ('vault' in data) && data.vault } ConfigManager.prototype.getKeychains = function () { diff --git a/app/scripts/lib/encryptor.js b/app/scripts/lib/encryptor.js index 91d6ed5ce..8a3b0b023 100644 --- a/app/scripts/lib/encryptor.js +++ b/app/scripts/lib/encryptor.js @@ -18,6 +18,10 @@ module.exports = { // Buffer <-> Hex string methods serializeBufferForStorage, serializeBufferFromStorage, + + // Buffer <-> base64 string methods + encodeBufferToBase64, + decodeBase64ToBuffer, } // Takes a Pojo, returns encrypted text. @@ -117,3 +121,15 @@ function unprefixedHex (num) { } return hex } + +function encodeBufferToBase64 (buf) { + var b64encoded = btoa(String.fromCharCode.apply(null, buf)) + return b64encoded +} + +function decodeBase64ToBuffer (base64) { + var u8_2 = new Uint8Array(atob(b64encoded).split("") + .map(function(c) { + return c.charCodeAt(0) + })) +} -- cgit v1.2.3 From 0deed1775237bc8d48eb41e83b5a661b55e4b6be Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 20 Oct 2016 12:07:53 -0700 Subject: Fix tests --- app/scripts/lib/encryptor.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/encryptor.js b/app/scripts/lib/encryptor.js index 8a3b0b023..3d069ab33 100644 --- a/app/scripts/lib/encryptor.js +++ b/app/scripts/lib/encryptor.js @@ -42,8 +42,9 @@ function encryptWithKey (key, dataObj) { iv: vector, }, key, dataBuffer).then(function(buf){ var buffer = new Uint8Array(buf) - var vectorStr = serializeBufferForStorage(vector) - return serializeBufferForStorage(buffer) + vectorStr + var vectorStr = encodeBufferToBase64(vector) + var vaultStr = encodeBufferToBase64(buffer) + return `${vaultStr}\\${vectorStr}` }) } @@ -56,9 +57,9 @@ function decrypt (password, text) { } function decryptWithKey (key, text) { - const parts = text.split('0x') - const encryptedData = serializeBufferFromStorage(parts[1]) - const vector = serializeBufferFromStorage(parts[2]) + const parts = text.split('\\') + const encryptedData = decodeBase64ToBuffer(parts[0]) + const vector = decodeBase64ToBuffer(parts[1]) return crypto.subtle.decrypt({name: 'AES-GCM', iv: vector}, key, encryptedData) .then(function(result){ const decryptedData = new Uint8Array(result) @@ -128,8 +129,9 @@ function encodeBufferToBase64 (buf) { } function decodeBase64ToBuffer (base64) { - var u8_2 = new Uint8Array(atob(b64encoded).split("") + var buf = new Uint8Array(atob(base64).split('') .map(function(c) { return c.charCodeAt(0) })) + return buf } -- cgit v1.2.3 From 55d56f77cf42a9c4e80768fd7e4a9bb6f0485606 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 20 Oct 2016 16:44:31 -0700 Subject: Began adding first basic keyring --- app/scripts/lib/idStore.js | 1 - 1 file changed, 1 deletion(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js index 9d0ca7f19..416b65b85 100644 --- a/app/scripts/lib/idStore.js +++ b/app/scripts/lib/idStore.js @@ -114,7 +114,6 @@ IdentityStore.prototype.getState = function () { conversionRate: configManager.getConversionRate(), conversionDate: configManager.getConversionDate(), gasMultiplier: configManager.getGasMultiplier(), - })) } -- cgit v1.2.3 From c3e1c5c57f2062155626647e239c2a760f3e4b8a Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Fri, 21 Oct 2016 11:10:36 -0700 Subject: Added SimpleKeyring tests --- app/scripts/lib/sig-util.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 app/scripts/lib/sig-util.js (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/sig-util.js b/app/scripts/lib/sig-util.js new file mode 100644 index 000000000..f8748f535 --- /dev/null +++ b/app/scripts/lib/sig-util.js @@ -0,0 +1,23 @@ +const ethUtil = require('ethereumjs-util') + +module.exports = { + + concatSig: function (v, r, s) { + const rSig = ethUtil.fromSigned(r) + const sSig = ethUtil.fromSigned(s) + const vSig = ethUtil.bufferToInt(v) + const rStr = padWithZeroes(ethUtil.toUnsigned(rSig).toString('hex'), 64) + const sStr = padWithZeroes(ethUtil.toUnsigned(sSig).toString('hex'), 64) + const vStr = ethUtil.stripHexPrefix(ethUtil.intToHex(vSig)) + return ethUtil.addHexPrefix(rStr.concat(sStr, vStr)).toString('hex') + }, + +} + +function padWithZeroes (number, length) { + var myString = '' + number + while (myString.length < length) { + myString = '0' + myString + } + return myString +} -- cgit v1.2.3 From 44aa1be2778a1647c9a607fd02c61bf93704d92d Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Fri, 21 Oct 2016 12:11:54 -0700 Subject: Create basic keyring-controller unit test file --- app/scripts/lib/encryptor.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/encryptor.js b/app/scripts/lib/encryptor.js index 3d069ab33..832e6d528 100644 --- a/app/scripts/lib/encryptor.js +++ b/app/scripts/lib/encryptor.js @@ -22,6 +22,8 @@ module.exports = { // Buffer <-> base64 string methods encodeBufferToBase64, decodeBase64ToBuffer, + + generateSalt, } // Takes a Pojo, returns encrypted text. @@ -135,3 +137,10 @@ function decodeBase64ToBuffer (base64) { })) return buf } + +function generateSalt (byteCount = 32) { + var view = new Uint8Array(byteCount) + global.crypto.getRandomValues(view) + var b64encoded = btoa(String.fromCharCode.apply(null, view)) + return b64encoded +} -- cgit v1.2.3 From 678301a20e6112d79a052c13f921bb75c451c613 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Tue, 25 Oct 2016 13:24:03 -0700 Subject: Phase out extra warning screen. --- app/scripts/lib/config-manager.js | 15 --------------- app/scripts/lib/idStore.js | 1 - 2 files changed, 16 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index ae4a84082..abe5dfc87 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -368,21 +368,6 @@ ConfigManager.prototype.getConversionDate = function () { return (('conversionDate' in data) && data.conversionDate) || 'N/A' } -ConfigManager.prototype.setShouldntShowWarning = function () { - var data = this.getData() - if (data.isEthConfirmed) { - data.isEthConfirmed = !data.isEthConfirmed - } else { - data.isEthConfirmed = true - } - this.setData(data) -} - -ConfigManager.prototype.getShouldntShowWarning = function () { - var data = this.getData() - return ('isEthConfirmed' in data) && data.isEthConfirmed -} - ConfigManager.prototype.getShapeShiftTxList = function () { var data = this.getData() var shapeShiftTxList = data.shapeShiftTxList ? data.shapeShiftTxList : [] diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js index 416b65b85..5943826a3 100644 --- a/app/scripts/lib/idStore.js +++ b/app/scripts/lib/idStore.js @@ -103,7 +103,6 @@ IdentityStore.prototype.getState = function () { isUnlocked: this._isUnlocked(), seedWords: seedWords, isConfirmed: configManager.getConfirmed(), - isEthConfirmed: configManager.getShouldntShowWarning(), unconfTxs: configManager.unconfirmedTxs(), transactions: configManager.getTxList(), unconfMsgs: messageManager.unconfirmedMsgs(), -- cgit v1.2.3 From 18e5173f061c2e21b5acb3e1b329343b5cffc558 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Sat, 29 Oct 2016 02:29:25 -0700 Subject: Now migrating old vaults to new DEN format --- app/scripts/lib/idStore-migrator.js | 48 +++++++++++++++++++++++++++++++++++++ app/scripts/lib/idStore.js | 4 +++- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 app/scripts/lib/idStore-migrator.js (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/idStore-migrator.js b/app/scripts/lib/idStore-migrator.js new file mode 100644 index 000000000..f8f7cb51a --- /dev/null +++ b/app/scripts/lib/idStore-migrator.js @@ -0,0 +1,48 @@ +const IdentityStore = require('./idStore') + + +module.exports = class IdentityStoreMigrator { + + constructor ({ configManager }) { + this.configManager = configManager + this.idStore = new IdentityStore({ configManager }) + } + + oldSeedForPassword( password ) { + const isOldVault = this.hasOldVault() + if (!isOldVault) { + console.log('does not seem to have old vault') + console.log('THE DATA:') + console.log(this.configManager.getData()) + return Promise.resolve(null) + } + + return new Promise((resolve, reject) => { + this.idStore.submitPassword(password, (err) => { + if (err) return reject(err) + try { + resolve(this.serializeVault()) + } catch (e) { + reject(e) + } + }) + }) + } + + serializeVault() { + const mnemonic = this.idStore._idmgmt.getSeed() + console.dir(this.idStore._idmgmt) + const n = this.idStore._getAddresses().length + + return { + type: 'HD Key Tree', + data: { mnemonic, n }, + } + } + + hasOldVault() { + const wallet = this.configManager.getWallet() + console.log('found old wallet: ' + wallet) + return wallet + } +} diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js index 14f25dd1d..8ee2b62dd 100644 --- a/app/scripts/lib/idStore.js +++ b/app/scripts/lib/idStore.js @@ -422,7 +422,9 @@ IdentityStore.prototype._loadIdentities = function () { var addresses = this._getAddresses() addresses.forEach((address, i) => { // // add to ethStore - this._ethStore.addAccount(ethUtil.addHexPrefix(address)) + if (this._ethStore) { + this._ethStore.addAccount(ethUtil.addHexPrefix(address)) + } // add to identities const defaultLabel = 'Wallet ' + (i + 1) const nickname = configManager.nicknameForWallet(address) -- cgit v1.2.3 From 96643c222a74552d98218fe1f9fc81e493a1960f Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Mon, 31 Oct 2016 11:35:09 -0700 Subject: Implement seed word confirmation page. Remove logs. Move HD render files to ui/app. --- app/scripts/lib/config-manager.js | 15 ++++++++++++++- app/scripts/lib/idStore-migrator.js | 5 ----- 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index abe5dfc87..8f5590738 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -2,6 +2,7 @@ const Migrator = require('pojo-migrator') const MetamaskConfig = require('../config.js') const migrations = require('./migrations') const rp = require('request-promise') +const ethUtil = require('ethereumjs-util') const TESTNET_RPC = MetamaskConfig.network.testnet const MAINNET_RPC = MetamaskConfig.network.mainnet @@ -138,7 +139,7 @@ ConfigManager.prototype.getSelectedAccount = function () { ConfigManager.prototype.setSelectedAccount = function (address) { var config = this.getConfig() - config.selectedAccount = address + config.selectedAccount = ethUtil.addHexPrefix(address) this.setConfig(config) } @@ -153,11 +154,23 @@ ConfigManager.prototype.setShowSeedWords = function (should) { this.setData(data) } + ConfigManager.prototype.getShouldShowSeedWords = function () { var data = this.migrator.getData() return data.showSeedWords } +ConfigManager.prototype.setSeedWords = function (words) { + var data = this.getData() + data.seedWords = words + this.setData(data) +} + +ConfigManager.prototype.getSeedWords = function () { + var data = this.getData() + return ('seedWords' in data) && data.seedWords +} + ConfigManager.prototype.getCurrentRpcAddress = function () { var provider = this.getProvider() if (!provider) return null diff --git a/app/scripts/lib/idStore-migrator.js b/app/scripts/lib/idStore-migrator.js index f8f7cb51a..c81e7ddfe 100644 --- a/app/scripts/lib/idStore-migrator.js +++ b/app/scripts/lib/idStore-migrator.js @@ -11,9 +11,6 @@ module.exports = class IdentityStoreMigrator { oldSeedForPassword( password ) { const isOldVault = this.hasOldVault() if (!isOldVault) { - console.log('does not seem to have old vault') - console.log('THE DATA:') - console.log(this.configManager.getData()) return Promise.resolve(null) } @@ -31,7 +28,6 @@ module.exports = class IdentityStoreMigrator { serializeVault() { const mnemonic = this.idStore._idmgmt.getSeed() - console.dir(this.idStore._idmgmt) const n = this.idStore._getAddresses().length return { @@ -42,7 +38,6 @@ module.exports = class IdentityStoreMigrator { hasOldVault() { const wallet = this.configManager.getWallet() - console.log('found old wallet: ' + wallet) return wallet } } -- cgit v1.2.3 From 4cf1b606e46fa735263b5e1fade5910b572335e3 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 2 Nov 2016 15:04:50 -0700 Subject: Fix handling of migrating old vault style Now old vaults are recognized as an "Initialized" MetaMask instance. Upon logging in, when fetching the initial password-derived key, if there is no new-style vault, but there is an old style vault, it is migrated to the new format before proceeding through the usual unlocking steps. --- app/scripts/lib/idStore-migrator.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/idStore-migrator.js b/app/scripts/lib/idStore-migrator.js index c81e7ddfe..2d1826641 100644 --- a/app/scripts/lib/idStore-migrator.js +++ b/app/scripts/lib/idStore-migrator.js @@ -5,12 +5,21 @@ module.exports = class IdentityStoreMigrator { constructor ({ configManager }) { this.configManager = configManager - this.idStore = new IdentityStore({ configManager }) + const hasOldVault = this.hasOldVault() + if (!hasOldVault) { + this.idStore = new IdentityStore({ configManager }) + } } oldSeedForPassword( password ) { - const isOldVault = this.hasOldVault() - if (!isOldVault) { + const hasOldVault = this.hasOldVault() + const configManager = this.configManager + + if (!this.idStore) { + this.idStore = new IdentityStore({ configManager }) + } + + if (!hasOldVault) { return Promise.resolve(null) } -- cgit v1.2.3 From 756f56cfee442992c51ac84b042b36dc3f7845ba Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 3 Nov 2016 10:42:34 -0700 Subject: Don't faucet in development --- app/scripts/lib/auto-faucet.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/auto-faucet.js b/app/scripts/lib/auto-faucet.js index 59cf0ec20..ec5e8ed4c 100644 --- a/app/scripts/lib/auto-faucet.js +++ b/app/scripts/lib/auto-faucet.js @@ -1,6 +1,8 @@ -var uri = 'https://faucet.metamask.io/' +const uri = 'https://faucet.metamask.io/' +const METAMASK_DEBUG = 'GULP_METAMASK_DEBUG' module.exports = function (address) { + if (METAMASK_DEBUG) return // Don't faucet in development var http = new XMLHttpRequest() var data = address http.open('POST', uri, true) -- cgit v1.2.3 From 4db976ae46352c49e4401eba865081425419efe0 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 3 Nov 2016 11:22:10 -0700 Subject: Don't faucet during tests --- app/scripts/lib/auto-faucet.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/auto-faucet.js b/app/scripts/lib/auto-faucet.js index ec5e8ed4c..1e86f735e 100644 --- a/app/scripts/lib/auto-faucet.js +++ b/app/scripts/lib/auto-faucet.js @@ -1,8 +1,9 @@ const uri = 'https://faucet.metamask.io/' const METAMASK_DEBUG = 'GULP_METAMASK_DEBUG' +const env = process.env.METAMASK_ENV module.exports = function (address) { - if (METAMASK_DEBUG) return // Don't faucet in development + if (METAMASK_DEBUG || env === 'test') return // Don't faucet in development or test var http = new XMLHttpRequest() var data = address http.open('POST', uri, true) -- cgit v1.2.3 From bd2a429a85d27fc82e76115ec136640cbfecf9e1 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 3 Nov 2016 11:59:20 -0700 Subject: Fix account nicknaming bug When nicknaming, we weren't normalizing the input, and so we were retrieving with differently formatted addresses than we were persisting. --- app/scripts/lib/config-manager.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index 8f5590738..f50d95c12 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -269,13 +269,15 @@ ConfigManager.prototype.getWalletNicknames = function () { } ConfigManager.prototype.nicknameForWallet = function (account) { + const address = ethUtil.addHexPrefix(account.toLowerCase()) const nicknames = this.getWalletNicknames() - return nicknames[account] + return nicknames[address] } ConfigManager.prototype.setNicknameForWallet = function (account, nickname) { + const address = ethUtil.addHexPrefix(account.toLowerCase()) const nicknames = this.getWalletNicknames() - nicknames[account] = nickname + nicknames[address] = nickname var data = this.getData() data.walletNicknames = nicknames this.setData(data) -- cgit v1.2.3 From ba7d6b437f2e03a9e2bb46dcda846cee1f816ce1 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 3 Nov 2016 16:06:57 -0700 Subject: Fix password validation and persistence issue Was wiping the vault on each successful password attempt... :P --- app/scripts/lib/encryptor.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/encryptor.js b/app/scripts/lib/encryptor.js index 832e6d528..fe83b86dd 100644 --- a/app/scripts/lib/encryptor.js +++ b/app/scripts/lib/encryptor.js @@ -69,6 +69,9 @@ function decryptWithKey (key, text) { const decryptedObj = JSON.parse(decryptedStr) return decryptedObj }) + .catch(function(reason) { + throw new Error('Incorrect password') + }) } function convertStringToArrayBufferView (str) { -- cgit v1.2.3 From 23263bec7d5100accd61f7648fd9355fc95e2bb7 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Fri, 11 Nov 2016 10:26:12 -0800 Subject: Linting to the max. --- app/scripts/lib/auto-reload.js | 5 ++--- app/scripts/lib/config-manager.js | 3 +-- app/scripts/lib/encryptor.js | 10 +++++----- app/scripts/lib/idStore-migrator.js | 6 +++--- app/scripts/lib/idStore.js | 8 ++++---- app/scripts/lib/inpage-provider.js | 8 ++++---- app/scripts/lib/is-popup-or-notification.js | 2 +- app/scripts/lib/notifications.js | 12 ++++-------- 8 files changed, 24 insertions(+), 30 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/auto-reload.js b/app/scripts/lib/auto-reload.js index 3c90905db..1302df35f 100644 --- a/app/scripts/lib/auto-reload.js +++ b/app/scripts/lib/auto-reload.js @@ -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() -} \ No newline at end of file +} diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index f50d95c12..0c5daa8e6 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -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) { diff --git a/app/scripts/lib/encryptor.js b/app/scripts/lib/encryptor.js index fe83b86dd..acfb418a1 100644 --- a/app/scripts/lib/encryptor.js +++ b/app/scripts/lib/encryptor.js @@ -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 diff --git a/app/scripts/lib/idStore-migrator.js b/app/scripts/lib/idStore-migrator.js index 2d1826641..818364720 100644 --- a/app/scripts/lib/idStore-migrator.js +++ b/app/scripts/lib/idStore-migrator.js @@ -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 } diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js index 390c8a8ab..2a46b1b5d 100644 --- a/app/scripts/lib/idStore.js +++ b/app/scripts/lib/idStore.js @@ -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 diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js index 052a8f5fe..6795f2bd4 100644 --- a/app/scripts/lib/inpage-provider.js +++ b/app/scripts/lib/inpage-provider.js @@ -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 { diff --git a/app/scripts/lib/is-popup-or-notification.js b/app/scripts/lib/is-popup-or-notification.js index 5c38ac823..693fa8751 100644 --- a/app/scripts/lib/is-popup-or-notification.js +++ b/app/scripts/lib/is-popup-or-notification.js @@ -1,4 +1,4 @@ -module.exports = function isPopupOrNotification() { +module.exports = function isPopupOrNotification () { const url = window.location.href if (url.match(/popup.html$/)) { return 'popup' diff --git a/app/scripts/lib/notifications.js b/app/scripts/lib/notifications.js index cd7535232..3db1ac6b5 100644 --- a/app/scripts/lib/notifications.js +++ b/app/scripts/lib/notifications.js @@ -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 -- cgit v1.2.3 From 7012747fb546bc1a95ce65b71bd3f74075150b77 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Fri, 11 Nov 2016 15:37:54 -0800 Subject: Package normalize inside sig util file. --- app/scripts/lib/sig-util.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/sig-util.js b/app/scripts/lib/sig-util.js index f8748f535..193dda381 100644 --- a/app/scripts/lib/sig-util.js +++ b/app/scripts/lib/sig-util.js @@ -12,6 +12,11 @@ module.exports = { return ethUtil.addHexPrefix(rStr.concat(sStr, vStr)).toString('hex') }, + normalize: function (address) { + if (!address) return + return ethUtil.addHexPrefix(address.toLowerCase()) + }, + } function padWithZeroes (number, length) { -- cgit v1.2.3 From 7de6b12aad4a674bdbb0749d2e61d9fd5f69c536 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Mon, 14 Nov 2016 16:49:16 -0800 Subject: Re-enable disclaimer screen. Rename variables to reflect role more clearly. --- app/scripts/lib/config-manager.js | 8 ++++---- app/scripts/lib/idStore.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index 0c5daa8e6..faf64bfdc 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -313,15 +313,15 @@ ConfigManager.prototype._emitUpdates = function (state) { }) } -ConfigManager.prototype.setConfirmed = function (confirmed) { +ConfigManager.prototype.setConfirmedDisclaimer = function (confirmed) { var data = this.getData() - data.isConfirmed = confirmed + data.isDisclaimerConfirmed = confirmed this.setData(data) } -ConfigManager.prototype.getConfirmed = function () { +ConfigManager.prototype.getConfirmedDisclaimer = function () { var data = this.getData() - return ('isConfirmed' in data) && data.isConfirmed + return ('isDisclaimerConfirmed' in data) && data.isDisclaimerConfirmed } ConfigManager.prototype.setTOSHash = function (hash) { diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js index 2a46b1b5d..31895b9bc 100644 --- a/app/scripts/lib/idStore.js +++ b/app/scripts/lib/idStore.js @@ -102,7 +102,7 @@ IdentityStore.prototype.getState = function () { isInitialized: !!configManager.getWallet() && !seedWords, isUnlocked: this._isUnlocked(), seedWords: seedWords, - isConfirmed: configManager.getConfirmed(), + isDisclaimerConfirmed: configManager.getConfirmedDisclaimer(), unconfTxs: configManager.unconfirmedTxs(), transactions: configManager.getTxList(), unconfMsgs: messageManager.unconfirmedMsgs(), -- cgit v1.2.3 From 585284cb88ec18515b246555a19c745b5bf8de84 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Tue, 15 Nov 2016 13:44:22 -0800 Subject: Lints. --- app/scripts/lib/idStore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js index eb625987f..d11c38be1 100644 --- a/app/scripts/lib/idStore.js +++ b/app/scripts/lib/idStore.js @@ -261,7 +261,7 @@ IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDone // 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.message || err) if (result === estimationParams.gas) { txData.simulationFails = true -- cgit v1.2.3 From e18109f1eac855a828dc5c6011bbc8a4dbc69f4c Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Tue, 15 Nov 2016 13:45:21 -0800 Subject: Fix semantics in comments --- app/scripts/lib/encryptor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/encryptor.js b/app/scripts/lib/encryptor.js index acfb418a1..2af2a1d2b 100644 --- a/app/scripts/lib/encryptor.js +++ b/app/scripts/lib/encryptor.js @@ -26,7 +26,7 @@ module.exports = { generateSalt, } -// Takes a Pojo, returns encrypted text. +// Takes a Pojo, returns cypher text. function encrypt (password, dataObj) { return keyFromPassword(password) .then(function (passwordDerivedKey) { -- cgit v1.2.3 From f229d32442f34859be169e38a42ffecdfb8fc48a Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 17 Nov 2016 13:49:46 -0800 Subject: Replace old random-id code with incrementing id generator --- app/scripts/lib/inpage-provider.js | 11 +---------- app/scripts/lib/random-id.js | 9 +++++++++ 2 files changed, 10 insertions(+), 10 deletions(-) create mode 100644 app/scripts/lib/random-id.js (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js index 052a8f5fe..f1ba2e0ed 100644 --- a/app/scripts/lib/inpage-provider.js +++ b/app/scripts/lib/inpage-provider.js @@ -2,6 +2,7 @@ const Streams = require('mississippi') const StreamProvider = require('web3-stream-provider') const ObjectMultiplex = require('./obj-multiplex') const RemoteStore = require('./remote-store.js').RemoteStore +const createRandomId = require('./random-id') module.exports = MetamaskInpageProvider @@ -119,16 +120,6 @@ function remoteStoreWithLocalStorageCache (storageKey) { return store } -function createRandomId(){ - const extraDigits = 3 - // 13 time digits - const datePart = new Date().getTime() * Math.pow(10, extraDigits) - // 3 random digits - const extraPart = Math.floor(Math.random() * Math.pow(10, extraDigits)) - // 16 digits - return datePart + extraPart -} - function eachJsonMessage(payload, transformFn){ if (Array.isArray(payload)) { return payload.map(transformFn) diff --git a/app/scripts/lib/random-id.js b/app/scripts/lib/random-id.js new file mode 100644 index 000000000..3c5ae5600 --- /dev/null +++ b/app/scripts/lib/random-id.js @@ -0,0 +1,9 @@ +const MAX = 1000000000 + +let idCounter = Math.round( Math.random() * MAX ) +function createRandomId() { + idCounter = idCounter % MAX + return idCounter++ +} + +module.exports = createRandomId -- cgit v1.2.3 From 39e0a33bba2709971edec0304027f646cb2db3cc Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 17 Nov 2016 14:29:35 -0800 Subject: random-id - use Number.MAX_SAFE_INTEGER as max --- app/scripts/lib/random-id.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/random-id.js b/app/scripts/lib/random-id.js index 3c5ae5600..78d9e34a5 100644 --- a/app/scripts/lib/random-id.js +++ b/app/scripts/lib/random-id.js @@ -1,4 +1,4 @@ -const MAX = 1000000000 +const MAX = Number.MAX_SAFE_INTEGER let idCounter = Math.round( Math.random() * MAX ) function createRandomId() { -- cgit v1.2.3 From ce1c5eb75a17f6a5fca9fce1a6d400e690ecabf7 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Fri, 18 Nov 2016 11:37:07 -0800 Subject: Update migration code for new hd wallet param name --- app/scripts/lib/idStore-migrator.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/idStore-migrator.js b/app/scripts/lib/idStore-migrator.js index 818364720..18134b677 100644 --- a/app/scripts/lib/idStore-migrator.js +++ b/app/scripts/lib/idStore-migrator.js @@ -37,11 +37,11 @@ module.exports = class IdentityStoreMigrator { serializeVault () { const mnemonic = this.idStore._idmgmt.getSeed() - const n = this.idStore._getAddresses().length + const numberOfAccounts = this.idStore._getAddresses().length return { type: 'HD Key Tree', - data: { mnemonic, n }, + data: { mnemonic, numberOfAccounts }, } } -- cgit v1.2.3 From d6286cd13aef8b861d84b078b468b02b302ba801 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Fri, 18 Nov 2016 16:27:26 -0800 Subject: Maintain linting. --- app/scripts/lib/inpage-provider.js | 2 +- app/scripts/lib/random-id.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js index c9d617996..034812b6a 100644 --- a/app/scripts/lib/inpage-provider.js +++ b/app/scripts/lib/inpage-provider.js @@ -120,7 +120,7 @@ function remoteStoreWithLocalStorageCache (storageKey) { return store } -function eachJsonMessage(payload, transformFn){ +function eachJsonMessage (payload, transformFn) { if (Array.isArray(payload)) { return payload.map(transformFn) } else { diff --git a/app/scripts/lib/random-id.js b/app/scripts/lib/random-id.js index 78d9e34a5..788f3370f 100644 --- a/app/scripts/lib/random-id.js +++ b/app/scripts/lib/random-id.js @@ -1,7 +1,7 @@ const MAX = Number.MAX_SAFE_INTEGER -let idCounter = Math.round( Math.random() * MAX ) -function createRandomId() { +let idCounter = Math.round(Math.random() * MAX) +function createRandomId () { idCounter = idCounter % MAX return idCounter++ } -- cgit v1.2.3