@@ -5,6 +5,7 @@ const {spawn, spawnSync} = require('child_process')
5
5
const portfinder = require ( 'portfinder' )
6
6
const net = require ( 'net' )
7
7
const underscore = require ( 'underscore' )
8
+ const bcrypt = require ( 'bcryptjs' )
8
9
9
10
const { app, ipcMain} = require ( 'electron' )
10
11
const { getExtensionsPath} = require ( '../js/lib/appUrlUtil' )
@@ -25,6 +26,7 @@ const gethProcessKey = isWindows ? 'geth.exe' : 'geth'
25
26
26
27
const ipcPath = isWindows ? '\\\\.\\pipe\\geth.ipc' : path . join ( gethDataDir , 'geth.ipc' )
27
28
const pidPath = isWindows ? '\\\\.\\pipe\\geth.pid' : path . join ( gethDataDir , 'geth.pid' )
29
+ const pwPath = path . join ( gethDataDir , 'wallets.pw' )
28
30
const gethProcessPath = path . join ( getExtensionsPath ( 'bin' ) , gethProcessKey )
29
31
30
32
const configurePeers = async ( dataDir ) => {
@@ -335,6 +337,46 @@ ipcMain.on('eth-wallet-get-keys-path', (e) => {
335
337
e . sender . send ( 'eth-wallet-keys-path' , path . join ( gethDataDir , 'keystore' ) )
336
338
} )
337
339
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
+
338
380
const launchGeth = async function ( ) {
339
381
await spawnGeth ( )
340
382
}
0 commit comments