Skip to content

Commit

Permalink
Add clipboard functionality and copy option
Browse files Browse the repository at this point in the history
  • Loading branch information
yerofey committed Feb 4, 2024
1 parent 1b742d7 commit 9f2e59c
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ $ cw -l
## Options

- `-b` or `-c` or `--chain`: Specify the blockchain ticker to generate a wallet for
- `-C` or `--copy`: Copy the generated mnemonic to the clipboard
- `-D` or `--csv`: Save output into CSV file with custom or default name ("`cw-output.csv`") - this is a shorthand for `-o csv -F filename`
- `-f` or `--format`: Specify the blockchain wallet format (for BTC: legacy, segwit, bech32)
- `-g` or `--geek`: Display some additional "geeky" info
Expand Down
4 changes: 2 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Method from './src/Method.js';
options.mnemonic === '' ||
options.mnemonic.split(' ').length === 1)
) {
return new Method('mnemonic').init({ mnemonic: options.mnemonic });
return new Method('mnemonic').init({ mnemonic: options.mnemonic, copy: options?.copy || false });
}

if (options.version) {
Expand All @@ -29,7 +29,7 @@ import Method from './src/Method.js';
return new Method('donate').init();
}

const chain = options.chain.toUpperCase() || 'ETH';
const chain = options.chain.toUpperCase() || 'ERC';
if (supportedChains.includes(chain)) {
return new Method('wallet', {
chain,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yerofey/cryptowallet-cli",
"version": "1.20.0",
"version": "1.21.0",
"description": "Crypto wallet generator CLI tool",
"type": "module",
"homepage": "https://github.com/yerofey/cryptowallet-cli",
Expand Down Expand Up @@ -114,6 +114,7 @@
"bs58": "^5.0.0",
"buffer": "^6.0.3",
"chalk": "5.3.0",
"clipboardy": "^4.0.0",
"coininfo": "5.2.1",
"coinkey": "3.0.0",
"columnify": "1.6.0",
Expand Down
102 changes: 99 additions & 3 deletions pnpm-lock.yaml

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

28 changes: 26 additions & 2 deletions src/Method.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { config } from 'dotenv';
import path from 'node:path';
import chalk from 'chalk';
import clipboardy from 'clipboardy';
import columnify from 'columnify';
import CsvWriter from 'csv-writer';
import { log, supportedChains, loadJson } from './utils.js';
Expand Down Expand Up @@ -69,6 +70,7 @@ class Method {
const mnemonicLength = ['12', '18', '24'].includes(mnemonic)
? parseInt(mnemonic, 10)
: 12;
const mnemonicString = generateMnemonicString(mnemonicLength);

log(
`✨ ${green('Done!')} ${blueBright(
Expand All @@ -77,13 +79,26 @@ class Method {
} words mnemonic string:`
)}\n`
);
log(`📄 ${generateMnemonicString(mnemonicLength)}`);
log(`📄 ${mnemonicString}`);
// copy to clipboard if flag is set
if (this.inputOptions.copy) {
clipboardy.writeSync(mnemonicString);
log(`📋 ${green('Mnemonic copied to your clipboard!')}`);
}
log();
log(
greenBright(
'ℹ️ You can import it into your favorite wallet app or use it to generate a wallet with "-m" flag'
)
);

// donation
log();
log(
blueBright(
'🙏 Consider supporting this project - check donations options with: cw --donate'
)
);
}

_version() {
Expand Down Expand Up @@ -199,6 +214,7 @@ class Method {

if (displayAsText) {
// display addresses
let index = 0;
for (const item of cw.wallet.addresses) {
if (cw.wallet.addresses.length > 1) {
log();
Expand Down Expand Up @@ -350,6 +366,13 @@ class Method {
if (item.privateKey !== undefined) {
log(`🔑 ${item.privateKey}`);
}
// copy to clipboard if flag is set
if (cw.options.copy && cw.wallet.mnemonic !== undefined && index == 0) {
clipboardy.writeSync(cw.wallet.mnemonic);
log(`📋 ${green('Mnemonic copied to your clipboard!')}`);
}

index += 1;
}

// tested
Expand Down Expand Up @@ -418,7 +441,7 @@ class Method {
}
}

// formats, network, apps
// formats, network, apps, attempts, donation
if (displayAsText) {
if (
cw.row.formats !== undefined ||
Expand Down Expand Up @@ -468,6 +491,7 @@ class Method {
);
}

// apps
if (cw.row.apps !== undefined) {
let apps = {
metamask: 'MetaMask',
Expand Down
1 change: 1 addition & 0 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { program } from 'commander';

program.option('-b, --chain <ticker>', 'Wallet for specific blockchain', 'ERC');
program.option('-c, --chain <ticker>', 'Wallet for specific blockchain', 'ERC');
program.option('-C, --copy', 'Copy the result to the clipboard');
program.option(
'-D, --csv [filename]',
'Save result into CSV file'
Expand Down

0 comments on commit 9f2e59c

Please sign in to comment.