Fix REQ message handling to support multiple filter subscriptions (#34)

This fix addresses an issue where REQ messages with multiple filters
were being rejected by the relay. Notably: The nostrmarket extension's
"Refresh from Nostr" functionality sends a single REQ message containing
4 different filter subscriptions:
- Direct Messages (kinds: [4])
- Stalls (kinds: [30017])
- Products (kinds: [30018])
- Profile (kinds: [0])

Changes:
- Changed validation from `len(data) != 3` to `len(data) < 3` to allow
multiple filters
- Added loop to process all filters in a single REQ message (data[2:])
- Accumulate responses from all filters before returning

This ensures compatibility with clients that batch multiple subscription
filters in a single REQ message, which is a valid pattern according to
NIP-01.
This commit is contained in:
PatMulligan 2025-09-10 15:35:25 +02:00 committed by GitHub
parent 5a1a400f45
commit 687d7b89c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -115,9 +115,15 @@ class NostrClientConnection:
await self._handle_event(event)
return []
if message_type == NostrEventType.REQ:
if len(data) != 3:
if len(data) < 3:
return []
return await self._handle_request(data[1], NostrFilter.parse_obj(data[2]))
subscription_id = data[1]
# Handle multiple filters in REQ message
responses = []
for filter_data in data[2:]:
response = await self._handle_request(subscription_id, NostrFilter.parse_obj(filter_data))
responses.extend(response)
return responses
if message_type == NostrEventType.CLOSE:
self._handle_close(data[1])
if message_type == NostrEventType.AUTH: