Skip to main content

PublicKey

Trait PublicKey 

Source
pub trait PublicKey: Clone + Sized {
    const LENGTH: usize;

    // Required methods
    fn from_bytes(bytes: &[u8]) -> AptosResult<Self>;
    fn to_bytes(&self) -> Vec<u8> ;

    // Provided method
    fn to_hex(&self) -> String { ... }
}
Expand description

A trait for public key types.

Required Associated Constants§

Source

const LENGTH: usize

The length of the public key in bytes.

Required Methods§

Source

fn from_bytes(bytes: &[u8]) -> AptosResult<Self>

Creates a public key from bytes.

§Errors

Returns an error if the bytes have an invalid length or format.

Source

fn to_bytes(&self) -> Vec<u8>

Returns the public key as bytes.

Provided Methods§

Source

fn to_hex(&self) -> String

Returns the public key as a hex string with 0x prefix.

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.

Implementors§

Source§

impl PublicKey for Bls12381PublicKey

Available on crate feature bls only.
Source§

const LENGTH: usize = BLS12381_PUBLIC_KEY_LENGTH

Source§

impl PublicKey for Ed25519PublicKey

Available on crate feature ed25519 only.
Source§

const LENGTH: usize = ED25519_PUBLIC_KEY_LENGTH

Source§

impl PublicKey for MultiEd25519PublicKey

Available on crate feature ed25519 only.
Source§

impl PublicKey for Secp256k1PublicKey

Available on crate feature secp256k1 only.
Source§

const LENGTH: usize = SECP256K1_PUBLIC_KEY_LENGTH

Source§

impl PublicKey for Secp256r1PublicKey

Available on crate feature secp256r1 only.
Source§

const LENGTH: usize = SECP256R1_PUBLIC_KEY_LENGTH