Skip to content

Latest commit

 

History

History

nip26

Dart implementation of Delegated Event Signing in Nostr as described in NIP-26.

Features

This package lets you create delegation tokens as a delegator, construct delegated events as a delegatee and check and get the delegator from an event as a client.

Usage

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

final delegatorRootKeyPair = KeyPair.generate();
final delegator = Delegator(delegatorRootKeyPair);

final delegateeKeyPair = KeyPair.generate();

final now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
final conditions = ConditionsQuery(
    kinds: [EventKind.textNote.value],
    createdAfter: now,
    createdBefore: now + 600,
);

final token = delegator.createDelegationToken(
    delegateePubkey: delegateeKeyPair.publicKey,
    conditionsQuery: conditions,
);

final delegatee = Delegatee(
    delegateeKeyPair,
    delegatorPubkey: delegatorRootKeyPair.publicKey,
    conditions: conditions,
    token: token,
);

final event = delegatee.constructSignedEvent(
    createdAt: now + 1,
    kind: EventKind.textNote.value,
    content: 'Hello, World in name of delegator!',
);

final delegator = Client.tryGetDelegatorOfEvent(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.