dart_nostr is a Dart and Flutter SDK for building Nostr applications. It handles relay connections, event signing and publishing, typed subscription management, key tooling, and NIP utilities — so you can focus on your product instead of the protocol.
Full API guides, per-feature references, and advanced configuration are in the documentation site:
- Introduction and overview
- Installation
- Quick start
- Keys
- Relays and events
- Identity (NIP-05, NIP-19)
- Error handling
- Advanced configuration
Source documentation is also available on pub.dev.
dependencies:
dart_nostr: ^10.0.0dart pub add dart_nostr
# or
flutter pub add dart_nostrimport 'package:dart_nostr/dart_nostr.dart';Future<void> main() async {
final nostr = Nostr.instance;
// Connect to relays
final connectResult = await nostr.connect([
'wss://relay.damus.io',
'wss://nos.lol',
]);
if (connectResult.isFailure) {
print(connectResult.failureOrNull);
return;
}
// Generate a key pair
final keyPair = nostr.keys.generateKeyPair();
// Publish a note
final event = NostrEvent.fromPartialData(
kind: 1,
content: 'Hello from dart_nostr',
keyPairs: keyPair,
);
final publishResult = await nostr.publish(event);
publishResult.fold(
(ok) => print('published: ${ok.isEventAccepted}'),
(failure) => print('failed: ${failure.message}'),
);
// Subscribe to recent notes
final subResult = nostr.subscribeRequest(
NostrRequest(
filters: [
NostrFilter(
kinds: [1],
limit: 20,
since: DateTime.now().subtract(const Duration(hours: 1)),
),
],
),
);
subResult.fold(
(stream) {
stream.stream.listen((event) => print(event.content));
},
(failure) => print('subscribe failed: ${failure.message}'),
);
}Every operation that can fail returns NostrResult<T>:
result.fold(
(value) { /* success */ },
(failure) {
print(failure.message);
print(failure.code);
print(failure.isRetryable);
},
);final keyPair = nostr.keys.generateKeyPair();
print(keyPair.public); // hex pubkey
print(keyPair.private); // hex privkey
// Reconstruct from private key
final same = nostr.keys.generateKeyPairFromExistingPrivateKey(keyPair.private);
// NIP-19 bech32 encoding
final npub = nostr.bech32.encodePublicKeyToNpub(keyPair.public);
final nsec = nostr.bech32.encodePrivateKeyToNsec(keyPair.private);
// Sign and verify
final sig = nostr.keys.sign(privateKey: keyPair.private, message: 'hello');
final ok = nostr.keys.verify(publicKey: keyPair.public, message: 'hello', signature: sig);final pubKey = await nostr.utils.pubKeyFromIdentifierNip05(
internetIdentifier: 'user@domain.com',
);
final verified = await nostr.utils.verifyNip05(
internetIdentifier: 'user@domain.com',
pubKey: pubKey ?? '',
);Nostr.instance— singleton;Nostr()— isolated instance with independent relay poolnostr.connect()/nostr.disconnect()— connection lifecycle with typed resultsnostr.publish()— signed event submission with relay OK responsenostr.subscribeRequest()/nostr.subscribeFilters()— typed stream subscriptionsnostr.count()— NIP-45 event count requestsnostr.keys— key generation, derivation, signing, verificationnostr.bech32— NIP-19 encode/decode (npub, nsec, nprofile, nevent)nostr.utils— NIP-05 resolution and verificationnostr.relays— low-level relay pool for protocol workNostrResult<T>/NostrFailure— typed error model throughoutNostrClientOptions/NostrRetryPolicy— configurable timeouts and retry
| Surface | Use when |
|---|---|
Top-level facade (nostr.connect, nostr.publish, ...) |
Building app features, need typed results and lifecycle management |
nostr.relays |
Raw relay operations, protocol research, custom orchestration |
nostr.services |
Direct access to internal components, building abstractions |
The example directory contains runnable samples:
- main.dart — end-to-end workflow covering all major features
- generate_key_pair.dart — key generation and validation
- sending_event_to_relays.dart — publish metadata and notes
- listening_to_events.dart — subscriptions and filters
- signing_and_verfiying_messages.dart — sign and verify
- verify_nip05.dart — NIP-05 verification
- relay_document_nip_11.dart — relay info fetch
dart testFork the repository, make changes, and open a pull request. Include tests where appropriate.
MIT. See LICENSE.