Skip to content

Commit 1435673

Browse files
committed
Merge branch 'bitcoreCli' of github.com:kajoseph/bitcore
2 parents 210ce79 + ed92507 commit 1435673

20 files changed

Lines changed: 679 additions & 530 deletions

packages/bitcore-cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
}
2727
],
2828
"bin": {
29-
"wallet": "./bin/wallet"
29+
"bitcore-cli": "./bin/wallet"
3030
},
3131
"scripts": {
3232
"test": "npm run compile && node copyTestWallets && mocha --exit 'build/test/**/*.js'",

packages/bitcore-cli/src/commands/create/createMultiSig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function createMultiSigWallet(
2323

2424
const copayerName = await getCopayerName();
2525
const addressType = await getAddressType({ chain, network, isMultiSig: true });
26-
const password = await getPassword('Enter a password for the wallet:', { hidden: false });
26+
const password = await getPassword('Lock your wallet with a password:', { hidden: false });
2727

2828
const { key, secret } = await wallet.create({ chain, network, account: 0, n, m, password, mnemonic, addressType, copayerName });
2929

packages/bitcore-cli/src/commands/create/createSingleSig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export async function createSingleSigWallet(
1414
const { verbose, mnemonic } = opts;
1515

1616
const addressType = await getAddressType({ chain, network });
17-
const password = await getPassword('Enter a password for the wallet:', { hidden: false });
17+
const password = await getPassword('Lock your wallet with a password:', { hidden: false });
1818
const copayerName = process.env.USER || 'copayer';
1919

2020
const { key } = await wallet.create({

packages/bitcore-cli/src/commands/create/createThresholdSig.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import url from 'url';
44
import { Key, type Network, TssKey } from '@bitpay-labs/bitcore-wallet-client';
55
import * as prompt from '@clack/prompts';
66
import { UserCancelled } from '../../errors';
7-
import { getAddressType, getCopayerName, getPassword } from '../../prompts';
7+
import { getAddressType, getCopayerName, getPassword, promptKeyshareBackup } from '../../prompts';
88
import { Utils } from '../../utils';
9+
import { exportWallet } from '../export';
910
import type { CommonArgs } from '../../../types/cli';
1011

1112

@@ -26,7 +27,7 @@ export async function createThresholdSigWallet(
2627

2728
const copayerName = await getCopayerName();
2829
const addressType = await getAddressType({ chain, network, isMultiSig: false, isTss: true });
29-
const password = await getPassword('Enter a password for the wallet:', { hidden: false });
30+
const password = await getPassword('Lock your wallet with a password:', { hidden: false });
3031

3132
let key;
3233
if (mnemonic) {
@@ -46,6 +47,16 @@ export async function createThresholdSigWallet(
4647
const tssPassword = crypto.randomBytes(20).toString('hex');
4748
await tss.newKey({ m, n, password: tssPassword });
4849

50+
prompt.note(
51+
'Next, you will be asked to enter party 1\'s public key. Once you enter it, ' +
52+
'a personal join code will be generated for you to give to them.' + os.EOL +
53+
'To get their public key, party 1 should go ahead and start the join process ' +
54+
'for their wallet by running bitcore-cli and selecting `Join Wallet`. Then they follow the ' +
55+
'prompts until it tells them to share the public key with the session leader (you).' + os.EOL + os.EOL +
56+
'Repeat this process for the other party members. Once all members have joined, the TSS ' +
57+
'wallet creation process will finish.'
58+
);
59+
4960
for (let i = 1; i < n; i++) {
5061
const pubkey = await prompt.text({
5162
message: `Enter party ${i}'s public key:`,
@@ -133,7 +144,15 @@ export async function createThresholdSigWallet(
133144
});
134145
});
135146

147+
148+
// Keyshare backup
149+
const ok = await promptKeyshareBackup();
150+
if (ok) {
151+
await exportWallet({ wallet, opts: { ...opts, readonly: false } });
152+
}
153+
136154
return {
137-
mnemonic: key.get(password).mnemonic
155+
// TSS wallets cannot be restored from a mnemonic alone, so we return null here. All the wallet recovery information is in the keyshare backup file.
156+
mnemonic: null
138157
};
139158
}

packages/bitcore-cli/src/commands/create/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,17 @@ export async function createWallet(args: CommonArgs<{ mnemonic?: string }>) {
3030
const [m, n] = Utils.parseMN(mOfN);
3131

3232
if (useTss) {
33-
({ mnemonic } = await createThresholdSigWallet({ wallet, chain, network, opts, m, n }));
33+
await createThresholdSigWallet({ wallet, chain, network, opts, m, n });
3434
} else {
3535
({ mnemonic } = await createMultiSigWallet({ wallet, chain, network, opts, m, n }));
3636
}
3737
}
3838

3939
// Re-fetch the client to ensure it has the latest state
4040
// and to complete the wallet creation process
41-
4241
await wallet.getClient({});
4342

44-
if (!opts.mnemonic) {
43+
if (!opts.mnemonic && mnemonic) {
4544
await Utils.showMnemonic(wallet.name, mnemonic, opts);
4645
}
4746
};

packages/bitcore-cli/src/commands/export.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ export async function exportWallet(args: CommonArgs<{ filename?: string; readonl
3030
}
3131
const replaceTilde = str => str.startsWith('~') ? str.replace('~', os.homedir()) : str;
3232

33-
const readOnly = !!opts.readonly || wallet.isReadOnly() || await prompt.confirm({
33+
const readOnly = opts.readonly ?? (wallet.isReadOnly() || await prompt.confirm({
3434
message: 'Export as read-only (cannot send funds)?',
3535
initialValue: false
36-
});
36+
}));
3737
if (prompt.isCancel(readOnly)) {
3838
throw new UserCancelled();
3939
}
@@ -66,7 +66,7 @@ export async function exportWallet(args: CommonArgs<{ filename?: string; readonl
6666
throw new UserCancelled();
6767
}
6868

69-
const exportPassword = await getPassword('Import/export password:', { hidden: false, minLength: 6 });
69+
const exportPassword = await getPassword('File encryption password:', { hidden: false, minLength: 6 });
7070

7171
await wallet.export({
7272
filename: replaceTilde(filename),

packages/bitcore-cli/src/commands/import.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export async function importWallet(args: CommonArgs) {
2626
throw new UserCancelled();
2727
}
2828

29-
const importPassword = await getPassword('Import/export password:', { hidden: true });
29+
const importPassword = await getPassword('File decryption password:', { hidden: true });
3030

3131
await wallet.import({
3232
filename: replaceTilde(filename),

packages/bitcore-cli/src/commands/join/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ export async function joinWallet(args: CommonArgs<{ mnemonic?: string }>) {
3939

4040
let mnemonic;
4141
if (useTss) {
42-
({ mnemonic } = await joinThresholdSigWallet(Object.assign({}, args, { chain })));
42+
await joinThresholdSigWallet(Object.assign({}, args, { chain }));
4343
} else {
4444
({ mnemonic } = await joinMultiSigWallet(args));
4545
}
4646

47-
if (!opts.mnemonic) {
47+
if (!opts.mnemonic && mnemonic) {
4848
await Utils.showMnemonic(wallet.name, mnemonic, opts);
4949
}
5050
};

packages/bitcore-cli/src/commands/join/joinMultiSig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export async function joinMultiSigWallet(args: CommonArgs<{ mnemonic?: string }>
2424
} = parsed;
2525

2626
const copayerName = await getCopayerName();
27-
const password = await getPassword('Enter a password for the wallet:', { hidden: false });
27+
const password = await getPassword('Lock your wallet with a password:', { hidden: false });
2828
const { key, joinedWalletName } = await wallet.create({ chain, network, account: 0, n: 2, m: 1, password, mnemonic, copayerName, joinSecret }); // n gets overwritten
2929

3030
prompt.log.success(Utils.colorText(`Wallet joined: ${joinedWalletName}`, 'green'));

packages/bitcore-cli/src/commands/join/joinThresholdSig.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import url from 'url';
33
import { Key, TssKey } from '@bitpay-labs/bitcore-wallet-client';
44
import * as prompt from '@clack/prompts';
55
import { UserCancelled } from '../../errors';
6-
import { getCopayerName, getNetwork, getPassword } from '../../prompts';
6+
import { getCopayerName, getNetwork, getPassword, promptKeyshareBackup } from '../../prompts';
77
import { Utils } from '../../utils';
8+
import { exportWallet } from '../export';
89
import type { CommonArgs } from '../../../types/cli';
910

1011
export async function joinThresholdSigWallet(
@@ -15,7 +16,7 @@ export async function joinThresholdSigWallet(
1516

1617
const network = await getNetwork();
1718
const copayerName = await getCopayerName();
18-
const password = await getPassword('Enter a password for the wallet:', { hidden: false });
19+
const password = await getPassword('Lock your wallet with a password:', { hidden: false });
1920

2021
let key;
2122
if (mnemonic) {
@@ -114,7 +115,15 @@ export async function joinThresholdSigWallet(
114115
});
115116
});
116117

118+
119+
// Keyshare backup
120+
const ok = await promptKeyshareBackup();
121+
if (ok) {
122+
await exportWallet({ wallet, opts: { ...opts, readonly: false } });
123+
}
124+
117125
return {
118-
mnemonic: key.get(password).mnemonic
126+
// TSS wallets cannot be restored from a mnemonic alone, so we return null here. All the wallet recovery information is in the keyshare backup file.
127+
mnemonic: null
119128
};
120129
}

0 commit comments

Comments
 (0)