I'll update this thread with my progress of the #golang code for
ssb message verification
According to the chapter on meesage formating from the protocol guide
Before signing a message it must be formatted as JSON as shown above. The formatting rules are:
- Two spaces for indentation.
- Dictionary entries and list elements each on their own line.
- Empty dictionaries appear as {} and empty lists appear as [].
- One space after the colon : for dictionary keys.
- No trailing newline.
To verify the signature, first remove the signature field from the message. Make sure the remaining message is formatted as JSON using the same formatting rules. Here the order of dictionary keys matters; the keys must be in the same order that you received them.
This rules out marshaling the message into map[string]interface{}
in go, since iterating over any map will have random order. We could however, if we knew or decided on some canonical ordering, see the issue linked here for more background on msg canonicalization.
I tried the approach that @Vendan chose for his client. Defining the fields as a struct{}
will maintain their order as defined in the code.
I still can't fully sync my feed with this approach but I'm not fully sure yet why. The messag keys start diverging so that latestMsg.key != newMsg.previous
.
The approach I am currently trying is to use the json tokenizer to achive the formatting rules while maintaining the odering in which messages came in.
Some other here be dragons terretory yet to be discovered:
- js also uses utf16 strings, i heard..?
- the monotonic timestamps + the fact that js uses ieee754 floats for everything