diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2021-08-20 13:54:43 +0000 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2021-08-20 13:54:43 +0000 |
| commit | c05487949a5cb9808945b5bdd174e14fdd7e51ea (patch) | |
| tree | 8d51bbe6968aae3bd99f8664f31214e84464c64d /src/account/signature.rs | |
| parent | f2817a2f4db1eb23fb6f422b937e161324a35d54 (diff) | |
Add support for multiple transaction formats
Additionally, transaction signing is now from file instead of being from command line arguments
Diffstat (limited to 'src/account/signature.rs')
| -rw-r--r-- | src/account/signature.rs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/account/signature.rs b/src/account/signature.rs index 012aea5..f017756 100644 --- a/src/account/signature.rs +++ b/src/account/signature.rs @@ -1,23 +1,29 @@ //! Module containing signature data model. -use ethnum::U256; +use ethnum::{AsU256, U256}; use std::fmt::{self, Display, Formatter}; -/// Signature Y-parity value. +/// The parity of the y-value of a secp256k1 signature. #[derive(Clone, Copy, Debug, Eq, PartialEq)] #[repr(u8)] -pub enum Parity { +pub enum YParity { /// Even parity. Even = 0, /// Odd parity. Odd = 1, } +impl AsU256 for YParity { + fn as_u256(self) -> U256 { + U256::new(self as _) + } +} + /// A secp256k1 signature. #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct Signature { /// Signature V value in Electrum notation. - pub y_parity: Parity, + pub y_parity: YParity, /// Signature R value. pub r: [u8; 32], /// Signature S value. @@ -32,7 +38,7 @@ impl Signature { /// Returns the signature's V value with EIP-155 chain replay protection. pub fn v_replay_protected(&self, chain_id: U256) -> U256 { - U256::new(self.y_parity as _) + chain_id * 2 + 35 + self.y_parity.as_u256() + chain_id * 2 + 35 } } @@ -55,7 +61,7 @@ mod tests { #[test] fn replay_protection() { let signature = Signature { - y_parity: Parity::Even, + y_parity: YParity::Even, r: [1; 32], s: [2; 32], }; @@ -65,7 +71,7 @@ mod tests { #[test] fn signature_to_string() { let signature = Signature { - y_parity: Parity::Even, + y_parity: YParity::Even, r: [1; 32], s: [2; 32], }; |
