Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Merge pull request #15027 from Slava/eth-wallet-password
Browse files Browse the repository at this point in the history
eth-wallet: password flow based on the hash stored on the fs
  • Loading branch information
Slava committed Aug 15, 2018
1 parent 670cb25 commit c1d1fe9
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 118 deletions.
42 changes: 42 additions & 0 deletions app/ethWallet-geth.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {spawn, spawnSync} = require('child_process')
const portfinder = require('portfinder')
const net = require('net')
const underscore = require('underscore')
const bcrypt = require('bcryptjs')

const {app, ipcMain} = require('electron')
const {getExtensionsPath} = require('../js/lib/appUrlUtil')
Expand All @@ -25,6 +26,7 @@ const gethProcessKey = isWindows ? 'geth.exe' : 'geth'

const ipcPath = isWindows ? '\\\\.\\pipe\\geth.ipc' : path.join(gethDataDir, 'geth.ipc')
const pidPath = isWindows ? '\\\\.\\pipe\\geth.pid' : path.join(gethDataDir, 'geth.pid')
const pwPath = path.join(gethDataDir, 'wallets.pw')
const gethProcessPath = path.join(getExtensionsPath('bin'), gethProcessKey)

const configurePeers = async (dataDir) => {
Expand Down Expand Up @@ -293,6 +295,46 @@ ipcMain.on('eth-wallet-get-keys-path', (e) => {
e.sender.send('eth-wallet-keys-path', path.join(gethDataDir, 'keystore'))
})

ipcMain.on('eth-wallet-get-password-hash', (e) => {
fs.readFile(pwPath, 'utf8', (err, hash) => {
if (err || !hash) {
e.sender.send('eth-wallet-password-hash', null)
} else {
e.sender.send('eth-wallet-password-hash', hash)
}
})
})

ipcMain.on('eth-wallet-store-password-hash', (e, str) => {
bcrypt.genSalt(14, (err, salt) => {
if (err) {
console.error(err)
return
}
bcrypt.hash(str, salt, (err, hash) => {
if (err) {
console.error(err)
return
}
fs.writeFile(pwPath, hash, (err) => {
if (err) {
console.error(err)
}
})
})
})
})

ipcMain.on('eth-wallet-get-compare-password-hash', (e, str, hash) => {
bcrypt.compare(str, hash, (err, res) => {
if (err) {
e.sender.send('eth-wallet-compare-password-hash', false)
} else {
e.sender.send('eth-wallet-compare-password-hash', res)
}
})
})

const launchGeth = async function () {
await spawnGeth()
}
Expand Down
127 changes: 12 additions & 115 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@
"bat-balance": "^1.0.7",
"bat-client": "^4.0.1",
"bat-publisher": "^2.0.23",
"bcryptjs": "^2.4.3",
"bignumber.js": "^4.0.4",
"brave-crypto": "^0.2.0",
"bloodhound-js": "github:brave/bloodhound",
"brave-crypto": "^0.2.0",
"child_process": "^1.0.2",
"clipboard-copy": "^1.0.0",
"compare-versions": "^3.0.1",
Expand Down Expand Up @@ -186,13 +187,13 @@
"less": "^2.5.3",
"less-loader": "^2.2.1",
"lolex": "~1.3.2",
"meteor-dapp-wallet-prebuilt": "0.2.30",
"meteor-dapp-wallet-prebuilt": "0.2.31",
"mkdirp": "^0.5.1",
"mocha": "^2.3.4",
"mockery": "^2.1.0",
"muon-winstaller": "^3.0.0",
"ncp": "^2.0.0",
"node-gyp": "^3.3.1",
"node-gyp": "^3.8.0",
"node-libs-browser": "~2.0.0",
"node-static": "^0.7.7",
"nsp": "^3.2.1",
Expand Down

0 comments on commit c1d1fe9

Please sign in to comment.