Event Details

This is a KIND 5391 event created on 2023-11-03 04:31:38 (1 year ago). Debug this event chain.

{
  "id": "b694ff17167a9d4bcd7dae028e102ccd1a5dc69afc1218d92d0af1f524d1fd66",
  "pubkey": "e8ed3798c6ffebffa08501ac39e271662bfd160f688f94c45d692d8767dd345a",
  "created_at": 1698985898,
  "kind": "5391",
  "tags": [
    [
      "e",
      "7c90faab92915b934eaeac038f4d0d188fbe66569268d3acfe47add69bc9c638",
      "wss://dashglow-test.nostr1.com",
      "root"
    ],
    [
      "m",
      "text/javascript"
    ],
    [
      "alt",
      "This is a binary chunk of a web-based video game. Play the full game at https://crashglow.com/game/nevent1qqs8ey864wffzkunf6h2cqu0f5x33ra7vetfy6xn4nly0twkn0yuvwqpremhxue69uhkgctndpnkcmmh946x2um59ehx7um5wgcjucm0d5q3vamnwvaz7tmjv4kxz7fwwpexjmtpdshxuet5qy28wumn8ghj7un9d3shjtnyv9kh2uewd9hszymhwden5te0wfjkcctev93xcefwdaexwqg5waehxw309aex2mrp0yhxummnw3ezumt9qyxhwumn8ghj7mn0wvhxcmmvqyt8wumn8ghj7un9d3shjtnwdaehgu3wvfskueqzyr5w6duccml7hlaqs5q6cw0zw9nzhlgkpa5gl9xyt45jmpm8m5695qcyqqqqqqgk7zq5g"
    ],
    [
      "index",
      "4"
    ],
    [
      "x",
      "7c8a57a48656f34ac9a8dd31ca419e155b5ed28df1bd279c74ccdb220579e243"
    ]
  ],
  "content": "TUZTLmNyZWF0ZU5vZGUocGFyZW50LCBuYW1lLCBtb2RlLCBkZXYpOw0KICB9LA0KICByZW5hbWU6IGZ1bmN0aW9uKG9sZF9ub2RlLCBuZXdfZGlyLCBuZXdfbmFtZSkgew0KICAgaWYgKEZTLmlzRGlyKG9sZF9ub2RlLm1vZGUpKSB7DQogICAgdmFyIG5ld19ub2RlOw0KICAgIHRyeSB7DQogICAgIG5ld19ub2RlID0gRlMubG9va3VwTm9kZShuZXdfZGlyLCBuZXdfbmFtZSk7DQogICAgfSBjYXR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ik7DQogIH0gZWxzZSBpZiAoIXJvb3QgJiYgIXBzZXVkbykgew0KICAgdmFyIGxvb2t1cCA9IEZTLmxvb2t1cFBhdGgobW91bnRwb2ludCwgew0KICAgIGZvbGxvd19tb3VudDogZmFsc2UNCiAgIH0pOw0KICAgbW91bnRwb2ludCA9IGxvb2t1cC5wYXRoOw0KICAgbm9kZSA9IGxvb2t1cC5ub2RlOw0KICAgaWYgKEZTLmlzTW91bnRwb2ludChub2RlKSkgew0KICAgIHRocm93IG5ldyBGUy5FcnJub0Vycm9yKDE2KTsNCiAgIH0NCiAgIGlmICghRlMuaXNEaXIobm9kZS5tb2RlKSkgew0KICAgIHRocm93IG5ldyBGUy5FcnJub0Vycm9yKDIwKTsNCiAgIH0NCiAgfQ0KICB2YXIgbW91bnQgPSB7DQogICB0eXBlOiB0eXBlLA0KICAgb3B0czogb3B0cywNCiAgIG1vdW50cG9pbnQ6IG1vdW50cG9pbnQsDQogICBtb3VudHM6IFtdDQogIH07DQogIHZhciBtb3VudFJvb3QgPSB0eXBlLm1vdW50KG1vdW50KTsNCiAgbW91bnRSb290Lm1vdW50ID0gbW91bnQ7DQogIG1vdW50LnJvb3QgPSBtb3VudFJvb3Q7DQogIGlmIChyb290KSB7DQogICBGUy5yb290ID0gbW91bnRSb290Ow0KICB9IGVsc2UgaWYgKG5vZGUpIHsNCiAgIG5vZGUubW91bnRlZCA9IG1vdW50Ow0KICAgaWYgKG5vZGUubW91bnQpIHsNCiAgICBub2RlLm1vdW50Lm1vdW50cy5wdXNoKG1vdW50KTsNCiAgIH0NCiAgfQ0KICByZXR1cm4gbW91bnRSb290Ow0KIH0sDQogdW5tb3VudDogZnVuY3Rpb24obW91bnRwb2ludCkgew0KICB2YXIgbG9va3VwID0gRlMubG9va3VwUGF0aChtb3VudHBvaW50LCB7DQogICBmb2xsb3dfbW91bnQ6IGZhbHNlDQogIH0pOw0KICBpZiAoIUZTLmlzTW91bnRwb2ludChsb29rdXAubm9kZSkpIHsNCiAgIH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wgMSk7DQogIEJyb3dzZXIubWFpbkxvb3Auc2NoZWR1bGVyKCk7DQogfQ0KIGlmIChzaW11bGF0ZUluZmluaXRlTG9vcCkgew0KICB0aHJvdyAiU2ltdWxhdGVJbmZpbml0ZUxvb3AiOw0KIH0NCn0NCg0KdmFyIEJyb3dzZXIgPSB7DQogbWFpbkxvb3A6IHsNCiAgc2NoZWR1bGVyOiBudWxsLA0KICBtZXRob2Q6ICIiLA0KICBjdXJyZW50bHlSdW5uaW5nTWFpbmxvb3A6IDAsDQogIGZ1bmM6IG51bGwsDQogIGFyZzogMCwNCiAgdGltaW5nTW9kZTogMCwNCiAgdGltaW5nVmFsdWU6IDAsDQogIGN1cnJlbnRGcmFtZU51bWJlcjogMCwNCiAgcXVldWU6IFtdLA0KICBwYXVz",
  "sig": "201e54552374c0700902a8f1c0731175d484af879e76933ed2af4c05c6c3104a46e16e6e0c2230895cfb7c65d79b2cbc734ae055f21646187d904430f9ea80de"
}

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