mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 16:48:50 +00:00
verifySignature: return false if the id is invalid
This commit is contained in:
8
event.ts
8
event.ts
@@ -115,8 +115,14 @@ export function validateEvent<T>(event: T): event is T & UnsignedEvent<number> {
|
||||
/** Verify the event's signature. This function mutates the event with a `verified` symbol, making it idempotent. */
|
||||
export function verifySignature<K extends number>(event: Event<K>): event is VerifiedEvent<K> {
|
||||
if (typeof event[verifiedSymbol] === 'boolean') return event[verifiedSymbol]
|
||||
|
||||
const hash = getEventHash(event)
|
||||
if (hash !== event.id) {
|
||||
return false
|
||||
}
|
||||
|
||||
try {
|
||||
event[verifiedSymbol] = schnorr.verify(event.sig, getEventHash(event), event.pubkey)
|
||||
event[verifiedSymbol] = schnorr.verify(event.sig, hash, event.pubkey)
|
||||
return event[verifiedSymbol]
|
||||
} catch (err) {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user