2022-04-16 23:53:25 +00:00
# [nostr-ts-relay](https://github.com/Cameri/nostr-ts-relay)
2022-10-26 16:38:50 -07:00
< p align = "center" >
< img alt = "nostr-ts-relay logo" height = "256px" width = "256px" src = "https://user-images.githubusercontent.com/378886/198158439-86e0345a-adc8-4efe-b0ab-04ff3f74c1b2.jpg" / >
< / p >
2022-10-19 02:37:20 +00:00
< p align = "center" >
2022-11-06 12:04:38 -05:00
< a href = "https://github.com/Cameri/nostr-ts-relay/releases" >
< img alt = "GitHub release" src = "https://img.shields.io/github/v/release/Cameri/nostr-ts-relay" >
< / a >
2022-10-18 23:43:13 -04:00
< a href = "https://github.com/Cameri/nostr-ts-relay/issues" >
< img alt = "GitHub issues" src = "https://img.shields.io/github/issues/Cameri/nostr-ts-relay?style=plastic" / >
< / a >
< a href = "https://github.com/Cameri/nostr-ts-relay/stargazers" >
< img alt = "GitHub stars" src = "https://img.shields.io/github/stars/Cameri/nostr-ts-relay" / >
< / a >
2022-11-06 21:11:46 -05:00
< img alt = "GitHub top language" src = "https://img.shields.io/github/languages/top/Cameri/nostr-ts-relay" >
2022-10-18 23:43:13 -04:00
< a href = "https://github.com/Cameri/nostr-ts-relay/network" >
< img alt = "GitHub forks" src = "https://img.shields.io/github/forks/Cameri/nostr-ts-relay" / >
< / a >
< a href = "https://github.com/Cameri/nostr-ts-relay/blob/main/LICENSE" >
< img alt = "GitHub license" src = "https://img.shields.io/github/license/Cameri/nostr-ts-relay" / >
< / a >
< a href = 'https://coveralls.io/github/Cameri/nostr-ts-relay?branch=main' >
< img alt = 'Coverage Status' src = 'https://coveralls.io/repos/github/Cameri/nostr-ts-relay/badge.svg?branch=main' / >
< / a >
2022-11-17 09:54:41 -05:00
< a href = 'https://sonarcloud.io/project/overview?id=Cameri_nostr-ts-relay' >
< img alt = 'Sonarcloud quality gate' src = 'https://sonarcloud.io/api/project_badges/measure?project=Cameri_nostr-ts-relay&metric=alert_status' / >
< / a >
2022-10-18 23:43:13 -04:00
< a href = 'https://github.com/Cameri/nostr-ts-relay/actions' >
< img alt = 'Build status' src = 'https://github.com/Cameri/nostr-ts-relay/actions/workflows/checks.yml/badge.svg?branch=main&event=push' / >
< / a >
2022-10-19 02:37:20 +00:00
< / p >
2022-04-16 23:53:25 +00:00
This is a [nostr ](https://github.com/fiatjaf/nostr ) relay, written in
Typescript.
2022-10-17 04:35:12 +00:00
This implementation is production-ready. See below for supported features.
2022-04-16 23:53:25 +00:00
The project master repository is available on [GitHub ](https://github.com/Cameri/nostr-ts-relay ).
2022-11-11 15:51:33 +05:30
[](https://railway.app/new/template/BWx8DY?referralCode=qVdmfO)
2022-04-16 23:53:25 +00:00
## Features
NIPs with a relay-specific implementation are listed here.
2022-08-13 06:43:32 +00:00
- [x] NIP-01: Basic protocol flow description
- [x] NIP-02: Contact list and petnames
- [x] NIP-04: Encrypted Direct Message
2022-08-16 04:10:00 +00:00
- [x] NIP-09: Event deletion
2022-08-08 13:04:43 +00:00
- [x] NIP-11: Relay information document
- [x] NIP-12: Generic tag queries
2022-09-22 21:47:57 +00:00
- [x] NIP-13: Proof of Work
2022-08-07 07:38:18 +00:00
- [x] NIP-15: End of Stored Events Notice
2022-08-13 06:43:32 +00:00
- [x] NIP-16: Event Treatment
2022-11-15 20:09:52 -05:00
- [x] NIP-20: Command Results
2022-09-22 21:47:57 +00:00
- [x] NIP-22: Event `created_at` Limits
2022-10-28 23:21:35 -04:00
- [x] NIP-26: Delegated Event Signing
2022-10-30 18:17:04 -04:00
- [x] NIP-33: Parameterized Replaceable Events
2022-04-16 23:53:25 +00:00
2022-08-07 22:47:59 +00:00
## Requirements
2022-11-15 20:09:52 -05:00
### Standalone setup
- PostgreSQL 15.0
- Redis
2022-10-28 23:21:35 -04:00
- Node v18
2022-08-07 22:47:59 +00:00
- Typescript
2022-10-17 04:35:12 +00:00
2022-11-15 20:09:52 -05:00
### Docker setups
- Node v18
- Docker v20.10
- Docker compose v2.10
2022-12-17 15:19:16 -05:00
## Full Guide
- [Set up a Nostr relay in under 5 minutes ](https://andreneves.xyz/p/set-up-a-nostr-relay-server-in-under ) by [André Neves ](https://twitter.com/andreneves ) (CTO & Co-Founder At [ZEBEDEE ](https://zebedee.io/ ))
2022-11-15 20:09:52 -05:00
## Quick Start (Docker Compose)
2022-08-07 22:47:59 +00:00
2022-11-06 01:25:36 -04:00
Install Docker following the [official guide ](https://docs.docker.com/engine/install/ ).
You may have to uninstall Docker if you installed it using a different guide.
Clone repository and enter directory:
```
git clone git@github .com:Cameri/nostr-ts-relay.git
cd nostr-ts-relay
```
2022-12-20 23:05:12 -05:00
Start:
2022-10-17 04:35:12 +00:00
```
2022-12-20 23:05:12 -05:00
./scripts/start
2022-10-28 23:21:35 -04:00
```
2022-12-20 23:05:12 -05:00
or
2022-11-06 19:30:29 -05:00
```
2022-12-20 23:05:12 -05:00
./scripts/start_with_tor
2022-11-06 19:30:29 -05:00
```
2022-12-20 23:05:12 -05:00
Stop the server with:
2022-11-06 19:30:29 -05:00
```
2022-12-20 23:05:12 -05:00
./scripts/stop
2022-11-06 19:30:29 -05:00
```
Print the Tor hostname:
```
2022-12-20 23:05:12 -05:00
./scripts/print_tor_hostname
2022-11-06 19:30:29 -05:00
```
2022-10-17 04:35:12 +00:00
## Quick Start (Standalone)
2022-04-16 23:53:25 +00:00
2022-08-07 22:47:59 +00:00
Set the following environment variables:
```
DB_HOST=localhost
DB_PORT=5432
2022-10-17 04:35:12 +00:00
DB_NAME=nostr_ts_relay
2022-08-07 22:47:59 +00:00
DB_USER=postgres
DB_PASSWORD=postgres
2022-11-15 20:09:52 -05:00
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_USER=default
REDIS_PASSWORD=nostr_ts_relay
2022-08-07 22:47:59 +00:00
```
2022-10-17 04:35:12 +00:00
Create `nostr_ts_relay` database:
2022-08-07 22:47:59 +00:00
```
$ psql -h $DB_HOST -p $DB_PORT -U $DB_USER -W
2022-10-17 04:35:12 +00:00
postgres=# create database nostr_ts_relay;
2022-08-07 22:47:59 +00:00
postgres=# quit
```
2022-11-15 20:09:52 -05:00
Start Redis and use `redis-cli` to set the default password and verify:
```
$ redis-cli
127.0.0.1:6379> CONFIG SET requirepass "nostr_ts_relay"
OK
127.0.0.1:6379> AUTH nostr_ts_relay
Ok
```
2022-11-06 01:25:36 -04:00
Clone repository and enter directory:
```
git clone git@github .com:Cameri/nostr-ts-relay.git
cd nostr-ts-relay
```
2022-08-07 07:38:18 +00:00
Install dependencies:
```
2022-10-17 04:35:12 +00:00
npm install -g knex
2022-08-07 07:38:18 +00:00
npm install
```
2022-10-28 23:21:35 -04:00
Run migrations (at least once and after pulling new changes):
2022-08-07 22:47:59 +00:00
```
npm run db:migrate
```
2022-10-17 04:35:12 +00:00
Create ~/.nostr folder:
```
mkdir ~/.nostr
```
2022-08-07 07:38:18 +00:00
To start in development mode:
```
npm run dev
```
2022-04-16 23:53:25 +00:00
2022-10-17 04:35:12 +00:00
Or, start in production mode:
```
npm run start
```
2022-10-28 23:21:35 -04:00
To clean up the build, coverage and test reports run:
```
npm run clean
```
## Tests
### Unit tests
2022-11-06 01:25:36 -04:00
Open a terminal and change to the project's directory:
```
cd /path/to/nostr-ts-relay
```
2022-10-28 23:21:35 -04:00
Run unit tests with:
```
npm run test:unit
```
Or, run unit tests in watch mode:
```
npm run test:unit:watch
```
To get unit test coverage run:
```
npm run cover:unit
```
To see the unit tests report open `.test-reports/unit/index.html` with a browser:
```
open .test-reports/unit/index.html
```
To see the unit tests coverage report open `.coverage/unit/lcov-report/index.html` with a browser:
```
open .coverage/unit/lcov-report/index.html
```
### Integration tests (Docker Compose)
2022-11-06 01:25:36 -04:00
Open a terminal and change to the project's directory:
```
cd /path/to/nostr-ts-relay
```
2022-10-28 23:21:35 -04:00
Run integration tests with:
```
npm run docker:test:integration
```
And to get integration test coverage run:
```
npm run docker:cover:integration
```
### Integration tests (Standalone)
2022-11-06 01:25:36 -04:00
Open a terminal and change to the project's directory:
```
cd /path/to/nostr-ts-relay
```
2022-10-28 23:21:35 -04:00
Set the following environment variables:
```
DB_HOST=localhost
DB_PORT=5432
DB_NAME=nostr_ts_relay_test
DB_USER=postgres
DB_PASSWORD=postgres
DB_MIN_POOL_SIZE=1
DB_MAX_POOL_SIZE=2
```
Then run the integration tests:
```
npm run test:integration
```
To see the integration tests report open `.test-reports/integration/report.html` with a browser:
```
open .test-reports/integration/report.html
```
To get the integration test coverage run:
```
npm run cover:integration
```
To see the integration test coverage report open `.coverage/integration/lcov-report/index.html` with a browser.
```
open .coverage/integration/lcov-report/index.html
```
2022-04-16 23:53:25 +00:00
## Configuration
2022-10-17 04:35:12 +00:00
You can change the default folder by setting the `NOSTR_CONFIG_DIR` environment variable to a different path.
Run nostr-ts-relay using one of the quick-start guides at least once and `~/.nostr/settings.json` will be created.
Any changes made to the settings file will be read on the next start.
2022-04-16 23:53:25 +00:00
2022-10-25 22:25:07 -04:00
A sample settings file is included at the project root under the name `settings.sample.json` . Feel free to copy it to `~/.nostr/settings.json`
if you would like to have a settings file before running the relay first.
2022-10-25 22:17:07 -04:00
2022-10-25 22:25:07 -04:00
See [CONFIGURATION.md ](CONFIGURATION.md ) for a detailed explanation of each environment variable and setting.
2022-04-16 23:53:25 +00:00
## Dev Channel
2022-10-18 23:43:13 -04:00
For development discussions, please use the [Nostr Typescript Relay Dev Channel ](https://t.me/nostr_ts_relay ).
For discussions about the protocol, please feel free to use the [Nostr Telegram Channel ](https://t.me/nostr_protocol ).
2022-04-16 23:53:25 +00:00
## License
This project is MIT licensed.