nip01 0.1.1+3 copy "nip01: ^0.1.1+3" to clipboard
nip01: ^0.1.1+3 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.

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');
});
copied to clipboard

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
points
70
downloads

Publisher

verified publisherkumuly.dev

Weekly Downloads

2024.07.09 - 2025.01.21

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

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

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

More

Packages that depend on nip01