Add nostr nip-05 registration with lnd invoices #1
3 changed files with 30 additions and 11 deletions
|
@ -3,7 +3,6 @@ package lnd
|
|||
import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
func Request(request []byte) (string, int, error) {
|
||||
// https://bitcoin.stackexchange.com/questions/73869/rpc-call-to-lnd
|
||||
spew.Dump(request)
|
||||
return "x", 1, nil
|
||||
}
|
||||
|
|
2
main.go
2
main.go
|
@ -14,8 +14,8 @@ func main() {
|
|||
Key: "npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6",
|
||||
Hostname: "devvul.com",
|
||||
}
|
||||
nostr.AddNostrAddr(nostrTest)
|
||||
*/
|
||||
nostr.AddNostrAddr(nostrTest)
|
||||
// matrix endpoints
|
||||
http.HandleFunc("/.well-known/matrix/server", matrix.MatrixServer)
|
||||
http.HandleFunc("/.well-known/matrix/client", matrix.MatrixClient)
|
||||
|
|
|
@ -31,14 +31,28 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
|
|||
http.ServeFile(w, r, "nostr/form.html")
|
||||
case "POST":
|
||||
r.ParseForm()
|
||||
relays := make(map[string][]string)
|
||||
npub := r.FormValue("Key")
|
||||
// convert npub to hex
|
||||
hexKey, err := convertNpubToHex(npub)
|
||||
rKey := getRkey(r.FormValue("Name"), getHostname(r.Host))
|
||||
// check if the user already exists
|
||||
redis, err := redis.New("localhost:6379", "", redis.NostrDb)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
exists := redis.Client.Exists(rKey)
|
||||
if exists.Val() == 1 {
|
||||
w.WriteHeader(http.StatusConflict)
|
||||
return
|
||||
}
|
||||
|
||||
// get the hexkey
|
||||
hexKey, err := convertNpubToHex(r.FormValue("Key"))
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// create the struct
|
||||
relays := make(map[string][]string)
|
||||
names := map[string]string{r.FormValue("Name"): hexKey}
|
||||
user := nostrWellKnown{}
|
||||
if r.FormValue("Relays") != "" {
|
||||
|
@ -50,6 +64,8 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
|
|||
user = nostrWellKnown{Names: names}
|
||||
}
|
||||
jsonUser, _ := json.Marshal(user)
|
||||
|
||||
// generate the payment request
|
||||
paymentReq, exp, err := lnd.Request(jsonUser)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
|
@ -74,7 +90,7 @@ func GetNostrAddr(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
requestedName := r.FormValue("name")
|
||||
// search for user@domain
|
||||
search := fmt.Sprintf("%s@%s", requestedName, getHostname(r.Host))
|
||||
search := getRkey(requestedName, getHostname(r.Host))
|
||||
addr, err := redis.Client.Get(search).Result()
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
|
@ -108,7 +124,7 @@ func AddNostrAddr(n NostrRequest) {
|
|||
if err != nil {
|
||||
fmt.Println("FAILED")
|
||||
}
|
||||
nameKey := fmt.Sprintf("%s@%s", n.Name, n.Hostname)
|
||||
nameKey := getRkey(n.Name, n.Hostname)
|
||||
err = r.Client.Set(nameKey, jsonUser, redis.NostrDb).Err()
|
||||
if err != nil {
|
||||
fmt.Println("FAILED")
|
||||
|
@ -117,9 +133,6 @@ func AddNostrAddr(n NostrRequest) {
|
|||
|
||||
func getHostname(hostname string) string {
|
||||
// remove port for local testing
|
||||
if strings.Contains(hostname, ":") {
|
||||
hostname = strings.Split(hostname, ":")[0]
|
||||
}
|
||||
return hostname
|
||||
}
|
||||
|
||||
|
@ -135,3 +148,10 @@ func convertNpubToHex(npub string) (string, error) {
|
|||
return hex.(string), nil
|
||||
|
||||
}
|
||||
|
||||
func getRkey(user string, hostname string) string {
|
||||
if strings.Contains(hostname, ":") {
|
||||
hostname = strings.Split(hostname, ":")[0]
|
||||
}
|
||||
return fmt.Sprintf("%s@%s", user, hostname)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue