Compare commits

..

No commits in common. "25440558e9b0799ff3291d5565ce2f6439cbed8b" and "5c35f2daac3a400c71e26faec2bd0be4451cd417" have entirely different histories.

3 changed files with 22 additions and 31 deletions

13
main.go
View file

@ -7,21 +7,9 @@ import (
"git.minhas.io/asara/well-goknown/logger" "git.minhas.io/asara/well-goknown/logger"
"git.minhas.io/asara/well-goknown/matrix" "git.minhas.io/asara/well-goknown/matrix"
"git.minhas.io/asara/well-goknown/nostr" "git.minhas.io/asara/well-goknown/nostr"
"git.minhas.io/asara/well-goknown/redis"
) )
func main() { func main() {
var err error
l := logger.Get()
// connect to redis
redis.NostrRedisConn, err = redis.New("localhost:6379", "", redis.NostrKeyspace)
if err != nil {
l.Fatal().Msg("unable to connect to redis")
}
redis.LndRedisConn, err = redis.New("localhost:6379", "", redis.LndKeyspace)
if err != nil {
l.Fatal().Msg("unable to connect to redis")
}
/* /*
nostrTest := nostr.NostrRequest{ nostrTest := nostr.NostrRequest{
Name: "asara", Name: "asara",
@ -31,6 +19,7 @@ func main() {
nostr.AddNostrAddr(nostrTest) nostr.AddNostrAddr(nostrTest)
*/ */
// matrix endpoints // matrix endpoints
l := logger.Get()
l.Debug().Msg("enabling matrix server endpoint") l.Debug().Msg("enabling matrix server endpoint")
http.HandleFunc("/.well-known/matrix/server", matrix.MatrixServer) http.HandleFunc("/.well-known/matrix/server", matrix.MatrixServer)
l.Debug().Msg("enabling matrix client endpoint") l.Debug().Msg("enabling matrix client endpoint")

View file

@ -37,7 +37,12 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "html/nostr_form.html") http.ServeFile(w, r, "html/nostr_form.html")
case "POST": case "POST":
r.ParseForm() r.ParseForm()
redisCli := redis.NostrRedisConn redisCli, err := redis.New("localhost:6379", "", redis.NostrDb)
if err != nil {
l.Error().Msg("unable to connect to redis")
w.WriteHeader(http.StatusInternalServerError)
return
}
// check if the user already exists // check if the user already exists
rKey := getRkey("verified", r.FormValue("Name"), getHostname(r.Host)) rKey := getRkey("verified", r.FormValue("Name"), getHostname(r.Host))
exists := redisCli.Client.Exists(ctx, rKey) exists := redisCli.Client.Exists(ctx, rKey)
@ -45,12 +50,6 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusConflict) w.WriteHeader(http.StatusConflict)
return return
} }
rKey = getRkey("requested", r.FormValue("Name"), getHostname(r.Host))
exists = redisCli.Client.Exists(ctx, rKey)
if exists.Val() == 1 {
w.WriteHeader(http.StatusConflict)
return
}
// get the hexkey // get the hexkey
hexKey, err := convertNpubToHex(r.FormValue("Key")) hexKey, err := convertNpubToHex(r.FormValue("Key"))
@ -77,8 +76,7 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
// generate the payment request // generate the payment request
exp := time.Until(time.Now().Add(time.Minute * 15)) exp := time.Until(time.Now().Add(time.Minute * 15))
// paymentReq, err := lnd.Request(rKey, jsonUser, exp) paymentReq, err := lnd.Request(rKey, jsonUser, exp)
_, err = lnd.Request(rKey, jsonUser, exp)
if err != nil { if err != nil {
w.WriteHeader(http.StatusServiceUnavailable) w.WriteHeader(http.StatusServiceUnavailable)
return return
@ -93,13 +91,19 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
func GetNostrAddr(w http.ResponseWriter, r *http.Request) { func GetNostrAddr(w http.ResponseWriter, r *http.Request) {
ctx := context.TODO() ctx := context.TODO()
l := logger.Get()
// get query string for username // get query string for username
r.ParseForm() r.ParseForm()
requestedName := r.FormValue("name")
// connect to redis // connect to redis
redisCli := redis.NostrRedisConn redisCli, err := redis.New("localhost:6379", "", redis.NostrDb)
if err != nil {
l.Error().Msg("unable to connect to redis")
w.WriteHeader(http.StatusInternalServerError)
return
}
requestedName := r.FormValue("name")
// search for user@domain // search for user@domain
search := getRkey("verified", requestedName, getHostname(r.Host)) search := getRkey("verified", requestedName, getHostname(r.Host))
addr, err := redisCli.Client.Get(ctx, search).Result() addr, err := redisCli.Client.Get(ctx, search).Result()
@ -138,7 +142,10 @@ func AddNostrAddr(n NostrRequest) {
} }
jsonUser, _ := json.Marshal(user) jsonUser, _ := json.Marshal(user)
redisCli := redis.NostrRedisConn redisCli, err := redis.New("localhost:6379", "", redis.NostrDb)
if err != nil {
l.Error().Msg("unable to connect to redis")
}
nameKey := getRkey("verified", n.Name, n.Hostname) nameKey := getRkey("verified", n.Name, n.Hostname)
enc := b64.StdEncoding.EncodeToString([]byte(jsonUser)) enc := b64.StdEncoding.EncodeToString([]byte(jsonUser))
err = redisCli.Client.Set(ctx, nameKey, enc, 0).Err() err = redisCli.Client.Set(ctx, nameKey, enc, 0).Err()

View file

@ -7,19 +7,14 @@ import (
) )
const ( const (
NostrKeyspace = iota NostrDb = iota
LndKeyspace = iota LndDb = iota
) )
type Redis struct { type Redis struct {
Client *redis.Client Client *redis.Client
} }
var (
NostrRedisConn *Redis
LndRedisConn *Redis
)
func New(address string, password string, database int) (*Redis, error) { func New(address string, password string, database int) (*Redis, error) {
client := redis.NewClient(&redis.Options{ client := redis.NewClient(&redis.Options{
Addr: address, Addr: address,