Skip to main content

KeyCodec

Trait KeyCodec 

Source
pub trait KeyCodec {
    type Pair: PairTrait;
    type PrivateKey: Clone;
    type PublicKey: Clone;
    type Address;

    const KEY_TYPE: &'static str;

    // Required methods
    fn derive_public(private_key: &Self::PrivateKey) -> Self::PublicKey;
    fn derive_address(public_key: &Self::PublicKey) -> Result<Self::Address>;
    fn encode_private(private_key: &Self::PrivateKey) -> Result<String>;
    fn decode_private(encoded: &str) -> Result<Self::PrivateKey>;
    fn encode_public(public_key: &Self::PublicKey) -> Result<String>;
    fn decode_public(encoded: &str) -> Result<Self::PublicKey>;
    fn encode_address(address: &Self::Address) -> Result<String>;
    fn decode_address(encoded: &str) -> Result<Self::Address>;
    fn random_private() -> Result<Self::PrivateKey>;
    fn import_suri(
        suri: &str,
        password: Option<&str>,
    ) -> Result<Self::PrivateKey>;
}
Expand description

Trait describing how to convert to and from string representations for key material, and how to generate/import keys for keyring operations.

Required Associated Constants§

Source

const KEY_TYPE: &'static str

Human-readable key type identifier (e.g., “ecdsa”, “sr25519”, “ed25519”).

Required Associated Types§

Source

type Pair: PairTrait

Concrete Substrate pair type.

Source

type PrivateKey: Clone

Private key wrapper type.

Source

type PublicKey: Clone

Public key wrapper type.

Source

type Address

Address type exposed by the scheme.

Required Methods§

Source

fn derive_public(private_key: &Self::PrivateKey) -> Self::PublicKey

Derive the public key from the provided private key.

Source

fn derive_address(public_key: &Self::PublicKey) -> Result<Self::Address>

Derive the address from the provided public key.

Source

fn encode_private(private_key: &Self::PrivateKey) -> Result<String>

Encode private key for storage.

Source

fn decode_private(encoded: &str) -> Result<Self::PrivateKey>

Decode private key from storage.

Source

fn encode_public(public_key: &Self::PublicKey) -> Result<String>

Encode public key for storage.

Source

fn decode_public(encoded: &str) -> Result<Self::PublicKey>

Decode public key from storage.

Source

fn encode_address(address: &Self::Address) -> Result<String>

Encode address for storage.

Source

fn decode_address(encoded: &str) -> Result<Self::Address>

Decode address from storage.

Source

fn random_private() -> Result<Self::PrivateKey>

Generate a new random private key.

Source

fn import_suri(suri: &str, password: Option<&str>) -> Result<Self::PrivateKey>

Import a private key from a SURI (mnemonic/derivation path).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§