@yerofey/cryptowallet-cli 1.16.2 â 1.17.1
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 +16 -4
- package/cli.js +3 -2
- package/package.json +1 -2
- package/src/Method.js +19 -6
- package/src/Wallet.js +57 -17
package/README.md
CHANGED
|
@@ -43,6 +43,16 @@ $ cw
|
|
|
43
43
|
# generate random BTC wallet (default format: bech32 - "bc1q...")
|
|
44
44
|
$ cw -c btc
|
|
45
45
|
|
|
46
|
+
# generate random mnemonic string (12 words) to import in any wallet app
|
|
47
|
+
$ cw -m
|
|
48
|
+
|
|
49
|
+
# generate random mnemonic string of a specific length (12, 18, or 24 words)
|
|
50
|
+
$ cw -m 18
|
|
51
|
+
$ cw -m 24
|
|
52
|
+
|
|
53
|
+
# generate a wallet from a given mnemonic string
|
|
54
|
+
$ cw -m "radio bright pizza pluck family crawl palm flame forget focus stock stadium"
|
|
55
|
+
|
|
46
56
|
# generate N random wallets (default coin is ETH/ERC-like)
|
|
47
57
|
$ cw -n 10
|
|
48
58
|
|
|
@@ -88,9 +98,6 @@ $ cw -c btc --csv
|
|
|
88
98
|
# generate few wallets and save the output into CSV file with custom name "new.csv"
|
|
89
99
|
$ cw -c btc -n 10 -D new
|
|
90
100
|
|
|
91
|
-
# generate just a mnemonic string (12 words) to import in any wallet app
|
|
92
|
-
$ cw -m
|
|
93
|
-
|
|
94
101
|
# list all supported blockchains
|
|
95
102
|
$ cw -l
|
|
96
103
|
```
|
|
@@ -133,7 +140,12 @@ $ cw -l
|
|
|
133
140
|
- `-f` or `--format`: Specify the blockchain wallet format (for BTC: legacy, segwit, bech32)
|
|
134
141
|
- `-g` or `--geek`: Display some additional "geeky" info
|
|
135
142
|
- `-l` or `--list`: List all supported blockchains
|
|
136
|
-
- `-m` or `--mnemonic`:
|
|
143
|
+
- `-m` or `--mnemonic [value]`: If used without a value or with `12`, `18`, or `24`, it generates a mnemonic string of that length. If a mnemonic string is provided, it generates a wallet from the given mnemonic. For example:
|
|
144
|
+
- `$ cw -m`: Generates a default 12-word mnemonic string.
|
|
145
|
+
- `$ cw -m 12`: Generates a 12-word mnemonic string.
|
|
146
|
+
- `$ cw -m 18`: Generates an 18-word mnemonic string.
|
|
147
|
+
- `$ cw -m 24`: Generates a 24-word mnemonic string.
|
|
148
|
+
- `$ cw -m "your mnemonic phrase here"`: Generates a wallet from the provided mnemonic string.
|
|
137
149
|
- `-n` or `--number`: Specify number of wallets to display (works for HD wallets only, like BTC/LTC/DOGE)
|
|
138
150
|
- `-p` or `--prefix`: Specify desired prefix for the wallet address (**case-insensitive**)
|
|
139
151
|
- `-P` or `--prefix-sensitive`: Specify desired prefix of the wallet address (**case-sensitive**)
|
package/cli.js
CHANGED
|
@@ -11,8 +11,9 @@ import Method from './src/Method.js';
|
|
|
11
11
|
return new Method('list').init();
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
if
|
|
15
|
-
|
|
14
|
+
// generate mnemonic string if no argument is passed or only the mnemonic length is passed
|
|
15
|
+
if (options.mnemonic === true || options.mnemonic === '' || options.mnemonic.split(' ').length === 1) {
|
|
16
|
+
return new Method('mnemonic').init({ mnemonic: options.mnemonic });
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
if (options.version) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yerofey/cryptowallet-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.1",
|
|
4
4
|
"description": "Crypto wallet generator CLI tool",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"homepage": "https://github.com/yerofey/cryptowallet-cli",
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"lint": "pnpm exec eslint src/*.js",
|
|
22
|
-
"postinstall": "cw --donate",
|
|
23
22
|
"test": "ava"
|
|
24
23
|
},
|
|
25
24
|
"files": [
|
package/src/Method.js
CHANGED
|
@@ -19,6 +19,7 @@ class Method {
|
|
|
19
19
|
this.name = name;
|
|
20
20
|
this.params = params;
|
|
21
21
|
this.callMethods = this._initializeMethods();
|
|
22
|
+
this.inputOptions = {};
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
_initializeMethods() {
|
|
@@ -61,16 +62,23 @@ class Method {
|
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
_mnemonic() {
|
|
65
|
+
const mnemonic = this.inputOptions.mnemonic || '12';
|
|
66
|
+
const mnemonicLength = ['12', '18', '24'].includes(mnemonic)
|
|
67
|
+
? parseInt(mnemonic, 10)
|
|
68
|
+
: 12;
|
|
69
|
+
|
|
64
70
|
log(
|
|
65
71
|
`⨠${green('Done!')} ${blueBright(
|
|
66
|
-
|
|
72
|
+
`Here is your randomly generated ${
|
|
73
|
+
mnemonicLength || 12
|
|
74
|
+
} words mnemonic string:`
|
|
67
75
|
)}\n`
|
|
68
76
|
);
|
|
69
|
-
log(`đ ${generateMnemonicString()}`);
|
|
77
|
+
log(`đ ${generateMnemonicString(mnemonicLength)}`);
|
|
70
78
|
log();
|
|
71
79
|
log(
|
|
72
80
|
greenBright(
|
|
73
|
-
'âšī¸ You can import
|
|
81
|
+
'âšī¸ You can import it into your favorite wallet app or use it to generate a wallet with "-m" flag'
|
|
74
82
|
)
|
|
75
83
|
);
|
|
76
84
|
}
|
|
@@ -349,7 +357,7 @@ class Method {
|
|
|
349
357
|
if (cw.row.network == 'EVM' || false) {
|
|
350
358
|
log(
|
|
351
359
|
yellow(
|
|
352
|
-
'đ You can use this wallet in Ethereum, Binance Smart Chain, Polygon and
|
|
360
|
+
'đ You can use this wallet in Ethereum, Binance Smart Chain, Polygon and many others networks (EVM compatible)'
|
|
353
361
|
)
|
|
354
362
|
);
|
|
355
363
|
}
|
|
@@ -381,7 +389,11 @@ class Method {
|
|
|
381
389
|
|
|
382
390
|
// donation
|
|
383
391
|
log();
|
|
384
|
-
log(
|
|
392
|
+
log(
|
|
393
|
+
blueBright(
|
|
394
|
+
'đ Consider supporting the project - see donation options with: cw --donate'
|
|
395
|
+
)
|
|
396
|
+
);
|
|
385
397
|
}
|
|
386
398
|
}
|
|
387
399
|
|
|
@@ -409,7 +421,8 @@ class Method {
|
|
|
409
421
|
`);
|
|
410
422
|
}
|
|
411
423
|
|
|
412
|
-
async init() {
|
|
424
|
+
async init(inputOptions = {}) {
|
|
425
|
+
this.inputOptions = inputOptions;
|
|
413
426
|
return (this.callMethods[this.name] || this.callMethods['_'])();
|
|
414
427
|
}
|
|
415
428
|
}
|
package/src/Wallet.js
CHANGED
|
@@ -18,12 +18,20 @@ import pkutils from 'ethereum-mnemonic-privatekey-utils';
|
|
|
18
18
|
import bCrypto from '@binance-chain/javascript-sdk/lib/crypto/index.js';
|
|
19
19
|
import tronWeb from 'tronweb';
|
|
20
20
|
import tezos from 'tezos-sign';
|
|
21
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
Keypair as SolanaKeypair,
|
|
23
|
+
PublicKey as SolanaPublickey,
|
|
24
|
+
} from '@solana/web3.js';
|
|
22
25
|
import bs58 from 'bs58';
|
|
23
|
-
import { TonClient, WalletContractV4, internal as TonInternal } from
|
|
24
|
-
import {
|
|
26
|
+
import { TonClient, WalletContractV4, internal as TonInternal } from '@ton/ton';
|
|
27
|
+
import {
|
|
28
|
+
mnemonicNew as newTonMnemonic,
|
|
29
|
+
mnemonicToPrivateKey as TonMnemonicToPrivateKey,
|
|
30
|
+
} from '@ton/crypto';
|
|
25
31
|
const { red } = chalk;
|
|
26
32
|
|
|
33
|
+
const supportedMnemonicLengths = [12, 18, 24];
|
|
34
|
+
|
|
27
35
|
class Wallet {
|
|
28
36
|
constructor(cw) {
|
|
29
37
|
this.cw = cw;
|
|
@@ -246,7 +254,17 @@ class Wallet {
|
|
|
246
254
|
const options = cw.options;
|
|
247
255
|
|
|
248
256
|
let format = options.format || '';
|
|
249
|
-
|
|
257
|
+
const mnemonic = options.mnemonic || '';
|
|
258
|
+
let mnemonicLength = 12;
|
|
259
|
+
let mnemonicString = '';
|
|
260
|
+
const mnemonicWordsCount = (mnemonic.split(' ') || []).length || 0;
|
|
261
|
+
if (mnemonicWordsCount == 1) {
|
|
262
|
+
const mnemonicInput = parseInt(mnemonic.split(' ')[0], 10);
|
|
263
|
+
mnemonicLength = supportedMnemonicLengths.includes(mnemonicInput) ? mnemonicInput : 12;
|
|
264
|
+
} else {
|
|
265
|
+
mnemonicString = mnemonic;
|
|
266
|
+
mnemonicLength = mnemonicWordsCount;
|
|
267
|
+
}
|
|
250
268
|
let number = options.number || 1;
|
|
251
269
|
let result = {};
|
|
252
270
|
|
|
@@ -338,7 +356,7 @@ class Wallet {
|
|
|
338
356
|
}
|
|
339
357
|
|
|
340
358
|
let addresses = [];
|
|
341
|
-
const mnemonic = mnemonicString ||
|
|
359
|
+
const mnemonic = mnemonicString || generateMnemonicString(mnemonicLength);
|
|
342
360
|
|
|
343
361
|
if (number == 1) {
|
|
344
362
|
const privateKey = bCrypto.getPrivateKeyFromMnemonic(mnemonic, true, 0);
|
|
@@ -375,7 +393,7 @@ class Wallet {
|
|
|
375
393
|
}
|
|
376
394
|
|
|
377
395
|
let addresses = [];
|
|
378
|
-
const mnemonic = mnemonicString ||
|
|
396
|
+
const mnemonic = mnemonicString || generateMnemonicString(mnemonicLength);
|
|
379
397
|
const privateKey = pkutils.getPrivateKeyFromMnemonic(mnemonic);
|
|
380
398
|
|
|
381
399
|
if (number == 1) {
|
|
@@ -448,22 +466,25 @@ class Wallet {
|
|
|
448
466
|
],
|
|
449
467
|
});
|
|
450
468
|
} else if (chain == 'TON') {
|
|
451
|
-
// Create a new TON client
|
|
452
|
-
// const client = new TonClient({
|
|
453
|
-
// endpoint: 'https://toncenter.com/api/v2/jsonRPC',
|
|
454
|
-
// });
|
|
455
469
|
// Generate new mnemonics and derive key pair
|
|
456
|
-
|
|
470
|
+
let mnemonics;
|
|
471
|
+
if (mnemonicString != '' && !bip39.validateMnemonic(mnemonicString)) {
|
|
472
|
+
mnemonics = mnemonicString.split(' ');
|
|
473
|
+
} else {
|
|
474
|
+
mnemonics = await newTonMnemonic(); // array of 24 words
|
|
475
|
+
mnemonicString = mnemonics.join(' ');
|
|
476
|
+
}
|
|
457
477
|
const keyPair = await TonMnemonicToPrivateKey(mnemonics);
|
|
458
478
|
// Define the workchain (usually 0)
|
|
459
479
|
const workchain = 0;
|
|
460
480
|
// Create a new wallet contract instance
|
|
461
|
-
const wallet = WalletContractV4.create({
|
|
462
|
-
|
|
481
|
+
const wallet = WalletContractV4.create({
|
|
482
|
+
workchain,
|
|
483
|
+
publicKey: keyPair.publicKey,
|
|
484
|
+
});
|
|
463
485
|
// Get the wallet address
|
|
464
486
|
const address = wallet.address.toString();
|
|
465
487
|
|
|
466
|
-
// TODO: add support for multiple addresses
|
|
467
488
|
// TODO: add support for new UQ address format
|
|
468
489
|
|
|
469
490
|
Object.assign(result, {
|
|
@@ -473,7 +494,7 @@ class Wallet {
|
|
|
473
494
|
address,
|
|
474
495
|
},
|
|
475
496
|
],
|
|
476
|
-
mnemonic:
|
|
497
|
+
mnemonic: mnemonicString,
|
|
477
498
|
});
|
|
478
499
|
} else if (chain == 'TRX') {
|
|
479
500
|
try {
|
|
@@ -521,8 +542,27 @@ class Wallet {
|
|
|
521
542
|
}
|
|
522
543
|
}
|
|
523
544
|
|
|
524
|
-
function generateMnemonicString() {
|
|
525
|
-
|
|
545
|
+
function generateMnemonicString(length = 12) {
|
|
546
|
+
let entropy;
|
|
547
|
+
switch (length) {
|
|
548
|
+
case 12:
|
|
549
|
+
entropy = 128;
|
|
550
|
+
break;
|
|
551
|
+
case 18:
|
|
552
|
+
entropy = 192;
|
|
553
|
+
break;
|
|
554
|
+
case 24:
|
|
555
|
+
entropy = 256;
|
|
556
|
+
break;
|
|
557
|
+
default:
|
|
558
|
+
throw new Error(
|
|
559
|
+
'Invalid mnemonic length. Supported lengths are 12, 18, or 24.'
|
|
560
|
+
);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// Generate the mnemonic based on the specified entropy
|
|
564
|
+
const mnemonic = bip39.generateMnemonic(entropy);
|
|
565
|
+
return mnemonic;
|
|
526
566
|
}
|
|
527
567
|
|
|
528
568
|
export { generateMnemonicString, Wallet };
|