nostr_dart 0.6.4 nostr_dart: ^0.6.4 copied to clipboard
A Nostr protocol client API for building censorship-resistant social network applications in Dart/Flutter.
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
andcontact_list
events to connected relays. - Request events and subscribe to updates.
Supported Nostr Implementation Possibilities:
- NIP-01: Basic protocol flow description
- NIP-02: Contact List and Petnames
- NIP-11: Relay Information Document
- NIP-13: Proof of Work
- NIP-15: End of Stored Events Notice
- NIP-20: Command Results
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