forked from BitGo/BitGoJS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreatewallet.js
47 lines (39 loc) · 1.71 KB
/
createwallet.js
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
//
// Create a multi-sig wallet at BitGo.
// This makes use of the convenience function createWalletWithKeychains
//
// This tool will help you see how to use the BitGo API to easily create a wallet.
// In this form, it creates 2 keys on the host which runs this example.
// It is HIGHLY RECOMMENDED that you GENERATE THE KEYS ON SEPARATE MACHINES for real money wallets!
//
// To perform more advanced features, such as encrypting keys yourself, please look at createWalletAdvanced.js
//
// Copyright 2014, BitGo, Inc. All Rights Reserved.
//
const BitGoJS = require('../src/index.js');
if (process.argv.length < 6) {
console.log('usage:\n\t' + process.argv[0] + ' ' + process.argv[1] + ' <user> <pass> <otp> <label> <backupXpub>');
process.exit(-1);
}
const user = process.argv[2];
const password = process.argv[3];
const otp = process.argv[4];
const label = process.argv[5];
let backupXpub = null;
if (process.argv.length > 6) {
backupXpub = process.argv[6];
}
const bitgo = new BitGoJS.BitGo();
// Authenticate
bitgo.authenticate({ username: user, password: password, otp: otp }, function(err, result) {
if (err) { console.dir(err); throw new Error('Could not authenticate!'); }
// Create the wallet
bitgo.wallets().createWalletWithKeychains({ passphrase: password, label: label, backupXpub: backupXpub }, function(err, result) {
if (err) { console.dir(err); throw new Error('Could not create wallet!'); }
console.log('New Wallet: ' + result.wallet.id());
console.dir(result.wallet.wallet);
console.log('BACK THIS UP: ');
console.log('User keychain encrypted xPrv: ' + result.userKeychain.encryptedXprv);
console.log('Backup keychain encrypted xPrv: ' + result.backupKeychain.encryptedXprv);
});
});