From eb6ca05e0f1d1b5cd8447f91c0d9ff885e1ed081 Mon Sep 17 00:00:00 2001 From: Mohammed Anas FIKHI Date: Sat, 20 Jan 2024 23:42:30 +0100 Subject: [PATCH] [ Add ] 7.0.0 --- CHANGELOG.md | 7 ++++ README.md | 2 +- example/check_key_validity.dart | 6 ++-- .../get_pubkey_from_identifier_nip_05.dart | 5 +-- example/listening_to_events.dart | 15 +++++---- example/main.dart | 32 +++++++++---------- ...pened_subscriptions_with_same_request.dart | 31 +++++++++++------- example/send_event_asynchronously.dart | 8 +++-- lib/dart_nostr.dart | 1 - lib/nostr/core/exceptions.dart | 2 +- lib/nostr/core/key_pairs.dart | 2 +- lib/nostr/dart_nostr.dart | 2 +- lib/nostr/instance/relays/relays.dart | 1 + lib/nostr/instance/tlv/tlv_utils.dart | 3 +- lib/nostr/model/event/event.dart | 22 +++++++------ lib/nostr/model/nostr_event_key.dart | 2 +- lib/nostr/model/nostr_events_stream.dart | 2 +- lib/nostr/model/ok.dart | 2 +- lib/nostr/model/relay_informations.dart | 1 - lib/nostr/model/request/close.dart | 2 +- lib/nostr/model/request/filter.dart | 2 +- lib/nostr/model/tlv.dart | 1 - lib/nostr/service/registry.dart | 1 - lib/nostr/service/web_sockets.dart | 1 - pubspec.yaml | 6 ++-- 25 files changed, 87 insertions(+), 72 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 184bfed..61e8e3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 7.0.0 + +- Breaking changes in most package services. +- Implementations for more asyncronous methods. +- New Mniimal Documentation for the package in readme.md file. +- Minor dev edits, fixes and improvements. + ## 6.1.0 - Implmenttaion of free resources method for the relays service of an instance that clears and closes all events registeries and streams. diff --git a/README.md b/README.md index c8633dd..abb182c 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ if you are working on a Nostr client, app... you will be able to apply and use a - [NIP-98](https://github.com/nostr-protocol/nips/blob/master/98.md) - [NIP-99](https://github.com/nostr-protocol/nips/blob/master/99.md) -NIPs marked as "not yet implemented" are not supported yet. +NIPs marked as "not yet implemented" are not supported yet. Some existant NIPs are platform specific or can't just be supported directly like [NIP 07](https://github.com/nostr-protocol/nips/blob/master/07.md) which is only web-specific, or [NIP 90](https://github.com/nostr-protocol/nips/blob/master/90.md) which is related to Data Vending machines. diff --git a/example/check_key_validity.dart b/example/check_key_validity.dart index 391b8eb..340fc9f 100644 --- a/example/check_key_validity.dart +++ b/example/check_key_validity.dart @@ -9,7 +9,9 @@ void main() { const secondKey = ''; print( - 'is firstKey a valid key? ${Nostr.instance.keysService.isValidPrivateKey(firstKey)}',); + 'is firstKey a valid key? ${Nostr.instance.keysService.isValidPrivateKey(firstKey)}', + ); print( - 'is secondKey a valid key? ${Nostr.instance.keysService.isValidPrivateKey(secondKey)}',); + 'is secondKey a valid key? ${Nostr.instance.keysService.isValidPrivateKey(secondKey)}', + ); } diff --git a/example/get_pubkey_from_identifier_nip_05.dart b/example/get_pubkey_from_identifier_nip_05.dart index 3fa8453..8a9a6a0 100644 --- a/example/get_pubkey_from_identifier_nip_05.dart +++ b/example/get_pubkey_from_identifier_nip_05.dart @@ -2,8 +2,9 @@ import 'package:dart_nostr/dart_nostr.dart'; Future main() async { final puKey = await Nostr.instance.utilsService.pubKeyFromIdentifierNip05( - internetIdentifier: - 'aljaz@raw.githubusercontent.com/aljazceru/awesome-nostr/main',); + internetIdentifier: + 'aljaz@raw.githubusercontent.com/aljazceru/awesome-nostr/main', + ); print(puKey); } diff --git a/example/listening_to_events.dart b/example/listening_to_events.dart index b432d39..84cd007 100644 --- a/example/listening_to_events.dart +++ b/example/listening_to_events.dart @@ -28,14 +28,15 @@ void main() async { // Now we create the stream of that request. // ignore: unused_local_variable final requestStream = Nostr.instance.relaysService.startEventsSubscription( - request: request, - onEose: (ease) { - print('ease received for subscription id: ${ease.subscriptionId}'); + request: request, + onEose: (ease) { + print('ease received for subscription id: ${ease.subscriptionId}'); - Nostr.instance.relaysService.closeEventsSubscription( - ease.subscriptionId, - ); - },); + Nostr.instance.relaysService.closeEventsSubscription( + ease.subscriptionId, + ); + }, + ); // We listen to the stream and print the events. requestStream.stream.listen((event) { diff --git a/example/main.dart b/example/main.dart index a745ac7..be3a0b6 100644 --- a/example/main.dart +++ b/example/main.dart @@ -11,7 +11,7 @@ Future main() async { // init relays await Nostr.instance.relaysService.init( - relaysUrl: ["wss://relay.damus.io"], + relaysUrl: ['wss://relay.damus.io'], ); final currentDateInMsAsString = @@ -20,17 +20,17 @@ Future main() async { // create an event final event = NostrEvent.fromPartialData( kind: 1, - content: "example content", + content: 'example content', keyPairs: keyPair, tags: [ - ["t", currentDateInMsAsString], + ['t', currentDateInMsAsString], ], ); // send the event Nostr.instance.relaysService.sendEventToRelays(event); - await Future.delayed(Duration(seconds: 5)); + await Future.delayed(const Duration(seconds: 5)); // create a subscription id. final subscriptionId = Nostr.instance.utilsService.random64HexChars(); @@ -40,7 +40,7 @@ Future main() async { subscriptionId: subscriptionId, filters: [ NostrFilter( - kinds: [1], + kinds: const [1], t: [currentDateInMsAsString], authors: [keyPair.public], ), @@ -50,40 +50,38 @@ Future main() async { // listen to events final sub = Nostr.instance.relaysService.startEventsSubscription( request: request, - onEose: (ease) => print(ease), + onEose: print, ); - StreamSubscription subscritpion = sub.stream.listen( - (event) { - print(event); - }, + final StreamSubscription subscritpion = sub.stream.listen( + print, onDone: () { - print("done"); + print('done'); }, ); - await Future.delayed(Duration(seconds: 5)); + await Future.delayed(const Duration(seconds: 5)); // cancel the subscription - subscritpion.cancel().whenComplete(() { + await subscritpion.cancel().whenComplete(() { Nostr.instance.relaysService.closeEventsSubscription(subscriptionId); }); - await Future.delayed(Duration(seconds: 5)); + await Future.delayed(const Duration(seconds: 5)); // create a new event that will not be received by the subscription because it is closed. final event2 = NostrEvent.fromPartialData( kind: 1, - content: "example content", + content: 'example content', keyPairs: keyPair, tags: [ - ["t", currentDateInMsAsString], + ['t', currentDateInMsAsString], ], ); // send the event 2 that will not be received by the subscription because it is closed. Nostr.instance.relaysService.sendEventToRelays( event2, - onOk: (ok) => print(ok), + onOk: print, ); } diff --git a/example/receiving_events_from_reopened_subscriptions_with_same_request.dart b/example/receiving_events_from_reopened_subscriptions_with_same_request.dart index c7d1232..59581aa 100644 --- a/example/receiving_events_from_reopened_subscriptions_with_same_request.dart +++ b/example/receiving_events_from_reopened_subscriptions_with_same_request.dart @@ -10,16 +10,20 @@ void main() async { final newKeyPair = Nostr.instance.keysService.generateKeyPair(); final event = NostrEvent.fromPartialData( - content: newKeyPair.public, - kind: 1, - keyPairs: newKeyPair, - tags: [ - ['t', newKeyPair.public], - ],); + content: newKeyPair.public, + kind: 1, + keyPairs: newKeyPair, + tags: [ + ['t', newKeyPair.public], + ], + ); - Nostr.instance.relaysService.sendEventToRelays(event, onOk: (ok) { - print('event sent, ${ok.eventId}'); - },); + Nostr.instance.relaysService.sendEventToRelays( + event, + onOk: (ok) { + print('event sent, ${ok.eventId}'); + }, + ); await Future.delayed(const Duration(seconds: 5)); @@ -68,7 +72,10 @@ void main() async { ], ); - Nostr.instance.relaysService.sendEventToRelays(anotherEvent, onOk: (ok) { - print('event sent, ${ok.eventId}'); - },); + Nostr.instance.relaysService.sendEventToRelays( + anotherEvent, + onOk: (ok) { + print('event sent, ${ok.eventId}'); + }, + ); } diff --git a/example/send_event_asynchronously.dart b/example/send_event_asynchronously.dart index 5842e8d..450e298 100644 --- a/example/send_event_asynchronously.dart +++ b/example/send_event_asynchronously.dart @@ -3,9 +3,11 @@ import 'dart:async'; import 'package:dart_nostr/dart_nostr.dart'; Future main(List args) async { - await Nostr.instance.relaysService.init(relaysUrl: [ - 'wss://relay.damus.io', - ],); + await Nostr.instance.relaysService.init( + relaysUrl: [ + 'wss://relay.damus.io', + ], + ); final keyPair = Nostr.instance.keysService.generateKeyPair(); diff --git a/lib/dart_nostr.dart b/lib/dart_nostr.dart index 4bc0940..357f01d 100644 --- a/lib/dart_nostr.dart +++ b/lib/dart_nostr.dart @@ -1,4 +1,3 @@ - export './nostr/core/key_pairs.dart'; export './nostr/core/utils.dart'; export './nostr/model/export.dart'; diff --git a/lib/nostr/core/exceptions.dart b/lib/nostr/core/exceptions.dart index ef6d23e..f8b47a8 100644 --- a/lib/nostr/core/exceptions.dart +++ b/lib/nostr/core/exceptions.dart @@ -2,9 +2,9 @@ /// Thrown when a relay is not found/registered. /// {@endtemplate} class RelayNotFoundException implements Exception { - /// {@macro relay_not_found_exception} RelayNotFoundException(this.relayUrl); + /// The url of the relay that was not found. final String relayUrl; diff --git a/lib/nostr/core/key_pairs.dart b/lib/nostr/core/key_pairs.dart index 96e0933..a1f27ee 100644 --- a/lib/nostr/core/key_pairs.dart +++ b/lib/nostr/core/key_pairs.dart @@ -7,7 +7,6 @@ import 'package:equatable/equatable.dart'; /// It is used by the [NostrClient] to sign messages. /// {@endtemplate} class NostrKeyPairs extends Equatable { - /// {@macro nostr_key_pairs} factory NostrKeyPairs({ required String private, @@ -32,6 +31,7 @@ class NostrKeyPairs extends Equatable { private: Nostr.instance.utilsService.random64HexChars(), ); } + /// This is the private generate Key, hex-encoded (64 chars) final String private; diff --git a/lib/nostr/dart_nostr.dart b/lib/nostr/dart_nostr.dart index 6fe40f1..2915a76 100644 --- a/lib/nostr/dart_nostr.dart +++ b/lib/nostr/dart_nostr.dart @@ -10,7 +10,6 @@ import 'package:dart_nostr/nostr/instance/utils/utils.dart'; /// This class is responsible for handling the connection to all relays. /// {@endtemplate} class Nostr implements NostrServiceBase { - /// {@macro nostr_service} factory Nostr() { // utils.log("A Nostr instance created successfully."); @@ -21,6 +20,7 @@ class Nostr implements NostrServiceBase { Nostr._() { utils = NostrClientUtils(); } + /// Wether this instance resources are disposed or not. bool _isDisposed = false; diff --git a/lib/nostr/instance/relays/relays.dart b/lib/nostr/instance/relays/relays.dart index ebea853..e7525d4 100644 --- a/lib/nostr/instance/relays/relays.dart +++ b/lib/nostr/instance/relays/relays.dart @@ -218,6 +218,7 @@ class NostrRelays implements NostrRelaysBase { }); } + @override Future sendCountEventToRelaysAsync( NostrCountEvent countEvent, { required Duration timeout, diff --git a/lib/nostr/instance/tlv/tlv_utils.dart b/lib/nostr/instance/tlv/tlv_utils.dart index 4a37d4c..5cc3572 100644 --- a/lib/nostr/instance/tlv/tlv_utils.dart +++ b/lib/nostr/instance/tlv/tlv_utils.dart @@ -66,7 +66,8 @@ class NostrTLV implements TLVBase { /// concatenate/chain list bytes Uint8List _concatenateUint8List(List lists) { - final totalLength = lists.map((list) => list.length).reduce((a, b) => a + b); + final totalLength = + lists.map((list) => list.length).reduce((a, b) => a + b); final result = Uint8List(totalLength); var offset = 0; for (final list in lists) { diff --git a/lib/nostr/model/event/event.dart b/lib/nostr/model/event/event.dart index a85d9af..ead2b92 100644 --- a/lib/nostr/model/event/event.dart +++ b/lib/nostr/model/event/event.dart @@ -12,7 +12,6 @@ import 'package:equatable/equatable.dart'; /// You can use [NostrEvent.fromPartialData] to create an event with less fields and lower complexity.. /// {@endtemplate} class NostrEvent extends Equatable { - const NostrEvent({ required this.content, required this.createdAt, @@ -41,19 +40,22 @@ class NostrEvent extends Equatable { createdAt: DateTime.fromMillisecondsSinceEpoch( (event['created_at'] as int) * 1000, ), - tags: List>.from((event['tags'] as List) - .map( - (nestedElem) => (nestedElem as List) - .map( - (nestedElemContent) => nestedElemContent.toString(), - ) - .toList(), - ) - .toList(),), + tags: List>.from( + (event['tags'] as List) + .map( + (nestedElem) => (nestedElem as List) + .map( + (nestedElemContent) => nestedElemContent.toString(), + ) + .toList(), + ) + .toList(), + ), subscriptionId: decoded[1] as String?, ots: event['ots'] as String?, ); } + /// The id of the event. final String id; diff --git a/lib/nostr/model/nostr_event_key.dart b/lib/nostr/model/nostr_event_key.dart index 7ed9cb8..1de9525 100644 --- a/lib/nostr/model/nostr_event_key.dart +++ b/lib/nostr/model/nostr_event_key.dart @@ -5,13 +5,13 @@ import 'package:equatable/equatable.dart'; /// This clas can be used to identify an event uniquely based on external factors such as the subscription id. /// {@endtemplate} class NostrEventKey extends Equatable { - /// {@macro nostr_event_key} const NostrEventKey({ required this.eventId, required this.sourceSubscriptionId, required this.originalSourceEvent, }); + /// The id of the event. final String eventId; diff --git a/lib/nostr/model/nostr_events_stream.dart b/lib/nostr/model/nostr_events_stream.dart index e2cca7f..a8cbedd 100644 --- a/lib/nostr/model/nostr_events_stream.dart +++ b/lib/nostr/model/nostr_events_stream.dart @@ -7,13 +7,13 @@ import 'package:equatable/equatable.dart'; /// Represents a holde class for the stream of nostr events and the subscription id. /// {@endtemplate} class NostrEventsStream extends Equatable { - /// {@macro nostr_events_stream} const NostrEventsStream({ required this.stream, required this.subscriptionId, required this.request, }); + /// This the stream of nostr events that you can listen to and get the events. final Stream stream; diff --git a/lib/nostr/model/ok.dart b/lib/nostr/model/ok.dart index ab17030..ec4f72f 100644 --- a/lib/nostr/model/ok.dart +++ b/lib/nostr/model/ok.dart @@ -7,13 +7,13 @@ import 'package:equatable/equatable.dart'; /// The ok command that is sent to the server when an event is accepted or declined. /// {@endtemplate} class NostrEventOkCommand extends Equatable { - /// {@macro nostr_event_ok_command} const NostrEventOkCommand({ required this.eventId, this.isEventAccepted, this.message, }); + /// The event ID of which this ok command was sent. final String eventId; diff --git a/lib/nostr/model/relay_informations.dart b/lib/nostr/model/relay_informations.dart index 5d02527..4897b02 100644 --- a/lib/nostr/model/relay_informations.dart +++ b/lib/nostr/model/relay_informations.dart @@ -1,7 +1,6 @@ import 'package:equatable/equatable.dart'; class RelayInformations extends Equatable { - const RelayInformations({ required this.contact, required this.description, diff --git a/lib/nostr/model/request/close.dart b/lib/nostr/model/request/close.dart index 91cb4f7..67817d1 100644 --- a/lib/nostr/model/request/close.dart +++ b/lib/nostr/model/request/close.dart @@ -7,11 +7,11 @@ import 'package:equatable/equatable.dart'; /// A request to close a subscription with a given subscription id. /// {@endtemplate} class NostrRequestClose extends Equatable { - /// {@macro nostr_request_close} const NostrRequestClose({ required this.subscriptionId, }); + /// The subscription id. final String subscriptionId; diff --git a/lib/nostr/model/request/filter.dart b/lib/nostr/model/request/filter.dart index 28a6e3f..9813cc3 100644 --- a/lib/nostr/model/request/filter.dart +++ b/lib/nostr/model/request/filter.dart @@ -4,7 +4,6 @@ import 'package:equatable/equatable.dart'; /// NostrFilter is a filter that can be used to match events. /// {@endtemplate} class NostrFilter extends Equatable { - /// {@macro nostr_filter} const NostrFilter({ this.ids, @@ -56,6 +55,7 @@ class NostrFilter extends Equatable { limit: limit, ); } + /// a list of event ids to filter with. final List? ids; diff --git a/lib/nostr/model/tlv.dart b/lib/nostr/model/tlv.dart index 85a88c1..d9d8716 100644 --- a/lib/nostr/model/tlv.dart +++ b/lib/nostr/model/tlv.dart @@ -1,7 +1,6 @@ import 'dart:typed_data'; class TLV { - TLV({ required this.type, required this.length, diff --git a/lib/nostr/service/registry.dart b/lib/nostr/service/registry.dart index 6f3cf17..67c723f 100644 --- a/lib/nostr/service/registry.dart +++ b/lib/nostr/service/registry.dart @@ -13,7 +13,6 @@ import 'package:meta/meta.dart'; /// {@endtemplate} @protected class NostrRegistry { - /// {@macro nostr_registry} NostrRegistry({required this.utils}); final NostrClientUtils utils; diff --git a/lib/nostr/service/web_sockets.dart b/lib/nostr/service/web_sockets.dart index 1c25ea4..91f9895 100644 --- a/lib/nostr/service/web_sockets.dart +++ b/lib/nostr/service/web_sockets.dart @@ -6,7 +6,6 @@ import 'package:dart_nostr/nostr/core/utils.dart'; /// A service that manages the relays web sockets connections /// {@endtemplate} class NostrWebSocketsService { - /// {@macro nostr_web_sockets_service} NostrWebSocketsService({ required this.utils, diff --git a/pubspec.yaml b/pubspec.yaml index a6db478..6ed14ef 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,9 +1,7 @@ name: dart_nostr -description: This is a helper package that simplify and accelerate the use of Nostr protocal in Dart/Flutter environment -version: 6.1.0 +description: Develop Scalable Dart/Flutter Nostr clients quickly and easily +version: 7.0.0 repository: https://github.com/anasfik/nostr/ -issue_tracker: https://github.com/anasfik/nostr/issues -documentation: https://anasfik.github.io/nostr/ environment: sdk: ">=3.0.0 <=3.2.5"