diff --git a/README.md b/README.md index fbbafea..3fc0738 100644 --- a/README.md +++ b/README.md @@ -36,13 +36,15 @@ put the details of your desired setup with the parameters you use to launch name #!/usr/bin/bash - /home//.local/bin/namestr -vc mleku.online npub1mlekuhhxqq6p8w9x5fs469cjk3fu9zw7uptujr55zmpuhhj48u3qnwx3q5 a.nos.lol bevo.nostr1.com bitcoiner.social nos.lol nostr.wine relay.nostr.band Bevo.nostr1.com ae.purplerelay.com nostr.plebchain.org christpill.nostr1.com relay.nostr.me relay.devstr.org relay.primal.net + /home//.local/bin/namestr -vc mleku.online npub1mlekuhhxqq6p8w9x5fs469cjk3fu9zw7uptujr55zmpuhhj48u3qnwx3q5 github.com/mleku a.nos.lol bevo.nostr1.com bitcoiner.social nos.lol nostr.wine relay.nostr.band Bevo.nostr1.com ae.purplerelay.com nostr.plebchain.org christpill.nostr1.com relay.nostr.me relay.devstr.org relay.primal.net The `-vc` enables logging, which prints the URL requests that came in. it only sends a proper answer to the NIP-05 request path, all others return the text "gfy". (hah, if you want to change it, just edit the file `cmd/root.go` and look for "gfy" and change it) after that is the domain name. this is intended for a domain name that is your nostr display name, mleku.online in my case. -after that, you put the npub. this is automatically decoded to hex for the json response. +then you put the npub. this is automatically decoded to hex for the json response. + +third element is a URL that you want to be given as a redirect, such as your github profile or other social network profile. after that, zero or more of just the domain names of the relays that you usually use to post with. the `wss://` prefix is not needed. diff --git a/cmd/root.go b/cmd/root.go index 610a344..ce68fcf 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -13,9 +13,11 @@ import ( ) type config struct { - c *cobra.Command - DataDir, message string - verbose, color bool + c *cobra.Command + DataDir, message string + domain, npub, redirection string + relays []string + verbose, color bool } var s config @@ -23,7 +25,7 @@ var DataDirPerm os.FileMode = 0700 // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ - Use: "namestr [...]", + Use: "namestr [...]", Short: "zero configuration NIP-05 DNS<->npub identity verification", Long: `namestr @@ -47,12 +49,12 @@ optionally a list of relays can be named, only their domain name is required, th s.c.Help() s.Fatal("at least domain name and npub is required\n") } - domain, npub, relays := args[0], args[1], args[2:] - s.Log("domain %v\n", domain) - s.Log("npub %v\n", npub) - s.Log("relays %v\n", relays) + s.domain, s.npub, s.redirection, s.relays = args[0], args[1], args[2], args[3:] + s.Log("domain %v\n", s.domain) + s.Log("npub %v\n", s.npub) + s.Log("relays %v\n", s.relays) - pk, err := nostr.NpubToPublicKey(npub) + pk, err := nostr.NpubToPublicKey(s.npub) if err != nil { s.Fatal("%s\n", err) } @@ -68,8 +70,8 @@ optionally a list of relays can be named, only their domain name is required, th "relays": { "` + pkHex + `": [ ` - rl := len(relays) - 1 - for i, rel := range relays { + rl := len(s.relays) - 1 + for i, rel := range s.relays { if i < rl { jsonText += ` ` + `"wss://` + rel + `", @@ -103,7 +105,7 @@ optionally a list of relays can be named, only their domain name is required, th } } s.Log("starting up server\n") - autotls.Run(s, domain) + autotls.Run(s, s.domain) s.Log("finished running server\n") }, } @@ -121,11 +123,11 @@ func CheckFileExists(name string) (fi os.FileInfo, exists bool, err error) { func (s config) ServeHTTP(w http.ResponseWriter, r *http.Request) { s.Log("%s\n", r.RequestURI) - w.WriteHeader(http.StatusOK) if r.RequestURI == "/.well-known/nostr.json?name=_" { + w.WriteHeader(http.StatusOK) w.Write([]byte(s.message)) } else { - w.Write([]byte("gfy")) + http.Redirect(w, r, s.redirection, http.StatusSeeOther) } }