bitcore-wallet/bin/wallet-create

55 lines
1.4 KiB
JavaScript
Executable File

#!/usr/bin/env node
var _ = require('lodash');
var program = require('commander');
var utils = require('./cli-utils');
program = utils.configureCommander(program);
program
.option('-t, --testnet', 'Create a Testnet Wallet')
.option('-p, --password', 'Encrypt wallet. Will ask password interactively')
.option('-c, --coin <coin>', 'coin (btc/bch)')
.usage('[options] <walletName> <m-n> [copayerName] <passphrase>')
.parse(process.argv);
var args = program.args;
if (!args[0])
program.help();
var walletName = args[0];
var copayerName = args[2] || process.env.USER;
var passphrase = args[3];
var network = program.testnet ? 'testnet' : 'livenet';
var coin = program.coin ? program.coin : 'btc';
var mn;
try {
mn = utils.parseMN(args[1]);
} catch (ex) {
utils.die(ex);
}
utils.getClient(program, {
doNotComplete: true
}, function(client) {
client.seedFromRandomWithMnemonic({
network: network,
passphrase: passphrase,
language: 'en',
coin: coin,
});
client.createWallet(walletName, copayerName, mn[0], mn[1], {
network: network
}, function(err, secret) {
utils.die(err);
console.log(' * ' + _.capitalize(network) + ' Wallet Created.');
utils.saveClient(program, client, {
doNotOverwrite: true
}, function() {
if (secret) {
console.log(' - Secret to share:\n\t' + secret);
}
});
});
});