Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Commit

Permalink
Adds wallet generator option
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-miller-0 committed Feb 7, 2018
1 parent e863f1f commit 4cf87a7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
38 changes: 21 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ const argv = require('yargs')
.alias('n', 'network')
.command('start', 'Start bridge client. Begin listening to peers and connected blockchains')
.alias('s', 'start')
.command('wallet', 'Generate a new wallet. You will be prompted for a password')
.alias('w', 'wallet')
.command('create-wallet', 'Generate a new wallet. You will be prompted for a password')
.argv;

console.log('Bridge Client v0.1\n')
Expand Down Expand Up @@ -51,7 +50,7 @@ if(argv.network) {
}
}


// Add a bridge
if (argv.add) {
// Add a bridge group
const group = argv.add.split(',');
Expand All @@ -62,6 +61,7 @@ if (argv.add) {
})
}

// Bootstrap with peers
if (argv.bootstrap) {
// Add bootstrap peers
const _peers = argv.bootstrap.split(',');
Expand All @@ -78,35 +78,30 @@ if (argv.bootstrap) {
})
}

if (argv.wallet) {
// Wallets - create or import
if (argv['create-wallet']) {
let pw;
let randomness;
let done = false;
let qText = ['Password', 'Re-enter password'];

let questions = [{
name: 'Password',
name: qText[0],
hidden: true,
replace: '*'
}, {
name: 'Re-enter password',
name: qText[1],
hidden: true,
replace: '*'
}];

if (argv.wallet == true) {
questions.push({
name: 'Randomness (just type random stuff)',
hidden: true,
replace: '*',
})
}

prompt.start();
prompt.get(questions, (err, res) => {
if (res['Password'] != res['Re-enter password']) {
if (res[qText[0]] != res[qText[1]]) {
console.log('Error: Your passwords do not match')
} else {
const w = new Wallet({ password: res[qText[0]] });
w.save(DIR)
}
console.log('res', res);
})
// console.log('Generating new wallet. Please enter a password.')
// process.stdout.write('Password> ');
Expand All @@ -126,6 +121,15 @@ if (argv.wallet) {
}

if (argv.start) {
// Get wallet
/*if (!argv.wallet) {
// If no wallet is provided, pull the first one in DATADIR/wallets
} else if (argv.wallet.length == 64) {
// The user can pass in a path to a wallet file
} else {
// Otherwise the user passes in an index of the desired wallet file within
// the DATADIR. This defaults to zero
}*/
// Start listening to peers and blockchains
let peers;
let clients;
Expand Down
23 changes: 19 additions & 4 deletions src/lib/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,32 @@
const crypto = require('crypto');
const ethwallet = require('ethereumjs-wallet');
const ethutil = require('ethereumjs-util');
const fs = require('fs');

class Wallet {
constructor(opts) {

this.wallet = new ethwallet(opts.pkey || crypto.randomBytes(32))
console.log('opts', opts)
this.password = opts.password ? opts.password : '';
console.log('this.pw', this.password)
this.wallet = new ethwallet(crypto.randomBytes(32));
}

salt(n, r) {

save(dir=`${process.cwd()}`) {
console.log('pw', this.password)
const cipher = crypto.createCipher('AES-256-CFB8', this.password);
let crypted = cipher.update(this.wallet.getPrivateKey(), 'utf8', 'hex')
crypted += cipher.final('hex');
if (!fs.existsSync(`${dir}/wallets`)) { fs.mkdirSync(`${dir}/wallets`); }
let fPath = `${dir}/wallets/${new Date().getTime()}_${crypto.randomBytes(8).toString('hex')}`;
fs.open(fPath, 'a+', (err, f) => {
fs.writeFileSync(fPath, crypted);
})
}

// rehydrate(fPath, )



// Get the address of this wallet
getAddress() {
return '0x' + this.wallet.getAddress().toString('hex');
Expand Down

0 comments on commit 4cf87a7

Please sign in to comment.