Enum massa_signature::signature_impl::KeyPair
source · pub enum KeyPair {
KeyPairV0(KeyPairV0),
}
Expand description
versioned KeyPair used for signature and decryption
Variants§
Implementations§
source§impl KeyPair
impl KeyPair
sourcepub fn get_version(&self) -> u64
pub fn get_version(&self) -> u64
Get the version of the given KeyPair
sourcepub fn generate(version: u64) -> Result<Self, MassaSignatureError>
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();
sourcepub fn sign(&self, hash: &Hash) -> Result<Signature, MassaSignatureError>
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();
sourcepub fn get_ser_len(&self) -> usize
pub fn get_ser_len(&self) -> usize
Return the total length after serialization
sourcepub fn to_bytes(&self) -> Vec<u8>
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();
sourcepub fn get_public_key(&self) -> PublicKey
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();
sourcepub fn from_bytes(data: &[u8]) -> Result<Self, MassaSignatureError>
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<'de> Deserialize<'de> for KeyPair
impl<'de> Deserialize<'de> for KeyPair
source§fn deserialize<D: Deserializer<'de>>(d: D) -> Result<KeyPair, D::Error>
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 FromStr for KeyPair
impl FromStr for KeyPair
source§fn from_str(s: &str) -> Result<Self, Self::Err>
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
type Err = MassaSignatureError
source§impl Serialize for KeyPair
impl Serialize for KeyPair
source§fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error>
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§
impl Freeze for KeyPair
impl RefUnwindSafe for KeyPair
impl Send for KeyPair
impl Sync for KeyPair
impl Unpin for KeyPair
impl UnwindSafe for KeyPair
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)