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
2 changed files with 53 additions and 4 deletions
Showing only changes of commit c7257e6885 - Show all commits

View file

@ -17,7 +17,8 @@ func main() {
nostr.AddNostrAddr(nostrTest)
*/
// matrix endpoints
http.HandleFunc("/.well-known/matrix/server", matrix.Matrix)
http.HandleFunc("/.well-known/matrix/server", matrix.MatrixServer)
http.HandleFunc("/.well-known/matrix/client", matrix.MatrixClient)
// nostr endpoints
http.HandleFunc("/.well-known/nostr.json", nostr.GetNostrAddr)

View file

@ -2,15 +2,16 @@ package matrix
import (
"encoding/json"
"fmt"
"net/http"
"os"
)
type matrixWellKnown struct {
type matrixServerWellKnown struct {
WellKnownAddress string `json:"m.server"`
}
func Matrix(w http.ResponseWriter, req *http.Request) {
func MatrixServer(w http.ResponseWriter, req *http.Request) {
// uses an environment variable for now
wellKnownAddr, ok := os.LookupEnv("MATRIX_WELL_KNOWN_ADDRESS")
if !ok {
@ -20,8 +21,55 @@ func Matrix(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
wellKnown := &matrixWellKnown{
wellKnown := &matrixServerWellKnown{
WellKnownAddress: wellKnownAddr,
}
json.NewEncoder(w).Encode(wellKnown)
}
type matrixBaseUrl struct {
BaseUrl string `json:"base_url"`
}
type matrixIdentityServer struct {
BaseUrl string `json:"base_url,omitempty"`
}
type matrixClientWellKnown struct {
HomeServer *matrixBaseUrl `json:"m.homeserver"`
IdentityServer *matrixIdentityServer `json:"m.identity_server,omitempty"`
}
func MatrixClient(w http.ResponseWriter, req *http.Request) {
// uses an environment variable for now
wellKnownAddr, ok := os.LookupEnv("MATRIX_WELL_KNOWN_ADDRESS")
if !ok {
w.WriteHeader(http.StatusNotFound)
return
}
identityServer, ok := os.LookupEnv("MATRIX_IDENTITY_SERVER")
if !ok {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
baseUrl := &matrixClientWellKnown{
HomeServer: &matrixBaseUrl{
BaseUrl: fmt.Sprintf("https://%s", wellKnownAddr),
},
}
json.NewEncoder(w).Encode(baseUrl)
} else {
identityServer = fmt.Sprintf("https://%s", identityServer)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
baseUrl := &matrixClientWellKnown{
HomeServer: &matrixBaseUrl{
BaseUrl: fmt.Sprintf("https://%s", wellKnownAddr),
},
IdentityServer: &matrixIdentityServer{
BaseUrl: identityServer,
},
}
json.NewEncoder(w).Encode(baseUrl)
}
}