[fix] Multibase public key decoding incorrectly #1279
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The PublicKeyField::key_decoded (i.e. "give me the raw public key bytes") was returning the wrong bytes for the
publicKeyMultibase
verification method field. Particularly, it was returning the [multikey-type + public key bytes] (i.e. the bytes prefixed with the key type), whereas we want it to just return the public key bytes (to align with what the other PublicKeyField variants decode to).The unit tests were previously self-fulfilling in testing this, so it was not spotted. An easy way to spot the error is looking at what the
PUBLIC_KEY_HEX
test vector used to be; a 34 byte long array.. when's the last time you've seen a public key that is 34 bytes long! (it's because we were leaving the 2 byte multikey type prefix in there[236, 1]
(a.k.a. 0xEC: https://github.com/multiformats/multicodec/blob/master/table.csv#L97)).I also removed the key_decoded solution for JWK, as it was incorrect too; it was just returning the JSON serialized JWK as if it is the public key bytes. IMO the
to_vec
method of theJsonWebKey
is misleading for this reason, so i removed it (i was expecting it to return the public key bytes..).