Compare commits
3 Commits
v0.5.0
...
feature/ru
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d59f31a3c6
|
||
|
|
5497930dd5 | ||
|
|
c064a8d5f0 |
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.1/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed YARD example rendering issues in `InvalidKeyFormatError#initialize`, `InvalidKeyLengthError#initialize`,
|
||||
`InvalidKeyTypeError#initialize`, `Event#initialize`, `EncryptedDirectMessage#initialize` and `Filter#to_h`
|
||||
|
||||
## [0.5.0] 2023-11-20
|
||||
|
||||
### Added
|
||||
@@ -82,6 +89,7 @@ principles of immutability and was a major source of internal complexity as I ne
|
||||
|
||||
- Initial release
|
||||
|
||||
[unreleased]: https://github.com/wilsonsilva/nostr/compare/v0.5.0...HEAD
|
||||
[0.5.0]: https://github.com/wilsonsilva/nostr/compare/v0.4.0...v0.5.0
|
||||
[0.4.0]: https://github.com/wilsonsilva/nostr/compare/v0.3.0...v0.4.0
|
||||
[0.3.0]: https://github.com/wilsonsilva/nostr/compare/v0.2.0...v0.3.0
|
||||
|
||||
@@ -81,7 +81,7 @@ module Nostr
|
||||
# @return [Subscription] The subscription object
|
||||
#
|
||||
def subscribe(subscription_id: SecureRandom.hex, filter: Filter.new)
|
||||
subscriptions[subscription_id] = Subscription.new(id: subscription_id, filter:)
|
||||
subscriptions[subscription_id] = Subscription.new(id: subscription_id, filter: filter)
|
||||
parent_to_child_channel.push([ClientMessageType::REQ, subscription_id, filter.to_h].to_json)
|
||||
subscriptions[subscription_id]
|
||||
end
|
||||
|
||||
@@ -9,7 +9,7 @@ module Nostr
|
||||
# Initializes the error
|
||||
#
|
||||
# @example
|
||||
# InvalidKeyFormatError.new('private'')
|
||||
# InvalidKeyFormatError.new('private')
|
||||
#
|
||||
# @param [String] key_kind The kind of key that is invalid (public or private)
|
||||
#
|
||||
|
||||
@@ -9,7 +9,7 @@ module Nostr
|
||||
# Initializes the error
|
||||
#
|
||||
# @example
|
||||
# InvalidKeyLengthError.new('private'')
|
||||
# InvalidKeyLengthError.new('private')
|
||||
#
|
||||
# @param [String] key_kind The kind of key that is invalid (public or private)
|
||||
#
|
||||
|
||||
@@ -9,10 +9,12 @@ module Nostr
|
||||
# Initializes the error
|
||||
#
|
||||
# @example
|
||||
# InvalidKeyTypeError.new('private'')
|
||||
# InvalidKeyTypeError.new('private')
|
||||
#
|
||||
# @param [String] key_kind The kind of key that is invalid (public or private)
|
||||
#
|
||||
def initialize(key_kind) = super("Invalid #{key_kind} key type")
|
||||
def initialize(key_kind)
|
||||
super("Invalid #{key_kind} key type")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -100,15 +100,15 @@ module Nostr
|
||||
#
|
||||
# @example Instantiating a new event
|
||||
# Nostr::Event.new(
|
||||
# id: 'ccf9fdf3e1466d7c20969c71ec98defcf5f54aee088513e1b73ccb7bd770d460',
|
||||
# pubkey: '48df4af6e240ac5f7c5de89bf5941b249880be0e87d03685b178ccb1a315f52e',
|
||||
# created_at: 1230981305,
|
||||
# kind: 1,
|
||||
# tags: [],
|
||||
# content: 'Your feedback is appreciated, now pay $8',
|
||||
# sig: '123ac2923b792ce730b3da34f16155470ab13c8f97f9c53eaeb334f1fb3a5dc9a7f643
|
||||
# 937c6d6e9855477638f5655c5d89c9aa5501ea9b578a66aced4f1cd7b3'
|
||||
# )
|
||||
# id: 'ccf9fdf3e1466d7c20969c71ec98defcf5f54aee088513e1b73ccb7bd770d460',
|
||||
# pubkey: '48df4af6e240ac5f7c5de89bf5941b249880be0e87d03685b178ccb1a315f52e',
|
||||
# created_at: 1230981305,
|
||||
# kind: 1,
|
||||
# tags: [],
|
||||
# content: 'Your feedback is appreciated, now pay $8',
|
||||
# sig: '123ac2923b792ce730b3da34f16155470ab13c8f97f9c53eaeb334f1fb3a5dc9a7f643
|
||||
# 937c6d6e9855477638f5655c5d89c9aa5501ea9b578a66aced4f1cd7b3'
|
||||
# )
|
||||
#
|
||||
# @param id [String|nil] 32-bytes sha256 of the the serialized event data.
|
||||
# @param sig [String|nil] 64-bytes signature of the sha256 hash of the serialized event data, which is
|
||||
@@ -149,7 +149,9 @@ module Nostr
|
||||
#
|
||||
# @return [Array<String>] The event's updated list of tags
|
||||
#
|
||||
def add_event_reference(event_id) = tags.push(['e', event_id])
|
||||
def add_event_reference(event_id)
|
||||
tags.push(['e', event_id])
|
||||
end
|
||||
|
||||
# Adds a reference to a pubkey as a 'p' tag
|
||||
#
|
||||
@@ -163,7 +165,9 @@ module Nostr
|
||||
#
|
||||
# @return [Array<String>] The event's updated list of tags
|
||||
#
|
||||
def add_pubkey_reference(pubkey) = tags.push(['p', pubkey.to_s])
|
||||
def add_pubkey_reference(pubkey)
|
||||
tags.push(['p', pubkey.to_s])
|
||||
end
|
||||
|
||||
# Signs an event with the user's private key
|
||||
#
|
||||
@@ -212,13 +216,13 @@ module Nostr
|
||||
#
|
||||
def to_h
|
||||
{
|
||||
id:,
|
||||
pubkey:,
|
||||
created_at:,
|
||||
kind:,
|
||||
tags:,
|
||||
content:,
|
||||
sig:
|
||||
id: id,
|
||||
pubkey: pubkey,
|
||||
created_at: created_at,
|
||||
kind: kind,
|
||||
tags: tags,
|
||||
content: content,
|
||||
sig: sig
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ module Nostr
|
||||
# The content is set to the URL (e.g., wss://somerelay.com) of a relay the event creator wants to
|
||||
# recommend to its followers.
|
||||
#
|
||||
# @deprecated This event kind was removed in https://github.com/nostr-protocol/nips/pull/703/files#diff-39307f1617417657ee9874be314f13aabdc74401b124d0afe8217f2919c9c7d8L105
|
||||
# @return [Integer]
|
||||
#
|
||||
RECOMMEND_SERVER = 2
|
||||
|
||||
@@ -11,19 +11,19 @@ module Nostr
|
||||
# @api public
|
||||
#
|
||||
# @example Instantiating a new encrypted direct message
|
||||
# Nostr::Events::EncryptedDirectMessage.new(
|
||||
# Nostr::Events::EncryptedDirectMessage.new(
|
||||
# sender_private_key: 'ccf9fdf3e1466d7c20969c71ec98defcf5f54aee088513e1b73ccb7bd770d460',
|
||||
# recipient_public_key: '48df4af6e240ac5f7c5de89bf5941b249880be0e87d03685b178ccb1a315f52e',
|
||||
# plain_text: 'Your feedback is appreciated, now pay $8',
|
||||
# )
|
||||
# )
|
||||
#
|
||||
# @example Instantiating a new encrypted direct message that references a previous direct message
|
||||
# Nostr::Events::EncryptedDirectMessage.new(
|
||||
# Nostr::Events::EncryptedDirectMessage.new(
|
||||
# sender_private_key: 'ccf9fdf3e1466d7c20969c71ec98defcf5f54aee088513e1b73ccb7bd770d460',
|
||||
# recipient_public_key: '48df4af6e240ac5f7c5de89bf5941b249880be0e87d03685b178ccb1a315f52e',
|
||||
# plain_text: 'Your feedback is appreciated, now pay $8',
|
||||
# previous_direct_message: 'ccf9fdf3e1466d7c20969c71ec98defcf5f54aee088513e1b73ccb7bd770d460'
|
||||
# )
|
||||
# )
|
||||
#
|
||||
# @param plain_text [String] The +content+ of the encrypted message.
|
||||
# @param sender_private_key [PrivateKey] 32-bytes hex-encoded private key of the message's author.
|
||||
|
||||
@@ -133,26 +133,29 @@ module Nostr
|
||||
# @api public
|
||||
#
|
||||
# @example
|
||||
# filter.to_h # => {:ids=>["c24881c305c5cfb7c1168be7e9b0e150"],
|
||||
# :authors=>["000000001c5c45196786e79f83d21fe801549fdc98e2c26f96dcef068a5dbcd7"],
|
||||
# :kinds=>[0, 1, 2],
|
||||
# :"#e"=>["7bdb422f254194ae4bb86d354c0bd5a888fce233ffc77dceb3e844ceec1fcfb2"],
|
||||
# :"#p"=>["000000001c5c45196786e79f83d21fe801549fdc98e2c26f96dcef068a5dbcd7"],
|
||||
# :since=>1230981305,
|
||||
# :until=>1292190341}
|
||||
# filter.to_h # =>
|
||||
# {
|
||||
# ids: ['c24881c305c5cfb7c1168be7e9b0e150'],
|
||||
# authors: ['000000001c5c45196786e79f83d21fe801549fdc98e2c26f96dcef068a5dbcd7'],
|
||||
# kinds: [0, 1, 2],
|
||||
# '#e': ['7bdb422f254194ae4bb86d354c0bd5a888fce233ffc77dceb3e844ceec1fcfb2'],
|
||||
# '#p': ['000000001c5c45196786e79f83d21fe801549fdc98e2c26f96dcef068a5dbcd7'],
|
||||
# since: 1230981305,
|
||||
# until: 1292190341
|
||||
# }
|
||||
#
|
||||
# @return [Hash] The filter as a hash.
|
||||
#
|
||||
def to_h
|
||||
{
|
||||
ids:,
|
||||
authors:,
|
||||
kinds:,
|
||||
ids: ids,
|
||||
authors: authors,
|
||||
kinds: kinds,
|
||||
'#e': e,
|
||||
'#p': p,
|
||||
since:,
|
||||
since: since,
|
||||
until: self.until,
|
||||
limit:
|
||||
limit: limit
|
||||
}.compact
|
||||
end
|
||||
|
||||
|
||||
@@ -79,7 +79,9 @@ module Nostr
|
||||
#
|
||||
# @return [String] The bech32 string representation of the key
|
||||
#
|
||||
def to_bech32 = Bech32.encode(hrp: self.class.hrp, data: self)
|
||||
def to_bech32
|
||||
Bech32.encode(hrp: self.class.hrp, data: self)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ module Nostr
|
||||
private_key = generate_private_key
|
||||
public_key = extract_public_key(private_key)
|
||||
|
||||
KeyPair.new(private_key:, public_key:)
|
||||
KeyPair.new(private_key: private_key, public_key: public_key)
|
||||
end
|
||||
|
||||
# Generates a private key
|
||||
@@ -89,7 +89,7 @@ module Nostr
|
||||
def get_key_pair_from_private_key(private_key)
|
||||
validate_private_key(private_key)
|
||||
public_key = extract_public_key(private_key)
|
||||
KeyPair.new(private_key:, public_key:)
|
||||
KeyPair.new(private_key: private_key, public_key: public_key)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -62,10 +62,10 @@ module Nostr
|
||||
)
|
||||
event = Event.new(
|
||||
pubkey: keypair.public_key,
|
||||
kind:,
|
||||
content:,
|
||||
created_at:,
|
||||
tags:
|
||||
kind: kind,
|
||||
content: content,
|
||||
created_at: created_at,
|
||||
tags: tags
|
||||
)
|
||||
event.sign(keypair.private_key)
|
||||
end
|
||||
|
||||
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
||||
spec.description = 'Client and relay implementation of the Nostr protocol.'
|
||||
spec.homepage = 'https://nostr-ruby.com/'
|
||||
spec.license = 'MIT'
|
||||
spec.required_ruby_version = '>= 3.2.0'
|
||||
spec.required_ruby_version = '>= 2.7.2'
|
||||
spec.metadata['rubygems_mfa_required'] = 'true'
|
||||
|
||||
spec.metadata['homepage_uri'] = spec.homepage
|
||||
|
||||
Reference in New Issue
Block a user