so, couldn't sleep because allergy still
i forgot how long the egg allergy takes to fully clear up, and it also seems to onset most of all at bedtime
so... i have an espresso to calm it down, and sit to write this binary encode/decode test
i have found the bug, i think
it's the old empty tag that should be a nil tag trick
original:
> "tags":[]
re-encodes from runtime format:
> "tags":[]
decodes back from being encoded from runtime to binary and binary back to runtime back to json:
> "tags":[[]]
well, that's the first, but hundreds of examples of this... it's from empty tags... most clients don't actually produce events with no tags at all, mostly... they are kooky looking events too, with strings of decimal numbers comma separated like they are encoding binary with decimal for whatever reason, instead of UTF-8
but digging further I also see another error:
```
{"id":"6f38c8cce14f986c86b0ee9808643d2f6827ac29168f9f96a96b6a521ea25841","pubkey":"9303ab260a6c7653fc8ea3b041d533c2c678c1e3c4772a05e9f53b8be99869c7","created_at":1715054396,"kind":5,"tags":[["e","7aea510b0c26be894ef641f0478efae0089ba1efb2f3165ad6136279bbb30bbe"],["a",
"31234:9303ab260a6c7653fc8ea3b041d533c2c678c1e3c4772a05e9f53b8be99869c7:de9917f2-9211-4375-8765-39babb31c177"],["k","31234"],["alt","Deletion event"]],"content":"","sig":"1ff9965d3bd7b4d4bcdf23312de2779f2faec93a160ab57ba570268a9042083a0b6e07cedf5cb1df8ec470c28850d21efd998619b4f58641542571ad075548e3"}
{"id":"6f38c8cce14f986c86b0ee9808643d2f6827ac29168f9f96a96b6a521ea25841","pubkey":"9303ab260a6c7653fc8ea3b041d533c2c678c1e3c4772a05e9f53b8be99869c7","created_at":1715054396,"kind":5,"tags":[["e","7aea510b0c26be894ef641f0478efae0089ba1efb2f3165ad6136279bbb30bbe"],["a",
"0:39333033616232363061366337363533666338656133623034316435333363326336373863316533633437373261303565396635336238626539393836396337:de9917f2-9211-4375-8765-39babb31c177"],["k","31234"],["alt","Deletion event"]],"content":"",
"sig":"1ff9965d3bd7b4d4bcdf23312de2779f2faec93a160ab57ba570268a9042083a0b6e07cedf5cb1df8ec470c28850d21efd998619b4f58641542571ad075548e3"}
```
there is an `a` tag in there (it's a delete) where the re-decoded form has failed to encode correctly, i've written code in the binary encoder to correctly handle a tags, they are kind:pubkey:string and it looks a lot like this one did not format the value correctly, those numbers are clearly decimal form of hexadecimal, and the initial kind value was not encoded (or failed decoding back)
i'd say i'm going to find several bugs in there with this, this is two to chalk up for tomorrow morning's work
i'd say i'll have every last bug in the binary encode/decode ironed out with this in hand
there's also some rare cases of what seems to be incorrectly computed IDs but i've made a check to see that when they are encoded back to JSON, it only prints information about this if the re-marshaled form is different from the original
looks like most clients even when they were buggy ordered the object fields of the event the same as in the nip-01 spec, so if it decodes the same data but the ID check is wrong then the event is invalid and can't be stored because the signature does not match the canonical event formatted hash (if the very same fields re-encode to json identically then absolutely no question the event is invalid
sorta thinking about that though, perhaps the signature validation could stand in after that fail, so if the signature is still valid then it gets a "valid" stamp as well just so these events are there... perhaps the relay could reply with a NOTICE about this or even put a message in the OK response saying the event ID is wrong but the signature is valid on the given ID
not that any clients actually honor or do anything useful with these things but ok, best effort and all... point being that i wasn't gonna allow this but maybe i should? thoughts?
some relays don't check, obviously, they must be really well written *cough*