@yerofey/cryptowallet-cli 1.18.4 → 1.19.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/Wallet.js +32 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yerofey/cryptowallet-cli",
3
- "version": "1.18.4",
3
+ "version": "1.19.0",
4
4
  "description": "Crypto wallet generator CLI tool",
5
5
  "type": "module",
6
6
  "homepage": "https://github.com/yerofey/cryptowallet-cli",
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';
@@ -25,16 +27,17 @@ import {
25
27
  import bs58 from 'bs58';
26
28
  import TonWeb from 'tonweb';
27
29
  import {
28
- mnemonicNew as newTonMnemonic,
29
30
  mnemonicToPrivateKey as TonMnemonicToPrivateKey,
31
+ mnemonicValidate as TonValidateMnemonic,
32
+ mnemonicNew as newTonMnemonic,
30
33
  } from '@ton/crypto';
31
- const { red } = chalk;
32
34
 
33
- const supportedMnemonicLengths = [12, 18, 24];
35
+ config();
34
36
 
35
37
  class Wallet {
36
38
  constructor(cw) {
37
39
  this.cw = cw;
40
+ this.supportedMnemonicLengths = [12, 18, 24];
38
41
  }
39
42
 
40
43
  async init() {
@@ -228,7 +231,7 @@ class Wallet {
228
231
  const mnemonicWordsCount = (mnemonic.split(' ') || []).length || 0;
229
232
  if (mnemonicWordsCount == 1) {
230
233
  const mnemonicInput = parseInt(mnemonic.split(' ')[0], 10);
231
- mnemonicLength = supportedMnemonicLengths.includes(mnemonicInput)
234
+ mnemonicLength = this.supportedMnemonicLengths.includes(mnemonicInput)
232
235
  ? mnemonicInput
233
236
  : 12;
234
237
  } else {
@@ -258,6 +261,7 @@ class Wallet {
258
261
  ],
259
262
  });
260
263
  } else if (chain == 'BTC') {
264
+ // Validate mnemonic
261
265
  if (mnemonicString != '' && !bip39.validateMnemonic(mnemonicString)) {
262
266
  return {
263
267
  error: 'mnemonic is not valid',
@@ -287,6 +291,7 @@ class Wallet {
287
291
  mnemonic,
288
292
  });
289
293
  } else if (chain == 'DOGE' || chain == 'LTC') {
294
+ // Validate mnemonic
290
295
  if (mnemonicString != '' && !bip39.validateMnemonic(mnemonicString)) {
291
296
  return {
292
297
  error: 'mnemonic is not valid',
@@ -319,6 +324,7 @@ class Wallet {
319
324
  mnemonic,
320
325
  });
321
326
  } else if (row.format == 'BEP2') {
327
+ // Validate mnemonic
322
328
  if (mnemonicString != '' && !bip39.validateMnemonic(mnemonicString)) {
323
329
  return {
324
330
  error: 'mnemonic is not valid',
@@ -356,6 +362,7 @@ class Wallet {
356
362
  mnemonic,
357
363
  });
358
364
  } else if (row.network == 'EVM') {
365
+ // Validate mnemonic
359
366
  if (mnemonicString != '' && !bip39.validateMnemonic(mnemonicString)) {
360
367
  return {
361
368
  error: 'mnemonic is not valid',
@@ -397,6 +404,7 @@ class Wallet {
397
404
  mnemonic,
398
405
  });
399
406
  } else if (chain == 'ONE') {
407
+ // Validate mnemonic
400
408
  if (mnemonicString != '' && !bip39.validateMnemonic(mnemonicString)) {
401
409
  return {
402
410
  error: 'mnemonic is not valid',
@@ -420,6 +428,7 @@ class Wallet {
420
428
  mnemonic,
421
429
  });
422
430
  } else if (chain == 'SOL') {
431
+ // TODO: generate wallet from mnemonic
423
432
  const wallet = SolanaKeypair.generate();
424
433
  const publicKeyString = new SolanaPublickey(wallet.publicKey).toBase58();
425
434
  const secretKeyString = bs58.encode(wallet.secretKey);
@@ -436,17 +445,28 @@ class Wallet {
436
445
  ],
437
446
  });
438
447
  } else if (chain == 'TON') {
448
+ // Validate mnemonic
449
+ if (
450
+ mnemonicString != '' &&
451
+ !(await TonValidateMnemonic(mnemonicString.split(' ')))
452
+ ) {
453
+ return {
454
+ error: 'mnemonic is not valid',
455
+ };
456
+ }
439
457
  // Generate new mnemonics and derive key pair
440
458
  let mnemonics;
441
- if (mnemonicString != '' && !bip39.validateMnemonic(mnemonicString)) {
442
- mnemonics = mnemonicString.split(' ');
459
+ if (mnemonicString != '') {
460
+ mnemonics = mnemonicString.split(' '); // array of 24 words
443
461
  } else {
444
462
  mnemonics = await newTonMnemonic(); // array of 24 words
445
463
  mnemonicString = mnemonics.join(' ');
446
464
  }
447
465
  const keyPair = await TonMnemonicToPrivateKey(mnemonics);
448
466
  const tonweb = new TonWeb();
449
- const wallet = tonweb.wallet.create({ publicKey: keyPair.publicKey });
467
+ // TODO: add support for different formats (simpleR1, simpleR2, simpleR3, v2R1, v2R2, v3R1, v3R2, v4R1, v4R2)
468
+ const WalletClass = tonweb.wallet.all.v4R2;
469
+ const wallet = new WalletClass(tonweb.provider, keyPair);
450
470
  const address = await wallet.getAddress();
451
471
  const nonBounceableAddress = address.toString(true, true, false);
452
472
  const bouncableAddress = address.toString(true, true, true);
@@ -465,6 +485,7 @@ class Wallet {
465
485
  mnemonic: mnemonicString,
466
486
  });
467
487
  } else if (chain == 'TRX') {
488
+ // TODO: generate wallet from mnemonic
468
489
  try {
469
490
  const wallet = await tronWeb.createAccount();
470
491
 
@@ -483,6 +504,7 @@ class Wallet {
483
504
  };
484
505
  }
485
506
  } else if (chain == 'XTZ') {
507
+ // TODO: generate wallet from mnemonic
486
508
  const wallet = tezos.generateKeysNoSeed();
487
509
 
488
510
  Object.assign(result, {
@@ -496,10 +518,12 @@ class Wallet {
496
518
  });
497
519
  } else {
498
520
  return {
499
- error: 'your desired blockchain is not supported yet',
521
+ error:
522
+ 'your desired blockchain is not supported yet, please open an issue on GitHub: https://github.com/yerofey/cryptowallet-cli/issues',
500
523
  };
501
524
  }
502
525
 
526
+ // Add not tested flag if needed
503
527
  if (row.tested !== undefined && row.tested == false) {
504
528
  Object.assign(result, {
505
529
  tested: false,