Description
I understand that not all implementors necessarily can expose this for various reasons. However, a lot of types can in fact implement this, and for those, it will be very useful for users of this library to be able to constrain generic parameters to be only those that can be generated/derived.
What I suggest is adding a new trait, e.g. Derivable
or whatever name may be appropriate, which will expose two functions generate_keypair()
and derive_keypair()
Then, we can implement that for the popular implementors (k256, p256, ed25519-dalek) easily. And, for example, I as a user of this library can expect K: Keypair + Derivable
and generate new instances of this key in a generic fashion like let keypair = K::generate_keypair()
.
This is much better than the current situation, where my code needs to look like this:
fn generates_keypair< V: Verifier<Sig>, S: Signer<Sig>, >( generate_signing_keypair: fn() -> (V, S), ) -> (V,S) { generate_signing_keypair() }
I think that receiving this function as a parameter makes no sense. Currently, I only need to generate keys for tests -- but this still is very ugly, and unnecessarily so.