From 8b3da1b85f86c07ebe8f3e248e6bdee4396d7e8e Mon Sep 17 00:00:00 2001 From: Mustafa Buyukcelebi Date: Wed, 9 Jan 2019 17:34:32 +0300 Subject: [PATCH] Added migration for pin --- src/providers/steem/auth.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/providers/steem/auth.js b/src/providers/steem/auth.js index a08080a4b..c47cf27ce 100644 --- a/src/providers/steem/auth.js +++ b/src/providers/steem/auth.js @@ -178,12 +178,27 @@ export const updatePinCode = async (data) => { export const verifyPinCode = async (data) => { const pinHash = await getPinCode(); + const result = getUserDataWithUsername(data.username); + const userData = result[0]; + + // This is migration for new pin structure, it will remove v2.2 + if (!pinHash) { + try { + if (userData.authType === 'steemConnect') { + decryptKey(userData.accessToken, data.pinCode); + } else { + decryptKey(userData.masterKey, data.pinCode); + } + await setPinCode(data.pinCode); + } catch (error) { + return Promise.reject(new Error('Invalid pin code, please check and try again')); + } + } + if (sha256(data.pinCode).toString() !== pinHash) { return Promise.reject(new Error('Invalid pin code, please check and try again')); } - const result = getUserDataWithUsername(data.username); - const userData = result[0]; if (result.length > 0) { if (userData.authType === 'steemConnect') { await refreshSCToken(userData, data.pinCode);