Enum clarity::Signature

source ·
pub enum Signature {
    LegacySignature {
        v: Uint256,
        r: Uint256,
        s: Uint256,
    },
    ModernSignature {
        v: bool,
        r: Uint256,
        s: Uint256,
    },
}

Variants§

§

LegacySignature

§

ModernSignature

Fields

§v: bool

todo fix serialization here

Implementations§

source§

impl Signature

source

pub fn new(v: bool, r: Uint256, s: Uint256) -> Signature

source

pub fn new_legacy(v: Uint256, r: Uint256, s: Uint256) -> Signature

source

pub fn get_r(&self) -> Uint256

source

pub fn get_s(&self) -> Uint256

source

pub fn get_v(&self) -> Uint256

Gets the v value, potentially encoded with a chain id

source

pub fn error_check(&self) -> Result<(), Error>

Like is_valid() but returns a reason

source

pub fn is_valid(&self) -> bool

source

pub fn legacy_network_id(&self) -> Option<Uint256>

Extracts the chain id from the legacy signature v value will return none if the signature is either a legacy signature not protected from replay or if the signature is a modern signature at which point the chain_id value is contained in the tx

source

pub fn get_signature_v(&self) -> Result<u8, Error>

Get the actual signature component V value, only two possibilities 27 or 28 this is different from V encoded with a chain id for which you should use get_v()

source

pub fn into_bytes(self) -> [u8; 65]

Converts a signature into a bytes string.

A signature in binary form consists of 65 bytes where first 32 bytes are “r” in big endian form, next 32 bytes are “s” in big endian form, and at the end there is one byte made of “v”.

This also consumes the signature.

source

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

Extracts signature as bytes.

This supersedes into_bytes as it does not consume the object itself.

source

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

Constructs a signature from a bytes string

This is opposite to into_bytes() where a signature is created based on a slice of bytes.

source

pub fn recover(&self, hash: &[u8]) -> Result<Address, Error>

Recover an address from a signature

This can be called with any arbitrary signature, and a hashed message.

Trait Implementations§

source§

impl Clone for Signature

source§

fn clone(&self) -> Signature

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Signature

source§

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

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

impl<'de> Deserialize<'de> for Signature

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Signature

source§

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

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

impl FromStr for Signature

source§

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

Constructs a signature back from a string representation

The input string’s length should be exactly 130 not including optional “0x” prefix at the beggining.

§

type Err = Error

The associated error which can be returned from parsing.
source§

impl Hash for Signature

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl LowerHex for Signature

source§

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

Formats the value using the given formatter.
source§

impl PartialEq for Signature

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Signature

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl UpperHex for Signature

source§

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

Formats the value using the given formatter.
source§

impl Eq for Signature

source§

impl StructuralPartialEq for Signature

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<U> As for U

source§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. 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, 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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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

§

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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,