From 5826f5ec3a233d5821f5ecf423a12867c9d4b219 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sat, 14 Aug 2021 18:55:05 -0300 Subject: [PATCH 1/4] support lnpay, check invoice before saving params. --- db.go | 10 +++++ go.mod | 2 +- go.sum | 8 +++- index.html | 102 +++++++++++++++++++++++++++++++++++++++++++------ main.go | 15 +++++++- makeinvoice.go | 12 +++--- 6 files changed, 125 insertions(+), 24 deletions(-) create mode 100644 db.go 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 d35817e..84a3fa7 100644 --- a/index.html +++ b/index.html @@ -1,34 +1,112 @@ -
+ + + +
+ +
+ + + + + + + + + +
+ +
+ + + + + + + + + +
+ +
+ + + + + + + diff --git a/main.go b/main.go index 099dc34..f77d40a 100644 --- a/main.go +++ b/main.go @@ -72,12 +72,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 From 21a7a1003c9ae7a581768d470ebecef43f0f1801 Mon Sep 17 00:00:00 2001 From: Andre Neves Date: Sat, 14 Aug 2021 20:52:16 -0300 Subject: [PATCH 2/4] UI revamp. --- LICENSE.md | 8 ++ README.md | 5 + index.html | 370 +++++++++++++++++++++++++++++++++++++---------------- main.go | 33 ++++- 4 files changed, 300 insertions(+), 116 deletions(-) create mode 100644 LICENSE.md create mode 100644 README.md diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..a97a245 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,8 @@ +Copyright © 2021 fiatjaf + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..03cc3a0 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# Satdress + +Federated Lightning Address Server + +## Instructions diff --git a/index.html b/index.html index 84a3fa7..f75a9de 100644 --- a/index.html +++ b/index.html @@ -1,113 +1,263 @@ - + + + + Satdress - Federated Lightning Address Server + + + + + + + + + + +
+
Satdress
+
Federated Lightning Address Server
+
+
Use the form below to connect your own node to a Lightning Address.
+ + + +
+ + +
+
+ + +
+
+ + +
+ + +
+ +
+ + + + diff --git a/main.go b/main.go index f77d40a..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, + ), + ) }, ) From 68b4d0eced9141148eb90cf106627cb70e3e7fc5 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sat, 14 Aug 2021 21:07:13 -0300 Subject: [PATCH 3/4] how to run instructions. --- README.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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. From f98da7d981ce9e530596c805dfe5b00f2ed1f7eb Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sat, 14 Aug 2021 22:08:44 -0300 Subject: [PATCH 4/4] add other services to makefile. --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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'