Commit graph

25 commits

Author SHA1 Message Date
Patrick Mulligan
5e95b309fe make format
Some checks are pending
CI / lint (push) Waiting to run
CI / tests (push) Blocked by required conditions
/ release (push) Waiting to run
/ pullrequest (push) Blocked by required conditions
2025-11-17 00:01:21 +01:00
Patrick Mulligan
dcc3204735 Fix NIP-09 deletion for parameterized replaceable events (NIP-33)
Fixed bug where deleting a parameterized replaceable event (e.g., kind 31922)
using an 'a' tag would incorrectly delete ALL events of that kind instead of
just the specific event with the matching d-tag.

**Root Cause:**
NostrFilter's 'd' field uses a Pydantic Field alias "#d". When creating a filter
with `NostrFilter(d=[value])`, Pydantic ignores it because the parameter name
doesn't match the alias.

**Fix:**
Changed filter creation to use the alias:
```python
NostrFilter(authors=[...], kinds=[...], **{"#d": [d_tag]})
```

**Testing:**
- Created two tasks with different d-tags
- Deleted only one task
- Verified only the specified task was marked as deleted in the database
- Confirmed the other task remained unaffected

This ensures proper NIP-09 deletion behavior for NIP-33 parameterized
replaceable events using 'a' tag format (kind:pubkey:d-identifier).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-17 00:01:21 +01:00
Patrick Mulligan
8bfd792548 Add NIP-09 support for parameterized replaceable events (NIP-33)
Extended NIP-09 deletion event handling to support both regular events
and parameterized replaceable events (NIP-33).

**Previous behavior:**
- Only handled 'e' tags (regular event IDs)
- Did not support 'a' tags for addressable/replaceable events

**New behavior:**
- Handles both 'e' tags (event IDs) and 'a' tags (event addresses)
- Parses 'a' tag format: kind:pubkey:d-identifier
- Validates deletion author matches event address pubkey (NIP-09 requirement)
- Creates appropriate filters for each deletion type

**Implementation:**
- Added parsing for 'a' tag event addresses
- Extract kind, pubkey, and d-tag from address format
- Build NostrFilter with authors, kinds, and d-tag parameters
- Collect all event IDs to delete from both 'e' and 'a' tags
- Mark matching events as deleted in single operation

This enables proper deletion of parameterized replaceable events like
calendar events (kind 31922-31924), long-form content (kind 30023),
and other addressable event kinds.

Implements NIP-09: https://github.com/nostr-protocol/nips/blob/master/09.md
Supports NIP-33: https://github.com/nostr-protocol/nips/blob/master/33.md
2025-11-17 00:01:21 +01:00
dni ⚡
a53d2d7767
refactor: get rid of secp lib (#40) 2025-11-04 10:30:43 +02:00
dni ⚡
35584a230f
chore: add uv, linting, fixes (#39)
Some checks failed
CI / lint (push) Has been cancelled
/ release (push) Has been cancelled
CI / tests (push) Has been cancelled
/ pullrequest (push) Has been cancelled
* chore: add uv, linting, fixes
2025-10-30 10:43:27 +01:00
PatMulligan
22df5868de
FEAT: Implement NIP-01 Addressable Events Support (#33)
* Implement NIP-16 parameterized replaceable events

Add support for parameterized replaceable events (kinds 30000-39999) to
properly
handle Nostr marketplace product and stall updates according to NIP-16
specification.

Changes:
- Add is_parameterized_replaceable_event property to NostrEvent
- Implement automatic deletion of previous versions when new
parameterized replaceable event is received
- Add 'd' tag filtering support to NostrFilter for parameterized
replacement logic
- Update SQL query generation to handle 'd' tag joins

Fixes issue where product updates would create duplicate entries instead
of
replacing previous versions, ensuring only the latest version remains
visible.

* Refactor event handling for addressable events

Renamed the property is_parameterized_replaceable_event to is_addressable_event in NostrEvent to align with NIP-01 specifications (previously NIP-16). Updated the client_connection.py to utilize the new property for extracting 'd' tag values for addressable replacement, ensuring proper event handling in the relay system.

* Refactor tag filtering logic in NostrFilter

Updated the tag filtering mechanism to ensure that the filter only fails if the specified tags ('e' and 'p') are not found. This change improves clarity and maintains functionality by allowing for more precise control over event filtering.

* update readme

* Fix addressable event deletion and SQL schema issues

- Fix Pydantic field alias usage for d tag filtering (use #d instead of
d)
- Remove nostrrelay schema prefixes from SQL table references
- Implement subquery approach for DELETE operations with JOINs
- Resolve SQLite DELETE syntax incompatibility with JOIN statements
- Ensure NIP-33 compliance: only delete events with matching d tag
values
2025-09-10 16:40:40 +03:00
PatMulligan
687d7b89c1
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.
2025-09-10 16:35:25 +03:00
Vlad Stan
3dc066fbd4
[fix] Ws api tests (#31) 2024-11-11 15:25:25 +02:00
dni ⚡
73054fd5ce
feat: update to v1.0.0 (#30) 2024-11-08 15:32:04 +02:00
Bitkarrot
2bdbbb274d
Update client_connection.py (#29)
omit return none, in ref to https://github.com/lnbits/nostrrelay/issues/27
2024-10-14 09:39:48 +03:00
dni ⚡
cc6752003a
feat: improve codequality and CI (#25)
* feat: improve codequality and CI
2024-08-30 13:20:23 +02:00
Vlad Stan
ccf620d476 feat: check account for REQ 2023-04-06 18:14:35 +03:00
Vlad Stan
dc50d3493d fix: is free to join if cost_to_join == 0 2023-04-06 18:14:12 +03:00
Vlad Stan
8ed361230b refactor: prepare for pay check 2023-04-06 17:33:09 +03:00
Vlad Stan
fddc8a1d22 refactor: field name 2023-04-06 17:31:49 +03:00
Vlad Stan
16b9d93dca fix: use Spec for PaymentSpec 2023-02-22 11:39:35 +02:00
Vlad Stan
8c860f851a feat: update supported NIPs 2023-02-21 16:20:19 +02:00
Vlad Stan
7ec3045130 feat: add extension clean-up endpoint 2023-02-17 14:57:31 +02:00
Vlad Stan
230729483c chore: code format 2023-02-17 14:44:39 +02:00
Vlad Stan
855812cb8f refactor: extract NostrRelay 2023-02-17 14:44:39 +02:00
Vlad Stan
2ebc83a286 refactor: extract NostrFilter 2023-02-17 14:44:39 +02:00
Vlad Stan
6be0169ea9 refactor: extract NostrEvent 2023-02-17 14:44:39 +02:00
Vlad Stan
c42d81f696 refactor: extract client_connection 2023-02-17 14:44:39 +02:00
Vlad Stan
aa68d2a79a refactor: extract EventValidator 2023-02-17 14:44:39 +02:00
Vlad Stan
c46c903703 refactor: move client-manager 2023-02-17 14:44:39 +02:00