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

Commit 9a22ba4

Browse files
authored
Merge pull request #15027 from Slava/eth-wallet-password
eth-wallet: password flow based on the hash stored on the fs
2 parents aff1a96 + 919d900 commit 9a22ba4

File tree

3 files changed

+58
-118
lines changed

3 files changed

+58
-118
lines changed

app/ethWallet-geth.js

+42
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const {spawn, spawnSync} = require('child_process')
55
const portfinder = require('portfinder')
66
const net = require('net')
77
const underscore = require('underscore')
8+
const bcrypt = require('bcryptjs')
89

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

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

3032
const configurePeers = async (dataDir) => {
@@ -335,6 +337,46 @@ ipcMain.on('eth-wallet-get-keys-path', (e) => {
335337
e.sender.send('eth-wallet-keys-path', path.join(gethDataDir, 'keystore'))
336338
})
337339

340+
ipcMain.on('eth-wallet-get-password-hash', (e) => {
341+
fs.readFile(pwPath, 'utf8', (err, hash) => {
342+
if (err || !hash) {
343+
e.sender.send('eth-wallet-password-hash', null)
344+
} else {
345+
e.sender.send('eth-wallet-password-hash', hash)
346+
}
347+
})
348+
})
349+
350+
ipcMain.on('eth-wallet-store-password-hash', (e, str) => {
351+
bcrypt.genSalt(14, (err, salt) => {
352+
if (err) {
353+
console.error(err)
354+
return
355+
}
356+
bcrypt.hash(str, salt, (err, hash) => {
357+
if (err) {
358+
console.error(err)
359+
return
360+
}
361+
fs.writeFile(pwPath, hash, (err) => {
362+
if (err) {
363+
console.error(err)
364+
}
365+
})
366+
})
367+
})
368+
})
369+
370+
ipcMain.on('eth-wallet-get-compare-password-hash', (e, str, hash) => {
371+
bcrypt.compare(str, hash, (err, res) => {
372+
if (err) {
373+
e.sender.send('eth-wallet-compare-password-hash', false)
374+
} else {
375+
e.sender.send('eth-wallet-compare-password-hash', res)
376+
}
377+
})
378+
})
379+
338380
const launchGeth = async function () {
339381
await spawnGeth()
340382
}

package-lock.json

+12-115
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@
9595
"bat-balance": "^1.0.7",
9696
"bat-client": "^4.0.1",
9797
"bat-publisher": "^2.0.23",
98+
"bcryptjs": "^2.4.3",
9899
"bignumber.js": "^4.0.4",
99-
"brave-crypto": "^0.2.0",
100100
"bloodhound-js": "github:brave/bloodhound",
101+
"brave-crypto": "^0.2.0",
101102
"child_process": "^1.0.2",
102103
"clipboard-copy": "^1.0.0",
103104
"compare-versions": "^3.0.1",
@@ -186,13 +187,13 @@
186187
"less": "^2.5.3",
187188
"less-loader": "^2.2.1",
188189
"lolex": "~1.3.2",
189-
"meteor-dapp-wallet-prebuilt": "0.2.30",
190+
"meteor-dapp-wallet-prebuilt": "0.2.31",
190191
"mkdirp": "^0.5.1",
191192
"mocha": "^2.3.4",
192193
"mockery": "^2.1.0",
193194
"muon-winstaller": "^3.0.0",
194195
"ncp": "^2.0.0",
195-
"node-gyp": "^3.3.1",
196+
"node-gyp": "^3.8.0",
196197
"node-libs-browser": "~2.0.0",
197198
"node-static": "^0.7.7",
198199
"nsp": "^3.2.1",

0 commit comments

Comments
 (0)