chore: fix merge conflicts

This commit is contained in:
Andre Neves 2021-08-15 09:59:30 -04:00
commit 4284e05c29
8 changed files with 196 additions and 67 deletions

View File

@ -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'

View File

@ -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.

10
db.go Normal file
View File

@ -0,0 +1,10 @@
package main
type Params struct {
Name string
Kind string
Host string
Key string
Pak string
Waki string
}

2
go.mod
View File

@ -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

8
go.sum
View File

@ -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=

View File

@ -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 @@
}
</style>
<body>
<div class="title">Satdress</div>
<div class="tagline">Federated Lightning Address Server</div>
<div class="card">
<div class="description">Use the form below to connect your own node to a <b>Lightning Address</b>. <br />You can also self-host this server.</div>
<form action="/grab" method="post">
<label>
<p class="label">
Desired Lightning Address
</p>
<input class="input" name="name">
</label>
<label>
<p class="label">
Type
</p>
<select name="kind">
<option>LND</option>
<option>Sparko</option>
<option>LNBits</option>
</select>
</label>
<label>
<p class="label">
Host (IP + Port)
</p>
<input class="input" name="host">
</label>
<label>
<p class="label">
Key or Invoice Macaroon
</p>
<input class="input" name="key">
</label>
<button class="submit">Submit</button>
</form>
</div>
<div class="resources">
<a class="resource-button" href="https://github.com/andrerfneves/lightning-address#readme" target="_blank">
Lightning Address Documentation
</a>
<a class="resource-button" href="https://github.com/fiatjaf/sataddress" target="_blank">
GitHub (MIT Licensed)
</a>
</div>
<main id="main">
<div class="title">Satdress</div>
<div class="tagline">Federated Lightning Address Server</div>
<div class="card">
<div class="description">Use the form below to connect your own node to a <b>Lightning Address</b>.</div>
<form action="/grab" method="post">
<label>
<p class="label">
Desired Username
</p>
<div style="position: relative;">
<input class="input" name="name">
<span class="suffix" style="position: absolute;">@{{ domain }}</span>
</div>
</label>
<label>
<p class="label">
Type
</p>
<select name="kind" v-model="kind">
<option value="lnd">LND</option>
<option value="sparko">Sparko</option>
<option value="lnpay">LNPay</option>
<option value="lnbits">LNbits</option>
</select>
</label>
<div v-if="kind == 'lnd'">
<label>
<p class="label">
Host (IP or domain + Port)
</p>
<input class="input" name="host">
</label>
<label>
<p class="label">
Macaroon
</p>
<input class="input" name="key">
</label>
</div>
<div v-if="kind == 'sparko' || kind == 'lnbits'">
<label>
<p class="label">
Host (IP or domain + Port)
</p>
<input class="input" name="host">
</label>
<label>
<p class="label">
Key
</p>
<input class="input" name="key">
</label>
</div>
<div v-if="kind == 'lnpay'">
<label>
<p class="label">
Public Access Key (pak)
</p>
<input class="input" name="pak">
</label>
<label>
<p class="label">
Wallet Invoice Key (waki)
</p>
<input class="input" name="waki">
</label>
</div>
<button class="submit">Submit</button>
</form>
</div>
<div class="resources">
<a class="resource-button" href="https://github.com/andrerfneves/lightning-address#readme" target="_blank">
Lightning Address Documentation
</a>
<a class="resource-button" :href="siteOwnerURL" target="_blank">Brought to you by {{ siteOwnerName }}</a>
<a class="resource-button" target="_blank" href="https://github.com/fiatjaf/satdress">You can host this server on your domain</a>
</div>
</main>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/3.2.2/vue.global.prod.min.js"></script>
<script>
const initial = {} // REPLACED WITH SERVER DATA // {siteOwnerName, siteOwnerURL, siteName, domain}
const Main = {
data() {
return {
kind: 'lnd',
...initial
}
}
}
Vue.createApp(Main).mount('#main')
</script>
</body>
</html>

48
main.go
View File

@ -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+"<p>offered by %s</p>", 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())

View File

@ -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