Skip to content

Commit

Permalink
Fix master key settings
Browse files Browse the repository at this point in the history
  • Loading branch information
m-pilarczyk committed Jan 16, 2019
1 parent 37bc470 commit eebae41
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 228 deletions.
73 changes: 0 additions & 73 deletions app/components/settingsList/SettingsList.css

This file was deleted.

113 changes: 0 additions & 113 deletions app/components/settingsList/SettingsList.js

This file was deleted.

2 changes: 1 addition & 1 deletion app/containers/Settings/KeysSettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class KeysSettingsPage extends PageComponent {
const { keys } = this.props.vault;

const importedKeys = keys.filter(key => key.type === 'imported');
const generatedKeys = keys.filter(key => key.type === 'auto');
const generatedKeys = keys.filter(key => key.type === 'master' || key.type === 'auto');

return (
<Page
Expand Down
20 changes: 1 addition & 19 deletions app/containers/Settings/SeedPhrasePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,8 @@ class SeedPhrasePage extends PageComponent {
render() {
const { vault, authDialog } = this.props;
let seedPhrase = ''.padStart(86, 'X');
let publicKey = ''.padStart(64, 'X');
let secretKey = ''.padStart(64, 'X');
if (authDialog.isConfirmed && authDialog.name === 'seedPhrase') {
const key = vault.keys.filter(k => k.type === 'master')[0];
seedPhrase = vault.seedPhrase;
publicKey = key.publicKey;
secretKey = key.secretKey;
}

return (
Expand All @@ -44,27 +39,14 @@ class SeedPhrasePage extends PageComponent {
>
<Form>
<Box layout="warning" icon={faExclamation}>
Store the seed phrase safely. Only the public key and signatures can be revealed.
The seed phrase and secret key must not be transferred to anyone.
Store the seed phrase safely. The seed phrase must not be transferred to anyone.
</Box>
<InputControl
value={seedPhrase}
rows={3}
readOnly
label="Seed Phrase"
/>
<InputControl
value={publicKey}
rows={2}
readOnly
label="Public key"
/>
<InputControl
value={secretKey}
rows={2}
readOnly
label="Secret key"
/>
<ButtonLink
to={this.getReferrer()}
icon="left"
Expand Down
2 changes: 1 addition & 1 deletion app/reducers/VaultReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export default function (vault = initialVault, action) {
case actions.REMOVE_KEY: {
const updatedVault = {
...vault,
keys: vault.keys.filter(k => k.type === 'auto' || k.publicKey !== action.publicKey)
keys: vault.keys.filter(k => k.type !== 'imported' || k.publicKey !== action.publicKey)
};

updatedVault.secret = VaultCrypt.save(updatedVault, action.password, action.callback);
Expand Down
50 changes: 29 additions & 21 deletions app/utils/vaultcrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ const SEED_PHRASE = 'p';
const SEED = 's';
const KEY_COUNT = 'c';
const KEYS = 'k';
const KEY_SK = 's';
const KEY_NAME = 'n';
const ACCOUNTS = 'a';
const ACCOUNT_ADDRESS = 'a';
const ACCOUNT_NAME = 'n';
// const SETTINGS = 'o';

function checkPassword(vault, password) {
try {
Expand All @@ -23,24 +24,27 @@ function checkPassword(vault, password) {
}

function encrypt(vault, password) {
const keys = vault.keys
.filter(key => key.type && key.type !== 'auto')
// eslint-disable-next-line no-unused-vars
.map(({ publicKey, ...keysToKeep }) => keysToKeep);
const crypt = CryptoJS.AES.encrypt(JSON.stringify({
const data = JSON.stringify({
[SEED_PHRASE]: vault.seedPhrase,
[SEED]: vault.seed,
[KEY_COUNT]: vault.keyCount,
[KEYS]: keys,
[ACCOUNTS]: vault.accounts.map(account => (
{
[ACCOUNT_ADDRESS]: account.address,
[ACCOUNT_NAME]: account.name,
}
)),
}), password)
.toString();
return crypt;
[KEYS]: vault.keys
.filter(key => key.type && key.type === 'imported')
.map(key => (
{
[KEY_SK]: key.secretKey,
[KEY_NAME]: key.name,
}
)),
[ACCOUNTS]: vault.accounts
.map(account => (
{
[ACCOUNT_ADDRESS]: account.address,
[ACCOUNT_NAME]: account.name,
}
)),
});
return CryptoJS.AES.encrypt(data, password).toString();;
}

function decrypt(encryptedVault, password) {
Expand All @@ -52,7 +56,14 @@ function decrypt(encryptedVault, password) {
seedPhrase: vault[SEED_PHRASE],
seed: vault[SEED],
keyCount: vault[KEY_COUNT],
keys: vault[KEYS] || [],
keys: vault[KEYS].map(key => (
{
secretKey: key[KEY_SK] || key.secretKey,
name: key[KEY_NAME] || key.name,
type: 'imported',
publicKey: KeyBox.getPublicKeyFromSecret(key[KEY_SK] || key.secretKey),
}
)),
accounts: vault[ACCOUNTS].map(account => (
{
address: account[ACCOUNT_ADDRESS],
Expand All @@ -61,10 +72,7 @@ function decrypt(encryptedVault, password) {
)),
};
const keys = [
...decryptedVault.keys.map(key => ({
...key,
publicKey: KeyBox.getPublicKeyFromSecret(key.secretKey),
})),
...decryptedVault.keys,
...KeyBox.initKeys(
decryptedVault.seed,
decryptedVault.keyCount || config.initKeysQuantity
Expand Down

0 comments on commit eebae41

Please sign in to comment.