informalsystems / tendermint-rs

Client libraries for Tendermint/CometBFT in Rust!
Apache License 2.0
587 stars 213 forks source link

tendermint: `PrivateKey` and `PublicKey` have `From` impls for `ed25519-consensus` types #1401

Closed cratelyn closed 3 months ago

cratelyn commented 3 months ago

currently, when working with tendermint::{PrivateKey, PublicKey}, users of the ed25519-consensus crate must convert a ed25519_consensus::VerificationKey or ed25519_consensus::SigningKey via TryFrom<&'_ [u8]>. this has the unfortunate effect of requiring a bounds check, on a value that is already known to be a valid key.

tendermint::PublicKey::from_raw_ed25519(&vk.to_bytes()).expect("consensus key is valid")

this branch introduces some additional From<T> implementations, to facilitate free conversions from ed25519-consensus types.

an internal SigningKey::new() constructor is also added, for the sake of consistency with VerificationKey::new(). this is optional, i'd be happy to back out of that change if it seems prudent.

some additional from_ed25519_consensus methods are provided, for cases where type inference might not suffice. these felt complimentary to existing methods like from_raw_ed25519, but are another optional change i'd be happy to back out of.

codecov-commenter commented 3 months ago

Codecov Report

Attention: Patch coverage is 11.53846% with 23 lines in your changes are missing coverage. Please review.

Project coverage is 59.3%. Comparing base (99ed0b9) to head (a1bce2c).

:exclamation: Current head a1bce2c differs from pull request most recent head 34e0c13. Consider uploading reports for the commit 34e0c13 to get more accurate results

Files Patch % Lines
tendermint/src/private_key.rs 0.0% 10 Missing :warning:
tendermint/src/crypto/ed25519/signing_key.rs 0.0% 6 Missing :warning:
tendermint/src/public_key.rs 42.8% 4 Missing :warning:
tendermint/src/crypto/ed25519/verification_key.rs 0.0% 3 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1401 +/- ## ======================================= - Coverage 60.1% 59.3% -0.8% ======================================= Files 271 271 Lines 26221 26549 +328 ======================================= - Hits 15768 15762 -6 - Misses 10453 10787 +334 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.