Merge pull request 'feat: add nostr relay' (#4) from feat/add_nostr_relay into main

Reviewed-on: https://git.devvul.com///Asara/well-goknown/pulls/4
This commit is contained in:
Amarpreet Minhas 2024-08-15 01:22:46 +00:00
commit b65ce5753a
9 changed files with 229 additions and 32 deletions

View file

@ -17,3 +17,8 @@ GRANT ALL PRIVILEGES ON DATABASE wgk TO wgk;
ALTER DATABASE wgk OWNER TO wgk; ALTER DATABASE wgk OWNER TO wgk;
EOF EOF
``` ```
To build a release version, go to a tag and run:
```
go build -ldflags="-X main.Commit=$(git tag)"
```

View file

@ -12,6 +12,11 @@ type (
MatrixIdentityServer string MatrixIdentityServer string
MatrixMsc3575Address string MatrixMsc3575Address string
MatrixWellKnownAddress string MatrixWellKnownAddress string
RelayName string
RelayPubkey string
RelayDescription string
RelayIcon string
RelayContact string
} }
) )
@ -23,6 +28,11 @@ func GetConfig() Config {
MatrixIdentityServer: getEnv("MATRIX_IDENTITY_SERVER", ""), MatrixIdentityServer: getEnv("MATRIX_IDENTITY_SERVER", ""),
MatrixMsc3575Address: getEnv("MATRIX_MSC3575_ADDRESS", ""), MatrixMsc3575Address: getEnv("MATRIX_MSC3575_ADDRESS", ""),
MatrixWellKnownAddress: getEnv("MATRIX_WELL_KNOWN_ADDRESS", ""), MatrixWellKnownAddress: getEnv("MATRIX_WELL_KNOWN_ADDRESS", ""),
RelayName: getEnv("RELAY_NAME", ""),
RelayPubkey: getEnv("RELAY_PUBKEY", ""),
RelayDescription: getEnv("RELAY_DESCRIPTION", ""),
RelayIcon: getEnv("RELAY_ICON", ""),
RelayContact: getEnv("RELAY_CONTACT", ""),
} }
} }

View file

@ -1,8 +1,8 @@
package db package db
import ( import (
"git.minhas.io/asara/gologger" "git.devvul.com/asara/gologger"
"git.minhas.io/asara/well-goknown/config" "git.devvul.com/asara/well-goknown/config"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
_ "github.com/lib/pq" _ "github.com/lib/pq"
) )

39
go.mod
View file

@ -1,16 +1,41 @@
module git.minhas.io/asara/well-goknown module git.devvul.com/asara/well-goknown
go 1.19 go 1.23.0
require ( require (
git.minhas.io/asara/gologger v0.7.0 git.devvul.com/asara/gologger v0.8.0
github.com/fiatjaf/eventstore v0.7.1
github.com/fiatjaf/khatru v0.7.5
github.com/jmoiron/sqlx v1.4.0 github.com/jmoiron/sqlx v1.4.0
github.com/lib/pq v1.10.9 github.com/lib/pq v1.10.9
github.com/nbd-wtf/go-nostr v0.34.5
) )
require ( require (
github.com/mattn/go-colorable v0.1.12 // indirect github.com/andybalholm/brotli v1.0.5 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/rs/zerolog v1.30.0 // indirect github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 // indirect
golang.org/x/sys v0.6.0 // indirect github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/fasthttp/websocket v1.5.7 // indirect
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect
github.com/gobwas/ws v1.3.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/puzpuzpuz/xsync/v3 v3.0.2 // indirect
github.com/rs/cors v1.7.0 // indirect
github.com/rs/zerolog v1.33.0 // indirect
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
github.com/tidwall/gjson v1.17.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.51.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/sys v0.20.0 // indirect
) )

83
go.sum
View file

@ -1,26 +1,87 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
git.minhas.io/asara/gologger v0.7.0 h1:pY3III9B/gBIXKyCHuyXwUV+4cBUj0swZciXQtsgVlY= git.devvul.com/asara/gologger v0.8.0 h1:UsBgNr1ZNpDVqVMTNy3KzSV1afqP0vmTiZvKXZ4YoGk=
git.minhas.io/asara/gologger v0.7.0/go.mod h1:5VKIJo/rWCJayKr4PteS9s9LE6zPlrsOC70C86/Zipg= git.devvul.com/asara/gologger v0.8.0/go.mod h1:APr1DdVYByFfPUGHqHtRMhxphQbj92/vT/t0iM40H/0=
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U=
github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 h1:KdUfX2zKommPRa+PD0sWZUyXe9w277ABlgELO7H04IM=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
github.com/fasthttp/websocket v1.5.7 h1:0a6o2OfeATvtGgoMKleURhLT6JqWPg7fYfWnH4KHau4=
github.com/fasthttp/websocket v1.5.7/go.mod h1:bC4fxSono9czeXHQUVKxsC0sNjbm7lPJR04GDFqClfU=
github.com/fiatjaf/eventstore v0.7.1 h1:5f2yvEtYvsvMBNttysmXhSSum5M1qwvPzjEQ/BFue7Q=
github.com/fiatjaf/eventstore v0.7.1/go.mod h1:ek/yWbanKVG767fK51Q3+6Mvi5oEHYSsdPym40nZexw=
github.com/fiatjaf/khatru v0.7.5 h1:UFo+cdbqHDn1W4Q4h03y3vzh1BiU+6fLYK48oWU2K34=
github.com/fiatjaf/khatru v0.7.5/go.mod h1:WVqij7X9Vr9UAMIwafQbKVFKxc42Np37vyficwUr/nQ=
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/ws v1.3.1 h1:Qi34dfLMWJbiKaNbDVzM9x27nZBjmkaW6i4+Ku+pGVU=
github.com/gobwas/ws v1.3.1/go.mod h1:hRKAFb8wOxFROYNsT1bqfWnhX+b5MFeJM9r2ZSwg/KY=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o= github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o=
github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY= github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU=
github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/nbd-wtf/go-nostr v0.34.5 h1:vti8WqvGWbVoWAPniaz7li2TpCyC+7ZS62Gmy7ib/z0=
github.com/nbd-wtf/go-nostr v0.34.5/go.mod h1:NZQkxl96ggbO8rvDpVjcsojJqKTPwqhP4i82O7K5DJs=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/puzpuzpuz/xsync/v3 v3.0.2 h1:3yESHrRFYr6xzkz61LLkvNiPFXxJEAABanTQpKbAaew=
github.com/puzpuzpuz/xsync/v3 v3.0.2/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA=
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c= github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w= github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee h1:8Iv5m6xEo1NR1AvpV+7XmhI4r39LGNzwUL4YpMuL5vk=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee/go.mod h1:qwtSXrKuJh/zsFQ12yEE89xfCrGKK63Rr7ctU/uCo4g=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tidwall/gjson v1.17.0 h1:/Jocvlh98kcTfpN2+JzGQWQcqrPQwDrVEMApx/M5ZwM=
github.com/tidwall/gjson v1.17.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA=
github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

22
main.go
View file

@ -3,11 +3,16 @@ package main
import ( import (
"net/http" "net/http"
"git.minhas.io/asara/gologger" "git.devvul.com/asara/gologger"
"git.minhas.io/asara/well-goknown/config" "git.devvul.com/asara/well-goknown/config"
"git.minhas.io/asara/well-goknown/db" "git.devvul.com/asara/well-goknown/db"
"git.minhas.io/asara/well-goknown/matrix" "git.devvul.com/asara/well-goknown/matrix"
"git.minhas.io/asara/well-goknown/nostr" "git.devvul.com/asara/well-goknown/nostr"
"github.com/fiatjaf/eventstore/postgresql"
)
var (
Version string
) )
func main() { func main() {
@ -16,6 +21,12 @@ func main() {
defer db.Close() defer db.Close()
nostr.DB = db nostr.DB = db
nostr.RelayDb = postgresql.PostgresBackend{DatabaseURL: config.GetConfig().DbUrl}
if err := nostr.RelayDb.Init(); err != nil {
l.Panic().Msgf("unable to connect to relay db: %s", err.Error())
}
relay := nostr.NewRelay(Version)
// matrix endpoints // matrix endpoints
l.Debug().Msg("enabling matrix well-known endpoints") l.Debug().Msg("enabling matrix well-known endpoints")
@ -25,6 +36,7 @@ func main() {
// nostr endpoints // nostr endpoints
l.Debug().Msg("enabling nostr well-known endpoints") l.Debug().Msg("enabling nostr well-known endpoints")
http.HandleFunc("/.well-known/nostr.json", nostr.GetNostrAddr) http.HandleFunc("/.well-known/nostr.json", nostr.GetNostrAddr)
http.Handle("/relay", relay)
// start server // start server
port := config.GetConfig().ListenAddr port := config.GetConfig().ListenAddr

View file

@ -5,8 +5,8 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"git.minhas.io/asara/gologger" "git.devvul.com/asara/gologger"
"git.minhas.io/asara/well-goknown/config" "git.devvul.com/asara/well-goknown/config"
) )
type matrixServerWellKnown struct { type matrixServerWellKnown struct {

View file

@ -1,18 +1,26 @@
package nostr package nostr
import ( import (
"context"
"encoding/json" "encoding/json"
"fmt"
"net" "net"
"net/http" "net/http"
"strings" "strings"
"git.minhas.io/asara/gologger" "git.devvul.com/asara/gologger"
"git.minhas.io/asara/well-goknown/config" "git.devvul.com/asara/well-goknown/config"
"github.com/fiatjaf/eventstore/postgresql"
"github.com/fiatjaf/khatru"
"github.com/fiatjaf/khatru/policies"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"github.com/nbd-wtf/go-nostr"
) )
var ( var (
DB *sqlx.DB DB *sqlx.DB
RelayDb postgresql.PostgresBackend
relay *khatru.Relay
) )
type nostrUser struct { type nostrUser struct {
@ -99,3 +107,74 @@ func GetNostrAddr(w http.ResponseWriter, r *http.Request) {
w.Write(j) w.Write(j)
return return
} }
func NewRelay(version string) *khatru.Relay {
// relay configuration
relay = khatru.NewRelay()
relay.Info.Name = config.GetConfig().RelayName
relay.Info.PubKey = config.GetConfig().RelayPubkey
relay.Info.Description = config.GetConfig().RelayDescription
relay.Info.Icon = config.GetConfig().RelayIcon
relay.Info.Contact = config.GetConfig().RelayContact
relay.Info.Version = version
relay.Info.Software = "https://git.devvul.com/asara/well-goknown"
// contact lists
relay.Info.SupportedNIPs = append(relay.Info.SupportedNIPs, 2)
// dms
relay.Info.SupportedNIPs = append(relay.Info.SupportedNIPs, 4)
relay.OnConnect = append(relay.OnConnect, func(ctx context.Context) {
khatru.RequestAuth(ctx)
})
// storage
relay.StoreEvent = append(relay.StoreEvent, RelayDb.SaveEvent)
relay.QueryEvents = append(relay.QueryEvents, RelayDb.QueryEvents)
relay.CountEvents = append(relay.CountEvents, RelayDb.CountEvents)
relay.DeleteEvent = append(relay.DeleteEvent, RelayDb.DeleteEvent)
// apply policies
policies.ApplySaneDefaults(relay)
relay.RejectEvent = append(
relay.RejectEvent,
RejectUnregisteredNpubs,
policies.PreventLargeTags(80),
policies.RejectEventsWithBase64Media,
policies.ValidateKind,
)
relay.RejectFilter = append(
relay.RejectFilter,
policies.RejectKind04Snoopers,
policies.AntiSyncBots,
policies.NoComplexFilters,
policies.NoEmptyFilters,
)
return relay
}
func RejectUnregisteredNpubs(ctx context.Context, event *nostr.Event) (reject bool, msg string) {
l := gologger.Get(config.GetConfig().LogLevel).With().Str("context", "nostr-reject-unregistered").Logger()
// reject nip-04 messages to users who aren't registered
if event.Kind == 4 {
receiver := event.Tags.GetFirst([]string{"p"}).Value()
var uid int
err := DB.QueryRow("SELECT id FROM users WHERE pubkey=$1", receiver).Scan(&uid)
if err != nil {
l.Debug().Msgf("recipient pubkey %s not found: %s", receiver, err.Error())
return true, fmt.Sprintf("recipient pubkey %s is not registered to any users", receiver)
}
return false, ""
}
// check if user is registered
var uid int
err := DB.QueryRow("SELECT id FROM users WHERE pubkey=$1", event.PubKey).Scan(&uid)
if err != nil {
l.Debug().Msgf("poster pubkey %s not found: %s", event.PubKey, err.Error())
return true, fmt.Sprintf("pubkey %s is not registered to any users", event.PubKey)
}
return false, ""
}

View file

@ -1,5 +1,10 @@
export DATABASE_URL="postgres://user:password@127.0.0.1:5432/db?sslmode=disable"
export LISTEN_ADDR=":8090" export LISTEN_ADDR=":8090"
export LOG_LEVEL=0 export LOG_LEVEL=0
export MATRIX_WELL_KNOWN_ADDRESS=matrix.example.com
export MATRIX_MSC3575_ADDRESS=https://matrix.example.com export MATRIX_MSC3575_ADDRESS=https://matrix.example.com
export DATABASE_URL="postgres://user:password@127.0.0.1:5432/db?sslmode=disable" export MATRIX_WELL_KNOWN_ADDRESS=matrix.example.com
export RELAY_CONTACT="matrix:u/asara:devvul.com"
export RELAY_DESCRIPTION="nostr relay running via git.devvul.com/asara/well-goknown"
export RELAY_ICON=""
export RELAY_NAME="Nostr Relay"
export RELAY_PUBKEY=""