Skip to content

Commit

Permalink
feat: Update version to 1.35.0 and add ethereum-cryptography dependen…
Browse files Browse the repository at this point in the history
…cy; enhance TRX wallet generation with mnemonic validation
  • Loading branch information
yerofey committed Jan 9, 2025
1 parent 9864456 commit e2d9112
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 8 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yerofey/cryptowallet-cli",
"version": "1.34.2",
"version": "1.35.0",
"description": "Crypto wallet generator CLI tool",
"type": "module",
"homepage": "https://github.com/yerofey/cryptowallet-cli",
Expand Down Expand Up @@ -131,6 +131,7 @@
"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",
"tezos-sign": "1.4.1",
"tonweb": "^0.0.66",
Expand Down
61 changes: 59 additions & 2 deletions pnpm-lock.yaml

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

19 changes: 15 additions & 4 deletions src/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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 @@ -614,22 +615,32 @@ class Wallet {
mnemonic: mnemonicString,
});
} else if (chain == 'TRX') {
// TODO: generate wallet from mnemonic
try {
const wallet = await tronWeb.createAccount();
// Validate mnemonic
if (mnemonicString !== '' && !bip39.validateMnemonic(mnemonicString)) {
return {
error: 'mnemonic is not valid',
};
}

// Generate mnemonic if not provided
const mnemonic = mnemonicString || bip39.generateMnemonic();
// Generate Tron address from private key
const wallet = tronWeb.utils.accounts.generateAccountWithMnemonic(mnemonic);

Object.assign(result, {
addresses: [
{
index: 0,
address: wallet.address.base58,
address: wallet.address,
privateKey: wallet.privateKey,
},
],
mnemonic,
});
} catch (error) {
return {
error,
error: `Failed to generate TRX wallet: ${error.message} (${error})`,
};
}
} else if (chain == 'XTZ') {
Expand Down
2 changes: 1 addition & 1 deletion src/chains/TRX.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"prefixTest": "(?![0OI])[1-9a-zA-Z]",
"rareSymbols": "[1-9a-z]",
"apps": ["tronlink", "trustwallet"],
"flags": ["p", "s"]
"flags": ["m", "p", "s"]
}

0 comments on commit e2d9112

Please sign in to comment.