From 05202229a556887cab64a7d6596fff1498450c71 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 9 Jul 2026 15:17:57 -0500 Subject: [PATCH] Validate gift-wrap event id even when skipping Schnorr verify Returning true unconditionally for wrap kinds also skipped the event id (content hash) check. The id is what we index and dedupe on, so it must still match the event's contents. Recompute the hash and compare it while continuing to skip only the redundant outer signature verification. --- src/components/NostrProvider.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/NostrProvider.tsx b/src/components/NostrProvider.tsx index 32b8a43..1a03c1e 100644 --- a/src/components/NostrProvider.tsx +++ b/src/components/NostrProvider.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useMemo, useRef, useState } from 'react'; import { type NostrSigner, NostrEvent, NostrFilter, NPool, NRelay1 } from '@nostrify/nostrify'; -import { verifyEvent } from 'nostr-tools'; +import { getEventHash, verifyEvent } from 'nostr-tools'; import { NostrContext } from '@nostrify/react'; import { NUser, useNostrLogin } from '@nostrify/react/login'; import { useQueryClient } from '@tanstack/react-query'; @@ -36,9 +36,14 @@ const NostrProvider: React.FC = (props) => { open(url: string) { return new NRelay1(url, { // Gift-wrap (1059/21059) outer signatures are redundant on the client - // skip them, verify everything else. + // (ephemeral or group-shared key), so skip the Schnorr verify for them. + // The event id (content hash) must still be validated so that the id we + // index/dedupe on actually matches the event's contents; only the + // signature check is redundant. Verify everything else in full. verifyEvent: (event: NostrEvent): boolean => { - if (event.kind === 1059 || event.kind === 21059) return true; + if (event.kind === 1059 || event.kind === 21059) { + return event.id === getEventHash(event); + } return verifyEvent(event); },