csecp256k1

Haskell FFI bindings to bitcoin-core/secp256k1.
git clone git://git.ppad.tech/csecp256k1.git
Log | Files | Refs | README | LICENSE

commit 75d24657209d68b3c9eb5c17a7c38b2d71cd5a05
parent d612d7115af5f4d0bffc70192e634c7ad7843300
Author: Jared Tobin <jared@jtobin.io>
Date:   Mon, 26 Aug 2024 12:52:23 -0230

lib: w{r}context now returns IO ()

Previously one could do e.g. 'wcontext pure' in order to return the
context itself, which would be invalid outside of the wcontext block.

Diffstat:
Mlib/Crypto/Secp256k1.hs | 22++++------------------
Mtest/Main.hs | 8++++----
2 files changed, 8 insertions(+), 22 deletions(-)

diff --git a/lib/Crypto/Secp256k1.hs b/lib/Crypto/Secp256k1.hs @@ -158,22 +158,11 @@ instance Exception Secp256k1Exception -- that has /not/ been randomized, and so /doesn't/ offer additional -- side-channel attack protection. For that, use 'wrcontext'. -- --- Do /not/ attempt to use the created 'Context' value outside --- of a 'wcontext' or 'wrcontext' block, as the internal --- bitcoin-core/secp256k1 context will have been destroyed by then. --- For example, don't be cheeky and do something like: --- --- > do --- > context <- wcontext pure --- > derive_pub context seckey --- --- unless you like segfaults. --- -- >>> wcontext $ \tex -> parse_pub tex bytestring -- "<bitcoin-core/secp256k1 public key>" wcontext - :: (Context -> IO a) -- ^ continuation to run in the context - -> IO a + :: (Context -> IO ()) -- ^ continuation to run in the context + -> IO () wcontext = bracket create destroy where create = do tex <- secp256k1_context_create _SECP256K1_CONTEXT_NONE @@ -189,15 +178,12 @@ wcontext = bracket create destroy where -- Use this function to execute computations that may benefit from -- additional side-channel attack protection. -- --- As with 'wcontext', do /not/ attempt to use a created 'Context' --- value outside of the 'wrcontext' block. --- -- >>> wrcontext entropy $ \tex -> sign tex sec msg -- "<bitcoin-core/secp256k1 signature>" wrcontext :: BS.ByteString -- ^ 32 bytes of fresh entropy - -> (Context -> IO a) -- ^ continuation to run in the context - -> IO a + -> (Context -> IO ()) -- ^ continuation to run in the context + -> IO () wrcontext enn con | BS.length enn /= 32 = throwIO CSecp256k1Error | otherwise = bracket create destroy con diff --git a/test/Main.hs b/test/Main.hs @@ -129,12 +129,12 @@ parse_xonly_test = serialize_xonly_test :: TestTree serialize_xonly_test = - testCase "serialize_xonly (success)" $ do - pux <- wcontext $ \tex -> do + testCase "serialize_xonly (success)" $ + wcontext $ \tex -> do pub <- parse_pub tex _PUB_COMPRESSED key <- xonly tex pub - serialize_xonly tex key - assertEqual "success" pux _PUB_XONLY + pux <- serialize_xonly tex key + assertEqual "success" pux _PUB_XONLY keypair_test :: TestTree keypair_test =