Skip to content

Commit 0c8fb14

Browse files
committed
UnlockWalletPassword is mandatory now
1 parent 6fd013c commit 0c8fb14

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

examples/wallet/app/actions/account.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import type {
66
AppState,
77
Thunk,
88
AccountKeys,
9-
AccountState,
10-
UnlockWalletPassword
9+
AccountState
1110
} from '../reducers/types';
1211
import type {
1312
Amount,
@@ -39,15 +38,11 @@ import {
3938
import routes from '../constants/routes.json';
4039

4140
export type SetKeysAction = { type: 'SET_KEYS' } & AccountKeys;
42-
export type SetKeysWithUnlockWalletPasswordAction = {
43-
type: 'SET_UNLOCK_WALLET_PASSWORD'
44-
} & UnlockWalletPassword;
4541
export const SET_KEYS = 'SET_KEYS';
46-
export const SET_UNLOCK_WALLET_PASSWORD = 'SET_UNLOCK_WALLET_PASSWORD';
4742

4843
export function setAccount(
4944
privateKey: string,
50-
unlockWalletPassword: ?string
45+
unlockWalletPassword: string
5146
): Thunk<SetKeysAction> {
5247
return function setAccountThunk(dispatch) {
5348
return getAccountFromPrivateKey(privateKey).then(keys =>
@@ -57,7 +52,7 @@ export function setAccount(
5752
}
5853

5954
export function setKeysWithUnlockWalletPassword(
60-
unlockWalletPassword: ?string = ''
55+
unlockWalletPassword: string = ''
6156
): Thunk<SetKeysAction> {
6257
return function setKeysWithUnlockWalletPasswordThunk(dispatch) {
6358
const accountKeys = readEncryptedAccountInfo(unlockWalletPassword);
@@ -104,7 +99,7 @@ export function setAccountFromPrivateKey(
10499
const initializeKeysAndRedirect = (
105100
dispatch: Dispatch,
106101
keys: AccountKeys,
107-
unlockWalletPassword: ?string = ''
102+
unlockWalletPassword: string = ''
108103
) => {
109104
dispatch({
110105
type: SET_KEYS,
@@ -128,7 +123,7 @@ const initializeKeysAndRedirect = (
128123
export function setAccountFromMnemonic(
129124
mnemonicPhrase: string,
130125
mnemonicPassword: string,
131-
unlockWalletPassword: ?string
126+
unlockWalletPassword: string
132127
): Thunk<SetKeysAction> {
133128
if (isValidMnemonic(mnemonicPhrase)) {
134129
const seed = createSeedFromMnemonic(mnemonicPhrase, mnemonicPassword);

examples/wallet/app/components/RestoreWalletFromMnemonic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export default ({ setAccountFromMnemonic }: Props) => {
109109
safer wallet seeds.
110110
</em>
111111
</Form.Text>
112-
<Form.Label className="mt-5">Unlock wallet (optional):</Form.Label>
112+
<Form.Label className="mt-5">Unlock wallet:</Form.Label>
113113
<Form.Group>
114114
<Form.Control
115115
type="password"

examples/wallet/app/reducers/types.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ export type AccountKeys = {
3737
identifier: Identifier
3838
};
3939

40-
export type UnlockWalletPassword = {
41-
unlockWalletPassword: string
42-
};
43-
4440
export type AccountState = {
4541
balance: Balance,
4642
counter: Counter,

examples/wallet/app/utils/storage.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,23 @@ export function isUnlockWalletPasswordCreated(): boolean {
1111
}
1212

1313
export function saveEncryptedAccountInfo(
14-
unlockWalletPassword: ?string,
14+
unlockWalletPassword: string,
1515
keys: AccountKeys
1616
): void {
1717
const plainTextAccountInfo = JSON.stringify(keys);
18-
const spedingPwd: string = unlockWalletPassword || '';
19-
const encryptedTextAccountInfo = aesEncrypt(spedingPwd, plainTextAccountInfo);
18+
if (!unlockWalletPassword || unlockWalletPassword === '') {
19+
throw new Error('Invalid unlock password');
20+
}
21+
const encryptedTextAccountInfo = aesEncrypt(
22+
unlockWalletPassword,
23+
plainTextAccountInfo
24+
);
2025
localStorage.setItem(WALLET_ENCRYPTED_KEYS, encryptedTextAccountInfo);
2126
}
2227

2328
// eslint-disable-next-line flowtype/space-after-type-colon
2429
export function readEncryptedAccountInfo(
25-
unlockWalletPassword: ?string
30+
unlockWalletPassword: string
2631
): ?AccountKeys {
2732
const encryptedHex = localStorage.getItem(WALLET_ENCRYPTED_KEYS);
2833
try {

0 commit comments

Comments
 (0)