Settings page for adding verified nostr pubkeys
This commit is contained in:
11
app/services/nostr_manager/validate_id.rb
Normal file
11
app/services/nostr_manager/validate_id.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
module NostrManager
|
||||
class ValidateId < NostrManagerService
|
||||
def initialize(event)
|
||||
@event = Nostr::Event.new(**event)
|
||||
end
|
||||
|
||||
def call
|
||||
@event.id == Digest::SHA256.hexdigest(JSON.generate(@event.serialize))
|
||||
end
|
||||
end
|
||||
end
|
||||
17
app/services/nostr_manager/verify_signature.rb
Normal file
17
app/services/nostr_manager/verify_signature.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
module NostrManager
|
||||
class VerifySignature < NostrManagerService
|
||||
def initialize(event)
|
||||
@event = Nostr::Event.new(**event)
|
||||
end
|
||||
|
||||
def call
|
||||
Schnorr.check_sig!(
|
||||
[@event.id].pack('H*'),
|
||||
[@event.pubkey].pack('H*'),
|
||||
[@event.sig].pack('H*')
|
||||
)
|
||||
rescue Schnorr::InvalidSignatureError
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
4
app/services/nostr_manager_service.rb
Normal file
4
app/services/nostr_manager_service.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
require "nostr"
|
||||
|
||||
class NostrManagerService < ApplicationService
|
||||
end
|
||||
Reference in New Issue
Block a user