Use bs58 base for regex (#33)
* Use bs58 base for regex * Fix match regex * Share bs58 regex
This commit is contained in:
parent
82e6cf290d
commit
d0ae20117f
@ -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 () {
|
||||
|
||||
9
packages/app-vanitygen/src/generator/regex.js
Normal file
9
packages/app-vanitygen/src/generator/regex.js
Normal file
@ -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;
|
||||
@ -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
|
||||
};
|
||||
|
||||
@ -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<Props, State> {
|
||||
|
||||
// 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
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user