getEventId static method

String getEventId({
  1. required int kind,
  2. required String content,
  3. required DateTime createdAt,
  4. required List tags,
  5. required String pubkey,
})

Creates the id of an event, based on Nostr specs.

Implementation

static String getEventId({
  required int kind,
  required String content,
  required DateTime createdAt,
  required List tags,
  required String pubkey,
}) {
  List data = [
    0,
    pubkey,
    createdAt.millisecondsSinceEpoch ~/ 1000,
    kind,
    tags,
    content
  ];

  final serializedEvent = jsonEncode(data);
  final bytes = utf8.encode(serializedEvent);
  final digest = sha256.convert(bytes);
  final id = hex.encode(digest.bytes);

  return id;
}