nip01 0.1.0 copy "nip01: ^0.1.0" to clipboard
nip01: ^0.1.0 copied to clipboard

This package contains the basic protocol flows for Nostr as described in the NIP-01.

Features #

This package contains the basic protocol flows for Nostr as described in the NIP-01. This includes the creation of key pairs, event creation, event publishing, event requests, and event listening among others.

Getting started #

Installation #

In your pubspec.yaml file add:

dependencies:
  nip01: ^0.1.0

Usage #

import 'package:nip01/nip01.dart';
import 'package:dartstr_utils/dartstr_utils.dart';

final keyPair = KeyPair.generate();
print('privateKey: ${keyPair.privateKey}');

final nip01Repository = Nip01RepositoryImpl(
    relayClientsManager: RelayClientsManagerImpl(['wss://example.relay.org']),
);

final partialEvent = Event(
    pubkey: '981cc2078af05b62ee1f98cff325aac755bf5c5836a265c254447b5933c6223b',
    createdAt: 1672175320,
    kind: EventKind.textNote.value,
    tags: [],
    content: "This is an event.",
);

final signedEvent = partialEvent.sign(keyPair);

final isPublished = await nip01Repository.publishEvent(signedEvent);
if (!isPublished) {
    throw Exception('Failed to publish event');
}

// Subscribe to events on the relay
final String subscriptionId = SecretGenerator.secretHex(
    64,
); // SecretGenerator is part of the dartstr_utils package

final eventsStream = await nip01Repository.subscribeToEvents(
    subscriptionId,
    [
      Filters(
        authors: [keyPair.publicKey],
        since: 1672175320,
      ),
    ],
);

eventsStream.listen((event) {
    print('Received event: $event');
});

Additional information #

This package is part of the Dartstr monorepo, which contains a set of modular and compatible Dart packages of different Nostr NIPS and utilities. Import just the packages of NIPS you need and keep your project lightweight. See the Dartstr monorepo for all available packages.

2
likes
150
pub points
33%
popularity

Publisher

verified publisherkumuly.dev

This package contains the basic protocol flows for Nostr as described in the NIP-01.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

async, bip340, convert, crypto, dartstr_utils, equatable, meta, web_socket_channel

More

Packages that depend on nip01