Skip to content

haorendashu/cfrelay

Repository files navigation

cfrelay

A relay run at cloudflare.

Features

  • NIP-01 (Basic protocol flow description)
  • NIP-02 (Follow List)
  • NIP-05 (Mapping Nostr keys to DNS-based internet identifiers)
  • NIP-09 (Event Deletion)
  • NIP-11 (Relay Information Document)
  • NIP-12 (Generic Tag Queries)
  • NIP-33 (Parameterized Replaceable Events)
  • NIP-42 (Authentication of clients to relays)
  • NIP-45 (Counting results)
  • NIP-50 (Search Capability)
  • NIP-95 (Shared File)
  • NIP-96 (HTTP File Storage Integration)
  • NIP-98 (HTTP Auth)

Implement

Function Cloudflare implement
Event Store D1
File Store (NIP-95) KV
File Store (NIP-96) R2

Why do we use the KV to save the file store?

Because the R2 must bing the payment method and when it run out of the free plan limit, it would make some fee.

Deploy

1. Install NPM

2. Install wrangler

3. Init D1 database

create d1 database

wrangler d1 create relay

run init script

wrangler d1 execute relay --file=init.sql

4.Init KV

wrangler kv:namespace create relay

5.Init R2 (Optional)

If you want to use R2, you must config your payment to cloudflare. I can't ensure that it won't cost you money

After config payment, you can init the R2 bucket now. You can do it in the cloudflare website or run this script:

wrangler r2 bucket create relay

It is important that config a custom domain for your bucket. Due to this domain can user cloudflare's cache and it will save you money.

You can readmore from this Connect a bucket to a custom domain .

5.Change files

change the owners in in src/index.js, chenge the 29320975df855fe34a7b45ada2421e2c741c37c0136901fe477133a91eb18b07 to you plain owner id.

const owners = ["29320975df855fe34a7b45ada2421e2c741c37c0136901fe477133a91eb18b07"];

(Optional). change the nip05 config

// nip05user config should set like this:
const nip05User = {"nicename": "pubkey"};

(Optional). If you use R2 for NIP-96 and had config a custom domain, you should config r2CustomDomain in src/index.js.

const r2CustomDomain = 'You custom domain like: https://xxxxxx.com ';

change config file wrangler.toml set the database_id and kv_namespaces' id

[[d1_databases]]
binding = "DB"
database_name = "relay"
database_id = "Here is there d1 id"

[[kv_namespaces]]
binding = "KV"
id = "Here is there kv id"

(Optional). If you use R2 for NIP-96, you should also add this setting to wrangler.toml.

[[d1_databases]]
[[r2_buckets]]
binding = "R2"
bucket_name = "You bucket name"

6.Deploy

run this script to install project dependent

npm install

run this script to deploy

npm run deploy

About

A nostr relay base on cloudflare wokers.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published