Struct web3_signature::Signature
source · pub struct Signature {
pub r: U256,
pub s: U256,
pub v: u64,
}
Expand description
An ECDSA signature with a recovery identifier.
The recovery identifier may be normalized, in Electrum notation or have EIP155 chain replay protection applied.
Fields§
§r: U256
R value
s: U256
S value
v: u64
V value for the recovery identifier
Implementations§
source§impl Signature
impl Signature
sourcepub fn new_normalized(r: U256, s: U256, v: u64) -> Self
pub fn new_normalized(r: U256, s: U256, v: u64) -> Self
Create a signature with normalized recovery identifier.
sourcepub fn new_electrum(r: U256, s: U256, v: u64) -> Self
pub fn new_electrum(r: U256, s: U256, v: u64) -> Self
Create a signature with electrum recovery identifier.
sourcepub fn new_eip155(r: U256, s: U256, v: u64) -> Self
pub fn new_eip155(r: U256, s: U256, v: u64) -> Self
Create a signature with EIP155 chain replay protection.
sourcepub fn is_normalized(&self) -> bool
pub fn is_normalized(&self) -> bool
Is the recovery identifier for this signature in
the normalized form (0
or 1
).
sourcepub fn is_electrum(&self) -> bool
pub fn is_electrum(&self) -> bool
Is the recovery identifier for this signature in
the electrum form (27
or 28
).
sourcepub fn is_eip155(&self) -> bool
pub fn is_eip155(&self) -> bool
Is the recovery identifier for this signature in the EIP155 form.
sourcepub fn normalize(self) -> Self
pub fn normalize(self) -> Self
Converts this signature into normalized form from an Electrum signature.
Panics if this signature is not in Electrum format.
sourcepub fn normalize_eip155(self, chain_id: u64) -> Self
pub fn normalize_eip155(self, chain_id: u64) -> Self
Converts this signature into normalized form from an EIP155 signature.
Panics if the signature could not be safely normalized for
example if a chain_id
was supplied that would cause the
existing v
value to become negative.
sourcepub fn into_electrum(self) -> Self
pub fn into_electrum(self) -> Self
Converts this signature into Electrum form.
Panics if this signature is not in it’s normalized form.
sourcepub fn into_eip155(self, chain_id: u64) -> Self
pub fn into_eip155(self, chain_id: u64) -> Self
Converts this signature applying EIP155 chain replay protection.
Panics if this signature is not in it’s normalized form.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Signature
impl<'de> Deserialize<'de> for Signature
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 PartialEq<Signature> for Signature
impl PartialEq<Signature> for Signature
source§impl<'a> TryFrom<&'a [u8]> for Signature
impl<'a> TryFrom<&'a [u8]> for Signature
source§fn try_from(bytes: &'a [u8]) -> Result<Self, Self::Error>
fn try_from(bytes: &'a [u8]) -> Result<Self, Self::Error>
Parses a raw signature which is expected to be 65 bytes long where
the first 32 bytes is the r
value, the second 32 bytes the s
value
and the final byte is the v
value in ‘Electrum’ notation.