@yerofey/cryptowallet-cli 1.18.4 → 1.20.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/package.json +2 -1
- package/src/Wallet.js +48 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yerofey/cryptowallet-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.0",
|
|
4
4
|
"description": "Crypto wallet generator CLI tool",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"homepage": "https://github.com/yerofey/cryptowallet-cli",
|
|
@@ -120,6 +120,7 @@
|
|
|
120
120
|
"commander": "11.1.0",
|
|
121
121
|
"csv-writer": "^1.6.0",
|
|
122
122
|
"dotenv": "^16.4.1",
|
|
123
|
+
"ed25519-hd-key": "^1.3.0",
|
|
123
124
|
"eth-lib": "0.1.29",
|
|
124
125
|
"ethereum-bip84": "0.0.3",
|
|
125
126
|
"ethereum-mnemonic-privatekey-utils": "1.0.5",
|
package/src/Wallet.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { config } from 'dotenv';
|
|
1
2
|
import { log } from './utils.js';
|
|
2
3
|
import chalk from 'chalk';
|
|
4
|
+
const { red } = chalk;
|
|
3
5
|
import CoinKey from 'coinkey';
|
|
4
6
|
import CoinInfo from 'coininfo';
|
|
5
7
|
import bip39 from 'bip39';
|
|
@@ -22,19 +24,21 @@ import {
|
|
|
22
24
|
Keypair as SolanaKeypair,
|
|
23
25
|
PublicKey as SolanaPublickey,
|
|
24
26
|
} from '@solana/web3.js';
|
|
27
|
+
import { derivePath } from 'ed25519-hd-key';
|
|
25
28
|
import bs58 from 'bs58';
|
|
26
29
|
import TonWeb from 'tonweb';
|
|
27
30
|
import {
|
|
28
|
-
mnemonicNew as newTonMnemonic,
|
|
29
31
|
mnemonicToPrivateKey as TonMnemonicToPrivateKey,
|
|
32
|
+
mnemonicValidate as TonValidateMnemonic,
|
|
33
|
+
mnemonicNew as newTonMnemonic,
|
|
30
34
|
} from '@ton/crypto';
|
|
31
|
-
const { red } = chalk;
|
|
32
35
|
|
|
33
|
-
|
|
36
|
+
config();
|
|
34
37
|
|
|
35
38
|
class Wallet {
|
|
36
39
|
constructor(cw) {
|
|
37
40
|
this.cw = cw;
|
|
41
|
+
this.supportedMnemonicLengths = [12, 18, 24];
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
async init() {
|
|
@@ -228,7 +232,7 @@ class Wallet {
|
|
|
228
232
|
const mnemonicWordsCount = (mnemonic.split(' ') || []).length || 0;
|
|
229
233
|
if (mnemonicWordsCount == 1) {
|
|
230
234
|
const mnemonicInput = parseInt(mnemonic.split(' ')[0], 10);
|
|
231
|
-
mnemonicLength = supportedMnemonicLengths.includes(mnemonicInput)
|
|
235
|
+
mnemonicLength = this.supportedMnemonicLengths.includes(mnemonicInput)
|
|
232
236
|
? mnemonicInput
|
|
233
237
|
: 12;
|
|
234
238
|
} else {
|
|
@@ -258,6 +262,7 @@ class Wallet {
|
|
|
258
262
|
],
|
|
259
263
|
});
|
|
260
264
|
} else if (chain == 'BTC') {
|
|
265
|
+
// Validate mnemonic
|
|
261
266
|
if (mnemonicString != '' && !bip39.validateMnemonic(mnemonicString)) {
|
|
262
267
|
return {
|
|
263
268
|
error: 'mnemonic is not valid',
|
|
@@ -287,6 +292,7 @@ class Wallet {
|
|
|
287
292
|
mnemonic,
|
|
288
293
|
});
|
|
289
294
|
} else if (chain == 'DOGE' || chain == 'LTC') {
|
|
295
|
+
// Validate mnemonic
|
|
290
296
|
if (mnemonicString != '' && !bip39.validateMnemonic(mnemonicString)) {
|
|
291
297
|
return {
|
|
292
298
|
error: 'mnemonic is not valid',
|
|
@@ -319,6 +325,7 @@ class Wallet {
|
|
|
319
325
|
mnemonic,
|
|
320
326
|
});
|
|
321
327
|
} else if (row.format == 'BEP2') {
|
|
328
|
+
// Validate mnemonic
|
|
322
329
|
if (mnemonicString != '' && !bip39.validateMnemonic(mnemonicString)) {
|
|
323
330
|
return {
|
|
324
331
|
error: 'mnemonic is not valid',
|
|
@@ -356,6 +363,7 @@ class Wallet {
|
|
|
356
363
|
mnemonic,
|
|
357
364
|
});
|
|
358
365
|
} else if (row.network == 'EVM') {
|
|
366
|
+
// Validate mnemonic
|
|
359
367
|
if (mnemonicString != '' && !bip39.validateMnemonic(mnemonicString)) {
|
|
360
368
|
return {
|
|
361
369
|
error: 'mnemonic is not valid',
|
|
@@ -397,6 +405,7 @@ class Wallet {
|
|
|
397
405
|
mnemonic,
|
|
398
406
|
});
|
|
399
407
|
} else if (chain == 'ONE') {
|
|
408
|
+
// Validate mnemonic
|
|
400
409
|
if (mnemonicString != '' && !bip39.validateMnemonic(mnemonicString)) {
|
|
401
410
|
return {
|
|
402
411
|
error: 'mnemonic is not valid',
|
|
@@ -420,9 +429,21 @@ class Wallet {
|
|
|
420
429
|
mnemonic,
|
|
421
430
|
});
|
|
422
431
|
} else if (chain == 'SOL') {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
432
|
+
// Validate mnemonic
|
|
433
|
+
if (mnemonicString != '' && !bip39.validateMnemonic(mnemonicString)) {
|
|
434
|
+
return {
|
|
435
|
+
error: 'mnemonic is not valid',
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const mnemonic = mnemonicString || generateMnemonicString(24);
|
|
440
|
+
const seed = await bip39.mnemonicToSeed(mnemonic);
|
|
441
|
+
const derivationPath = "m/44'/501'/0'/0'";
|
|
442
|
+
const derivedSeed = derivePath(derivationPath, seed.toString('hex')).key;
|
|
443
|
+
const keypair = SolanaKeypair.fromSeed(derivedSeed);
|
|
444
|
+
const publicKey = new SolanaPublickey(keypair.publicKey);
|
|
445
|
+
const publicKeyString = publicKey.toString();
|
|
446
|
+
const secretKeyString = bs58.encode(keypair.secretKey);
|
|
426
447
|
|
|
427
448
|
// TODO: add support for multiple addresses
|
|
428
449
|
|
|
@@ -434,19 +455,31 @@ class Wallet {
|
|
|
434
455
|
privateKey: secretKeyString,
|
|
435
456
|
},
|
|
436
457
|
],
|
|
458
|
+
mnemonic,
|
|
437
459
|
});
|
|
438
460
|
} else if (chain == 'TON') {
|
|
461
|
+
// Validate mnemonic
|
|
462
|
+
if (
|
|
463
|
+
mnemonicString != '' &&
|
|
464
|
+
!(await TonValidateMnemonic(mnemonicString.split(' ')))
|
|
465
|
+
) {
|
|
466
|
+
return {
|
|
467
|
+
error: 'mnemonic is not valid',
|
|
468
|
+
};
|
|
469
|
+
}
|
|
439
470
|
// Generate new mnemonics and derive key pair
|
|
440
471
|
let mnemonics;
|
|
441
|
-
if (mnemonicString != ''
|
|
442
|
-
mnemonics = mnemonicString.split(' ');
|
|
472
|
+
if (mnemonicString != '') {
|
|
473
|
+
mnemonics = mnemonicString.split(' '); // array of 24 words
|
|
443
474
|
} else {
|
|
444
475
|
mnemonics = await newTonMnemonic(); // array of 24 words
|
|
445
476
|
mnemonicString = mnemonics.join(' ');
|
|
446
477
|
}
|
|
447
478
|
const keyPair = await TonMnemonicToPrivateKey(mnemonics);
|
|
448
479
|
const tonweb = new TonWeb();
|
|
449
|
-
|
|
480
|
+
// TODO: add support for different formats (simpleR1, simpleR2, simpleR3, v2R1, v2R2, v3R1, v3R2, v4R1, v4R2)
|
|
481
|
+
const WalletClass = tonweb.wallet.all.v4R2;
|
|
482
|
+
const wallet = new WalletClass(tonweb.provider, keyPair);
|
|
450
483
|
const address = await wallet.getAddress();
|
|
451
484
|
const nonBounceableAddress = address.toString(true, true, false);
|
|
452
485
|
const bouncableAddress = address.toString(true, true, true);
|
|
@@ -465,6 +498,7 @@ class Wallet {
|
|
|
465
498
|
mnemonic: mnemonicString,
|
|
466
499
|
});
|
|
467
500
|
} else if (chain == 'TRX') {
|
|
501
|
+
// TODO: generate wallet from mnemonic
|
|
468
502
|
try {
|
|
469
503
|
const wallet = await tronWeb.createAccount();
|
|
470
504
|
|
|
@@ -483,6 +517,7 @@ class Wallet {
|
|
|
483
517
|
};
|
|
484
518
|
}
|
|
485
519
|
} else if (chain == 'XTZ') {
|
|
520
|
+
// TODO: generate wallet from mnemonic
|
|
486
521
|
const wallet = tezos.generateKeysNoSeed();
|
|
487
522
|
|
|
488
523
|
Object.assign(result, {
|
|
@@ -496,10 +531,12 @@ class Wallet {
|
|
|
496
531
|
});
|
|
497
532
|
} else {
|
|
498
533
|
return {
|
|
499
|
-
error:
|
|
534
|
+
error:
|
|
535
|
+
'your desired blockchain is not supported yet, please open an issue on GitHub: https://github.com/yerofey/cryptowallet-cli/issues',
|
|
500
536
|
};
|
|
501
537
|
}
|
|
502
538
|
|
|
539
|
+
// Add not tested flag if needed
|
|
503
540
|
if (row.tested !== undefined && row.tested == false) {
|
|
504
541
|
Object.assign(result, {
|
|
505
542
|
tested: false,
|