Send app name, URL, and icon in NIP-46 client metadata

This commit is contained in:
raucao committed 2026-11-27 16:07:32 +04:00
1 parent 8aa302da03
commit 39fd823003
8 files changed
+86 -8

No files matched your search

@@ -35,6 +35,14 @@ module Settings
wss://nostr.kosmos.org
]
field :nostr_client_icon_url, type: :string,
default: "https://assets.kosmos.org/img/app-icon-256px.png",
validates: { format: {
with: %r{\Ahttps?://.+},
allow_blank: true,
message: "must be an http:// or https:// URL"
} }
field :nostr_zaps_relay_limit, type: :integer,
default: 12
+5 -3
View File
@@ -149,11 +149,13 @@ class NostrSignerSession < ApplicationRecord
end
def nostrconnect_uri
domain = Setting.accounts_domain.to_s
params = relays.map { |relay| ["relay", relay] }
params << ["secret", secret] if secret.present?
params << ["name", domain] if domain.present?
params << ["url", "https://#{domain}"] if domain.present?
NostrManager::RemoteSigner.client_metadata.each do |key, value|
params << [key.to_s, value] if value.present?
end
params << ["perms", NostrManager::RemoteSigner::PERMS]
"nostrconnect://#{client_public_key}?#{URI.encode_www_form(params)}"
@@ -3,6 +3,7 @@ module NostrManager
KIND = 24133
AUTH_KIND = 22242
ALLOWED_SIGN_KINDS = [0, 10002, 10063, 24242].freeze
CLIENT_NAME = "Kosmos Accounts"
PERMS = %w[
sign_event:0
sign_event:10002
@@ -11,6 +12,17 @@ module NostrManager
sign_event:24242
].join(",")
def self.client_metadata
domain = Setting.accounts_domain.to_s.chomp("/")
return {} if domain.blank?
{
name: CLIENT_NAME,
url: "https://#{domain}",
image: Setting.nostr_client_icon_url.presence
}.compact
end
class Error < StandardError; end
class RequestError < Error; end
class UnsupportedTransportError < Error; end
@@ -86,10 +86,7 @@ module NostrManager
end
def client_metadata
domain = Setting.accounts_domain.to_s
metadata = { name: domain } if domain.present?
metadata[:url] = "https://#{domain}" if domain.present?
metadata || {}
NostrManager::RemoteSigner.client_metadata
end
def verify_auth_event!(event, user_pubkey)
@@ -73,6 +73,11 @@
value: Setting.nostr_signer_relays.join("\n"),
class: "h-32 w-80" %>
<% end %>
<%= render FormElements::FieldsetResettableSettingComponent.new(
key: :nostr_client_icon_url,
title: "Client icon URL",
description: "Small square image shown in remote signer connection prompts"
) %>
</ul>
</section>
<% end %>
+8 -1
View File
@@ -48,7 +48,11 @@ RSpec.describe NostrSignerSession, type: :model do
expect(found.token).to eq(session.token)
end
it "builds a nostrconnect URI with relays and permissions" do
it "builds a nostrconnect URI with relays, permissions, and client metadata" do
allow(Setting).to receive(:accounts_domain).and_return("accounts.example.com")
allow(Setting).to receive(:nostr_client_icon_url)
.and_return("https://assets.example.com/icon.png")
session = build_session
session.save!
@@ -59,6 +63,9 @@ RSpec.describe NostrSignerSession, type: :model do
expect(uri.host).to eq(keypair.public_key.to_s)
expect(params["relay"]).to eq("wss://relay.example.com")
expect(params["secret"]).to eq("connection-secret")
expect(params["name"]).to eq("Kosmos Accounts")
expect(params["url"]).to eq("https://accounts.example.com")
expect(params["image"]).to eq("https://assets.example.com/icon.png")
expect(params["perms"]).to include("sign_event:0")
end
@@ -10,6 +10,8 @@ RSpec.describe NostrManager::RemoteSigner::ListenForConnection, type: :model do
before do
allow(Setting).to receive(:nostr_signer_relays).and_return(["wss://relay.example.com"])
allow(Setting).to receive(:accounts_domain).and_return(domain)
allow(Setting).to receive(:nostr_client_icon_url)
.and_return("https://assets.example.com/icon.png")
end
def stub_pool(pool)
@@ -35,6 +37,17 @@ RSpec.describe NostrManager::RemoteSigner::ListenForConnection, type: :model do
)
end
it "uses the shared client metadata" do
session = build_session
service = described_class.new(session: session)
expect(service.send(:client_metadata)).to eq(
name: "Kosmos Accounts",
url: "https://accounts.example.com",
image: "https://assets.example.com/icon.png"
)
end
it "verifies a client-initiated connection" do
session = build_session
pool = build_pool(session)
@@ -0,0 +1,34 @@
require "rails_helper"
RSpec.describe NostrManager::RemoteSigner, type: :model do
describe ".client_metadata" do
before do
allow(Setting).to receive(:accounts_domain).and_return("accounts.example.com")
allow(Setting).to receive(:nostr_client_icon_url)
.and_return("https://assets.example.com/icon.png")
end
it "returns the app name, URL, and icon" do
expect(described_class.client_metadata).to eq(
name: "Kosmos Accounts",
url: "https://accounts.example.com",
image: "https://assets.example.com/icon.png"
)
end
it "omits a blank icon" do
allow(Setting).to receive(:nostr_client_icon_url).and_return(nil)
expect(described_class.client_metadata).to eq(
name: "Kosmos Accounts",
url: "https://accounts.example.com"
)
end
it "returns nothing without an accounts domain" do
allow(Setting).to receive(:accounts_domain).and_return(nil)
expect(described_class.client_metadata).to eq({})
end
end
end