Add nostr nip-05 registration with lnd invoices #1
2 changed files with 53 additions and 4 deletions
3
main.go
3
main.go
|
@ -17,7 +17,8 @@ func main() {
|
||||||
nostr.AddNostrAddr(nostrTest)
|
nostr.AddNostrAddr(nostrTest)
|
||||||
*/
|
*/
|
||||||
// matrix endpoints
|
// 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
|
// nostr endpoints
|
||||||
http.HandleFunc("/.well-known/nostr.json", nostr.GetNostrAddr)
|
http.HandleFunc("/.well-known/nostr.json", nostr.GetNostrAddr)
|
||||||
|
|
|
@ -2,15 +2,16 @@ package matrix
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type matrixWellKnown struct {
|
type matrixServerWellKnown struct {
|
||||||
WellKnownAddress string `json:"m.server"`
|
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
|
// uses an environment variable for now
|
||||||
wellKnownAddr, ok := os.LookupEnv("MATRIX_WELL_KNOWN_ADDRESS")
|
wellKnownAddr, ok := os.LookupEnv("MATRIX_WELL_KNOWN_ADDRESS")
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -20,8 +21,55 @@ func Matrix(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
wellKnown := &matrixWellKnown{
|
wellKnown := &matrixServerWellKnown{
|
||||||
WellKnownAddress: wellKnownAddr,
|
WellKnownAddress: wellKnownAddr,
|
||||||
}
|
}
|
||||||
json.NewEncoder(w).Encode(wellKnown)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue