pub struct Keypair(/* private fields */);Expand description
A vanilla Ed25519 key pair
Implementations§
Source§impl Keypair
impl Keypair
Sourcepub const SECRET_KEY_LENGTH: usize = 32usize
pub const SECRET_KEY_LENGTH: usize = 32usize
Can be used for generating a Keypair without a dependency on rand types
Sourcepub fn generate<R>(csprng: &mut R) -> Keypair
👎Deprecated since 2.2.2: Use Keypair::new() instead or generate 32 random bytes and use Keypair::new_from_array
pub fn generate<R>(csprng: &mut R) -> Keypair
Keypair::new() instead or generate 32 random bytes and use Keypair::new_from_arrayConstructs a new, random Keypair using a caller-provided RNG
Sourcepub fn new_from_array(secret_key: [u8; 32]) -> Keypair
pub fn new_from_array(secret_key: [u8; 32]) -> Keypair
Constructs a new Keypair using secret key bytes
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Keypair, Error>
👎Deprecated since 2.2.2: Use Keypair::try_from(&[u8]) instead
pub fn from_bytes(bytes: &[u8]) -> Result<Keypair, Error>
Recovers a Keypair from a byte array
Sourcepub fn from_base58_string(s: &str) -> Keypair
pub fn from_base58_string(s: &str) -> Keypair
Recovers a Keypair from a base58-encoded string
Sourcepub fn to_base58_string(&self) -> String
pub fn to_base58_string(&self) -> String
Returns this Keypair as a base58-encoded string
Sourcepub fn secret(&self) -> &SecretKey
👎Deprecated since 2.2.2: Use secret_bytes()
pub fn secret(&self) -> &SecretKey
Gets this Keypair’s SecretKey
Sourcepub fn secret_bytes(&self) -> &[u8; 32]
pub fn secret_bytes(&self) -> &[u8; 32]
Gets this Keypair’s secret key bytes
Sourcepub fn insecure_clone(&self) -> Keypair
pub fn insecure_clone(&self) -> Keypair
Allows Keypair cloning
Note that the Clone trait is intentionally unimplemented because making a
second copy of sensitive secret keys in memory is usually a bad idea.
Only use this in tests or when strictly required. Consider using std::sync::Arc<Keypair>
instead.
Trait Implementations§
Source§impl<'de> DeserializeAs<'de, Keypair> for AsKeypair
impl<'de> DeserializeAs<'de, Keypair> for AsKeypair
Source§fn deserialize_as<D>(
deserializer: D,
) -> Result<Keypair, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize_as<D>(
deserializer: D,
) -> Result<Keypair, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl EncodableKey for Keypair
impl EncodableKey for Keypair
fn read<R>(reader: &mut R) -> Result<Keypair, Box<dyn Error>>where
R: Read,
fn write<W>(&self, writer: &mut W) -> Result<String, Box<dyn Error>>where
W: Write,
fn read_from_file<F>(path: F) -> Result<Self, Box<dyn Error>>
fn write_to_file<F>(&self, outfile: F) -> Result<String, Box<dyn Error>>
Source§impl EncodableKeypair for Keypair
impl EncodableKeypair for Keypair
Source§fn encodable_pubkey(&self) -> <Keypair as EncodableKeypair>::Pubkey
fn encodable_pubkey(&self) -> <Keypair as EncodableKeypair>::Pubkey
Returns the associated pubkey. Use this function specifically for settings that involve
reading or writing pubkeys. For other settings, use Signer::pubkey() instead.
type Pubkey = Pubkey
Source§impl SerializeAs<Keypair> for AsKeypair
impl SerializeAs<Keypair> for AsKeypair
Source§fn serialize_as<S>(
x: &Keypair,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize_as<S>(
x: &Keypair,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl Signer for Keypair
impl Signer for Keypair
Source§fn pubkey(&self) -> Pubkey
fn pubkey(&self) -> Pubkey
Pubkey if the implementor has none.Source§fn try_pubkey(&self) -> Result<Pubkey, SignerError>
fn try_pubkey(&self) -> Result<Pubkey, SignerError>
Source§fn sign_message(&self, message: &[u8]) -> Signature
fn sign_message(&self, message: &[u8]) -> Signature
message
bytes. Returns the all-zeros Signature if signing is not possible.Source§fn try_sign_message(&self, message: &[u8]) -> Result<Signature, SignerError>
fn try_sign_message(&self, message: &[u8]) -> Result<Signature, SignerError>
message bytes.