nostream/README.md

392 lines
9.5 KiB
Markdown
Raw Permalink Normal View History

2022-12-24 15:44:38 -05:00
# [nostream](https://github.com/Cameri/nostream)
2022-04-16 23:53:25 +00:00
2022-10-26 16:38:50 -07:00
<p align="center">
2022-12-24 15:44:38 -05:00
<img alt="nostream logo" height="256px" width="256px" src="https://user-images.githubusercontent.com/378886/198158439-86e0345a-adc8-4efe-b0ab-04ff3f74c1b2.jpg" />
2022-10-26 16:38:50 -07:00
</p>
2022-10-19 02:37:20 +00:00
<p align="center">
2022-12-24 15:44:38 -05:00
<a href="https://github.com/Cameri/nostream/releases">
<img alt="GitHub release" src="https://img.shields.io/github/v/release/Cameri/nostream">
2022-11-06 12:04:38 -05:00
</a>
2022-12-24 15:44:38 -05:00
<a href="https://github.com/Cameri/nostream/issues">
<img alt="GitHub issues" src="https://img.shields.io/github/issues/Cameri/nostream?style=plastic" />
2022-10-18 23:43:13 -04:00
</a>
2022-12-24 15:44:38 -05:00
<a href="https://github.com/Cameri/nostream/stargazers">
<img alt="GitHub stars" src="https://img.shields.io/github/stars/Cameri/nostream" />
2022-10-18 23:43:13 -04:00
</a>
2022-12-24 15:44:38 -05:00
<img alt="GitHub top language" src="https://img.shields.io/github/languages/top/Cameri/nostream">
<a href="https://github.com/Cameri/nostream/network">
<img alt="GitHub forks" src="https://img.shields.io/github/forks/Cameri/nostream" />
2022-10-18 23:43:13 -04:00
</a>
2022-12-24 15:44:38 -05:00
<a href="https://github.com/Cameri/nostream/blob/main/LICENSE">
<img alt="GitHub license" src="https://img.shields.io/github/license/Cameri/nostream" />
2022-10-18 23:43:13 -04:00
</a>
2022-12-24 15:44:38 -05:00
<a href='https://coveralls.io/github/Cameri/nostream?branch=main'>
<img alt='Coverage Status' src='https://coveralls.io/repos/github/Cameri/nostream/badge.svg?branch=main' />
2022-10-18 23:43:13 -04:00
</a>
2022-12-26 01:21:25 -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&metric=alert_status' />
</a>
2022-12-24 15:44:38 -05:00
<a href='https://github.com/Cameri/nostream/actions'>
<img alt='Build status' src='https://github.com/Cameri/nostream/actions/workflows/checks.yml/badge.svg?branch=main&event=push' />
2022-10-18 23:43:13 -04:00
</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-12-24 15:44:38 -05:00
The project master repository is available on [GitHub](https://github.com/Cameri/nostream).
2022-04-16 23:53:25 +00:00
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template/Xfk5F7?referralCode=Kfv2ly)
2022-11-11 15:51:33 +05:30
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
- [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
- [x] NIP-26: Delegated Event Signing
2022-12-26 01:21:25 -05:00
- [x] NIP-28: Public Chat
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 14.0
2022-11-15 20:09:52 -05:00
- Redis
- 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
- Docker v20.10
- Docker Compose v2.10
### Local Docker setup
- Docker Desktop v4.2.0 or newer
- [mkcert](https://github.com/FiloSottile/mkcert)
2022-11-15 20:09:52 -05:00
WARNING: Docker distributions from Snap, Brew or Debian repositories are NOT SUPPORTED and will result in errors.
Install Docker from their [official guide](https://docs.docker.com/engine/install/) ONLY.
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/))
## Local Quick Start (Docker Compose)
Install Docker Desktop following the [official guide](https://docs.docker.com/desktop/).
You may have to uninstall Docker on your machine if you installed it using a different guide.
Clone repository and enter directory:
```
git clone git@github.com:Cameri/nostream.git
cd nostream
```
Start:
```
./scripts/start_local
```
This will run in the foreground of the terminal until you stop it with Ctrl+C.
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:
```
2022-12-24 15:44:38 -05:00
git clone git@github.com:Cameri/nostream.git
cd nostream
2022-11-06 01:25:36 -04:00
```
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-12-20 23:05:12 -05:00
or
```
2022-12-20 23:05:12 -05:00
./scripts/start_with_tor
```
2022-12-20 23:05:12 -05:00
Stop the server with:
```
2022-12-20 23:05:12 -05:00
./scripts/stop
```
Print the Tor hostname:
```
2022-12-20 23:05:12 -05:00
./scripts/print_tor_hostname
```
### Running as a Service
By default this server will run continuously until you stop it with Ctrl+C or until the system restarts.
You can [install as a systemd service](https://www.swissrouting.com/nostr.html#installing-as-a-service) if you want the server to run again automatically whenever the system is restarted. For example:
```
2022-12-24 15:44:38 -05:00
$ nano /etc/systemd/system/nostream.service
# Note: replace "User=..." with your username, and
2022-12-24 15:44:38 -05:00
# "/home/nostr/nostream" with the directory where you cloned the repo.
[Unit]
Description=Nostr TS Relay
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=5
User=nostr
2022-12-24 15:44:38 -05:00
WorkingDirectory=/home/nostr/nostream
ExecStart=/home/nostr/nostream/scripts/start
ExecStop=/home/nostr/nostream/scripts/stop
[Install]
WantedBy=multi-user.target
```
And then:
```
2022-12-24 15:44:38 -05:00
systemctl enable nostream
systemctl start nostream
```
The logs can be viewed with:
```
2022-12-24 15:44:38 -05:00
journalctl -u nostream
```
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_URI="postgresql://postgres:postgres@localhost:5432/nostr_ts_relay_test"
or
2022-08-07 22:47:59 +00:00
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
REDIS_URI="redis://default:nostr_ts_relay@localhost:6379"
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:
```
2022-12-24 15:44:38 -05:00
git clone git@github.com:Cameri/nostream.git
cd nostream
2022-11-06 01:25:36 -04:00
```
Install dependencies:
```
2022-10-17 04:35:12 +00:00
npm install -g knex
npm install
```
Run migrations (at least once and after pulling new changes):
2022-08-07 22:47:59 +00:00
```
npm run db:migrate
```
2023-01-18 15:38:13 -08:00
Create .nostr folder inside nostream project folder:
2022-10-17 04:35:12 +00:00
```
2023-01-18 15:38:13 -08:00
mkdir .nostr
2022-10-17 04:35:12 +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
```
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:
```
2022-12-24 15:44:38 -05:00
cd /path/to/nostream
2022-11-06 01:25:36 -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:
```
2022-12-24 15:44:38 -05:00
cd /path/to/nostream
2022-11-06 01:25:36 -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:
```
2022-12-24 15:44:38 -05:00
cd /path/to/nostream
2022-11-06 01:25:36 -04:00
```
Set the following environment variables:
```
DB_URI="postgresql://postgres:postgres@localhost:5432/nostr_ts_relay_test"
or
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.
2023-01-18 15:38:13 -08:00
Run nostream using one of the quick-start guides at least once and `nostream/.nostr/settings.json` will be created.
2022-10-17 04:35:12 +00:00
Any changes made to the settings file will be read on the next start.
2022-04-16 23:53:25 +00:00
Default settings can be found under `resources/default-settings.yaml`. Feel free to copy it to `nostream/.nostr/settings.yaml` 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
2023-01-18 15:38:13 -08:00
For development discussions, please use the [Nostr Typescript Relay Dev Group](https://t.me/nostream_dev).
2022-10-18 23:43:13 -04:00
2023-01-18 15:38:13 -08:00
For discussions about the protocol, please feel free to use the [Nostr Telegram Group](https://t.me/nostr_protocol).
2022-04-16 23:53:25 +00:00
2022-12-23 07:11:42 -05:00
# Author
I'm Cameri on most social networks. You can find me on Nostr by npub1qqqqqqyz0la2jjl752yv8h7wgs3v098mh9nztd4nr6gynaef6uqqt0n47m.
2023-01-18 15:38:13 -08:00
# Contributors (A-Z)
- Anton Livaja
- Juan Angel
- Kevin Smith
- Saransh Sharma
- swissrouting
2022-04-16 23:53:25 +00:00
## License
This project is MIT licensed.