Skip to content

Commit

Permalink
[ Add ] 7.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
anasfik committed Jan 20, 2024
1 parent e5aa83e commit eb6ca05
Show file tree
Hide file tree
Showing 25 changed files with 87 additions and 72 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 4 additions & 2 deletions example/check_key_validity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)}',
);
}
5 changes: 3 additions & 2 deletions example/get_pubkey_from_identifier_nip_05.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import 'package:dart_nostr/dart_nostr.dart';

Future<void> 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);
}
15 changes: 8 additions & 7 deletions example/listening_to_events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
32 changes: 15 additions & 17 deletions example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Future<void> main() async {

// init relays
await Nostr.instance.relaysService.init(
relaysUrl: ["wss://relay.damus.io"],
relaysUrl: ['wss://relay.damus.io'],
);

final currentDateInMsAsString =
Expand All @@ -20,17 +20,17 @@ Future<void> 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();
Expand All @@ -40,7 +40,7 @@ Future<void> main() async {
subscriptionId: subscriptionId,
filters: [
NostrFilter(
kinds: [1],
kinds: const [1],
t: [currentDateInMsAsString],
authors: [keyPair.public],
),
Expand All @@ -50,40 +50,38 @@ Future<void> 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,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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}');
},
);
}
8 changes: 5 additions & 3 deletions example/send_event_asynchronously.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import 'dart:async';
import 'package:dart_nostr/dart_nostr.dart';

Future<void> main(List<String> 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();

Expand Down
1 change: 0 additions & 1 deletion lib/dart_nostr.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

export './nostr/core/key_pairs.dart';
export './nostr/core/utils.dart';
export './nostr/model/export.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/nostr/core/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion lib/nostr/core/key_pairs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion lib/nostr/dart_nostr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -21,6 +20,7 @@ class Nostr implements NostrServiceBase {
Nostr._() {
utils = NostrClientUtils();
}

/// Wether this instance resources are disposed or not.
bool _isDisposed = false;

Expand Down
1 change: 1 addition & 0 deletions lib/nostr/instance/relays/relays.dart
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class NostrRelays implements NostrRelaysBase {
});
}

@override
Future<NostrCountResponse> sendCountEventToRelaysAsync(
NostrCountEvent countEvent, {
required Duration timeout,
Expand Down
3 changes: 2 additions & 1 deletion lib/nostr/instance/tlv/tlv_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class NostrTLV implements TLVBase {

/// concatenate/chain list bytes
Uint8List _concatenateUint8List(List<Uint8List> 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) {
Expand Down
22 changes: 12 additions & 10 deletions lib/nostr/model/event/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -41,19 +40,22 @@ class NostrEvent extends Equatable {
createdAt: DateTime.fromMillisecondsSinceEpoch(
(event['created_at'] as int) * 1000,
),
tags: List<List<String>>.from((event['tags'] as List)
.map(
(nestedElem) => (nestedElem as List)
.map(
(nestedElemContent) => nestedElemContent.toString(),
)
.toList(),
)
.toList(),),
tags: List<List<String>>.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;

Expand Down
2 changes: 1 addition & 1 deletion lib/nostr/model/nostr_event_key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion lib/nostr/model/nostr_events_stream.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<NostrEvent> stream;

Expand Down
2 changes: 1 addition & 1 deletion lib/nostr/model/ok.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion lib/nostr/model/relay_informations.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:equatable/equatable.dart';

class RelayInformations extends Equatable {

const RelayInformations({
required this.contact,
required this.description,
Expand Down
2 changes: 1 addition & 1 deletion lib/nostr/model/request/close.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading

0 comments on commit eb6ca05

Please sign in to comment.