diff --git a/Gemfile b/Gemfile
index 81aceee..1f0a7b3 100644
--- a/Gemfile
+++ b/Gemfile
@@ -57,6 +57,7 @@ gem "sentry-rails"
# Services
gem 'discourse_api'
+gem "lnurl"
gem 'nostr', git: 'https://gitea.kosmos.org/kosmos/nostr-gem.git', branch: 'feature/ruby_2.7_compat'
group :development, :test do
diff --git a/Gemfile.lock b/Gemfile.lock
index 75236f6..3fdc74c 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -206,6 +206,8 @@ GEM
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
+ lnurl (1.0.1)
+ bech32 (~> 1.1)
lockbox (1.2.0)
loofah (2.21.3)
crass (~> 1.0.2)
@@ -430,6 +432,7 @@ DEPENDENCIES
letter_opener
letter_opener_web
listen (~> 3.2)
+ lnurl
lockbox
net-ldap
nostr!
diff --git a/app/controllers/services/lightning_controller.rb b/app/controllers/services/lightning_controller.rb
index 44a4589..94aed24 100644
--- a/app/controllers/services/lightning_controller.rb
+++ b/app/controllers/services/lightning_controller.rb
@@ -1,4 +1,5 @@
require "rqrcode"
+require "lnurl"
class Services::LightningController < ApplicationController
before_action :authenticate_user!
@@ -8,9 +9,56 @@ class Services::LightningController < ApplicationController
def index
@wallet_url = "lndhub://#{current_user.ln_account}:#{current_user.ln_password}@#{ENV['LNDHUB_PUBLIC_URL']}"
+ initialize_lndhub_qr_code
+ end
- qrcode = RQRCode::QRCode.new(@wallet_url)
- @svg = qrcode.as_svg(
+ def transactions
+ @transactions = fetch_transactions
+ end
+
+ def qr_lnurlp
+ lnurlp_url = "https://kosmos.org/.well-known/lnurlp/#{current_user.cn}"
+ lnurlp_bech32 = Lnurl.new(lnurlp_url).to_bech32
+ qr_code = RQRCode::QRCode.new("lightning:" + lnurlp_bech32)
+
+ respond_to do |format|
+ format.svg do
+ qr_svg = qr_code.as_svg(
+ color: "000",
+ shape_rendering: "crispEdges",
+ module_size: 6,
+ standalone: true,
+ use_path: true,
+ svg_attributes: {
+ class: 'inline-block'
+ }
+ )
+ send_data(
+ qr_svg,
+ filename: "bitcoin-lightning-#{current_user.address}.svg",
+ type: "image/svg+xml"
+ )
+ end
+ format.png do
+ qr_png = qr_code.as_png(
+ fill: "white",
+ color: "black",
+ size: 1024,
+ )
+ send_data(
+ qr_png,
+ filename: "bitcoin-lightning-#{current_user.address}.png",
+ type: "image/png"
+ )
+ end
+ end
+ end
+
+ private
+
+ def initialize_lndhub_qr_code
+ qr_code = RQRCode::QRCode.new(@wallet_url)
+ @lndhub_qr_svg = qr_code.as_svg(
color: "000",
shape_rendering: "crispEdges",
module_size: 6,
@@ -22,12 +70,6 @@ class Services::LightningController < ApplicationController
)
end
- def transactions
- @transactions = fetch_transactions
- end
-
- private
-
def authenticate_with_lndhub(options={})
if session[:ln_auth_token].present? && !options[:force_reauth]
@ln_auth_token = session[:ln_auth_token]
diff --git a/app/views/services/lightning/index.html.erb b/app/views/services/lightning/index.html.erb
index fda9558..6d18379 100644
--- a/app/views/services/lightning/index.html.erb
+++ b/app/views/services/lightning/index.html.erb
@@ -7,13 +7,25 @@
+
Your Kosmos user address is also a
Lightning Address!
The easiest way to receive sats is by just giving out your address:
- <%= current_user.address %>
+
+ disabled="disabled"
+ data-clipboard-target="source" />
+
Lightning Address
-
- <%= raw @svg %> + <%= raw @lndhub_qr_svg %>
@@ -88,6 +100,24 @@ + ++ You can print out or publish a QR code for people to scan with their + wallet apps, so they can send you sats without a direct personal + interaction (for example at a concert, or on your website). +
++ <%= link_to "Download SVG file", + qr_lnurlp_services_lightning_index_path(format: "svg"), + class: "btn-md btn-blue w-full sm:w-auto"%> + or + <%= link_to "Download PNG file", + qr_lnurlp_services_lightning_index_path(format: "png"), + class: "btn-md btn-blue w-full sm:w-auto"%> +
+