Only support primary domain for Lightning Address
Part of the process of removing support for serving multiple domains from a single akkounts instance. Also puts the Lightning Address discovery routes under the .well-known path. Combined, these changes simplify reverse-proxying to the .well-known endpoints.
This commit is contained in:
parent
eaf41e0835
commit
a628a03f84
@ -1,6 +1,6 @@
|
|||||||
class LnurlpayController < ApplicationController
|
class LnurlpayController < ApplicationController
|
||||||
before_action :check_feature_enabled
|
before_action :check_service_available
|
||||||
before_action :find_user_by_address
|
before_action :find_user
|
||||||
|
|
||||||
MIN_SATS = 10
|
MIN_SATS = 10
|
||||||
MAX_SATS = 1_000_000
|
MAX_SATS = 1_000_000
|
||||||
@ -9,7 +9,7 @@ class LnurlpayController < ApplicationController
|
|||||||
def index
|
def index
|
||||||
render json: {
|
render json: {
|
||||||
status: "OK",
|
status: "OK",
|
||||||
callback: "https://accounts.kosmos.org/lnurlpay/#{@user.address}/invoice",
|
callback: "https://#{Setting.accounts_domain}/lnurlpay/#{@user.cn}/invoice",
|
||||||
tag: "payRequest",
|
tag: "payRequest",
|
||||||
maxSendable: MAX_SATS * 1000, # msat
|
maxSendable: MAX_SATS * 1000, # msat
|
||||||
minSendable: MIN_SATS * 1000, # msat
|
minSendable: MIN_SATS * 1000, # msat
|
||||||
@ -69,9 +69,8 @@ class LnurlpayController < ApplicationController
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def find_user_by_address
|
def find_user
|
||||||
address = params[:address].split("@")
|
@user = User.where(cn: params[:username], ou: Setting.primary_domain).first
|
||||||
@user = User.where(cn: address.first, ou: address.last).first
|
|
||||||
http_status :not_found if @user.nil?
|
http_status :not_found if @user.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -89,7 +88,7 @@ class LnurlpayController < ApplicationController
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def check_feature_enabled
|
def check_service_available
|
||||||
http_status :not_found unless Setting.lndhub_enabled?
|
http_status :not_found unless Setting.lndhub_enabled?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -56,14 +56,12 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
get 'lnurlpay/:address', to: 'lnurlpay#index',
|
get '.well-known/webfinger', to: 'webfinger#show'
|
||||||
as: 'lightning_address', constraints: { address: /[^\/]+/}
|
|
||||||
get 'lnurlpay/:address/invoice', to: 'lnurlpay#invoice',
|
|
||||||
as: 'lnurlpay_invoice', constraints: { address: /[^\/]+/}
|
|
||||||
get 'keysend/:address', to: 'lnurlpay#keysend',
|
|
||||||
as: 'lightning_address_keysend', constraints: { address: /[^\/]+/}
|
|
||||||
|
|
||||||
get '.well-known/nostr', to: 'well_known#nostr'
|
get '.well-known/nostr', to: 'well_known#nostr'
|
||||||
|
get '.well-known/lnurlpay/:username', to: 'lnurlpay#index', as: 'lightning_address'
|
||||||
|
get '.well-known/keysend/:username', to: 'lnurlpay#keysend', as: 'lightning_address_keysend'
|
||||||
|
|
||||||
|
get 'lnurlpay/:username/invoice', to: 'lnurlpay#invoice', as: 'lnurlpay_invoice'
|
||||||
|
|
||||||
post 'webhooks/lndhub', to: 'webhooks#lndhub'
|
post 'webhooks/lndhub', to: 'webhooks#lndhub'
|
||||||
|
|
||||||
@ -96,8 +94,6 @@ Rails.application.routes.draw do
|
|||||||
}, controller: 'oauth'
|
}, controller: 'oauth'
|
||||||
end
|
end
|
||||||
|
|
||||||
get '.well-known/webfinger', to: 'webfinger#show'
|
|
||||||
|
|
||||||
namespace :discourse do
|
namespace :discourse do
|
||||||
get "connect", to: 'sso#connect'
|
get "connect", to: 'sso#connect'
|
||||||
end
|
end
|
||||||
|
@ -2,59 +2,59 @@ require 'rails_helper'
|
|||||||
|
|
||||||
RSpec.describe "/lnurlpay", type: :request do
|
RSpec.describe "/lnurlpay", type: :request do
|
||||||
|
|
||||||
context "Non-existent user/address" do
|
context "Non-existent user" do
|
||||||
describe "GET /lnurlpay/:address" do
|
describe "GET /.well-known/lnurlpay/:username" do
|
||||||
it "returns a 404" do
|
it "returns a 404" do
|
||||||
get lightning_address_path(address: "csw@kosmos.org")
|
get lightning_address_path(username: "csw")
|
||||||
expect(response).to have_http_status(:not_found)
|
expect(response).to have_http_status(:not_found)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET /lnurlpay/:address/invoice" do
|
describe "GET /lnurlpay/:username/invoice" do
|
||||||
it "returns a 404" do
|
it "returns a 404" do
|
||||||
get lnurlpay_invoice_path(address: "csw@kosmos.org", params: { amount: 5000 })
|
get lnurlpay_invoice_path(username: "csw", params: { amount: 5000 })
|
||||||
expect(response).to have_http_status(:not_found)
|
expect(response).to have_http_status(:not_found)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET /keysend/:address/" do
|
describe "GET /.well-known/keysend/:username/" do
|
||||||
it "returns a 404" do
|
it "returns a 404" do
|
||||||
get lightning_address_keysend_path(address: "csw@kosmos.org")
|
get lightning_address_keysend_path(username: "csw")
|
||||||
expect(response).to have_http_status(:not_found)
|
expect(response).to have_http_status(:not_found)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "Valid user/address" do
|
context "Valid user" do
|
||||||
let(:user) { create :user, cn: 'satoshi', ou: 'kosmos.org', ln_account: 'abcdefg123456' }
|
let(:user) { create :user, cn: 'satoshi', ou: 'kosmos.org', ln_account: 'abcdefg123456' }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
login_as user, :scope => :user
|
login_as user, :scope => :user
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET /lnurlpay/:address" do
|
describe "GET /.well-known/lnurlpay/:username" do
|
||||||
it "returns a formatted Lightning Address response" do
|
it "returns a formatted Lightning Address response" do
|
||||||
get lightning_address_path(address: "satoshi@kosmos.org")
|
get lightning_address_path(username: "satoshi")
|
||||||
|
|
||||||
expect(response).to have_http_status(:ok)
|
expect(response).to have_http_status(:ok)
|
||||||
|
|
||||||
res = JSON.parse(response.body)
|
res = JSON.parse(response.body)
|
||||||
expect(res["status"]).to eq('OK')
|
expect(res["status"]).to eq('OK')
|
||||||
expect(res["tag"]).to eq('payRequest')
|
expect(res["tag"]).to eq('payRequest')
|
||||||
expect(res["callback"]).to match(lnurlpay_invoice_path('satoshi@kosmos.org'))
|
expect(res["callback"]).to match(lnurlpay_invoice_path('satoshi'))
|
||||||
expect(res["minSendable"]).to be_a(Integer)
|
expect(res["minSendable"]).to be_a(Integer)
|
||||||
expect(res["maxSendable"]).to be_a(Integer)
|
expect(res["maxSendable"]).to be_a(Integer)
|
||||||
expect(res["commentAllowed"]).to be_a(Integer)
|
expect(res["commentAllowed"]).to be_a(Integer)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET /lnurlpay/:address/invoice" do
|
describe "GET /lnurlpay/:username/invoice" do
|
||||||
before do
|
before do
|
||||||
allow_any_instance_of(User).to receive(:ln_create_invoice).and_return("lnbc50u1p3lwgknpp52g78gqya5euvzjc53fc6hkmlm2rfjhcd305tcmc0g9gaestav48sdq4gdhkven9v5sx6mmwv4ujzcqzpgxqyz5vqsp5skkz4jlqr6tkvv2g9739ygrjupc4rkqd94mc7dfpj3pgx3f6w7qs9qyyssq7mf3fzcuxlmkr9nqatcch3u8uf4gjyawe052tejz8e9fqxu4pncqk3qklt8g6ylpshg09xyjquyrgtc72vcw5cp0dzcf406apyua7dgpnfn7an")
|
allow_any_instance_of(User).to receive(:ln_create_invoice).and_return("lnbc50u1p3lwgknpp52g78gqya5euvzjc53fc6hkmlm2rfjhcd305tcmc0g9gaestav48sdq4gdhkven9v5sx6mmwv4ujzcqzpgxqyz5vqsp5skkz4jlqr6tkvv2g9739ygrjupc4rkqd94mc7dfpj3pgx3f6w7qs9qyyssq7mf3fzcuxlmkr9nqatcch3u8uf4gjyawe052tejz8e9fqxu4pncqk3qklt8g6ylpshg09xyjquyrgtc72vcw5cp0dzcf406apyua7dgpnfn7an")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a formatted lnurlpay response" do
|
it "returns a formatted lnurlpay response" do
|
||||||
get lnurlpay_invoice_path(address: "satoshi@kosmos.org", params: {
|
get lnurlpay_invoice_path(username: "satoshi", params: {
|
||||||
amount: 50000, comment: "Coffee time!"
|
amount: 50000, comment: "Coffee time!"
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ RSpec.describe "/lnurlpay", type: :request do
|
|||||||
|
|
||||||
context "amount too low" do
|
context "amount too low" do
|
||||||
it "returns an error" do
|
it "returns an error" do
|
||||||
get lnurlpay_invoice_path(address: "satoshi@kosmos.org", params: {
|
get lnurlpay_invoice_path(username: "satoshi", params: {
|
||||||
amount: 5000, comment: "Coffee time!"
|
amount: 5000, comment: "Coffee time!"
|
||||||
})
|
})
|
||||||
expect(response).to have_http_status(:ok)
|
expect(response).to have_http_status(:ok)
|
||||||
@ -81,7 +81,7 @@ RSpec.describe "/lnurlpay", type: :request do
|
|||||||
|
|
||||||
context "comment too long" do
|
context "comment too long" do
|
||||||
it "returns an error" do
|
it "returns an error" do
|
||||||
get lnurlpay_invoice_path(address: "satoshi@kosmos.org", params: {
|
get lnurlpay_invoice_path(username: "satoshi", params: {
|
||||||
amount: 5000000, comment: "Coffee time is the best time, so here's some money for you to get some. May I suggest to sample some Pacamara beans from El Salvador?"
|
amount: 5000000, comment: "Coffee time is the best time, so here's some money for you to get some. May I suggest to sample some Pacamara beans from El Salvador?"
|
||||||
})
|
})
|
||||||
expect(response).to have_http_status(:ok)
|
expect(response).to have_http_status(:ok)
|
||||||
@ -92,9 +92,9 @@ RSpec.describe "/lnurlpay", type: :request do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET /keysend/:address/" do
|
describe "GET /.well-known/keysend/:username/" do
|
||||||
it "returns a formatted Lightning Address keysend response" do
|
it "returns a formatted Lightning Address keysend response" do
|
||||||
get lightning_address_keysend_path(address: "satoshi@kosmos.org")
|
get lightning_address_keysend_path(username: "satoshi")
|
||||||
|
|
||||||
expect(response).to have_http_status(:ok)
|
expect(response).to have_http_status(:ok)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user