Skip to content
Open
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
3 changes: 2 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export default defineConfig([
ecmaVersion: 2020,
globals: {
...globals.node,
'NodeJS': 'readonly'
'NodeJS': 'readonly',
'BufferEncoding': 'readonly',
}
}
},
Expand Down
5 changes: 3 additions & 2 deletions packages/bitcore-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
"postcompile": "node createBin -v",
"clean": "rm -rf ./build",
"lint": "eslint .",
"fix": "eslint --fix --quiet .",
"precommit": "echo 'TODO: npm run lint; npm run fix'"
"fix:errors": "eslint --fix --quiet .",
"fix:all": "eslint --fix .",
"precommit": "npm run lint; npm run fix:errors"
},
"dependencies": {
"@clack/prompts": "1.0.0-alpha.3",
Expand Down
414 changes: 206 additions & 208 deletions packages/bitcore-cli/src/cli.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/bitcore-cli/src/commands/addresses.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as prompt from '@clack/prompts';
import os from 'os';
import type { CommonArgs } from '../../types/cli';
import os from 'os';
import { Utils } from '../utils';

export function command(args: CommonArgs) {
Expand All @@ -26,7 +26,7 @@ export async function getAddresses(args: CommonArgs<{ pageSize?: number; page?:
}
const { pageSize } = opts;

await Utils.paginate(async (page, viewAction) => {
await Utils.paginate(async (page, _viewAction) => {
const addresses = await wallet.client.getMainAddresses({
// doNotVerify: true,
limit: pageSize,
Expand Down
2 changes: 1 addition & 1 deletion packages/bitcore-cli/src/commands/balance.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as prompt from '@clack/prompts';
import os from 'os';
import type { CommonArgs } from '../../types/cli';
import type { ITokenObj } from '../../types/wallet';
import os from 'os';
import { Utils } from '../utils';

export function command(args: CommonArgs) {
Expand Down
6 changes: 3 additions & 3 deletions packages/bitcore-cli/src/commands/create/createMultiSig.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as prompt from '@clack/prompts';
import { getAddressType, getCopayerName, getPassword } from '../../prompts';
import type { CommonArgs } from '../../../types/cli';
import { type Network } from 'bitcore-wallet-client';
import os from 'os';
import type { CommonArgs } from '../../../types/cli';
import { getAddressType, getCopayerName, getPassword } from '../../prompts';
import { Utils } from '../../utils';

export async function createMultiSigWallet(
Expand Down Expand Up @@ -32,5 +32,5 @@ export async function createMultiSigWallet(

return {
mnemonic: key.get(password).mnemonic,
}
};
}
6 changes: 3 additions & 3 deletions packages/bitcore-cli/src/commands/create/createSingleSig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as prompt from '@clack/prompts';
import { type Network } from 'bitcore-wallet-client';
import type { CommonArgs } from '../../../types/cli';
import { getAddressType, getPassword } from '../../prompts';
import type { CommonArgs } from '../../../types/cli';
import { type Network } from 'bitcore-wallet-client';
import { Utils } from '../../utils';

export async function createSingleSigWallet(
Expand Down Expand Up @@ -34,5 +34,5 @@ export async function createSingleSigWallet(

return {
mnemonic: key.get(password).mnemonic,
}
};
}
10 changes: 5 additions & 5 deletions packages/bitcore-cli/src/commands/create/createThresholdSig.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as prompt from '@clack/prompts';
import { Key, TssKey, type Network } from 'bitcore-wallet-client'
import { getAddressType, getCopayerName, getPassword } from '../../prompts';
import { Key, type Network, TssKey } from 'bitcore-wallet-client';
import type { CommonArgs } from '../../../types/cli';
import crypto from 'crypto';
import os from 'os';
import url from 'url';
import type { CommonArgs } from '../../../types/cli';
import { UserCancelled } from '../../errors';
import { getAddressType, getCopayerName, getPassword } from '../../prompts';
import { Utils } from '../../utils';


Expand Down Expand Up @@ -45,7 +45,7 @@ export async function createThresholdSigWallet(
for (let i = 1; i < n; i++) {
const pubkey = await prompt.text({
message: `Enter party ${i}'s public key:`,
validate: (input) => !!input ? undefined : 'Public key cannot be empty.',
validate: (input) => input ? undefined : 'Public key cannot be empty.',
});
if (prompt.isCancel(pubkey)) {
throw new UserCancelled();
Expand Down Expand Up @@ -98,7 +98,7 @@ export async function createThresholdSigWallet(
});
tss.on('roundsubmitted', (round) => spinner.message(`Round ${round} submitted`));
tss.on('error', prompt.log.error);
tss.on('wallet', async (wallet) => {
tss.on('wallet', async (_wallet) => {
// TODO: what to do with the wallet?
// console.log('Created wallet at BWS:', wallet);
});
Expand Down
8 changes: 4 additions & 4 deletions packages/bitcore-cli/src/commands/create/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Constants } from 'crypto-wallet-core';
import type { CommonArgs } from '../../../types/cli';
import { getChain, getIsMultiParty, getMofN, getMultiPartyScheme, getNetwork } from '../../prompts';
import { Utils } from '../../utils';
import type { CommonArgs } from '../../../types/cli';
import { Constants } from 'crypto-wallet-core';
import { createMultiSigWallet } from './createMultiSig';
import { createSingleSigWallet } from './createSingleSig';
import { createThresholdSigWallet } from './createThresholdSig';
import { Utils } from '../../utils';

export async function createWallet(args: CommonArgs<{ mnemonic?: string }>) {
const { wallet, opts } = args;
Expand All @@ -31,7 +31,7 @@ export async function createWallet(args: CommonArgs<{ mnemonic?: string }>) {
if (useTss) {
({ mnemonic } = await createThresholdSigWallet({ wallet, chain, network, opts, m, n }));
} else {
({ mnemonic} = await createMultiSigWallet({ wallet, chain, network, opts, m, n }));
({ mnemonic } = await createMultiSigWallet({ wallet, chain, network, opts, m, n }));
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/bitcore-cli/src/commands/derive.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as prompt from '@clack/prompts';
import type { CommonArgs } from '../../types/cli';
import { Deriver } from 'crypto-wallet-core';
import { getAction } from '../prompts';
import os from 'os';
import type { CommonArgs } from '../../types/cli';
import { UserCancelled } from '../errors';
import { getAction } from '../prompts';

export function command(args: CommonArgs) {
const { program } = args;
Expand Down
4 changes: 2 additions & 2 deletions packages/bitcore-cli/src/commands/export.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as prompt from '@clack/prompts';
import type { CommonArgs } from '../../types/cli';
import fs from 'fs';
import { getPassword } from '../prompts';
import os from 'os';
import path from 'path';
import type { CommonArgs } from '../../types/cli';
import { UserCancelled } from '../errors';
import { getPassword } from '../prompts';

export function command(args: CommonArgs) {
const { wallet, program } = args;
Expand Down
6 changes: 3 additions & 3 deletions packages/bitcore-cli/src/commands/import.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as prompt from '@clack/prompts';
import type { CommonArgs } from '../../types/cli';
import fs from 'fs';
import { getPassword } from '../prompts';
import os from 'os';
import type { CommonArgs } from '../../types/cli';
import { UserCancelled } from '../errors';
import { getPassword } from '../prompts';

export async function importWallet(args: CommonArgs) {
const { wallet, opts } = args;
const { wallet } = args;
const replaceTilde = str => str.startsWith('~') ? str.replace('~', os.homedir()) : str;

const filename = await prompt.text({
Expand Down
4 changes: 2 additions & 2 deletions packages/bitcore-cli/src/commands/join/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as prompt from '@clack/prompts';
import { Constants } from 'crypto-wallet-core';
import type { CommonArgs } from '../../../types/cli';
import { Constants } from 'crypto-wallet-core';
import { getChain } from '../../prompts';
import { Utils } from '../../utils';
import { joinMultiSigWallet } from './joinMultiSig';
import { joinThresholdSigWallet } from './joinThresholdSig';
import { Utils } from '../../utils';


export async function joinWallet(args: CommonArgs<{ mnemonic?: string; }>) {
Expand Down
8 changes: 4 additions & 4 deletions packages/bitcore-cli/src/commands/join/joinMultiSig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as prompt from '@clack/prompts';
import { getCopayerName, getPassword } from '../../prompts';
import BWC from 'bitcore-wallet-client';
import type { CommonArgs } from '../../../types/cli';
import { getCopayerName, getPassword } from '../../prompts';
import { Utils } from '../../utils';

export async function joinMultiSigWallet(args: CommonArgs<{ mnemonic?: string; }>) {
Expand All @@ -10,7 +10,7 @@ export async function joinMultiSigWallet(args: CommonArgs<{ mnemonic?: string; }

const secret = (await prompt.text({
message: 'Enter the secret to join the wallet:',
validate: (input) => !!input?.trim() ? null : 'Secret cannot be empty.',
validate: (input) => input?.trim() ? null : 'Secret cannot be empty.',
})).toString().trim();

const parsed = BWC.parseSecret(secret);
Expand All @@ -21,7 +21,7 @@ export async function joinMultiSigWallet(args: CommonArgs<{ mnemonic?: string; }

const copayerName = await getCopayerName();
const password = await getPassword('Enter a password for the wallet:', { hidden: false });
const { key, creds } = await wallet.create({ chain, network, account: 0, n: 2, password, mnemonic, copayerName }); // n gets overwritten
const { key } = await wallet.create({ chain, network, account: 0, n: 2, password, mnemonic, copayerName }); // n gets overwritten
const joinedWallet = await wallet.client.joinWallet(secret, copayerName, { chain });
await wallet.load(); // Is this needed after joining?

Expand All @@ -30,5 +30,5 @@ export async function joinMultiSigWallet(args: CommonArgs<{ mnemonic?: string; }

return {
mnemonic: key.get(password).mnemonic,
}
};
};
12 changes: 6 additions & 6 deletions packages/bitcore-cli/src/commands/join/joinThresholdSig.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as prompt from '@clack/prompts';
import { Key, TssKey } from 'bitcore-wallet-client'
import { getCopayerName, getNetwork, getPassword } from '../../prompts';
import { Key, TssKey } from 'bitcore-wallet-client';
import type { CommonArgs } from '../../../types/cli';
import os from 'os';
import url from 'url';
import type { CommonArgs } from '../../../types/cli';
import { UserCancelled } from '../../errors';
import { getCopayerName, getNetwork, getPassword } from '../../prompts';
import { Utils } from '../../utils';

export async function joinThresholdSigWallet(
args: CommonArgs<{ mnemonic?: string; }> & { chain: string; }
args: CommonArgs<{ mnemonic?: string; }> & { chain: string; }
) {
const { wallet, chain, opts } = args;
const { verbose, mnemonic } = opts;
Expand Down Expand Up @@ -84,7 +84,7 @@ args: CommonArgs<{ mnemonic?: string; }> & { chain: string; }
tss.subscribe({ copayerName });
tss.on('roundsubmitted', (round) => spinner.message(`Round ${round} submitted`));
tss.on('error', prompt.log.error);
tss.on('wallet', async (wallet) => {
tss.on('wallet', async (_wallet) => {
// TOOD: what to do with this?
// console.log('Joined wallet at BWS:', wallet);
});
Expand All @@ -111,7 +111,7 @@ args: CommonArgs<{ mnemonic?: string; }> & { chain: string; }
} catch (err) {
reject(err);
}
})
});
});

return {
Expand Down
2 changes: 1 addition & 1 deletion packages/bitcore-cli/src/commands/preferences.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as prompt from '@clack/prompts';
import os from 'os';
import type { CommonArgs } from '../../types/cli';
import os from 'os';

export function command(args: CommonArgs) {
const { program } = args;
Expand Down
6 changes: 3 additions & 3 deletions packages/bitcore-cli/src/commands/sign.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import prompt from '@clack/prompts';
import { Deriver, type Types as CWCTypes, Validation } from 'crypto-wallet-core';
import os from 'os';
import { type Types as CWCTypes, Deriver, Validation } from 'crypto-wallet-core';
import { type CommonArgs } from '../../types/cli';
import os from 'os';
import prompt from '@clack/prompts';
import { UserCancelled } from '../errors';
import { Utils } from '../utils';

Expand Down
6 changes: 3 additions & 3 deletions packages/bitcore-cli/src/commands/status.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as prompt from '@clack/prompts';
import { Status } from 'bitcore-wallet-client';
import os from 'os';
import type { CommonArgs } from '../../types/cli';
import { displayBalance } from './balance';
import type { ITokenObj } from '../../types/wallet';
import os from 'os';
import { Status } from 'bitcore-wallet-client';
import { Utils } from '../utils';
import { displayBalance } from './balance';

export async function command(args: CommonArgs) {
const { program } = args;
Expand Down
2 changes: 1 addition & 1 deletion packages/bitcore-cli/src/commands/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Wallet } from '../wallet';


export async function setToken(args: CommonArgs) {
const { wallet, opts } = args;
const { wallet } = args;

const currencies = await Wallet.getCurrencies(wallet.network);
function findTokenObj(value) {
Expand Down
8 changes: 4 additions & 4 deletions packages/bitcore-cli/src/commands/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as prompt from '@clack/prompts';
import { type Txp } from 'bitcore-wallet-client';
import { Validation } from 'crypto-wallet-core';
import os from 'os';
import type { CommonArgs } from '../../types/cli';
import type { ITokenObj } from '../../types/wallet';
import os from 'os';
import { type Txp } from 'bitcore-wallet-client';
import { UserCancelled } from '../errors';
import { Utils } from '../utils';
import { Validation } from 'crypto-wallet-core';

export function command(args: CommonArgs) {
const { wallet, program } = args;
const { program } = args;
program
.description('Create and send a transaction')
.usage('<walletName> --command transaction [options]')
Expand Down
12 changes: 6 additions & 6 deletions packages/bitcore-cli/src/commands/txhistory.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as prompt from '@clack/prompts';
import fs from 'fs';
import os from 'os';
import type { CommonArgs } from '../../types/cli';
import type { ITokenObj } from '../../types/wallet';
import fs from 'fs';
import { getFileName } from '../prompts';
import type { ITokenObj } from '../../types/wallet';
import os from 'os';
import { Utils } from '../utils';

export function command(args: CommonArgs) {
Expand Down Expand Up @@ -90,9 +90,9 @@ export async function getTxHistory(
const outputFile = opts.command
? Utils.replaceTilde(typeof opts.export === 'string' ? opts.export : defaultValue)
: await getFileName({
message: 'Enter output file path to save proposal:',
defaultValue,
});
message: 'Enter output file path to save proposal:',
defaultValue,
});

await fs.promises.writeFile(outputFile, JSON.stringify(history, null, 2));
prompt.log.info(`Page ${page} exported to: ${outputFile}`);
Expand Down
18 changes: 9 additions & 9 deletions packages/bitcore-cli/src/commands/txproposals.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as prompt from '@clack/prompts';
import { getAction, getFileName } from '../prompts';
import type { CommonArgs } from '../../types/cli';
import fs from 'fs';
import os from 'os';
import type { CommonArgs } from '../../types/cli';
import { UserCancelled } from '../errors';
import { getAction, getFileName } from '../prompts';
import { Utils } from '../utils';

export function command(args: CommonArgs) {
Expand Down Expand Up @@ -141,9 +141,9 @@ export async function getTxProposals(
action = opts.command
? opts.action || (opts.export ? 'export' : 'exit')
: await getAction({
options,
initialValue
});
options,
initialValue
});
if (prompt.isCancel(action)) {
throw new UserCancelled();
}
Expand Down Expand Up @@ -208,9 +208,9 @@ export async function getTxProposals(
const outputFile = opts.command
? Utils.replaceTilde(typeof opts.export === 'string' ? opts.export : defaultValue)
: await getFileName({
message: 'Enter output file path to save proposal:',
defaultValue,
});
message: 'Enter output file path to save proposal:',
defaultValue,
});
fs.writeFileSync(outputFile, JSON.stringify(txp, null, 2));
prompt.log.success(`Exported to ${outputFile}`);
break;
Expand All @@ -225,7 +225,7 @@ export async function getTxProposals(
action = 'exit'; // Exit after processing the action in command mode
}
// TODO: handle actions
} while (!['menu', 'exit'].includes(action))
} while (!['menu', 'exit'].includes(action));

return { action };
};
Loading