Struct fuel_crypto::Signature
source · [−]#[repr(transparent)]pub struct Signature(_);
Expand description
Secp256k1 signature implementation
Implementations
sourceimpl Signature
impl Signature
sourcepub fn sign(secret: &SecretKey, message: &Message) -> Self
pub fn sign(secret: &SecretKey, message: &Message) -> Self
Sign a given message and compress the v
to the signature
The compression scheme is described in https://github.com/FuelLabs/fuel-specs/blob/master/specs/protocol/cryptographic_primitives.md#public-key-cryptography
sourcepub fn recover(self, message: &Message) -> Result<PublicKey, Error>
pub fn recover(self, message: &Message) -> Result<PublicKey, Error>
Recover the public key from a signature performed with
Signature::sign
It takes the signature as owned because this operation is not idempotent. The taken signature will not be recoverable. Signatures are meant to be single use, so this avoids unnecessary copy.
sourcepub fn verify(self, pk: &PublicKey, message: &Message) -> Result<(), Error>
pub fn verify(self, pk: &PublicKey, message: &Message) -> Result<(), Error>
Verify a signature produced by Signature::sign
It takes the signature as owned because this operation is not idempotent. The taken signature will not be recoverable. Signatures are meant to be single use, so this avoids unnecessary copy.
sourceimpl Signature
impl Signature
sourcepub unsafe fn from_bytes_unchecked(bytes: [u8; 64]) -> Self
pub unsafe fn from_bytes_unchecked(bytes: [u8; 64]) -> Self
Add a conversion from arbitrary slices into owned
Safety
There is no guarantee the provided bytes will be a valid signature. Internally, some FFI
calls to secp256k1
are performed and we might have undefined behavior in case the bytes
are not canonically encoded to a valid secp256k1
signature.
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 be a valid signature. Internally, some FFI
calls to secp256k1
are performed and we might have undefined behavior in case the bytes
are not canonically encoded to a valid secp256k1
signature.
Methods from Deref<Target = [u8; 64]>
1.57.0 · sourcepub fn as_slice(&self) -> &[T]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
pub fn as_slice(&self) -> &[T]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
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
sourceimpl Ord for Signature
impl Ord for Signature
sourceimpl PartialOrd<Signature> for Signature
impl PartialOrd<Signature> for Signature
sourcefn partial_cmp(&self, other: &Signature) -> Option<Ordering>
fn partial_cmp(&self, other: &Signature) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Copy for Signature
impl Eq for Signature
impl StructuralEq for Signature
impl StructuralPartialEq for Signature
Auto Trait Implementations
impl RefUnwindSafe for Signature
impl Send for Signature
impl Sync for Signature
impl Unpin for Signature
impl UnwindSafe for Signature
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more