mirror of
https://github.com/fiatjaf/nak.git
synced 2024-10-30 00:59:07 -04:00
fix some things.
This commit is contained in:
parent
78b5cccfc2
commit
e7027c169a
|
@ -1,5 +1,4 @@
|
|||
import React, {useState, useEffect} from 'react'
|
||||
import useBooleanState from 'use-boolean-state'
|
||||
import React, {useState} from 'react'
|
||||
import useComputedState from 'use-computed-state'
|
||||
import {
|
||||
getPublicKey,
|
||||
|
@ -12,10 +11,10 @@ import {
|
|||
import Item from '../components/item'
|
||||
|
||||
export default function EventSigning({value}) {
|
||||
let evt = JSON.parse(value)
|
||||
let [privateKey, setPrivateKey] = useState(
|
||||
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
|
||||
)
|
||||
let [isValidSignature, signatureGood, signatureBad] = useBooleanState(false)
|
||||
let privateKeyIsValid = useComputedState(
|
||||
() => privateKey.match(/[a-f0-9]{64}/),
|
||||
[privateKey]
|
||||
|
@ -25,16 +24,23 @@ export default function EventSigning({value}) {
|
|||
[privateKeyIsValid]
|
||||
)
|
||||
let signature = useComputedState(async () => {
|
||||
evt.pubkey = publicKey
|
||||
return await signEvent(evt, privateKey)
|
||||
try {
|
||||
evt.pubkey = publicKey
|
||||
return await signEvent(evt, privateKey)
|
||||
} catch (err) {
|
||||
return null
|
||||
}
|
||||
}, [value, privateKey])
|
||||
|
||||
let evt = JSON.parse(value)
|
||||
|
||||
useEffect(() => {
|
||||
verifySignature(evt)
|
||||
.then(ok => (ok ? signatureGood() : signatureBad()))
|
||||
.catch(signatureBad)
|
||||
let isValidSignature = useComputedState(async () => {
|
||||
if (evt.id && evt.signature) {
|
||||
try {
|
||||
return await verifySignature(evt)
|
||||
} catch (err) {
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}, [value])
|
||||
|
||||
return (
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"esbuild": "^0.14.21",
|
||||
"esbuild-plugin-alias": "^0.2.1",
|
||||
"events": "^3.3.0",
|
||||
"nostr-tools": "^0.21.4",
|
||||
"nostr-tools": "^0.22.1",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
"use-boolean-state": "^1.0.2",
|
||||
|
|
Loading…
Reference in New Issue
Block a user