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:
@@ -7,6 +7,9 @@ module Nostr
|
||||
def encrypt_text: (PrivateKey, PublicKey, String) -> String
|
||||
def decrypt_text: (PrivateKey, PublicKey, String) -> String
|
||||
def sign_event: (Event, PrivateKey) -> Event
|
||||
def sign_message: (String, PrivateKey) -> Signature
|
||||
def valid_sig?: (String, PublicKey, Signature) -> bool
|
||||
def check_sig!: (String, PublicKey, Signature) -> bool
|
||||
|
||||
private
|
||||
|
||||
|
||||
5
sig/nostr/errors/invalid_signature_format_error.rbs
Normal file
5
sig/nostr/errors/invalid_signature_format_error.rbs
Normal file
@@ -0,0 +1,5 @@
|
||||
module Nostr
|
||||
class InvalidSignatureFormatError < SignatureValidationError
|
||||
def initialize: -> void
|
||||
end
|
||||
end
|
||||
5
sig/nostr/errors/invalid_signature_length_error.rbs
Normal file
5
sig/nostr/errors/invalid_signature_length_error.rbs
Normal file
@@ -0,0 +1,5 @@
|
||||
module Nostr
|
||||
class InvalidSignatureLengthError < SignatureValidationError
|
||||
def initialize: -> void
|
||||
end
|
||||
end
|
||||
5
sig/nostr/errors/invalid_signature_type_error.rbs
Normal file
5
sig/nostr/errors/invalid_signature_type_error.rbs
Normal file
@@ -0,0 +1,5 @@
|
||||
module Nostr
|
||||
class InvalidSignatureTypeError < SignatureValidationError
|
||||
def initialize: -> void
|
||||
end
|
||||
end
|
||||
4
sig/nostr/errors/signature_validation_error.rbs
Normal file
4
sig/nostr/errors/signature_validation_error.rbs
Normal file
@@ -0,0 +1,4 @@
|
||||
module Nostr
|
||||
class SignatureValidationError < Error
|
||||
end
|
||||
end
|
||||
@@ -6,7 +6,7 @@ module Nostr
|
||||
attr_reader tags: Array[Array[String]]
|
||||
attr_reader content: String
|
||||
attr_accessor id: String?|nil
|
||||
attr_accessor sig: String?|nil
|
||||
attr_accessor sig: Signature?
|
||||
|
||||
def initialize: (
|
||||
pubkey: PublicKey,
|
||||
@@ -15,7 +15,7 @@ module Nostr
|
||||
?created_at: Integer,
|
||||
?tags: Array[Array[String]],
|
||||
?id: String|nil,
|
||||
?sig: String|nil
|
||||
?sig: Signature?
|
||||
) -> void
|
||||
|
||||
def serialize: -> [Integer, String, Integer, Integer, Array[Array[String]], String]
|
||||
@@ -32,6 +32,7 @@ module Nostr
|
||||
def ==: (Event other) -> bool
|
||||
|
||||
def sign:(PrivateKey) -> Event
|
||||
def verify_signature: -> bool
|
||||
|
||||
def add_event_reference: (String) -> Array[Array[String]]
|
||||
def add_pubkey_reference: (PublicKey) -> Array[Array[String]]
|
||||
|
||||
14
sig/nostr/signature.rbs
Normal file
14
sig/nostr/signature.rbs
Normal file
@@ -0,0 +1,14 @@
|
||||
module Nostr
|
||||
class Signature < String
|
||||
FORMAT: Regexp
|
||||
LENGTH: int
|
||||
|
||||
def initialize: (String) -> void
|
||||
|
||||
private
|
||||
|
||||
attr_reader hex_value: String
|
||||
|
||||
def validate: (String) -> nil
|
||||
end
|
||||
end
|
||||
4
sig/vendor/schnorr.rbs
vendored
4
sig/vendor/schnorr.rbs
vendored
@@ -1,4 +1,6 @@
|
||||
# Added only to satisfy the Steep requirements. Not 100% reliable.
|
||||
module Schnorr
|
||||
def self.sign: (String message, String private_key, ?String aux_rand) -> untyped
|
||||
def self.sign: (String message, String private_key, ?String aux_rand) -> Signature
|
||||
def self.valid_sig?: (String message, String public_key, String signature) -> bool
|
||||
def self.check_sig!: (String message, String public_key, String signature) -> bool
|
||||
end
|
||||
|
||||
16
sig/vendor/schnorr/signature.rbs
vendored
Normal file
16
sig/vendor/schnorr/signature.rbs
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
# Added only to satisfy the Steep requirements. Not 100% reliable.
|
||||
module Schnorr
|
||||
class InvalidSignatureError < StandardError
|
||||
end
|
||||
|
||||
class Signature
|
||||
attr_reader r: Integer
|
||||
attr_reader s: Integer
|
||||
|
||||
def self.decode: (String string) -> Signature
|
||||
|
||||
def initialize: (Integer r, Integer s) -> void
|
||||
def encode: -> String
|
||||
def ==: (untyped other) -> bool
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user