nostr_dart 0.4.1 nostr_dart: ^0.4.1 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-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:
await nostr.pool.add([Relay URL]);
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.