Skip to content

Commit

Permalink
feat: Refactor TRX and TRON chain configurations, update README, and …
Browse files Browse the repository at this point in the history
…bump version to 1.38.2
  • Loading branch information
yerofey committed Feb 13, 2025
1 parent f02767e commit c8d73e7
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 99 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Minimum Node.js version](https://badgen.net/npm/node/@yerofey/cryptowallet-cli)](https://npmjs.com/@yerofey/cryptowallet-cli)
[![NPM package version](https://badgen.net/npm/v/@yerofey/cryptowallet-cli)](https://npmjs.com/package/@yerofey/cryptowallet-cli)

> Crypto wallet generator CLI tool
> CW: crypto wallet generator CLI tool
![Screenshot](https://i.imgur.com/uWuT4lF.png)

Expand Down Expand Up @@ -259,9 +259,9 @@ Each chain JSON file is structured to provide essential information about the bl
- `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.
- `formats`: (Optional) An object defining multiple wallet formats if the blockchain supports more than one format. Each format should specify its unique properties.

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

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

## Contributing

Expand Down
48 changes: 22 additions & 26 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
#!/usr/bin/env node
'use strict';

// filter out unwanted "bigint" warning messages
const originalStderrWrite = process.stderr.write;
process.stderr.write = function (chunk, encoding, callback) {
const msg = chunk.toString();
if (msg.includes('bigint: Failed to load bindings')) return;
originalStderrWrite.apply(process.stderr, arguments);
};

import os from 'node:os';
import {
Worker,
Expand All @@ -17,65 +9,67 @@ import {
workerData,
} from 'node:worker_threads';
import { fileURLToPath } from 'node:url';
import chalk from 'chalk';
import { options } from './src/options.js';
import { log, supportedChains } from './src/utils.js';
import { exit, log, supportedChains } from './src/utils.js';
import Method from './src/Method.js';
import chalk from 'chalk';

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

const exit = process.exit;

if (options.list !== undefined) {
// show all supported chains
if (options.list) {
(async () => {
return new Method('list').init();
await new Method('list').init();
exit(0);
})();
exit(0);
}

// generate mnemonic string if no argument is passed or only the mnemonic length is passed
// generate mnemonic string
if (
options.mnemonic &&
(options.mnemonic === true ||
options.mnemonic === '' ||
options.mnemonic.split(' ').length === 1)
) {
(async () => {
return new Method('mnemonic').init({
new Method('mnemonic').init({
mnemonic: options.mnemonic,
copy: options?.copy || false,
});
exit(0);
})();
exit(0);
}

// show the version number
if (options.version) {
(async () => {
return new Method('version').init();
new Method('version').init();
exit(0);
})();
exit(0);
}

// show donation message
if (options.donate) {
(async () => {
return new Method('donate').init();
new Method('donate').init();
exit(0);
})();
exit(0);
}

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

// multi-threads mode (only for suffix, prefix, number)
const allMachineThreads = os.cpus().length;
const availableThreads = os.cpus().length - 1; // leave 1 core for the main thread
const defaultThreads = os.cpus().length / 2; // use half of the available threads
const inputThreads = parseInt(options.threads || 1, 10); // default to 1 thread
const inputThreads = parseInt(options.threads || defaultThreads, 10); // user input threads
let numThreads = defaultThreads; // default to half of the available threads
if (inputThreads > availableThreads) {
numThreads = defaultThreads;
Expand All @@ -90,13 +84,15 @@ if (isMainThread) {
console.log(
chalk.green(
'🐢 Using only 1 thread to generate a wallet, this might take a while...'
)
),
chalk.gray(`(pass "-t ${availableThreads}" to use all available threads)`)
);
} else {
console.log(
chalk.green(
`⚡ Using ${numThreads}/${allMachineThreads} threads to generate a wallet...`
)
),
chalk.gray(`(pass "-t ${availableThreads}" to use all available threads)`)
);
}

Expand Down
35 changes: 2 additions & 33 deletions package-lock.json

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

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yerofey/cryptowallet-cli",
"version": "1.38.1",
"version": "1.38.2",
"description": "Crypto wallet generator CLI tool",
"type": "module",
"homepage": "https://github.com/yerofey/cryptowallet-cli",
Expand Down Expand Up @@ -41,7 +41,6 @@
}
],
"bin": {
"cryptowallet": "cli.js",
"cw": "cli.js"
},
"engines": {
Expand All @@ -58,6 +57,7 @@
"./src/"
],
"keywords": [
"cw",
"cli",
"cli-app",
"console",
Expand Down Expand Up @@ -133,7 +133,6 @@
"ed25519-hd-key": "^1.3.0",
"eth-lib": "0.1.29",
"ethereum-bip84": "0.0.3",
"ethereum-cryptography": "^3.0.0",
"ethereum-mnemonic-privatekey-utils": "1.0.5",
"qrcode-terminal": "^0.12.0",
"tezos-sign": "1.4.1",
Expand Down
21 changes: 0 additions & 21 deletions pnpm-lock.yaml

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

7 changes: 4 additions & 3 deletions src/Method.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import clipboardy from 'clipboardy';
import columnify from 'columnify';
import CsvWriter from 'csv-writer';
import qr from 'qrcode-terminal';
import { log, supportedChains, loadJson } from './utils.js';
import { generateMnemonicString } from './Wallet.js';
import CW from './CW.js';
import { generateMnemonicString } from './Wallet.js';
import { log, supportedChains, loadJson } from './utils.js';

config();

const {
blue,
green,
Expand Down Expand Up @@ -53,7 +54,7 @@ class Method {
for (const val of supportedChains) {
// eslint-disable-next-line no-undef
const data = await loadJson(
`${path.dirname(import.meta.url)}/chains/${val}.json`.replace(
`${path.dirname(import.meta.url)}${path.sep}chains${path.sep}${val}.json`.replace(
'file://',
''
)
Expand Down
18 changes: 12 additions & 6 deletions src/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { config } from 'dotenv';
import { log } from './utils.js';
import chalk from 'chalk';
const { red, yellow } = chalk;
const { red, yellow, gray } = chalk;
import CoinKey from 'coinkey';
import CoinInfo from 'coininfo';
import bip39 from 'bip39';
Expand All @@ -21,7 +21,6 @@ import { Account } from 'eth-lib/lib/index.js';
import { Wallet as HarmonyWallet } from '@harmony-js/account';
import pkutils from 'ethereum-mnemonic-privatekey-utils';
import bCrypto from '@binance-chain/javascript-sdk/lib/crypto/index.js';
import { HDKey } from 'ethereum-cryptography/hdkey.js';
import tronWeb from 'tronweb';
import tezos from 'tezos-sign';
import {
Expand Down Expand Up @@ -112,7 +111,9 @@ class Wallet {
if (options.prefix && options.suffix) {
// prefix & suffix
log(
`⏳ Generating wallet with "${options.prefix}" prefix and "${options.suffix}" suffix, this for sure will take a while...`
gray(
`⏳ Generating wallet with "${options.prefix}" prefix and "${options.suffix}" suffix, this for sure will take a while...`
)
);
onlyBoth = true;
} else {
Expand All @@ -123,7 +124,9 @@ class Wallet {
RegExp(row.rareSymbols, 'g').test(options.prefix))
) {
log(
`⏳ Generating wallet with "${options.prefix}" prefix, this might take a while...`
gray(
`⏳ Generating wallet with "${options.prefix}" prefix, this might take a while...`
)
);
onlyPrefix = true;
}
Expand All @@ -134,7 +137,9 @@ class Wallet {
RegExp(row.rareSymbols, 'g').test(options.suffix))
) {
log(
`⏳ Generating wallet with "${options.suffix}" suffix, this might take a while...`
gray(
`⏳ Generating wallet with "${options.suffix}" suffix, this might take a while...`
)
);
onlySuffix = true;
}
Expand Down Expand Up @@ -626,7 +631,8 @@ class Wallet {
// Generate mnemonic if not provided
const mnemonic = mnemonicString || bip39.generateMnemonic();
// Generate Tron address from private key
const wallet = tronWeb.utils.accounts.generateAccountWithMnemonic(mnemonic);
const wallet =
tronWeb.utils.accounts.generateAccountWithMnemonic(mnemonic);

Object.assign(result, {
addresses: [
Expand Down
9 changes: 9 additions & 0 deletions src/chains/TRON.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"title": "TRON",
"network": "TRON",
"startsWith": "T",
"prefixTest": "(?![0OI])[1-9a-zA-Z]",
"rareSymbols": "[1-9a-z]",
"apps": ["tronlink", "trustwallet"],
"flags": ["m", "p", "s"]
}
Loading

0 comments on commit c8d73e7

Please sign in to comment.