Commit 3a691ef
authored
feat: implement NIP-17 & NIP-44 v2 for Modern Direct Messages (#458)
* feat: implement NIP-17 & NIP-44 v2 for Modern Direct Messages
This commit introduces comprehensive support for NIP-17 (Private Direct Messages)
and NIP-44 v2 (Encrypted Payloads), establishing the modern standard for
secure messaging on Nostr.
Changes included:
- **NIP-17 Support**:
- Added new Event Kinds: Seal (13), Direct Message (14), File Message (15), and Gift Wrap (1059).
- Implemented `GiftWrapEventStrategy` to handle and validate incoming Gift Wrap events.
- Added repository-level protections to block direct relay publication of inner events (Kinds 13, 14, 15), mandating they be encrypted inside a Gift Wrap.
- **NIP-44 v2 Crypto**:
- Implemented `nip44Encrypt` and `nip44Decrypt` functions supporting ChaCha20, HKDF extraction/expansion, and MAC verification as per NIP-44 v2 specifications.
- Added `validateNip44Payload` to ensure payloads adhere to the exact format requirements without needing to decrypt them.
- **Cleanup**:
- Removed deprecated `encryptKind4Event` (legacy NIP-04 DM algorithm) from `event.ts`.
- Updated `package.json` to declare NIPs 17 and 44 in `supportedNipExtensions`.
- **Tests**:
- Added extensive unit tests across NIP-44 encryption logic, Event Strategies, and Message Handlers.
- Resolved `sort-imports` ESLint violations in multiple handler specs.
* fix: address NIP-17/NIP-44 security review findings
- nip44: replace dead try/catch with explicit base64 regex + length%4 check
- gift-wrap: validate recipient p tag is a 64-char lowercase hex pubkey; fix error message
- mirroring worker: block inner event kinds (13/14/15) from being persisted directly1 parent ab2dfeb commit 3a691ef
12 files changed
Lines changed: 1175 additions & 371 deletions
File tree
- src
- app
- constants
- factories
- handlers
- event-strategies
- utils
- test/unit
- handlers
- event-strategies
- utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | | - | |
| 19 | + | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| |||
0 commit comments