Struct massa_signature::signature_impl::KeyPairV0
source · pub struct KeyPairV0(SigningKey);
Expand description
versioned KeyPair used for signature and decryption
Tuple Fields§
§0: SigningKey
Implementations§
source§impl KeyPairV0
impl KeyPairV0
pub const SECRET_KEY_BYTES_SIZE: usize = 32usize
sourcepub fn get_version(&self) -> u64
pub fn get_version(&self) -> u64
Return the current version keypair
sourcepub fn get_ser_len(&self) -> usize
pub fn get_ser_len(&self) -> usize
Return the total length after serialization
source§impl KeyPairV0
impl KeyPairV0
sourcepub fn sign(&self, hash: &Hash) -> Result<SignatureV0, MassaSignatureError>
pub fn sign(&self, hash: &Hash) -> Result<SignatureV0, 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_public_key(&self) -> PublicKeyV0
pub fn get_public_key(&self) -> PublicKeyV0
Get the public key of the keypair
Example
let keypair = KeyPair::generate(0).unwrap();
let public_key = keypair.get_public_key();
sourcepub fn generate() -> Self
pub fn generate() -> Self
Generate a new KeyPair
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 from_bytes(data: &[u8]) -> Result<Self, MassaSignatureError>
pub fn from_bytes(data: &[u8]) -> Result<Self, MassaSignatureError>
Convert a byte array of size SECRET_KEY_BYTES_SIZE
to a KeyPair
.
IMPORTANT: providing more bytes than needed does not result in an error.
Example
let keypair = KeyPair::generate(0).unwrap();
let bytes = keypair.to_bytes();
let keypair2 = KeyPair::from_bytes(&bytes).unwrap();
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for KeyPairV0
impl Send for KeyPairV0
impl Sync for KeyPairV0
impl Unpin for KeyPairV0
impl UnwindSafe for KeyPairV0
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
Mutably borrows from an owned value. Read more