Skip to content

Commit

Permalink
UnlockWalletPassword is mandatory now
Browse files Browse the repository at this point in the history
  • Loading branch information
dmernies-iohk committed Jan 14, 2020
1 parent f16d978 commit c588509
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
15 changes: 5 additions & 10 deletions examples/wallet/app/actions/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import type {
AppState,
Thunk,
AccountKeys,
AccountState,
UnlockWalletPassword
AccountState
} from '../reducers/types';
import type {
Amount,
Expand Down Expand Up @@ -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 =>
Expand All @@ -57,7 +52,7 @@ export function setAccount(
}

export function setKeysWithUnlockWalletPassword(
unlockWalletPassword: ?string = ''
unlockWalletPassword: string = ''
): Thunk<SetKeysAction> {
return function setKeysWithUnlockWalletPasswordThunk(dispatch) {
const accountKeys = readEncryptedAccountInfo(unlockWalletPassword);
Expand Down Expand Up @@ -104,7 +99,7 @@ export function setAccountFromPrivateKey(
const initializeKeysAndRedirect = (
dispatch: Dispatch,
keys: AccountKeys,
unlockWalletPassword: ?string = ''
unlockWalletPassword: string = ''
) => {
dispatch({
type: SET_KEYS,
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 0 additions & 4 deletions examples/wallet/app/reducers/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ export type AccountKeys = {
identifier: Identifier
};

export type UnlockWalletPassword = {
unlockWalletPassword: string
};

export type AccountState = {
balance: Balance,
counter: Counter,
Expand Down
13 changes: 9 additions & 4 deletions examples/wallet/app/utils/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c588509

Please sign in to comment.