Skip to content

Commit

Permalink
feat(primitives): Add y_parity_byte_non_eip155 to Parity (#499)
Browse files Browse the repository at this point in the history
* feat(primitives): add fn to get v as 27,28 in the case of a non eip155 sig

* rename

* Update crates/primitives/src/signature/parity.rs

Co-authored-by: Bjerg <onbjerg@users.noreply.github.com>

* feat: also apply + 27 in the simple Parity case

---------

Co-authored-by: Bjerg <onbjerg@users.noreply.github.com>
  • Loading branch information
Evalir and onbjerg committed Jan 25, 2024
1 parent f5fbc85 commit 6a3a043
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions crates/primitives/src/signature/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ impl Parity {
self.y_parity() as u8
}

/// Return the y-parity byte as 27 or 28,
/// in the case of a non-EIP155 signature.
pub const fn y_parity_byte_non_eip155(&self) -> Option<u8> {
match self {
Self::NonEip155(v) | Self::Parity(v) => Some(*v as u8 + 27),
_ => None,
}
}

/// Inverts the parity.
pub const fn inverted(&self) -> Self {
match *self {
Expand Down

0 comments on commit 6a3a043

Please sign in to comment.