Skip to content

pluja/nerostr

Repository files navigation

nerostr: a nostr monero-paid relay

Everyone is free to read, but only paid users can publish events.

A Nostr expensive relay paid with Monero and written in Go!

Contents

Features

  • Very easy to self-host.
  • Lightweight and fast.
    • Uses strfry nostr relay, which is a very fast and efficient relay.
    • Uses badgerdb as a database, which is a fast and efficient golang database.
    • Talks directly with the monero-wallet-rpc to check for payments and get subaddresses.
  • Simple UI written using Golang templates and TailwindCSS.

Why?

Nostr has no spam filters/control. With public relays, the global feed and public chat channels get filled with spam, making them unusable.

In order to avoid spam in your feed, you pay a small fee (~$1) to a relay. Your pubkey gets whitelisted in that relay, and then you are able to publish events there. Reading from these relays is always free for everyone! This allows getting much more curated and clean results in the global page.

Also, paid relays can build up communities of users interested in particular topics, allowing users to follow relays based on their interests.

TLDR; Pay-to-relay to avoid nostr spammers.

Self-hosting your own relay

Selfhosting a Nerostr relay is very easy, you just need a small server and Docker.

  1. Get the docker-compose.yml file from this repo.
wget https://raw.githubusercontent.com/pluja/nerostr/master/docker-compose.yml
  1. Create a new Monero wallet, get the wallet and wallet.keys files and put them in ./nerostr_data/wallet/ folder.

    • You can use the monero-wallet-cli to create a new wallet, or use Feather Wallet for a GUI wallet.
  2. Get the .env file from this repo and modify all the variables to your needs. Mainly you will have to edit the NEROSTR_HOST, MONERO_WALLET_FILENAME and MONERO_WALLET_PASSWORD variables.

curl -fsSL -o .env https://raw.githubusercontent.com/pluja/nerostr/main/example.env
  1. Get the config file for your the strfry relay:
wget https://raw.githubusercontent.com/pluja/nerostr/master/strfry/strfry.conf

Warning You can change the strfry config as you want, but you must make sure to have the plugin = "/app/nerostr-auth.sh" line in the writePolicy section. If you don't have this, the paywall won't do anything and all events will be accepted by the relay.

Reverse proxies examples

The following configurations assume that the webserver containers are in the same docker network as the Nerostr nerostr and strfry-relay containers. If that is not the case, you can bind a local port for each of the nerostr and strfry containers, and then use localhost:<PORT> in the reverse proxy configuration.

Caddy

xmr.usenostr.org {
	@websockets {
		header Connection *Upgrade*
		header Upgrade	websocket
	}

        @json {
		header Accept application/nostr+json
	}

	reverse_proxy @json strfry-nerostr-relay:7777 {
		header_up Accept application/nostr+json
	}
	reverse_proxy @websockets strfry-nerostr-relay:7777
	reverse_proxy nerostr:8080
}

Nginx

server {
    listen 80;
    server_name xmr.usenostr.org;

    location / {
        proxy_pass http://nerostr:8080;
    }

    location / {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_pass http://strfry-nerostr-relay:7777;
    }
}

Brief explanation of how it works

Users go to the paywall frontend, enter their pubkey either in npub or hex format, and pay a small fee in Monero. Once paid, their pubkey gets added to the whitelist database.

The strfry relay uses the nerostr-auth plugin to check if the pubkey of the user is in the whitelist database. If it is, the event gets accepted and published. If it is not, the event gets rejected.

The payment monitor talks directly with the monero-wallet-rpc to check for payments.

API

Nerostr has a simple API that allows you to manage the whitelist database.

Whitelist a pubkey

To add a new user to the whitelist, you can use the API:

curl --request POST \
    --url <NEROSTR_INSTANCE>/api/user/<PUBKEY> \
    --header "X-API-KEY: <API_KEY>"

Replace the variables with your own values. If you set an API key in the .env file, use that one. If you didn't set it, you can get it from the application startup logs, check them with docker compose logs nerostr | head.

Remove a pubkey from the whitelist

To remove a pubkey from the whitelist, you can use the API:

curl --request DELETE \
    --url <NEROSTR_INSTANCE>/api/user/<PUBKEY> \
    --header "X-API-KEY: <API_KEY>"

Replace the variables with your own values. If you set an API key in the .env file, use that one. If you didn't set it, you can get it from the application startup logs, check them with docker compose logs nerostr | head.

Migrating from previous versions

If you are migrating from a previous version of Nerostr, or you want to whitelist a list of pubkeys, you will have to do the following:

  1. Get all the whitelisted pubkeys from your previous Nerostr instance:
sudo sqlite3 nerostr.db "SELECT pub_key FROM users WHERE status='ok';" > keys.txt
  1. Get the keys.txt file, put it in a folder and add the followint bash script to that folder:
#!/bin/bash

input_file=$1
nerostr_host=$2
api_key=$3

# Read the input file line by line
while IFS= read -r pubkey
do
  # Run the curl command for each key
  curl --request POST \
    --url $nerostr_host/api/user/$pubkey \
    --header "X-API-KEY: $api_key"
done < "$input_file"
  1. Run the script with the following command:
./script.sh /path/to/keys.txt <YOUR.NEROSTR.HOST.COM> <API_KEY>

Where <YOUR.NEROSTR.HOST.COM> is the domain of your Nerostr instance (with http/https), and <API_KEY> is the API key you have set in the .env file, or gotten in the application startup logs (if you haven't set it in .env file).

This will add all the pubkeys to the whitelist database.

🧡 Support this project

kycnot.me/about#support

Known Nerostr Relays

Relay Paywall Status and Info
wss://xmr.usenostr.org xmr.usenostr.org info
wss://nostr.portemonero.com nostr.portemonero.com info
wss://xmr.ithurtswhenip.ee xmr.ithurtswhenip.ee info
wss://nostr.xmr.rocks nostr.xmr.rocks info