Add remote signer connect and login UI
This commit is contained in:
20 files changed
+1054
-10
No files matched your search
@@ -0,0 +1,106 @@
|
||||
<section class="mt-8">
|
||||
<h4 class="mb-0"><%= @title %></h4>
|
||||
|
||||
<% if @description.present? %>
|
||||
<p class="mt-2 text-sm text-gray-600"><%= @description %></p>
|
||||
<% end %>
|
||||
|
||||
<% if @active_session.present? %>
|
||||
<div class="mt-4 rounded-md bg-emerald-50 p-4 text-sm text-emerald-800">
|
||||
<p class="font-bold">Connected via remote signer</p>
|
||||
<p class="mt-1 break-all"><%= @active_session.user_pubkey_bech32 %></p>
|
||||
<% if @active_session.verified_at.present? %>
|
||||
<p class="mt-1 text-xs">Connected <%= @active_session.verified_at.strftime("%Y-%m-%d %H:%M") %></p>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<% if @show_disconnect && @destroy_url.present? %>
|
||||
<p class="mt-4">
|
||||
<%= button_to "Disconnect remote signer", @destroy_url, method: :delete,
|
||||
class: "btn-md btn-outline text-red-700" %>
|
||||
</p>
|
||||
<% end %>
|
||||
<% elsif @pending_session.present? %>
|
||||
<div data-controller="nostr-signer-connect"
|
||||
data-nostr-signer-connect-status-url-value="<%= @status_url %>">
|
||||
<% unless @pending_session.bunker? %>
|
||||
<p class="mt-3 text-sm">Scan this QR code with your signer app, or copy the connection URI:</p>
|
||||
|
||||
<div class="mt-4 flex justify-center rounded-lg bg-white p-3">
|
||||
<%= qr_svg %>
|
||||
</div>
|
||||
|
||||
<p class="mt-3">
|
||||
<input type="text" readonly value="<%= @pending_session.nostrconnect_uri %>"
|
||||
class="w-full text-xs" data-nostr-signer-connect-target="uri" />
|
||||
</p>
|
||||
<p class="mt-2">
|
||||
<button type="button" class="btn-sm btn-gray"
|
||||
data-action="nostr-signer-connect#copy">
|
||||
Copy connection URI
|
||||
</button>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<p class="mt-4 text-sm text-gray-600" data-nostr-signer-connect-target="status">
|
||||
Waiting for your signer…
|
||||
</p>
|
||||
|
||||
<p class="mt-2 hidden text-sm" data-nostr-signer-connect-target="authWrapper">
|
||||
<a href="#" target="_blank" rel="noopener noreferrer"
|
||||
class="text-blue-700 underline"
|
||||
data-nostr-signer-connect-target="authLink">
|
||||
Authenticate with your signer
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<p class="mt-2 hidden text-sm text-red-700" data-nostr-signer-connect-target="error"></p>
|
||||
|
||||
<details class="mt-4 text-sm">
|
||||
<summary class="cursor-pointer text-gray-600">Prefer a bunker:// URI?</summary>
|
||||
<%= form_with url: @create_url, method: :post, local: true, class: "mt-3" do %>
|
||||
<p>
|
||||
<%= text_field_tag :bunker_uri, nil,
|
||||
placeholder: "bunker://…",
|
||||
class: "w-full text-xs",
|
||||
autocomplete: "off" %>
|
||||
</p>
|
||||
<p class="mt-2">
|
||||
<%= submit_tag "Connect bunker", class: "btn-sm btn-gray" %>
|
||||
</p>
|
||||
<% end %>
|
||||
</details>
|
||||
|
||||
<% if @show_disconnect && @destroy_url.present? %>
|
||||
<p class="mt-4">
|
||||
<%= button_to "Cancel", @destroy_url, method: :delete,
|
||||
class: "btn-sm btn-outline text-gray-700" %>
|
||||
</p>
|
||||
<% end %>
|
||||
</div>
|
||||
<% else %>
|
||||
<p class="mt-3 text-sm">
|
||||
Connect a signer app on your phone or desktop. Your private key never leaves your signer.
|
||||
</p>
|
||||
|
||||
<p class="mt-4">
|
||||
<%= button_to "Connect remote signer", @create_url, method: :post,
|
||||
class: "btn-md btn-blue w-full sm:w-auto" %>
|
||||
</p>
|
||||
|
||||
<details class="mt-4 text-sm">
|
||||
<summary class="cursor-pointer text-gray-600">Already have a bunker:// URI?</summary>
|
||||
<%= form_with url: @create_url, method: :post, local: true, class: "mt-3" do %>
|
||||
<p>
|
||||
<%= text_field_tag :bunker_uri, nil,
|
||||
placeholder: "bunker://…",
|
||||
class: "w-full text-xs",
|
||||
autocomplete: "off" %>
|
||||
</p>
|
||||
<p class="mt-2">
|
||||
<%= submit_tag "Connect bunker", class: "btn-sm btn-gray" %>
|
||||
</p>
|
||||
<% end %>
|
||||
</details>
|
||||
<% end %>
|
||||
</section>
|
||||
@@ -0,0 +1,27 @@
|
||||
require "rqrcode"
|
||||
|
||||
class NostrSignerConnectComponent < ViewComponent::Base
|
||||
def initialize(pending_session: nil, active_session: nil, create_url:, destroy_url: nil,
|
||||
status_url: nil, title: "Remote signer", description: nil,
|
||||
show_disconnect: true)
|
||||
@pending_session = pending_session
|
||||
@active_session = active_session
|
||||
@create_url = create_url
|
||||
@destroy_url = destroy_url
|
||||
@status_url = status_url
|
||||
@title = title
|
||||
@description = description
|
||||
@show_disconnect = show_disconnect
|
||||
end
|
||||
|
||||
def qr_svg
|
||||
RQRCode::QRCode.new(@pending_session.nostrconnect_uri).as_svg(
|
||||
color: "000",
|
||||
shape_rendering: "crispEdges",
|
||||
module_size: 5,
|
||||
standalone: true,
|
||||
use_path: true,
|
||||
svg_attributes: { class: "inline-block" }
|
||||
).html_safe
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,117 @@
|
||||
module Settings
|
||||
class NostrSignaturesController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
|
||||
MAX_BODY_BYTES = 100_000
|
||||
RATE_LIMIT = 20
|
||||
RATE_WINDOW = 5.minutes
|
||||
|
||||
def create
|
||||
return render_error("Remote signing is not configured", :service_unavailable) unless
|
||||
NostrSignerSession.encryption_available?
|
||||
return render_error("This account has no Nostr public key", :forbidden) if
|
||||
current_user.nostr_pubkey.blank?
|
||||
return render_error("No remote signer is connected", :forbidden) if active_signer_session.nil?
|
||||
return render_error("Too many signing requests. Please try again later.", :too_many_requests) if
|
||||
rate_limited?
|
||||
return render_error("Request is too large", :payload_too_large) if
|
||||
request.content_length.to_i > MAX_BODY_BYTES
|
||||
|
||||
template = build_template
|
||||
sign_request = current_user.nostr_sign_requests.create!(
|
||||
kind: template["kind"],
|
||||
template: template,
|
||||
status: "pending",
|
||||
expires_at: NostrSignRequest::TTL.from_now
|
||||
)
|
||||
|
||||
NostrSignEventJob.perform_later(sign_request.id)
|
||||
|
||||
render json: { token: sign_request.token, status: "pending" }
|
||||
rescue ActionController::ParameterMissing, ArgumentError, TypeError, JSON::ParserError => e
|
||||
render_error("Invalid event: #{e.message}", :unprocessable_entity)
|
||||
end
|
||||
|
||||
def show
|
||||
sign_request = current_user.nostr_sign_requests.find_by(token: params[:token])
|
||||
return render_error("Unknown signing request", :not_found) if sign_request.nil?
|
||||
|
||||
case sign_request.status
|
||||
when "signed"
|
||||
render json: { status: "signed", signed_event: sign_request.signed_event }
|
||||
when "failed"
|
||||
render json: { status: "failed", error: sign_request.error }, status: :unprocessable_entity
|
||||
when "expired"
|
||||
render json: { status: "expired", error: sign_request.error }, status: :gone
|
||||
else
|
||||
if sign_request.expires_at < Time.current
|
||||
sign_request.expire!
|
||||
render json: { status: "expired", error: sign_request.error }, status: :gone
|
||||
else
|
||||
render json: { status: "pending" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def active_signer_session
|
||||
@active_signer_session ||= NostrSignerSession
|
||||
.where(user: current_user, status: %w[verified connected])
|
||||
.order(updated_at: :desc)
|
||||
.first
|
||||
end
|
||||
|
||||
def build_template
|
||||
raw = params.require(:event)
|
||||
raw = raw.to_unsafe_h if raw.respond_to?(:to_unsafe_h)
|
||||
raw = raw.symbolize_keys
|
||||
|
||||
kind = Integer(raw[:kind])
|
||||
content = raw[:content].to_s
|
||||
created_at = Integer(raw[:created_at] || Time.current.to_i)
|
||||
tags = Array(raw[:tags]).map { |tag| Array(tag).map(&:to_s) }
|
||||
|
||||
allowed_kinds = NostrManager::RemoteSigner::ALLOWED_SIGN_KINDS
|
||||
raise ArgumentError, "kind #{kind} is not allowed" unless allowed_kinds.include?(kind)
|
||||
|
||||
event = Nostr::Event.new(
|
||||
pubkey: current_user.nostr_pubkey.presence || "0" * 64,
|
||||
kind: kind,
|
||||
content: content,
|
||||
created_at: created_at,
|
||||
tags: tags
|
||||
)
|
||||
|
||||
raise ArgumentError, "stale created_at" unless NostrManager::EventLimits.fresh?(event)
|
||||
unless NostrManager::EventLimits.within_size_limits?(event)
|
||||
raise ArgumentError, "content or tags too large"
|
||||
end
|
||||
|
||||
if kind == 24242
|
||||
verbs = tags.select { |tag| tag[0] == "t" }.map { |tag| tag[1] }
|
||||
raise ArgumentError, "invalid upload authorization" unless verbs.include?("upload")
|
||||
end
|
||||
|
||||
{
|
||||
"kind" => kind,
|
||||
"content" => content,
|
||||
"created_at" => created_at,
|
||||
"tags" => tags
|
||||
}
|
||||
end
|
||||
|
||||
def rate_limited?
|
||||
key = "nostr_sign:#{current_user.id}"
|
||||
count = Rails.cache.read(key).to_i
|
||||
return true if count >= RATE_LIMIT
|
||||
|
||||
Rails.cache.write(key, count + 1, expires_in: RATE_WINDOW)
|
||||
false
|
||||
end
|
||||
|
||||
def render_error(message, status)
|
||||
render json: { error: message }, status: status
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,143 @@
|
||||
module Settings
|
||||
class NostrSignersController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
|
||||
RATE_LIMIT = 8
|
||||
RATE_WINDOW = 10.minutes
|
||||
STATUS_RATE_LIMIT = 240
|
||||
STATUS_RATE_WINDOW = 5.minutes
|
||||
MAX_PENDING = 20
|
||||
|
||||
def create
|
||||
return render_error("Nostr is not enabled", :forbidden) unless Setting.nostr_enabled?
|
||||
return render_error("Remote signing is not configured", :service_unavailable) unless
|
||||
NostrSignerSession.encryption_available?
|
||||
return render_error("Too many connection attempts. Please try again later.", :too_many_requests) if
|
||||
rate_limited?
|
||||
return render_error("Too many pending connections. Please try again later.", :too_many_requests) if
|
||||
pending_connections_exceeded?
|
||||
|
||||
signer_session =
|
||||
if params[:bunker_uri].present?
|
||||
parsed = NostrManager::RemoteSigner::ParseBunkerUri.call(uri: params[:bunker_uri])
|
||||
NostrManager::RemoteSigner::CreateSession.call(
|
||||
flow: "settings",
|
||||
user: current_user,
|
||||
relays: parsed[:relays],
|
||||
connection_method: "bunker",
|
||||
remote_signer_pubkey: parsed[:remote_signer_pubkey],
|
||||
secret: parsed[:secret]
|
||||
)
|
||||
else
|
||||
NostrManager::RemoteSigner::CreateSession.call(flow: "settings", user: current_user)
|
||||
end
|
||||
|
||||
session[:nostr_signer_token] = signer_session.token
|
||||
NostrConnectListenerJob.perform_later(signer_session.id)
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to setting_path(:nostr) }
|
||||
format.json do
|
||||
render json: {
|
||||
token: signer_session.token,
|
||||
uri: signer_session.nostrconnect_uri,
|
||||
expires_at: signer_session.expires_at
|
||||
}
|
||||
end
|
||||
end
|
||||
rescue NostrManager::RemoteSigner::Error => e
|
||||
render_error(e.message, :unprocessable_entity)
|
||||
end
|
||||
|
||||
def status
|
||||
return render_error("Too many status requests. Please try again later.", :too_many_requests) if
|
||||
status_rate_limited?
|
||||
|
||||
signer_session = NostrSignerSession.find_by_token(params[:token])
|
||||
return render_error("Unknown connection", :not_found) if signer_session.nil? ||
|
||||
signer_session.user_id != current_user.id
|
||||
|
||||
signer_session.update_column(:last_status_poll_at, Time.current)
|
||||
|
||||
if signer_session.verified? || signer_session.connected?
|
||||
connect_account!(signer_session)
|
||||
elsif signer_session.failed? || signer_session.expired?
|
||||
render json: { status: signer_session.status, error: signer_session.error }
|
||||
else
|
||||
render json: { status: "pending", auth_url: signer_session.auth_url }
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
current_user.nostr_signer_sessions
|
||||
.where(status: %w[pending verified connected])
|
||||
.delete_all
|
||||
session.delete(:nostr_signer_token)
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to setting_path(:nostr), flash: { success: "Remote signer disconnected" } }
|
||||
format.json { render json: { ok: true } }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def connect_account!(signer_session)
|
||||
conflict = false
|
||||
|
||||
signer_session.with_lock do
|
||||
next if signer_session.consumed_at.present?
|
||||
|
||||
other_user = LdapManager::FetchUserByNostrKey.call(pubkey: signer_session.user_pubkey)
|
||||
|
||||
if other_user.present? && other_user != current_user
|
||||
conflict = true
|
||||
else
|
||||
LdapManager::UpdateNostrKey.call(dn: current_user.dn, pubkey: signer_session.user_pubkey)
|
||||
signer_session.update!(status: "connected", consumed_at: Time.current)
|
||||
end
|
||||
end
|
||||
|
||||
if conflict
|
||||
render_error("Public key already in use for a different account", :unprocessable_entity)
|
||||
else
|
||||
session.delete(:nostr_signer_token)
|
||||
render json: { status: "connected", npub: signer_session.user_pubkey_bech32 }
|
||||
end
|
||||
end
|
||||
|
||||
def rate_limited?
|
||||
key = "nostr_signer:#{current_user.id}"
|
||||
count = Rails.cache.read(key).to_i
|
||||
return true if count >= RATE_LIMIT
|
||||
|
||||
Rails.cache.write(key, count + 1, expires_in: RATE_WINDOW)
|
||||
false
|
||||
end
|
||||
|
||||
def status_rate_limited?
|
||||
key = "nostr_signer_status:#{current_user.id}"
|
||||
count = Rails.cache.read(key).to_i
|
||||
return true if count >= STATUS_RATE_LIMIT
|
||||
|
||||
Rails.cache.write(key, count + 1, expires_in: STATUS_RATE_WINDOW)
|
||||
false
|
||||
end
|
||||
|
||||
def pending_connections_exceeded?
|
||||
NostrSignerSession
|
||||
.where(status: "pending")
|
||||
.where("expires_at > ?", Time.current)
|
||||
.count >= MAX_PENDING
|
||||
end
|
||||
|
||||
def render_error(message, status)
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
redirect_to setting_path(:nostr), flash: { alert: message }
|
||||
end
|
||||
format.json { render json: { error: message }, status: status }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -23,6 +23,13 @@ class SettingsController < ApplicationController
|
||||
@user.preferences[:lightning_notify_zap_received] != "disabled"
|
||||
when "nostr"
|
||||
session[:shared_secret] ||= SecureRandom.base64(12)
|
||||
@pending_signer_session = NostrSignerSession.find_by_token(session[:nostr_signer_token])
|
||||
|
||||
if @pending_signer_session &&
|
||||
(@pending_signer_session.user_id != current_user.id ||
|
||||
!(@pending_signer_session.pending? || @pending_signer_session.verified?))
|
||||
@pending_signer_session = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
module Users
|
||||
class NostrConnectsController < ApplicationController
|
||||
RATE_LIMIT = 10
|
||||
RATE_WINDOW = 10.minutes
|
||||
STATUS_RATE_LIMIT = 240
|
||||
STATUS_RATE_WINDOW = 5.minutes
|
||||
MAX_PENDING = 20
|
||||
|
||||
def show
|
||||
unless Setting.nostr_enabled? && NostrSignerSession.encryption_available?
|
||||
redirect_to new_user_session_path, alert: "Nostr login is not available right now."
|
||||
return
|
||||
end
|
||||
|
||||
@signer_session = find_or_create_session
|
||||
|
||||
if @signer_session.nil?
|
||||
redirect_to new_user_session_path,
|
||||
alert: "Too many connection attempts. Please try again later."
|
||||
else
|
||||
session[:nostr_connect_token] = @signer_session.token
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
unless Setting.nostr_enabled? && NostrSignerSession.encryption_available?
|
||||
redirect_to new_user_session_path, alert: "Nostr login is not available right now."
|
||||
return
|
||||
end
|
||||
|
||||
if rate_limited?
|
||||
redirect_to new_user_session_path,
|
||||
alert: "Too many connection attempts. Please try again later."
|
||||
return
|
||||
end
|
||||
|
||||
if pending_connections_exceeded?
|
||||
redirect_to new_user_session_path,
|
||||
alert: "Too many pending connections. Please try again later."
|
||||
return
|
||||
end
|
||||
|
||||
parsed = NostrManager::RemoteSigner::ParseBunkerUri.call(uri: params[:bunker_uri])
|
||||
signer_session = NostrManager::RemoteSigner::CreateSession.call(
|
||||
flow: "login",
|
||||
relays: parsed[:relays],
|
||||
connection_method: "bunker",
|
||||
remote_signer_pubkey: parsed[:remote_signer_pubkey],
|
||||
secret: parsed[:secret]
|
||||
)
|
||||
|
||||
session[:nostr_connect_token] = signer_session.token
|
||||
NostrConnectListenerJob.perform_later(signer_session.id)
|
||||
|
||||
redirect_to nostr_connect_path
|
||||
rescue NostrManager::RemoteSigner::Error => e
|
||||
redirect_to nostr_connect_path, alert: e.message
|
||||
end
|
||||
|
||||
def status
|
||||
if status_rate_limited?
|
||||
return render json: { error: "Too many status requests. Please try again later." },
|
||||
status: :too_many_requests
|
||||
end
|
||||
|
||||
signer_session = NostrSignerSession.find_by_token(session[:nostr_connect_token])
|
||||
|
||||
unless signer_session&.flow == "login"
|
||||
return render json: { status: "failed", error: "Unknown connection" }, status: :not_found
|
||||
end
|
||||
|
||||
signer_session.update_column(:last_status_poll_at, Time.current)
|
||||
|
||||
if signer_session.verified?
|
||||
sign_in_user(signer_session)
|
||||
elsif signer_session.connected? && signer_session.user.present?
|
||||
sign_in(:user, signer_session.user)
|
||||
session.delete(:nostr_connect_token)
|
||||
render json: {
|
||||
status: "connected",
|
||||
redirect_url: after_sign_in_path_for(signer_session.user)
|
||||
}
|
||||
elsif signer_session.failed? || signer_session.expired?
|
||||
render json: { status: signer_session.status, error: signer_session.error }
|
||||
else
|
||||
render json: { status: "pending", auth_url: signer_session.auth_url }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_or_create_session
|
||||
existing = NostrSignerSession.find_by_token(session[:nostr_connect_token])
|
||||
|
||||
if existing && existing.flow == "login" && (existing.pending? || existing.verified?)
|
||||
NostrConnectListenerJob.perform_later(existing.id) if existing.pending?
|
||||
return existing
|
||||
end
|
||||
|
||||
return nil if pending_connections_exceeded?
|
||||
|
||||
NostrManager::RemoteSigner::CreateSession.call(flow: "login").tap do |signer_session|
|
||||
NostrConnectListenerJob.perform_later(signer_session.id)
|
||||
end
|
||||
end
|
||||
|
||||
def sign_in_user(signer_session)
|
||||
user = LdapManager::FetchUserByNostrKey.call(pubkey: signer_session.user_pubkey)
|
||||
|
||||
if user.nil?
|
||||
signer_session.fail!("No account is linked to this public key. Add it in your settings first.")
|
||||
return render json: { status: "failed", error: signer_session.error }, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
signer_session.with_lock do
|
||||
next if signer_session.consumed_at.present?
|
||||
|
||||
NostrSignerSession
|
||||
.where(user: user, status: %w[pending verified connected])
|
||||
.where.not(id: signer_session.id)
|
||||
.delete_all
|
||||
|
||||
signer_session.update!(
|
||||
user: user,
|
||||
status: "connected",
|
||||
consumed_at: Time.current
|
||||
)
|
||||
end
|
||||
|
||||
sign_in(:user, user)
|
||||
session.delete(:nostr_connect_token)
|
||||
|
||||
render json: {
|
||||
status: "connected",
|
||||
redirect_url: after_sign_in_path_for(user)
|
||||
}
|
||||
end
|
||||
|
||||
def rate_limited?
|
||||
key = "nostr_connect_ip:#{request.remote_ip}"
|
||||
count = Rails.cache.read(key).to_i
|
||||
return true if count >= RATE_LIMIT
|
||||
|
||||
Rails.cache.write(key, count + 1, expires_in: RATE_WINDOW)
|
||||
false
|
||||
end
|
||||
|
||||
def status_rate_limited?
|
||||
key = "nostr_connect_status_ip:#{request.remote_ip}"
|
||||
count = Rails.cache.read(key).to_i
|
||||
return true if count >= STATUS_RATE_LIMIT
|
||||
|
||||
Rails.cache.write(key, count + 1, expires_in: STATUS_RATE_WINDOW)
|
||||
false
|
||||
end
|
||||
|
||||
def pending_connections_exceeded?
|
||||
NostrSignerSession
|
||||
.where(status: "pending")
|
||||
.where("expires_at > ?", Time.current)
|
||||
.count >= MAX_PENDING
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -21,6 +21,20 @@ module ApplicationHelper
|
||||
}).to_html
|
||||
end
|
||||
|
||||
def active_nostr_signer_session
|
||||
return nil unless user_signed_in?
|
||||
return nil unless NostrSignerSession.encryption_available?
|
||||
|
||||
@active_nostr_signer_session ||= current_user.nostr_signer_sessions
|
||||
.where(status: %w[verified connected])
|
||||
.order(updated_at: :desc)
|
||||
.first
|
||||
end
|
||||
|
||||
def nostr_remote_signer_available?
|
||||
Setting.nostr_enabled? && NostrSignerSession.encryption_available?
|
||||
end
|
||||
|
||||
def image_url_for(attachment)
|
||||
return s3_image_url(attachment) if Setting.s3_enabled?
|
||||
|
||||
|
||||
@@ -3,13 +3,14 @@ import { csrfToken } from "lib/csrf"
|
||||
|
||||
// Connects to data-controller="nostr-login"
|
||||
export default class extends Controller {
|
||||
static targets = [ "loginForm", "loginButton" ]
|
||||
static targets = [ "loginButton" ]
|
||||
static values = { site: String, sharedSecret: String }
|
||||
|
||||
connect() {
|
||||
if (window.nostr) {
|
||||
this.element.classList.remove("hidden")
|
||||
this.loginButtonTarget.disabled = false
|
||||
this.loginFormTarget.classList.remove("hidden")
|
||||
this.loginButtonTarget.classList.remove("hidden")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
const POLL_INTERVAL = 2000
|
||||
const MAX_ATTEMPTS = 160
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = [ "status", "error", "authWrapper", "authLink", "uri" ]
|
||||
static values = { statusUrl: String }
|
||||
|
||||
connect () {
|
||||
this.attempts = 0
|
||||
this.stopped = false
|
||||
this.poll()
|
||||
}
|
||||
|
||||
disconnect () {
|
||||
this.stopped = true
|
||||
clearTimeout(this.timer)
|
||||
}
|
||||
|
||||
async poll () {
|
||||
if (this.stopped) return
|
||||
|
||||
this.attempts += 1
|
||||
|
||||
try {
|
||||
const response = await fetch(this.statusUrlValue, {
|
||||
credentials: "include",
|
||||
headers: { "Accept": "application/json" }
|
||||
})
|
||||
const data = await response.json().catch(() => ({}))
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.error || `HTTP ${response.status}`)
|
||||
}
|
||||
|
||||
if (data.status === "connected") {
|
||||
this.statusTarget.textContent = "Connected. Redirecting…"
|
||||
window.location.href = data.redirect_url || window.location.href
|
||||
return
|
||||
}
|
||||
|
||||
if (data.status === "failed" || data.status === "expired") {
|
||||
this.showError(data.error || "The connection failed. Please try again.")
|
||||
return
|
||||
}
|
||||
|
||||
this.showAuthUrl(data.auth_url)
|
||||
|
||||
if (this.attempts >= MAX_ATTEMPTS) {
|
||||
this.showError("Timed out waiting for your signer. Please try again.")
|
||||
return
|
||||
}
|
||||
|
||||
this.timer = setTimeout(() => this.poll(), POLL_INTERVAL)
|
||||
} catch (error) {
|
||||
this.showError(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
async copy () {
|
||||
try {
|
||||
await navigator.clipboard.writeText(this.uriTarget.value)
|
||||
this.statusTarget.textContent = "Connection URI copied."
|
||||
setTimeout(() => {
|
||||
if (!this.stopped) this.statusTarget.textContent = "Waiting for your signer…"
|
||||
}, 3000)
|
||||
} catch (error) {
|
||||
this.showError("Could not copy the connection URI.")
|
||||
}
|
||||
}
|
||||
|
||||
showAuthUrl (url) {
|
||||
if (!url) {
|
||||
this.authWrapperTarget.classList.add("hidden")
|
||||
return
|
||||
}
|
||||
|
||||
this.authLinkTarget.href = url
|
||||
this.authWrapperTarget.classList.remove("hidden")
|
||||
}
|
||||
|
||||
showError (message) {
|
||||
this.errorTarget.textContent = message
|
||||
this.errorTarget.classList.remove("hidden")
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ export default class extends Controller {
|
||||
if (this.hasSetPubkeyTarget) {
|
||||
this.setPubkeyTarget.disabled = false
|
||||
}
|
||||
} else {
|
||||
} else if (this.element.dataset.nostrRemoteSignerAvailable !== "true") {
|
||||
this.noExtensionTarget.classList.remove("hidden")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,4 +60,19 @@
|
||||
class: "h-44 w-80" %>
|
||||
<% end %>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h3>Remote signer (NIP-46)</h3>
|
||||
<ul role="list">
|
||||
<%= render FormElements::FieldsetComponent.new(
|
||||
title: "Signer relays",
|
||||
description: "Relays used to exchange NIP-46 connection and signing messages. One URL per line."
|
||||
) do %>
|
||||
<%= f.text_area :nostr_signer_relays,
|
||||
value: Setting.nostr_signer_relays.join("\n"),
|
||||
class: "h-32 w-80" %>
|
||||
<% end %>
|
||||
</ul>
|
||||
</section>
|
||||
<% end %>
|
||||
@@ -57,10 +57,9 @@
|
||||
<% end %>
|
||||
|
||||
<div data-controller="nostr-login"
|
||||
data-nostr-login-target="loginForm"
|
||||
data-nostr-login-site-value="<%= Setting.accounts_domain %>"
|
||||
data-nostr-login-shared-secret-value="<%= session[:shared_secret] %>"
|
||||
class="hidden">
|
||||
class="<%= 'hidden' unless nostr_remote_signer_available? %>">
|
||||
<div class="relative my-6">
|
||||
<div class="absolute inset-0 flex items-center" aria-hidden="true">
|
||||
<div class="w-full border-t border-gray-200"></div>
|
||||
@@ -69,12 +68,18 @@
|
||||
<span class="bg-white px-2 text-sm text-gray-500 italic">or</span>
|
||||
</div>
|
||||
</div>
|
||||
<p>
|
||||
<% if nostr_remote_signer_available? %>
|
||||
<p>
|
||||
<%= link_to "Log in with a remote signer", nostr_connect_path,
|
||||
class: "block w-full btn-md btn-gray text-purple-600 text-center" %>
|
||||
</p>
|
||||
<% end %>
|
||||
<p class="mt-2">
|
||||
<button disabled tabindex="5"
|
||||
class="w-full btn-md btn-gray text-purple-600"
|
||||
class="hidden w-full btn-md btn-gray text-purple-600"
|
||||
data-nostr-login-target="loginButton"
|
||||
data-action="nostr-login#login">
|
||||
Log in with Nostr
|
||||
Log in with browser extension
|
||||
</button>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html class="h-full">
|
||||
<html class="h-full" data-remote-signer="<%= active_nostr_signer_session.present? %>">
|
||||
<head>
|
||||
<title>Kosmos Accounts</title>
|
||||
<%= csrf_meta_tags %>
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
data-settings--nostr-pubkey-user-address-value="<%= current_user.address %>"
|
||||
data-settings--nostr-pubkey-site-value="<%= Setting.accounts_domain %>"
|
||||
data-settings--nostr-pubkey-shared-secret-value="<%= session[:shared_secret] %>"
|
||||
data-settings--nostr-pubkey-pubkey-hex-value="<%= current_user.nostr_pubkey %>">
|
||||
data-settings--nostr-pubkey-pubkey-hex-value="<%= current_user.nostr_pubkey %>"
|
||||
data-remote-signer="<%= active_nostr_signer_session.present? %>"
|
||||
data-nostr-remote-signer-available="<%= nostr_remote_signer_available? %>">
|
||||
<section class="mb-8 sm:mb-12">
|
||||
<h3>Nostr</h3>
|
||||
<h4 class="mb-0">
|
||||
@@ -85,6 +87,16 @@
|
||||
</button>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<% if nostr_remote_signer_available? %>
|
||||
<%= render NostrSignerConnectComponent.new(
|
||||
pending_session: @pending_signer_session,
|
||||
active_session: active_nostr_signer_session,
|
||||
create_url: nostr_signer_settings_path,
|
||||
destroy_url: nostr_signer_settings_path,
|
||||
status_url: @pending_signer_session ? nostr_signer_status_settings_path(token: @pending_signer_session.token) : nil
|
||||
) %>
|
||||
<% end %>
|
||||
</section>
|
||||
|
||||
<% if current_user.nostr_pubkey.present? %>
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<%= render HeaderCompactComponent.new(title: "Log in with a remote signer") %>
|
||||
|
||||
<%= render MainCompactComponent.new do %>
|
||||
<p class="mb-6 text-sm text-gray-600">
|
||||
Open your Nostr signer app and scan the QR code, or paste a bunker URI.
|
||||
Your private key stays in your signer.
|
||||
</p>
|
||||
|
||||
<%= render NostrSignerConnectComponent.new(
|
||||
pending_session: @signer_session,
|
||||
create_url: nostr_connect_path,
|
||||
status_url: nostr_connect_status_path,
|
||||
title: "Remote signer",
|
||||
show_disconnect: false
|
||||
) %>
|
||||
|
||||
<p class="mt-8 text-sm">
|
||||
<%= link_to "Back to login", new_user_session_path, class: "text-gray-500 underline" %>
|
||||
</p>
|
||||
<% end %>
|
||||
@@ -6,6 +6,9 @@ Rails.application.routes.draw do
|
||||
|
||||
devise_scope :user do
|
||||
post 'users/nostr_login', to: 'users/sessions#nostr_login'
|
||||
get 'users/nostr_connect', to: 'users/nostr_connects#show', as: :nostr_connect
|
||||
post 'users/nostr_connect', to: 'users/nostr_connects#create'
|
||||
get 'users/nostr_connect/status', to: 'users/nostr_connects#status', as: :nostr_connect_status
|
||||
end
|
||||
|
||||
get 'welcome', to: 'welcome#index'
|
||||
@@ -67,6 +70,11 @@ Rails.application.routes.draw do
|
||||
delete 'nostr_pubkey', to: 'settings#remove_nostr_pubkey'
|
||||
get 'fetch_nostr_metadata', as: 'nostr_metadata'
|
||||
post 'nostr_publish', to: 'settings/nostr_events#create', as: :nostr_publish
|
||||
post 'nostr_signer', to: 'settings/nostr_signers#create', as: :nostr_signer
|
||||
get 'nostr_signer/status', to: 'settings/nostr_signers#status', as: :nostr_signer_status
|
||||
delete 'nostr_signer', to: 'settings/nostr_signers#destroy'
|
||||
post 'nostr_sign', to: 'settings/nostr_signatures#create', as: :nostr_sign
|
||||
get 'nostr_sign/:token', to: 'settings/nostr_signatures#show', as: :nostr_sign_status
|
||||
post 'nostr_media', to: 'settings/nostr_media#create', as: :nostr_media
|
||||
post 'nostr_profile_images', to: 'settings/nostr_profile_images#create', as: :nostr_profile_images
|
||||
get 'nostr_profile_images/:field', to: 'settings/nostr_profile_images#show', as: :nostr_profile_image
|
||||
|
||||
@@ -18,6 +18,12 @@ RSpec.describe 'Nostr Settings', type: :feature do
|
||||
expect(page).to have_css('button[data-settings--nostr-pubkey-target=setPubkey]:disabled')
|
||||
end
|
||||
|
||||
scenario 'With a remote signer available' do
|
||||
visit setting_path(:nostr)
|
||||
expect(page).to have_button("Connect remote signer")
|
||||
expect(page).to have_content("Already have a bunker:// URI?")
|
||||
end
|
||||
|
||||
# scenario 'Successfully saving a key' do
|
||||
# Note: Needs a more complex JS testing setup (maybe poltergeist), not
|
||||
# worth it for now
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe "Settings::NostrSignatures", type: :request do
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
let(:user) { create :user, cn: "mark", ou: "kosmos.org" }
|
||||
let(:user_pubkey) { SecureRandom.hex(32) }
|
||||
let(:template) do
|
||||
{
|
||||
kind: 0,
|
||||
content: '{"name":"mark"}',
|
||||
tags: [],
|
||||
created_at: Time.current.to_i
|
||||
}
|
||||
end
|
||||
|
||||
before do
|
||||
login_as user, scope: :user
|
||||
Rails.cache.clear
|
||||
allow(Setting).to receive(:nostr_signer_relays).and_return(["wss://relay.example.com"])
|
||||
allow_any_instance_of(User).to receive(:nostr_pubkey).and_return(user_pubkey)
|
||||
end
|
||||
|
||||
def create_verified_session
|
||||
signer_session = NostrManager::RemoteSigner::CreateSession.call(flow: "settings", user: user)
|
||||
signer_session.complete_connection!(
|
||||
remote_signer_pubkey: SecureRandom.hex(32),
|
||||
user_pubkey: user_pubkey
|
||||
)
|
||||
signer_session
|
||||
end
|
||||
|
||||
describe "POST /settings/nostr_sign" do
|
||||
it "creates a signing request and enqueues the job" do
|
||||
create_verified_session
|
||||
|
||||
expect do
|
||||
post nostr_sign_settings_path, params: { event: template }, as: :json
|
||||
end.to change(NostrSignRequest, :count).by(1)
|
||||
.and have_enqueued_job(NostrSignEventJob)
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
data = JSON.parse(response.body)
|
||||
expect(data["token"]).to be_present
|
||||
expect(data["status"]).to eq("pending")
|
||||
end
|
||||
|
||||
it "rejects kinds that are not allowed" do
|
||||
create_verified_session
|
||||
|
||||
expect do
|
||||
post nostr_sign_settings_path, params: { event: template.merge(kind: 1) }, as: :json
|
||||
end.not_to change(NostrSignRequest, :count)
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(JSON.parse(response.body)["error"]).to include("not allowed")
|
||||
end
|
||||
|
||||
it "requires an active remote signer" do
|
||||
post nostr_sign_settings_path, params: { event: template }, as: :json
|
||||
|
||||
expect(response).to have_http_status(:forbidden)
|
||||
end
|
||||
|
||||
it "rejects stale events" do
|
||||
create_verified_session
|
||||
|
||||
post nostr_sign_settings_path,
|
||||
params: { event: template.merge(created_at: 1.hour.ago.to_i) },
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(JSON.parse(response.body)["error"]).to include("stale")
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /settings/nostr_sign/:token" do
|
||||
it "returns a signed event" do
|
||||
create_verified_session
|
||||
sign_request = NostrSignRequest.create!(
|
||||
user: user,
|
||||
kind: 0,
|
||||
template: template.stringify_keys,
|
||||
status: "signed",
|
||||
signed_event: { id: "abc", kind: 0 },
|
||||
expires_at: 1.minute.from_now
|
||||
)
|
||||
|
||||
get nostr_sign_status_settings_path(token: sign_request.token), as: :json
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(JSON.parse(response.body)["signed_event"]).to eq("id" => "abc", "kind" => 0)
|
||||
end
|
||||
|
||||
it "returns a failure" do
|
||||
create_verified_session
|
||||
sign_request = NostrSignRequest.create!(
|
||||
user: user,
|
||||
kind: 0,
|
||||
template: template.stringify_keys,
|
||||
status: "failed",
|
||||
error: "No response",
|
||||
expires_at: 1.minute.from_now
|
||||
)
|
||||
|
||||
get nostr_sign_status_settings_path(token: sign_request.token), as: :json
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(JSON.parse(response.body)["error"]).to eq("No response")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,123 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe "Settings::NostrSigners", type: :request do
|
||||
let(:user) { create :user, cn: "mark", ou: "kosmos.org" }
|
||||
let(:other_user) { create :user, id: 2, cn: "markymark", ou: "kosmos.org", email: "markymark@example.com" }
|
||||
let(:user_pubkey) { SecureRandom.hex(32) }
|
||||
|
||||
before do
|
||||
login_as user, scope: :user
|
||||
Rails.cache.clear
|
||||
allow(Setting).to receive(:nostr_signer_relays).and_return(["wss://relay.example.com"])
|
||||
allow_any_instance_of(User).to receive(:dn)
|
||||
.and_return("cn=#{user.cn},ou=kosmos.org,cn=users,dc=kosmos,dc=org")
|
||||
allow_any_instance_of(User).to receive(:nostr_pubkey).and_return(nil)
|
||||
end
|
||||
|
||||
describe "POST /settings/nostr_signer" do
|
||||
it "creates a pending nostrconnect session" do
|
||||
expect do
|
||||
post nostr_signer_settings_path, as: :json
|
||||
end.to change(NostrSignerSession, :count).by(1)
|
||||
.and have_enqueued_job(NostrConnectListenerJob)
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
data = JSON.parse(response.body)
|
||||
expect(data["token"]).to be_present
|
||||
expect(data["uri"]).to start_with("nostrconnect://")
|
||||
end
|
||||
|
||||
it "renders the QR code and status poll for a pending session" do
|
||||
post nostr_signer_settings_path, as: :json
|
||||
|
||||
get setting_path(:nostr)
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.body).to include("nostrconnect://")
|
||||
expect(response.body).to include("Waiting for your signer")
|
||||
end
|
||||
|
||||
it "creates a bunker session" do
|
||||
remote = SecureRandom.hex(32)
|
||||
allow(NostrManager::RelayUrlValidator).to receive(:strict_valid?).and_return(true)
|
||||
|
||||
post nostr_signer_settings_path,
|
||||
params: { bunker_uri: "bunker://#{remote}?relay=wss%3A%2F%2Frelay.example.com&secret=abc" },
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
session = NostrSignerSession.last
|
||||
expect(session).to be_bunker
|
||||
expect(session.remote_signer_pubkey).to eq(remote)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /settings/nostr_signer/status" do
|
||||
def create_verified_session
|
||||
session = NostrManager::RemoteSigner::CreateSession.call(flow: "settings", user: user)
|
||||
session.update!(
|
||||
status: "verified",
|
||||
user_pubkey: user_pubkey,
|
||||
remote_signer_pubkey: SecureRandom.hex(32)
|
||||
)
|
||||
session
|
||||
end
|
||||
|
||||
it "stores the verified pubkey in LDAP once" do
|
||||
session = create_verified_session
|
||||
allow(LdapManager::FetchUserByNostrKey).to receive(:call).with(pubkey: user_pubkey).and_return(nil)
|
||||
expect(LdapManager::UpdateNostrKey).to receive(:call).with(
|
||||
dn: "cn=mark,ou=kosmos.org,cn=users,dc=kosmos,dc=org",
|
||||
pubkey: user_pubkey
|
||||
).once
|
||||
|
||||
2.times { get nostr_signer_status_settings_path(token: session.token), as: :json }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(JSON.parse(response.body)["status"]).to eq("connected")
|
||||
expect(session.reload).to be_connected
|
||||
end
|
||||
|
||||
it "rejects a public key already linked to another account" do
|
||||
session = create_verified_session
|
||||
allow(LdapManager::FetchUserByNostrKey).to receive(:call).with(pubkey: user_pubkey).and_return(other_user)
|
||||
expect(LdapManager::UpdateNostrKey).not_to receive(:call)
|
||||
|
||||
get nostr_signer_status_settings_path(token: session.token), as: :json
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(JSON.parse(response.body)["error"]).to eq("Public key already in use for a different account")
|
||||
end
|
||||
|
||||
it "returns pending while waiting for the signer" do
|
||||
session = NostrManager::RemoteSigner::CreateSession.call(flow: "settings", user: user)
|
||||
|
||||
get nostr_signer_status_settings_path(token: session.token), as: :json
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(JSON.parse(response.body)["status"]).to eq("pending")
|
||||
end
|
||||
|
||||
it "returns a failure message" do
|
||||
session = NostrManager::RemoteSigner::CreateSession.call(flow: "settings", user: user)
|
||||
session.fail!("Your signer did not respond.")
|
||||
|
||||
get nostr_signer_status_settings_path(token: session.token), as: :json
|
||||
|
||||
expect(JSON.parse(response.body)["status"]).to eq("failed")
|
||||
expect(JSON.parse(response.body)["error"]).to eq("Your signer did not respond.")
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE /settings/nostr_signer" do
|
||||
it "removes all active sessions" do
|
||||
NostrManager::RemoteSigner::CreateSession.call(flow: "settings", user: user)
|
||||
|
||||
expect do
|
||||
delete nostr_signer_settings_path, as: :json
|
||||
end.to change(NostrSignerSession, :count).by(-1)
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,77 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe "Users::NostrConnects", type: :request do
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
let(:user) { create :user, cn: "mark", ou: "kosmos.org" }
|
||||
|
||||
before do
|
||||
Rails.cache.clear
|
||||
allow(Setting).to receive(:nostr_signer_relays).and_return(["wss://relay.example.com"])
|
||||
allow(Setting).to receive(:accounts_domain).and_return("accounts.example.com")
|
||||
end
|
||||
|
||||
describe "GET /users/nostr_connect" do
|
||||
it "creates a pending login session and renders the QR page" do
|
||||
expect do
|
||||
get nostr_connect_path
|
||||
end.to change(NostrSignerSession, :count).by(1)
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.body).to include("nostrconnect://")
|
||||
expect(NostrSignerSession.last.flow).to eq("login")
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /users/nostr_connect/status" do
|
||||
it "signs in the user linked to the verified pubkey" do
|
||||
get nostr_connect_path
|
||||
signer_session = NostrSignerSession.last
|
||||
signer_session.update!(
|
||||
status: "verified",
|
||||
user_pubkey: SecureRandom.hex(32),
|
||||
remote_signer_pubkey: SecureRandom.hex(32)
|
||||
)
|
||||
allow(LdapManager::FetchUserByNostrKey).to receive(:call)
|
||||
.with(pubkey: signer_session.user_pubkey)
|
||||
.and_return(user)
|
||||
|
||||
get nostr_connect_status_path, as: :json
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
data = JSON.parse(response.body)
|
||||
expect(data["status"]).to eq("connected")
|
||||
expect(data["redirect_url"]).to be_present
|
||||
expect(request.env["warden"].user).to eq(user)
|
||||
expect(signer_session.reload).to be_connected
|
||||
end
|
||||
|
||||
it "fails when the pubkey is not linked to an account" do
|
||||
get nostr_connect_path
|
||||
signer_session = NostrSignerSession.last
|
||||
signer_session.update!(status: "verified", user_pubkey: SecureRandom.hex(32))
|
||||
allow(LdapManager::FetchUserByNostrKey).to receive(:call).and_return(nil)
|
||||
|
||||
get nostr_connect_status_path, as: :json
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(JSON.parse(response.body)["status"]).to eq("failed")
|
||||
expect(signer_session.reload).to be_failed
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /users/nostr_connect with a bunker URI" do
|
||||
it "creates a bunker login session and redirects" do
|
||||
remote = SecureRandom.hex(32)
|
||||
allow(NostrManager::RelayUrlValidator).to receive(:strict_valid?).and_return(true)
|
||||
|
||||
post nostr_connect_path,
|
||||
params: { bunker_uri: "bunker://#{remote}?relay=wss%3A%2F%2Frelay.example.com" }
|
||||
|
||||
expect(response).to have_http_status(:redirect)
|
||||
signer_session = NostrSignerSession.last
|
||||
expect(signer_session).to be_bunker
|
||||
expect(signer_session.remote_signer_pubkey).to eq(remote)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user