Closed alandotcom closed 8 years ago
cc @naoitoi @MatthewPhinney @gip
I think this generally looks good, but we conflate "json without signature" and "json with invalid signature" (since both return false
). I think these two cases are important to distinguish between. A clearer API might be something like
verify = function (json, signature, pubKey)
I'm fine with this change, provided the connenctor logs the json that failed to validate, so we can pinpoint if it was due to an incorrect signature, or a missing signature.
LGTM
@clark800 @MatthewPhinney I updated this so that verify
returns an object with some information rather than true/false. The problem is the underlying libraries throw exceptions on anything that's invalid (include invalid public key or public key mismatch) which isn't useful to a caller of this method
but we conflate "json without signature" and "json with invalid signature" (since both return false)
The caller shouldn't have to care about the shape of the object or know that a signed JSON object contains a signature at the top level key signature
. Imagine if we wanted to change from JCS to some other signing implementation that created a signed object with a different shape? The caller code would have to change.
@MatthewPhinney
There's some duplication in the unit tests, but I'd prefer to clean that up in a later commit
@clark800 can you look at the changes from the latest commit?
latest changes LGTM
The caller shouldn't have to care about the shape of the object or know that a signed JSON object contains a signature at the top level key signature.
I wasn't trying to argue that the caller should need to understand how the json is structured, but rather that we may want more granular error messages, in the case of failed validations. Looks like 4c28bd0c149a03fc18adf52d0f7e148ee5661173 addresses this, so LGTM.
Returning false avoids having to wrap the verify call in a try/catch everywhere it's used. For example, if a Connector receives an unsigned notification