pub enum PublicKey {
    PublicKeyV0(PublicKeyV0),
}
Expand description

Public key used to check if a message was encoded by the corresponding PublicKey. Generated from the KeyPair using SignatureEngine

Variants§

§

PublicKeyV0(PublicKeyV0)

Implementations§

source§

impl PublicKey

source

pub fn verify_signature( &self, hash: &Hash, signature: &Signature ) -> Result<(), MassaSignatureError>

Checks if the Signature associated with data bytes was produced with the KeyPair associated to given PublicKey

source

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

Serialize a PublicKey as bytes.

Example
let keypair = KeyPair::generate(0).unwrap();

let serialize = keypair.get_public_key().to_bytes();
source

pub fn get_ser_len(&self) -> usize

Return the total length after serialization

source

pub fn from_bytes(data: &[u8]) -> Result<PublicKey, MassaSignatureError>

Deserialize a PublicKey from bytes.

Example
let keypair = KeyPair::generate(0).unwrap();

let serialized = keypair.get_public_key().to_bytes();
let deserialized: PublicKey = PublicKey::from_bytes(&serialized).unwrap();

Trait Implementations§

source§

impl Clone for PublicKey

source§

fn clone(&self) -> PublicKey

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for PublicKey

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for PublicKey

source§

fn deserialize<D: Deserializer<'de>>(d: D) -> Result<PublicKey, D::Error>

::serde::Deserialize trait for PublicKey if the deserializer is human readable, deserialization is done using deserialize_bs58_check else, it uses deserialize_binary

Example

Human readable deserialization :

let keypair = KeyPair::generate(0).unwrap();

let serialized = serde_json::to_string(&keypair.get_public_key()).unwrap();
let deserialized: PublicKey = serde_json::from_str(&serialized).unwrap();
source§

impl Deserializer<PublicKey> for PublicKeyDeserializer

source§

fn deserialize<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>( &self, buffer: &'a [u8] ) -> IResult<&'a [u8], PublicKey, E>

use massa_signature::{PublicKey, PublicKeyDeserializer, KeyPair};
use massa_serialization::{DeserializeError, Deserializer};
use massa_hash::Hash;

let keypair = KeyPair::generate(0).unwrap();
let public_key = keypair.get_public_key();
let serialized = public_key.to_bytes();
let (rest, deser_public_key) = PublicKeyDeserializer::new().deserialize::<DeserializeError>(&serialized).unwrap();
assert!(rest.is_empty());
assert_eq!(keypair.get_public_key(), deser_public_key);
source§

impl Display for PublicKey

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FromStr for PublicKey

source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Example

let pubkey = KeyPair::generate(0).unwrap().get_public_key();
let string = pubkey.to_string();
let pubkey_2 = PublicKey::from_str(&string).unwrap();
assert_eq!(pubkey.to_string(), pubkey_2.to_string());
§

type Err = MassaSignatureError

The associated error which can be returned from parsing.
source§

impl Hash for PublicKey

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for PublicKey

source§

fn cmp(&self, other: &PublicKey) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<PublicKey> for PublicKey

source§

fn eq(&self, other: &PublicKey) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<PublicKey> for PublicKey

source§

fn partial_cmp(&self, other: &PublicKey) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for PublicKey

source§

fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error>

::serde::Serialize trait for PublicKey if the serializer is human readable, serialization is done using serialize_bs58_check else, it uses serialize_binary

Example

Human readable serialization :

let keypair = KeyPair::generate(0).unwrap();
let serialized: String = serde_json::to_string(&keypair.get_public_key()).unwrap();
source§

impl Copy for PublicKey

source§

impl Eq for PublicKey

source§

impl StructuralEq for PublicKey

source§

impl StructuralPartialEq for PublicKey

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,