-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from davidreis97/master
0.0.3
- Loading branch information
Showing
11 changed files
with
134 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "jwt-editor" | ||
version = "0.0.2" | ||
version = "0.0.3" | ||
description = "JWT Editor" | ||
authors = ["[email protected]"] | ||
license = "MIT" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,42 @@ | ||
import { Flex, Text, Textarea } from "@mantine/core" | ||
import KeyPair from "../helpers/key-pair"; | ||
import { isValidAsymmetricKey } from "../logic/crypto"; | ||
import { useEffect, useState } from "react"; | ||
|
||
interface AsymmetricSignatureInputProps { | ||
onPublicKeyChange: (pubKey: string) => void | ||
onPrivateKeyChange: (privKey: string) => void | ||
keyPair: KeyPair | ||
keyPair: KeyPair, | ||
algorithm: string, | ||
} | ||
|
||
function validateKeyField(key: string, setIsValid: (valid: boolean) => void, algorithm: string) { | ||
useEffect(() => { | ||
async function parseKey() { | ||
setIsValid(await isValidAsymmetricKey(key, algorithm)) | ||
} | ||
|
||
if (!!!key) | ||
setIsValid(true); | ||
else | ||
parseKey() | ||
}, [key]) | ||
} | ||
|
||
export default function AsymmetricSignatureInput(props: AsymmetricSignatureInputProps) { | ||
const [validPublicKey, setValidPublicKey] = useState<boolean>(true); | ||
const [validPrivateKey, setValidPrivateKey] = useState<boolean>(true); | ||
|
||
validateKeyField(props.keyPair.publicKey, setValidPublicKey, props.algorithm) | ||
validateKeyField(props.keyPair.privateKey, setValidPrivateKey, props.algorithm) | ||
|
||
return ( | ||
<> | ||
<Flex ml="md" align="end"> | ||
<Textarea value={props.keyPair.publicKey} placeholder="Public Key" onChange={(evt) => props.onPublicKeyChange(evt.target.value)} /> | ||
<Textarea error={!validPublicKey} value={props.keyPair.publicKey} placeholder="Public Key" onChange={(evt) => props.onPublicKeyChange(evt.target.value)} /> | ||
<Text>,</Text> | ||
</Flex> | ||
<Textarea value={props.keyPair.privateKey} mt="0.3rem" w="fit-content" ml="md" placeholder="Private Key" onChange={(evt) => props.onPrivateKeyChange(evt.target.value)} /> | ||
<Textarea error={!validPrivateKey} value={props.keyPair.privateKey} mt="0.3rem" w="fit-content" ml="md" placeholder="Private Key" onChange={(evt) => props.onPrivateKeyChange(evt.target.value)} /> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export function canJsonParse(data: string) { | ||
if (!!!data) | ||
return true; | ||
|
||
try { | ||
JSON.parse(data) | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
|
||
export function formatJson(data: string) { | ||
try { | ||
const obj = JSON.parse(data); | ||
return JSON.stringify(obj, null, 2) | ||
} catch (e) { | ||
return data | ||
} | ||
} | ||
|
||
export function cleanUpJsonInput(data: string) { | ||
return data | ||
.replace(/[\u2018\u2019]/g, "'") | ||
.replace(/[\u201C\u201D]/g, '"') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useState, useEffect } from "react"; | ||
|
||
export default function useActiveElement() { | ||
const [active, setActive] = useState(document.activeElement); | ||
|
||
const handleFocusIn = () => { | ||
setActive(document.activeElement); | ||
} | ||
|
||
useEffect(() => { | ||
document.addEventListener('focusin', handleFocusIn) | ||
return () => { | ||
document.removeEventListener('focusin', handleFocusIn) | ||
}; | ||
}, []) | ||
|
||
return active; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters