basic public key from private.

This commit is contained in:
fiatjaf 2022-02-11 16:47:50 -03:00
parent e7027c169a
commit 1d26118430
3 changed files with 30 additions and 2 deletions

View File

@ -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'))

View File

@ -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(

27
handlers/KeyHandling.jsx Normal file
View File

@ -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 (
<>
<Item label="private key">{privateKey}</Item>
<Item label="public key">{publicKey}</Item>
</>
)
}
KeyHandling.match = value => {
try {
if (value.toLowerCase().match(/^[a-f0-9]{64}$/)) return true
} catch (err) {
/**/
}
return false
}