Browse Source

rename to lndconnect, use lndconnect url specification

make_cert_optional
Otto Suess 6 years ago
parent
commit
5c163e35fe
No known key found for this signature in database GPG Key ID: F7EFC44C2C240A11
  1. 12
      README.md
  2. 10
      config.go
  3. 40
      lndconnect.go

12
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

10
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)

40
zapconnect.go → 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.")
}
}
Loading…
Cancel
Save