Keypair

Struct Keypair 

Source
pub struct Keypair(/* private fields */);
Expand description

A vanilla Ed25519 key pair

Implementations§

Source§

impl Keypair

Source

pub const SECRET_KEY_LENGTH: usize = 32usize

Can be used for generating a Keypair without a dependency on rand types

Source

pub fn generate<R>(csprng: &mut R) -> Keypair
where R: CryptoRng + RngCore,

👎Deprecated since 2.2.2: Use Keypair::new() instead or generate 32 random bytes and use Keypair::new_from_array

Constructs a new, random Keypair using a caller-provided RNG

Source

pub fn new() -> Keypair

Constructs a new, random Keypair using OsRng

Source

pub fn new_from_array(secret_key: [u8; 32]) -> Keypair

Constructs a new Keypair using secret key bytes

Source

pub fn from_bytes(bytes: &[u8]) -> Result<Keypair, Error>

👎Deprecated since 2.2.2: Use Keypair::try_from(&[u8]) instead

Recovers a Keypair from a byte array

Source

pub fn to_bytes(&self) -> [u8; 64]

Returns this Keypair as a byte array

Source

pub fn from_base58_string(s: &str) -> Keypair

Recovers a Keypair from a base58-encoded string

Source

pub fn to_base58_string(&self) -> String

Returns this Keypair as a base58-encoded string

Source

pub fn secret(&self) -> &SecretKey

👎Deprecated since 2.2.2: Use secret_bytes()

Gets this Keypair’s SecretKey

Source

pub fn secret_bytes(&self) -> &[u8; 32]

Gets this Keypair’s secret key bytes

Source

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 Debug for Keypair

Source§

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

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

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>,

Deserialize this value from the given Serde deserializer.
Source§

impl EncodableKey for Keypair

Source§

fn read<R>(reader: &mut R) -> Result<Keypair, Box<dyn Error>>
where R: Read,

Source§

fn write<W>(&self, writer: &mut W) -> Result<String, Box<dyn Error>>
where W: Write,

Source§

fn read_from_file<F>(path: F) -> Result<Self, Box<dyn Error>>
where F: AsRef<Path>,

Source§

fn write_to_file<F>(&self, outfile: F) -> Result<String, Box<dyn Error>>
where F: AsRef<Path>,

Source§

impl EncodableKeypair for Keypair

Source§

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.

Source§

type Pubkey = Pubkey

Source§

impl From<Keypair> for Keypair

Source§

fn from(value: Keypair) -> Keypair

Converts to this type from the input type.
Source§

impl From<Keypair> for Value

Source§

fn from(x: Keypair) -> Value

Converts to this type from the input type.
Source§

impl From<Keypair> for Wallet

Source§

fn from(value: Keypair) -> Self

Converts to this type from the input type.
Source§

impl KeypairExt for Keypair

Source§

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

Source§

impl<T> PartialEq<T> for Keypair
where T: Signer,

Source§

fn eq(&self, other: &T) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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,

Serialize this value into the given Serde serializer.
Source§

impl Signer for Keypair

Source§

fn pubkey(&self) -> Pubkey

Infallibly gets the implementor’s public key. Returns the all-zeros Pubkey if the implementor has none.
Source§

fn try_pubkey(&self) -> Result<Pubkey, SignerError>

Fallibly gets the implementor’s public key
Source§

fn sign_message(&self, message: &[u8]) -> Signature

Infallibly produces an Ed25519 signature over the provided message bytes. Returns the all-zeros Signature if signing is not possible.
Source§

fn try_sign_message(&self, message: &[u8]) -> Result<Signature, SignerError>

Fallibly produces an Ed25519 signature over the provided message bytes.
Source§

fn is_interactive(&self) -> bool

Whether the implementation requires user interaction to sign
Source§

impl TryFrom<&[u8]> for Keypair

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(bytes: &[u8]) -> Result<Keypair, <Keypair as TryFrom<&[u8]>>::Error>

Performs the conversion.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,