mirror of
https://github.com/fiatjaf/nak.git
synced 2024-10-30 09:09:08 -04:00
basic public key from private.
This commit is contained in:
parent
e7027c169a
commit
1d26118430
3
app.jsx
3
app.jsx
|
@ -3,8 +3,9 @@ import {render} from 'react-dom'
|
||||||
|
|
||||||
import Nothing from './handlers/Nothing'
|
import Nothing from './handlers/Nothing'
|
||||||
import EventSigning from './handlers/EventSigning'
|
import EventSigning from './handlers/EventSigning'
|
||||||
|
import KeyHandling from './handlers/KeyHandling'
|
||||||
|
|
||||||
const handlers = [EventSigning, Nothing]
|
const handlers = [EventSigning, KeyHandling, Nothing]
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
let [value, setValue] = useState(localStorage.getItem('value'))
|
let [value, setValue] = useState(localStorage.getItem('value'))
|
||||||
|
|
|
@ -16,7 +16,7 @@ export default function EventSigning({value}) {
|
||||||
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
|
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
|
||||||
)
|
)
|
||||||
let privateKeyIsValid = useComputedState(
|
let privateKeyIsValid = useComputedState(
|
||||||
() => privateKey.match(/[a-f0-9]{64}/),
|
() => privateKey.match(/^[a-f0-9]{64}$/),
|
||||||
[privateKey]
|
[privateKey]
|
||||||
)
|
)
|
||||||
let publicKey = useComputedState(
|
let publicKey = useComputedState(
|
||||||
|
|
27
handlers/KeyHandling.jsx
Normal file
27
handlers/KeyHandling.jsx
Normal 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user