nostr_dart 0.6.3 copy "nostr_dart: ^0.6.3" to clipboard
nostr_dart: ^0.6.3 copied to clipboard

A Nostr protocol client API for building censorship-resistant social network applications in Dart/Flutter.

Dart

A Nostr client library written in Dart.

Features #

Use this library in your Dart/Flutter app to:

  • Connect to Nostr relays.
  • Publish set_metadata, text_note, recommend_server and contact_list events to connected relays.
  • Request events and subscribe to updates.

Supported Nostr Implementation Possibilities:

Getting started #

Add the following to your pubspec.yaml:

dependencies:
  nostr_dart: ^[version]

Usage #

Initialise nostr_dart:

import 'package:nostr_dart/nostr_dart.dart'

final nostr = Nostr(privateKey: [private key], powDifficulty: [difficulty]);

Add a relay for subscribing to events only:

await nostr.pool.add(Relay([Relay URL]));

Add a relay for subscribing and publishing events:

await nostr.pool.add(Relay([Relay URL], access: WriteAccess.readWrite));

Retrieve relay information:

final info = nostr.pool.info[Relay URL];
print(info.name);

// or 
for (RelayInfo relay in nostr.pool.info.values) {
  print(relay.name);
}

Retrieve events from connected relays and subscribe to updates:

final subId = nostr.pool.subscribe([List of filters], [onEvent callback], [Subscription ID]);

Publish a text note:

nostr.sendTextNote([content], [tags]);

Publish metadata:

nostr.sendMetaData(name: [name], about: [about], picture: [picture url]);

Publish server recommendation:

nostr.recommendServer([Relay URL]);

Publish a contact list:

final contacts = ContactList();
final contact = Contact(publicKey: [public key], url: [relay url], petname: [petname]);
contacts.add(contact);
nostr.sendContactList(contacts);

Publish an arbitrary event:

final event = Event(publicKey, 1, [], "A beautifully handcrafted event");
nostr.sendEvent(event);

Remove an existing subscription:

nostr.pool.unsubscribe([subscription ID]);

Remove a connected relay:

nostr.pool.remove([Relay URL]);

Contributing #

Pull requests are welcome. Please write tests to cover your new feature.

To run nostr_dart tests, from the nostr_dart directory:

dart run build_runner build
dart test
1
likes
0
pub points
23%
popularity

Publisher

unverified uploader

A Nostr protocol client API for building censorship-resistant social network applications in Dart/Flutter.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

bip340, build_runner, clock, crypto, hex, http, mockito, queue, string_validator, web_socket_channel

More

Packages that depend on nostr_dart