From 08015ed306e070c9076dc5d499016b20640d3766 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Mon, 14 Feb 2022 13:15:00 -0300 Subject: [PATCH] add isValidHash field. --- handlers/EventSigning.jsx | 52 ++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/handlers/EventSigning.jsx b/handlers/EventSigning.jsx index 8dc3916..4d0bedf 100644 --- a/handlers/EventSigning.jsx +++ b/handlers/EventSigning.jsx @@ -33,6 +33,11 @@ export default function EventSigning({value}) { return null } }, [value, privateKey]) + let eventHash = useComputedState(() => getEventHash(evt), [value]) + let isValidHash = useComputedState( + () => evt.id === eventHash, + [value, eventHash] + ) let isValidSignature = useComputedState(async () => { if (evt.id && evt.sig) { try { @@ -54,28 +59,35 @@ export default function EventSigning({value}) { {serializeEvent(evt)} - {getEventHash(evt)} + {eventHash} - {evt.sig ? ( - - {isValidSignature?.toString() || ''} - - ) : ( - <> - - setPrivateKey(e.target.value.toLowerCase())} - />{' '} - {privateKeyIsValid ? 'valid' : 'invalid'} + + {isValidHash?.toString()} + + {isValidHash && + (evt.sig ? ( + + {isValidSignature?.toString() || ''} - {publicKey} - {privateKeyIsValid ? signature : ''} - - )} + ) : ( + <> + + setPrivateKey(e.target.value.toLowerCase())} + />{' '} + {privateKeyIsValid ? 'valid' : 'invalid'} + + {publicKey} + {privateKeyIsValid ? signature : ''} + + ))} ) }