Skip to content

Commit 568877f

Browse files
committed
feat: comprehensive test suite and project metadata
Test Improvements: - Add unit tests for all nodes (relay-config, filter, npub-filter) - Implement WebSocket connection tests - Add mock implementations for better test isolation - Set up test helper utilities - Add error handling test cases Project Setup: - Add GitHub badges (npm, license, tests, security) - Configure Node-RED specific metadata and tags - Set up GitHub Actions workflow for automated testing - Update package.json with proper Node-RED fields - Add comprehensive documentation Test Coverage: - Core node functionality - WebSocket connection handling - Event filtering logic - Error scenarios - Mock implementations
1 parent 07c7fe6 commit 568877f

File tree

13 files changed

+684
-234
lines changed

13 files changed

+684
-234
lines changed

.github/workflows/test.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [14.x, 16.x, 18.x]
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Use Node.js ${{ matrix.node-version }}
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
cache: 'npm'
24+
- run: npm ci
25+
- run: npm run build --if-present
26+
- run: npm test

README.md

Lines changed: 93 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# node-red-contrib-nostr
22

3+
[![npm version](https://badge.fury.io/js/node-red-contrib-nostr.svg)](https://badge.fury.io/js/node-red-contrib-nostr)
4+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5+
[![Node-RED](https://img.shields.io/badge/Node--RED-Contribution-red.svg)](https://flows.nodered.org/node/node-red-contrib-nostr)
6+
[![Tests](https://github.com/HumanjavaEnterprises/node-red-contrib-nostr/actions/workflows/test.yml/badge.svg)](https://github.com/HumanjavaEnterprises/node-red-contrib-nostr/actions/workflows/test.yml)
7+
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
8+
[![Known Vulnerabilities](https://snyk.io/test/github/HumanJavaEnterprise/node-red-contrib-nostr/badge.svg)](https://snyk.io/test/github/HumanJavaEnterprise/node-red-contrib-nostr)
9+
310
A [Node-RED](http://nodered.org) node for integrating with the Nostr protocol. This node allows you to connect to Nostr relays, publish events, and subscribe to events in the Nostr network.
411

512
## ⚠️ Security Note
@@ -40,16 +47,22 @@ This package provides nodes for interacting with Nostr relays, allowing you to:
4047
- Secure credential management
4148
- Automatic reconnection handling
4249

43-
## Robust WebSocket Handling
50+
## Technical Architecture
4451

45-
This package uses [nostr-websocket-utils](https://github.com/yourusername/nostr-websocket-utils), a purpose-built library for handling Nostr WebSocket connections with enterprise-grade reliability:
52+
### Module System
53+
This package uses a hybrid approach to module systems to ensure maximum compatibility:
54+
- Built as CommonJS for Node-RED compatibility
55+
- Handles ESM dependencies through dynamic imports
56+
- Supports both modern and legacy Node.js environments
4657

47-
- **Automatic Reconnection**: Smart backoff strategy for handling connection drops
48-
- **Connection Health**: Built-in heartbeat monitoring to detect stale connections
49-
- **Type Safety**: Full TypeScript support for all Nostr message types
50-
- **Error Resilience**: Comprehensive error handling and recovery
51-
- **Memory Efficient**: Proper cleanup of resources and event listeners
52-
- **Debug Support**: Detailed logging for troubleshooting connection issues
58+
### WebSocket Management
59+
Built on [nostr-websocket-utils](https://github.com/yourusername/nostr-websocket-utils) for enterprise-grade reliability:
60+
- **Automatic Reconnection**: Smart backoff strategy for connection drops
61+
- **Connection Health**: Built-in heartbeat monitoring
62+
- **Type Safety**: Full TypeScript support
63+
- **Error Resilience**: Comprehensive error handling
64+
- **Memory Efficient**: Proper cleanup of resources
65+
- **Debug Support**: Detailed logging
5366

5467
## Install
5568

@@ -80,184 +93,117 @@ docker compose up -d
8093

8194
### 1. Nostr Relay Config Node
8295
Configuration node for managing relay connections:
83-
- Multiple relay support (up to 3 relays)
96+
- Multiple relay support
8497
- Secure private key storage
8598
- Automatic reconnection handling
8699
- Connection status monitoring
100+
- Dynamic import of ESM dependencies
87101

88-
### 2. Nostr Relay Node
89-
Main node for interacting with relays:
90-
- Event publishing
91-
- Event subscription with filters
92-
- Real-time status updates
93-
- Error handling and recovery
94-
95-
### 3. Nostr Filter Node
102+
### 2. Nostr Filter Node
96103
Specialized node for event filtering:
97104
- Filter by event kinds
98-
- Filter by authors
105+
- Filter by authors (NPUBs)
99106
- Filter by tags
107+
- Time-based filtering
100108
- Custom filter combinations
109+
- Real-time event processing
101110

102-
## Example Flows
111+
### 3. Nostr NPUB Filter Node
112+
Dedicated node for NPUB-based filtering:
113+
- Monitor specific NPUBs
114+
- Filter by event types
115+
- Real-time NPUB event tracking
116+
- Automatic hex key conversion
103117

104-
The package includes several example flows that demonstrate common use cases:
118+
## Example Flows
105119

106-
### 1. Monitor Jack's Posts
107-
A flow that monitors Jack Dorsey's Nostr posts in real-time:
120+
### Basic Event Monitoring
108121
```json
109122
{
110-
"name": "Monitor Jack's Posts",
111-
"nodes": [
112-
{
113-
"id": "relay-config",
114-
"type": "nostr-relay-config",
115-
"name": "Main Relays",
116-
"relay1": "wss://relay.damus.io",
117-
"relay2": "wss://nos.lol",
118-
"relay3": "wss://relay.nostr.band",
119-
"pingInterval": 30
120-
},
121-
{
122-
"id": "jack-monitor",
123-
"type": "nostr-relay",
124-
"name": "Jack's Posts",
125-
"relayConfig": "relay-config",
126-
"npub": "npub1sg6plzptd64u62a878hep2kev88swjh3tw00gjsfl8yz5tc68qysh7j4xz",
127-
"eventKinds": [1]
128-
}
129-
]
123+
"id": "basic-monitor",
124+
"type": "nostr-filter",
125+
"relay": "wss://relay.example.com",
126+
"filterType": "kind",
127+
"eventKinds": [1],
128+
"wires": [["debug"]]
130129
}
131130
```
132131

133-
To import this flow:
134-
1. Open Node-RED
135-
2. Click the menu (≡) button
136-
3. Select Import → Examples → node-red-contrib-nostr
137-
4. Choose "Monitor Jack's Posts"
138-
139-
Other example flows include:
140-
- Basic Relay Connection: Simple example of connecting to a Nostr relay
141-
- Multi-User Monitor: Monitor multiple Nostr users simultaneously
142-
143-
## Usage
144-
145-
### Relay Configuration
146-
147-
1. Add a new "nostr-relay-config" node
148-
2. Configure up to 3 relay URLs (e.g., wss://relay.damus.io)
149-
3. Set your private key (securely stored in credentials)
150-
4. Configure auto-reconnect settings
151-
152-
### Event Publishing
153-
154-
```javascript
155-
msg.payload = {
156-
type: "publish",
157-
content: {
158-
kind: 1, // Event kind (1 for note)
159-
content: "Hello Nostr!",
160-
tags: [ // Optional tags
161-
["t", "node-red"],
162-
["t", "automation"]
163-
]
164-
}
132+
### NPUB Tracking
133+
```json
134+
{
135+
"id": "npub-track",
136+
"type": "nostr-npub-filter",
137+
"relay": "wss://relay.example.com",
138+
"npubValue": "npub1...",
139+
"eventKinds": [1, 6],
140+
"wires": [["debug"]]
165141
}
166142
```
167143

168-
### Event Subscription
169-
170-
```javascript
171-
msg.payload = {
172-
type: "subscribe",
173-
content: {
174-
filters: [{
175-
kinds: [1, 6, 7], // Text notes, reposts, reactions
176-
authors: ["<pubkey>"],
177-
"#t": ["node-red"] // Filter by tag
178-
}]
179-
}
180-
}
144+
## Error Handling
145+
146+
The nodes implement comprehensive error handling:
147+
- Invalid private key detection
148+
- Relay connection failures
149+
- Message parsing errors
150+
- NPUB validation
151+
- WebSocket connection issues
152+
153+
## Development
154+
155+
### Building from Source
156+
```bash
157+
npm install
158+
npm run build
181159
```
182160

183-
### Output Format
184-
185-
```javascript
186-
msg.payload = {
187-
type: "event",
188-
content: {
189-
id: string, // Event ID
190-
pubkey: string, // Author's public key
191-
created_at: number, // Unix timestamp
192-
kind: number, // Event kind
193-
tags: string[][], // Event tags
194-
content: string, // Event content
195-
sig: string // Event signature
196-
}
197-
}
161+
### Running Tests
162+
```bash
163+
npm test
198164
```
199165

200-
### Status Indicators
166+
Test coverage includes:
167+
- Unit tests for all nodes
168+
- WebSocket connection handling
169+
- Event filtering logic
170+
- Error handling
201171

202-
The nodes use standard Node-RED status indicators:
203-
- 🔴 Red: Disconnected or error
204-
- 🟡 Yellow: Connecting or processing
205-
- 🟢 Green: Connected and ready
172+
### Docker Development
173+
```bash
174+
docker compose -f docker-compose.dev.yml up
175+
```
206176

207177
## Supported NIPs
208178

209-
| NIP | Status | Description |
210-
|-----|--------|-------------|
211-
| [01](https://github.com/nostr-protocol/nips/blob/master/01.md) || Basic protocol flow description |
212-
| [02](https://github.com/nostr-protocol/nips/blob/master/02.md) || Contact List and Petnames |
213-
| [09](https://github.com/nostr-protocol/nips/blob/master/09.md) | 🚧 | Event Deletion |
214-
| [10](https://github.com/nostr-protocol/nips/blob/master/10.md) || Reply Threading |
215-
| [19](https://github.com/nostr-protocol/nips/blob/master/19.md) || bech32-encoded entities (for npub support) |
216-
| [23](https://github.com/nostr-protocol/nips/blob/master/23.md) | 🚧 | Long-form Content |
217-
| [42](https://github.com/nostr-protocol/nips/blob/master/42.md) || Authentication of clients to relays |
218-
| [51](https://github.com/nostr-protocol/nips/blob/master/51.md) | 🚧 | Lists (bookmarks & follow lists) |
219-
220-
Legend:
221-
- ✅ Fully Supported
222-
- 🚧 In Progress/Planned
223-
- ❌ Planned for Future
224-
225-
## Best Practices
226-
227-
1. **Key Management**:
228-
- Generate dedicated keys for automation
229-
- Never use your main Nostr identity
230-
- Rotate keys periodically
231-
- Use Node-RED's credential encryption
232-
233-
2. **Relay Selection**:
234-
- Use reliable, well-known relays
235-
- Consider running your own relay for critical applications
236-
- Monitor relay health and performance
237-
- Configure multiple relays for redundancy
238-
239-
3. **Rate Limiting**:
240-
- Be mindful of relay resources
241-
- Implement appropriate delays
242-
- Filter events as specifically as possible
243-
- Use appropriate subscription filters
179+
- NIP-01: Basic protocol flow
180+
- NIP-02: Contact List and Petnames
181+
- NIP-04: Encrypted Direct Messages
182+
- NIP-05: Mapping Nostr keys to DNS-based internet identifiers
244183

245184
## Contributing
246185

247186
1. Fork the repository
248187
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
249-
3. Commit your changes (`git commit -am 'Add some amazing feature'`)
188+
3. Commit your changes (`git commit -m 'feat: add amazing feature'`)
250189
4. Push to the branch (`git push origin feature/amazing-feature`)
251190
5. Open a Pull Request
252191

253192
## License
254193

255194
This project is licensed under the MIT License - see the LICENSE file for details.
256195

257-
## Repository
196+
## Node-RED Specific Tags
258197

259-
[https://github.com/HumanjavaEnterprises/node-red-contrib-nostr](https://github.com/HumanjavaEnterprises/node-red-contrib-nostr)
198+
This module provides nodes for working with Nostr protocol in Node-RED.
260199

261-
## Author
200+
### Node Properties
262201

263-
[vveerrgg](https://github.com/vveerrgg)
202+
* Category: network
203+
* Name: node-red-contrib-nostr
204+
* Types: nostr-relay-config, nostr-filter, nostr-npub-filter
205+
* Description: Node-RED nodes for interacting with Nostr protocol
206+
* Author: Human Java Enterprise
207+
* Keywords: node-red,nostr,websocket,relay,filter,npub
208+
* Dependencies: @humanjavaenterprises/nostr-tools,nostr-websocket-utils
209+
* Node-RED: >= 2.0.0

0 commit comments

Comments
 (0)