Fix vanitygen (type passing) & support sr25519 (#1066)
* Fix vanitygen (type passing) * Correct types * Allow sr25519 vanity generation
This commit is contained in:
parent
7fc1a88d34
commit
c9b35f71f7
@ -21,7 +21,8 @@ import translate from './translate';
|
||||
type Props = ComponentProps & I18nProps & {
|
||||
match: {
|
||||
params: {
|
||||
seed?: string
|
||||
seed?: string,
|
||||
type?: KeypairType
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -86,10 +87,10 @@ class Creator extends React.PureComponent<Props, State> {
|
||||
constructor (props: Props) {
|
||||
super(props);
|
||||
|
||||
const { match: { params: { seed } }, t } = this.props;
|
||||
const { match: { params: { seed, type } }, t } = this.props;
|
||||
|
||||
this.state = {
|
||||
...this.emptyState(seed || null, '', DEFAULT_TYPE),
|
||||
...this.emptyState(seed || null, '', type || DEFAULT_TYPE),
|
||||
seedOptions: [
|
||||
{ value: 'bip', text: t('Mnemonic') },
|
||||
{ value: 'raw', text: t('Raw seed') }
|
||||
|
||||
@ -12,7 +12,7 @@ type Props = BareProps & {
|
||||
address: string;
|
||||
count: number;
|
||||
offset: number;
|
||||
onCreateToggle: (passthrough: string) => void,
|
||||
onCreateToggle: (seed: string) => void,
|
||||
onRemove: (address: string) => void,
|
||||
seed: Uint8Array;
|
||||
};
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import { KeypairType } from '@polkadot/util-crypto/types';
|
||||
import { Generator$Matches, Generator$Result } from '../vanitygen/types';
|
||||
import { ComponentProps } from '../types';
|
||||
|
||||
@ -10,6 +11,7 @@ import './index.css';
|
||||
|
||||
import React from 'react';
|
||||
import { Button, Dropdown, Input } from '@polkadot/ui-app';
|
||||
import uiSettings from '@polkadot/ui-settings';
|
||||
|
||||
import generator from '../vanitygen';
|
||||
import matchRegex from '../vanitygen/regex';
|
||||
@ -28,6 +30,7 @@ type State = {
|
||||
match: string,
|
||||
matches: Generator$Matches,
|
||||
startAt: number,
|
||||
type: KeypairType,
|
||||
withCase: boolean
|
||||
};
|
||||
|
||||
@ -48,6 +51,7 @@ class VanityApp extends React.PureComponent<Props, State> {
|
||||
match: DEFAULT_MATCH,
|
||||
matches: [],
|
||||
startAt: 0,
|
||||
type: 'ed25519',
|
||||
withCase: true
|
||||
};
|
||||
|
||||
@ -107,30 +111,42 @@ class VanityApp extends React.PureComponent<Props, State> {
|
||||
|
||||
renderOptions () {
|
||||
const { t } = this.props;
|
||||
const { isMatchValid, isRunning, match, withCase } = this.state;
|
||||
const { isMatchValid, isRunning, match, type, withCase } = this.state;
|
||||
|
||||
return (
|
||||
<div className='ui--row'>
|
||||
<Input
|
||||
autoFocus
|
||||
className='medium'
|
||||
help={t('Type here what you would like your address to contain. This tool will generate the keys and show the associated addresses that best match your search. You can use "?" as a wildcard for a character.')}
|
||||
isDisabled={isRunning}
|
||||
isError={!isMatchValid}
|
||||
label={t('Search for')}
|
||||
onChange={this.onChangeMatch}
|
||||
value={match}
|
||||
/>
|
||||
<Dropdown
|
||||
className='medium'
|
||||
help={t('Should the search be case sensitive, e.g if you select "no" your search for "Some" may return addresses containing "somE" or "sOme"...')}
|
||||
isDisabled={isRunning}
|
||||
label={t('case sensitive')}
|
||||
options={BOOL_OPTIONS}
|
||||
onChange={this.onChangeCase}
|
||||
value={withCase}
|
||||
/>
|
||||
</div>
|
||||
<>
|
||||
<div className='ui--row'>
|
||||
<Input
|
||||
autoFocus
|
||||
className='medium'
|
||||
help={t('Type here what you would like your address to contain. This tool will generate the keys and show the associated addresses that best match your search. You can use "?" as a wildcard for a character.')}
|
||||
isDisabled={isRunning}
|
||||
isError={!isMatchValid}
|
||||
label={t('Search for')}
|
||||
onChange={this.onChangeMatch}
|
||||
value={match}
|
||||
/>
|
||||
<Dropdown
|
||||
className='medium'
|
||||
help={t('Should the search be case sensitive, e.g if you select "no" your search for "Some" may return addresses containing "somE" or "sOme"...')}
|
||||
isDisabled={isRunning}
|
||||
label={t('case sensitive')}
|
||||
options={BOOL_OPTIONS}
|
||||
onChange={this.onChangeCase}
|
||||
value={withCase}
|
||||
/>
|
||||
</div>
|
||||
<div className='ui--row'>
|
||||
<Dropdown
|
||||
className='medium'
|
||||
defaultValue={type}
|
||||
help={t('Determines what cryptography will be used to create this account. Note that to validate on Polkadot, the session account must use "ed25519".')}
|
||||
label={t('keypair crypto type')}
|
||||
onChange={this.onChangeType}
|
||||
options={uiSettings.availableCryptos}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@ -205,11 +221,14 @@ class VanityApp extends React.PureComponent<Props, State> {
|
||||
this.checkMatches();
|
||||
}
|
||||
|
||||
const { match, type, withCase } = this.state;
|
||||
|
||||
this.results.push(
|
||||
generator({
|
||||
match: this.state.match,
|
||||
match,
|
||||
runs: 10,
|
||||
withCase: this.state.withCase
|
||||
type,
|
||||
withCase
|
||||
})
|
||||
);
|
||||
|
||||
@ -220,8 +239,9 @@ class VanityApp extends React.PureComponent<Props, State> {
|
||||
|
||||
private onCreateToggle = (seed: string) => {
|
||||
const { basePath } = this.props;
|
||||
const { type } = this.state;
|
||||
|
||||
window.location.hash = `${basePath}/create/${seed}`;
|
||||
window.location.hash = `${basePath}/create/${type}/${seed}`;
|
||||
}
|
||||
|
||||
onChangeCase = (withCase: boolean): void => {
|
||||
@ -238,6 +258,10 @@ class VanityApp extends React.PureComponent<Props, State> {
|
||||
});
|
||||
}
|
||||
|
||||
onChangeType = (type: KeypairType): void => {
|
||||
this.setState({ type } as State);
|
||||
}
|
||||
|
||||
onRemove = (address: string): void => {
|
||||
this.setState(
|
||||
(prevState: State) => ({
|
||||
|
||||
@ -110,7 +110,7 @@ class AccountsApp extends React.PureComponent<Props, State> {
|
||||
/>
|
||||
</header>
|
||||
<Switch>
|
||||
<Route path={`${basePath}/create/:seed`} render={renderCreator} />
|
||||
<Route path={`${basePath}/create/:type/:seed`} render={renderCreator} />
|
||||
<Route path={`${basePath}/create`} render={renderCreator} />
|
||||
<Route path={`${basePath}/restore`} render={this.renderComponent(Restore)} />
|
||||
<Route path={`${basePath}/vanity`} render={this.renderComponent(Vanity)} />
|
||||
|
||||
@ -3,6 +3,9 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { KeypairType } from '@polkadot/util-crypto/types';
|
||||
import { Generator$Options } from './types';
|
||||
|
||||
import yargs from 'yargs';
|
||||
import chalk from 'chalk';
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
@ -17,10 +20,14 @@ type Best = {
|
||||
seed?: Uint8Array
|
||||
};
|
||||
|
||||
const { match, withCase } = yargs
|
||||
const { match, type, withCase } = yargs
|
||||
.option('match', {
|
||||
default: 'EEEEE'
|
||||
})
|
||||
.option('type', {
|
||||
choices: ['ed25519', 'sr25519'],
|
||||
default: 'ed25519'
|
||||
})
|
||||
.option('withCase', {
|
||||
default: true
|
||||
})
|
||||
@ -29,9 +36,10 @@ const { match, withCase } = yargs
|
||||
const INDICATORS = ['|', '/', '-', '\\'];
|
||||
const NUMBER_REGEX = new RegExp('(\\d+?)(?=(\\d{3})+(?!\\d)|$)', 'g');
|
||||
|
||||
const options = {
|
||||
const options: Generator$Options = {
|
||||
match,
|
||||
runs: 50,
|
||||
type: type as KeypairType,
|
||||
withCase
|
||||
};
|
||||
const startAt = Date.now();
|
||||
|
||||
@ -5,13 +5,16 @@
|
||||
import { Generator$Match, Generator$Options } from './types';
|
||||
|
||||
import { encodeAddress } from '@polkadot/keyring';
|
||||
import { naclKeypairFromSeed, randomAsU8a } from '@polkadot/util-crypto';
|
||||
import { naclKeypairFromSeed, randomAsU8a, schnorrkelKeypairFromSeed } from '@polkadot/util-crypto';
|
||||
|
||||
import calculate from './calculate';
|
||||
|
||||
export default function generator (test: Array<string>, options: Generator$Options): Generator$Match {
|
||||
const seed = randomAsU8a();
|
||||
const address = encodeAddress(naclKeypairFromSeed(seed).publicKey);
|
||||
const pair = options.type === 'sr25519'
|
||||
? schnorrkelKeypairFromSeed(seed)
|
||||
: naclKeypairFromSeed(seed);
|
||||
const address = encodeAddress(pair.publicKey);
|
||||
const { count, offset } = calculate(test, address, options);
|
||||
|
||||
return {
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { KeypairType } from '@polkadot/util-crypto/types';
|
||||
|
||||
export type Generator$Calculation = {
|
||||
count: number,
|
||||
offset: number
|
||||
@ -17,7 +19,8 @@ export type Generator$Matches = Array<Generator$Match>;
|
||||
export type Generator$Options = {
|
||||
atOffset?: number,
|
||||
match: string,
|
||||
runs?: number,
|
||||
runs: number,
|
||||
type: KeypairType,
|
||||
withCase?: boolean
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user