Skip to content

Commit c8d73e7

Browse files
committed
feat: Refactor TRX and TRON chain configurations, update README, and bump version to 1.38.2
1 parent f02767e commit c8d73e7

11 files changed

Lines changed: 60 additions & 99 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![Minimum Node.js version](https://badgen.net/npm/node/@yerofey/cryptowallet-cli)](https://npmjs.com/@yerofey/cryptowallet-cli)
55
[![NPM package version](https://badgen.net/npm/v/@yerofey/cryptowallet-cli)](https://npmjs.com/package/@yerofey/cryptowallet-cli)
66

7-
> Crypto wallet generator CLI tool
7+
> CW: crypto wallet generator CLI tool
88
99
![Screenshot](https://i.imgur.com/uWuT4lF.png)
1010

@@ -259,9 +259,9 @@ Each chain JSON file is structured to provide essential information about the bl
259259
- `flags`: An array of supported features for the wallet generation. Common flags include `m` for mnemonic support, `n` for generating multiple wallets, `p` for prefix support, and `s` for suffix support.
260260
- `formats`: (Optional) An object defining multiple wallet formats if the blockchain supports more than one format. Each format should specify its unique properties.
261261

262-
By following this structure, the `cryptowallet-cli` tool can understand and support wallet generation for a wide array of blockchains.
262+
By following this structure, the `cw` tool can understand and support wallet generation for a wide array of blockchains.
263263

264-
Feel free to contribute by adding support for more chains, and help in making `cryptowallet-cli` a more comprehensive tool for the crypto community!
264+
Feel free to contribute by adding support for more chains, and help in making `cw` a more comprehensive tool for the crypto community!
265265

266266
## Contributing
267267

cli.js

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
#!/usr/bin/env node
22
'use strict';
33

4-
// filter out unwanted "bigint" warning messages
5-
const originalStderrWrite = process.stderr.write;
6-
process.stderr.write = function (chunk, encoding, callback) {
7-
const msg = chunk.toString();
8-
if (msg.includes('bigint: Failed to load bindings')) return;
9-
originalStderrWrite.apply(process.stderr, arguments);
10-
};
11-
124
import os from 'node:os';
135
import {
146
Worker,
@@ -17,65 +9,67 @@ import {
179
workerData,
1810
} from 'node:worker_threads';
1911
import { fileURLToPath } from 'node:url';
20-
import chalk from 'chalk';
2112
import { options } from './src/options.js';
22-
import { log, supportedChains } from './src/utils.js';
13+
import { exit, log, supportedChains } from './src/utils.js';
2314
import Method from './src/Method.js';
15+
import chalk from 'chalk';
2416

2517
// get the current file path
2618
const __filename = fileURLToPath(import.meta.url);
2719

28-
const exit = process.exit;
29-
30-
if (options.list !== undefined) {
20+
// show all supported chains
21+
if (options.list) {
3122
(async () => {
32-
return new Method('list').init();
23+
await new Method('list').init();
24+
exit(0);
3325
})();
34-
exit(0);
3526
}
3627

37-
// generate mnemonic string if no argument is passed or only the mnemonic length is passed
28+
// generate mnemonic string
3829
if (
3930
options.mnemonic &&
4031
(options.mnemonic === true ||
4132
options.mnemonic === '' ||
4233
options.mnemonic.split(' ').length === 1)
4334
) {
4435
(async () => {
45-
return new Method('mnemonic').init({
36+
new Method('mnemonic').init({
4637
mnemonic: options.mnemonic,
4738
copy: options?.copy || false,
4839
});
40+
exit(0);
4941
})();
50-
exit(0);
5142
}
5243

44+
// show the version number
5345
if (options.version) {
5446
(async () => {
55-
return new Method('version').init();
47+
new Method('version').init();
48+
exit(0);
5649
})();
57-
exit(0);
5850
}
5951

52+
// show donation message
6053
if (options.donate) {
6154
(async () => {
62-
return new Method('donate').init();
55+
new Method('donate').init();
56+
exit(0);
6357
})();
64-
exit(0);
6558
}
6659

60+
// generate a wallet
6761
const chain = (options.chain.toUpperCase() || 'EVM').trim();
6862
if (!supportedChains.includes(chain)) {
6963
log(chalk.red('⛔️ Error: this chain is not supported!'));
70-
process.exit(1);
64+
exit(1);
7165
}
7266
options.b = chain; // ensure the chain is passed to the Method class
7367

7468
// multi-threads mode (only for suffix, prefix, number)
7569
const allMachineThreads = os.cpus().length;
7670
const availableThreads = os.cpus().length - 1; // leave 1 core for the main thread
7771
const defaultThreads = os.cpus().length / 2; // use half of the available threads
78-
const inputThreads = parseInt(options.threads || 1, 10); // default to 1 thread
72+
const inputThreads = parseInt(options.threads || defaultThreads, 10); // user input threads
7973
let numThreads = defaultThreads; // default to half of the available threads
8074
if (inputThreads > availableThreads) {
8175
numThreads = defaultThreads;
@@ -90,13 +84,15 @@ if (isMainThread) {
9084
console.log(
9185
chalk.green(
9286
'🐢 Using only 1 thread to generate a wallet, this might take a while...'
93-
)
87+
),
88+
chalk.gray(`(pass "-t ${availableThreads}" to use all available threads)`)
9489
);
9590
} else {
9691
console.log(
9792
chalk.green(
9893
`⚡ Using ${numThreads}/${allMachineThreads} threads to generate a wallet...`
99-
)
94+
),
95+
chalk.gray(`(pass "-t ${availableThreads}" to use all available threads)`)
10096
);
10197
}
10298

package-lock.json

Lines changed: 2 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@yerofey/cryptowallet-cli",
3-
"version": "1.38.1",
3+
"version": "1.38.2",
44
"description": "Crypto wallet generator CLI tool",
55
"type": "module",
66
"homepage": "https://github.com/yerofey/cryptowallet-cli",
@@ -41,7 +41,6 @@
4141
}
4242
],
4343
"bin": {
44-
"cryptowallet": "cli.js",
4544
"cw": "cli.js"
4645
},
4746
"engines": {
@@ -58,6 +57,7 @@
5857
"./src/"
5958
],
6059
"keywords": [
60+
"cw",
6161
"cli",
6262
"cli-app",
6363
"console",
@@ -133,7 +133,6 @@
133133
"ed25519-hd-key": "^1.3.0",
134134
"eth-lib": "0.1.29",
135135
"ethereum-bip84": "0.0.3",
136-
"ethereum-cryptography": "^3.0.0",
137136
"ethereum-mnemonic-privatekey-utils": "1.0.5",
138137
"qrcode-terminal": "^0.12.0",
139138
"tezos-sign": "1.4.1",

pnpm-lock.yaml

Lines changed: 0 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Method.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import clipboardy from 'clipboardy';
55
import columnify from 'columnify';
66
import CsvWriter from 'csv-writer';
77
import qr from 'qrcode-terminal';
8-
import { log, supportedChains, loadJson } from './utils.js';
9-
import { generateMnemonicString } from './Wallet.js';
108
import CW from './CW.js';
9+
import { generateMnemonicString } from './Wallet.js';
10+
import { log, supportedChains, loadJson } from './utils.js';
1111

1212
config();
13+
1314
const {
1415
blue,
1516
green,
@@ -53,7 +54,7 @@ class Method {
5354
for (const val of supportedChains) {
5455
// eslint-disable-next-line no-undef
5556
const data = await loadJson(
56-
`${path.dirname(import.meta.url)}/chains/${val}.json`.replace(
57+
`${path.dirname(import.meta.url)}${path.sep}chains${path.sep}${val}.json`.replace(
5758
'file://',
5859
''
5960
)

src/Wallet.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { config } from 'dotenv';
33
import { log } from './utils.js';
44
import chalk from 'chalk';
5-
const { red, yellow } = chalk;
5+
const { red, yellow, gray } = chalk;
66
import CoinKey from 'coinkey';
77
import CoinInfo from 'coininfo';
88
import bip39 from 'bip39';
@@ -21,7 +21,6 @@ import { Account } from 'eth-lib/lib/index.js';
2121
import { Wallet as HarmonyWallet } from '@harmony-js/account';
2222
import pkutils from 'ethereum-mnemonic-privatekey-utils';
2323
import bCrypto from '@binance-chain/javascript-sdk/lib/crypto/index.js';
24-
import { HDKey } from 'ethereum-cryptography/hdkey.js';
2524
import tronWeb from 'tronweb';
2625
import tezos from 'tezos-sign';
2726
import {
@@ -112,7 +111,9 @@ class Wallet {
112111
if (options.prefix && options.suffix) {
113112
// prefix & suffix
114113
log(
115-
`⏳ Generating wallet with "${options.prefix}" prefix and "${options.suffix}" suffix, this for sure will take a while...`
114+
gray(
115+
`⏳ Generating wallet with "${options.prefix}" prefix and "${options.suffix}" suffix, this for sure will take a while...`
116+
)
116117
);
117118
onlyBoth = true;
118119
} else {
@@ -123,7 +124,9 @@ class Wallet {
123124
RegExp(row.rareSymbols, 'g').test(options.prefix))
124125
) {
125126
log(
126-
`⏳ Generating wallet with "${options.prefix}" prefix, this might take a while...`
127+
gray(
128+
`⏳ Generating wallet with "${options.prefix}" prefix, this might take a while...`
129+
)
127130
);
128131
onlyPrefix = true;
129132
}
@@ -134,7 +137,9 @@ class Wallet {
134137
RegExp(row.rareSymbols, 'g').test(options.suffix))
135138
) {
136139
log(
137-
`⏳ Generating wallet with "${options.suffix}" suffix, this might take a while...`
140+
gray(
141+
`⏳ Generating wallet with "${options.suffix}" suffix, this might take a while...`
142+
)
138143
);
139144
onlySuffix = true;
140145
}
@@ -626,7 +631,8 @@ class Wallet {
626631
// Generate mnemonic if not provided
627632
const mnemonic = mnemonicString || bip39.generateMnemonic();
628633
// Generate Tron address from private key
629-
const wallet = tronWeb.utils.accounts.generateAccountWithMnemonic(mnemonic);
634+
const wallet =
635+
tronWeb.utils.accounts.generateAccountWithMnemonic(mnemonic);
630636

631637
Object.assign(result, {
632638
addresses: [

src/chains/TRON.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"title": "TRON",
3+
"network": "TRON",
4+
"startsWith": "T",
5+
"prefixTest": "(?![0OI])[1-9a-zA-Z]",
6+
"rareSymbols": "[1-9a-z]",
7+
"apps": ["tronlink", "trustwallet"],
8+
"flags": ["m", "p", "s"]
9+
}

0 commit comments

Comments
 (0)