Enum massa_signature::signature_impl::KeyPair

source ·
pub enum KeyPair {
    KeyPairV0(KeyPairV0),
}
Expand description

versioned KeyPair used for signature and decryption

Variants§

§

KeyPairV0(KeyPairV0)

Implementations§

source§

impl KeyPair

source

pub fn get_version(&self) -> u64

Get the version of the given KeyPair

source

pub fn generate(version: u64) -> Result<Self, MassaSignatureError>

Generates a new KeyPair of the version given as parameter. Errors if the version number does not exist

§Example
let keypair = KeyPair::generate(0).unwrap();
let data = Hash::compute_from("Hello World!".as_bytes());
let signature = keypair.sign(&data).unwrap();

let serialized: String = signature.to_bs58_check();
source

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

Returns the Signature produced by signing data bytes with a KeyPair.

§Example
let keypair = KeyPair::generate(0).unwrap();
let data = Hash::compute_from("Hello World!".as_bytes());
let signature = keypair.sign(&data).unwrap();
source

pub fn get_ser_len(&self) -> usize

Return the total length after serialization

source

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

Return the bytes (as a Vec) representing the keypair

§Example
let keypair = KeyPair::generate(0).unwrap();
let bytes = keypair.to_bytes();
source

pub fn get_public_key(&self) -> PublicKey

Get the public key of the keypair

§Example
let keypair = KeyPair::generate(0).unwrap();
let public_key = keypair.get_public_key();
source

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

Convert a byte slice to a KeyPair

§Example
let keypair = KeyPair::generate(0).unwrap();
let bytes = keypair.to_bytes();
let keypair2 = KeyPair::from_bytes(&bytes).unwrap();
assert_eq!(keypair.to_string(), keypair2.to_string());

Trait Implementations§

source§

impl Clone for KeyPair

source§

fn clone(&self) -> KeyPair

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 KeyPair

source§

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

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

impl<'de> Deserialize<'de> for KeyPair

source§

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

::serde::Deserialize trait for KeyPair 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).unwrap();
let deserialized: KeyPair = serde_json::from_str(&serialized).unwrap();
source§

impl Display for KeyPair

source§

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

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

impl FromStr for KeyPair

source§

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

§Example

let keypair = KeyPair::generate(0).unwrap();
let string = keypair.to_string();
let keypair2 = KeyPair::from_str(&string).unwrap();
assert_eq!(keypair.to_string(), keypair2.to_string());
§

type Err = MassaSignatureError

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

impl Serialize for KeyPair

source§

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

::serde::Serialize trait for KeyPair 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).unwrap();

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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 T
where 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 for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where 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 T
where 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 T
where 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 T
where 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 T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

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