|
1 | 1 | # node-red-contrib-nostr |
2 | 2 |
|
| 3 | +[](https://badge.fury.io/js/node-red-contrib-nostr) |
| 4 | +[](https://opensource.org/licenses/MIT) |
| 5 | +[](https://flows.nodered.org/node/node-red-contrib-nostr) |
| 6 | +[](https://github.com/HumanjavaEnterprises/node-red-contrib-nostr/actions/workflows/test.yml) |
| 7 | +[](https://standardjs.com) |
| 8 | +[](https://snyk.io/test/github/HumanJavaEnterprise/node-red-contrib-nostr) |
| 9 | + |
3 | 10 | 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. |
4 | 11 |
|
5 | 12 | ## ⚠️ Security Note |
@@ -40,16 +47,22 @@ This package provides nodes for interacting with Nostr relays, allowing you to: |
40 | 47 | - Secure credential management |
41 | 48 | - Automatic reconnection handling |
42 | 49 |
|
43 | | -## Robust WebSocket Handling |
| 50 | +## Technical Architecture |
44 | 51 |
|
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 |
46 | 57 |
|
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 |
53 | 66 |
|
54 | 67 | ## Install |
55 | 68 |
|
@@ -80,184 +93,117 @@ docker compose up -d |
80 | 93 |
|
81 | 94 | ### 1. Nostr Relay Config Node |
82 | 95 | Configuration node for managing relay connections: |
83 | | -- Multiple relay support (up to 3 relays) |
| 96 | +- Multiple relay support |
84 | 97 | - Secure private key storage |
85 | 98 | - Automatic reconnection handling |
86 | 99 | - Connection status monitoring |
| 100 | +- Dynamic import of ESM dependencies |
87 | 101 |
|
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 |
96 | 103 | Specialized node for event filtering: |
97 | 104 | - Filter by event kinds |
98 | | -- Filter by authors |
| 105 | +- Filter by authors (NPUBs) |
99 | 106 | - Filter by tags |
| 107 | +- Time-based filtering |
100 | 108 | - Custom filter combinations |
| 109 | +- Real-time event processing |
101 | 110 |
|
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 |
103 | 117 |
|
104 | | -The package includes several example flows that demonstrate common use cases: |
| 118 | +## Example Flows |
105 | 119 |
|
106 | | -### 1. Monitor Jack's Posts |
107 | | -A flow that monitors Jack Dorsey's Nostr posts in real-time: |
| 120 | +### Basic Event Monitoring |
108 | 121 | ```json |
109 | 122 | { |
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"]] |
130 | 129 | } |
131 | 130 | ``` |
132 | 131 |
|
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"]] |
165 | 141 | } |
166 | 142 | ``` |
167 | 143 |
|
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 |
181 | 159 | ``` |
182 | 160 |
|
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 |
198 | 164 | ``` |
199 | 165 |
|
200 | | -### Status Indicators |
| 166 | +Test coverage includes: |
| 167 | +- Unit tests for all nodes |
| 168 | +- WebSocket connection handling |
| 169 | +- Event filtering logic |
| 170 | +- Error handling |
201 | 171 |
|
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 | +``` |
206 | 176 |
|
207 | 177 | ## Supported NIPs |
208 | 178 |
|
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 |
244 | 183 |
|
245 | 184 | ## Contributing |
246 | 185 |
|
247 | 186 | 1. Fork the repository |
248 | 187 | 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'`) |
250 | 189 | 4. Push to the branch (`git push origin feature/amazing-feature`) |
251 | 190 | 5. Open a Pull Request |
252 | 191 |
|
253 | 192 | ## License |
254 | 193 |
|
255 | 194 | This project is licensed under the MIT License - see the LICENSE file for details. |
256 | 195 |
|
257 | | -## Repository |
| 196 | +## Node-RED Specific Tags |
258 | 197 |
|
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. |
260 | 199 |
|
261 | | -## Author |
| 200 | +### Node Properties |
262 | 201 |
|
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