nostr 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +36 -0
- data/README.md +123 -16
- data/Steepfile +16 -0
- data/lib/nostr/crypto.rb +143 -0
- data/lib/nostr/event.rb +157 -11
- data/lib/nostr/event_kind.rb +15 -0
- data/lib/nostr/events/encrypted_direct_message.rb +53 -0
- data/lib/nostr/keygen.rb +1 -1
- data/lib/nostr/user.rb +3 -31
- data/lib/nostr/version.rb +1 -1
- data/lib/nostr.rb +2 -1
- data/nostr.gemspec +3 -0
- data/sig/nostr/client.rbs +20 -0
- data/sig/nostr/client_message_type.rbs +7 -0
- data/sig/nostr/crypto.rbs +16 -0
- data/sig/nostr/event.rbs +39 -0
- data/sig/nostr/event_kind.rbs +9 -0
- data/sig/nostr/events/encrypted_direct_message.rbs +12 -0
- data/sig/nostr/filter.rbs +25 -0
- data/sig/nostr/key_pair.rbs +9 -0
- data/sig/nostr/keygen.rbs +13 -0
- data/sig/nostr/relay.rbs +9 -0
- data/sig/nostr/subscription.rbs +9 -0
- data/sig/nostr/user.rbs +22 -0
- data/sig/vendor/ecsda/group/secp256k1.rbs +6 -0
- data/sig/vendor/event_emitter.rbs +9 -0
- data/sig/vendor/event_machine/channel.rbs +18 -0
- data/sig/vendor/event_machine.rbs +69 -0
- data/sig/vendor/schnorr.rbs +4 -0
- metadata +65 -4
- data/lib/nostr/event_fragment.rb +0 -111
data/lib/nostr/event_fragment.rb
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Nostr
|
4
|
-
# Part of an +Event+. A complete +Event+ must have an +id+ and a +sig+.
|
5
|
-
class EventFragment
|
6
|
-
# 32-bytes hex-encoded public key of the event creator
|
7
|
-
#
|
8
|
-
# @api public
|
9
|
-
#
|
10
|
-
# @example
|
11
|
-
# event.pubkey # => '48df4af6e240ac5f7c5de89bf5941b249880be0e87d03685b178ccb1a315f52e'
|
12
|
-
#
|
13
|
-
# @return [String]
|
14
|
-
#
|
15
|
-
attr_reader :pubkey
|
16
|
-
|
17
|
-
# Date of the creation of the vent. A UNIX timestamp, in seconds
|
18
|
-
#
|
19
|
-
# @api public
|
20
|
-
#
|
21
|
-
# @example
|
22
|
-
# event.created_at # => 1230981305
|
23
|
-
#
|
24
|
-
# @return [Integer]
|
25
|
-
#
|
26
|
-
attr_reader :created_at
|
27
|
-
|
28
|
-
# The kind of the event. An integer from 0 to 2
|
29
|
-
#
|
30
|
-
# @api public
|
31
|
-
#
|
32
|
-
# @example
|
33
|
-
# event.kind # => 1
|
34
|
-
#
|
35
|
-
# @return [Integer]
|
36
|
-
#
|
37
|
-
attr_reader :kind
|
38
|
-
|
39
|
-
# An array of tags. Each tag is an array of strings
|
40
|
-
#
|
41
|
-
# @api public
|
42
|
-
#
|
43
|
-
# @example Tags referencing an event
|
44
|
-
# event.tags #=> [["e", "event_id", "relay URL"]]
|
45
|
-
#
|
46
|
-
# @example Tags referencing a key
|
47
|
-
# event.tags #=> [["p", "event_id", "relay URL"]]
|
48
|
-
#
|
49
|
-
# @return [Array<Array>]
|
50
|
-
#
|
51
|
-
attr_reader :tags
|
52
|
-
|
53
|
-
# An arbitrary string
|
54
|
-
#
|
55
|
-
# @api public
|
56
|
-
#
|
57
|
-
# @example
|
58
|
-
# event.content # => 'Your feedback is appreciated, now pay $8'
|
59
|
-
#
|
60
|
-
# @return [String]
|
61
|
-
#
|
62
|
-
attr_reader :content
|
63
|
-
|
64
|
-
# Instantiates a new EventFragment
|
65
|
-
#
|
66
|
-
# @api public
|
67
|
-
#
|
68
|
-
# @example
|
69
|
-
# Nostr::EventFragment.new(
|
70
|
-
# pubkey: 'ccf9fdf3e1466d7c20969c71ec98defcf5f54aee088513e1b73ccb7bd770d460',
|
71
|
-
# created_at: 1230981305,
|
72
|
-
# kind: 1,
|
73
|
-
# tags: [['e', '189df012cfff8a075785b884bd702025f4a7a37710f581c4ac9d33e24b585408']],
|
74
|
-
# content: 'Your feedback is appreciated, now pay $8'
|
75
|
-
# )
|
76
|
-
#
|
77
|
-
# @param pubkey [String] 32-bytes hex-encoded public key of the event creator.
|
78
|
-
# @param created_at [Integer] Date of the creation of the vent. A UNIX timestamp, in seconds.
|
79
|
-
# @param kind [Integer] The kind of the event. An integer from 0 to 2.
|
80
|
-
# @param tags [Array<Array>] An array of tags. Each tag is an array of strings.
|
81
|
-
# @param content [String] Arbitrary string.
|
82
|
-
#
|
83
|
-
def initialize(pubkey:, kind:, content:, created_at: Time.now.to_i, tags: [])
|
84
|
-
@pubkey = pubkey
|
85
|
-
@created_at = created_at
|
86
|
-
@kind = kind
|
87
|
-
@tags = tags
|
88
|
-
@content = content
|
89
|
-
end
|
90
|
-
|
91
|
-
# Serializes the event fragment, to obtain a SHA256 hash of it
|
92
|
-
#
|
93
|
-
# @api public
|
94
|
-
#
|
95
|
-
# @example Converting the event to a hash
|
96
|
-
# event_fragment.serialize
|
97
|
-
#
|
98
|
-
# @return [Array] The event fragment as an array.
|
99
|
-
#
|
100
|
-
def serialize
|
101
|
-
[
|
102
|
-
0,
|
103
|
-
pubkey,
|
104
|
-
created_at,
|
105
|
-
kind,
|
106
|
-
tags,
|
107
|
-
content
|
108
|
-
]
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|