forked from bitpay/bitcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwallet-create
executable file
·51 lines (44 loc) · 1.33 KB
/
wallet-create
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/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) {
let {key, cred} = utils.create(client, { coin, network, account: 0, n: mn[1] });
client.createWallet(walletName, copayerName, mn[0], mn[1], {
network: network,
coin: coin,
}, function(err, secret) {
utils.die(err);
console.log(' * ' + _.capitalize(network) + ' Wallet Created.');
utils.saveClient(program, key, cred, {
doNotOverwrite: true
}, function() {
if (secret) {
console.log(' - Secret to share:\n\t' + secret);
}
});
});
});