{-# LANGUAGE CPP #-}

-- | Initialization for the library's functionality
module Cardano.Crypto.Init (
  cryptoInit
  ) where

import Cardano.Crypto.Libsodium.Init (sodiumInit)
#if defined(SECP256K1_ENABLED)
import Control.Monad (void)
import Cardano.Crypto.SECP256K1.C (secpCtxPtr)
import Control.Exception (evaluate)
#endif

-- | Initialize all the functionality provided by this library. This should be
-- called at least once /before/ you use anything this library provides, in
-- @main@.
--
-- It is safe to call this multiple times, but isn't necessary.
--
-- = Note
--
-- This includes a call to 'sodiumInit'. 
cryptoInit :: IO ()
cryptoInit :: IO ()
cryptoInit = do
  IO ()
sodiumInit
#if defined(SECP256K1_ENABLED)
  IO (ForeignPtr SECP256k1Context) -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO (ForeignPtr SECP256k1Context) -> IO ())
-> (ForeignPtr SECP256k1Context
    -> IO (ForeignPtr SECP256k1Context))
-> ForeignPtr SECP256k1Context
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ForeignPtr SECP256k1Context -> IO (ForeignPtr SECP256k1Context)
forall a. a -> IO a
evaluate (ForeignPtr SECP256k1Context -> IO ())
-> ForeignPtr SECP256k1Context -> IO ()
forall a b. (a -> b) -> a -> b
$ ForeignPtr SECP256k1Context
secpCtxPtr
#endif