From bf28887ea16e80d0af019fc469afcd5e3bb41adc Mon Sep 17 00:00:00 2001 From: noumantahir Date: Thu, 18 Apr 2024 18:07:22 +0500 Subject: [PATCH 1/2] make key updated do not overwrite already existing keys --- src/providers/hive/auth.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/providers/hive/auth.js b/src/providers/hive/auth.js index 44422b256b..4926ae1b91 100644 --- a/src/providers/hive/auth.js +++ b/src/providers/hive/auth.js @@ -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', ''), }; }; From de8e2252b7dc13b8fb6c879f5c2baadd614ee9a4 Mon Sep 17 00:00:00 2001 From: noumantahir Date: Thu, 18 Apr 2024 18:07:50 +0500 Subject: [PATCH 2/2] make sure to only update imported private key and not duplicate to all key types --- src/providers/hive/auth.js | 32 ++++++++++++++----- .../importPrivateKeyModal.tsx | 2 -- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/providers/hive/auth.js b/src/providers/hive/auth.js index 4926ae1b91..a94a749ea6 100644 --- a/src/providers/hive/auth.js +++ b/src/providers/hive/auth.js @@ -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')); diff --git a/src/screens/backupKeysScreen/importPrivateKeyModal.tsx b/src/screens/backupKeysScreen/importPrivateKeyModal.tsx index 04bfd4cd1d..cee12f3cce 100644 --- a/src/screens/backupKeysScreen/importPrivateKeyModal.tsx +++ b/src/screens/backupKeysScreen/importPrivateKeyModal.tsx @@ -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);