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:
Wilson Silva
2024-03-14 22:03:26 +00:00
parent f8893f9b0e
commit 01010c763f
25 changed files with 637 additions and 47 deletions

View File

@@ -0,0 +1,13 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Nostr::InvalidSignatureFormatError do
describe '#initialize' do
let(:error) { described_class.new }
it 'builds a useful error message' do
expect(error.message).to eq('Only lowercase hexadecimal characters are allowed in signatures.')
end
end
end

View File

@@ -0,0 +1,13 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Nostr::InvalidSignatureLengthError do
describe '#initialize' do
let(:error) { described_class.new }
it 'builds a useful error message' do
expect(error.message).to eq('Invalid signature length. It should have 128 characters.')
end
end
end

View File

@@ -0,0 +1,13 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Nostr::InvalidSignatureTypeError do
describe '#initialize' do
let(:error) { described_class.new }
it 'builds a useful error message' do
expect(error.message).to eq('Invalid signature type')
end
end
end