feat: convert privKeyBytes to hex

redux doesnt like uint8Array, rename shouldQuit to shouldQuitOnClick
pull/3083/head
yougotwill 9 months ago
parent 9a4356a6b7
commit cbf0a5b877

@ -28,13 +28,13 @@ export const BackButtonWithinContainer = ({
children, children,
margin, margin,
callback, callback,
shouldQuit, shouldQuitOnClick,
quitMessage, quitMessage,
}: { }: {
children: ReactNode; children: ReactNode;
margin?: string; margin?: string;
callback?: () => void; callback?: () => void;
shouldQuit?: boolean; shouldQuitOnClick?: boolean;
quitMessage?: string; quitMessage?: string;
}) => { }) => {
return ( return (
@ -46,7 +46,11 @@ export const BackButtonWithinContainer = ({
alignItems="flex-start" alignItems="flex-start"
> >
<div style={{ margin }}> <div style={{ margin }}>
<BackButton callback={callback} shouldQuit={shouldQuit} quitMessage={quitMessage} /> <BackButton
callback={callback}
shouldQuitOnClick={shouldQuitOnClick}
quitMessage={quitMessage}
/>
</div> </div>
{children} {children}
</StyledBackButtonContainer> </StyledBackButtonContainer>
@ -55,11 +59,11 @@ export const BackButtonWithinContainer = ({
export const BackButton = ({ export const BackButton = ({
callback, callback,
shouldQuit, shouldQuitOnClick,
quitMessage, quitMessage,
}: { }: {
callback?: () => void; callback?: () => void;
shouldQuit?: boolean; shouldQuitOnClick?: boolean;
quitMessage?: string; quitMessage?: string;
}) => { }) => {
const step = useOnboardStep(); const step = useOnboardStep();
@ -76,7 +80,7 @@ export const BackButton = ({
iconRotation={90} iconRotation={90}
padding={'0'} padding={'0'}
onClick={() => { onClick={() => {
if (shouldQuit && quitMessage) { if (shouldQuitOnClick && quitMessage) {
dispatch( dispatch(
updateQuitModal({ updateQuitModal({
title: window.i18n('warning'), title: window.i18n('warning'),

@ -3,8 +3,9 @@ import { useDispatch } from 'react-redux';
import useMount from 'react-use/lib/useMount'; import useMount from 'react-use/lib/useMount';
import { SettingsKey } from '../../../data/settings-key'; import { SettingsKey } from '../../../data/settings-key';
import { mnDecode } from '../../../session/crypto/mnemonic'; import { mnDecode } from '../../../session/crypto/mnemonic';
import { ProfileManager } from '../../../session/profile_manager/ProfileManager';
import { StringUtils } from '../../../session/utils'; import { StringUtils } from '../../../session/utils';
import { fromHex } from '../../../session/utils/String'; import { fromHex, toHex } from '../../../session/utils/String';
import LIBSESSION_CONSTANTS from '../../../session/utils/libsession/libsession_constants'; import LIBSESSION_CONSTANTS from '../../../session/utils/libsession/libsession_constants';
import { trigger } from '../../../shims/events'; import { trigger } from '../../../shims/events';
import { import {
@ -13,13 +14,13 @@ import {
setDisplayName, setDisplayName,
setDisplayNameError, setDisplayNameError,
setHexGeneratedPubKey, setHexGeneratedPubKey,
setPrivateKeyBytes, setPrivateKeyBytesHex,
setRecoveryPassword, setRecoveryPassword,
} from '../../../state/onboarding/ducks/registration'; } from '../../../state/onboarding/ducks/registration';
import { import {
useDisplayName, useDisplayName,
useDisplayNameError, useDisplayNameError,
useOnboardPrivateKeyBytes, useOnboardPrivateKeyBytesHex,
useRecoveryPassword, useRecoveryPassword,
} from '../../../state/onboarding/selectors/registration'; } from '../../../state/onboarding/selectors/registration';
import { import {
@ -35,7 +36,6 @@ import { resetRegistration } from '../RegistrationStages';
import { ContinueButton, OnboardDescription, OnboardHeading } from '../components'; import { ContinueButton, OnboardDescription, OnboardHeading } from '../components';
import { BackButtonWithinContainer } from '../components/BackButton'; import { BackButtonWithinContainer } from '../components/BackButton';
import { displayNameIsValid, sanitizeDisplayNameOrToast } from '../utils'; import { displayNameIsValid, sanitizeDisplayNameOrToast } from '../utils';
import { ProfileManager } from '../../../session/profile_manager/ProfileManager';
export type AccountDetails = { export type AccountDetails = {
recoveryPassword: string; recoveryPassword: string;
@ -59,7 +59,7 @@ async function signUp(signUpDetails: AccountDetails) {
} }
export const CreateAccount = () => { export const CreateAccount = () => {
const privateKeyBytes = useOnboardPrivateKeyBytes(); const privateKeyBytesHex = useOnboardPrivateKeyBytesHex();
const recoveryPassword = useRecoveryPassword(); const recoveryPassword = useRecoveryPassword();
const displayName = useDisplayName(); const displayName = useDisplayName();
const displayNameError = useDisplayNameError(); const displayNameError = useDisplayNameError();
@ -82,7 +82,7 @@ export const CreateAccount = () => {
const newHexPubKey = StringUtils.decode(keyPair.pubKey, 'hex'); const newHexPubKey = StringUtils.decode(keyPair.pubKey, 'hex');
dispatch(setRecoveryPassword(mnemonic)); dispatch(setRecoveryPassword(mnemonic));
dispatch(setPrivateKeyBytes(keyPair.ed25519KeyPair.privateKey)); dispatch(setPrivateKeyBytesHex(toHex(keyPair.ed25519KeyPair.privateKey)));
dispatch(setHexGeneratedPubKey(newHexPubKey)); // our 'frontend' account ID dispatch(setHexGeneratedPubKey(newHexPubKey)); // our 'frontend' account ID
} }
}; };
@ -97,7 +97,7 @@ export const CreateAccount = () => {
} }
try { try {
if (!privateKeyBytes) { if (!privateKeyBytesHex) {
throw new Error('Private key not found'); throw new Error('Private key not found');
} }
@ -122,7 +122,7 @@ export const CreateAccount = () => {
return ( return (
<BackButtonWithinContainer <BackButtonWithinContainer
margin={'2px 0 0 -36px'} margin={'2px 0 0 -36px'}
shouldQuit={true} shouldQuitOnClick={true}
quitMessage={window.i18n('onboardingBackAccountCreation')} quitMessage={window.i18n('onboardingBackAccountCreation')}
callback={() => { callback={() => {
dispatch(setDisplayName('')); dispatch(setDisplayName(''));

@ -197,7 +197,7 @@ export const RestoreAccount = () => {
return ( return (
<BackButtonWithinContainer <BackButtonWithinContainer
margin={'2px 0 0 -36px'} margin={'2px 0 0 -36px'}
shouldQuit={step !== AccountRestoration.RecoveryPassword} shouldQuitOnClick={step !== AccountRestoration.RecoveryPassword}
quitMessage={window.i18n('onboardingBackLoadAccount')} quitMessage={window.i18n('onboardingBackLoadAccount')}
callback={() => { callback={() => {
dispatch(setRecoveryPassword('')); dispatch(setRecoveryPassword(''));

@ -41,7 +41,7 @@ export type OnboardingState = {
progress: number; progress: number;
recoveryPassword: string; recoveryPassword: string;
recoveryPasswordError: string | undefined; recoveryPasswordError: string | undefined;
privateKeyBytes: Uint8Array | undefined; privateKeyBytesHex: string | undefined;
hexGeneratedPubKey: string; hexGeneratedPubKey: string;
displayName: string; displayName: string;
displayNameError: string | undefined; displayNameError: string | undefined;
@ -55,7 +55,7 @@ const initialState: OnboardingState = {
progress: 0, progress: 0,
recoveryPassword: '', recoveryPassword: '',
recoveryPasswordError: undefined, recoveryPasswordError: undefined,
privateKeyBytes: undefined, privateKeyBytesHex: undefined,
hexGeneratedPubKey: '', hexGeneratedPubKey: '',
displayName: '', displayName: '',
displayNameError: undefined, displayNameError: undefined,
@ -92,8 +92,8 @@ export const registrationSlice = createSlice({
setHexGeneratedPubKey(state, action: PayloadAction<string>) { setHexGeneratedPubKey(state, action: PayloadAction<string>) {
return { ...state, hexGeneratedPubKey: action.payload }; return { ...state, hexGeneratedPubKey: action.payload };
}, },
setPrivateKeyBytes(state, action: PayloadAction<Uint8Array>) { setPrivateKeyBytesHex(state, action: PayloadAction<string>) {
return { ...state, privateKeyBytes: action.payload }; return { ...state, privateKeyBytesHex: action.payload };
}, },
setDisplayName(state, action: PayloadAction<string>) { setDisplayName(state, action: PayloadAction<string>) {
return { ...state, displayName: action.payload }; return { ...state, displayName: action.payload };
@ -114,7 +114,7 @@ export const {
setRecoveryPassword, setRecoveryPassword,
setRecoveryPasswordError, setRecoveryPasswordError,
setHexGeneratedPubKey, setHexGeneratedPubKey,
setPrivateKeyBytes, setPrivateKeyBytesHex,
setDisplayName, setDisplayName,
setDisplayNameError, setDisplayNameError,
} = registrationSlice.actions; } = registrationSlice.actions;

@ -54,9 +54,9 @@ const getHexGeneratedPubKey = createSelector(
(state: OnboardingState): string => state.hexGeneratedPubKey (state: OnboardingState): string => state.hexGeneratedPubKey
); );
const getPrivateKeyBytes = createSelector( const getPrivateKeyBytesHex = createSelector(
getRegistration, getRegistration,
(state: OnboardingState): Uint8Array | undefined => state.privateKeyBytes (state: OnboardingState): string | undefined => state.privateKeyBytesHex
); );
const getDisplayName = createSelector( const getDisplayName = createSelector(
@ -103,8 +103,8 @@ export const useOnboardHexGeneratedPubKey = () => {
return useSelector(getHexGeneratedPubKey); return useSelector(getHexGeneratedPubKey);
}; };
export const useOnboardPrivateKeyBytes = () => { export const useOnboardPrivateKeyBytesHex = () => {
return useSelector(getPrivateKeyBytes); return useSelector(getPrivateKeyBytesHex);
}; };
export const useDisplayName = () => { export const useDisplayName = () => {

Loading…
Cancel
Save