You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I try to construct the publicKey back from these bytes:
let public_key = PublicKey::from_bytes(&public_key_bytes);
I get an error:
error[E0277]: arrays only have std trait implementations for lengths 0..=32
--> ethers-core/src/types/crypto/keys.rs:308:60
|
308 | let public_key = PublicKey::from_bytes(&public_key_bytes)
| ^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[u8; 33]`
|
= note: required because of the requirements on the impl of `std::convert::AsRef<[u8]>` for `[u8; 33]`
= note: required because of the requirements on the impl of `std::convert::AsRef<[u8]>` for `&[u8; 33]`
= note: required by `elliptic_curve::weierstrass::public_key::PublicKey::<C>::from_bytes`
Basically, the from_bytes expects a byte array of length 32.
What am I missing here? Any help would be appreciated.
The text was updated successfully, but these errors were encountered:
This is a (recently removed) limitation of the Rust standard library: common trait impls used to be special cased for [T; 0] -> [T; 32] because Rust's type system didn't used to support const generics. But now it does and this restriction was recently removed in the nightly compiler.
In the meantime you'll need to explicitly slice the array to get &[u8]:
let public_key = PublicKey::from_bytes(&public_key_bytes[..]);
Hello, thank you for the wonderful work that has been put into building this library!
As I understand, a
PublicKey
by default is stored in the compressed form (33 bytes).On obtaining a byte array for the public key, I get an array of length 33
When I try to construct the
publicKey
back from these bytes:I get an error:
Basically, the
from_bytes
expects a byte array of length 32.What am I missing here? Any help would be appreciated.
The text was updated successfully, but these errors were encountered: