pub struct KeyPair {
pub private_key: Secp256r1PrivateKey,
pub public_key: Secp256r1PublicKey,
}
Expand description
Represents an Elliptic Curve Key Pair containing both a private and a public key.
Fields§
§private_key: Secp256r1PrivateKey
The private key component of the key pair.
public_key: Secp256r1PublicKey
The public key component of the key pair.
Implementations§
Source§impl KeyPair
impl KeyPair
Sourcepub fn new(
private_key: Secp256r1PrivateKey,
public_key: Secp256r1PublicKey,
) -> Self
pub fn new( private_key: Secp256r1PrivateKey, public_key: Secp256r1PublicKey, ) -> Self
Creates a new KeyPair
instance given a private key and its corresponding public key.
§Arguments
private_key
- ASecp256r1PrivateKey
representing the private key.public_key
- ASecp256r1PublicKey
representing the public key.
pub fn private_key(&self) -> Secp256r1PrivateKey
pub fn public_key(&self) -> Secp256r1PublicKey
Sourcepub fn from_secret_key(private_key: &Secp256r1PrivateKey) -> Self
pub fn from_secret_key(private_key: &Secp256r1PrivateKey) -> Self
Derives a new KeyPair
instance from just a private key.
The public key is derived from the given private key.
§Arguments
private_key
- ASecp256r1PrivateKey
representing the private key.
Sourcepub fn private_key_bytes(&self) -> [u8; 32]
pub fn private_key_bytes(&self) -> [u8; 32]
Returns the 32-byte representation of the private key.
Sourcepub fn public_key_bytes(&self) -> [u8; 64]
pub fn public_key_bytes(&self) -> [u8; 64]
Returns the 64-byte uncompressed representation of the public key.
Source§impl KeyPair
impl KeyPair
Sourcepub fn new_random() -> Self
pub fn new_random() -> Self
Generates a new random KeyPair
.
Sourcepub fn from_private_key(private_key: &[u8; 32]) -> Result<Self, CryptoError>
pub fn from_private_key(private_key: &[u8; 32]) -> Result<Self, CryptoError>
Creates an KeyPair
from a given 32-byte private key.
§Arguments
private_key
- A 32-byte slice representing the private key.
Sourcepub fn from_wif(wif: &str) -> Result<Self, CryptoError>
pub fn from_wif(wif: &str) -> Result<Self, CryptoError>
Creates an KeyPair
from a given Wallet Import Format (WIF) string.
This will use the private key encoded in the WIF to generate the key pair.
§Arguments
wif
- A Wallet Import Format (WIF) string.
The WIF string should be in the format Kx...
or Lx...
.
The key pair will be generated from the private key encoded in the WIF.
The public key will be derived from the private key.
Sourcepub fn from_public_key(public_key: &[u8; 64]) -> Result<Self, CryptoError>
pub fn from_public_key(public_key: &[u8; 64]) -> Result<Self, CryptoError>
Creates an KeyPair
from a given 65-byte public key.
This will use a dummy private key internally.
§Arguments
public_key
- A 65-byte slice representing the uncompressed public key.
Sourcepub fn export_as_wif(&self) -> String
pub fn export_as_wif(&self) -> String
Exports the key pair as a Wallet Import Format (WIF) string
Returns: The WIF encoding of this key pair
pub fn get_script_hash(&self) -> ScriptHash
pub fn get_address(&self) -> String
Trait Implementations§
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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more