From 05310fc02beb6ff9c507b91aebc9d1a05a6e5ca1 Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Sun, 22 Jan 2023 21:42:05 +0100 Subject: [PATCH] lndconnect: update to Zeus 0.7.1 - Generate lndconnect URLs with protocol `c-lightning-rest` for clightning. (Zeus now auto-detects the lightning implementation by the URL protocol.) - Use improved QR code format (via qrencode) . --- docs/services.md | 11 ++++------- modules/lndconnect.nix | 41 +++++++++++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/docs/services.md b/docs/services.md index 640a162..be62fa5 100644 --- a/docs/services.md +++ b/docs/services.md @@ -143,7 +143,7 @@ The default password location is `$secretsDir/rtl-password`. See: [Secrets dir](./configuration.md#secrets-dir) # Use Zeus (mobile lightning wallet) via Tor -1. Install [Zeus](https://zeusln.app) +1. Install [Zeus](https://zeusln.app) (version ≥ 0.7.1) 2. Edit your `configuration.nix` @@ -186,19 +186,16 @@ See: [Secrets dir](./configuration.md#secrets-dir) ``` 5. Configure Zeus - - Add a new node - - Select `Scan lndconnect config` (at the bottom) and scan the QR code - - For clightning: Set `Node interface` to `c-lightning-REST` + - Add a new node and scan the QR code - Click `Save node config` - Start sending and stacking sats privately ### Additional lndconnect features -- Create plain text URLs or QR code images +- Create a plain text URL: ```bash lndconnect --url - lndconnect --image ``` -- Set a custom host. By default, `lndconnect` detects the system's external IP and uses it as the host. +- Set a custom host. By default, `lndconnect` detects the system's external IP and uses it as the host. ```bash lndconnect --host myhost ``` diff --git a/modules/lndconnect.nix b/modules/lndconnect.nix index 468e6ff..6bfb5d2 100644 --- a/modules/lndconnect.nix +++ b/modules/lndconnect.nix @@ -82,6 +82,7 @@ let mkLndconnect = { name, shebang ? "#!${pkgs.stdenv.shell} -e", + isClightning ? false, port, macaroonPath, enableOnion, @@ -93,12 +94,39 @@ let # https://github.com/LN-Zap/lndconnect/issues/25 pkgs.hiPrio (pkgs.writeScriptBin name '' ${shebang} - exec ${config.nix-bitcoin.pkgs.lndconnect}/bin/lndconnect \ - ${optionalString enableOnion "--host=$(cat ${config.nix-bitcoin.onionAddresses.dataDir}/${onionService})"} \ - --port=${toString port} \ - ${if enableOnion || certPath == null then "--nocert" else "--tlscertpath='${certPath}'"} \ - --adminmacaroonpath='${macaroonPath}' \ - --configfile=/dev/null "$@" + url=$( + ${getExe config.nix-bitcoin.pkgs.lndconnect} --url \ + ${optionalString enableOnion "--host=$(cat ${config.nix-bitcoin.onionAddresses.dataDir}/${onionService})"} \ + --port=${toString port} \ + ${if enableOnion || certPath == null then "--nocert" else "--tlscertpath='${certPath}'"} \ + --adminmacaroonpath='${macaroonPath}' \ + --configfile=/dev/null "$@" + ) + + ${optionalString isClightning + # - Change URL procotcol to c-lightning-rest + # - Encode macaroon as hex (in uppercase) instead of base 64. + # Because `macaroon` is always the last URL fragment, the + # sed replacement below works correctly. + '' + macaroonHex=$(${getExe pkgs.xxd} -p -u -c 99999 '${macaroonPath}') + url=$( + echo "$url" | ${getExe pkgs.gnused} " + s|^lndconnect|c-lightning-rest| + s|macaroon=.*|macaroon=$macaroonHex| + "; + ) + '' + } + + # If --url is in args + if [[ " $* " =~ " --url " ]]; then + echo "$url" + else + # This UTF-8 encoding yields a smaller, more convenient output format + # compared to the native lndconnect output + echo -n "$url" | ${getExe pkgs.qrencode} -t UTF8 -o - + fi ''); operatorName = config.nix-bitcoin.operator.name; @@ -144,6 +172,7 @@ in { environment.systemPackages = [( mkLndconnect { name = "lndconnect-clightning"; + isClightning = true; enableOnion = clightning-rest.lndconnect.onion; onionService = "${operatorName}/clightning-rest"; port = clightning-rest.port;