Skip to content

Commit

Permalink
Merge pull request #2861 from ecency/nt/private-import-fix
Browse files Browse the repository at this point in the history
Nt/private import fix
  • Loading branch information
feruzm authored Apr 22, 2024
2 parents 69a5215 + de8e225 commit 777b389
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
50 changes: 33 additions & 17 deletions src/providers/hive/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,27 +330,27 @@ export const getUpdatedUserData = (userData, data) => {
masterKey:
get(userData, 'authType', '') === AUTH_TYPE.MASTER_KEY
? encryptKey(data.password, get(data, 'pinCode'))
: '',
: get(userData, 'masterKey', ''),
postingKey:
get(userData, 'authType', '') === AUTH_TYPE.MASTER_KEY ||
get(userData, 'authType', '') === AUTH_TYPE.POSTING_KEY
get(userData, 'authType', '') === AUTH_TYPE.POSTING_KEY
? encryptKey(get(privateKeys, 'postingKey', '').toString(), get(data, 'pinCode'))
: '',
: get(userData, 'postingKey', ''),
activeKey:
get(userData, 'authType', '') === AUTH_TYPE.MASTER_KEY ||
get(userData, 'authType', '') === AUTH_TYPE.ACTIVE_KEY
get(userData, 'authType', '') === AUTH_TYPE.ACTIVE_KEY
? encryptKey(get(privateKeys, 'activeKey', '').toString(), get(data, 'pinCode'))
: '',
: get(userData, 'activeKey', ''),
memoKey:
get(userData, 'authType', '') === AUTH_TYPE.MASTER_KEY ||
get(userData, 'authType', '') === AUTH_TYPE.MEMO_KEY
get(userData, 'authType', '') === AUTH_TYPE.MEMO_KEY
? encryptKey(get(privateKeys, 'memoKey', '').toString(), get(data, 'pinCode'))
: '',
: get(userData, 'memoKey', ''),
ownerKey:
get(userData, 'authType', '') === AUTH_TYPE.MASTER_KEY ||
get(userData, 'authType', '') === AUTH_TYPE.OWNER_KEY
get(userData, 'authType', '') === AUTH_TYPE.OWNER_KEY
? encryptKey(get(privateKeys, 'ownerKey', '').toString(), get(data, 'pinCode'))
: '',
: get(userData, 'ownerKey', ''),
};
};

Expand All @@ -369,22 +369,38 @@ export const getUpdatedUserKeys = async (currentAccountData, data) => {
// // Set private keys of user
const privateKeys = getPrivateKeys(data.username, data.password);

// Check all keys
// Check all keys and set authType
let authType = '';
Object.keys(publicKeys).forEach((pubKey) => {
if (publicKeys[pubKey] === privateKeys[pubKey].createPublic().toString()) {
loginFlag = true;
if (privateKeys.isMasterKey) {
authType = AUTH_TYPE.MASTER_KEY;
} else {
authType = pubKey;
}
}
});



if (loginFlag) {
currentAccountData.local = {
const _prevAuthType = currentAccountData.authType

const _localData = {
...currentAccountData.local,
masterKey: encryptKey(data.password, get(data, 'pinCode')),
postingKey: encryptKey(get(privateKeys, 'postingKey', '').toString(), get(data, 'pinCode')),
activeKey: encryptKey(get(privateKeys, 'activeKey', '').toString(), get(data, 'pinCode')),
memoKey: encryptKey(get(privateKeys, 'memoKey', '').toString(), get(data, 'pinCode')),
ownerKey: encryptKey(get(privateKeys, 'ownerKey', '').toString(), get(data, 'pinCode')),
};
authType
}
const _userData = getUpdatedUserData(_localData, data)

//sustain appropriate authType;
if(_prevAuthType === AUTH_TYPE.STEEM_CONNECT){
_userData.authType = _prevAuthType;
}

await setUserData(_userData);
currentAccountData.local = _userData

return currentAccountData;
}
return Promise.reject(new Error('auth.invalid_credentials'));
Expand Down
2 changes: 0 additions & 2 deletions src/screens/backupKeysScreen/importPrivateKeyModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ export const ImportPrivateKeyModalModal = forwardRef(({}, ref) => {
getUpdatedUserKeys(currentAccount, data)
.then((result) => {
if (result) {
// Save user data to Realm DB
// await setUserData(updatedUserData);
// update user data in redux
dispatch(updateCurrentAccount({ ...result }));
setShowModal(false);
Expand Down

0 comments on commit 777b389

Please sign in to comment.