Trait KeyType

Source
pub trait KeyType:
    Sized
    + Clone
    + Eq
    + Debug
    + PartialEq
    + Ord
    + PartialOrd
    + Hash
    + Send
    + Sync
    + Serialize
    + DeserializeOwned
    + 'static {
    type Secret: Clone + Serialize + DeserializeOwned + Ord + Send + Sync + Eq + PartialEq + BytesEncoding + Debug;
    type Public: Clone + Serialize + DeserializeOwned + Ord + Send + Sync + Hash + Eq + PartialEq + BytesEncoding + Debug;
    type Signature: Clone + Serialize + DeserializeOwned + Ord + Send + Sync + Eq + PartialEq + BytesEncoding + Debug;
    type Error: Clone + Send + Sync + Debug;

    // Required methods
    fn key_type_id() -> KeyTypeId;
    fn generate_with_seed(
        seed: Option<&[u8]>,
    ) -> Result<Self::Secret, Self::Error>;
    fn generate_with_string(secret: String) -> Result<Self::Secret, Self::Error>;
    fn public_from_secret(secret: &Self::Secret) -> Self::Public;
    fn sign_with_secret(
        secret: &mut Self::Secret,
        msg: &[u8],
    ) -> Result<Self::Signature, Self::Error>;
    fn sign_with_secret_pre_hashed(
        secret: &mut Self::Secret,
        msg: &[u8; 32],
    ) -> Result<Self::Signature, Self::Error>;
    fn verify(
        public: &Self::Public,
        msg: &[u8],
        signature: &Self::Signature,
    ) -> bool;

    // Provided methods
    fn get_rng() -> impl CryptoRng + Rng { ... }
    fn get_test_rng() -> impl CryptoRng + Rng { ... }
}
Expand description

Trait for key types that can be stored in the keystore

Required Associated Types§

Required Methods§

Source

fn key_type_id() -> KeyTypeId

Source

fn generate_with_seed(seed: Option<&[u8]>) -> Result<Self::Secret, Self::Error>

Source

fn generate_with_string(secret: String) -> Result<Self::Secret, Self::Error>

Source

fn public_from_secret(secret: &Self::Secret) -> Self::Public

Source

fn sign_with_secret( secret: &mut Self::Secret, msg: &[u8], ) -> Result<Self::Signature, Self::Error>

Source

fn sign_with_secret_pre_hashed( secret: &mut Self::Secret, msg: &[u8; 32], ) -> Result<Self::Signature, Self::Error>

Source

fn verify( public: &Self::Public, msg: &[u8], signature: &Self::Signature, ) -> bool

Provided Methods§

Source

fn get_rng() -> impl CryptoRng + Rng

Get a cryptographically secure random number generator

Source

fn get_test_rng() -> impl CryptoRng + Rng

Get a deterministic random number generator for testing

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl KeyType for K256Ecdsa

Implementors§