nostrb 0.1.0.1
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 +7 -0
- data/Rakefile +24 -0
- data/VERSION +1 -0
- data/lib/nostrb/event.rb +154 -0
- data/lib/nostrb/filter.rb +144 -0
- data/lib/nostrb/json.rb +19 -0
- data/lib/nostrb/names.rb +71 -0
- data/lib/nostrb/oj.rb +6 -0
- data/lib/nostrb/relay.rb +142 -0
- data/lib/nostrb/sequel.rb +222 -0
- data/lib/nostrb/source.rb +111 -0
- data/lib/nostrb/sqlite.rb +441 -0
- data/lib/nostrb.rb +111 -0
- data/nostrb.gemspec +18 -0
- data/test/common.rb +25 -0
- data/test/event.rb +193 -0
- data/test/nostrb.rb +87 -0
- data/test/relay.rb +360 -0
- data/test/source.rb +136 -0
- metadata +74 -0
data/test/source.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'nostrb/source'
|
2
|
+
require_relative 'common'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
include Nostrb
|
6
|
+
|
7
|
+
describe Source do
|
8
|
+
describe "instantiation" do
|
9
|
+
it "wraps a binary pubkey" do
|
10
|
+
s = Source.new(Test::PK)
|
11
|
+
expect(s).must_be_kind_of Source
|
12
|
+
expect(s.pk).must_equal Test::PK
|
13
|
+
|
14
|
+
expect {
|
15
|
+
Source.new(SchnorrSig.bin2hex(Test::PK))
|
16
|
+
}.must_raise EncodingError
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "event creation" do
|
21
|
+
it "creates text_note events" do
|
22
|
+
s = Source.new(Test::PK)
|
23
|
+
e = s.text_note('hello world')
|
24
|
+
expect(e).must_be_kind_of Event
|
25
|
+
expect(e.kind).must_equal 1
|
26
|
+
expect(e.content).must_equal 'hello world'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "creates user_metadata events" do
|
30
|
+
s = Source.new(Test::PK)
|
31
|
+
e = s.user_metadata(name: 'Bob Loblaw',
|
32
|
+
about: "Bob Loblaw's Law Blog",
|
33
|
+
picture: "https://localhost/me.jpg")
|
34
|
+
expect(e).must_be_kind_of Event
|
35
|
+
expect(e.kind).must_equal 0
|
36
|
+
|
37
|
+
# above data becomes JSON string in content
|
38
|
+
expect(e.content).wont_be_empty
|
39
|
+
expect(e.tags).must_be_empty
|
40
|
+
end
|
41
|
+
|
42
|
+
it "creates follow_list events" do
|
43
|
+
pubkey_hsh = {
|
44
|
+
SchnorrSig.bin2hex(Random.bytes(32)) => ['foo', 'bar'],
|
45
|
+
SchnorrSig.bin2hex(Random.bytes(32)) => ['baz', 'quux'],
|
46
|
+
SchnorrSig.bin2hex(Random.bytes(32)) => ['asdf', '123'],
|
47
|
+
}
|
48
|
+
s = Source.new(Test::PK)
|
49
|
+
e = s.follow_list(pubkey_hsh)
|
50
|
+
expect(e).must_be_kind_of Event
|
51
|
+
expect(e.kind).must_equal 3
|
52
|
+
|
53
|
+
# above data goes into tags structure, not content
|
54
|
+
expect(e.content).must_be_empty
|
55
|
+
expect(e.tags).wont_be_empty
|
56
|
+
end
|
57
|
+
|
58
|
+
it "creates deletion_request events" do
|
59
|
+
fake_ids = Array.new(3) { SchnorrSig.bin2hex Random.bytes(32) }
|
60
|
+
|
61
|
+
s = Source.new(Test::PK)
|
62
|
+
e = s.deletion_request('testing deletes', *fake_ids)
|
63
|
+
expect(e.content).wont_be_empty
|
64
|
+
expect(e.tags).wont_be_empty
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe Filter do
|
70
|
+
it "starts empty" do
|
71
|
+
f = Filter.new
|
72
|
+
expect(f).must_be_kind_of Filter
|
73
|
+
expect(f.to_h).must_be_empty
|
74
|
+
end
|
75
|
+
|
76
|
+
it "validates added ids" do
|
77
|
+
f = Filter.new
|
78
|
+
ids = Array.new(3) { SchnorrSig.bin2hex(Random.bytes(32)) }
|
79
|
+
f.add_ids(*ids)
|
80
|
+
expect(f.to_h).wont_be_empty
|
81
|
+
expect(f.to_h["ids"]).wont_be_empty
|
82
|
+
expect(f.to_h["ids"]).must_equal ids
|
83
|
+
end
|
84
|
+
|
85
|
+
it "validates added tags" do
|
86
|
+
f = Filter.new
|
87
|
+
ids = Array.new(3) { SchnorrSig.bin2hex(Random.bytes(32)) }
|
88
|
+
f.add_tag('e', ids)
|
89
|
+
hsh = f.to_h
|
90
|
+
expect(hsh).wont_be_empty
|
91
|
+
expect(hsh.key?("tags")).must_equal false
|
92
|
+
expect(hsh["#e"]).wont_be_empty
|
93
|
+
expect(hsh["#e"]).must_equal ids
|
94
|
+
end
|
95
|
+
|
96
|
+
it "accepts integers for since, until, and limit" do
|
97
|
+
f = Filter.new
|
98
|
+
f.since = Time.now.to_i - 99_999
|
99
|
+
f.until = Time.now.to_i
|
100
|
+
hsh = f.to_h
|
101
|
+
expect(hsh).wont_be_empty
|
102
|
+
expect(hsh["until"]).must_be_kind_of Integer
|
103
|
+
expect(hsh["since"]).must_be_kind_of Integer
|
104
|
+
expect(hsh.key?("limit")).must_equal false
|
105
|
+
|
106
|
+
f.limit = 99
|
107
|
+
expect(f.to_h["limit"]).must_equal 99
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "stuff" do
|
112
|
+
it "creates EVENT messages to publish signed events" do
|
113
|
+
sk, pk = SchnorrSig.keypair
|
114
|
+
e = Event.new(pk: pk).sign(sk)
|
115
|
+
a = Source.publish(e)
|
116
|
+
expect(a).must_be_kind_of Array
|
117
|
+
expect(a[0]).must_equal "EVENT"
|
118
|
+
end
|
119
|
+
|
120
|
+
it "creates REQ messages to subscribe to events using filters" do
|
121
|
+
f = Filter.new
|
122
|
+
pubkey = SchnorrSig.bin2hex Random.bytes(32)
|
123
|
+
sid = Source.random_sid
|
124
|
+
f.add_authors(pubkey)
|
125
|
+
a = Source.subscribe(sid, f)
|
126
|
+
expect(a).must_be_kind_of Array
|
127
|
+
expect(a[0]).must_equal "REQ"
|
128
|
+
end
|
129
|
+
|
130
|
+
it "creates CLOSE messages to end all subscriptions / streams" do
|
131
|
+
sid = Source.random_sid
|
132
|
+
a = Source.close(sid)
|
133
|
+
expect(a).must_be_kind_of Array
|
134
|
+
expect(a[0]).must_equal "CLOSE"
|
135
|
+
end
|
136
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nostrb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rick Hull
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 1980-01-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: schnorr_sig
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
description: TBD
|
28
|
+
email:
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- Rakefile
|
34
|
+
- VERSION
|
35
|
+
- lib/nostrb.rb
|
36
|
+
- lib/nostrb/event.rb
|
37
|
+
- lib/nostrb/filter.rb
|
38
|
+
- lib/nostrb/json.rb
|
39
|
+
- lib/nostrb/names.rb
|
40
|
+
- lib/nostrb/oj.rb
|
41
|
+
- lib/nostrb/relay.rb
|
42
|
+
- lib/nostrb/sequel.rb
|
43
|
+
- lib/nostrb/source.rb
|
44
|
+
- lib/nostrb/sqlite.rb
|
45
|
+
- nostrb.gemspec
|
46
|
+
- test/common.rb
|
47
|
+
- test/event.rb
|
48
|
+
- test/nostrb.rb
|
49
|
+
- test/relay.rb
|
50
|
+
- test/source.rb
|
51
|
+
homepage: https://github.com/rickhull/nostrb
|
52
|
+
licenses:
|
53
|
+
- LGPL-2.1-only
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '3.0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubygems_version: 3.5.9
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: Minimal Nostr library in Ruby
|
74
|
+
test_files: []
|