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<'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.