diff --git a/src/app/auth/create/step-1.tsx b/src/app/auth/create/step-1.tsx index 8341f324..e3533890 100644 --- a/src/app/auth/create/step-1.tsx +++ b/src/app/auth/create/step-1.tsx @@ -9,15 +9,14 @@ import { Button } from '@shared/button'; import { EyeOffIcon, EyeOnIcon, LoaderIcon } from '@shared/icons'; import { useOnboarding } from '@stores/onboarding'; +import { useStronghold } from '@stores/stronghold'; export function CreateStep1Screen() { - const navigate = useNavigate(); const queryClient = useQueryClient(); + const navigate = useNavigate(); + const setPrivkey = useStronghold((state) => state.setPrivkey); + const setPubkey = useOnboarding((state) => state.setPubkey); - const [setPubkey, setPrivkey] = useOnboarding((state) => [ - state.setPubkey, - state.setPrivkey, - ]); const [privkeyInput, setPrivkeyInput] = useState('password'); const [loading, setLoading] = useState(false); diff --git a/src/app/auth/create/step-2.tsx b/src/app/auth/create/step-2.tsx index 7ecf2fb4..19388650 100644 --- a/src/app/auth/create/step-2.tsx +++ b/src/app/auth/create/step-2.tsx @@ -29,11 +29,15 @@ const resolver: Resolver = async (values) => { export function CreateStep2Screen() { const navigate = useNavigate(); - const setPassword = useStronghold((state) => state.setPassword); - const [pubkey, privkey] = useOnboarding((state) => [state.pubkey, state.privkey]); const [passwordInput, setPasswordInput] = useState('password'); const [loading, setLoading] = useState(false); + const [privkey, setPassword] = useStronghold((state) => [ + state.privkey, + state.setPassword, + ]); + + const pubkey = useOnboarding((state) => state.privkey); const { save } = useSecureStorage(); diff --git a/src/app/auth/create/step-5.tsx b/src/app/auth/create/step-5.tsx index f9132426..fd86eeff 100644 --- a/src/app/auth/create/step-5.tsx +++ b/src/app/auth/create/step-5.tsx @@ -163,7 +163,7 @@ export function CreateStep5Screen() { } }; - const list = data ? data.profiles.concat(INITIAL_LIST) : []; + const list = data ? data.profiles.concat(INITIAL_LIST) : INITIAL_LIST; return (
diff --git a/src/app/auth/import/step-1.tsx b/src/app/auth/import/step-1.tsx index 0c73349d..3b4e6e63 100644 --- a/src/app/auth/import/step-1.tsx +++ b/src/app/auth/import/step-1.tsx @@ -9,6 +9,7 @@ import { createAccount } from '@libs/storage'; import { LoaderIcon } from '@shared/icons'; import { useOnboarding } from '@stores/onboarding'; +import { useStronghold } from '@stores/stronghold'; type FormValues = { privkey: string; @@ -31,11 +32,9 @@ const resolver: Resolver = async (values) => { export function ImportStep1Screen() { const queryClient = useQueryClient(); const navigate = useNavigate(); + const setPrivkey = useStronghold((state) => state.setPrivkey); + const setPubkey = useOnboarding((state) => state.setPubkey); - const [setPubkey, setPrivkey] = useOnboarding((state) => [ - state.setPubkey, - state.setPrivkey, - ]); const [loading, setLoading] = useState(false); const account = useMutation({ @@ -74,6 +73,7 @@ export function ImportStep1Screen() { // use for onboarding process only setPubkey(pubkey); + // add stronghold state setPrivkey(privkey); // add account to local database diff --git a/src/app/auth/import/step-2.tsx b/src/app/auth/import/step-2.tsx index 6a65cc0d..3d5cd54c 100644 --- a/src/app/auth/import/step-2.tsx +++ b/src/app/auth/import/step-2.tsx @@ -29,11 +29,15 @@ const resolver: Resolver = async (values) => { export function ImportStep2Screen() { const navigate = useNavigate(); - const setPassword = useStronghold((state) => state.setPassword); const [passwordInput, setPasswordInput] = useState('password'); const [loading, setLoading] = useState(false); - const [pubkey, privkey] = useOnboarding((state) => [state.pubkey, state.privkey]); + const [privkey, setPassword] = useStronghold((state) => [ + state.privkey, + state.setPassword, + ]); + + const pubkey = useOnboarding((state) => state.pubkey); const { save } = useSecureStorage(); diff --git a/src/app/auth/migrate.tsx b/src/app/auth/migrate.tsx index ce8f857b..ed174eee 100644 --- a/src/app/auth/migrate.tsx +++ b/src/app/auth/migrate.tsx @@ -5,7 +5,7 @@ import { useNavigate } from 'react-router-dom'; import { removePrivkey } from '@libs/storage'; -import { CheckCircleIcon, EyeOffIcon, EyeOnIcon, LoaderIcon } from '@shared/icons'; +import { EyeOffIcon, EyeOnIcon, LoaderIcon } from '@shared/icons'; import { useStronghold } from '@stores/stronghold'; @@ -35,14 +35,15 @@ export function MigrateScreen() { const navigate = useNavigate(); const [passwordInput, setPasswordInput] = useState('password'); - const [passwordStep, setPasswordStep] = useState({ loading: false, done: false }); - const [privkeyStep, setPrivkeyStep] = useState({ loading: false, done: false }); + const [loading, setLoading] = useState(false); + const [setPassword, setPrivkey] = useStronghold((state) => [ + state.setPassword, + state.setPrivkey, + ]); const { account } = useAccount(); const { save } = useSecureStorage(); - const setPassword = useStronghold((state) => state.setPassword); - // toggle private key const showPassword = () => { if (passwordInput === 'password') { @@ -52,16 +53,6 @@ export function MigrateScreen() { } }; - const clearPrivkey = async () => { - setPrivkeyStep((prev) => ({ ...prev, loading: true })); - const res = await removePrivkey(); - if (res) { - setPrivkeyStep({ done: true, loading: false }); - } else { - setPrivkeyStep((prev) => ({ ...prev, loading: false })); - } - }; - const { register, setError, @@ -70,27 +61,32 @@ export function MigrateScreen() { } = useForm({ resolver }); const onSubmit = async (data: { [x: string]: string }) => { - setPasswordStep((prev) => ({ ...prev, loading: true })); + setLoading(true); if (data.password.length > 3) { // add password to local state setPassword(data.password); // load private in secure storage try { + // save privkey to secure storage await save(account.pubkey, account.privkey, data.password); + // add privkey to state + setPrivkey(account.privkey); + // remove privkey in db + await removePrivkey(); // clear cache await queryClient.invalidateQueries(['currentAccount']); // redirect to home navigate('/', { replace: true }); } catch { - setPasswordStep((prev) => ({ ...prev, loading: false })); + setLoading(false); setError('password', { type: 'custom', message: 'Wrong password', }); } } else { - setPasswordStep((prev) => ({ ...prev, loading: false })); + setLoading(false); setError('password', { type: 'custom', message: 'Password is required and must be greater than 3', @@ -109,53 +105,25 @@ export function MigrateScreen() {
-

- Remove plaintext privkey store in local database -

You're using old Lume version which store your private key as plaintext in database, this is huge security risk.

-

To secure your private key

-
    -
  • Firstly, click button below to remove it from local database
  • -
  • - Then set password and Lume will put your private key in secure storage -
  • -
-
-
-
- -
- {privkeyStep.done ? ( - privkeyStep.loading ? ( - - ) : ( - - ) - ) : ( - - )} -
-
+

+ To secure your private key, please set a password and Lume will put your + private key in secure storage. +

+

+ It is not possible to start the app without applying this step, it is + easy and fast! +

- Set password to protect your key + Set a password to protect your key
- {privkeyStep.done && ( - - )} +