Skip to content

Commit 4b2269c

Browse files
committed
UnlockWalletPassword is used instead of SpendingPassword
1 parent be98350 commit 4b2269c

File tree

5 files changed

+37
-33
lines changed

5 files changed

+37
-33
lines changed

examples/wallet/app/actions/account.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
Thunk,
88
AccountKeys,
99
AccountState,
10-
SpendingPassword
10+
UnlockWalletPassword
1111
} from '../reducers/types';
1212
import type {
1313
Amount,
@@ -39,40 +39,40 @@ import {
3939
import routes from '../constants/routes.json';
4040

4141
export type SetKeysAction = { type: 'SET_KEYS' } & AccountKeys;
42-
export type SetKeysWithSpendingPasswordAction = {
43-
type: 'SET_SPENDING_PASSWORD'
44-
} & SpendingPassword;
42+
export type SetKeysWithUnlockWalletPasswordAction = {
43+
type: 'SET_UNLOCK_WALLET_PASSWORD'
44+
} & UnlockWalletPassword;
4545
export const SET_KEYS = 'SET_KEYS';
46-
export const SET_SPENDING_PASSWORD = 'SET_SPENDING_PASSWORD';
46+
export const SET_UNLOCK_WALLET_PASSWORD = 'SET_UNLOCK_WALLET_PASSWORD';
4747

4848
export function setAccount(
4949
privateKey: string,
50-
spendingPassword: ?string
50+
unlockWalletPassword: ?string
5151
): Thunk<SetKeysAction> {
5252
return function setAccountThunk(dispatch) {
5353
return getAccountFromPrivateKey(privateKey).then(keys =>
54-
curry(initializeKeysAndRedirect)(dispatch, keys, spendingPassword)
54+
curry(initializeKeysAndRedirect)(dispatch, keys, unlockWalletPassword)
5555
);
5656
};
5757
}
5858

5959
export function setKeysWithUnlockWalletPassword(
60-
spendingPassword: ?string = ''
60+
unlockWalletPassword: ?string = ''
6161
): Thunk<SetKeysAction> {
6262
return function setKeysWithUnlockWalletPasswordThunk(dispatch) {
63-
const accountKeys = readEncryptedAccountInfo(spendingPassword);
63+
const accountKeys = readEncryptedAccountInfo(unlockWalletPassword);
6464
if (accountKeys) {
65-
const spendingPasswordKeys = {
65+
const unlockWalletPasswordKeys = {
6666
walletId: 'wallet01',
67-
spendingPassword
67+
unlockWalletPassword
6868
};
6969
dispatch({
70-
type: SET_SPENDING_PASSWORD,
71-
...spendingPasswordKeys
70+
type: SET_UNLOCK_WALLET_PASSWORD,
71+
...unlockWalletPasswordKeys
7272
});
7373

7474
return getAccountFromPrivateKey(accountKeys.privateKey).then(keys =>
75-
curry(initializeKeysAndRedirect)(dispatch, keys, spendingPassword)
75+
curry(initializeKeysAndRedirect)(dispatch, keys, unlockWalletPassword)
7676
);
7777
}
7878
throw new Error('Invalid password');
@@ -113,14 +113,14 @@ export function setAccountFromPrivateKey(
113113
const initializeKeysAndRedirect = (
114114
dispatch: Dispatch,
115115
keys: AccountKeys,
116-
spendingPassword: ?string = ''
116+
unlockWalletPassword: ?string = ''
117117
) => {
118118
dispatch({
119119
type: SET_KEYS,
120120
...keys
121121
});
122122

123-
saveEncryptedAccountInfo(spendingPassword, keys);
123+
saveEncryptedAccountInfo(unlockWalletPassword, keys);
124124

125125
return Promise.all([
126126
dispatch(updateAccountTransactions()),
@@ -137,13 +137,13 @@ const initializeKeysAndRedirect = (
137137
export function setAccountFromMnemonic(
138138
mnemonicPhrase: string,
139139
mnemonicPassword: string,
140-
spendingPassword: ?string
140+
unlockWalletPassword: ?string
141141
): Thunk<SetKeysAction> {
142142
if (isValidMnemonic(mnemonicPhrase)) {
143143
const seed = createSeedFromMnemonic(mnemonicPhrase, mnemonicPassword);
144144
return function setAccountThunk(dispatch) {
145145
return getAccountFromSeed(seed).then(keys =>
146-
curry(initializeKeysAndRedirect)(dispatch, keys, spendingPassword)
146+
curry(initializeKeysAndRedirect)(dispatch, keys, unlockWalletPassword)
147147
);
148148
};
149149
}

examples/wallet/app/reducers/account.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22
import sortBy from 'lodash/sortBy';
33
import {
4-
SET_SPENDING_PASSWORD,
4+
SET_UNLOCK_WALLET_PASSWORD,
55
SET_KEYS,
66
SET_ACCOUNT_STATE,
77
SEND_TRANSACTION,
@@ -13,7 +13,7 @@ import type {
1313
SendTransactionAction,
1414
SetAccountStateAction,
1515
SetTransactionsAction,
16-
SetKeysWithSpendingPasswordAction,
16+
SetKeysWithUnlockWalletPasswordAction,
1717
SendStakeDelegation
1818
} from '../actions/account';
1919
import type { Account } from './types';
@@ -23,7 +23,7 @@ export default function account(
2323
state: Account,
2424
// eslint-disable-next-line flowtype/space-after-type-colon
2525
action:
26-
| SetKeysWithSpendingPasswordAction
26+
| SetKeysWithUnlockWalletPasswordAction
2727
| SetKeysAction
2828
| SetAccountStateAction
2929
| SendTransactionAction
@@ -34,10 +34,10 @@ export default function account(
3434
return { transactions: [] };
3535
}
3636
switch (action.type) {
37-
case SET_SPENDING_PASSWORD:
37+
case SET_UNLOCK_WALLET_PASSWORD:
3838
return Object.assign({}, state, {
3939
walletId: action.walletId,
40-
spendingPassword: action.spendingPassword
40+
unlockWalletPassword: action.unlockWalletPassword
4141
});
4242
case SET_KEYS:
4343
return Object.assign({}, state, {

examples/wallet/app/reducers/types.js

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

40-
export type SpendingPassword = {
40+
export type UnlockWalletPassword = {
4141
walletId: string,
42-
spendingPassword: string
42+
unlockWalletPassword: string
4343
};
4444

4545
export type AccountState = {

examples/wallet/app/utils/decrypt.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ const blake2b = data => blakejs.blake2b(data, null, 32);
66
const SECRET = 'wallet_demo#';
77
const AES_SECRET = ':aes_secret#';
88

9-
export function aesEncrypt(spendingPassword: string, text: string): string {
10-
const aesPasswordText = spendingPassword.concat(SECRET).concat(AES_SECRET);
9+
export function aesEncrypt(unlockWalletPassword: string, text: string): string {
10+
const aesPasswordText = unlockWalletPassword
11+
.concat(SECRET)
12+
.concat(AES_SECRET);
1113
const aesKey = blake2b(aesPasswordText);
1214
const aesCtr = new aesjs.ModeOfOperation.ctr(aesKey, new aesjs.Counter(5));
1315
const encryptedBytes = aesCtr.encrypt(aesjs.utils.utf8.toBytes(text));
@@ -16,10 +18,12 @@ export function aesEncrypt(spendingPassword: string, text: string): string {
1618
}
1719

1820
export function aesDecrypt(
19-
spendingPassword: string,
21+
unlockWalletPassword: string,
2022
encryptedHex: string
2123
): string {
22-
const aesPasswordText = spendingPassword.concat(SECRET).concat(AES_SECRET);
24+
const aesPasswordText = unlockWalletPassword
25+
.concat(SECRET)
26+
.concat(AES_SECRET);
2327
const aesKey = blake2b(aesPasswordText);
2428
const aesCtr = new aesjs.ModeOfOperation.ctr(aesKey, new aesjs.Counter(5));
2529
const decryptedBytes = aesCtr.decrypt(aesjs.utils.hex.toBytes(encryptedHex));

examples/wallet/app/utils/storage.js

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

1313
export function saveEncryptedAccountInfo(
14-
spendingPassword: ?string,
14+
unlockWalletPassword: ?string,
1515
keys: AccountKeys
1616
): void {
1717
const plainTextAccountInfo = JSON.stringify(keys);
18-
const spedingPwd: string = spendingPassword || '';
18+
const spedingPwd: string = unlockWalletPassword || '';
1919
const encryptedTextAccountInfo = aesEncrypt(spedingPwd, plainTextAccountInfo);
2020
localStorage.setItem(WALLET_ENCRYPTED_KEYS, encryptedTextAccountInfo);
2121
}
2222

2323
// eslint-disable-next-line flowtype/space-after-type-colon
2424
export function readEncryptedAccountInfo(
25-
spendingPassword: ?string
25+
unlockWalletPassword: ?string
2626
): ?AccountKeys {
2727
const encryptedHex = localStorage.getItem(WALLET_ENCRYPTED_KEYS);
2828
try {
2929
if (encryptedHex && encryptedHex.length > 0) {
30-
const plainText = aesDecrypt(spendingPassword, encryptedHex);
30+
const plainText = aesDecrypt(unlockWalletPassword, encryptedHex);
3131
const accountKeys = JSON.parse(plainText);
3232
return accountKeys;
3333
}

0 commit comments

Comments
 (0)