Add nostr nip-05 registration with lnd invoices #1

Merged
Asara merged 33 commits from nostr_lnd into main 2023-05-30 00:10:37 +00:00
Showing only changes of commit f6144f470d - Show all commits

View file

@ -37,16 +37,16 @@ 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 := redis.NostrRedisConn.Client
// 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.Exists(ctx, rKey)
if exists.Val() == 1 { if exists.Val() == 1 {
w.WriteHeader(http.StatusConflict) w.WriteHeader(http.StatusConflict)
return return
} }
rKey = getRkey("requested", r.FormValue("Name"), getHostname(r.Host)) rKey = getRkey("requested", r.FormValue("Name"), getHostname(r.Host))
exists = redisCli.Client.Exists(ctx, rKey) exists = redisCli.Exists(ctx, rKey)
if exists.Val() == 1 { if exists.Val() == 1 {
w.WriteHeader(http.StatusConflict) w.WriteHeader(http.StatusConflict)
return return
@ -84,7 +84,7 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
return return
} }
requestKey := getRkey("requested", r.FormValue("Name"), getHostname(r.Host)) requestKey := getRkey("requested", r.FormValue("Name"), getHostname(r.Host))
err = redisCli.Client.Set(ctx, requestKey, enc, exp).Err() err = redisCli.Set(ctx, requestKey, enc, exp).Err()
if err != nil { if err != nil {
l.Error().Msg("unable to connect to redis") l.Error().Msg("unable to connect to redis")
} }
@ -98,11 +98,11 @@ func GetNostrAddr(w http.ResponseWriter, r *http.Request) {
requestedName := r.FormValue("name") requestedName := r.FormValue("name")
// connect to redis // connect to redis
redisCli := redis.NostrRedisConn redisCli := redis.NostrRedisConn.Client
// 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.Get(ctx, search).Result()
if err != nil { if err != nil {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
return return
@ -138,10 +138,10 @@ func AddNostrAddr(n NostrRequest) {
} }
jsonUser, _ := json.Marshal(user) jsonUser, _ := json.Marshal(user)
redisCli := redis.NostrRedisConn redisCli := redis.NostrRedisConn.Client
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.Set(ctx, nameKey, enc, 0).Err()
if err != nil { if err != nil {
l.Error().Msg("unable to connect to redis") l.Error().Msg("unable to connect to redis")
} }