mirror of
https://github.com/ilyakooo0/secp256k1-haskell.git
synced 2024-09-11 12:25:38 +03:00
parent
539999933e
commit
3307b6d5dd
@ -482,15 +482,18 @@ tweakMulPubKey (PubKey fp) (Tweak ft) = withContext $ \ctx ->
|
||||
|
||||
-- | Add multiple public keys together.
|
||||
combinePubKeys :: [PubKey] -> Maybe PubKey
|
||||
combinePubKeys pubs = withContext $ \ctx -> pointers [] pubs $ \ps ->
|
||||
allocaArray (length ps) $ \a -> do
|
||||
pokeArray a ps
|
||||
fp <- mallocForeignPtr
|
||||
ret <- withForeignPtr fp $ \p ->
|
||||
ecPubKeyCombine ctx p a (fromIntegral $ length ps)
|
||||
if isSuccess ret
|
||||
then return $ Just $ PubKey fp
|
||||
else return Nothing
|
||||
combinePubKeys pubs = withContext $ \ctx ->
|
||||
if pubs == []
|
||||
then return Nothing
|
||||
else pointers [] pubs $ \ps ->
|
||||
allocaArray (length ps) $ \a -> do
|
||||
pokeArray a ps
|
||||
fp <- mallocForeignPtr
|
||||
ret <- withForeignPtr fp $ \p ->
|
||||
ecPubKeyCombine ctx p a (fromIntegral $ length ps)
|
||||
if isSuccess ret
|
||||
then return $ Just $ PubKey fp
|
||||
else return Nothing
|
||||
where
|
||||
pointers ps [] f = f ps
|
||||
pointers ps (PubKey fp : pubs') f =
|
||||
|
@ -57,6 +57,7 @@ spec = do
|
||||
it "add public key" $ property $ tweakAddPubKeyTest
|
||||
it "multiply public key" $ property $ tweakMulPubKeyTest
|
||||
it "combine public keys" $ property $ combinePubKeyTest
|
||||
it "can't combine 0 public keys" $ property $ combinePubKeyEmptyListTest
|
||||
it "negates tweak" $ property $ negateTweakTest
|
||||
#ifdef ECDH
|
||||
describe "ecdh" $ do
|
||||
@ -277,6 +278,13 @@ combinePubKeyTest =
|
||||
expected = importPubKey $ hexToBytes
|
||||
"043d9a7ec70011efc23c33a7e62d2ea73cca87797e3b659d93bea6aa871aebde56c3bc6134ca82e324b0ab9c0e601a6d2933afe7fb5d9f3aae900f5c5dc6e362c8"
|
||||
|
||||
combinePubKeyEmptyListTest :: Assertion
|
||||
combinePubKeyEmptyListTest =
|
||||
assertEqual "empty pubkey list must return Nothing" expected combined
|
||||
where
|
||||
expected = Nothing
|
||||
combined = combinePubKeys []
|
||||
|
||||
negateTweakTest :: Assertion
|
||||
negateTweakTest =
|
||||
assertEqual "can recover secret key 1 after adding tweak 1" oneKey subtracted
|
||||
|
Loading…
Reference in New Issue
Block a user