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
6 changed files with 74 additions and 21 deletions
Showing only changes of commit 2b7a06a0f4 - Show all commits

5
go.mod
View file

@ -2,7 +2,10 @@ module git.minhas.io/asara/well-goknown
go 1.19 go 1.19
require github.com/go-redis/redis v6.15.9+incompatible require (
github.com/davecgh/go-spew v1.1.1
github.com/go-redis/redis v6.15.9+incompatible
)
require ( require (
github.com/onsi/ginkgo v1.16.5 // indirect github.com/onsi/ginkgo v1.16.5 // indirect

1
go.sum
View file

@ -1,4 +1,5 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=

8
lnd/lnd.go Normal file
View file

@ -0,0 +1,8 @@
package lnd
import "fmt"
func main() {
// https://bitcoin.stackexchange.com/questions/73869/rpc-call-to-lnd
fmt.Println("vim-go")
}

14
main.go
View file

@ -8,7 +8,21 @@ import (
) )
func main() { func main() {
/*
nostrTest := nostr.NostrRequest{
Name: "asara",
Key: "abcdefg",
Hostname: "devvul.com",
}
nostr.AddNostrAddr(nostrTest)
*/
// matrix endpoints
http.HandleFunc("/.well-known/matrix/server", matrix.Matrix) http.HandleFunc("/.well-known/matrix/server", matrix.Matrix)
// nostr endpoints
http.HandleFunc("/.well-known/nostr.json", nostr.GetNostrAddr) http.HandleFunc("/.well-known/nostr.json", nostr.GetNostrAddr)
http.HandleFunc("/request/nostr", nostr.RequestNostrAddr)
// start server
http.ListenAndServe(":8090", nil) http.ListenAndServe(":8090", nil)
} }

View file

@ -1,11 +1,12 @@
package nostr package nostr
import ( import (
"encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"strings" "strings"
"github.com/go-redis/redis" "git.minhas.io/asara/well-goknown/redis"
) )
type nostrWellKnown struct { type nostrWellKnown struct {
@ -17,46 +18,51 @@ type NostrRequest struct {
Name string `json:"name"` Name string `json:"name"`
Key string `json:"key"` Key string `json:"key"`
Hostname string Hostname string
Relays []string `json:"relays"` Relays []string `json:"relays,omitempty"`
} }
/*
func AddNostrAddr(n NostrRequest) { func AddNostrAddr(n NostrRequest) {
// transform request to well known struct // transform request to well known struct
relays := make(map[string][]string)
user := nostrWellKnown{}
names := map[string]string{n.Name: n.Key} names := map[string]string{n.Name: n.Key}
relays := map[string][]string{n.Key: n.Relays} if n.Relays != nil {
user := nostrWellKnown{Names: names, Relays: relays} relays = map[string][]string{n.Key: n.Relays}
user = nostrWellKnown{Names: names, Relays: relays}
} else {
user = nostrWellKnown{Names: names}
}
jsonUser, _ := json.Marshal(user) jsonUser, _ := json.Marshal(user)
client := redis.NewClient(&redis.Options{ r, err := redis.New("localhost:6379", "", 0)
Addr: "localhost:6379", if err != nil {
Password: "", fmt.Println("FAILED")
DB: 0, }
})
nameKey := fmt.Sprintf("%s@%s", n.Name, n.Hostname) nameKey := fmt.Sprintf("%s@%s", n.Name, n.Hostname)
err := client.Set(nameKey, jsonUser, 0).Err() err = r.Client.Set(nameKey, jsonUser, 0).Err()
if err != nil { if err != nil {
fmt.Println("FAILED") fmt.Println("FAILED")
} }
} }
*/
func RequestNostrAddr(w http.ResponseWriter, req *http.Request) {
}
func GetNostrAddr(w http.ResponseWriter, req *http.Request) { func GetNostrAddr(w http.ResponseWriter, req *http.Request) {
// get query string for username // get query string for username
req.ParseForm() req.ParseForm()
// connect to redis // connect to redis
client := redis.NewClient(&redis.Options{ r, err := redis.New("localhost:6379", "", 0)
Addr: "localhost:6379", if err != nil {
Password: "", w.WriteHeader(http.StatusNotFound)
DB: 0, return
}) }
requestedName := req.FormValue("name") requestedName := req.FormValue("name")
hostname := getHostname(req.Host)
// search for user@domain // search for user@domain
search := fmt.Sprintf("%s@%s", requestedName, hostname) search := fmt.Sprintf("%s@%s", requestedName, getHostname(req.Host))
addr, err := client.Get(search).Result() addr, err := r.Client.Get(search).Result()
if err != nil { if err != nil {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
return return

21
redis/redis.go Normal file
View file

@ -0,0 +1,21 @@
package redis
import "github.com/go-redis/redis"
type Redis struct {
Client *redis.Client
}
func New(address string, password string, database int) (*Redis, error) {
client := redis.NewClient(&redis.Options{
Addr: address,
Password: password,
DB: database,
})
if err := client.Ping().Err(); err != nil {
return nil, err
}
return &Redis{
Client: client,
}, nil
}