NostrEvent.deserialized constructor

NostrEvent.deserialized(
  1. String data
)

This represents a nostr event that is received from the relays, it takes directly the relay message which is serialized, and handles all internally

Implementation

factory NostrEvent.deserialized(String data) {
  assert(NostrEvent.canBeDeserialized(data));
  final decoded = jsonDecode(data) as List;

  final event = decoded.last as Map<String, dynamic>;
  return NostrEvent(
    id: event['id'] as String,
    kind: event['kind'] as int,
    content: event['content'] as String,
    sig: event['sig'] as String,
    pubkey: event['pubkey'] as String,
    createdAt: DateTime.fromMillisecondsSinceEpoch(
      (event['created_at'] as int) * 1000,
    ),
    tags: List<List<String>>.from(
      (event['tags'] as List)
          .map(
            (nestedElem) => (nestedElem as List)
                .map(
                  (nestedElemContent) => nestedElemContent.toString(),
                )
                .toList(),
          )
          .toList(),
    ),
    subscriptionId: decoded[1] as String?,

  );
}