From 5c163e35fef1b66b663979dc3ea1406bcd5c12d8 Mon Sep 17 00:00:00 2001 From: Otto Suess Date: Thu, 27 Dec 2018 10:28:24 +0100 Subject: [PATCH] rename to lndconnect, use lndconnect url specification --- README.md | 12 +++++----- config.go | 10 ++++----- zapconnect.go => lndconnect.go | 40 +++++++++++++++------------------- 3 files changed, 28 insertions(+), 34 deletions(-) rename zapconnect.go => lndconnect.go (65%) diff --git a/README.md b/README.md index a1e4887..233b727 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,19 @@ -# zapconnect 🌩 +# lndconnect 🌩 Generate QRCode to connect iOS app to remote LND. -## Installing zapconnect +## Installing lndconnect ``` -go get -d github.com/LN-Zap/zapconnect -cd $GOPATH/src/github.com/LN-Zap/zapconnect +go get -d github.com/LN-Zap/lndconnect +cd $GOPATH/src/github.com/LN-Zap/lndconnect make ``` -## Starting zapconnect +## Starting lndconnect ``` -zapconnect +lndconnect ``` ## Application Options diff --git a/config.go b/config.go index ac2f27d..cb92a35 100644 --- a/config.go +++ b/config.go @@ -42,7 +42,7 @@ type chainConfig struct { RegTest bool `long:"regtest" description:"Use the regression test network"` } -type zapConnectConfig struct { +type lndConnectConfig struct { LocalIp bool `short:"i" long:"localip" description:"Include local ip in QRCode"` Localhost bool `short:"l" long:"localhost" description:"Use 127.0.0.1 for ip"` Host string `long:"host" description:"Use specific host name"` @@ -53,12 +53,12 @@ type zapConnectConfig struct { Readonly bool `long:"readonly" description:"use readonly macaroon"` } -// config defines the configuration options for zapconnect. +// config defines the configuration options for lndconnect. // // See loadConfig for further details regarding the configuration // loading+parsing process. type config struct { - ZapConnect *zapConnectConfig `group:"ZapConnect"` + LndConnect *lndConnectConfig `group:"LndConnect"` LndDir string `long:"lnddir" description:"The base directory that contains lnd's data, logs, configuration file, etc."` ConfigFile string `long:"C" long:"configfile" description:"Path to configuration file"` @@ -95,7 +95,7 @@ type config struct { // 4) Parse CLI options and overwrite/add any specified options func loadConfig() (*config, error) { defaultCfg := config{ - ZapConnect: &zapConnectConfig{ + LndConnect: &lndConnectConfig{ Port: defaultRPCPort, }, LndDir: defaultLndDir, @@ -132,7 +132,7 @@ func loadConfig() (*config, error) { var configFileError error cfg := preCfg - // We don't have a full representation of all LND options in zapconnect + // We don't have a full representation of all LND options in lndconnect // so while parsing the config file, we only take what we need, ignoring // all the unknown (to us) options. p := flags.NewParser(&cfg, flags.IgnoreUnknown) diff --git a/zapconnect.go b/lndconnect.go similarity index 65% rename from zapconnect.go rename to lndconnect.go index 9a6305f..093d62e 100644 --- a/zapconnect.go +++ b/lndconnect.go @@ -2,7 +2,6 @@ package main import ( b64 "encoding/base64" - "encoding/json" "encoding/pem" "fmt" "io/ioutil" @@ -64,12 +63,12 @@ func main() { fmt.Println("failed to decode PEM block containing certificate") } - certificate := b64.StdEncoding.EncodeToString([]byte(block.Bytes)) + certificate := b64.RawURLEncoding.EncodeToString([]byte(block.Bytes)) var macBytes []byte - if loadedConfig.ZapConnect.Invoice { + if loadedConfig.LndConnect.Invoice { macBytes, err = ioutil.ReadFile(loadedConfig.InvoiceMacPath) - } else if loadedConfig.ZapConnect.Readonly { + } else if loadedConfig.LndConnect.Readonly { macBytes, err = ioutil.ReadFile(loadedConfig.ReadMacPath) } else { macBytes, err = ioutil.ReadFile(loadedConfig.AdminMacPath) @@ -80,38 +79,33 @@ func main() { return } - macaroonB64 := b64.StdEncoding.EncodeToString([]byte(macBytes)) + macaroonB64 := b64.RawURLEncoding.EncodeToString([]byte(macBytes)) ipString := "" - if loadedConfig.ZapConnect.Host != "" { - ipString = loadedConfig.ZapConnect.Host - } else if loadedConfig.ZapConnect.LocalIp { + if loadedConfig.LndConnect.Host != "" { + ipString = loadedConfig.LndConnect.Host + } else if loadedConfig.LndConnect.LocalIp { ipString = getLocalIP() - } else if loadedConfig.ZapConnect.Localhost { + } else if loadedConfig.LndConnect.Localhost { ipString = "127.0.0.1" } else { ipString = getPublicIP() } ipString = net.JoinHostPort( - ipString, fmt.Sprint(loadedConfig.ZapConnect.Port), + ipString, fmt.Sprint(loadedConfig.LndConnect.Port), ) - cert := &certificates{ - Cert: certificate, - Macaroon: macaroonB64, - Ip: ipString, - } - certB, _ := json.Marshal(cert) + urlString := fmt.Sprintf("lndconnect:?cert=%s&macaroon=%s&host=%s", certificate, macaroonB64, ipString) - if loadedConfig.ZapConnect.Json { - fmt.Println(string(certB)) - } else if loadedConfig.ZapConnect.Image { - qrcode.WriteFile(string(certB), qrcode.Medium, 512, "zapconnect-qr.png") - fmt.Println("Wrote QR Code to file \"zapconnect-qr.png\"") + if loadedConfig.LndConnect.Json { + fmt.Println(urlString) + } else if loadedConfig.LndConnect.Image { + qrcode.WriteFile(urlString, qrcode.Medium, 512, "lndconnect-qr.png") + fmt.Println("Wrote QR Code to file \"lndconnect-qr.png\"") } else { obj := qrcodeTerminal.New() - obj.Get(string(certB)).Print() - fmt.Println("\n⚠️ Press \"cmd + -\" a few times to see the full QR Code!\nIf that doesn't work run \"zapconnect -j\" to get a code you can copy paste into the app.") + obj.Get(urlString).Print() + fmt.Println("\n⚠️ Press \"cmd + -\" a few times to see the full QR Code!\nIf that doesn't work run \"lndconnect -j\" to get a code you can copy paste into the app.") } }