Created
September 13, 2023 08:23
-
-
Save maurges/1d9500bf2a0c4e2147c4b4873fe6531b to your computer and use it in GitHub Desktop.
Assemble ecdsa presignatures into a signature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env runhaskell | |
import Data.Foldable (foldl') | |
import Numeric (showHex) | |
import System.Environment (getArgs) | |
hex = flip showHex "" | |
m = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 :: Integer | |
sumMod m = foldl' (\a b -> (a + b) `mod` m) 0 | |
main = do | |
args <- getArgs | |
let (r_hexs, s_hexs) = unzip . map (splitAt 64) $ args | |
let r_hex = head r_hexs | |
if not . all (== r_hex) $ r_hexs | |
then error "Mismatching rs" | |
else pure () | |
let ss = map (read . (<>) "0x") s_hexs :: [Integer] | |
let s' = sumMod m ss | |
let s = min s' (m - s') | |
putStrLn $ r_hex <> hex s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment