Class: Nostrb::Source
- Inherits:
-
Object
- Object
- Nostrb::Source
- Defined in:
- lib/nostrb/source.rb
Overview
A Source holds a public key and creates Events.
Instance Attribute Summary collapse
-
#pk ⇒ Object
readonly
Returns the value of attribute pk.
Class Method Summary collapse
- .close(sid) ⇒ Object
-
.publish(signed) ⇒ Object
Client Requests.
-
.random_sid ⇒ Object
Utils / Init.
- .subscribe(sid, *filters) ⇒ Object
Instance Method Summary collapse
-
#deletion_request(explanation, *event_ids) ⇒ Object
(also: #delete)
NIP-09 Input explanation: content string *event_ids: array of event ids, hex format Output Event content: explanation kind: 5, deletion request tags: [[‘e’, event_id]] TODO: support deletion of replaceable events (‘a’ tags).
-
#event(content, kind) ⇒ Object
Event Creation.
-
#follow_list(pubkey_hsh) ⇒ Object
(also: #follows)
NIP-02 Input pubkey_hsh: a ruby hash of the form: pubkey => [relay_url, petname] “deadbeef1234abcdef” => [“wss://alicerelay.com/”, “alice”] Output Event content: “” kind: 3, follow list tags: [[‘p’, pubkey, relay_url, petname]].
-
#initialize(pk) ⇒ Source
constructor
A new instance of Source.
- #pubkey ⇒ Object
-
#text_note(content) ⇒ Object
NIP-01 Input content: string Output Event content: <content> kind: 1.
-
#user_metadata(name:, about:, picture:, **kwargs) ⇒ Object
(also: #profile)
NIP-01 Input name: string about: string picture: string, URL Output Event content: “name”:<username>,“about”:<string>,“picture”:<url> kind: 0, user metadata.
Constructor Details
Instance Attribute Details
#pk ⇒ Object (readonly)
Returns the value of attribute pk.
31 32 33 |
# File 'lib/nostrb/source.rb', line 31 def pk @pk end |
Class Method Details
.close(sid) ⇒ Object
22 |
# File 'lib/nostrb/source.rb', line 22 def self.close(sid) = ["CLOSE", Nostrb.sid!(sid)].freeze |
.publish(signed) ⇒ Object
Client Requests
14 |
# File 'lib/nostrb/source.rb', line 14 def self.publish(signed) = ["EVENT", signed.to_h].freeze |
.random_sid ⇒ Object
Utils / Init
27 28 29 |
# File 'lib/nostrb/source.rb', line 27 def self.random_sid SchnorrSig.bin2hex(Random.bytes(32)).freeze end |
Instance Method Details
#deletion_request(explanation, *event_ids) ⇒ Object Also known as: delete
NIP-09 Input
explanation: content string
*event_ids: array of event ids, hex format
Output
Event
content: explanation
kind: 5, deletion request
tags: [['e', event_id]]
TODO: support deletion of replaceable events (‘a’ tags)
104 105 106 107 108 |
# File 'lib/nostrb/source.rb', line 104 def deletion_request(explanation, *event_ids) e = event(explanation, 5) event_ids.each { |eid| e.ref_event(eid) } e end |
#event(content, kind) ⇒ Object
Event Creation
42 43 44 |
# File 'lib/nostrb/source.rb', line 42 def event(content, kind) Event.new(content, kind: kind, pk: @pk) end |
#follow_list(pubkey_hsh) ⇒ Object Also known as: follows
NIP-02 Input
pubkey_hsh: a ruby hash of the form: pubkey => [relay_url, petname]
"deadbeef1234abcdef" => ["wss://alicerelay.com/", "alice"]
Output
Event
content: ""
kind: 3, follow list
tags: [['p', pubkey, relay_url, petname]]
83 84 85 86 87 88 89 90 91 |
# File 'lib/nostrb/source.rb', line 83 def follow_list(pubkey_hsh) list = event('', 3) pubkey_hsh.each { |pubkey, (url, name)| list.ref_pubkey(Nostrb.pubkey!(pubkey), Nostrb.txt!(url), Nostrb.txt!(name)) } list end |
#pubkey ⇒ Object
37 |
# File 'lib/nostrb/source.rb', line 37 def pubkey = SchnorrSig.bin2hex(@pk).freeze |
#text_note(content) ⇒ Object
NIP-01 Input
content: string
Output
Event
content: <content>
kind: 1
53 54 55 |
# File 'lib/nostrb/source.rb', line 53 def text_note(content) event(content, 1) end |
#user_metadata(name:, about:, picture:, **kwargs) ⇒ Object Also known as: profile
NIP-01 Input
name: string
about: string
picture: string, URL
Output
Event
content: {"name":<username>,"about":<string>,"picture":<url>}
kind: 0, user metadata
66 67 68 69 70 71 |
# File 'lib/nostrb/source.rb', line 66 def (name:, about:, picture:, **kwargs) full = kwargs.merge(name: Nostrb.txt!(name), about: Nostrb.txt!(about), picture: Nostrb.txt!(picture)) event(Nostrb.json(full), 0) end |