Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add message signing and verifying #97

Merged
merged 5 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/EditAccountModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ function EditAccountModal({
isSubmitted={isSubmitted}
/>
<Text color="orange" my={4} fontSize="xs" textAlign="center">
Any changes to the parameters below will alter the account address.
Any changes to the parameters below will alter the account
address.
<br />
Proceed at your own risk.
</Text>
Expand Down
145 changes: 93 additions & 52 deletions src/components/KeyManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
IconKey,
IconPlus,
IconTrash,
IconWritingSign,
} from '@tabler/icons-react';

import useConfirmation from '../hooks/useConfirmation';
Expand Down Expand Up @@ -64,6 +65,7 @@ import ImportKeyFromLedgerModal from './ImportKeyFromLedgerModal';
import ImportKeyPairModal from './ImportKeyPairModal';
import RenameKeyModal from './RenameKeyModal';
import RevealSecretKeyModal from './RevealSecretKeyModal';
import SignMessageModal from './SignMessageModal';

type KeyManagerProps = {
isOpen: boolean;
Expand Down Expand Up @@ -117,9 +119,11 @@ function KeyManager({ isOpen, onClose }: KeyManagerProps): JSX.Element {
const createAccountModal = useDisclosure();
const importAccountModal = useDisclosure();
const editAccountModal = useDisclosure();
const signMessageModal = useDisclosure();

const [renameKeyIdx, setRenameKeyIdx] = useState(0);
const [editAccountIdx, setEditAccountIdx] = useState(0);
const [signMessageByKeyIndex, setSignMessageByKeyIndex] = useState(0);

const closeHandler = () => {
onClose();
Expand Down Expand Up @@ -241,59 +245,91 @@ function KeyManager({ isOpen, onClose }: KeyManagerProps): JSX.Element {
backgroundColor="blackAlpha.300"
borderRadius="md"
>
{key.type === KeyPairType.Software ? (
<Button
size="xx-small"
p={1}
fontSize="xx-small"
fontWeight="normal"
float="right"
display="flex"
alignItems="center"
borderRadius="sm"
textTransform="uppercase"
gap={1}
onClick={() => revealSecretKey(key)}
variant="ghostWhite"
>
<IconKey size={12} />
Export secret key
</Button>
) : (
<Badge
p={1}
fontSize="xx-small"
fontWeight="normal"
float="right"
display="flex"
alignItems="center"
colorScheme="orange"
gap={1}
>
<IconDeviceUsb size={12} />
Hardware
</Badge>
)}
<Text fontWeight="bold" mb={1}>
<Flex
float="right"
flexDir={{ base: 'column', sm: 'row-reverse' }}
alignItems="flex-end"
gap={{ base: 1, sm: 2 }}
>
{key.type === KeyPairType.Software ? (
<>
<Button
size="xx-small"
p={1}
fontSize="xx-small"
fontWeight="normal"
display="flex"
alignItems="center"
borderRadius="sm"
textTransform="uppercase"
gap={1}
onClick={() => revealSecretKey(key)}
variant="ghostWhite"
>
<IconKey size={12} />
Export secret key
</Button>
<Button
size="xx-small"
p={1}
fontSize="xx-small"
fontWeight="normal"
display="flex"
alignItems="center"
borderRadius="sm"
textTransform="uppercase"
gap={1}
onClick={() => {
setSignMessageByKeyIndex(idx);
signMessageModal.onOpen();
}}
variant="ghostWhite"
>
<IconWritingSign size={12} />
Sign message
</Button>
</>
) : (
<Badge
p={1}
fontSize="xx-small"
fontWeight="normal"
display="flex"
alignItems="center"
colorScheme="orange"
gap={1}
>
<IconDeviceUsb size={12} />
Hardware
</Badge>
)}
</Flex>
<Text as="div" fontWeight="bold" mb={1}>
{key.displayName}
<IconButton
ml={2}
aria-label="Rename key"
onClick={() => onRenameKey(idx)}
icon={<IconEdit size={12} />}
variant="whiteOutline"
borderWidth={1}
size="xs"
/>
<IconButton
ml={1}
aria-label="Delete key"
onClick={() => onDeleteKey(idx)}
icon={<IconTrash size={12} />}
variant="dangerOutline"
borderWidth={1}
size="xs"
/>
<Box
display={{ base: 'block', sm: 'inline-block' }}
ml={{ base: 0, sm: 2 }}
my={{ base: 2, sm: 0 }}
>
<IconButton
aria-label="Rename key"
onClick={() => onRenameKey(idx)}
icon={<IconEdit size={12} />}
variant="whiteOutline"
borderWidth={1}
size="xs"
mr={1}
/>
<IconButton
aria-label="Delete key"
onClick={() => onDeleteKey(idx)}
icon={<IconTrash size={12} />}
variant="dangerOutline"
borderWidth={1}
size="xs"
mr={1}
/>
</Box>
</Text>

<Text fontSize="xx-small">Public Key</Text>
Expand Down Expand Up @@ -483,6 +519,11 @@ function KeyManager({ isOpen, onClose }: KeyManagerProps): JSX.Element {
isOpen={editAccountModal.isOpen}
onClose={editAccountModal.onClose}
/>
<SignMessageModal
keyIndex={signMessageByKeyIndex}
isOpen={signMessageModal.isOpen}
onClose={signMessageModal.onClose}
/>
</DrawerBody>
</DrawerContent>
</Drawer>
Expand Down
10 changes: 10 additions & 0 deletions src/components/MainMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { MAIN_MENU_BUTTONS_SIZE } from '../utils/constants';

import KeyManager from './KeyManager';
import MnemonicsModal from './MnemonicsModal';
import VerifyMessageModal from './VerifyMessageModal';
import WipeOutAlert from './WipeOutAlert';

function MainMenu(): JSX.Element {
Expand All @@ -24,6 +25,7 @@ function MainMenu(): JSX.Element {
const wipeAlert = useDisclosure();

const keyManagerDrawer = useDisclosure();
const verifyMessageModal = useDisclosure();
const { revealMnemonics } = useMnemonics();
const iconSize = useBreakpointValue(MAIN_MENU_BUTTONS_SIZE, { ssr: false });

Expand All @@ -46,6 +48,10 @@ function MainMenu(): JSX.Element {
<MenuItem onClick={revealMnemonics}>Backup mnemonic</MenuItem>
<MenuItem onClick={exportWalletFile}>Export wallet file</MenuItem>
<MenuDivider />
<MenuItem onClick={verifyMessageModal.onOpen}>
Verify Message
</MenuItem>
<MenuDivider />
<MenuItem color="red" onClick={wipeAlert.onOpen}>
Wipe out
</MenuItem>
Expand All @@ -57,6 +63,10 @@ function MainMenu(): JSX.Element {
isOpen={keyManagerDrawer.isOpen}
onClose={keyManagerDrawer.onClose}
/>
<VerifyMessageModal
isOpen={verifyMessageModal.isOpen}
onClose={verifyMessageModal.onClose}
/>
</>
);
}
Expand Down
Empty file removed src/components/SignMessage.tsx
Empty file.
Loading