NostrEvent.fromRelayMessage constructor
NostrEvent.fromRelayMessage(
- 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.fromRelayMessage(String data) {
assert(canBeDeserializedEvent(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'] * 1000,
),
tags: List<List<String>>.from((event['tags'] as List)
.map(
(nestedElem) => (nestedElem as List)
.map(
(nestedElemContent) => nestedElemContent.toString(),
)
.toList(),
)
.toList()),
subscriptionId: decoded.length == 3 ? decoded[1] as String : null,
ots: event['ots'] as String?,
);
}