add isValidHash field.

This commit is contained in:
fiatjaf 2022-02-14 13:15:00 -03:00
parent 93359bc1e8
commit 08015ed306

View File

@ -33,6 +33,11 @@ export default function EventSigning({value}) {
return null return null
} }
}, [value, privateKey]) }, [value, privateKey])
let eventHash = useComputedState(() => getEventHash(evt), [value])
let isValidHash = useComputedState(
() => evt.id === eventHash,
[value, eventHash]
)
let isValidSignature = useComputedState(async () => { let isValidSignature = useComputedState(async () => {
if (evt.id && evt.sig) { if (evt.id && evt.sig) {
try { try {
@ -54,28 +59,35 @@ export default function EventSigning({value}) {
{serializeEvent(evt)} {serializeEvent(evt)}
</Item> </Item>
<Item label="event id" hint="sha256 hash of serialized event"> <Item label="event id" hint="sha256 hash of serialized event">
{getEventHash(evt)} {eventHash}
</Item> </Item>
{evt.sig ? ( <Item
<Item label="signature valid"> label="event id matches hash"
{isValidSignature?.toString() || ''} hint="the calculated hash from event data matches the 'id' in the body?"
</Item> >
) : ( {isValidHash?.toString()}
<> </Item>
<Item {isValidHash &&
label="private key" (evt.sig ? (
hint="paste any private key here (32 bytes hex-encoded)" <Item label="signature valid">
> {isValidSignature?.toString() || ''}
<input
value={privateKey}
onChange={e => setPrivateKey(e.target.value.toLowerCase())}
/>{' '}
{privateKeyIsValid ? 'valid' : 'invalid'}
</Item> </Item>
<Item label="public key">{publicKey}</Item> ) : (
<Item label="signature">{privateKeyIsValid ? signature : ''}</Item> <>
</> <Item
)} label="private key"
hint="paste any private key here (32 bytes hex-encoded)"
>
<input
value={privateKey}
onChange={e => setPrivateKey(e.target.value.toLowerCase())}
/>{' '}
{privateKeyIsValid ? 'valid' : 'invalid'}
</Item>
<Item label="public key">{publicKey}</Item>
<Item label="signature">{privateKeyIsValid ? signature : ''}</Item>
</>
))}
</> </>
) )
} }