nostr 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +1 -1
  3. data/.rubocop.yml +23 -0
  4. data/.tool-versions +2 -1
  5. data/CHANGELOG.md +36 -1
  6. data/README.md +92 -228
  7. data/docs/.gitignore +4 -0
  8. data/docs/.vitepress/config.mjs +112 -0
  9. data/docs/README.md +44 -0
  10. data/docs/api-examples.md +49 -0
  11. data/docs/bun.lockb +0 -0
  12. data/docs/common-use-cases/bech32-encoding-and-decoding-(NIP-19).md +190 -0
  13. data/docs/core/client.md +108 -0
  14. data/docs/core/keys.md +136 -0
  15. data/docs/core/user.md +43 -0
  16. data/docs/events/contact-list.md +29 -0
  17. data/docs/events/encrypted-direct-message.md +28 -0
  18. data/docs/events/recommend-server.md +32 -0
  19. data/docs/events/set-metadata.md +20 -0
  20. data/docs/events/text-note.md +15 -0
  21. data/docs/events.md +11 -0
  22. data/docs/getting-started/installation.md +21 -0
  23. data/docs/getting-started/overview.md +170 -0
  24. data/docs/implemented-nips.md +9 -0
  25. data/docs/index.md +44 -0
  26. data/docs/markdown-examples.md +85 -0
  27. data/docs/package.json +12 -0
  28. data/docs/relays/connecting-to-a-relay.md +21 -0
  29. data/docs/relays/publishing-events.md +29 -0
  30. data/docs/relays/receiving-events.md +6 -0
  31. data/docs/subscriptions/creating-a-subscription.md +49 -0
  32. data/docs/subscriptions/deleting-a-subscription.md +10 -0
  33. data/docs/subscriptions/filtering-subscription-events.md +115 -0
  34. data/docs/subscriptions/updating-a-subscription.md +4 -0
  35. data/lib/nostr/bech32.rb +203 -0
  36. data/lib/nostr/client.rb +2 -1
  37. data/lib/nostr/crypto.rb +11 -7
  38. data/lib/nostr/errors/error.rb +7 -0
  39. data/lib/nostr/errors/invalid_hrp_error.rb +21 -0
  40. data/lib/nostr/errors/invalid_key_format_error.rb +20 -0
  41. data/lib/nostr/errors/invalid_key_length_error.rb +20 -0
  42. data/lib/nostr/errors/invalid_key_type_error.rb +18 -0
  43. data/lib/nostr/errors/key_validation_error.rb +6 -0
  44. data/lib/nostr/errors.rb +8 -0
  45. data/lib/nostr/event.rb +3 -4
  46. data/lib/nostr/events/encrypted_direct_message.rb +4 -3
  47. data/lib/nostr/filter.rb +4 -4
  48. data/lib/nostr/key.rb +100 -0
  49. data/lib/nostr/key_pair.rb +30 -6
  50. data/lib/nostr/keygen.rb +43 -4
  51. data/lib/nostr/private_key.rb +36 -0
  52. data/lib/nostr/public_key.rb +36 -0
  53. data/lib/nostr/relay_message_type.rb +18 -0
  54. data/lib/nostr/subscription.rb +2 -2
  55. data/lib/nostr/user.rb +17 -8
  56. data/lib/nostr/version.rb +1 -1
  57. data/lib/nostr.rb +6 -0
  58. data/nostr.gemspec +9 -9
  59. data/sig/nostr/bech32.rbs +14 -0
  60. data/sig/nostr/client.rbs +5 -5
  61. data/sig/nostr/crypto.rbs +5 -5
  62. data/sig/nostr/errors/error.rbs +4 -0
  63. data/sig/nostr/errors/invalid_hrb_error.rbs +6 -0
  64. data/sig/nostr/errors/invalid_key_format_error.rbs +5 -0
  65. data/sig/nostr/errors/invalid_key_length_error.rbs +5 -0
  66. data/sig/nostr/errors/invalid_key_type_error.rbs +5 -0
  67. data/sig/nostr/errors/key_validation_error.rbs +4 -0
  68. data/sig/nostr/event.rbs +4 -4
  69. data/sig/nostr/events/encrypted_direct_message.rbs +2 -2
  70. data/sig/nostr/filter.rbs +3 -12
  71. data/sig/nostr/key.rbs +16 -0
  72. data/sig/nostr/key_pair.rbs +7 -3
  73. data/sig/nostr/keygen.rbs +5 -2
  74. data/sig/nostr/private_key.rbs +4 -0
  75. data/sig/nostr/public_key.rbs +4 -0
  76. data/sig/nostr/relay_message_type.rbs +8 -0
  77. data/sig/nostr/user.rbs +4 -8
  78. data/sig/vendor/bech32/nostr/entity.rbs +41 -0
  79. data/sig/vendor/bech32/nostr/nip19.rbs +20 -0
  80. data/sig/vendor/bech32/segwit_addr.rbs +21 -0
  81. data/sig/vendor/bech32.rbs +25 -0
  82. data/sig/vendor/event_emitter.rbs +10 -3
  83. data/sig/vendor/event_machine/channel.rbs +1 -1
  84. data/sig/vendor/faye/websocket/api.rbs +45 -0
  85. data/sig/vendor/faye/websocket/client.rbs +43 -0
  86. data/sig/vendor/faye/websocket.rbs +30 -0
  87. metadata +79 -21
@@ -0,0 +1,25 @@
1
+ # Added only to satisfy the Steep requirements. Not 100% reliable.
2
+ module Bech32
3
+ SEPARATOR: String
4
+ BECH32M_CONST: Integer
5
+
6
+ def encode: (untyped hrp, untyped data, untyped spec) -> untyped
7
+ def self.encode: (untyped hrp, untyped data, untyped spec) -> untyped
8
+ def decode: (untyped bech, ?Integer max_length) -> [untyped, untyped, Integer]?
9
+ def self.decode: (untyped bech, ?Integer max_length) -> [untyped, untyped, Integer]?
10
+ def create_checksum: (untyped hrp, untyped data, untyped spec) -> Array[Integer]
11
+ def self.create_checksum: (untyped hrp, untyped data, untyped spec) -> Array[Integer]
12
+ def verify_checksum: (untyped hrp, untyped data) -> Integer?
13
+ def self.verify_checksum: (untyped hrp, untyped data) -> Integer?
14
+ def expand_hrp: (untyped hrp) -> untyped
15
+ def self.expand_hrp: (untyped hrp) -> untyped
16
+ def convert_bits: (untyped data, untyped from, untyped to, ?true padding) -> Array[Integer]?
17
+ def self.convert_bits: (untyped data, untyped from, untyped to, ?true padding) -> Array[Integer]?
18
+ def polymod: (untyped values) -> Integer
19
+ def self.polymod: (untyped values) -> Integer
20
+
21
+ module Encoding
22
+ BECH32: Integer
23
+ BECH32M: Integer
24
+ end
25
+ end
@@ -1,9 +1,16 @@
1
1
  # Added only to satisfy the Steep requirements. Not 100% reliable.
2
2
  module EventEmitter
3
- def add_listener: (untyped `type`, ?{once: true} params) -> Integer
3
+ interface _Event
4
+ def data: -> String
5
+ def message: -> String
6
+ def code: -> Integer
7
+ def reason: -> String
8
+ end
9
+
10
+ def add_listener: (Symbol event_name) { (_Event event) -> void } -> void
4
11
  alias on add_listener
5
12
 
6
13
  def remove_listener: (untyped id_or_type) -> Array[untyped]?
7
- def emit: (untyped `type`, *untyped data) -> Array[untyped]
8
- def once: (untyped `type`) -> Integer
14
+ def emit: (Symbol `type`, *untyped data) -> Array[untyped]
15
+ def once: (Symbol `type`) -> Integer
9
16
  end
@@ -6,7 +6,7 @@ module EventMachine
6
6
 
7
7
  def initialize: -> void
8
8
  def num_subscribers: -> Integer
9
- def subscribe: (*untyped a) ?{ -> untyped } -> Integer
9
+ def subscribe: (*untyped a) ?{ (untyped) -> untyped } -> Integer
10
10
  def unsubscribe: (untyped name) -> untyped
11
11
  def push: (*untyped items) -> untyped
12
12
  alias << push
@@ -0,0 +1,45 @@
1
+ # Added only to satisfy the Steep requirements. Not 100% reliable.
2
+ module Faye
3
+ class WebSocket
4
+ module API
5
+ CONNECTING: Integer
6
+ OPEN: Integer
7
+ CLOSING: Integer
8
+ CLOSED: Integer
9
+ CLOSE_TIMEOUT: Integer
10
+
11
+ @driver: untyped
12
+ @ping: nil
13
+ @ping_id: Integer
14
+ @stream: nil
15
+ @proxy: nil
16
+ @ping_timer: nil
17
+ @close_timer: nil
18
+ @close_params: [String, Integer]?
19
+ @onerror: nil
20
+ @onclose: nil
21
+ @onmessage: nil
22
+ @onopen: nil
23
+
24
+ attr_reader url: untyped
25
+ attr_reader ready_state: Integer
26
+ attr_reader buffered_amount: Integer
27
+
28
+ def initialize: (?Hash[untyped, untyped] options) -> void
29
+ def write: (untyped data) -> untyped
30
+ def send: (untyped message) -> false
31
+ def ping: (?String message) -> false
32
+ def close: (?nil code, ?nil reason) -> untyped
33
+ def protocol: -> String
34
+
35
+ private
36
+
37
+ def open: -> nil
38
+ def receive_message: (untyped data) -> nil
39
+ def emit_error: (untyped message) -> nil
40
+ def begin_close: (String reason, Integer code, ?Hash[untyped, untyped] options) -> nil
41
+ def finalize_close: -> nil
42
+ def parse: (untyped data) -> untyped
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,43 @@
1
+ # Added only to satisfy the Steep requirements. Not 100% reliable.
2
+ module Faye
3
+ class WebSocket
4
+ class Client
5
+ DEFAULT_PORTS: Hash[String, Integer]
6
+ SECURE_PROTOCOLS: [String, String]
7
+
8
+ include EventEmitter
9
+ include API
10
+
11
+ @url: untyped
12
+ @endpoint: untyped
13
+ @origin_tls: Hash[untyped, untyped]
14
+ @socket_tls: Hash[untyped, untyped]
15
+ @driver: bot
16
+ @proxy: nil
17
+ @ssl_verifier: untyped
18
+ @stream: untyped
19
+
20
+ def initialize: (untyped url, ?Array[String] protocols, ?Hash[untyped, untyped] options) -> void
21
+
22
+ private
23
+
24
+ def configure_proxy: (Hash[untyped, untyped] proxy) -> nil
25
+ def start_tls: (untyped uri, Hash[untyped, untyped] options) -> nil
26
+ def on_connect: (untyped stream) -> untyped
27
+ def on_network_error: (nil error) -> untyped
28
+ def ssl_verify_peer: (untyped cert) -> untyped
29
+ def ssl_handshake_completed: -> untyped
30
+
31
+ module Connection
32
+ attr_accessor parent: bot
33
+
34
+ def connection_completed: -> untyped
35
+ def ssl_verify_peer: (untyped cert) -> untyped
36
+ def ssl_handshake_completed: -> untyped
37
+ def receive_data: (untyped data) -> untyped
38
+ def unbind: (?nil error) -> untyped
39
+ def write: (untyped data) -> nil
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,30 @@
1
+ # Added only to satisfy the Steep requirements. Not 100% reliable.
2
+ module Faye
3
+ class WebSocket
4
+ ADAPTERS: Hash[String, :Goliath | :Rainbows | :Thin]
5
+
6
+ @url: String
7
+ @driver_started: false
8
+ @stream: Stream
9
+ @driver: bot
10
+
11
+ def self.determine_url: (untyped env, ?[String, String] schemes) -> String
12
+ def self.ensure_reactor_running: -> nil
13
+ def self.load_adapter: (untyped backend) -> bool?
14
+ def self.secure_request?: (untyped env) -> bool
15
+ def self.websocket?: (untyped env) -> untyped
16
+
17
+ attr_reader env: untyped
18
+
19
+ def initialize: (untyped env, ?nil protocols, ?Hash[untyped, untyped] options) -> void
20
+ def start_driver: -> nil
21
+ def rack_response: -> [Integer, Hash[untyped, untyped], Array[untyped]]
22
+
23
+ class Stream
24
+ @socket_object: bot
25
+
26
+ def fail: -> untyped
27
+ def receive: (untyped data) -> untyped
28
+ end
29
+ end
30
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nostr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wilson Silva
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-25 00:00:00.000000000 Z
11
+ date: 2023-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bech32
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '1.4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '1.4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bip-schnorr
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.4'
33
+ version: '0.6'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.4'
40
+ version: '0.6'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: ecdsa
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -226,14 +226,14 @@ dependencies:
226
226
  requirements:
227
227
  - - "~>"
228
228
  - !ruby/object:Gem::Version
229
- version: '5.6'
229
+ version: '6.4'
230
230
  type: :development
231
231
  prerelease: false
232
232
  version_requirements: !ruby/object:Gem::Requirement
233
233
  requirements:
234
234
  - - "~>"
235
235
  - !ruby/object:Gem::Version
236
- version: '5.6'
236
+ version: '6.4'
237
237
  - !ruby/object:Gem::Dependency
238
238
  name: rack
239
239
  requirement: !ruby/object:Gem::Requirement
@@ -254,28 +254,28 @@ dependencies:
254
254
  requirements:
255
255
  - - "~>"
256
256
  - !ruby/object:Gem::Version
257
- version: '13.0'
257
+ version: '13.1'
258
258
  type: :development
259
259
  prerelease: false
260
260
  version_requirements: !ruby/object:Gem::Requirement
261
261
  requirements:
262
262
  - - "~>"
263
263
  - !ruby/object:Gem::Version
264
- version: '13.0'
264
+ version: '13.1'
265
265
  - !ruby/object:Gem::Dependency
266
266
  name: rbs
267
267
  requirement: !ruby/object:Gem::Requirement
268
268
  requirements:
269
269
  - - "~>"
270
270
  - !ruby/object:Gem::Version
271
- version: '2.8'
271
+ version: '3.3'
272
272
  type: :development
273
273
  prerelease: false
274
274
  version_requirements: !ruby/object:Gem::Requirement
275
275
  requirements:
276
276
  - - "~>"
277
277
  - !ruby/object:Gem::Version
278
- version: '2.8'
278
+ version: '3.3'
279
279
  - !ruby/object:Gem::Dependency
280
280
  name: rspec
281
281
  requirement: !ruby/object:Gem::Requirement
@@ -296,14 +296,14 @@ dependencies:
296
296
  requirements:
297
297
  - - "~>"
298
298
  - !ruby/object:Gem::Version
299
- version: '1.42'
299
+ version: '1.57'
300
300
  type: :development
301
301
  prerelease: false
302
302
  version_requirements: !ruby/object:Gem::Requirement
303
303
  requirements:
304
304
  - - "~>"
305
305
  - !ruby/object:Gem::Version
306
- version: '1.42'
306
+ version: '1.57'
307
307
  - !ruby/object:Gem::Dependency
308
308
  name: rubocop-rake
309
309
  requirement: !ruby/object:Gem::Requirement
@@ -324,14 +324,14 @@ dependencies:
324
324
  requirements:
325
325
  - - '='
326
326
  - !ruby/object:Gem::Version
327
- version: '2.16'
327
+ version: '2.25'
328
328
  type: :development
329
329
  prerelease: false
330
330
  version_requirements: !ruby/object:Gem::Requirement
331
331
  requirements:
332
332
  - - '='
333
333
  - !ruby/object:Gem::Version
334
- version: '2.16'
334
+ version: '2.25'
335
335
  - !ruby/object:Gem::Dependency
336
336
  name: simplecov
337
337
  requirement: !ruby/object:Gem::Requirement
@@ -366,14 +366,14 @@ dependencies:
366
366
  requirements:
367
367
  - - "~>"
368
368
  - !ruby/object:Gem::Version
369
- version: '1.3'
369
+ version: '1.6'
370
370
  type: :development
371
371
  prerelease: false
372
372
  version_requirements: !ruby/object:Gem::Requirement
373
373
  requirements:
374
374
  - - "~>"
375
375
  - !ruby/object:Gem::Version
376
- version: '1.3'
376
+ version: '1.6'
377
377
  - !ruby/object:Gem::Dependency
378
378
  name: typeprof
379
379
  requirement: !ruby/object:Gem::Requirement
@@ -452,45 +452,103 @@ files:
452
452
  - README.md
453
453
  - Rakefile
454
454
  - Steepfile
455
+ - docs/.gitignore
456
+ - docs/.vitepress/config.mjs
457
+ - docs/README.md
458
+ - docs/api-examples.md
459
+ - docs/bun.lockb
460
+ - docs/common-use-cases/bech32-encoding-and-decoding-(NIP-19).md
461
+ - docs/core/client.md
462
+ - docs/core/keys.md
463
+ - docs/core/user.md
464
+ - docs/events.md
465
+ - docs/events/contact-list.md
466
+ - docs/events/encrypted-direct-message.md
467
+ - docs/events/recommend-server.md
468
+ - docs/events/set-metadata.md
469
+ - docs/events/text-note.md
470
+ - docs/getting-started/installation.md
471
+ - docs/getting-started/overview.md
472
+ - docs/implemented-nips.md
473
+ - docs/index.md
474
+ - docs/markdown-examples.md
475
+ - docs/package.json
476
+ - docs/relays/connecting-to-a-relay.md
477
+ - docs/relays/publishing-events.md
478
+ - docs/relays/receiving-events.md
479
+ - docs/subscriptions/creating-a-subscription.md
480
+ - docs/subscriptions/deleting-a-subscription.md
481
+ - docs/subscriptions/filtering-subscription-events.md
482
+ - docs/subscriptions/updating-a-subscription.md
455
483
  - lib/nostr.rb
484
+ - lib/nostr/bech32.rb
456
485
  - lib/nostr/client.rb
457
486
  - lib/nostr/client_message_type.rb
458
487
  - lib/nostr/crypto.rb
488
+ - lib/nostr/errors.rb
489
+ - lib/nostr/errors/error.rb
490
+ - lib/nostr/errors/invalid_hrp_error.rb
491
+ - lib/nostr/errors/invalid_key_format_error.rb
492
+ - lib/nostr/errors/invalid_key_length_error.rb
493
+ - lib/nostr/errors/invalid_key_type_error.rb
494
+ - lib/nostr/errors/key_validation_error.rb
459
495
  - lib/nostr/event.rb
460
496
  - lib/nostr/event_kind.rb
461
497
  - lib/nostr/events/encrypted_direct_message.rb
462
498
  - lib/nostr/filter.rb
499
+ - lib/nostr/key.rb
463
500
  - lib/nostr/key_pair.rb
464
501
  - lib/nostr/keygen.rb
502
+ - lib/nostr/private_key.rb
503
+ - lib/nostr/public_key.rb
465
504
  - lib/nostr/relay.rb
505
+ - lib/nostr/relay_message_type.rb
466
506
  - lib/nostr/subscription.rb
467
507
  - lib/nostr/user.rb
468
508
  - lib/nostr/version.rb
469
509
  - nostr.gemspec
470
510
  - sig/nostr.rbs
511
+ - sig/nostr/bech32.rbs
471
512
  - sig/nostr/client.rbs
472
513
  - sig/nostr/client_message_type.rbs
473
514
  - sig/nostr/crypto.rbs
515
+ - sig/nostr/errors/error.rbs
516
+ - sig/nostr/errors/invalid_hrb_error.rbs
517
+ - sig/nostr/errors/invalid_key_format_error.rbs
518
+ - sig/nostr/errors/invalid_key_length_error.rbs
519
+ - sig/nostr/errors/invalid_key_type_error.rbs
520
+ - sig/nostr/errors/key_validation_error.rbs
474
521
  - sig/nostr/event.rbs
475
522
  - sig/nostr/event_kind.rbs
476
523
  - sig/nostr/events/encrypted_direct_message.rbs
477
524
  - sig/nostr/filter.rbs
525
+ - sig/nostr/key.rbs
478
526
  - sig/nostr/key_pair.rbs
479
527
  - sig/nostr/keygen.rbs
528
+ - sig/nostr/private_key.rbs
529
+ - sig/nostr/public_key.rbs
480
530
  - sig/nostr/relay.rbs
531
+ - sig/nostr/relay_message_type.rbs
481
532
  - sig/nostr/subscription.rbs
482
533
  - sig/nostr/user.rbs
534
+ - sig/vendor/bech32.rbs
535
+ - sig/vendor/bech32/nostr/entity.rbs
536
+ - sig/vendor/bech32/nostr/nip19.rbs
537
+ - sig/vendor/bech32/segwit_addr.rbs
483
538
  - sig/vendor/ecsda/group/secp256k1.rbs
484
539
  - sig/vendor/event_emitter.rbs
485
540
  - sig/vendor/event_machine.rbs
486
541
  - sig/vendor/event_machine/channel.rbs
542
+ - sig/vendor/faye/websocket.rbs
543
+ - sig/vendor/faye/websocket/api.rbs
544
+ - sig/vendor/faye/websocket/client.rbs
487
545
  - sig/vendor/schnorr.rbs
488
- homepage: https://github.com/wilsonsilva/nostr
546
+ homepage: https://nostr-ruby.com/
489
547
  licenses:
490
548
  - MIT
491
549
  metadata:
492
550
  rubygems_mfa_required: 'true'
493
- homepage_uri: https://github.com/wilsonsilva/nostr
551
+ homepage_uri: https://nostr-ruby.com/
494
552
  source_code_uri: https://github.com/wilsonsilva/nostr
495
553
  changelog_uri: https://github.com/wilsonsilva/nostr/blob/main/CHANGELOG.md
496
554
  post_install_message:
@@ -508,7 +566,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
508
566
  - !ruby/object:Gem::Version
509
567
  version: '0'
510
568
  requirements: []
511
- rubygems_version: 3.4.7
569
+ rubygems_version: 3.4.20
512
570
  signing_key:
513
571
  specification_version: 4
514
572
  summary: Client and relay implementation of the Nostr protocol.