Nosflare is a serverless Nostr relay purpose-built for Cloudflare Workers and the Cloudflare KV store.
This relay is designed to be easy to deploy, scalable, and cost-effective, leveraging Cloudflare's edge computing infrastructure to provide a resilient relay for the Nostr decentralized social protocol.
Most applicable NIPs are supported along with support for allowlisting or blocklisting pubkeys and event kinds, throttle number of events from a single pubkey through rate limiting, block specific words or phrases, blast events to other relays, and support of NIP-05 for username@your-domain.com
verified Nostr addresses.
- Supports a range of Nostr Improvement Proposals (NIPs), including NIPs 1, 2, 4, 5, 9, 11, 12, 15, 16, 17, 20, 22, 33, and 40.
- A Cloudflare account with Workers and KV Store enabled.
- Node.js and npm (for installing dependencies and running the build script).
- Wrangler CLI (optional) or access to the Cloudflare dashboard for deployment.
This project requires the @noble/curves package for cryptographic operations and esbuild:
npm install @noble/curves
npm install -g esbuild
Clone the worker.js
file to your machine. Edit the contents of relayInfo
and relayIcon
as desired to customize the relay name, icon, etc.
Optional:
- Edit the
nip05Users
section to add usernames and their hex pubkey for NIP-05 verified Nostr address. - Edit the
blockedPubkeys
orallowedPubkeys
andblockedEventKinds
orallowedEventKinds
to either blocklist or allowlist pubkeys and event kinds. - Edit
blockedContent
to block specific words and/or phrases. - Edit
blastRelays
to specify other relays for blasting events. - Edit
excludedRateLimitKinds
to exclude event kinds from rate limiting.
How blocklisting and allowlisting works: If pubkey(s) or event kind(s) is in blocklist, only that pubkey(s) or event kind(s) will be blocked and all others allowed. Conversely, if pubkey(s) or event kind(s) is in allowlist, only that pubkey(s) and event kind(s) will be allowed and all others blocked.
We'll use esbuild
to bundle the worker script:
esbuild worker.js --bundle --outfile=dist/worker.js --platform=neutral --target=es2020
The command assumes you're in the same directory as the worker.js
file.
You can deploy Nosflare using either the Wrangler CLI, directly through the Cloudflare dashboard, or with the third-party deployment script:
- Configure your
wrangler.toml
with your Cloudflare account details. - Publish the worker:
wrangler publish
- Add a custom domain (this will be the desired relay URL).
- Create a KV namespace to store events. You can call it whatever you want.
- Bind the
relayDb
variable to the KV namespace for the Worker in the Settings > Variables tab under the "KV Namespace Bindings" section.
- Log in to your Cloudflare dashboard.
- Go to the Workers section and create a new worker. You can call it whatever you'd like.
- Copy the contents of
dist/worker.js
and paste into the online editor. See theexample.js
file in this repo for what a successfully bundled file should look like. - Save and deploy the worker.
- Add a custom domain (this will be the desired relay URL).
- Create a KV namespace to store events. You can call it whatever you want.
- Bind the
relayDb
variable to the KV namespace for the Worker in the Settings > Variables tab under the "KV Namespace Bindings" section.
A third-party script to easily deploy Nosflare. Read more here.
Nosflare acts as a Nostr relay. Users can connect using any standard Nostr client by pointing to the deployed Cloudflare Worker URL or custom domain. The relay adheres to the basic tenets of the Nostr protocol, handling events according to the specified NIPs above.
As mentioned, you can either use the Cloudflare Worker's default "workers.dev" endpoint URL or a custom domain, adding it to any Nostr client using the secure websocket protocol.
Example:
wss://nostr-relay.example.workers.dev/
The current release of Nosflare is primarily focused on basic protocol flow usage. This ensures events are stored and retrieved very quickly. However, the following is a non-exhaustive list of planned features:
- "Pay-to-relay" (charging sats for access)
- Client authorization (NIP-42)
- File storage through Cloudflare R2 bucket (NIP-96)
- Encrypted DMs (NIP-44)
Contributions to Nosflare are welcome! Please submit issues, feature requests, or pull requests through the project's GitHub repository.
Nosflare is open-sourced software licensed under the MIT license.
For inquiries related to Nosflare, you can reach out on Nostr at npub16jdfqgazrkapk0yrqm9rdxlnys7ck39c7zmdzxtxqlmmpxg04r0sd733sv
- The awesome Nostr community for the protocol development.
- Cloudflare Workers for an easy-to-use serverless execution environment.
- The noble library for providing Schnorr signatures over secp256k1.
- PastaGringo for making the NosflareDeploy script.