Event Details

This is a KIND 5391 event created on 2024-03-25 23:51:32 (7 months, 3 weeks ago). Debug this event chain.

{
  "id": "662cc584ce04bafb5393ab5a8624010fe854d55298e82c22bca8ca657d1a7b31",
  "pubkey": "a029df4a2c4a042f4b23a0d6197fd9680805327e023eb1705c70d13db9821a3d",
  "created_at": 1711410692,
  "kind": "5391",
  "tags": [
    [
      "e",
      "67c2163ef886642d4e3a0c9d99c4b056a0176320a88b3a502595d1bf9f8b15dc",
      "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/nevent1qqsx0ssk8mugvepdfcaqe8vecjc9dgqhvvs23ze62qjet5dln793thqpremhxue69uhkgctndpnkcmmh946x2um59ehx7um5wgcjucm0d5q3vamnwvaz7tmjv4kxz7fwwpexjmtpdshxuet5qy28wumn8ghj7un9d3shjtnyv9kh2uewd9hszymhwden5te0wfjkcctev93xcefwdaexwqg5waehxw309aex2mrp0yhxummnw3ezumt9qyxhwumn8ghj7mn0wvhxcmmvqyt8wumn8ghj7un9d3shjtnwdaehgu3wvfskueqzyzsznh62939qgt6tywsdvxtlm95qspfj0cpravtst3cdz0desgdr6qcyqqqqqqgn47xm6"
    ],
    [
      "index",
      "1"
    ],
    [
      "x",
      "a33194f438851920cc43d59c61a386b79adcc5a55b0b64667386cd8f43baaab0"
    ]
  ],
  "content": "bnVsbCkgewoJCQlyZXR1cm4gbnVsbDsKCQl9CgoJCXJldHVybiB7CgkJCWJhciA6IGJhckluZGV4LAoJCQliZWF0IDogYmVhdDE2SW5kZXgsCgkJfTsKCX07CgoJdGhpcy5nZXRCbGlwU3RhdGUgPSBmdW5jdGlvbigpIHsKCQlyZXR1cm4gYWN0aXZlU2Z4OwoJfTsKCgl0aGlzLnBsYXlOb3RlID0gZnVuY3Rpb24ocGl0Y2gsIGluc3RydW1lbnQsIGNoYW5uZWwsIGtleSkgewoJCWJlYXQxNiA9IHRl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W107CgkJdmFyIGN1ckl0ZW1JbmRleCA9IC0xOyAvLyAtMSBpbmRpY2F0ZXMgbm90IHJlYWRpbmcgYW4gaXRlbSB5ZXQKCQl2YXIgcmVxdWlyZWRMZWFkaW5nV2hpdGVzcGFjZSA9IC0xOwoKCQlmdW5jdGlvbiBwYXJzZVNlcXVlbmNlSXRlbUxpbmUoc3RhdGUpIHsKCQkJ",
  "sig": "d7c87803988520b04cb37d00a5bb605228bd831683dd4864ae2acd54f18c30faef01008fafbc41011990871efc6178e7ff39cd2a223fb69886b356151c5e5a0d"
}

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