Event.deserialize constructor

Event.deserialize(
  1. dynamic input, {
  2. bool verify = true,
})

Deserialize a nostr event message

  • "EVENT", event JSON as defined above
  • "EVENT", subscription_id, event JSON as defined above
Event event = Event.deserialize([
  "EVENT",
  {
    "id": "67bd60e47d7fdddadebff890143167bcd7b5d28b2c3008eae40e0ac5ba0e6b34",
    "kind": 1,
    "pubkey":
        "36685fa5106b1bc03ae7bea82eded855d8f56c41db4c8bdef8099e1e0f2b2afa",
    "created_at": 1674403511,
    "content":
        "Block 773103 was just confirmed. The total value of all the non-coinbase outputs was 61,549,183,849 sats, or \$14,025,828",
    "tags": [],
    "sig":
        "4912a6850a711a876fd2443771f69e094041f7e832df65646a75c2c77989480cce9b41aa5ea3d055c16fe5beb7d11d3d5fa29b4c4046c150b09393c4d3d16eb4"
  }
]);

Implementation

factory Event.deserialize(input, {bool verify = true}) {
  Map<String, dynamic> json = {};
  String? subscriptionId;
  if (input.length == 2) {
    json = input[1] as Map<String, dynamic>;
  } else if (input.length == 3) {
    json = input[2] as Map<String, dynamic>;
    subscriptionId = input[1] as String;
  } else {
    throw Exception('invalid input');
  }

  List<List<String>> tags = (json['tags'] as List<dynamic>)
      .map((e) => (e as List<dynamic>).map((e) => e as String).toList())
      .toList();

  return Event(
    json['id'],
    json['pubkey'],
    json['created_at'],
    json['kind'],
    tags,
    json['content'],
    json['sig'],
    subscriptionId: subscriptionId,
    verify: verify,
  );
}