pub struct Secp256r1PrivateKey { /* private fields */ }
Implementations§
Source§impl Secp256r1PrivateKey
impl Secp256r1PrivateKey
Sourcepub fn new_random() -> Self
pub fn new_random() -> Self
Generates a new private key using the provided random number generator (RNG).
-
Parameter rng: A mutable reference to an
OsRng
instance. -
Returns: A new instance of the private key.
Sourcepub fn random(rng: &mut OsRng) -> Self
pub fn random(rng: &mut OsRng) -> Self
Generates a new private key using the provided random number generator (RNG).
-
Parameter rng: A mutable reference to an
OsRng
instance. -
Returns: A new instance of the private key.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, CryptoError>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, CryptoError>
Creates a private key from a byte slice.
This method attempts to construct a private key from a given byte array. Returns an error if the byte slice does not represent a valid private key.
-
Parameter bytes: A byte slice representing the private key.
-
Returns: A
Result
with the private key or aCryptoError
Sourcepub fn to_raw_bytes(&self) -> [u8; 32]
pub fn to_raw_bytes(&self) -> [u8; 32]
Returns the raw byte representation of the private key.
- Returns: A 32-byte array representing the private key.
Sourcepub fn to_public_key(&self) -> Secp256r1PublicKey
pub fn to_public_key(&self) -> Secp256r1PublicKey
Converts the private key to its corresponding public key.
- Returns: The corresponding
Secp256r1PublicKey
.
pub fn erase(&mut self)
Sourcepub fn sign_tx(&self, message: &[u8]) -> Result<Secp256r1Signature, CryptoError>
pub fn sign_tx(&self, message: &[u8]) -> Result<Secp256r1Signature, CryptoError>
Signs a transaction with the private key.
This method signs the provided message (transaction) using the private key and returns the signature.
-
Parameter message: A byte slice representing the message to be signed.
-
Returns: A
Result
with theSecp256r1Signature
or aCryptoError
.
Sourcepub fn sign_prehash(
&self,
message: &[u8],
) -> Result<Secp256r1Signature, CryptoError>
pub fn sign_prehash( &self, message: &[u8], ) -> Result<Secp256r1Signature, CryptoError>
Signs a prehashed message with the private key. This method signs the provided prehashed message using the private key and returns the signature.
- Parameter message: A byte slice representing the prehashed message to be signed.
- Returns: A
Result
with theSecp256r1Signature
or aCryptoError
. - Note: The message should be prehashed using a secure hash function before calling this method. The signature is generated using the ECDSA algorithm.
Trait Implementations§
Source§impl Clone for Secp256r1PrivateKey
impl Clone for Secp256r1PrivateKey
Source§fn clone(&self) -> Secp256r1PrivateKey
fn clone(&self) -> Secp256r1PrivateKey
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for Secp256r1PrivateKey
impl Debug for Secp256r1PrivateKey
Source§impl<'de> Deserialize<'de> for Secp256r1PrivateKey
impl<'de> Deserialize<'de> for Secp256r1PrivateKey
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Display for Secp256r1PrivateKey
impl Display for Secp256r1PrivateKey
Source§impl Hash for Secp256r1PrivateKey
impl Hash for Secp256r1PrivateKey
Source§impl PartialEq for Secp256r1PrivateKey
impl PartialEq for Secp256r1PrivateKey
Auto Trait Implementations§
impl Freeze for Secp256r1PrivateKey
impl RefUnwindSafe for Secp256r1PrivateKey
impl Send for Secp256r1PrivateKey
impl Sync for Secp256r1PrivateKey
impl Unpin for Secp256r1PrivateKey
impl UnwindSafe for Secp256r1PrivateKey
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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string
, but without panic on OOM.