diff --git a/.nvmrc b/.nvmrc index d4b25d0..bd0878c 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -16.16 +20.5 diff --git a/README.md b/README.md index 043ac6a..914f7ac 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,7 @@ $ cw -l - [ ] v17.x ā›” - [x] v18.x āœ… - [x] v19.x āœ… +- [x] v20.x āœ… *tested on Mac M1* diff --git a/cli.js b/cli.js index 73ff825..9872ec8 100644 --- a/cli.js +++ b/cli.js @@ -1,52 +1,12 @@ #!/usr/bin/env node 'use strict'; -import { program } from 'commander'; import chalk from 'chalk'; +import { options } from './src/options.js'; import { log, supportedChains } from './src/utils.js'; import Method from './src/Method.js'; -program.option('-b, --chain ', 'Wallet for specific blockchain', 'ERC'); -program.option('-c, --chain ', 'Wallet for specific blockchain', 'ERC'); -program.option( - '-D, --csv [filename]', - 'Save result into CSV file' -); -program.option( - '-f, --format ', - 'Wallet format type (for cryptos with multiple wallet formats)' -); -program.option( - '-F, --filename ', - 'Filename to output the data (works with -o argument)' -); -program.option('-g, --geek', 'Display some more info (geeky)'); -program.option('-l, --list', 'List all supported cryptos'); -program.option( - '-m, --mnemonic [mnemonic]', - 'Generate wallet from mnemonic string OR just a mnemonic string' -); -program.option( - '-n, --number ', - 'Number of wallets to generate (if supported)' -); -program.option('-o, --output ', 'Return results into some file'); -program.option('-p, --prefix ', 'Desired wallet prefix'); -program.option( - '-P, --prefix-sensitive ', - 'Desired wallet prefix (case-sensitive)' -); -program.option('-s, --suffix ', 'Desired wallet suffix'); -program.option( - '-S, --suffix-sensitive ', - 'Desired wallet suffix (case-sensitive)' -); -program.option('-v, --version', 'Display cryptowallet version'); -program.parse(); - (async () => { - const options = program.opts(); - if (options.list !== undefined) { return new Method('list').init(); } diff --git a/package.json b/package.json index 43d1acf..80c2d01 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@yerofey/cryptowallet-cli", - "version": "1.9.0", + "version": "1.10.0", "description": "Crypto wallet generator CLI tool", "type": "module", "homepage": "https://github.com/yerofey/cryptowallet-cli", diff --git a/src/CW.js b/src/CW.js index 0e90950..54732f0 100644 --- a/src/CW.js +++ b/src/CW.js @@ -3,11 +3,17 @@ import { Wallet } from './Wallet.js'; class CW { constructor(chain, options = {}) { + this.chain = chain; + this.options = this._prepareOptions(chain, options); + } + + _prepareOptions(chain, options) { const csvFilename = 'cw-output'; + if (options.csv !== undefined) { options.output = 'csv'; - if (typeof options.csv === 'string' && (options.csv).length > 0) { + if (typeof options.csv === 'string' && options.csv.length > 0) { options.filename = options.csv; } } @@ -26,15 +32,7 @@ class CW { suffixIsCaseSensitive: options.suffixSensitive !== undefined, }; - for (const key of Object.keys(defaultValues)) { - // eslint-disable-next-line no-prototype-builtins - if (!options.hasOwnProperty(key)) { - options[key] = defaultValues[key]; - } - } - - this.chain = chain; - this.options = options; + return { ...defaultValues, ...options }; } async init() { @@ -42,10 +40,7 @@ class CW { this.row = chainData.row || {}; const w = await new Wallet(this).init(); - - for (const key of Object.keys(w)) { - this[key] = w[key]; - } + Object.assign(this, w); return this; } diff --git a/src/Chain.js b/src/Chain.js index 87d48e8..38e7b94 100644 --- a/src/Chain.js +++ b/src/Chain.js @@ -2,38 +2,43 @@ import path from 'node:path'; import { loadJson } from './utils.js'; class Chain { - constructor(chain, format) { + constructor(chain, format = '') { this.chain = chain; this.format = format; + this.row = null; } async init() { - // eslint-disable-next-line no-undef - const content = await loadJson(`${path.dirname(import.meta.url)}/chains/${this.chain}.json`.replace('file://', '')); - const data = (() => { - if (content.formats !== undefined) { - if (this.format != '' && this.format != content.defaultFormat) { - // case-insensitive format - for (const key of Object.keys(content.formats)) { - if (this.format.toLowerCase() == key.toLowerCase()) { - return content.formats[key]; - } - } - } - - return content.formats[content.defaultFormat]; - } - - return content; - })(); - - this.row = { - ...content, - ...data, - }; - + const content = await this._loadChainJson(); + this.row = this._parseContent(content); return this; } + + async _loadChainJson() { + const filePath = `${path.dirname(import.meta.url)}/chains/${ + this.chain + }.json`.replace('file://', ''); + return await loadJson(filePath); + } + + _parseContent(content) { + if (!content.formats) return content; + + const formatKey = this._findFormatKey(content); + return { ...content, ...content.formats[formatKey] }; + } + + _findFormatKey(content) { + if (!this.format || this.format === content.defaultFormat) + return content.defaultFormat; + + const normalizedFormat = this.format.toLowerCase(); + const matchingKey = Object.keys(content.formats).find( + (key) => key.toLowerCase() === normalizedFormat + ); + + return matchingKey || content.defaultFormat; + } } export default Chain; diff --git a/src/Method.js b/src/Method.js index cf77eeb..fd7103b 100644 --- a/src/Method.js +++ b/src/Method.js @@ -1,5 +1,11 @@ import path from 'node:path'; import chalk from 'chalk'; +import columnify from 'columnify'; +import CsvWriter from 'csv-writer'; +import { log, supportedChains, loadJson } from './utils.js'; +import { generateMnemonicString } from './Wallet.js'; +import CW from './CW.js'; + const { blue, green, @@ -10,366 +16,372 @@ const { magenta, white, } = chalk; -import columnify from 'columnify'; -import CsvWriter from 'csv-writer'; -import { - log, - supportedChains, - loadJson, -} from './utils.js'; -import { generateMnemonicString } from './Wallet.js'; -import CW from './CW.js'; -const pkg = await loadJson(`${path.dirname(import.meta.url)}/../package.json`.replace('file://', '')); -// eslint-disable-next-line no-undef + +const pkg = await loadJson( + `${path.dirname(import.meta.url)}/../package.json`.replace('file://', '') +); const _version = pkg['version'] || 0; class Method { constructor(name, params = {}) { this.name = name; this.params = params; + this.callMethods = this._initializeMethods(); } - async init() { - const callMethod = { + _initializeMethods() { + return { _: () => {}, - list: async () => { - log(`šŸ”  All supported blockchains:\n`); - let cryptos = {}; - for (const val of supportedChains) { - // eslint-disable-next-line no-undef - const data = await loadJson(`${path.dirname(import.meta.url)}/chains/${val}.json`.replace('file://', '')); + list: this._list.bind(this), + mnemonic: this._mnemonic.bind(this), + version: this._version.bind(this), + wallet: this._wallet.bind(this), + }; + } - let title = data.title || ''; - if (title == '' || val == 'ERC') { - continue; - } - cryptos[blue(val)] = title; - } + async _list() { + log(`šŸ”  All supported blockchains:\n`); + let cryptos = {}; + for (const val of supportedChains) { + // eslint-disable-next-line no-undef + const data = await loadJson( + `${path.dirname(import.meta.url)}/chains/${val}.json`.replace( + 'file://', + '' + ) + ); + + let title = data.title || ''; + if (title == '' || val == 'ERC') { + continue; + } + cryptos[blue(val)] = title; + } + log( + columnify(cryptos, { + showHeaders: false, + columnSplitter: ' - ', + }) + ); + log(); + log(`ā„¹ļø Use flag "-c TICKER" to select specific blockchain`); + } + + _mnemonic() { + log( + `āœØ ${green('Done!')} ${blueBright( + 'Here is your randomly generated 12 words mnemonic string:' + )}\n` + ); + log(`šŸ“„ ${generateMnemonicString()}`); + log(); + log( + greenBright( + 'ā„¹ļø You can import this wallet into MetaMask, Trust Wallet and many other wallet apps' + ) + ); + } + + _version() { + log(_version); + } + + async _wallet() { + const chain = this.params.chain; + const options = this.params.options; + + const cw = await new CW(chain, options).init(); + + let chainFullName = + (cw.row.name || chain) + + (cw.wallet.format !== undefined && cw.wallet.format != '' + ? ' (' + cw.wallet.format + ')' + : ''); + + if (cw.options.prefix && !cw.prefixFound) { + log( + `šŸ˜¢ ${yellow( + 'Sorry, ' + chainFullName + ' does not support prefix yet...' + )}` + ); + } + + if (cw.options.suffix && !cw.suffixFound) { + log( + `šŸ˜¢ ${yellow( + 'Sorry, ' + chainFullName + ' does not support suffix yet...' + )}` + ); + } + + if (cw.options.mnemonic != '' && cw.wallet.mnemonic == undefined) { + log( + `šŸ˜¢ ${yellow( + 'Sorry, ' + chainFullName + ' does not support mnemonic yet...' + )}` + ); + } + + if (cw.wallet.error !== undefined) { + log(`ā›”ļø ${red(`Error: ${cw.wallet.error}`)}`); + return; + } + + let linesCount = 0; + const outputFormats = ['csv']; + const displayAsText = + cw.options.output === undefined || + !outputFormats.includes(cw.options.output); + + // prefix, suffix + if (displayAsText) { + if (cw.prefixFound && cw.suffixFound) { log( - columnify(cryptos, { - showHeaders: false, - columnSplitter: ' - ', - }) + `āœØ ${green('Done!')} ${blueBright( + 'Here is your brand new ' + + chainFullName + + ' wallet with "' + + cw.options.prefix + + '" prefix and "' + + cw.options.suffix + + '" suffix:' + )}\n` ); - log(); - log(`ā„¹ļø Use flag "-c TICKER" to select specific blockchain`); - }, - mnemonic: () => { + } else if (cw.prefixFound) { log( `āœØ ${green('Done!')} ${blueBright( - 'Here is your randomly generated 12 words mnemonic string:' + 'Here is your brand new ' + + chainFullName + + ' wallet with "' + + cw.options.prefix + + '" prefix:' )}\n` ); - log(`šŸ“„ ${generateMnemonicString()}`); - log(); + } else if (cw.suffixFound) { log( - greenBright( - 'ā„¹ļø You can import this wallet into MetaMask, Trust Wallet and many other wallet apps' - ) + `āœØ ${green('Done!')} ${blueBright( + 'Here is your brand new ' + + chainFullName + + ' wallet with "' + + cw.options.suffix + + '" suffix:' + )}\n` ); - }, - version: () => { - log(_version); - }, - wallet: async () => { - const chain = this.params.chain; - const options = this.params.options; - - const cw = await new CW(chain, options).init(); - - let chainFullName = - (cw.row.name || chain) + - (cw.wallet.format !== undefined && cw.wallet.format != '' - ? ' (' + cw.wallet.format + ')' - : ''); - - if (cw.options.prefix && !cw.prefixFound) { - log( - `šŸ˜¢ ${yellow( - 'Sorry, ' + chainFullName + ' does not support prefix yet...' - )}` - ); - } - - if (cw.options.suffix && !cw.suffixFound) { - log( - `šŸ˜¢ ${yellow( - 'Sorry, ' + chainFullName + ' does not support suffix yet...' - )}` - ); - } - - if (cw.options.mnemonic != '' && cw.wallet.mnemonic == undefined) { - log( - `šŸ˜¢ ${yellow( - 'Sorry, ' + chainFullName + ' does not support mnemonic yet...' - )}` - ); - } - - if (cw.wallet.error !== undefined) { - log(`ā›”ļø ${red(`Error: ${cw.wallet.error}`)}`); - return; - } + } else { + log( + `āœØ ${green('Done!')} ${blueBright( + 'Here is your brand new ' + chainFullName + ' wallet:' + )}\n` + ); + } + linesCount += 1; + } - let linesCount = 0; - const outputFormats = ['csv']; - const displayAsText = - cw.options.output === undefined || - !outputFormats.includes(cw.options.output); + // result + let outputData = {}; + if (cw.wallet.addresses !== undefined) { + // private key + if (cw.wallet.privateExtendedKey && cw.options.geek) { + log(`šŸ” ${cw.wallet.privateExtendedKey}`); + linesCount += 1; + } + // mnemonic + if (cw.wallet.mnemonic) { + log(`šŸ“„ ${cw.wallet.mnemonic}`); + linesCount += 1; + } + // addresses + if (displayAsText) { + for (const item of cw.wallet.addresses) { + if (cw.wallet.addresses.length > 1) { + log(); + log(`šŸ†” ${item.index}`); + } - // prefix, suffix - if (displayAsText) { - if (cw.prefixFound && cw.suffixFound) { - log( - `āœØ ${green('Done!')} ${blueBright( - 'Here is your brand new ' + - chainFullName + - ' wallet with "' + - cw.options.prefix + - '" prefix and "' + - cw.options.suffix + - '" suffix:' - )}\n` + if ( + cw.prefixFound && + cw.prefixFoundInWallets.includes(item.address) && + cw.suffixFound && + cw.suffixFoundInWallets.includes(item.address) + ) { + // highlight found prefix + const addressCutPrefixLength = + cw.row.startsWith.length + cw.options.prefix.length; + const addressFirstPart = item.address.slice( + cw.row.startsWith.length, + addressCutPrefixLength + ); + const addressLastPart = item.address.slice( + item.address.length - cw.options.suffix.length ); - } else if (cw.prefixFound) { log( - `āœØ ${green('Done!')} ${blueBright( - 'Here is your brand new ' + - chainFullName + - ' wallet with "' + - cw.options.prefix + - '" prefix:' - )}\n` + `šŸ‘› ${cw.row.startsWith}${magenta( + addressFirstPart + )}${item.address.substring( + cw.row.startsWith.length + addressFirstPart.length, + item.address.length - addressLastPart.length + )}${magenta(addressLastPart)}` ); - } else if (cw.suffixFound) { + } else if ( + cw.prefixFound && + cw.prefixFoundInWallets.includes(item.address) + ) { + // highlight found prefix + const addressCutLength = + cw.row.startsWith.length + cw.options.prefix.length; log( - `āœØ ${green('Done!')} ${blueBright( - 'Here is your brand new ' + - chainFullName + - ' wallet with "' + - cw.options.suffix + - '" suffix:' - )}\n` + `šŸ‘› ${cw.row.startsWith}${magenta( + item.address.slice(cw.row.startsWith.length, addressCutLength) + )}${item.address.slice(addressCutLength)}` ); - } else { + } else if ( + cw.suffixFound && + cw.suffixFoundInWallets.includes(item.address) + ) { + // highlight found suffix log( - `āœØ ${green('Done!')} ${blueBright( - 'Here is your brand new ' + chainFullName + ' wallet:' - )}\n` + `šŸ‘› ${item.address.slice( + 0, + item.address.length - cw.options.suffix.length + )}${magenta( + item.address.slice( + item.address.length - cw.options.suffix.length + ) + )}` ); + } else { + log(`šŸ‘› ${item.address}`); } - linesCount += 1; + log(`šŸ”‘ ${item.privateKey}`); } + } else { + outputData.wallets = cw.wallet.addresses; + } - // result - let outputData = {}; - if (cw.wallet.addresses !== undefined) { - // private key - if (cw.wallet.privateExtendedKey && cw.options.geek) { - log(`šŸ” ${cw.wallet.privateExtendedKey}`); - linesCount += 1; - } - // mnemonic - if (cw.wallet.mnemonic) { - log(`šŸ“„ ${cw.wallet.mnemonic}`); - linesCount += 1; - } - // addresses - if (displayAsText) { - for (const item of cw.wallet.addresses) { - if (cw.wallet.addresses.length > 1) { - log(); - log(`šŸ†” ${item.index}`); - } + if (displayAsText && cw.row.path !== undefined && cw.options.geek) { + log(); + log(`šŸ—‚ wallet address path: ${cw.row.path}'/0'/0/ID`); + linesCount += 1; + } - if ( - cw.prefixFound && - cw.prefixFoundInWallets.includes(item.address) && - cw.suffixFound && - cw.suffixFoundInWallets.includes(item.address) - ) { - // highlight found prefix - const addressCutPrefixLength = - cw.row.startsWith.length + cw.options.prefix.length; - const addressFirstPart = item.address.slice( - cw.row.startsWith.length, - addressCutPrefixLength - ); - const addressLastPart = item.address.slice( - item.address.length - cw.options.suffix.length - ); - log( - `šŸ‘› ${cw.row.startsWith}${magenta( - addressFirstPart - )}${item.address.substring( - cw.row.startsWith.length + addressFirstPart.length, - item.address.length - addressLastPart.length - )}${magenta(addressLastPart)}` - ); - } else if ( - cw.prefixFound && - cw.prefixFoundInWallets.includes(item.address) - ) { - // highlight found prefix - const addressCutLength = - cw.row.startsWith.length + cw.options.prefix.length; - log( - `šŸ‘› ${cw.row.startsWith}${magenta( - item.address.slice( - cw.row.startsWith.length, - addressCutLength - ) - )}${item.address.slice(addressCutLength)}` - ); - } else if ( - cw.suffixFound && - cw.suffixFoundInWallets.includes(item.address) - ) { - // highlight found suffix - log( - `šŸ‘› ${item.address.slice( - 0, - item.address.length - cw.options.suffix.length - )}${magenta( - item.address.slice( - item.address.length - cw.options.suffix.length - ) - )}` - ); - } else { - log(`šŸ‘› ${item.address}`); - } - log(`šŸ”‘ ${item.privateKey}`); + // generate csv + if (!displayAsText) { + const filename = + cw.options.csvOutputFilename || + cw.options.filename.split('.')[0] || + 'cw-output'; + // eslint-disable-next-line no-undef + const createCsvWriter = CsvWriter.createObjectCsvWriter; + const csvWriter = createCsvWriter({ + path: `${filename}.csv`, + header: [ + { + id: 'index', + title: 'index', + }, + { + id: 'address', + title: 'address', + }, + { + id: 'privateKey', + title: 'privateKey', + }, + ], + }); + csvWriter + .writeRecords(outputData.wallets) + .then(() => + log( + `${linesCount > 0 ? '\n' : ''}šŸŸ  ${yellow( + `Don't forget to save the data above manually, because it is not in the output file` + )} \nāœØ ${green('Done!')} ${blueBright( + `The output successfully saved into "./${filename}.csv" file` + )}` + ) + ) + .catch(() => + log( + `${linesCount > 0 ? '\n' : ''}ā›”ļø ${red( + `Error: failed to generate a file` + )}` + ) + ); + } + } - } - } else { - outputData.wallets = cw.wallet.addresses; - } + if (displayAsText) { + if ( + cw.row.formats !== undefined || + cw.row.network == 'EVM' || + cw.row.apps || + cw.wallet.tested !== undefined + ) { + log(); + } - if (displayAsText && cw.row.path !== undefined && cw.options.geek) { - log(); - log(`šŸ—‚ wallet address path: ${cw.row.path}'/0'/0/ID`); - linesCount += 1; - } + if (cw.wallet.tested !== undefined) { + log( + red( + 'ā€¼ļø This wallet generation format was not tested yet, do not use it!' + ) + ); + } - // generate csv - if (!displayAsText) { - const filename = cw.options.csvOutputFilename || cw.options.filename.split('.')[0] || 'cw-output'; - // eslint-disable-next-line no-undef - const createCsvWriter = CsvWriter.createObjectCsvWriter; - const csvWriter = createCsvWriter({ - path: `${filename}.csv`, - header: [ - { - id: 'index', - title: 'index', - }, - { - id: 'address', - title: 'address', - }, - { - id: 'privateKey', - title: 'privateKey', - }, - ], - }); - csvWriter - .writeRecords(outputData.wallets) - .then(() => - log( - `${linesCount > 0 ? '\n' : ''}šŸŸ  ${yellow( - `Don't forget to save the data above manually, because it is not in the output file` - )} \nāœØ ${green('Done!')} ${blueBright( - `The output successfully saved into "./${filename}.csv" file` - )}` - ) - ) - .catch(() => - log( - `${linesCount > 0 ? '\n' : ''}ā›”ļø ${red( - `Error: failed to generate a file` - )}` - ) - ); - } + if ( + cw.row.formats !== undefined && + Object.keys(cw.row.formats).length > 1 + ) { + let formatsString = ''; + for (const val of Object.keys(cw.row.formats)) { + formatsString += blue(val) + ', '; } + log( + yellow( + '*ļøāƒ£ You can create different wallet formats: ' + + formatsString.substring(0, formatsString.length - 2) + + ' (use it with ' + + white('-f') + + ' flag)' + ) + ); + } - if (displayAsText) { - if ( - cw.row.formats !== undefined || - cw.row.network == 'EVM' || - cw.row.apps || - cw.wallet.tested !== undefined - ) { - log(); - } - - if (cw.wallet.tested !== undefined) { - log( - red( - 'ā€¼ļø This wallet generation format was not tested yet, do not use it!' - ) - ); - } + if (cw.row.network == 'EVM' || false) { + log( + yellow( + 'šŸ†’ You can use this wallet in Ethereum, Binance Smart Chain, Polygon and few more networks (EVM compatible)' + ) + ); + } - if ( - cw.row.formats !== undefined && - Object.keys(cw.row.formats).length > 1 - ) { - let formatsString = ''; - for (const val of Object.keys(cw.row.formats)) { - formatsString += blue(val) + ', '; - } - log( - yellow( - '*ļøāƒ£ You can create different wallet formats: ' + - formatsString.substring(0, formatsString.length - 2) + - ' (use it with ' + - white('-f') + - ' flag)' - ) - ); - } + if (cw.row.apps !== undefined) { + let apps = { + metamask: 'MetaMask', + tronlink: 'TronLink', + trustwallet: 'Trust Wallet', + 'harmony-chrome-ext': 'Harmony Chrome Extension Wallet', + 'binance-chain-wallet': 'Binance Chain Wallet', + }; + let appsArray = []; - if (cw.row.network == 'EVM' || false) { - log( - yellow( - 'šŸ†’ You can use this wallet in Ethereum, Binance Smart Chain, Polygon and few more networks (EVM compatible)' - ) - ); + for (let key of Object.keys(apps)) { + if (cw.row.apps.includes(key)) { + appsArray.push(apps[key]); } + } - if (cw.row.apps !== undefined) { - let apps = { - metamask: 'MetaMask', - tronlink: 'TronLink', - trustwallet: 'Trust Wallet', - 'harmony-chrome-ext': 'Harmony Chrome Extension Wallet', - 'binance-chain-wallet': 'Binance Chain Wallet', - }; - let appsArray = []; - - for (let key of Object.keys(apps)) { - if (cw.row.apps.includes(key)) { - appsArray.push(apps[key]); - } - } - - let appsString = appsArray.join(', '); - if (cw.row.apps || false) { - appsString += ' and many other wallet apps'; - } - log( - greenBright('ā„¹ļø You can import this wallet into ' + appsString) - ); - } + let appsString = appsArray.join(', '); + if (cw.row.apps || false) { + appsString += ' and many other wallet apps'; } - }, - }; + log(greenBright('ā„¹ļø You can import this wallet into ' + appsString)); + } + } + } - return (callMethod[this.name] || callMethod['_'])(); + async init() { + return (this.callMethods[this.name] || this.callMethods['_'])(); } } diff --git a/src/Wallet.js b/src/Wallet.js index 29bdcc3..8ce2117 100644 --- a/src/Wallet.js +++ b/src/Wallet.js @@ -1,35 +1,24 @@ import { log } from './utils.js'; import chalk from 'chalk'; -const { red } = chalk; import CoinKey from 'coinkey'; import CoinInfo from 'coininfo'; import bip39 from 'bip39'; import bip84 from 'bip84'; -const { - fromMnemonic, - fromZPrv, -} = bip84; +const { fromMnemonic, fromZPrv } = bip84; import ethereumBip from 'ethereum-bip84'; -const { - fromMnemonic: fromMnemonicEthereum, - fromZPrv: fromZPrvEthereum, -} = ethereumBip; +const { fromMnemonic: fromMnemonicEthereum, fromZPrv: fromZPrvEthereum } = + ethereumBip; import dogecoinBip from '@yerofey/dogecoin-bip84'; -const { - fromMnemonic: fromMnemonicDoge, - fromZPrv: fromZPrvDoge -} = dogecoinBip; +const { fromMnemonic: fromMnemonicDoge, fromZPrv: fromZPrvDoge } = dogecoinBip; import litecoinBip from '@yerofey/litecoin-bip84'; -const { - fromMnemonic: fromMnemonicLite, - fromZPrv: fromZPrvLite, -} = litecoinBip; +const { fromMnemonic: fromMnemonicLite, fromZPrv: fromZPrvLite } = litecoinBip; 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 tronWeb from 'tronweb'; import tezos from 'tezos-sign'; +const { red } = chalk; class Wallet { constructor(cw) { @@ -312,8 +301,9 @@ class Wallet { }; } - const _fromMnemonic = (chain == 'DOGE') ? fromMnemonicDoge : fromMnemonicLite; - const _fromZPrv = (chain == 'DOGE') ? fromZPrvDoge : fromZPrvLite; + const _fromMnemonic = + chain == 'DOGE' ? fromMnemonicDoge : fromMnemonicLite; + const _fromZPrv = chain == 'DOGE' ? fromZPrvDoge : fromZPrvLite; const mnemonic = mnemonicString || bip39.generateMnemonic(); const root = new _fromMnemonic(mnemonic, ''); const child = root.deriveAccount(0); @@ -487,7 +477,4 @@ function generateMnemonicString() { return bip39.generateMnemonic(); } -const _generateMnemonicString = generateMnemonicString; -export { _generateMnemonicString as generateMnemonicString }; -const _Wallet = Wallet; -export { _Wallet as Wallet }; +export { generateMnemonicString, Wallet }; diff --git a/src/options.js b/src/options.js new file mode 100644 index 0000000..a057b90 --- /dev/null +++ b/src/options.js @@ -0,0 +1,43 @@ +import { program } from 'commander'; + + +program.option('-b, --chain ', 'Wallet for specific blockchain', 'ERC'); +program.option('-c, --chain ', 'Wallet for specific blockchain', 'ERC'); +program.option( + '-D, --csv [filename]', + 'Save result into CSV file' +); +program.option( + '-f, --format ', + 'Wallet format type (for cryptos with multiple wallet formats)' +); +program.option( + '-F, --filename ', + 'Filename to output the data (works with -o argument)' +); +program.option('-g, --geek', 'Display some more info (geeky)'); +program.option('-l, --list', 'List all supported cryptos'); +program.option( + '-m, --mnemonic [mnemonic]', + 'Generate wallet from mnemonic string OR just a mnemonic string' +); +program.option( + '-n, --number ', + 'Number of wallets to generate (if supported)' +); +program.option('-o, --output ', 'Return results into some file'); +program.option('-p, --prefix ', 'Desired wallet prefix'); +program.option( + '-P, --prefix-sensitive ', + 'Desired wallet prefix (case-sensitive)' +); +program.option('-s, --suffix ', 'Desired wallet suffix'); +program.option( + '-S, --suffix-sensitive ', + 'Desired wallet suffix (case-sensitive)' +); +program.option('-v, --version', 'Display cryptowallet version'); +program.parse(); + +export const options = program.opts(); +export const zeroOptions = Object.keys(options).length === 0; diff --git a/src/utils.js b/src/utils.js index 55373c8..7afc2f8 100644 --- a/src/utils.js +++ b/src/utils.js @@ -21,12 +21,8 @@ const loadFile = async (filename, defaultValue = {}) => { }; const loadJson = async (filename) => { - return JSON.parse( - await readFile( - new URL(filename, import.meta.url) - ) - ); -} + return JSON.parse(await readFile(new URL(filename, import.meta.url))); +}; const objectHasAllKeys = (obj, keysArray) => // eslint-disable-next-line no-prototype-builtins @@ -34,17 +30,11 @@ const objectHasAllKeys = (obj, keysArray) => let supportedChains = []; // eslint-disable-next-line no-undef -const chainsFolder = `${path.dirname(decodeURIComponent(import.meta.url))}/chains/`.replace('file://', ''); -filesList(chainsFolder).forEach((item) => { - const name = item.replace(chainsFolder, '').replace('.json', ''); - supportedChains.push(name); -}); +const chainsFolder = `${path.dirname( + decodeURIComponent(import.meta.url) +)}/chains/`.replace('file://', ''); +supportedChains = filesList(chainsFolder).map((item) => + item.replace(chainsFolder, '').replace('.json', '') +); -const _log = log; -export { _log as log }; -export { loadFile }; -export { loadJson }; -const _objectHasAllKeys = objectHasAllKeys; -export { _objectHasAllKeys as objectHasAllKeys }; -const _supportedChains = supportedChains; -export { _supportedChains as supportedChains }; +export { log, loadFile, loadJson, objectHasAllKeys, supportedChains };