Skip to content

Spl0itable/nosflare

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nosflare

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.

Supported NIPs

Getting Started

Prerequisites

  • 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.

Dependencies

This project requires the @noble/curves package for cryptographic operations and esbuild:

npm install @noble/curves
npm install -g esbuild

Building

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 or allowedPubkeys and blockedEventKinds or allowedEventKinds 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.

Deployment

You can deploy Nosflare using either the Wrangler CLI, directly through the Cloudflare dashboard, or with the third-party deployment script:

Using Wrangler CLI

  1. Configure your wrangler.toml with your Cloudflare account details.
  2. Publish the worker:
wrangler publish
  1. Add a custom domain (this will be the desired relay URL).
  2. Create a KV namespace to store events. You can call it whatever you want.
  3. Bind the relayDb variable to the KV namespace for the Worker in the Settings > Variables tab under the "KV Namespace Bindings" section.

Using Cloudflare Dashboard

  1. Log in to your Cloudflare dashboard.
  2. Go to the Workers section and create a new worker. You can call it whatever you'd like.
  3. Copy the contents of dist/worker.js and paste into the online editor. See the example.js file in this repo for what a successfully bundled file should look like.
  4. Save and deploy the worker.
  5. Add a custom domain (this will be the desired relay URL).
  6. Create a KV namespace to store events. You can call it whatever you want.
  7. Bind the relayDb variable to the KV namespace for the Worker in the Settings > Variables tab under the "KV Namespace Bindings" section.

Using NosflareDeploy script

A third-party script to easily deploy Nosflare. Read more here.

Usage

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/

Roadmap

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)

Contributing

Contributions to Nosflare are welcome! Please submit issues, feature requests, or pull requests through the project's GitHub repository.

License

Nosflare is open-sourced software licensed under the MIT license.

Contact

For inquiries related to Nosflare, you can reach out on Nostr at npub16jdfqgazrkapk0yrqm9rdxlnys7ck39c7zmdzxtxqlmmpxg04r0sd733sv

Acknowledgements

  • 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.

About

Nostr relay powered by Cloudflare Worker and KV store

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published