module Cardano.Crypto.Signing.Safe.SafeSigner
  ( SafeSigner (..),
    noPassSafeSigner,
    safeToVerification,
  )
where

import Cardano.Crypto.Signing.Safe.PassPhrase (PassPhrase, emptyPassphrase)
import Cardano.Crypto.Signing.SigningKey (SigningKey (..), toVerification)
import Cardano.Crypto.Signing.VerificationKey (VerificationKey (..))
import Cardano.Prelude

-- | SafeSigner datatype to encapsulate sensitive data
data SafeSigner = SafeSigner !SigningKey !PassPhrase
  deriving (Int -> SafeSigner -> ShowS
[SafeSigner] -> ShowS
SafeSigner -> String
(Int -> SafeSigner -> ShowS)
-> (SafeSigner -> String)
-> ([SafeSigner] -> ShowS)
-> Show SafeSigner
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SafeSigner] -> ShowS
$cshowList :: [SafeSigner] -> ShowS
show :: SafeSigner -> String
$cshow :: SafeSigner -> String
showsPrec :: Int -> SafeSigner -> ShowS
$cshowsPrec :: Int -> SafeSigner -> ShowS
Show)

noPassSafeSigner :: SigningKey -> SafeSigner
noPassSafeSigner :: SigningKey -> SafeSigner
noPassSafeSigner SigningKey
sk = SigningKey -> PassPhrase -> SafeSigner
SafeSigner SigningKey
sk PassPhrase
emptyPassphrase

safeToVerification :: SafeSigner -> VerificationKey
safeToVerification :: SafeSigner -> VerificationKey
safeToVerification (SafeSigner SigningKey
sk PassPhrase
_) = SigningKey -> VerificationKey
toVerification SigningKey
sk