Skip to content

Commit

Permalink
chore!: make EventSigner sign method async
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-orion committed Dec 5, 2024
1 parent 7f3ca51 commit b7d5310
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion example/nostr_dart_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void main() async {

final KeyStore keyStore = KeyStore.generate();

final EventMessage event = EventMessage.fromData(
final EventMessage event = await EventMessage.fromData(
signer: keyStore,
kind: 0,
content: '{"name":"test"}',
Expand Down
2 changes: 1 addition & 1 deletion example/relay_connection_custom_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void main() async {

final KeyStore keyStore = KeyStore.generate();

final EventMessage event = EventMessage.fromData(
final EventMessage event = await EventMessage.fromData(
signer: keyStore,
kind: 0,
content: '{"name":"test"}',
Expand Down
4 changes: 3 additions & 1 deletion lib/src/crypto/key_store.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'dart:async';

import 'package:nostr_dart/src/crypto/utils.dart';

mixin EventSigner {

String get publicKey;

String sign({required String message});
FutureOr<String> sign({required String message});

}

Expand Down
7 changes: 4 additions & 3 deletions lib/src/model/event_message.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:convert';

import 'package:nostr_dart/nostr_dart.dart';
Expand Down Expand Up @@ -96,13 +97,13 @@ class EventMessage extends RelayMessage {
this.subscriptionId,
});

factory EventMessage.fromData({
static FutureOr<EventMessage> fromData({
required EventSigner signer,
required int kind,
required String content,
List<List<String>> tags = const [],
DateTime? createdAt,
}) {
}) async {
createdAt ??= DateTime.now();

final String eventId = calculateEventId(
Expand All @@ -120,7 +121,7 @@ class EventMessage extends RelayMessage {
kind: kind,
tags: tags,
content: content,
sig: signer.sign(message: eventId),
sig: await signer.sign(message: eventId),
);
}

Expand Down
4 changes: 2 additions & 2 deletions test/event_message_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ void main() {
);
});

test('might be instantiated with fromData constructor', () {
test('might be instantiated with fromData constructor', () async {
final KeyStore keyStore = KeyStore.fromPrivate(privateKey);
final EventMessage message = EventMessage.fromData(
final EventMessage message = await EventMessage.fromData(
signer: keyStore,
kind: kind,
content: content,
Expand Down

0 comments on commit b7d5310

Please sign in to comment.