Struct fuel_crypto::SecretKey
source · #[repr(transparent)]pub struct SecretKey(_);
Expand description
Asymmetric secret key
Implementations§
source§impl SecretKey
impl SecretKey
sourcepub fn random<R>(rng: &mut R) -> Selfwhere
R: Rng + ?Sized,
Available on crate features std
and random
only.
pub fn random<R>(rng: &mut R) -> Selfwhere R: Rng + ?Sized,
std
and random
only.Create a new random secret
sourcepub fn new_from_mnemonic_phrase_with_path(
phrase: &str,
path: &str
) -> Result<Self, Error>
Available on crate feature std
only.
pub fn new_from_mnemonic_phrase_with_path( phrase: &str, path: &str ) -> Result<Self, Error>
std
only.Generate a new secret key from a mnemonic phrase and its derivation path.
Both are passed as &str
. If you want to manually create a DerivationPath
and Mnemonic
, use SecretKey::new_from_mnemonic
.
The derivation path is a list of integers, each representing a child index.
sourcepub fn new_from_mnemonic(
d: DerivationPath,
m: Mnemonic<English>
) -> Result<Self, Error>
Available on crate feature std
only.
pub fn new_from_mnemonic( d: DerivationPath, m: Mnemonic<English> ) -> Result<Self, Error>
std
only.Generate a new secret key from a DerivationPath
and Mnemonic
.
If you want to pass strings instead, use SecretKey::new_from_mnemonic_phrase_with_path
.
sourcepub unsafe fn is_slice_in_field_unchecked(slice: &[u8]) -> bool
Available on crate feature std
only.
pub unsafe fn is_slice_in_field_unchecked(slice: &[u8]) -> bool
std
only.Check if the provided slice represents a scalar that fits the field.
Safety
This function extends the unsafety of
SecretKey::as_ref_unchecked
.
sourcepub fn is_in_field(&self) -> bool
Available on crate feature std
only.
pub fn is_in_field(&self) -> bool
std
only.Check if the secret key representation fits the scalar field.
sourcepub fn public_key(&self) -> PublicKey
Available on crate feature std
only.
pub fn public_key(&self) -> PublicKey
std
only.Return the curve representation of this secret.
The discrete logarithm property guarantees this is a one-way function.
source§impl SecretKey
impl SecretKey
sourcepub unsafe fn from_bytes_unchecked(bytes: [u8; 32]) -> Self
pub unsafe fn from_bytes_unchecked(bytes: [u8; 32]) -> Self
Add a conversion from arbitrary slices into owned
Safety
There is no guarantee the provided bytes will fit the field. The field
security can be checked with SecretKey::is_in_field
.
sourcepub unsafe fn from_slice_unchecked(bytes: &[u8]) -> Self
pub unsafe fn from_slice_unchecked(bytes: &[u8]) -> Self
Add a conversion from arbitrary slices into owned
Safety
This function will not panic if the length of the slice is smaller than
Self::LEN
. Instead, it will cause undefined behavior and read random
disowned bytes.
There is no guarantee the provided bytes will fit the field.
sourcepub unsafe fn as_ref_unchecked(bytes: &[u8]) -> &Self
pub unsafe fn as_ref_unchecked(bytes: &[u8]) -> &Self
Copy-free reference cast
There is no guarantee the provided bytes will fit the field.
Safety
Inputs smaller than Self::LEN
will cause undefined behavior.
Methods from Deref<Target = [u8; 32]>§
1.57.0 · sourcepub fn as_slice(&self) -> &[T]
pub fn as_slice(&self) -> &[T]
Returns a slice containing the entire array. Equivalent to &s[..]
.
sourcepub fn each_ref(&self) -> [&T; N]
🔬This is a nightly-only experimental API. (array_methods
)
pub fn each_ref(&self) -> [&T; N]
array_methods
)Borrows each element and returns an array of references with the same
size as self
.
Example
#![feature(array_methods)]
let floats = [3.1, 2.7, -1.0];
let float_refs: [&f64; 3] = floats.each_ref();
assert_eq!(float_refs, [&3.1, &2.7, &-1.0]);
This method is particularly useful if combined with other methods, like
map
. This way, you can avoid moving the original
array if its elements are not Copy
.
#![feature(array_methods)]
let strings = ["Ferris".to_string(), "♥".to_string(), "Rust".to_string()];
let is_ascii = strings.each_ref().map(|s| s.is_ascii());
assert_eq!(is_ascii, [true, false, true]);
// We can still access the original array: it has not been moved.
assert_eq!(strings.len(), 3);
sourcepub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])
🔬This is a nightly-only experimental API. (split_array
)
pub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])
split_array
)Divides one array reference into two at an index.
The first will contain all indices from [0, M)
(excluding
the index M
itself) and the second will contain all
indices from [M, N)
(excluding the index N
itself).
Panics
Panics if M > N
.
Examples
#![feature(split_array)]
let v = [1, 2, 3, 4, 5, 6];
{
let (left, right) = v.split_array_ref::<0>();
assert_eq!(left, &[]);
assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}
{
let (left, right) = v.split_array_ref::<2>();
assert_eq!(left, &[1, 2]);
assert_eq!(right, &[3, 4, 5, 6]);
}
{
let (left, right) = v.split_array_ref::<6>();
assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
assert_eq!(right, &[]);
}
sourcepub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])
🔬This is a nightly-only experimental API. (split_array
)
pub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])
split_array
)Divides one array reference into two at an index from the end.
The first will contain all indices from [0, N - M)
(excluding
the index N - M
itself) and the second will contain all
indices from [N - M, N)
(excluding the index N
itself).
Panics
Panics if M > N
.
Examples
#![feature(split_array)]
let v = [1, 2, 3, 4, 5, 6];
{
let (left, right) = v.rsplit_array_ref::<0>();
assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
assert_eq!(right, &[]);
}
{
let (left, right) = v.rsplit_array_ref::<2>();
assert_eq!(left, &[1, 2, 3, 4]);
assert_eq!(right, &[5, 6]);
}
{
let (left, right) = v.rsplit_array_ref::<6>();
assert_eq!(left, &[]);
assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}
Trait Implementations§
source§impl Borrow<SecretKey> for SecretKey
Available on crate feature std
only.
impl Borrow<SecretKey> for SecretKey
std
only.source§fn borrow(&self) -> &Secp256k1SecretKey
fn borrow(&self) -> &Secp256k1SecretKey
source§impl<'de> Deserialize<'de> for SecretKey
impl<'de> Deserialize<'de> for SecretKey
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 Distribution<SecretKey> for Standard
Available on crate features std
and random
only.
impl Distribution<SecretKey> for Standard
std
and random
only.source§fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> SecretKey
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> SecretKey
T
, using rng
as the source of randomness.source§impl Ord for SecretKey
impl Ord for SecretKey
source§impl PartialEq<SecretKey> for SecretKey
impl PartialEq<SecretKey> for SecretKey
source§impl PartialOrd<SecretKey> for SecretKey
impl PartialOrd<SecretKey> for SecretKey
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Copy for SecretKey
impl Eq for SecretKey
impl StructuralEq for SecretKey
impl StructuralPartialEq for SecretKey
Auto Trait Implementations§
impl RefUnwindSafe for SecretKey
impl Send for SecretKey
impl Sync for SecretKey
impl Unpin for SecretKey
impl UnwindSafe for SecretKey
Blanket Implementations§
§impl<T> Base32Len for Twhere
T: AsRef<[u8]>,
impl<T> Base32Len for Twhere T: AsRef<[u8]>,
§fn base32_len(&self) -> usize
fn base32_len(&self) -> usize
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> ToHex for Twhere
T: AsRef<[u8]>,
impl<T> ToHex for Twhere T: AsRef<[u8]>,
source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere U: FromIterator<char>,
self
into the result. Lower case
letters are used (e.g. f9b4ca
)source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere U: FromIterator<char>,
self
into the result. Upper case
letters are used (e.g. F9B4CA
)