Skip to content

Commit

Permalink
Backup
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonsilva committed Nov 14, 2023
1 parent be4c3e0 commit 22ecebe
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/nostr/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,19 @@ def sign(private_key)
crypto.sign_event(self, private_key)
end

# Whether the event is signed or not
#
# @api public
#
# @example
# event.signed? # => true
#
# @return [Boolean] +true+ if the event is signed and +false+ otherwise
#
def signed?
!sig.nil?
end

# Serializes the event, to obtain a SHA256 digest of it
#
# @api public
Expand Down
2 changes: 2 additions & 0 deletions sig/nostr/event.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ module Nostr

def serialize: -> [Integer, String, Integer, Integer, Array[Array[String]], String]

def signed?: -> bool

def to_h: -> {
id: String?|nil,
pubkey: String,
Expand Down
34 changes: 34 additions & 0 deletions spec/nostr/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,40 @@
end
end

describe '#signed?' do
context 'when the event has a signature' do
let(:event) do
described_class.new(
id: '20f31a9b2a0ced48a167add9732ccade1dca5e34b44316e37da4af33bc8946a9',
pubkey: 'ccf9fdf3e1466d7c20969c71ec98defcf5f54aee088513e1b73ccb7bd770d460',
created_at: 1_230_981_305,
kind: 1,
tags: [],
content: 'Your feedback is appreciated, now pay $8',
sig: '058613f8d34c053294cc28b7f9e1f8f0e80fd1ac94fb20f2da6ca514e7360b39' \
'63d0086171f842ffebf1f7790ce147b4811a15ef3f59c76ec1324b970cc57ffe'
)
end

specify { expect(event).to be_signed }
end

context 'when the event does not have a signature' do
let(:event) do
described_class.new(
id: '20f31a9b2a0ced48a167add9732ccade1dca5e34b44316e37da4af33bc8946a9',
pubkey: 'ccf9fdf3e1466d7c20969c71ec98defcf5f54aee088513e1b73ccb7bd770d460',
created_at: 1_230_981_305,
kind: 1,
tags: [],
content: 'Your feedback is appreciated, now pay $8',
)
end

specify { expect(event).not_to be_signed }
end
end

describe '#tags' do
it 'exposes the event tags' do
expect(event.tags).to eq(
Expand Down

0 comments on commit 22ecebe

Please sign in to comment.