@yerofey/cryptowallet-cli 1.3.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -26,10 +26,10 @@ $ cw -p aaa
26
26
  # generate random BTC wallet (default format: bech32 - "bc1q...")
27
27
  $ cw -c BTC
28
28
 
29
- # generate random BTC wallet with desired prefix (case sensitive)
29
+ # generate random BTC wallet with desired prefix (case-insensitive)
30
30
  $ cw -c BTC -p ABC
31
31
 
32
- # generate random BTC wallet with desired prefix (case insensitive)
32
+ # generate random BTC wallet with desired prefix (case-sensitive)
33
33
  $ cw -c BTC -P abc
34
34
 
35
35
  # generate BTC legacy wallet ("1...")
@@ -95,10 +95,10 @@ $ cw -l
95
95
  * `-l` or `--list`: List all supported cryptocurrencies
96
96
  * `-m` or `--mnemonic`: Use a bip39 mnemonic phrase (if is set) to generate wallet, or leave it empty to generate new one
97
97
  * `-n` or `--number`: Specify number of wallets to display (works for HD wallets only, like BTC/LTC/DOGE)
98
- * `-p` or `--prefix`: Specify desired prefix of an wallet address (**case-sensitive**)
99
- * `-P` or `--prefix-ignorecase`: Specify desired prefix of an wallet address (**case-insensitive**)
100
- * `-s` or `--suffix`: Specify desired suffix of an wallet address (**case-sensitive**)
101
- * `-S` or `--suffix-ignorecase`: Specify desired suffix of an wallet address (**case-insensitive**)
98
+ * `-p` or `--prefix`: Specify desired prefix of an wallet address (**case-insensitive**)
99
+ * `-P` or `--prefix-sensitive`: Specify desired prefix of an wallet address (**case-sensitive**)
100
+ * `-s` or `--suffix`: Specify desired suffix of an wallet address (**case-insensitive**)
101
+ * `-S` or `--suffix-sensitive`: Specify desired suffix of an wallet address (**case-sensitive**)
102
102
  * `-v` or `--version`: Display the version of CW tool
103
103
 
104
104
  ## Highlights
package/cli.js CHANGED
@@ -3,19 +3,20 @@
3
3
 
4
4
  const { program } = require('commander');
5
5
  const chalk = require('chalk');
6
- const { log, supportedCoins } = require('./src/utils');
6
+ const { log, supportedChains } = require('./src/utils');
7
7
  const Method = require('./src/Method');
8
8
 
9
- program.option('-c, --coin <ticker>', 'Wallet for specific coin', 'ERC');
9
+ program.option('-b, --chain <ticker>', 'Wallet for specific blockchain', 'ERC');
10
+ program.option('-c, --chain <ticker>', 'Wallet for specific blockchain', 'ERC');
10
11
  program.option('-f, --format <format>', 'Wallet format type (for cryptos with multiple wallet formats)');
11
12
  program.option('-g, --geek', 'Display some more info (geeky)');
12
13
  program.option('-l, --list', 'List all supported cryptos');
13
14
  program.option('-m, --mnemonic [mnemonic]', 'Generate wallet from mnemonic string OR just a mnemonic string');
14
15
  program.option('-n, --number <number>', 'Number of wallets to generate (if supported)');
15
- program.option('-p, --prefix <prefix>', 'Desired wallet prefix (case sensitive)');
16
- program.option('-P, --prefix-ignorecase <prefix>', 'Desired wallet prefix (case insensitive)');
17
- program.option('-s, --suffix <suffix>', 'Desired wallet suffix (case sensitive)');
18
- program.option('-S, --suffix-ignorecase <suffix>', 'Desired wallet suffix (case insensitive)');
16
+ program.option('-p, --prefix <prefix>', 'Desired wallet prefix');
17
+ program.option('-P, --prefix-sensitive <prefix>', 'Desired wallet prefix (case-sensitive)');
18
+ program.option('-s, --suffix <suffix>', 'Desired wallet suffix');
19
+ program.option('-S, --suffix-sensitive <suffix>', 'Desired wallet suffix (case-sensitive)');
19
20
  program.option('-v, --version', 'Display cryptowallet version');
20
21
  program.parse();
21
22
 
@@ -34,13 +35,13 @@ program.parse();
34
35
  return new Method('version').init();
35
36
  }
36
37
 
37
- const coin = (options.coin).toUpperCase() || '';
38
- if (supportedCoins.includes(coin)) {
38
+ const chain = (options.chain).toUpperCase() || '';
39
+ if (supportedChains.includes(chain)) {
39
40
  return new Method('wallet', {
40
- coin,
41
- options
41
+ chain,
42
+ options,
42
43
  }).init();
43
44
  }
44
45
 
45
- log(chalk.red('⛔️ Error: coin not supported!'));
46
+ log(chalk.red('⛔️ Error: this blockchain is not supported!'));
46
47
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yerofey/cryptowallet-cli",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "homepage": "https://github.com/yerofey/cryptowallet-cli",
5
5
  "author": "Yerofey S. <pm@yerofey.dev> (https://github.com/yerofey)",
6
6
  "bin": {
package/src/CW.js CHANGED
@@ -1,18 +1,18 @@
1
- const Coin = require('./Coin');
1
+ const Chain = require('./Chain');
2
2
  const { Wallet } = require('./Wallet');
3
3
 
4
4
  class CW {
5
- constructor(coin, options = {}) {
5
+ constructor(chain, options = {}) {
6
6
  const defaultValues = {
7
- coin: coin || options.coin || '',
7
+ chain: chain || options.chain || '',
8
8
  format: '',
9
9
  geek: false,
10
10
  mnemonic: '',
11
11
  number: 1,
12
- prefix: options.prefixIgnorecase || '',
13
- prefixIgnoreCase: options.prefixIgnorecase !== undefined,
14
- suffix: options.suffixIgnorecase || '',
15
- suffixIgnoreCase: options.suffixIgnorecase !== undefined,
12
+ prefix: options.prefixSensitive || '',
13
+ prefixIsCaseSensitive: options.prefixSensitive !== undefined,
14
+ suffix: options.suffixSensitive || '',
15
+ suffixIsCaseSensitive: options.suffixSensitive !== undefined,
16
16
  }
17
17
 
18
18
  for (const key of Object.keys(defaultValues)) {
@@ -21,9 +21,9 @@ class CW {
21
21
  }
22
22
  }
23
23
 
24
- this.coin = coin;
24
+ this.chain = chain;
25
25
  this.options = options;
26
- this.row = new Coin(coin, options.format).row;
26
+ this.row = new Chain(chain, options.format).row;
27
27
  }
28
28
 
29
29
  async init() {
@@ -1,6 +1,6 @@
1
- class Coin {
2
- constructor(coin, format) {
3
- const content = require('./coins/' + coin + '.json') || {};
1
+ class Chain {
2
+ constructor(chain, format) {
3
+ const content = require('./chains/' + chain + '.json') || {};
4
4
  const data = (() => {
5
5
  if (content.formats !== undefined) {
6
6
  if (format != '' && format != content.defaultFormat) {
@@ -25,4 +25,4 @@ class Coin {
25
25
  }
26
26
  }
27
27
 
28
- module.exports = Coin;
28
+ module.exports = Chain;
package/src/Method.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const chalk = require('chalk');
2
2
  const columnify = require('columnify');
3
- const { log, supportedCoins } = require('./utils');
3
+ const { log, supportedChains } = require('./utils');
4
4
  const { generateMnemonicString } = require('./Wallet');
5
5
  const selfInfo = require('../package.json');
6
6
  const CW = require('./CW');
@@ -15,10 +15,10 @@ class Method {
15
15
  const callMethod = {
16
16
  '_': () => {},
17
17
  'list': () => {
18
- log(`🔠 All supported cryptos:\n`);
18
+ log(`🔠 All supported blockchains:\n`);
19
19
  let cryptos = {};
20
- for (const val of supportedCoins) {
21
- const data = require('./coins/' + val + '.json');
20
+ for (const val of supportedChains) {
21
+ const data = require('./chains/' + val + '.json');
22
22
  let title = data.title || '';
23
23
  if (title == '' || val == 'ERC') {
24
24
  continue;
@@ -30,7 +30,7 @@ class Method {
30
30
  columnSplitter: ' - ',
31
31
  }));
32
32
  log();
33
- log(`ℹ️ Use flag "-c TICKER" to select specific coin`);
33
+ log(`ℹ️ Use flag "-c TICKER" to select specific blockchain`);
34
34
  },
35
35
  'mnemonic': () => {
36
36
  log(`✨ ${chalk.green('Done!')} ${chalk.blueBright('Here is your randomly generated 12 words mnemonic string:')}\n`);
@@ -42,23 +42,23 @@ class Method {
42
42
  log(selfInfo.version);
43
43
  },
44
44
  'wallet': async () => {
45
- const coin = this.params.coin;
45
+ const chain = this.params.chain;
46
46
  const options = this.params.options;
47
47
 
48
- const cw = await new CW(coin, options).init();
48
+ const cw = await new CW(chain, options).init();
49
49
 
50
- let coinFullName = (cw.row.name || coin) + (cw.wallet.format !== undefined && cw.wallet.format != '' ? ' (' + cw.wallet.format + ')' : '');
50
+ let chainFullName = (cw.row.name || chain) + (cw.wallet.format !== undefined && cw.wallet.format != '' ? ' (' + cw.wallet.format + ')' : '');
51
51
 
52
52
  if (cw.options.prefix && !cw.prefixFound) {
53
- log(`😢 ${chalk.yellow('Sorry, ' + coinFullName + ' does not support prefix yet...')}`);
53
+ log(`😢 ${chalk.yellow('Sorry, ' + chainFullName + ' does not support prefix yet...')}`);
54
54
  }
55
55
 
56
56
  if (cw.options.suffix && !cw.suffixFound) {
57
- log(`😢 ${chalk.yellow('Sorry, ' + coinFullName + ' does not support suffix yet...')}`);
57
+ log(`😢 ${chalk.yellow('Sorry, ' + chainFullName + ' does not support suffix yet...')}`);
58
58
  }
59
59
 
60
60
  if (cw.options.mnemonic != '' && cw.wallet.mnemonic == undefined) {
61
- log(`😢 ${chalk.yellow('Sorry, ' + coinFullName + ' does not support mnemonic yet...')}`);
61
+ log(`😢 ${chalk.yellow('Sorry, ' + chainFullName + ' does not support mnemonic yet...')}`);
62
62
  }
63
63
 
64
64
  if (cw.wallet.error !== undefined) {
@@ -68,13 +68,13 @@ class Method {
68
68
 
69
69
  // prefix, suffix
70
70
  if (cw.prefixFound && cw.suffixFound) {
71
- log(`✨ ${chalk.green('Done!')} ${chalk.blueBright('Here is your brand new ' + coinFullName + ' wallet with "' + cw.options.prefix + '" prefix and "' + cw.options.suffix + '" suffix:')}\n`);
71
+ log(`✨ ${chalk.green('Done!')} ${chalk.blueBright('Here is your brand new ' + chainFullName + ' wallet with "' + cw.options.prefix + '" prefix and "' + cw.options.suffix + '" suffix:')}\n`);
72
72
  } else if (cw.prefixFound) {
73
- log(`✨ ${chalk.green('Done!')} ${chalk.blueBright('Here is your brand new ' + coinFullName + ' wallet with "' + cw.options.prefix + '" prefix:')}\n`);
73
+ log(`✨ ${chalk.green('Done!')} ${chalk.blueBright('Here is your brand new ' + chainFullName + ' wallet with "' + cw.options.prefix + '" prefix:')}\n`);
74
74
  } else if (cw.suffixFound) {
75
- log(`✨ ${chalk.green('Done!')} ${chalk.blueBright('Here is your brand new ' + coinFullName + ' wallet with "' + cw.options.suffix + '" suffix:')}\n`);
75
+ log(`✨ ${chalk.green('Done!')} ${chalk.blueBright('Here is your brand new ' + chainFullName + ' wallet with "' + cw.options.suffix + '" suffix:')}\n`);
76
76
  } else {
77
- log(`✨ ${chalk.green('Done!')} ${chalk.blueBright('Here is your brand new ' + coinFullName + ' wallet:')}\n`);
77
+ log(`✨ ${chalk.green('Done!')} ${chalk.blueBright('Here is your brand new ' + chainFullName + ' wallet:')}\n`);
78
78
  }
79
79
 
80
80
  // result
@@ -94,7 +94,6 @@ class Method {
94
94
 
95
95
  if (cw.prefixFound && cw.prefixFoundInWallets.includes(item.address) && cw.suffixFound && cw.suffixFoundInWallets.includes(item.address)) {
96
96
  // highlight found prefix
97
- // log(`👛 ${item.address}`);
98
97
  const addressCutPrefixLength = cw.row.startsWith.length + cw.options.prefix.length;
99
98
  const addressFirstPart = item.address.slice(cw.row.startsWith.length, addressCutPrefixLength);
100
99
  const addressLastPart = item.address.slice(item.address.length - cw.options.suffix.length);
package/src/Wallet.js CHANGED
@@ -11,7 +11,10 @@ class Wallet {
11
11
  const row = cw.row;
12
12
  const options = cw.options;
13
13
 
14
- const badSymbolsArray = (options.prefix != '' ? options.prefix.split('').filter(char => !RegExp(row.prefixTest, 'g').test(char)) : []);
14
+ const desiredSymbolsArray = (options.prefix.length > 0 || options.suffix.length > 0) ? options.prefix.split('').concat(options.suffix.split('')) : [];
15
+ const desiredSymbolsUniqueArray = desiredSymbolsArray.filter((item, pos) => desiredSymbolsArray.indexOf(item) === pos);
16
+ const badSymbolsArray = desiredSymbolsUniqueArray.filter(char => !RegExp(row.prefixTest, 'g').test(char)) || [];
17
+
15
18
  let wallet = {};
16
19
  let prefixFound = false;
17
20
  let prefixFoundInWallets = [];
@@ -21,8 +24,8 @@ class Wallet {
21
24
  let onlySuffix = false;
22
25
  let onlyBoth = false;
23
26
 
24
- const prefixFoundInAddress = (address, isIgnoringCase, prefix, symbol) => (!isIgnoringCase && address.startsWith(symbol + '' + prefix) || isIgnoringCase && (address).toUpperCase().startsWith((symbol + '' + prefix).toUpperCase()));
25
- const suffixFoundInAddress = (address, isIgnoringCase, suffix) => (!isIgnoringCase && address.endsWith(suffix) || isIgnoringCase && (address).toUpperCase().endsWith(suffix));
27
+ const prefixFoundInAddress = (address, isCaseSensitive, prefix, symbol) => (isCaseSensitive && address.startsWith(symbol + '' + prefix) || !isCaseSensitive && (address).toUpperCase().startsWith((symbol + '' + prefix).toUpperCase()));
28
+ const suffixFoundInAddress = (address, isCaseSensitive, suffix) => (isCaseSensitive && address.endsWith(suffix) || !isCaseSensitive && (address).toUpperCase().endsWith(suffix));
26
29
 
27
30
  if (options.prefix && row.flags.includes('p') || options.suffix && row.flags.includes('s')) {
28
31
  if (badSymbolsArray.length === 0) {
@@ -49,34 +52,34 @@ class Wallet {
49
52
  wallet = await this.createWallet();
50
53
  for (let firstSymbol of startsWithSymbols) {
51
54
  if (wallet.address !== undefined) { // one address
52
- if (onlyPrefix && prefixFoundInAddress(wallet.address, options.prefixIgnoreCase, options.prefix, firstSymbol)) {
55
+ if (onlyPrefix && prefixFoundInAddress(wallet.address, options.prefixIsCaseSensitive, options.prefix, firstSymbol)) {
53
56
  prefixFound = true;
54
57
  break loop;
55
58
  }
56
59
 
57
- if (onlySuffix && suffixFoundInAddress(wallet.address, options.suffixIgnoreCase, options.suffix)) {
60
+ if (onlySuffix && suffixFoundInAddress(wallet.address, options.suffixIsCaseSensitive, options.suffix)) {
58
61
  suffixFound = true;
59
62
  break loop;
60
63
  }
61
64
 
62
- if (onlyBoth && prefixFoundInAddress(wallet.address, options.prefixIgnoreCase, options.prefix, firstSymbol) && suffixFoundInAddress(wallet.address, options.suffixIgnoreCase, options.suffix)) {
65
+ if (onlyBoth && prefixFoundInAddress(wallet.address, options.prefixIsCaseSensitive, options.prefix, firstSymbol) && suffixFoundInAddress(wallet.address, options.suffixIsCaseSensitive, options.suffix)) {
63
66
  prefixFound = true;
64
67
  suffixFound = true;
65
68
  break loop;
66
69
  }
67
70
  } else if (wallet.addresses !== undefined) { // multiple addresses
68
71
  for (let item of wallet.addresses) {
69
- if (onlyPrefix && prefixFoundInAddress(item.address, options.prefixIgnoreCase, options.prefix, firstSymbol)) {
72
+ if (onlyPrefix && prefixFoundInAddress(item.address, options.prefixIsCaseSensitive, options.prefix, firstSymbol)) {
70
73
  prefixFound = true;
71
74
  prefixFoundInWallets.push(item.address);
72
75
  }
73
76
 
74
- if (onlySuffix && suffixFoundInAddress(item.address, options.suffixIgnoreCase, options.suffix)) {
77
+ if (onlySuffix && suffixFoundInAddress(item.address, options.suffixIsCaseSensitive, options.suffix)) {
75
78
  suffixFound = true;
76
79
  suffixFoundInWallets.push(item.address);
77
80
  }
78
81
 
79
- if (onlyBoth && prefixFoundInAddress(item.address, options.prefixIgnoreCase, options.prefix, firstSymbol) && suffixFoundInAddress(item.address, options.suffixIgnoreCase, options.suffix)) {
82
+ if (onlyBoth && prefixFoundInAddress(item.address, options.prefixIsCaseSensitive, options.prefix, firstSymbol) && suffixFoundInAddress(item.address, options.suffixIsCaseSensitive, options.suffix)) {
80
83
  prefixFound = true;
81
84
  prefixFoundInWallets.push(item.address);
82
85
  suffixFound = true;
@@ -117,7 +120,7 @@ class Wallet {
117
120
 
118
121
  async createWallet() {
119
122
  const cw = this.cw;
120
- const coin = cw.coin;
123
+ const chain = cw.chain;
121
124
  const row = cw.row;
122
125
  const options = cw.options;
123
126
 
@@ -128,7 +131,7 @@ class Wallet {
128
131
 
129
132
  if (row.length == 0) {
130
133
  return {
131
- error: 'coin not found',
134
+ error: 'this blockchain is not found',
132
135
  }
133
136
  }
134
137
 
@@ -136,7 +139,7 @@ class Wallet {
136
139
  const CoinKey = require('coinkey');
137
140
  const CoinInfo = require('coininfo');
138
141
 
139
- const wallet = CoinKey.createRandom(CoinInfo(coin).versions);
142
+ const wallet = CoinKey.createRandom(CoinInfo(chain).versions);
140
143
 
141
144
  result = Object.assign(result, {
142
145
  format,
@@ -146,7 +149,7 @@ class Wallet {
146
149
  privateKey: wallet.privateWif,
147
150
  }]
148
151
  });
149
- } else if (coin == 'BTC') {
152
+ } else if (chain == 'BTC') {
150
153
  const bip39 = require('bip39');
151
154
  const { fromMnemonic, fromZPrv } = require('bip84');
152
155
 
@@ -178,7 +181,7 @@ class Wallet {
178
181
  privateExtendedKey: account.getAccountPrivateKey(),
179
182
  mnemonic
180
183
  });
181
- } else if (coin == 'DOGE' || coin == 'LTC') {
184
+ } else if (chain == 'DOGE' || chain == 'LTC') {
182
185
  const bip39 = require('bip39');
183
186
  const { fromMnemonic, fromZPrv } = require('@yerofey/' + row.title.toLowerCase() + '-bip84');
184
187
 
@@ -292,7 +295,7 @@ class Wallet {
292
295
  addresses,
293
296
  mnemonic,
294
297
  });
295
- } else if (coin == 'ONE') {
298
+ } else if (chain == 'ONE') {
296
299
  const bip39 = require('bip39');
297
300
  const { Wallet } = require('@harmony-js/account');
298
301
 
@@ -316,7 +319,7 @@ class Wallet {
316
319
  }],
317
320
  mnemonic,
318
321
  });
319
- } else if (coin == 'TRX') {
322
+ } else if (chain == 'TRX') {
320
323
  const tronWeb = require('tronweb');
321
324
 
322
325
  try {
@@ -334,7 +337,7 @@ class Wallet {
334
337
  error
335
338
  }
336
339
  }
337
- } else if (coin == 'XTZ') {
340
+ } else if (chain == 'XTZ') {
338
341
  const tezos = require('tezos-sign');
339
342
  const wallet = tezos.generateKeysNoSeed();
340
343
 
@@ -347,7 +350,7 @@ class Wallet {
347
350
  });
348
351
  } else {
349
352
  return {
350
- error: 'coin is not supported yet'
353
+ error: 'your desired blockchain is not supported yet'
351
354
  }
352
355
  }
353
356
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/src/utils.js CHANGED
@@ -13,13 +13,13 @@ const filesList = (dir) => {
13
13
 
14
14
  const objectHasAllKeys = (obj, keysArray) => keysArray.every(item => obj.hasOwnProperty(item));
15
15
 
16
- let supportedCoins = [];
17
- const coinsFolder = __dirname + '/coins/';
18
- filesList(coinsFolder).forEach((item) => {
19
- const name = item.replace(coinsFolder, '').replace('.json', '');
20
- supportedCoins.push(name);
16
+ let supportedChains = [];
17
+ const chainsFolder = __dirname + '/chains/';
18
+ filesList(chainsFolder).forEach((item) => {
19
+ const name = item.replace(chainsFolder, '').replace('.json', '');
20
+ supportedChains.push(name);
21
21
  });
22
22
 
23
23
  module.exports.log = log;
24
24
  module.exports.objectHasAllKeys = objectHasAllKeys;
25
- module.exports.supportedCoins = supportedCoins;
25
+ module.exports.supportedChains = supportedChains;