Skip to content

Commit

Permalink
feat: support paid (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
flxxyz authored Jun 2, 2023
1 parent 4fa1dbf commit e690bbd
Show file tree
Hide file tree
Showing 100 changed files with 2,210 additions and 958 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Bug report
about: Create a report to help us improve
title: "[BUG] "
labels: bug
assignees: Guakamoli
assignees: denostr-protocol

---

Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Feature request
about: Suggest an idea for this project
title: "[REQUEST]"
labels: enhancement
assignees: Guakamoli
assignees: denostr-protocol

---

Expand Down
52 changes: 28 additions & 24 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,34 @@

The following environment variables can be set:

| Name | Description | Default |
| ---------------------- | -------------------------------- | ------------------------------------ |
| SECRET | Long random secret. | abcdefghijklmnopqrstuvwxyz1234567890 |
| RELAY_PORT | Relay's server port | 8008 |
| RELAY_PRIVATE_KEY | Relay's private key in hex | (auto-generated) |
| MONGO_URI | MongoDB URI | |
| MONGO_MIN_POOL_SIZE | Min. connections per worker | 0 |
| MONGO_MAX_POOL_SIZE | Max. connections per worker | 3 |
| MONGO_REPLICA_ENABLED | Read Replica (RR) Toggle | false |
| MONGO_RR_MIN_POOL_SIZE | Min. connections per worker (RR) | 0 |
| MONGO_RR_MAX_POOL_SIZE | Max. connections per worker (RR) | 3 |
| TOR_HOST | Tor Hostname | |
| TOR_CONTROL_PORT | Tor control Port | 9051 |
| TOR_PASSWORD | Tor control password | nostr_ts_relay |
| HIDDEN_SERVICE_PORT | Tor hidden service port | 80 |
| REDIS_HOST | Redis Host | |
| REDIS_PORT | Redis Port | 6379 |
| REDIS_DB | Redis DB | 0 |
| REDIS_USER | Redis User | |
| REDIS_PASS | Redis Password | |
| REDIS_TLS | Redis TLS | false |
| NOSTR_CONFIG_DIR | Configuration directory | <project_root>/.nostr/ |
| DEBUG | Debugging filter | |
| ZEBEDEE_API_KEY | Zebedee Project API Key | |
| Name | Description | Default |
| -------------------------- | ----------------------------------- | --------------------------------------- |
| SECRET | Long random secret. | abcdefghijklmnopqrstuvwxyz1234567890 |
| RELAY_PORT | Relay's server port | 8008 |
| RELAY_PRIVATE_KEY | Relay's private key in hex | (auto-generated) |
| MONGO_URI | MongoDB URI | |
| MONGO_MIN_POOL_SIZE | Min. connections per worker | 0 |
| MONGO_MAX_POOL_SIZE | Max. connections per worker | 3 |
| MONGO_REPLICA_ENABLED | Read Replica (RR) Toggle | false |
| MONGO_RR_MIN_POOL_SIZE | Min. connections per worker (RR) | 0 |
| MONGO_RR_MAX_POOL_SIZE | Max. connections per worker (RR) | 3 |
| TOR_HOST | Tor Hostname | |
| TOR_CONTROL_PORT | Tor control Port | 9051 |
| TOR_PASSWORD | Tor control password | nostr_ts_relay |
| HIDDEN_SERVICE_PORT | Tor hidden service port | 80 |
| REDIS_HOST | Redis Host | |
| REDIS_PORT | Redis Port | 6379 |
| REDIS_DB | Redis DB | 0 |
| REDIS_USER | Redis User | |
| REDIS_PASS | Redis Password | |
| REDIS_TLS | Redis TLS | false |
| NOSTR_CONFIG_DIR | Configuration directory | <project_root>/.nostr/ |
| DEBUG | Debugging filter | |
| ZEBEDEE_API_KEY | Zebedee Project API Key | |
| LNBITS_API_KEY | Lnbits Invoice/read Key | |
| OPENNODE_API_KEY | API Key with Invoices Key | |
| NODELESS_API_KEY | Nodeless API key | |
| NODELESS_WEBHOOK_SECRET | Nodeless webhook secret | |

# Settings

Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ FROM denoland/deno:alpine-1.31.3 as base

LABEL org.opencontainers.image.title=denostr
LABEL org.opencontainers.image.description='Deno-based, cloud-native nostr implementation supported by ByteTrade and Revo, forked from nostream.'
LABEL org.opencontainers.image.authors=GUAKAMOLI
LABEL org.opencontainers.image.authors=Denostr
LABEL org.opencontainers.image.licenses=MIT
LABEL org.opencontainers.image.url=https://github.com/guakamoli/denostr
LABEL org.opencontainers.image.source=https://github.com/guakamoli/denostr
LABEL org.opencontainers.image.url=https://github.com/denostr-protocol/denostr
LABEL org.opencontainers.image.source=https://github.com/denostr-protocol/denostr

# Create the app directory
WORKDIR /app
Expand Down
107 changes: 80 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
# [Denostr](https://github.com/Guakamoli/denostr)
# [Denostr](https://github.com/denostr-protocol/denostr)

<p align="center">
<img alt="denostr logo" height="256px" width="256px" src="https://user-images.githubusercontent.com/8678079/233816217-27504e7e-b429-4388-ac69-592122fa922b.png" />
</p>

<p align="center">
<a href="https://github.com/Guakamoli/denostr/releases">
<img alt="GitHub release" src="https://img.shields.io/github/v/release/Guakamoli/denostr">
<a href="https://github.com/denostr-protocol/denostr/releases">
<img alt="GitHub release" src="https://img.shields.io/github/v/release/denostr-protocol/denostr">
</a>
<a href="https://github.com/Guakamoli/denostr/issues">
<img alt="GitHub issues" src="https://img.shields.io/github/issues/Guakamoli/denostr?style=plastic" />
<a href="https://github.com/denostr-protocol/denostr/issues">
<img alt="GitHub issues" src="https://img.shields.io/github/issues/denostr-protocol/denostr?style=plastic" />
</a>
<a href="https://github.com/Guakamoli/denostr/stargazers">
<img alt="GitHub stars" src="https://img.shields.io/github/stars/Guakamoli/denostr" />
<a href="https://github.com/denostr-protocol/denostr/stargazers">
<img alt="GitHub stars" src="https://img.shields.io/github/stars/denostr-protocol/denostr" />
</a>
<img alt="GitHub top language" src="https://img.shields.io/github/languages/top/Guakamoli/denostr">
<a href="https://github.com/Guakamoli/denostr/network">
<img alt="GitHub forks" src="https://img.shields.io/github/forks/Guakamoli/denostr" />
<img alt="GitHub top language" src="https://img.shields.io/github/languages/top/denostr-protocol/denostr">
<a href="https://github.com/denostr-protocol/denostr/network">
<img alt="GitHub forks" src="https://img.shields.io/github/forks/denostr-protocol/denostr" />
</a>
<a href="https://github.com/Guakamoli/denostr/blob/main/LICENSE">
<img alt="GitHub license" src="https://img.shields.io/github/license/Guakamoli/denostr" />
<a href="https://github.com/denostr-protocol/denostr/blob/main/LICENSE">
<img alt="GitHub license" src="https://img.shields.io/github/license/denostr-protocol/denostr" />
</a>
<a href='https://coveralls.io/github/Guakamoli/denostr?branch=main'>
<img alt='Coverage Status' src='https://coveralls.io/repos/github/Guakamoli/denostr/badge.svg?branch=main' />
<a href='https://coveralls.io/github/denostr-protocol/denostr?branch=main'>
<img alt='Coverage Status' src='https://coveralls.io/repos/github/denostr-protocol/denostr/badge.svg?branch=main' />
</a>
<a href='https://github.com/Guakamoli/denostr/actions'>
<img alt='Build status' src='https://github.com/Guakamoli/denostr/actions/workflows/checks.yml/badge.svg?branch=main&event=push' />
<a href='https://github.com/denostr-protocol/denostr/actions'>
<img alt='Build status' src='https://github.com/denostr-protocol/denostr/actions/workflows/checks.yml/badge.svg?branch=main&event=push' />
</a>
</p>

Expand All @@ -35,7 +35,7 @@ This is a [nostr](https://github.com/fiatjaf/nostr) relay, written in Typescript

This implementation is production-ready. See below for supported features.

The project main repository is available on [GitHub](https://github.com/Guakamoli/denostr).
The project main repository is available on [GitHub](https://github.com/denostr-protocol/denostr).

## Features

Expand Down Expand Up @@ -70,33 +70,86 @@ Todo
- Deno v1.30.x or v1.31.x
- Typescript
- MongoDB 4.4, 5.0, 6.0
- Redis (Optional)
- Redis (Standalone Optional, Cluster Required)

### kubernetes setups

- v1.18.8 or later

## Full Guide

- [ ] Set up a paid Nostr relay
> NOTE: If the payment is enabled, it is recommended to start another instance with `WORKER_TYPE=maintenance` following the "Quick Start" guide.
### Accepting payments

1. Zebedee
1. Before you begin
- Complete one of the Quick Start guides in this document
- Create a `.env` file
- On `.nostr/settings.yaml` file make the following changes:
- Set `payments.enabled` to `true`
- Set `payments.feeSchedules.admission.enabled` to `true`
- Set `limits.event.pubkey.minBalance` to the minimum balance in msats required to accept events (i.e. `1000000` to require a balance of `1000` sats)
- Choose one of the following payment processors: `lnbits`, `lnurl`, `zebedee`

2. [LNbits](https://lnbits.com/)
- Complete the step "Before you begin"
- Create a new wallet on you public LNbits instance
- [Demo](https://legend.lnbits.com/) server must not be used for production
- Your instance must be accessible from the internet and have a valid SSL/TLS certificate
- Get wallet "Invoice/read key" (in Api docs section of your wallet)
- set `LNBITS_API_KEY` environment variable with the "Invoice/read key" Key above on your `.env` file

```
LNBITS_API_KEY={YOUR_LNBITS_API_KEY_HERE}
```
- On your `.nostr/settings.yaml` file make the following changes:
- Set `payments.processor` to `lnbits`
- set `lnbits.baseURL` to your LNbits instance URL (e.g. `https://{YOUR_LNBITS_DOMAIN_HERE}/`)
- Set `paymentsProcessors.lnbits.callbackBaseURL` to match your callbcak URL (e.g. `https://{YOUR_DOMAIN_HERE}/callbacks/lnbits`)
- Restart Denostr
3. [Alby](https://getalby.com/) or any LNURL Provider with [LNURL-verify](https://github.com/lnurl/luds/issues/182) support
- Complete the step "Before you begin"
- [Create a new account](https://getalby.com/user/new) if you don't have an LNURL
- On your `.nostr/settings.yaml` file make the following changes:
- Set `payments.processor` to `lnurl`
- Set `lnurl.invoiceURL` to your LNURL (e.g. `https://getalby.com/lnurlp/your-username`)
- Restart Denostr
4. [ZEBEDEE](https://zebedee.io)
- Complete the step "Before you begin"
- [Sign up for a ZEBEDEE Developer Dashboard account](https://dashboard.zebedee.io/signup), create a new LIVE Project, and get that Project's API Key
- Set `ZEBEDEE_API_KEY` environment variable with the API Key above on your `.env` file
```
ZEBEDEE_API_KEY={YOUR_ZEBEDEE_API_KEY_HERE}
```
- Follow the required steps for all payments processors
- On `.nostr/settings.yaml` file make the following changes:
- `payments.processor` to `zebedee`
- `paymentsProcessors.zebedee.callbackBaseURL` to match your callback URL (e.g. `https://{YOUR_DOMAIN_HERE}/callbacks/zebedee`)
- Restart Denostr
5. Ensure payments are required for your public key
- Visit https://{YOUR-DOMAIN}/
- You should be presented with a form requesting an admission fee to be paid
- Fill out the form and take the necessary steps to pay the invoice
- Wait until the screen indicates that payment was received
- Add your relay URL to your favorite Nostr client (wss://{YOUR-DOMAIN}) and wait for it to connect
- Send a couple notes to test
- Go to https://websocketking.com/ and connect to your relay (wss://{YOUR_DOMAIN})
- Convert your npub to hexadecimal using a [Key Converter](https://damus.io/key/)
- Send the following JSON message: `["REQ", "payment-test", {"authors":["your-pubkey-in-hexadecimal"]}]`
- You should get back the few notes you sent earlier
- You must set `ZEBEDEE_API_KEY` with an API Key from one of your projects in your Zebedee Developer Dashboard. Contact @foxp2zeb on Telegram or npub1rvg76s0gz535txd9ypg2dfqv0x7a80ar6e096j3v343xdxyrt4ksmkxrck on Nostr requesting access to
the Zebedee Developer Dashboard. See the Zebedee full guide on how to set up a paid relay.

2. Lnbits

- You must set `LNBITS_API_KEY` with an API Key from one of "Invoice/read key" in your wallet.
### Quick Start (Standalone)
Clone repository and enter directory:
```sh
git clone https://github.com/Guakamoli/denostr.git --depth 1 && cd denostr
git clone https://github.com/denostr-protocol/denostr.git --depth 1 && cd denostr
```

Create `.env` file inside denostr project folder
Expand Down
43 changes: 26 additions & 17 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
{
"tasks": {
"dev": "deno run --allow-all --watch src/index.ts",
"start": "deno run --allow-all src/index.ts",
"dev": "deno run -A --unstable --watch src/index.ts",
"start": "deno run -A --unstable src/index.ts",
"test": "deno test --no-check -A",
"test:unit": "deno test test/unit --no-check -A",
"test:unit:cache": "deno test --no-check -A test/unit/cache",
"test:unit:factories": "deno test --no-check -A test/unit/factories",
"test:unit:handlers": "deno test --no-check -A test/unit/handlers",
"test:unit:repositories": "deno test --no-check -A test/unit/repositories",
"test:unit:schemas": "deno test --no-check -A test/unit/schemas",
"test:unit:tor": "deno test --no-check -A test/unit/tor",
"test:unit:utils": "deno test --no-check -A test/unit/utils",
"test:integration": "deno test test/integration --no-check -A",
"test:integration:nip01": "deno test test/integration/features/nip-01/nip-01.feature.test.ts --no-check -A",
"test:integration:nip09": "deno test test/integration/features/nip-09/nip-09.feature.test.ts --no-check -A",
Expand All @@ -13,37 +20,39 @@
"git-hooks": "deno run --no-check=remote --allow-run=deno,git --allow-read --allow-write=.git-hooks https://deno.land/x/githooked/mod.ts install",
"bump": "deno run --allow-all .bump/bump.ts",
"cache": "deno cache src/index.ts --reload",
"force-cache": "deno cache src/index.ts --reload --lock-write"
"cache:force": "deno cache src/index.ts --reload --lock-write"
},
"imports": {
"@/": "./src/",
"Buffer": "https://deno.land/std@0.177.1/node/buffer.ts",
"crypto": "https://deno.land/std@0.177.1/node/crypto.ts",
"events": "https://deno.land/std@0.177.1/node/events.ts",
"stream": "https://deno.land/std@0.177.1/node/stream.ts",
"stream/promises": "https://deno.land/std@0.177.1/node/stream/promises.mjs",
"dns": "https://deno.land/std@0.177.1/node/dns.ts",
"net": "https://deno.land/std@0.177.1/node/net.ts",
"tls": "https://deno.land/std@0.177.1/node/tls.ts",
"path": "https://deno.land/std@0.177.1/node/path.ts",
"os": "https://deno.land/std@0.177.1/node/os.ts",
"fs": "https://deno.land/std@0.177.1/node/fs.ts",
"fs/promises": "https://deno.land/std@0.177.1/node/fs/promises.ts",
"dotenv": "https://deno.land/x/dotenv@v3.2.0/mod.ts",
"ramda": "https://deno.land/x/ramda@v0.27.2/mod.ts",
"redis": "https://deno.land/x/redis@v0.29.2/mod.ts",
"redis": "https://deno.land/x/redis@v0.29.4/mod.ts",
"redis/": "https://deno.land/x/redis@v0.29.4/",
"debug": "https://deno.land/x/debuglog@v1.0.0/debug.ts",
"websocket": "./vendor/deno.land/x/websocket@v0.1.4/mod.ts",
"jest": "https://deno.land/std@0.180.0/testing/bdd.ts",
"oak": "https://deno.land/x/oak@v12.1.0/mod.ts",
"Buffer": "https://deno.land/std@0.139.0/node/buffer.ts",
"secp256k1": "https://deno.land/x/secp256k1@1.7.1/mod.ts",
"crypto": "https://deno.land/std@0.177.0/node/crypto.ts",
"oak-csp": "https://deno.land/x/oak_csp@1.0.3/mod.ts",
"json2yaml": "https://deno.land/x/json2yaml@v1.0.1/mod.ts",
"chai": "https://cdn.skypack.dev/chai@4.3.4?dts",
"sinon-chai": "https://cdn.skypack.dev/sinon-chai@3.7.0?dts",
"sinon": "https://cdn.skypack.dev/sinon@15.0.1?dts",
"@cucumber/cucumber": "https://cdn.skypack.dev/@cucumber/cucumber@9.0.0?dts",
"joi": "https://cdn.skypack.dev/joi@17.7.0?dts",
"rxjs": "https://cdn.skypack.dev/rxjs@7.8.0?dts",
"chai-as-promised": "https://cdn.skypack.dev/chai-as-promised@7.1.1?dts",
"events": "https://deno.land/std@0.177.0/node/events.ts",
"stream": "node:stream",
"stream/promises": "node:stream/promises",
"dns": "node:dns",
"net": "node:net",
"tls": "node:tls",
"path": "node:path",
"os": "node:os",
"fs": "node:fs",
"fs/promises": "node:fs/promises",
"bson": "npm:bson@5.3.0",
"@isaacs/ttlcache": "npm:@isaacs/ttlcache@1.4.0",
"mongodb": "npm:mongodb@5.3.0",
Expand Down
Loading

0 comments on commit e690bbd

Please sign in to comment.