diff --git a/app.jsx b/app.jsx index d805203..c2d3566 100644 --- a/app.jsx +++ b/app.jsx @@ -3,8 +3,9 @@ import {render} from 'react-dom' import Nothing from './handlers/Nothing' import EventSigning from './handlers/EventSigning' +import KeyHandling from './handlers/KeyHandling' -const handlers = [EventSigning, Nothing] +const handlers = [EventSigning, KeyHandling, Nothing] function App() { let [value, setValue] = useState(localStorage.getItem('value')) diff --git a/handlers/EventSigning.jsx b/handlers/EventSigning.jsx index eda9cff..e230704 100644 --- a/handlers/EventSigning.jsx +++ b/handlers/EventSigning.jsx @@ -16,7 +16,7 @@ export default function EventSigning({value}) { 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' ) let privateKeyIsValid = useComputedState( - () => privateKey.match(/[a-f0-9]{64}/), + () => privateKey.match(/^[a-f0-9]{64}$/), [privateKey] ) let publicKey = useComputedState( diff --git a/handlers/KeyHandling.jsx b/handlers/KeyHandling.jsx new file mode 100644 index 0000000..fc2f55f --- /dev/null +++ b/handlers/KeyHandling.jsx @@ -0,0 +1,27 @@ +import React from 'react' +import useBooleanState from 'use-boolean-state' + +import {getPublicKey} from 'nostr-tools' + +import Item from '../components/item' + +export default function KeyHandling({value}) { + let privateKey = value + let publicKey = getPublicKey(privateKey) + + return ( + <> + {privateKey} + {publicKey} + + ) +} + +KeyHandling.match = value => { + try { + if (value.toLowerCase().match(/^[a-f0-9]{64}$/)) return true + } catch (err) { + /**/ + } + return false +}