Skip to content

Commit

Permalink
Fix recoverPublicKey
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgenii Akentev committed Nov 15, 2023
1 parent 5fd48f3 commit ffbf20e
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src-secp256k1/Crypto/Secp256k1/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -666,13 +666,17 @@ recoverPublicKey
-> Bool
-- ^ is second key
-> Maybe Point
recoverPublicKey e r s oddY secondKey = case nC *. rP of
O -> if validatePublicKey pk then Just pk else Nothing
_ -> error "something went wrong (probably the value for second key is incorrect)"
recoverPublicKey e r s oddY secondKey
| Just rP <- pointFromX x oddY =
case nC *. rP of
O ->
let pk = invM r .*. (s .*. rP .-. e .*. gC)
in if validatePublicKey pk then Just pk else Nothing
_ -> error "something went wrong (probably the value for second key is incorrect)"
| otherwise = Nothing
where
x = if secondKey then zConv r .+ fp nC else zConv r
Just rP = pointFromX x oddY -- FIXME this fails for an invalid @secondKey@ value
pk = invM r .*. (s .*. rP .-. e .*. gC)


-- -------------------------------------------------------------------------- --
-- Hexdecimal Representation
Expand Down

0 comments on commit ffbf20e

Please sign in to comment.