From d0ae20117f28667f2f4ccb8bee02eef9077baadd Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 9 May 2018 15:55:19 +0200 Subject: [PATCH] Use bs58 base for regex (#33) * Use bs58 base for regex * Fix match regex * Share bs58 regex --- packages/app-vanitygen/src/generator/cli.js | 8 +++++++- packages/app-vanitygen/src/generator/regex.js | 9 +++++++++ packages/app-vanitygen/src/generator/sodium.js | 4 +--- packages/app-vanitygen/src/index.js | 11 ++++++----- 4 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 packages/app-vanitygen/src/generator/regex.js diff --git a/packages/app-vanitygen/src/generator/cli.js b/packages/app-vanitygen/src/generator/cli.js index e3a83752b2..76742907f0 100644 --- a/packages/app-vanitygen/src/generator/cli.js +++ b/packages/app-vanitygen/src/generator/cli.js @@ -8,6 +8,7 @@ const chalk = require('chalk'); const u8aToHex = require('@polkadot/util/u8a/toHex'); const generator = require('./index.js'); +const matchRegex = require('./regex'); const { pkFromSeed } = require('./sodium'); const { match, withCase } = yargs @@ -20,7 +21,7 @@ const { match, withCase } = yargs .argv; const INDICATORS = ['|', '/', '-', '\\']; -const NUMBER_REGEX = /(\d+?)(?=(\d{3})+(?!\d)|$)/g; +const NUMBER_REGEX = new RegExp('(\\d+?)(?=(\\d{3})+(?!\\d)|$)', 'g'); const options = { match, @@ -32,6 +33,11 @@ let best = { count: -1 }; let total = 0; let indicator = -1; +if (!matchRegex.test(match)) { + console.error("Invalid character found in match string, allowed is '1-9' (no '0'), 'A-N & P-Z' (no 'O'), 'a-k & m-z' (no 'l') and '?' (wildcard)"); + process.exit(-1); +} + console.log(options); function showProgress () { diff --git a/packages/app-vanitygen/src/generator/regex.js b/packages/app-vanitygen/src/generator/regex.js new file mode 100644 index 0000000000..da43e650b3 --- /dev/null +++ b/packages/app-vanitygen/src/generator/regex.js @@ -0,0 +1,9 @@ +// Copyright 2017-2018 Jaco Greeff +// This software may be modified and distributed under the terms +// of the ISC license. See the LICENSE file for details. +// @flow + +// NOTE bs58 characters, no '0', 'O' or 'l' +const regex = new RegExp('^[1-9A-NP-Za-km-z?]*$', ''); + +module.exports = regex; diff --git a/packages/app-vanitygen/src/generator/sodium.js b/packages/app-vanitygen/src/generator/sodium.js index 70532c355b..8753978a16 100644 --- a/packages/app-vanitygen/src/generator/sodium.js +++ b/packages/app-vanitygen/src/generator/sodium.js @@ -19,11 +19,9 @@ try { .baseBuffer ); } catch (error) { - // oops, nothing + console.log(`Using NaCl bindings from 'tweet-nacl' (faster 'sodium' dependency not installed)`); } -console.log(`Using NaCl bindings from ${!pkFromSeed ? 'tweet-nacl' : 'node-sodium'}`); - module.exports = { pkFromSeed }; diff --git a/packages/app-vanitygen/src/index.js b/packages/app-vanitygen/src/index.js index a2974f854b..228e3155d4 100644 --- a/packages/app-vanitygen/src/index.js +++ b/packages/app-vanitygen/src/index.js @@ -16,6 +16,7 @@ import Dropdown from 'semantic-ui-react/dist/es/modules/Dropdown'; import Match from './Match'; import generator from './generator'; +import matchRegex from './generator/regex'; import generatorSort from './generator/sort'; import translate from './translate'; @@ -33,8 +34,7 @@ type State = { withCase: boolean } -const DEFAULT_MATCH = 'Some?'; -const MATCH_REGEX = /[1-9A-Za-z?]*$/; +const DEFAULT_MATCH = 'Some'; const BOOL_OPTIONS = [ { text: 'No', value: false }, { text: 'Yes', value: true } @@ -215,10 +215,11 @@ class App extends React.PureComponent { // eslint-disable-next-line no-unused-vars onChangeMatch = (event: SyntheticEvent<*>, { value }): void => { - const isMatchValid = MATCH_REGEX.test(value) && value.length < 31; - this.setState({ - isMatchValid, + isMatchValid: + matchRegex.test(value) && + (value.length !== 0) && + (value.length < 31), match: value }); }