Allow the verification of signatures and events
Added the methods: - Event#verify_signature - Crypto#check_sig! - Crypto#valid_sig? - Crypto#sign_message Fixed a primitive obsession by introducing a Signature class to ensure that signatures are valid Nostr signatures.
This commit is contained in:
18
lib/nostr/errors/invalid_signature_format_error.rb
Normal file
18
lib/nostr/errors/invalid_signature_format_error.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Nostr
|
||||
# Raised when the signature is in an invalid format
|
||||
#
|
||||
# @api public
|
||||
#
|
||||
class InvalidSignatureFormatError < SignatureValidationError
|
||||
# Initializes the error
|
||||
#
|
||||
# @example
|
||||
# InvalidSignatureFormatError.new
|
||||
#
|
||||
def initialize
|
||||
super('Only lowercase hexadecimal characters are allowed in signatures.')
|
||||
end
|
||||
end
|
||||
end
|
||||
18
lib/nostr/errors/invalid_signature_length_error.rb
Normal file
18
lib/nostr/errors/invalid_signature_length_error.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Nostr
|
||||
# Raised when the signature's length is not 128 characters
|
||||
#
|
||||
# @api public
|
||||
#
|
||||
class InvalidSignatureLengthError < SignatureValidationError
|
||||
# Initializes the error
|
||||
#
|
||||
# @example
|
||||
# InvalidSignatureLengthError.new
|
||||
#
|
||||
def initialize
|
||||
super('Invalid signature length. It should have 128 characters.')
|
||||
end
|
||||
end
|
||||
end
|
||||
16
lib/nostr/errors/invalid_signature_type_error.rb
Normal file
16
lib/nostr/errors/invalid_signature_type_error.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Nostr
|
||||
# Raised when the signature is not a string
|
||||
#
|
||||
# @api public
|
||||
#
|
||||
class InvalidSignatureTypeError < SignatureValidationError
|
||||
# Initializes the error
|
||||
#
|
||||
# @example
|
||||
# InvalidSignatureTypeError.new
|
||||
#
|
||||
def initialize = super('Invalid signature type')
|
||||
end
|
||||
end
|
||||
6
lib/nostr/errors/signature_validation_error.rb
Normal file
6
lib/nostr/errors/signature_validation_error.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Nostr
|
||||
# Base class for all signature validation errors
|
||||
class SignatureValidationError < Error; end
|
||||
end
|
||||
Reference in New Issue
Block a user