Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 1 addition & 112 deletions packages/bitcore-cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions packages/bitcore-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
"@bitpay-labs/crypto-wallet-core": "^11.10.3",
"@clack/prompts": "1.5.1",
"commander": "14.0.0",
"external-editor": "3.1.0",
"usb": "2.15.0"
"external-editor": "3.1.0"
},
"devDependencies": {
"@bitpay-labs/bitcore-wallet-service": "^11.10.3",
Expand Down
3 changes: 1 addition & 2 deletions packages/bitcore-cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const { version } = JSON.parse(fs.readFileSync(path.join(__dirname, '../../packa

program
.addHelpText('beforeAll', bitcoreLogo)
.usage('<walletName> [options]')
.usage('<walletName>|list [options]')
.description('A command line tool for Bitcore wallets')
.argument('<walletName>', 'Name of the wallet you want to create, join, or interact with. Use "list" to see all wallets in the specified directory.')
.optionsGroup('Global Options')
Expand All @@ -31,7 +31,6 @@ program
.option('--no-status', 'Do not display the wallet status on startup. Defaults to true when running with --command')
.option('-s, --pageSize <number>', 'Number of items per page of a list output', (value) => parseInt(value, 10), 10)
.option('-v, --verbose', 'Show more data and logs')
.option('--list', 'See all wallets in the specified directory')
.option('--register', 'Register the wallet with the Bitcore Wallet Service if it does not exist')
.option('--walletId <walletId>', 'Support Staff Only: Wallet ID to provide support for')
.option('-h, --help', 'Display help message. Use with --command to get help for a specific command')
Expand Down
63 changes: 41 additions & 22 deletions packages/bitcore-cli/src/commands/create/createThresholdSig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,47 @@ export async function createThresholdSigWallet(
extra: tssPassword
});

const goBack = await prompt.select({
message: `Join code for party ${i}:${os.EOL}${joinCode}`,
initialValue: false,
options: [
{
label: 'Continue →',
value: false
},
{
label: '↩ Go Back',
value: true,
hint: `Re-enter party ${i}'s public key`
}
]
});
if (prompt.isCancel(goBack)) {
throw new UserCancelled();
}
let joinCodeAction: 'copy' | 'continue' | 'goBack' | symbol;
do {
joinCodeAction = await prompt.select({
message: joinCodeAction === 'copy' ? 'Copied!' : `Join code for party ${i}:${os.EOL}${joinCode}`,
initialValue: joinCodeAction === 'copy' ? 'continue' : 'copy',
options: [
{
label: 'Continue →',
value: 'continue'
},
{
label: 'Copy to clipboard ⎘',
value: 'copy'
},
{
label: '↩ Go Back',
value: 'goBack',
hint: `Re-enter party ${i}'s public key`
}
]
});
if (prompt.isCancel(joinCodeAction)) {
throw new UserCancelled();
}

if (goBack) {
i--; // Retry this party
}
switch (joinCodeAction) {
case 'goBack':
i--; // Retry this party
break;
case 'copy':
try {
Utils.copyToClipboard(joinCode);
} catch (error) {
prompt.log.error(`Error copying to clipboard: ${error instanceof Error ? error.message : String(error)}`);
joinCodeAction = null; // Reset to re-prompt the user
}
break;
case 'continue':
break;
}
} while (joinCodeAction !== 'continue');
}

const spinner = prompt.spinner({ indicator: 'timer' });
Expand All @@ -112,7 +131,7 @@ export async function createThresholdSigWallet(
createWalletOpts: Utils.getSegwitInfo(addressType)
});
tss.on('roundsubmitted', (round) => spinner.message(`Round ${round} submitted`));
tss.on('error', prompt.log.error);
tss.on('error', e => prompt.log.error('Unexpected error during TSS wallet creation: ' + (e.stack || e)));
tss.on('wallet', async (_wallet) => {
// TODO: what to do with the wallet?
// console.log('Created wallet at BWS:', wallet);
Expand Down
31 changes: 23 additions & 8 deletions packages/bitcore-cli/src/commands/join/joinThresholdSig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,28 @@ export async function joinThresholdSigWallet(
});

const authPubKey = tss.getAuthPublicKey();
const done = await prompt.select({
message: `Give the following public key to the session leader:${os.EOL}${Utils.colorText(authPubKey, 'blue')}`,
options: [{ label: 'Done', value: true, hint: 'Hit Enter/Return to continue' }]
});
if (prompt.isCancel(done)) {
throw new UserCancelled();
}
let pubKeyAction: 'copy' | 'done' | symbol;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth cleaning up the TS errors for using pubKeyAction before it's defined. Give it an initial value and add it to the type declaration?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing any such typescript errors. Maybe your editor's TS version is 6.x instead of the workspace's 5.x?

do {
pubKeyAction = await prompt.select({
message: pubKeyAction === 'copy' ? 'Copied!' : `Give the following public key to the session leader:${os.EOL}${Utils.colorText(authPubKey, 'blue')}`,
initialValue: pubKeyAction === 'copy' ? 'done' : 'copy',
options: [
{ label: 'Done', value: 'done', hint: 'Hit Enter/Return to continue' },
{ label: 'Copy to clipboard ⎘', value: 'copy' }
]
});
if (prompt.isCancel(pubKeyAction)) {
throw new UserCancelled();
}
if (pubKeyAction === 'copy') {
try {
Utils.copyToClipboard(authPubKey);
} catch (error) {
prompt.log.error(`Error copying to clipboard: ${error instanceof Error ? error.message : String(error)}`);
pubKeyAction = null; // Reset to re-prompt the user
}
}
} while (pubKeyAction !== 'done');

const joinCode = await prompt.text({
message: 'Enter the join code from the session leader:',
Expand Down Expand Up @@ -84,7 +99,7 @@ export async function joinThresholdSigWallet(
});
tss.subscribe({ copayerName });
tss.on('roundsubmitted', (round) => spinner.message(`Round ${round} submitted`));
tss.on('error', prompt.log.error);
tss.on('error', e => prompt.log.error('Unexpected error during TSS wallet creation: ' + (e.stack || e)));
tss.on('wallet', async (_wallet) => {
// TOOD: what to do with this?
// console.log('Joined wallet at BWS:', wallet);
Expand Down
10 changes: 5 additions & 5 deletions packages/bitcore-cli/src/commands/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export async function createTransaction(
return; // valid value, optional
}
const val = parseInt(value);
if (isNaN(val) || val < 0) {
if (isNaN(val) || val < 0 || !(/^\d+$/.test(value))) {
return 'Please enter a valid destination tag';
}
return; // valid value
Expand Down Expand Up @@ -256,7 +256,7 @@ export async function createTransaction(
throw new UserCancelled();
}
if (BWCUtils.isUtxoChain(chain)) {
customFeeRate = (Number(customFeeRate) * 1000).toString(); // convert to sats/KB
customFeeRate = Math.round(Number(customFeeRate) * 1000).toString(); // convert to sats/KB
}
}

Expand All @@ -267,8 +267,8 @@ export async function createTransaction(
}],
message: note,
feeLevel: feeLevel === 'custom' ? undefined : feeLevel,
feePerKb: feeLevel === 'custom' ? parseFloat(customFeeRate) : undefined,
fee: opts.fee ? parseFloat(opts.fee) : undefined,
feePerKb: feeLevel === 'custom' ? BigInt(Math.ceil(Number(customFeeRate))) : undefined,
fee: opts.fee ? BigInt(Math.ceil(parseFloat(opts.fee))) : undefined,
sendMax,
tokenAddress: tokenObj?.contractAddress,
flags: opts.flags,
Expand All @@ -294,7 +294,7 @@ export async function createTransaction(
: Utils.renderAmount(currency, BigInt(txp.amount) + BigInt(txp.fee))
}`);
if (txp.nonce != null) {
lines.push(`Nonce: ${txp.nonce}`);
lines.push(`Nonce: ${BigInt(txp.nonce)}`);
}
if (note) {
lines.push(`Note: ${txp.message}`);
Expand Down
Loading