From e7027c169a30d6ec6bf555e7ba405667eb8e6e2d Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Fri, 11 Feb 2022 16:31:42 -0300 Subject: [PATCH] fix some things. --- handlers/EventSigning.jsx | 30 ++++++++++++++++++------------ package.json | 2 +- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/handlers/EventSigning.jsx b/handlers/EventSigning.jsx index c096a36..eda9cff 100644 --- a/handlers/EventSigning.jsx +++ b/handlers/EventSigning.jsx @@ -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 ( diff --git a/package.json b/package.json index c6c5306..4fc03d0 100644 --- a/package.json +++ b/package.json @@ -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",