nip01 0.0.2 copy "nip01: ^0.0.2" to clipboard
nip01: ^0.0.2 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.0.2

Usage #

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

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

final relayCommunication = RelayCommunicationImpl(
    RelayConnectionProviderImpl(
        'wss://relay01.nostr.org',
    ),
);

relayCommunication.init();

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

final signedEvent = partialEvent.sign(creatorKeyPair);

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

// Listen to events
final eventsSubscription = relayCommunication.events.listen(
    (event) {
        // Handle event
    },
);

// Subscribe to events on the relay
final String subscriptionId = SecretGenerator.secretHex(64); // SecretGenerator is part of the dartstr_utils package
relayCommunication.requestEvents(
    subscriptionId,
    [
        Filters(
            authors: keyPair.publicKey,
            since: 1672175320,
        )
    ],
);

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
160
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

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

More

Packages that depend on nip01