toEvent method

Future<Nip01Event> toEvent(
  1. EventSigner? signer
)

Implementation

Future<Nip01Event> toEvent(EventSigner? signer) async {
  String content = "";
  List<Nip51ListElement> privateElements =
      elements.where((element) => element.private).toList();
  if (privateElements.isNotEmpty && signer != null) {
    String json = jsonEncode(privateElements
        .map((element) => [element.tag, element.value])
        .toList());
    content = await signer.encrypt(json, signer.getPublicKey()) ?? '';
  }
  Nip01Event event = Nip01Event(
    pubKey: pubKey,
    kind: kind,
    tags: elements
        .where((element) => !element.private)
        .map((element) => [element.tag, element.value])
        .toList(),
    content: content,
    createdAt: createdAt,
  );
  return event;
}