diff --git a/Makefile b/Makefile index ef18238..ac31083 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,6 @@ satdress: $(shell find . -name "*.go") CC=$$(which musl-gcc) go build -ldflags='-s -w -linkmode external -extldflags "-static"' -o ./satdress deploy: satdress - ssh root@hulsmann 'systemctl stop bitmia' + ssh root@hulsmann 'systemctl stop bitmia tinytip payaddress paymentlink' scp satdress hulsmann:satdress/satdress - ssh root@hulsmann 'systemctl start bitmia' + ssh root@hulsmann 'systemctl start bitmia tinytip payaddress paymentlink' diff --git a/README.md b/README.md index 03cc3a0..fa97ed6 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,23 @@ Federated Lightning Address Server -## Instructions +## How to run + +1. Download the binary from the releases page (or compile with `go build` or `go get`) +2. Set the following environment variables somehow (using example values from bitmia.com): + +``` +PORT=17422 +DOMAIN=bitmia.com +SECRET=askdbasjdhvakjvsdjasd +SITE_OWNER_URL=https://t.me/qecez +SITE_OWNER_NAME=@qecez +SITE_NAME=Bitmia +``` + +3. Start the app with `./satdress` +4. Serve the app to the world on your domain using whatever technique you're used to + +## Get help + +Maybe ask for help on https://t.me/lnurl if you're in trouble. diff --git a/db.go b/db.go new file mode 100644 index 0000000..adeb803 --- /dev/null +++ b/db.go @@ -0,0 +1,10 @@ +package main + +type Params struct { + Name string + Kind string + Host string + Key string + Pak string + Waki string +} diff --git a/go.mod b/go.mod index 44a42f3..db60f88 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.16 require ( github.com/cockroachdb/pebble v0.0.0-20210812144839-61318a019370 github.com/fiatjaf/go-lnurl v1.4.0 - github.com/fiatjaf/makeinvoice v1.1.0 + github.com/fiatjaf/makeinvoice v1.2.0 github.com/gorilla/mux v1.8.0 github.com/kelseyhightower/envconfig v1.4.0 github.com/lib/pq v1.10.2 diff --git a/go.sum b/go.sum index cafcf04..90d6ac1 100644 --- a/go.sum +++ b/go.sum @@ -119,8 +119,8 @@ github.com/fiatjaf/lightningd-gjson-rpc v1.4.0 h1:Iv5tt4YuNoSMfR39wiV0tqnHYTJ85o github.com/fiatjaf/lightningd-gjson-rpc v1.4.0/go.mod h1:SQGA0qcY2qypaMXDQlE5V5+2MnLZzQ7NzfRsScliFeE= github.com/fiatjaf/ln-decodepay v1.0.0 h1:1YUMjvLock+BicMNwoZ/OA3oG2ZYEaJ8AzdS6EGVMTQ= github.com/fiatjaf/ln-decodepay v1.0.0/go.mod h1:/LWK+ZUa3i8MqbRjIMAiVQS2+NbhwKWlwib2n446cMQ= -github.com/fiatjaf/makeinvoice v1.0.1 h1:tPGEBeAVU6hZWDf/nQRAMyDELWVRUJWbzJ4WiRh9Kpg= -github.com/fiatjaf/makeinvoice v1.0.1/go.mod h1:3BkUQoA+VZeR4qQbK3qN+KQrh96z5dMNBMuKfdxSBE0= +github.com/fiatjaf/makeinvoice v1.2.0 h1:lWvjFyMq3R9yzln/I67Ex2/c0cBUiuWS4WEc32AWuNc= +github.com/fiatjaf/makeinvoice v1.2.0/go.mod h1:R+p/0XfRNob2hu+nyIiC2xaSy/HcdQ21rbNNuUHRB70= github.com/flosch/pongo2 v0.0.0-20190707114632-bbf5a6c351f4/go.mod h1:T9YF2M40nIgbVgp3rreNmTged+9HrbNTIQf1PsaIiTA= github.com/frankban/quicktest v1.2.2/go.mod h1:Qh/WofXFeiAFII1aEBu529AtJo6Zg2VHscnEsbBnJ20= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= @@ -191,6 +191,8 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/hydrogen18/memlistener v0.0.0-20141126152155-54553eb933fb/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE= github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA= +github.com/imroc/req v0.3.0 h1:3EioagmlSG+z+KySToa+Ylo3pTFZs+jh3Brl7ngU12U= +github.com/imroc/req v0.3.0/go.mod h1:F+NZ+2EFSo6EFXdeIbpfE9hcC233id70kf0byW97Caw= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/iris-contrib/blackfriday v2.0.0+incompatible/go.mod h1:UzZ2bDEoaSGPbkg6SAB4att1aAwTmVIx/5gCVqeyUdI= github.com/iris-contrib/go.uuid v2.0.0+incompatible/go.mod h1:iz2lgM/1UnEf1kP0L/+fafWORmlnuysV2EMP8MW+qe0= @@ -259,6 +261,8 @@ github.com/lightningnetwork/lnd/queue v1.0.3 h1:5ufYVE7lh9GJnL1wOoeO3bZ3aAHWNnkN github.com/lightningnetwork/lnd/queue v1.0.3/go.mod h1:YTkTVZCxz8tAYreH27EO3s8572ODumWrNdYW2E/YKxg= github.com/lightningnetwork/lnd/ticker v1.0.0 h1:S1b60TEGoTtCe2A0yeB+ecoj/kkS4qpwh6l+AkQEZwU= github.com/lightningnetwork/lnd/ticker v1.0.0/go.mod h1:iaLXJiVgI1sPANIF2qYYUJXjoksPNvGNYowB8aRbpX0= +github.com/lnpay/lnpay-go v1.1.0 h1:8nj5Nk42MNWE0PjeUnvBWqK9HP22khNOULljbD+N78g= +github.com/lnpay/lnpay-go v1.1.0/go.mod h1:9R+L95XntdDXkU59ZzAozn7K/1nKsRfnuzu8QsSSzM8= github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796 h1:sjOGyegMIhvgfq5oaue6Td+hxZuf3tDC8lAPrFldqFw= github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796/go.mod h1:3p7ZTf9V1sNPI5H8P3NkTFF4LuwMdPl2DodF60qAKqY= github.com/ltcsuite/ltcutil v0.0.0-20181217130922-17f3b04680b6/go.mod h1:8Vg/LTOO0KYa/vlHWJ6XZAevPQThGH5sufO0Hrou/lA= diff --git a/index.html b/index.html index b94b644..bb0bd3f 100644 --- a/index.html +++ b/index.html @@ -38,6 +38,10 @@ .title { font-size: 40px; +<<<<<<< HEAD +======= + text-align: center; +>>>>>>> f98da7d981ce9e530596c805dfe5b00f2ed1f7eb font-weight: 700; letter-spacing: 1px; } @@ -114,6 +118,20 @@ background-color: #f3f3f3; } +<<<<<<< HEAD +======= + .suffix { + height: 35px; + display: inline-flex; + padding: 0 10px; + font-size: 14px; + align-items: center; + border-radius: 5px; + margin-bottom: 25px; + letter-spacing: 0.5px; + } + +>>>>>>> f98da7d981ce9e530596c805dfe5b00f2ed1f7eb select { height: 35px; outline: none; @@ -153,51 +171,99 @@ } -
Satdress
-
Federated Lightning Address Server
-
-
Use the form below to connect your own node to a Lightning Address.
You can also self-host this server.
-
- - - - - -
-
-
- - Lightning Address Documentation - - - GitHub (MIT Licensed) - -
+
+
Satdress
+
Federated Lightning Address Server
+
+
Use the form below to connect your own node to a Lightning Address.
+
+ + +
+ + +
+
+ + +
+
+ + +
+ +
+
+
+ + Lightning Address Documentation + + Brought to you by {{ siteOwnerName }} + You can host this server on your domain +
+
+ + - - diff --git a/main.go b/main.go index 099dc34..23f0b41 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "fmt" "net/http" "os" + "strings" "time" "github.com/cockroachdb/pebble" @@ -19,11 +20,13 @@ import ( ) type Settings struct { - Host string `envconfig:"HOST" default:"0.0.0.0"` - Port string `envconfig:"PORT" required:"true"` - Domain string `envconfig:"DOMAIN" required:"true"` - Secret string `envconfig:"SECRET" required:"true"` - SiteOwner string `envconfig:"SITE_OWNER" required:"true"` + Host string `envconfig:"HOST" default:"0.0.0.0"` + Port string `envconfig:"PORT" required:"true"` + Domain string `envconfig:"DOMAIN" required:"true"` + Secret string `envconfig:"SECRET" required:"true"` + SiteOwnerName string `envconfig:"SITE_OWNER_NAME" required:"true"` + SiteOwnerURL string `envconfig:"SITE_OWNER_URL" required:"true"` + SiteName string `envconfig:"SITE_NAME" required:"true"` } var s Settings @@ -51,7 +54,25 @@ func main() { router.Path("/").HandlerFunc( func(w http.ResponseWriter, r *http.Request) { w.Header().Set("content-type", "text/html") - fmt.Fprintf(w, html+"

offered by %s

", s.SiteOwner) + serverData, _ := json.Marshal(struct { + Domain string `json:"domain"` + SiteOwnerName string `json:"siteOwnerName"` + SiteOwnerURL string `json:"siteOwnerURL"` + SiteName string `json:"siteName"` + }{ + Domain: s.Domain, + SiteOwnerName: s.SiteOwnerName, + SiteOwnerURL: s.SiteOwnerURL, + SiteName: s.SiteName, + }) + fmt.Fprintf(w, + strings.ReplaceAll( + strings.ReplaceAll( + html, "{} // REPLACED WITH SERVER DATA", string(serverData), + ), + "Satdress", s.SiteName, + ), + ) }, ) @@ -72,12 +93,23 @@ func main() { closer.Close() } - data, _ := json.Marshal(Params{ + params := Params{ Kind: r.FormValue("kind"), Host: r.FormValue("host"), Key: r.FormValue("key"), - }) + Pak: r.FormValue("pak"), + Waki: r.FormValue("waki"), + } + // check if the given data works + if _, err := makeInvoice(params, 1000); err != nil { + w.WriteHeader(400) + fmt.Fprint(w, "couldn't make an invoice with the given data: "+err.Error()) + return + } + + // save it + data, _ := json.Marshal(params) if err := db.Set(name, data, pebble.Sync); err != nil { w.WriteHeader(500) fmt.Fprint(w, "error! "+err.Error()) diff --git a/makeinvoice.go b/makeinvoice.go index 7e37b50..66bcefc 100644 --- a/makeinvoice.go +++ b/makeinvoice.go @@ -9,13 +9,6 @@ import ( "github.com/tidwall/sjson" ) -type Params struct { - Name string - Kind string - Host string - Key string -} - func makeMetadata(params Params) string { metadata, _ := sjson.Set("[]", "0.0", "text/identifier") metadata, _ = sjson.Set(metadata, "0.1", params.Name+"@"+s.Domain) @@ -50,6 +43,11 @@ func makeInvoice(params Params, msat int) (bolt11 string, err error) { Host: params.Host, Key: params.Key, } + case "lnpay": + backend = makeinvoice.LNPayParams{ + PublicAccessKey: params.Pak, + WalletInvoiceKey: params.Waki, + } } // actually generate the invoice