Compare commits
No commits in common. "bfee9ce183928b741358ae51b39609e3de1b6e99" and "f6144f470df3761654abe821d5f55a69f0fdaaae" have entirely different histories.
bfee9ce183
...
f6144f470d
2 changed files with 4 additions and 30 deletions
|
@ -7,9 +7,6 @@ import (
|
||||||
type (
|
type (
|
||||||
Config struct {
|
Config struct {
|
||||||
ListenAddr string
|
ListenAddr string
|
||||||
LndCertB64 string
|
|
||||||
LndAddr string
|
|
||||||
LndMacaroonHex string
|
|
||||||
LogLevel string
|
LogLevel string
|
||||||
MatrixIdentityServer string
|
MatrixIdentityServer string
|
||||||
MatrixWellKnownAddress string
|
MatrixWellKnownAddress string
|
||||||
|
@ -20,9 +17,6 @@ type (
|
||||||
func GetConfig() Config {
|
func GetConfig() Config {
|
||||||
return Config{
|
return Config{
|
||||||
ListenAddr: getEnv("LISTEN_ADDR", ":8090"),
|
ListenAddr: getEnv("LISTEN_ADDR", ":8090"),
|
||||||
LndCertB64: getEnv("LND_CERT_B64", ""),
|
|
||||||
LndAddr: getEnv("LND_ADDR", ""),
|
|
||||||
LndMacaroonHex: getEnv("LND_MACAROON_HEX", ""),
|
|
||||||
LogLevel: getEnv("LOG_LEVEL", "INFO"),
|
LogLevel: getEnv("LOG_LEVEL", "INFO"),
|
||||||
MatrixIdentityServer: getEnv("MATRIX_IDENTITY_SERVER", ""),
|
MatrixIdentityServer: getEnv("MATRIX_IDENTITY_SERVER", ""),
|
||||||
MatrixWellKnownAddress: getEnv("MATRIX_WELL_KNOWN_ADDRESS", ""),
|
MatrixWellKnownAddress: getEnv("MATRIX_WELL_KNOWN_ADDRESS", ""),
|
||||||
|
|
|
@ -21,10 +21,6 @@ type nostrWellKnown struct {
|
||||||
Relays map[string][]string `json:"relays,omitempty"`
|
Relays map[string][]string `json:"relays,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type jsonErrorMessage struct {
|
|
||||||
Error string `json:"error"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type NostrRequest struct {
|
type NostrRequest struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
|
@ -37,6 +33,7 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
|
||||||
l := logger.Get()
|
l := logger.Get()
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case "GET":
|
case "GET":
|
||||||
|
l.Debug().Msg("get nostr register form")
|
||||||
http.ServeFile(w, r, "html/nostr_form.html")
|
http.ServeFile(w, r, "html/nostr_form.html")
|
||||||
case "POST":
|
case "POST":
|
||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
|
@ -46,28 +43,20 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
|
||||||
exists := redisCli.Exists(ctx, rKey)
|
exists := redisCli.Exists(ctx, rKey)
|
||||||
if exists.Val() == 1 {
|
if exists.Val() == 1 {
|
||||||
w.WriteHeader(http.StatusConflict)
|
w.WriteHeader(http.StatusConflict)
|
||||||
json.NewEncoder(w).Encode(&jsonErrorMessage{
|
|
||||||
Error: "username already registered",
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rKey = getRkey("requested", r.FormValue("Name"), getHostname(r.Host))
|
rKey = getRkey("requested", r.FormValue("Name"), getHostname(r.Host))
|
||||||
exists = redisCli.Exists(ctx, rKey)
|
exists = redisCli.Exists(ctx, rKey)
|
||||||
if exists.Val() == 1 {
|
if exists.Val() == 1 {
|
||||||
w.WriteHeader(http.StatusConflict)
|
w.WriteHeader(http.StatusConflict)
|
||||||
json.NewEncoder(w).Encode(&jsonErrorMessage{
|
|
||||||
Error: "username already requested, try again in a few minutes",
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the hexkey
|
// get the hexkey
|
||||||
hexKey, err := convertNpubToHex(r.FormValue("Key"))
|
hexKey, err := convertNpubToHex(r.FormValue("Key"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
l.Error().Msg("unable to convert npub to hex")
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
json.NewEncoder(w).Encode(&jsonErrorMessage{
|
|
||||||
Error: err.Error(),
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,9 +81,6 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
|
||||||
_, 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)
|
||||||
json.NewEncoder(w).Encode(&jsonErrorMessage{
|
|
||||||
Error: "service unavailable",
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
requestKey := getRkey("requested", r.FormValue("Name"), getHostname(r.Host))
|
requestKey := getRkey("requested", r.FormValue("Name"), getHostname(r.Host))
|
||||||
|
@ -119,17 +105,11 @@ func GetNostrAddr(w http.ResponseWriter, r *http.Request) {
|
||||||
addr, err := redisCli.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)
|
||||||
json.NewEncoder(w).Encode(&jsonErrorMessage{
|
|
||||||
Error: "username not registered",
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dec, err := b64.StdEncoding.DecodeString(addr)
|
dec, err := b64.StdEncoding.DecodeString(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
json.NewEncoder(w).Encode(&jsonErrorMessage{
|
|
||||||
Error: "internal server error",
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,11 +154,11 @@ func getHostname(hostname string) string {
|
||||||
|
|
||||||
func convertNpubToHex(npub string) (string, error) {
|
func convertNpubToHex(npub string) (string, error) {
|
||||||
if !strings.HasPrefix(npub, "npub1") {
|
if !strings.HasPrefix(npub, "npub1") {
|
||||||
return "", errors.New("key does not start with npub1 prefix")
|
return "", errors.New("Not an npub key")
|
||||||
}
|
}
|
||||||
_, hex, err := nip19.Decode(npub)
|
_, hex, err := nip19.Decode(npub)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.New("unable to decode npub key")
|
return "", errors.New("Unable to decode npub")
|
||||||
}
|
}
|
||||||
|
|
||||||
return hex.(string), nil
|
return hex.(string), nil
|
||||||
|
|
Loading…
Reference in a new issue