Event Details

This is a KIND 5391 event created on 2024-03-24 16:18:35 (7 months, 3 weeks ago). Debug this event chain.

{
  "id": "13c2a89b17429c1642bfeedc5194c5c942a16900dbffab1d46614258160fb5b7",
  "pubkey": "a029df4a2c4a042f4b23a0d6197fd9680805327e023eb1705c70d13db9821a3d",
  "created_at": 1711297115,
  "kind": "5391",
  "tags": [
    [
      "e",
      "97948bc0c73bb7173599cdd0364af026a8d01cdcd2cad13e0ec964c495a2e31e",
      "wss://dashglow-test.nostr1.com",
      "root"
    ],
    [
      "m",
      "text/html"
    ],
    [
      "alt",
      "This is a binary chunk of a web-based video game. Play the full game at https://crashglow.com/game/nevent1qqsf09ytcrrnhdchxkvum5pkftczd2xsrnwd9jk38c8vjexyjk3wx8spremhxue69uhkgctndpnkcmmh946x2um59ehx7um5wgcjucm0d5q3vamnwvaz7tmjv4kxz7fwwpexjmtpdshxuet5qy28wumn8ghj7un9d3shjtnyv9kh2uewd9hszymhwden5te0wfjkcctev93xcefwdaexwqg5waehxw309aex2mrp0yhxummnw3ezumt9qyxhwumn8ghj7mn0wvhxcmmvqyt8wumn8ghj7un9d3shjtnwdaehgu3wvfskueqzyzsznh62939qgt6tywsdvxtlm95qspfj0cpravtst3cdz0desgdr6qcyqqqqqqgvkufgw"
    ],
    [
      "index",
      "2"
    ],
    [
      "x",
      "a33194f438851920cc43d59c61a386b79adcc5a55b0b64667386cd8f43baaab0"
    ]
  ],
  "content": "dmFyIGxpbmVUZXh0ID0gIiI7CgkJCXZhciB3aGl0ZXNwYWNlQ291bnQgPSAwOwoJCQl2YXIgaXNOZXdMaXN0SXRlbSA9IGZhbHNlOwoJCQl2YXIgZW5jb3VudGVyZWROb25XaGl0ZXNwYWNlID0gZmFsc2U7CgoJCQl3aGlsZSAoIXN0YXRlLkRvbmUoKSAmJiAhKHN0YXRlLkNoYXIoKSA9PT0gU3ltLkxpbmVicmVhaykpIHsKCQkJCS8vIGNvdW50IHdoaXRlc3BhY2UgdW50aWwgd2UgaGl0IHR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F0uaGFybW9ueVtpXVtqXS5iZWF0cyAhPSAxKSB7CgkJCQkJd29ybGRTdHIgKz0gdHVuZVtpZF0uaGFybW9ueVtpXVtqXS5iZWF0czsKCQkJCX0KCQkJCWlmICh0dW5lW2lkXS5oYXJtb255W2ldW2pdLmJlYXRzID4gMCkgewoJCQkJCXdvcmxkU3RyICs9IG5vdGVTdHI7CgkJCQl9CgkJCQlpZiAodHVuZVtpZF0uaGFybW9ueVtpXVtqXS5iZWF0cyA+IDAgJiYgdHVuZVtpZF0uaGFybW9ueVtpXVtqXS5vY3RhdmUgIT0gT2N0YXZlWzRdKSB7CgkJCQkJd29ybGRTdHIgKz0gc2VyaWFsaXplT2N0YXZlKHR1bmVbaWRdLmhhcm1vbnlbaV1bal0ub2N0YXZlKTsKCQkJCX0KCQkJCWlmICh0dW5lW2lkXS5oYXJtb255W2ldW2pdLmJlYXRzID4gMCAmJiB0dW5lW2lkXS5oYXJtb255W2ldW2pdLmJsaXAgIT0gdW5kZWZpbmVkKSB7CgkJCQkJd29ybGRTdHIgKz0gIn4iICsgdHVuZVtpZF0uaGFybW9ueVtpXVtqXS5ibGlwOwoJCQkJfQoJCQkJaWYgKGogPCAxNSkgewoJCQkJCXdvcmxkU3RyICs9ICIsIjsKCQkJCX0KCQkJfQoJCQl3b3JsZFN0ciArPSAiXG4iOwoKCQkJaWYgKGkgPCAodHVuZVtpZF0ubWVsb2R5Lmxlbmd0aCAtIDEpKSB7CgkJCQl3b3JsZFN0ciArPSAiPiI7CgkJCQl3b3JsZFN0ciArPSAiXG4iOwoJCQl9CgkJfQoJCWlmICh0dW5lW2lkXS5uYW1lICE9IG51bGwpIHsKCQkJLyogTkFNRSAqLwoJCQl3b3JsZFN0ciArPSAiTkFNRSAiICsg",
  "sig": "57440e090d98f3278423df391666959531bea6b7c0d8b5f925bd489c02744e09ec559ab755fa4d020d687bbc51f40604452979da92ee666402e15f51946f2134"
}

Note: Under active development, if you find a bug, please report it here GitHub & Reach out.