{-# LANGUAGE DataKinds                  #-}
{-# LANGUAGE FlexibleInstances          #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses      #-}
{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE TypeOperators              #-}

-- |
-- Module      :  Network.Ipfs.Api.Key
-- Copyright   :  Aleksandr Krupenkin 2016-2021
-- License     :  Apache-2.0
--
-- Maintainer  :  mail@akru.me
-- Stability   :  experimental
-- Portability :  unknown
--
-- Api calls with `key` prefix.
--

module Network.Ipfs.Api.Key where

import           Control.Monad.IO.Class         (MonadIO)
import           Data.Text                      (Text)

import           Network.Ipfs.Api.Internal      (_keyGen, _keyList, _keyRename,
                                                 _keyRm)
import           Network.Ipfs.Api.Internal.Call (call)
import           Network.Ipfs.Api.Types         (KeyDetailsObj, KeyObj,
                                                 KeyRenameObj)
import           Network.Ipfs.Client            (IpfsT)


-- | 'List all local keypairs.
list :: MonadIO m => IpfsT m KeyObj
list :: IpfsT m KeyObj
list = ClientM KeyObj -> IpfsT m KeyObj
forall (m :: * -> *) a. MonadIO m => ClientM a -> IpfsT m a
call ClientM KeyObj
_keyList

-- | Create a new keypair.
gen :: MonadIO m => Text -> Text -> IpfsT m KeyDetailsObj
gen :: Text -> Text -> IpfsT m KeyDetailsObj
gen Text
name = ClientM KeyDetailsObj -> IpfsT m KeyDetailsObj
forall (m :: * -> *) a. MonadIO m => ClientM a -> IpfsT m a
call (ClientM KeyDetailsObj -> IpfsT m KeyDetailsObj)
-> (Text -> ClientM KeyDetailsObj) -> Text -> IpfsT m KeyDetailsObj
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text -> ClientM KeyDetailsObj
_keyGen Text
name (Maybe Text -> ClientM KeyDetailsObj)
-> (Text -> Maybe Text) -> Text -> ClientM KeyDetailsObj
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text
forall a. a -> Maybe a
Just

-- | Rename a keypair.
rename :: MonadIO m => Text -> Text -> IpfsT m KeyRenameObj
rename :: Text -> Text -> IpfsT m KeyRenameObj
rename Text
was = ClientM KeyRenameObj -> IpfsT m KeyRenameObj
forall (m :: * -> *) a. MonadIO m => ClientM a -> IpfsT m a
call (ClientM KeyRenameObj -> IpfsT m KeyRenameObj)
-> (Text -> ClientM KeyRenameObj) -> Text -> IpfsT m KeyRenameObj
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text -> ClientM KeyRenameObj
_keyRename Text
was (Maybe Text -> ClientM KeyRenameObj)
-> (Text -> Maybe Text) -> Text -> ClientM KeyRenameObj
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text
forall a. a -> Maybe a
Just

-- | Remove a keypair.
rm :: MonadIO m => Text -> IpfsT m KeyObj
rm :: Text -> IpfsT m KeyObj
rm = ClientM KeyObj -> IpfsT m KeyObj
forall (m :: * -> *) a. MonadIO m => ClientM a -> IpfsT m a
call (ClientM KeyObj -> IpfsT m KeyObj)
-> (Text -> ClientM KeyObj) -> Text -> IpfsT m KeyObj
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ClientM KeyObj
_keyRm