Warn on locally stored accounts (#3345)
This commit is contained in:
parent
645b6c43ca
commit
107bfc7065
@ -10,18 +10,20 @@ import { createWindow } from './window';
|
||||
|
||||
const ENV = process.env.NODE_ENV || 'production';
|
||||
|
||||
const onReady = async () => {
|
||||
registerAccountStoreHandlers();
|
||||
setupContentSecurityPolicy(ENV);
|
||||
await createWindow(ENV);
|
||||
await setupAutoUpdater();
|
||||
};
|
||||
|
||||
app.on('web-contents-created', (e, webContents) => {
|
||||
webContents.on('new-window', (e, url) => {
|
||||
app.on('web-contents-created', (_, webContents): void => {
|
||||
webContents.on('new-window', (e, url): void => {
|
||||
e.preventDefault();
|
||||
shell.openExternal(url).catch(console.error);
|
||||
});
|
||||
});
|
||||
|
||||
app.whenReady().then(onReady).catch(console.error);
|
||||
app
|
||||
.whenReady()
|
||||
.then(async (): Promise<void> => {
|
||||
registerAccountStoreHandlers();
|
||||
setupContentSecurityPolicy(ENV);
|
||||
|
||||
await createWindow(ENV);
|
||||
await setupAutoUpdater();
|
||||
})
|
||||
.catch(console.error);
|
||||
|
||||
@ -2,10 +2,9 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Modal, Password } from '@polkadot/react-components';
|
||||
import keyring from '@polkadot/ui-keyring';
|
||||
|
||||
import React, { useCallback, useState } from 'react';
|
||||
import { Modal, Password, PasswordStrength } from '@polkadot/react-components';
|
||||
import keyring from '@polkadot/ui-keyring';
|
||||
|
||||
import { useTranslation } from '../translate';
|
||||
|
||||
@ -67,9 +66,11 @@ export default function PasswordInput ({ onChange, onEnter, password }: Props):
|
||||
onEnter={onEnter}
|
||||
value={password2}
|
||||
/>
|
||||
<PasswordStrength value={password} />
|
||||
</Modal.Column>
|
||||
<Modal.Column>
|
||||
<p>{t<string>('The password and password confirmation for this account. This is required to authenticate any transactions made and to encrypt the keypair.')}</p>
|
||||
<p>{t<string>('Ensure you are using a strong password for proper account protection.')}</p>
|
||||
</Modal.Column>
|
||||
</Modal.Columns>
|
||||
);
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import React, { useCallback, useState } from 'react';
|
||||
import { AddressRow, Button, Modal, Password } from '@polkadot/react-components';
|
||||
import { AddressRow, Button, Modal, Password, PasswordStrength } from '@polkadot/react-components';
|
||||
import keyring from '@polkadot/ui-keyring';
|
||||
|
||||
import { useTranslation } from '../../translate';
|
||||
@ -91,14 +91,15 @@ function ChangePass ({ address, className = '', onClose }: Props): React.ReactEl
|
||||
<Modal
|
||||
className={`${className} app--accounts-Modal`}
|
||||
header={t<string>('Change account password')}
|
||||
size='large'
|
||||
>
|
||||
<Modal.Content>
|
||||
<AddressRow
|
||||
isInline
|
||||
value={address}
|
||||
>
|
||||
<p>{t<string>('This will apply to any future use of this account as stored on this browser. Ensure that you securely store this new password and that it is strong and unique to the account.')}</p>
|
||||
<div>
|
||||
/>
|
||||
<Modal.Columns>
|
||||
<Modal.Column>
|
||||
<Password
|
||||
autoFocus
|
||||
help={t<string>('The existing account password as specified when this account was created or when it was last changed.')}
|
||||
@ -108,6 +109,13 @@ function ChangePass ({ address, className = '', onClose }: Props): React.ReactEl
|
||||
tabIndex={1}
|
||||
value={oldPass}
|
||||
/>
|
||||
</Modal.Column>
|
||||
<Modal.Column>
|
||||
<p>{t<string>('The existing account password as specified when this account was created or when it was last changed.')}</p>
|
||||
</Modal.Column>
|
||||
</Modal.Columns>
|
||||
<Modal.Columns>
|
||||
<Modal.Column>
|
||||
<Password
|
||||
help={t<string>('The new account password. Once set, all future account unlocks will be performed with this new password.')}
|
||||
isError={!newPass1.isValid}
|
||||
@ -126,8 +134,12 @@ function ChangePass ({ address, className = '', onClose }: Props): React.ReactEl
|
||||
tabIndex={2}
|
||||
value={newPass2.password}
|
||||
/>
|
||||
</div>
|
||||
</AddressRow>
|
||||
<PasswordStrength value={newPass1.password} />
|
||||
</Modal.Column>
|
||||
<Modal.Column>
|
||||
<p>{t<string>('This will apply to any future use of this account as stored on this browser. Ensure that you securely store this new password and that it is strong and unique to the account.')}</p>
|
||||
</Modal.Column>
|
||||
</Modal.Columns>
|
||||
</Modal.Content>
|
||||
<Modal.Actions onCancel={onClose}>
|
||||
<Button
|
||||
|
||||
@ -50,6 +50,7 @@ interface CreateOptions {
|
||||
}
|
||||
|
||||
const DEFAULT_PAIR_TYPE = 'sr25519';
|
||||
const isElectron = navigator.userAgent.toLowerCase().indexOf(' electron/') > -1;
|
||||
|
||||
function deriveValidate (seed: string, derivePath: string, pairType: KeypairType): string | null {
|
||||
try {
|
||||
@ -264,7 +265,6 @@ function Create ({ className = '', onClose, onStatusChange, seed: propsSeed, typ
|
||||
<Modal.Column>
|
||||
<Input
|
||||
autoFocus
|
||||
className='full'
|
||||
help={t<string>('Name given to this account. You can edit it. To use the account to validate or nominate, it is a good practice to append the function of the account in the name, e.g "name_you_want - stash".')}
|
||||
isError={!isNameValid}
|
||||
label={t<string>('name')}
|
||||
@ -281,7 +281,6 @@ function Create ({ className = '', onClose, onStatusChange, seed: propsSeed, typ
|
||||
<Modal.Columns>
|
||||
<Modal.Column>
|
||||
<Input
|
||||
className='full'
|
||||
help={t<string>('The private key for your account is derived from this seed. This seed must be kept secret as anyone in its possession has access to the funds of this account. If you validate, use the seed of the session account as the "--key" parameter of your node.')}
|
||||
isAction
|
||||
isError={!isSeedValid}
|
||||
@ -335,7 +334,6 @@ function Create ({ className = '', onClose, onStatusChange, seed: propsSeed, typ
|
||||
<Modal.Columns>
|
||||
<Modal.Column>
|
||||
<Input
|
||||
className='full'
|
||||
help={t<string>('You can set a custom derivation path for this account using the following syntax "/<soft-key>//<hard-key>///<password>". The "/<soft-key>" and "//<hard-key>" may be repeated and mixed`. The "///password" is optional and should only occur once.')}
|
||||
isError={!!deriveError}
|
||||
label={t<string>('secret derivation path')}
|
||||
@ -357,6 +355,11 @@ function Create ({ className = '', onClose, onStatusChange, seed: propsSeed, typ
|
||||
</Modal.Column>
|
||||
</Modal.Columns>
|
||||
</Expander>
|
||||
{!isElectron && (
|
||||
<article className='warning'>
|
||||
<p>{t<string>('Consider storing your account in a signer such as a browser extension, hardware device, QR-capable phone wallet (non-connected) or desktop application for optimal account security.')} {t<string>('Future versions of the web-only interface will drop support for non-external accounts, much like the IPFS version.')}</p>
|
||||
</article>
|
||||
)}
|
||||
</Modal.Content>
|
||||
<Modal.Actions onCancel={onClose}>
|
||||
<Button
|
||||
|
||||
56
packages/react-components/src/PasswordStrength.tsx
Normal file
56
packages/react-components/src/PasswordStrength.tsx
Normal file
@ -0,0 +1,56 @@
|
||||
// Copyright 2017-2020 @polkadot/react-components authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
function calcStrength (password: string): number {
|
||||
// at least 8 characters
|
||||
return (/.{8,}/.test(password) ? 1 : 0) * (
|
||||
// bonus if longer
|
||||
(/.{12,}/.test(password) ? 1 : 0) +
|
||||
// a lower letter
|
||||
(/[a-z]/.test(password) ? 1 : 0) +
|
||||
// a upper letter
|
||||
(/[A-Z]/.test(password) ? 1 : 0) +
|
||||
// a digit
|
||||
(/\d/.test(password) ? 1 : 0) +
|
||||
// a special character
|
||||
(/[^A-Za-z0-9]/.test(password) ? 1 : 0)
|
||||
);
|
||||
}
|
||||
|
||||
function PasswordStrength ({ className = '', value }: Props): React.ReactElement<Props> {
|
||||
const [style, setStyle] = useState<React.CSSProperties>({ width: `${calcStrength(value) * 20}%` });
|
||||
|
||||
useEffect((): void => {
|
||||
setStyle({ width: `${calcStrength(value) * 20}%` });
|
||||
}, [value]);
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<div
|
||||
className='ui--highlight--bg'
|
||||
style={style}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.memo(styled(PasswordStrength)`
|
||||
background: ##eee6e6;
|
||||
border-radius: 0.25rem;
|
||||
margin-left: 2rem;
|
||||
margin-top: 0.25rem;
|
||||
overflow: hidden;
|
||||
|
||||
> div {
|
||||
height: 0.5rem;
|
||||
}
|
||||
`);
|
||||
@ -72,6 +72,7 @@ export { default as Modal } from './Modal';
|
||||
export { default as Nonce } from './Nonce';
|
||||
export { default as Output } from './Output';
|
||||
export { default as Password } from './Password';
|
||||
export { default as PasswordStrength } from './PasswordStrength';
|
||||
export { default as Popup } from './Popup';
|
||||
export { default as Progress } from './Progress';
|
||||
export { default as ProposedAction } from './ProposedAction';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user