Skip to content
Permalink
Browse files

UnlockWalletPassword is mandatory now

  • Loading branch information
dmernies-iohk committed Jan 14, 2020
1 parent f16d978 commit c588509e2513d5bd5d9ad79fbc841528614be5f5
@@ -6,8 +6,7 @@ import type {
AppState,
Thunk,
AccountKeys,
AccountState,
UnlockWalletPassword
AccountState
} from '../reducers/types';
import type {
Amount,
@@ -39,15 +38,11 @@ import {
import routes from '../constants/routes.json';

export type SetKeysAction = { type: 'SET_KEYS' } & AccountKeys;
export type SetKeysWithUnlockWalletPasswordAction = {
type: 'SET_UNLOCK_WALLET_PASSWORD'
} & UnlockWalletPassword;
export const SET_KEYS = 'SET_KEYS';
export const SET_UNLOCK_WALLET_PASSWORD = 'SET_UNLOCK_WALLET_PASSWORD';

export function setAccount(
privateKey: string,
unlockWalletPassword: ?string
unlockWalletPassword: string
): Thunk<SetKeysAction> {
return function setAccountThunk(dispatch) {
return getAccountFromPrivateKey(privateKey).then(keys =>
@@ -57,7 +52,7 @@ export function setAccount(
}

export function setKeysWithUnlockWalletPassword(
unlockWalletPassword: ?string = ''
unlockWalletPassword: string = ''
): Thunk<SetKeysAction> {
return function setKeysWithUnlockWalletPasswordThunk(dispatch) {
const accountKeys = readEncryptedAccountInfo(unlockWalletPassword);
@@ -104,7 +99,7 @@ export function setAccountFromPrivateKey(
const initializeKeysAndRedirect = (
dispatch: Dispatch,
keys: AccountKeys,
unlockWalletPassword: ?string = ''
unlockWalletPassword: string = ''
) => {
dispatch({
type: SET_KEYS,
@@ -128,7 +123,7 @@ const initializeKeysAndRedirect = (
export function setAccountFromMnemonic(
mnemonicPhrase: string,
mnemonicPassword: string,
unlockWalletPassword: ?string
unlockWalletPassword: string
): Thunk<SetKeysAction> {
if (isValidMnemonic(mnemonicPhrase)) {
const seed = createSeedFromMnemonic(mnemonicPhrase, mnemonicPassword);
@@ -109,7 +109,7 @@ export default ({ setAccountFromMnemonic }: Props) => {
safer wallet seeds.
</em>
</Form.Text>
<Form.Label className="mt-5">Unlock wallet (optional):</Form.Label>
<Form.Label className="mt-5">Unlock wallet:</Form.Label>
<Form.Group>
<Form.Control
type="password"
@@ -37,10 +37,6 @@ export type AccountKeys = {
identifier: Identifier
};

export type UnlockWalletPassword = {
unlockWalletPassword: string
};

export type AccountState = {
balance: Balance,
counter: Counter,
@@ -11,18 +11,23 @@ export function isUnlockWalletPasswordCreated(): boolean {
}

export function saveEncryptedAccountInfo(
unlockWalletPassword: ?string,
unlockWalletPassword: string,
keys: AccountKeys
): void {
const plainTextAccountInfo = JSON.stringify(keys);
const spedingPwd: string = unlockWalletPassword || '';
const encryptedTextAccountInfo = aesEncrypt(spedingPwd, plainTextAccountInfo);
if (!unlockWalletPassword || unlockWalletPassword === '') {
throw new Error('Invalid unlock password');
}
const encryptedTextAccountInfo = aesEncrypt(
unlockWalletPassword,
plainTextAccountInfo
);
localStorage.setItem(WALLET_ENCRYPTED_KEYS, encryptedTextAccountInfo);
}

// eslint-disable-next-line flowtype/space-after-type-colon
export function readEncryptedAccountInfo(
unlockWalletPassword: ?string
unlockWalletPassword: string
): ?AccountKeys {
const encryptedHex = localStorage.getItem(WALLET_ENCRYPTED_KEYS);
try {

0 comments on commit c588509

Please sign in to comment.
You can’t perform that action at this time.