Add NIP-05 well-known endpoint
This commit is contained in:
parent
c48538a1c6
commit
34e4cec503
16
app/controllers/well_known_controller.rb
Normal file
16
app/controllers/well_known_controller.rb
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
class WellKnownController < ApplicationController
|
||||||
|
def nostr
|
||||||
|
http_status :unprocessable_entity and return if params[:name].blank?
|
||||||
|
domain = request.headers["X-Forwarded-Host"].presence || Setting.primary_domain
|
||||||
|
@user = User.where(cn: params[:name], ou: domain).first
|
||||||
|
http_status :not_found and return if @user.nil? || @user.nostr_pubkey.blank?
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.json do
|
||||||
|
render json: {
|
||||||
|
names: { "#{@user.cn}": @user.nostr_pubkey }
|
||||||
|
}.to_json
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -44,6 +44,8 @@ Rails.application.routes.draw do
|
|||||||
get 'keysend/:address', to: 'lnurlpay#keysend',
|
get 'keysend/:address', to: 'lnurlpay#keysend',
|
||||||
as: 'lightning_address_keysend', constraints: { address: /[^\/]+/}
|
as: 'lightning_address_keysend', constraints: { address: /[^\/]+/}
|
||||||
|
|
||||||
|
get '.well-known/nostr', to: 'well_known#nostr'
|
||||||
|
|
||||||
post 'webhooks/lndhub', to: 'webhooks#lndhub'
|
post 'webhooks/lndhub', to: 'webhooks#lndhub'
|
||||||
|
|
||||||
namespace :api do
|
namespace :api do
|
||||||
|
41
spec/requests/well_known_spec.rb
Normal file
41
spec/requests/well_known_spec.rb
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe "Well-known URLs", type: :request do
|
||||||
|
describe "GET /nostr" do
|
||||||
|
context "without username param" do
|
||||||
|
it "returns a 422 status" do
|
||||||
|
get "/.well-known/nostr.json"
|
||||||
|
expect(response).to have_http_status(:unprocessable_entity)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "non-existent user" do
|
||||||
|
it "returns a 404 status" do
|
||||||
|
get "/.well-known/nostr.json?name=bob"
|
||||||
|
expect(response).to have_http_status(:not_found)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "user does not have a nostr pubkey configured" do
|
||||||
|
let(:user) { create :user, cn: 'spongebob', ou: 'kosmos.org' }
|
||||||
|
|
||||||
|
it "returns a 404 status" do
|
||||||
|
get "/.well-known/nostr.json?name=spongebob"
|
||||||
|
expect(response).to have_http_status(:not_found)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "user with nostr pubkey" do
|
||||||
|
let(:user) { create :user, cn: 'bobdylan', ou: 'kosmos.org', nostr_pubkey: '438d35a6750d0dd6b75d032af8a768aad76b62f0c70ecb45f9c4d9e63540f7f4' }
|
||||||
|
before { user.save! }
|
||||||
|
|
||||||
|
it "returns a NIP-05 response" do
|
||||||
|
get "/.well-known/nostr.json?name=bobdylan"
|
||||||
|
expect(response).to have_http_status(:ok)
|
||||||
|
res = JSON.parse(response.body)
|
||||||
|
expect(res["names"].keys.size).to eq(1)
|
||||||
|
expect(res["names"]["bobdylan"]).to eq(user.nostr_pubkey)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user