diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2021-08-17 20:25:03 +0000 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2021-08-17 20:25:03 +0000 |
| commit | ce4994f3efaed2afbf75d58a627342bac54160db (patch) | |
| tree | 072ec72ae0f3e4e5e636eb84a380398a59c3bbee /src/account.rs | |
| parent | 53c20ea16872d1a7ab3e394d972f7b856d48dd0b (diff) | |
Signature now has a parity value
This is done as a pre-requisite to adding additional transaction types.
Diffstat (limited to 'src/account.rs')
| -rw-r--r-- | src/account.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/account.rs b/src/account.rs index 6233f6a..511d6aa 100644 --- a/src/account.rs +++ b/src/account.rs @@ -3,7 +3,10 @@ mod address; mod signature; -pub use self::{address::Address, signature::Signature}; +pub use self::{ + address::Address, + signature::{Parity, Signature}, +}; use crate::hash; use anyhow::Result; use secp256k1::{ @@ -61,7 +64,11 @@ impl PrivateKey { debug_assert_eq!(raw_signature.len(), 64); Signature { - v: 27 + (recovery_id.to_i32() as u8), + y_parity: match recovery_id.to_i32() { + 0 => Parity::Even, + 1 => Parity::Odd, + n => unreachable!("non 0 or 1 signature y-parity bit {}", n), + }, r: raw_signature[..32].try_into().unwrap(), s: raw_signature[32..].try_into().unwrap(), } @@ -76,7 +83,7 @@ impl Debug for PrivateKey { impl Drop for PrivateKey { fn drop(&mut self) { - self.0 = ONE_KEY + self.0 = ONE_KEY; } } @@ -102,7 +109,7 @@ mod tests { assert_eq!( key.sign(message), Signature { - v: 28, + y_parity: Parity::Odd, r: hex!("408790f153cbfa2722fc708a57d97a43b24429724cf060df7c915d468c43bd84"), s: hex!("61c96aac95ce37d7a31087b6634f4a3ea439a9f704b5c818584fa2a32fa83859"), }, |
