This is an example Nostr rust project to enable '402 Payment Required' responses for requests to paid content.

Overview

Nostr Paywall Example

This is an example Nostr rust project to enable 402 Payment Required responses for requests to paid content. To prove payment, a NIP 98 - HTTP Auth Nostr event should be included, which will unlock access the content post-payment - ideally on on refresh on successful payment.

This project doesn't handle money, and is a reference project to help you get started. If there is enough interest, it could become a rust create (library) project.

Unsupported Today (however, ideally on the roadmap)

  1. Generating invoices for 402 Payment Required responses to enable payment (embedding the pubkey and content_id metadata in an invoice)
  2. Database schema
  3. Database access check logic / query (with access to pubkey and content_id)
  4. Actual Content delivery
  5. Split payments and similar

Customisation

  1. check_pubkey_access() in db.rs - You can customise the Postgres DB query used to check access. Currently the check returns true for all valid NIP 98 header.
  2. content in routes.rs - You can write your own content delivery logic here; for URL redirection, Images, proxied content, or anything else.

Getting Started

git clone https://github.com/blakejakopovic/nostr_paywall_example
cd nostr_paywall_example

cp .env.example .env
nano .env
# Ensure you update AUTH_EVENT_HOST to match your expected server hostname, or the NIP-98 auth will fail

RUST_LOG=info cargo run --release

Usage / Testing

  1. Create a NIP 98 HTTP Auth event. You can use this tool with a test pubkey https://nostrtool.com. Just keep in mind by default you only have 60 seconds before the event's created_at value becomes too old (and you will get a Bad Request response).
{
  "id": "cddeb723c58a2ff78cd5f0f315d855306ce7eada1714a26572ac0f0d2e619925",
  "pubkey": "970e0ebe27a552be8982047974f60302caab0fcb9aa86855f81102e67e084e45",
  "created_at": 1682772206,
  "kind": 27235,
  "tags": [
    [
      "u",
      "http://localhost:8080/m/test_content_id"
    ],
    [
      "method",
      "GET"
    ]
  ],
  "content": "",
  "sig": "2ef81b6b7d494d57dc06ac261aeb1e9c7dfeeb3868b2c4daee604ccdf4cb9cda8f3df08c50f93c99e327ad8fb40175907d47f7dfc100633af3fe38f085d6c888"
}
  1. Base64 encode the event. Easily done here https://www.base64encode.org.
ewogICJpZCI6ICJjZGRlYjcyM2M1OGEyZmY3OGNkNWYwZjMxNWQ4NTUzMDZjZTdlYWRhMTcxNGEyNjU3MmFjMGYwZDJlNjE5OTI1IiwKICAicHVia2V5IjogIjk3MGUwZWJlMjdhNTUyYmU4OTgyMDQ3OTc0ZjYwMzAyY2FhYjBmY2I5YWE4Njg1NWY4MTEwMmU2N2UwODRlNDUiLAogICJjcmVhdGVkX2F0IjogMTY4Mjc3MjIwNiwKICAia2luZCI6IDI3MjM1LAogICJ0YWdzIjogWwogICAgWwogICAgICAidSIsCiAgICAgICJodHRwOi8vbG9jYWxob3N0OjgwODAvbS90ZXN0X2NvbnRlbnRfaWQiCiAgICBdLAogICAgWwogICAgICAibWV0aG9kIiwKICAgICAgIkdFVCIKICAgIF0KICBdLAogICJjb250ZW50IjogIiIsCiAgInNpZyI6ICIyZWY4MWI2YjdkNDk0ZDU3ZGMwNmFjMjYxYWViMWU5YzdkZmVlYjM4NjhiMmM0ZGFlZTYwNGNjZGY0Y2I5Y2RhOGYzZGYwOGM1MGY5M2M5OWUzMjdhZDhmYjQwMTc1OTA3ZDQ3ZjdkZmMxMDA2MzNhZjNmZTM4ZjA4NWQ2Yzg4OCIKfQ==
  1. Run the following command with your matching event u tag and base64 event output.
curl -H "AUTHORIZATION: nostr REPLACE_WITH_BASE64_ENCODED_EVENT" localhost:8080/m/test_content_id
You might also like...
Rust crate to enable ANSI escape code support on Windows.

enable-ansi-support: Enable ANSI escape code support on Windows 10 About This crate provides one function, enable_ansi_support, which allows ANSI esca

Work to enable a Classic Mac (24-bit 68000) with ~16MB of RAM.

Apple SE FDHD ROM analysis In order to build a Mac clone that doesn't fully emulate the hardware (which is possible because the ROM abstracts hardware

πŸ’« This program allows you to do requests in Rust without reqwest !

Zapros πŸ’« This program allows you to do requests in Rust without reqwest ! Usage : Get use crate::http_client::HttpClient; use crate::http_client::Htt

CLI program for sending one-off requests to the VTube Studio API

vtubestudio-cli (vts) CLI program for sending one-off requests to the VTube Studio API. It connects to the websocket, authenticates, performs one or t

Use asynchronous api requests in conjunction with yew's suspense feature

Yew API Hook Use asynchronous api requests in conjunction with yew's suspense feature Usage #[function_component] fn App() - Html { html! {

Components of Fornjot that are no longer actively maintained. Pull requests still welcome!

Fornjot - Extra Components About These are extra components from the Fornjot repository, that are no longer actively maintained. Fornjot's goal was to

Track where Nixpkgs pull requests have reached.

nixpkgs-track Track where Nixpkgs pull requests have reached (is that update in nixpkgs-unstable yet??). Originally created as a local and reliable CL

Ideas = Creations, a multi-language CMS(Content Management System) based on Rust Web stacks, with long-term upgrade and maintenance.

Ideas = Creations δΈ­ζ–‡ RustHub: Rust ideas yesterday, shining creations today! This repository holds source code used to run https://rusthub.org, it's

Rust SDK for the core C2PA (Coalition for Content Provenance and Authenticity) specification

C2PA Rust SDK The Coalition for Content Provenance and Authenticity (C2PA) addresses the prevalence of misleading information online through the devel

Owner
Blake Jakopovic
Blake Jakopovic
Send files between machines - no installation required!

skicka.pwy.io:99 Skicka (from Swedish send) allows to send files between machines - no installation required! Transmitting a file is as easy as piping

Patryk Wychowaniec 55 Jul 12, 2023
Nostr CLI client built with Rust

Nostr CLI client built with Rust Encrypted chat inside Nostr leaks metadata of who talks to who. This small CLI app implements a "public inbox," which

Vincent Liao 10 Dec 19, 2022
siamstr.com Nostr Address Provider written in Rust.

Siamstr Nostr Address Provider Running project Rust Toolchain You'll need to use the nightly Rust toolchain, and install the wasm32-unknown-unknown ta

Vaz. 5 Nov 27, 2023
simple but convenient CLI-based Nostr client app for following users and sending DMs

nostr-commander-rs TLDR: simple but convenient CLI-based Nostr client app for publishing, sending DMs, as well as following users and channels nostr-c

null 18 Dec 30, 2022
convert nostr keys and note-ids between hex and bech32

Key-Convertr People are copy-pasting nostr private keys into webpages to convert between the original hex-encoding and bech32-encoding (specified in N

Rijndael 14 Jan 9, 2023
Safer Nostr is a service that helps protect users by loading sensitive information (IP leak) and using AI to prevent inappropriate images from being uploaded.

Safer Nostr is a service that helps protect users by loading sensitive information (IP leak) and using AI to prevent inappropriate images from being uploaded. It also offers image optimization and storage options. It has configurable privacy and storage settings, as well as custom cache expiration.

Thomas 4 Dec 29, 2022
A simple tool to mine nostr vanity pubkeys.

Nostr CPU pubkey miner A simple tool to mine nostr vanity pubkeys. Currently supports hexadecimal and bech32 vanity keys. Tested on Windows but should

Antonin Verdier 3 Jan 19, 2023
A GPT-3 access point through Nostr, powered by lightning

Geppeto A Nostr based API for GPT-3, powered on Lightning. The bot listens for event kind 29000 (inspired by NIP-9000) and will query the prompt to th

null 5 May 24, 2023
Nostr protocol implementation, SDK and FFI

Searchnos: an experimental implementation of NIP-50 This is a relay-like bridge server that provides a Nostr full-text search capability by using Elas

SAGE 8 Jul 2, 2023
A fast nostr opengraph server, built on nostrdb and egui.

notecrumbs A nostr opengraph server build on nostrdb, egui, and skia. It renders notes using the CPU in around 50ms. Status WIP! Local note fetching w

Damus 7 Dec 21, 2023