pub struct Ed25519PrivateKey { /* private fields */ }ed25519 only.Expand description
An Ed25519 private key.
The private key is zeroized when dropped to prevent sensitive data from remaining in memory.
§Example
use aptos_sdk::crypto::{Ed25519PrivateKey, Signer};
// Generate a random key
let private_key = Ed25519PrivateKey::generate();
// Sign a message
let signature = private_key.sign(b"hello");
// Get the public key
let public_key = private_key.public_key();Implementations§
Source§impl Ed25519PrivateKey
impl Ed25519PrivateKey
Sourcepub fn from_bytes(bytes: &[u8]) -> AptosResult<Self>
pub fn from_bytes(bytes: &[u8]) -> AptosResult<Self>
Creates a private key from raw bytes.
§Errors
Returns AptosError::InvalidPrivateKey if:
- The byte slice length is not exactly 32 bytes
Sourcepub fn from_hex(hex_str: &str) -> AptosResult<Self>
pub fn from_hex(hex_str: &str) -> AptosResult<Self>
Creates a private key from a hex string.
§Errors
Returns AptosError::Hex if the hex string is invalid.
Returns AptosError::InvalidPrivateKey if the decoded bytes are not exactly 32 bytes.
Sourcepub fn from_aip80(s: &str) -> AptosResult<Self>
pub fn from_aip80(s: &str) -> AptosResult<Self>
Creates a private key from AIP-80 format string.
AIP-80 format: ed25519-priv-0x{hex_bytes}
§Errors
Returns an error if the format is invalid or the key bytes are invalid.
§Example
use aptos_sdk::crypto::Ed25519PrivateKey;
let key = Ed25519PrivateKey::from_aip80(
"ed25519-priv-0x0000000000000000000000000000000000000000000000000000000000000001"
).unwrap();Sourcepub fn to_bytes(&self) -> [u8; 32]
pub fn to_bytes(&self) -> [u8; 32]
Returns the private key as bytes.
Warning: Handle the returned bytes carefully to avoid leaking sensitive key material.
Sourcepub fn to_aip80(&self) -> String
pub fn to_aip80(&self) -> String
Returns the private key in AIP-80 format.
AIP-80 format: ed25519-priv-0x{hex_bytes}
§Example
use aptos_sdk::crypto::Ed25519PrivateKey;
let key = Ed25519PrivateKey::generate();
let aip80 = key.to_aip80();
assert!(aip80.starts_with("ed25519-priv-0x"));Sourcepub fn public_key(&self) -> Ed25519PublicKey
pub fn public_key(&self) -> Ed25519PublicKey
Returns the corresponding public key.
Sourcepub fn sign(&self, message: &[u8]) -> Ed25519Signature
pub fn sign(&self, message: &[u8]) -> Ed25519Signature
Signs a message and returns the signature.
Trait Implementations§
Source§impl Clone for Ed25519PrivateKey
impl Clone for Ed25519PrivateKey
Source§fn clone(&self) -> Ed25519PrivateKey
fn clone(&self) -> Ed25519PrivateKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more