diff --git a/packages/app-accounts/src/Creator.tsx b/packages/app-accounts/src/Creator.tsx index 6ff2813c40..0c47be4b41 100644 --- a/packages/app-accounts/src/Creator.tsx +++ b/packages/app-accounts/src/Creator.tsx @@ -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 { 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') } diff --git a/packages/app-accounts/src/Vanity/Match.tsx b/packages/app-accounts/src/Vanity/Match.tsx index 20ee87934f..03b707c436 100644 --- a/packages/app-accounts/src/Vanity/Match.tsx +++ b/packages/app-accounts/src/Vanity/Match.tsx @@ -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; }; diff --git a/packages/app-accounts/src/Vanity/index.tsx b/packages/app-accounts/src/Vanity/index.tsx index 0a794ca208..8c542bebd1 100644 --- a/packages/app-accounts/src/Vanity/index.tsx +++ b/packages/app-accounts/src/Vanity/index.tsx @@ -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 { match: DEFAULT_MATCH, matches: [], startAt: 0, + type: 'ed25519', withCase: true }; @@ -107,30 +111,42 @@ class VanityApp extends React.PureComponent { renderOptions () { const { t } = this.props; - const { isMatchValid, isRunning, match, withCase } = this.state; + const { isMatchValid, isRunning, match, type, withCase } = this.state; return ( -
- - -
+ <> +
+ + +
+
+ +
+ ); } @@ -205,11 +221,14 @@ class VanityApp extends React.PureComponent { 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 { 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 { }); } + onChangeType = (type: KeypairType): void => { + this.setState({ type } as State); + } + onRemove = (address: string): void => { this.setState( (prevState: State) => ({ diff --git a/packages/app-accounts/src/index.tsx b/packages/app-accounts/src/index.tsx index 9ff40c1ffb..9ff276b4e1 100644 --- a/packages/app-accounts/src/index.tsx +++ b/packages/app-accounts/src/index.tsx @@ -110,7 +110,7 @@ class AccountsApp extends React.PureComponent { /> - + diff --git a/packages/app-accounts/src/vanitygen/cli.ts b/packages/app-accounts/src/vanitygen/cli.ts index 0866f99d0b..765e2ac740 100644 --- a/packages/app-accounts/src/vanitygen/cli.ts +++ b/packages/app-accounts/src/vanitygen/cli.ts @@ -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(); diff --git a/packages/app-accounts/src/vanitygen/generate.ts b/packages/app-accounts/src/vanitygen/generate.ts index 2144f62561..7931d9af1d 100644 --- a/packages/app-accounts/src/vanitygen/generate.ts +++ b/packages/app-accounts/src/vanitygen/generate.ts @@ -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, 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 { diff --git a/packages/app-accounts/src/vanitygen/types.d.ts b/packages/app-accounts/src/vanitygen/types.d.ts index c385513ae4..72b79d2fd4 100644 --- a/packages/app-accounts/src/vanitygen/types.d.ts +++ b/packages/app-accounts/src/vanitygen/types.d.ts @@ -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; export type Generator$Options = { atOffset?: number, match: string, - runs?: number, + runs: number, + type: KeypairType, withCase?: boolean };