Skip to content

Commit

Permalink
v1.4.0: -p option is now case-insensitive and -P option is case-s…
Browse files Browse the repository at this point in the history
…ensitive
  • Loading branch information
yerofey committed Apr 15, 2022
1 parent 18189ad commit d6113a3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ $ cw -p aaa
# generate random BTC wallet (default format: bech32 - "bc1q...")
$ cw -c BTC

# generate random BTC wallet with desired prefix (case sensitive)
# generate random BTC wallet with desired prefix (case-insensitive)
$ cw -c BTC -p ABC

# generate random BTC wallet with desired prefix (case insensitive)
# generate random BTC wallet with desired prefix (case-sensitive)
$ cw -c BTC -P abc

# generate BTC legacy wallet ("1...")
Expand Down Expand Up @@ -95,10 +95,10 @@ $ cw -l
* `-l` or `--list`: List all supported cryptocurrencies
* `-m` or `--mnemonic`: Use a bip39 mnemonic phrase (if is set) to generate wallet, or leave it empty to generate new one
* `-n` or `--number`: Specify number of wallets to display (works for HD wallets only, like BTC/LTC/DOGE)
* `-p` or `--prefix`: Specify desired prefix of an wallet address (**case-sensitive**)
* `-P` or `--prefix-ignorecase`: Specify desired prefix of an wallet address (**case-insensitive**)
* `-s` or `--suffix`: Specify desired suffix of an wallet address (**case-sensitive**)
* `-S` or `--suffix-ignorecase`: Specify desired suffix of an wallet address (**case-insensitive**)
* `-p` or `--prefix`: Specify desired prefix of an wallet address (**case-insensitive**)
* `-P` or `--prefix-sensitive`: Specify desired prefix of an wallet address (**case-sensitive**)
* `-s` or `--suffix`: Specify desired suffix of an wallet address (**case-insensitive**)
* `-S` or `--suffix-sensitive`: Specify desired suffix of an wallet address (**case-sensitive**)
* `-v` or `--version`: Display the version of CW tool

## Highlights
Expand Down
8 changes: 4 additions & 4 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ 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>', 'Number of wallets to generate (if supported)');
program.option('-p, --prefix <prefix>', 'Desired wallet prefix (case sensitive)');
program.option('-P, --prefix-ignorecase <prefix>', 'Desired wallet prefix (case insensitive)');
program.option('-s, --suffix <suffix>', 'Desired wallet suffix (case sensitive)');
program.option('-S, --suffix-ignorecase <suffix>', 'Desired wallet suffix (case insensitive)');
program.option('-p, --prefix <prefix>', 'Desired wallet prefix');
program.option('-P, --prefix-sensitive <prefix>', 'Desired wallet prefix (case-sensitive)');
program.option('-s, --suffix <suffix>', 'Desired wallet suffix');
program.option('-S, --suffix-sensitive <suffix>', 'Desired wallet suffix (case-sensitive)');
program.option('-v, --version', 'Display cryptowallet version');
program.parse();

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yerofey/cryptowallet-cli",
"version": "1.3.0",
"version": "1.4.0",
"homepage": "https://github.com/yerofey/cryptowallet-cli",
"author": "Yerofey S. <[email protected]> (https://github.com/yerofey)",
"bin": {
Expand Down
8 changes: 4 additions & 4 deletions src/CW.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class CW {
geek: false,
mnemonic: '',
number: 1,
prefix: options.prefixIgnorecase || '',
prefixIgnoreCase: options.prefixIgnorecase !== undefined,
suffix: options.suffixIgnorecase || '',
suffixIgnoreCase: options.suffixIgnorecase !== undefined,
prefix: options.prefixSensitive || '',
prefixIsCaseSensitive: options.prefixSensitive !== undefined,
suffix: options.suffixSensitive || '',
suffixIsCaseSensitive: options.suffixSensitive !== undefined,
}

for (const key of Object.keys(defaultValues)) {
Expand Down
16 changes: 8 additions & 8 deletions src/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class Wallet {
let onlySuffix = false;
let onlyBoth = false;

const prefixFoundInAddress = (address, isIgnoringCase, prefix, symbol) => (!isIgnoringCase && address.startsWith(symbol + '' + prefix) || isIgnoringCase && (address).toUpperCase().startsWith((symbol + '' + prefix).toUpperCase()));
const suffixFoundInAddress = (address, isIgnoringCase, suffix) => (!isIgnoringCase && address.endsWith(suffix) || isIgnoringCase && (address).toUpperCase().endsWith(suffix));
const prefixFoundInAddress = (address, isCaseSensitive, prefix, symbol) => (isCaseSensitive && address.startsWith(symbol + '' + prefix) || !isCaseSensitive && (address).toUpperCase().startsWith((symbol + '' + prefix).toUpperCase()));
const suffixFoundInAddress = (address, isCaseSensitive, suffix) => (isCaseSensitive && address.endsWith(suffix) || !isCaseSensitive && (address).toUpperCase().endsWith(suffix));

if (options.prefix && row.flags.includes('p') || options.suffix && row.flags.includes('s')) {
if (badSymbolsArray.length === 0) {
Expand All @@ -52,34 +52,34 @@ class Wallet {
wallet = await this.createWallet();
for (let firstSymbol of startsWithSymbols) {
if (wallet.address !== undefined) { // one address
if (onlyPrefix && prefixFoundInAddress(wallet.address, options.prefixIgnoreCase, options.prefix, firstSymbol)) {
if (onlyPrefix && prefixFoundInAddress(wallet.address, options.prefixIsCaseSensitive, options.prefix, firstSymbol)) {
prefixFound = true;
break loop;
}

if (onlySuffix && suffixFoundInAddress(wallet.address, options.suffixIgnoreCase, options.suffix)) {
if (onlySuffix && suffixFoundInAddress(wallet.address, options.suffixIsCaseSensitive, options.suffix)) {
suffixFound = true;
break loop;
}

if (onlyBoth && prefixFoundInAddress(wallet.address, options.prefixIgnoreCase, options.prefix, firstSymbol) && suffixFoundInAddress(wallet.address, options.suffixIgnoreCase, options.suffix)) {
if (onlyBoth && prefixFoundInAddress(wallet.address, options.prefixIsCaseSensitive, options.prefix, firstSymbol) && suffixFoundInAddress(wallet.address, options.suffixIsCaseSensitive, options.suffix)) {
prefixFound = true;
suffixFound = true;
break loop;
}
} else if (wallet.addresses !== undefined) { // multiple addresses
for (let item of wallet.addresses) {
if (onlyPrefix && prefixFoundInAddress(item.address, options.prefixIgnoreCase, options.prefix, firstSymbol)) {
if (onlyPrefix && prefixFoundInAddress(item.address, options.prefixIsCaseSensitive, options.prefix, firstSymbol)) {
prefixFound = true;
prefixFoundInWallets.push(item.address);
}

if (onlySuffix && suffixFoundInAddress(item.address, options.suffixIgnoreCase, options.suffix)) {
if (onlySuffix && suffixFoundInAddress(item.address, options.suffixIsCaseSensitive, options.suffix)) {
suffixFound = true;
suffixFoundInWallets.push(item.address);
}

if (onlyBoth && prefixFoundInAddress(item.address, options.prefixIgnoreCase, options.prefix, firstSymbol) && suffixFoundInAddress(item.address, options.suffixIgnoreCase, options.suffix)) {
if (onlyBoth && prefixFoundInAddress(item.address, options.prefixIsCaseSensitive, options.prefix, firstSymbol) && suffixFoundInAddress(item.address, options.suffixIsCaseSensitive, options.suffix)) {
prefixFound = true;
prefixFoundInWallets.push(item.address);
suffixFound = true;
Expand Down

0 comments on commit d6113a3

Please sign in to comment.