{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Ouroboros.Consensus.Byron.Crypto.DSIGN (
ByronDSIGN
, HasSignTag (..)
, SigDSIGN (..)
, SignKeyDSIGN (..)
, VerKeyDSIGN (..)
) where
import qualified Cardano.Chain.Block as CC.Block
import qualified Cardano.Chain.UTxO as CC.UTxO
import Cardano.Crypto (ProtocolMagicId, SignTag (..), Signature (..),
SigningKey (..), VerificationKey (..), deterministicKeyGen,
signRaw, toVerification, verifySignatureRaw)
import Cardano.Crypto.DSIGN.Class
import Cardano.Crypto.Seed (SeedBytesExhausted (..), getBytesFromSeed)
import qualified Cardano.Crypto.Signing as Crypto
import qualified Cardano.Crypto.Wallet as CC
import Cardano.Ledger.Binary
import Control.Exception (throw)
import Data.ByteString (ByteString)
import Data.Coerce (coerce)
import Data.Proxy (Proxy (..))
import GHC.Generics (Generic)
import NoThunks.Class (InspectHeapNamed (..), NoThunks)
import Ouroboros.Consensus.Util (eitherToMaybe)
import Ouroboros.Consensus.Util.Condense
class (HasSignTag a, Decoded a) => ByronSignable a
instance (HasSignTag a, Decoded a) => ByronSignable a
class HasSignTag a where
signTag :: VerKeyDSIGN ByronDSIGN -> proxy a -> SignTag
signTagFor :: forall a. HasSignTag a
=> VerKeyDSIGN ByronDSIGN -> a -> SignTag
signTagFor :: forall a. HasSignTag a => VerKeyDSIGN ByronDSIGN -> a -> SignTag
signTagFor VerKeyDSIGN ByronDSIGN
genKey a
_ = VerKeyDSIGN ByronDSIGN -> Proxy a -> SignTag
forall a (proxy :: * -> *).
HasSignTag a =>
VerKeyDSIGN ByronDSIGN -> proxy a -> SignTag
forall (proxy :: * -> *).
VerKeyDSIGN ByronDSIGN -> proxy a -> SignTag
signTag VerKeyDSIGN ByronDSIGN
genKey (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @a)
instance HasSignTag CC.UTxO.TxSigData where
signTag :: forall (proxy :: * -> *).
VerKeyDSIGN ByronDSIGN -> proxy TxSigData -> SignTag
signTag VerKeyDSIGN ByronDSIGN
_ = SignTag -> proxy TxSigData -> SignTag
forall a b. a -> b -> a
const SignTag
SignTx
instance HasSignTag (Annotated CC.Block.ToSign ByteString) where
signTag :: forall (proxy :: * -> *).
VerKeyDSIGN ByronDSIGN
-> proxy (Annotated ToSign ByteString) -> SignTag
signTag (VerKeyByronDSIGN VerificationKey
vk) = SignTag -> proxy (Annotated ToSign ByteString) -> SignTag
forall a b. a -> b -> a
const (SignTag -> proxy (Annotated ToSign ByteString) -> SignTag)
-> SignTag -> proxy (Annotated ToSign ByteString) -> SignTag
forall a b. (a -> b) -> a -> b
$ VerificationKey -> SignTag
SignBlock VerificationKey
vk
data ByronDSIGN
instance DSIGNAlgorithm ByronDSIGN where
type SeedSizeDSIGN ByronDSIGN = 32
type SizeVerKeyDSIGN ByronDSIGN = 64
type SizeSignKeyDSIGN ByronDSIGN = 128
type SizeSigDSIGN ByronDSIGN = 64
algorithmNameDSIGN :: forall (proxy :: * -> *). proxy ByronDSIGN -> String
algorithmNameDSIGN proxy ByronDSIGN
_ = String
"ByronDSIGN"
type ContextDSIGN ByronDSIGN = (ProtocolMagicId, VerKeyDSIGN ByronDSIGN)
newtype VerKeyDSIGN ByronDSIGN = VerKeyByronDSIGN VerificationKey
deriving (Int -> VerKeyDSIGN ByronDSIGN -> ShowS
[VerKeyDSIGN ByronDSIGN] -> ShowS
VerKeyDSIGN ByronDSIGN -> String
(Int -> VerKeyDSIGN ByronDSIGN -> ShowS)
-> (VerKeyDSIGN ByronDSIGN -> String)
-> ([VerKeyDSIGN ByronDSIGN] -> ShowS)
-> Show (VerKeyDSIGN ByronDSIGN)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VerKeyDSIGN ByronDSIGN -> ShowS
showsPrec :: Int -> VerKeyDSIGN ByronDSIGN -> ShowS
$cshow :: VerKeyDSIGN ByronDSIGN -> String
show :: VerKeyDSIGN ByronDSIGN -> String
$cshowList :: [VerKeyDSIGN ByronDSIGN] -> ShowS
showList :: [VerKeyDSIGN ByronDSIGN] -> ShowS
Show, VerKeyDSIGN ByronDSIGN -> VerKeyDSIGN ByronDSIGN -> Bool
(VerKeyDSIGN ByronDSIGN -> VerKeyDSIGN ByronDSIGN -> Bool)
-> (VerKeyDSIGN ByronDSIGN -> VerKeyDSIGN ByronDSIGN -> Bool)
-> Eq (VerKeyDSIGN ByronDSIGN)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: VerKeyDSIGN ByronDSIGN -> VerKeyDSIGN ByronDSIGN -> Bool
== :: VerKeyDSIGN ByronDSIGN -> VerKeyDSIGN ByronDSIGN -> Bool
$c/= :: VerKeyDSIGN ByronDSIGN -> VerKeyDSIGN ByronDSIGN -> Bool
/= :: VerKeyDSIGN ByronDSIGN -> VerKeyDSIGN ByronDSIGN -> Bool
Eq, (forall x.
VerKeyDSIGN ByronDSIGN -> Rep (VerKeyDSIGN ByronDSIGN) x)
-> (forall x.
Rep (VerKeyDSIGN ByronDSIGN) x -> VerKeyDSIGN ByronDSIGN)
-> Generic (VerKeyDSIGN ByronDSIGN)
forall x. Rep (VerKeyDSIGN ByronDSIGN) x -> VerKeyDSIGN ByronDSIGN
forall x. VerKeyDSIGN ByronDSIGN -> Rep (VerKeyDSIGN ByronDSIGN) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. VerKeyDSIGN ByronDSIGN -> Rep (VerKeyDSIGN ByronDSIGN) x
from :: forall x. VerKeyDSIGN ByronDSIGN -> Rep (VerKeyDSIGN ByronDSIGN) x
$cto :: forall x. Rep (VerKeyDSIGN ByronDSIGN) x -> VerKeyDSIGN ByronDSIGN
to :: forall x. Rep (VerKeyDSIGN ByronDSIGN) x -> VerKeyDSIGN ByronDSIGN
Generic)
deriving Context -> VerKeyDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
Proxy (VerKeyDSIGN ByronDSIGN) -> String
(Context -> VerKeyDSIGN ByronDSIGN -> IO (Maybe ThunkInfo))
-> (Context -> VerKeyDSIGN ByronDSIGN -> IO (Maybe ThunkInfo))
-> (Proxy (VerKeyDSIGN ByronDSIGN) -> String)
-> NoThunks (VerKeyDSIGN ByronDSIGN)
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: Context -> VerKeyDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
noThunks :: Context -> VerKeyDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> VerKeyDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> VerKeyDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy (VerKeyDSIGN ByronDSIGN) -> String
showTypeOf :: Proxy (VerKeyDSIGN ByronDSIGN) -> String
NoThunks via InspectHeapNamed "VerKeyDSIGN ByronDSIGN" (VerKeyDSIGN ByronDSIGN)
newtype SignKeyDSIGN ByronDSIGN = SignKeyByronDSIGN SigningKey
deriving (Int -> SignKeyDSIGN ByronDSIGN -> ShowS
[SignKeyDSIGN ByronDSIGN] -> ShowS
SignKeyDSIGN ByronDSIGN -> String
(Int -> SignKeyDSIGN ByronDSIGN -> ShowS)
-> (SignKeyDSIGN ByronDSIGN -> String)
-> ([SignKeyDSIGN ByronDSIGN] -> ShowS)
-> Show (SignKeyDSIGN ByronDSIGN)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SignKeyDSIGN ByronDSIGN -> ShowS
showsPrec :: Int -> SignKeyDSIGN ByronDSIGN -> ShowS
$cshow :: SignKeyDSIGN ByronDSIGN -> String
show :: SignKeyDSIGN ByronDSIGN -> String
$cshowList :: [SignKeyDSIGN ByronDSIGN] -> ShowS
showList :: [SignKeyDSIGN ByronDSIGN] -> ShowS
Show, (forall x.
SignKeyDSIGN ByronDSIGN -> Rep (SignKeyDSIGN ByronDSIGN) x)
-> (forall x.
Rep (SignKeyDSIGN ByronDSIGN) x -> SignKeyDSIGN ByronDSIGN)
-> Generic (SignKeyDSIGN ByronDSIGN)
forall x.
Rep (SignKeyDSIGN ByronDSIGN) x -> SignKeyDSIGN ByronDSIGN
forall x.
SignKeyDSIGN ByronDSIGN -> Rep (SignKeyDSIGN ByronDSIGN) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x.
SignKeyDSIGN ByronDSIGN -> Rep (SignKeyDSIGN ByronDSIGN) x
from :: forall x.
SignKeyDSIGN ByronDSIGN -> Rep (SignKeyDSIGN ByronDSIGN) x
$cto :: forall x.
Rep (SignKeyDSIGN ByronDSIGN) x -> SignKeyDSIGN ByronDSIGN
to :: forall x.
Rep (SignKeyDSIGN ByronDSIGN) x -> SignKeyDSIGN ByronDSIGN
Generic)
deriving Context -> SignKeyDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
Proxy (SignKeyDSIGN ByronDSIGN) -> String
(Context -> SignKeyDSIGN ByronDSIGN -> IO (Maybe ThunkInfo))
-> (Context -> SignKeyDSIGN ByronDSIGN -> IO (Maybe ThunkInfo))
-> (Proxy (SignKeyDSIGN ByronDSIGN) -> String)
-> NoThunks (SignKeyDSIGN ByronDSIGN)
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: Context -> SignKeyDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
noThunks :: Context -> SignKeyDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> SignKeyDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> SignKeyDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy (SignKeyDSIGN ByronDSIGN) -> String
showTypeOf :: Proxy (SignKeyDSIGN ByronDSIGN) -> String
NoThunks via InspectHeapNamed "SignKeyDSIGN ByronDSIGN" (SignKeyDSIGN ByronDSIGN)
newtype SigDSIGN ByronDSIGN = SigByronDSIGN (Signature CC.Block.ToSign)
deriving (Int -> SigDSIGN ByronDSIGN -> ShowS
[SigDSIGN ByronDSIGN] -> ShowS
SigDSIGN ByronDSIGN -> String
(Int -> SigDSIGN ByronDSIGN -> ShowS)
-> (SigDSIGN ByronDSIGN -> String)
-> ([SigDSIGN ByronDSIGN] -> ShowS)
-> Show (SigDSIGN ByronDSIGN)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SigDSIGN ByronDSIGN -> ShowS
showsPrec :: Int -> SigDSIGN ByronDSIGN -> ShowS
$cshow :: SigDSIGN ByronDSIGN -> String
show :: SigDSIGN ByronDSIGN -> String
$cshowList :: [SigDSIGN ByronDSIGN] -> ShowS
showList :: [SigDSIGN ByronDSIGN] -> ShowS
Show, SigDSIGN ByronDSIGN -> SigDSIGN ByronDSIGN -> Bool
(SigDSIGN ByronDSIGN -> SigDSIGN ByronDSIGN -> Bool)
-> (SigDSIGN ByronDSIGN -> SigDSIGN ByronDSIGN -> Bool)
-> Eq (SigDSIGN ByronDSIGN)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SigDSIGN ByronDSIGN -> SigDSIGN ByronDSIGN -> Bool
== :: SigDSIGN ByronDSIGN -> SigDSIGN ByronDSIGN -> Bool
$c/= :: SigDSIGN ByronDSIGN -> SigDSIGN ByronDSIGN -> Bool
/= :: SigDSIGN ByronDSIGN -> SigDSIGN ByronDSIGN -> Bool
Eq, (forall x. SigDSIGN ByronDSIGN -> Rep (SigDSIGN ByronDSIGN) x)
-> (forall x. Rep (SigDSIGN ByronDSIGN) x -> SigDSIGN ByronDSIGN)
-> Generic (SigDSIGN ByronDSIGN)
forall x. Rep (SigDSIGN ByronDSIGN) x -> SigDSIGN ByronDSIGN
forall x. SigDSIGN ByronDSIGN -> Rep (SigDSIGN ByronDSIGN) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SigDSIGN ByronDSIGN -> Rep (SigDSIGN ByronDSIGN) x
from :: forall x. SigDSIGN ByronDSIGN -> Rep (SigDSIGN ByronDSIGN) x
$cto :: forall x. Rep (SigDSIGN ByronDSIGN) x -> SigDSIGN ByronDSIGN
to :: forall x. Rep (SigDSIGN ByronDSIGN) x -> SigDSIGN ByronDSIGN
Generic)
deriving Context -> SigDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
Proxy (SigDSIGN ByronDSIGN) -> String
(Context -> SigDSIGN ByronDSIGN -> IO (Maybe ThunkInfo))
-> (Context -> SigDSIGN ByronDSIGN -> IO (Maybe ThunkInfo))
-> (Proxy (SigDSIGN ByronDSIGN) -> String)
-> NoThunks (SigDSIGN ByronDSIGN)
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: Context -> SigDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
noThunks :: Context -> SigDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> SigDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> SigDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy (SigDSIGN ByronDSIGN) -> String
showTypeOf :: Proxy (SigDSIGN ByronDSIGN) -> String
NoThunks via InspectHeapNamed "SigDSIGN ByronDSIGN" (SigDSIGN ByronDSIGN)
type Signable ByronDSIGN = ByronSignable
genKeyDSIGN :: Seed -> SignKeyDSIGN ByronDSIGN
genKeyDSIGN Seed
seed =
SigningKey -> SignKeyDSIGN ByronDSIGN
SignKeyByronDSIGN (SigningKey -> SignKeyDSIGN ByronDSIGN)
-> ((VerificationKey, SigningKey) -> SigningKey)
-> (VerificationKey, SigningKey)
-> SignKeyDSIGN ByronDSIGN
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (VerificationKey, SigningKey) -> SigningKey
forall a b. (a, b) -> b
snd ((VerificationKey, SigningKey) -> SignKeyDSIGN ByronDSIGN)
-> (VerificationKey, SigningKey) -> SignKeyDSIGN ByronDSIGN
forall a b. (a -> b) -> a -> b
$ ByteString -> (VerificationKey, SigningKey)
deterministicKeyGen ByteString
seedBytes
where
seedBytes :: ByteString
seedBytes = case Word -> Seed -> Maybe (ByteString, Seed)
getBytesFromSeed Word
32 Seed
seed of
Just (ByteString
x,Seed
_) -> ByteString
x
Maybe (ByteString, Seed)
Nothing -> SeedBytesExhausted -> ByteString
forall a e. Exception e => e -> a
throw (SeedBytesExhausted -> ByteString)
-> SeedBytesExhausted -> ByteString
forall a b. (a -> b) -> a -> b
$ Int -> SeedBytesExhausted
SeedBytesExhausted (-Int
1)
deriveVerKeyDSIGN :: SignKeyDSIGN ByronDSIGN -> VerKeyDSIGN ByronDSIGN
deriveVerKeyDSIGN (SignKeyByronDSIGN SigningKey
sk) = VerificationKey -> VerKeyDSIGN ByronDSIGN
VerKeyByronDSIGN (VerificationKey -> VerKeyDSIGN ByronDSIGN)
-> VerificationKey -> VerKeyDSIGN ByronDSIGN
forall a b. (a -> b) -> a -> b
$ SigningKey -> VerificationKey
toVerification SigningKey
sk
signDSIGN :: forall a.
(Signable ByronDSIGN a, HasCallStack) =>
ContextDSIGN ByronDSIGN
-> a -> SignKeyDSIGN ByronDSIGN -> SigDSIGN ByronDSIGN
signDSIGN (ProtocolMagicId
magic, VerKeyDSIGN ByronDSIGN
genKey) a
a (SignKeyByronDSIGN SigningKey
sk) =
Signature ToSign -> SigDSIGN ByronDSIGN
SigByronDSIGN
(Signature ToSign -> SigDSIGN ByronDSIGN)
-> (Signature Raw -> Signature ToSign)
-> Signature Raw
-> SigDSIGN ByronDSIGN
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Signature Raw -> Signature ToSign
forall a b. Coercible a b => a -> b
coerce
(Signature Raw -> SigDSIGN ByronDSIGN)
-> Signature Raw -> SigDSIGN ByronDSIGN
forall a b. (a -> b) -> a -> b
$ ProtocolMagicId
-> Maybe SignTag -> SigningKey -> ByteString -> Signature Raw
signRaw ProtocolMagicId
magic (SignTag -> Maybe SignTag
forall a. a -> Maybe a
Just (SignTag -> Maybe SignTag) -> SignTag -> Maybe SignTag
forall a b. (a -> b) -> a -> b
$ VerKeyDSIGN ByronDSIGN -> a -> SignTag
forall a. HasSignTag a => VerKeyDSIGN ByronDSIGN -> a -> SignTag
signTagFor VerKeyDSIGN ByronDSIGN
genKey a
a) SigningKey
sk (a -> ByteString
forall t. Decoded t => t -> ByteString
recoverBytes a
a)
verifyDSIGN :: forall a.
(Signable ByronDSIGN a, HasCallStack) =>
ContextDSIGN ByronDSIGN
-> VerKeyDSIGN ByronDSIGN
-> a
-> SigDSIGN ByronDSIGN
-> Either String ()
verifyDSIGN (ProtocolMagicId
magic, VerKeyDSIGN ByronDSIGN
genKey) (VerKeyByronDSIGN VerificationKey
vk) a
a (SigByronDSIGN Signature ToSign
sig) =
if VerificationKey -> ByteString -> Signature Raw -> Bool
verifySignatureRaw VerificationKey
vk (ProtocolMagicId -> SignTag -> ByteString
Crypto.signTag ProtocolMagicId
magic (VerKeyDSIGN ByronDSIGN -> a -> SignTag
forall a. HasSignTag a => VerKeyDSIGN ByronDSIGN -> a -> SignTag
signTagFor VerKeyDSIGN ByronDSIGN
genKey a
a) ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> a -> ByteString
forall t. Decoded t => t -> ByteString
recoverBytes a
a) (Signature Raw -> Bool) -> Signature Raw -> Bool
forall a b. (a -> b) -> a -> b
$ Signature ToSign -> Signature Raw
forall a b. Coercible a b => a -> b
coerce Signature ToSign
sig
then () -> Either String ()
forall a b. b -> Either a b
Right ()
else String -> Either String ()
forall a b. a -> Either a b
Left String
"Verification failed"
rawSerialiseVerKeyDSIGN :: VerKeyDSIGN ByronDSIGN -> ByteString
rawSerialiseVerKeyDSIGN (VerKeyByronDSIGN (VerificationKey XPub
vk)) = XPub -> ByteString
CC.unXPub XPub
vk
rawSerialiseSignKeyDSIGN :: SignKeyDSIGN ByronDSIGN -> ByteString
rawSerialiseSignKeyDSIGN (SignKeyByronDSIGN (SigningKey XPrv
sk)) = XPrv -> ByteString
CC.unXPrv XPrv
sk
rawSerialiseSigDSIGN :: SigDSIGN ByronDSIGN -> ByteString
rawSerialiseSigDSIGN (SigByronDSIGN (Signature XSignature
sig)) = XSignature -> ByteString
CC.unXSignature XSignature
sig
rawDeserialiseVerKeyDSIGN :: ByteString -> Maybe (VerKeyDSIGN ByronDSIGN)
rawDeserialiseVerKeyDSIGN ByteString
bs =
VerificationKey -> VerKeyDSIGN ByronDSIGN
VerKeyByronDSIGN (VerificationKey -> VerKeyDSIGN ByronDSIGN)
-> (XPub -> VerificationKey) -> XPub -> VerKeyDSIGN ByronDSIGN
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XPub -> VerificationKey
VerificationKey (XPub -> VerKeyDSIGN ByronDSIGN)
-> Maybe XPub -> Maybe (VerKeyDSIGN ByronDSIGN)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Either String XPub -> Maybe XPub
forall a b. Either a b -> Maybe b
eitherToMaybe (Either String XPub -> Maybe XPub)
-> Either String XPub -> Maybe XPub
forall a b. (a -> b) -> a -> b
$ ByteString -> Either String XPub
CC.xpub ByteString
bs)
rawDeserialiseSignKeyDSIGN :: ByteString -> Maybe (SignKeyDSIGN ByronDSIGN)
rawDeserialiseSignKeyDSIGN ByteString
bs =
SigningKey -> SignKeyDSIGN ByronDSIGN
SignKeyByronDSIGN (SigningKey -> SignKeyDSIGN ByronDSIGN)
-> (XPrv -> SigningKey) -> XPrv -> SignKeyDSIGN ByronDSIGN
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XPrv -> SigningKey
SigningKey (XPrv -> SignKeyDSIGN ByronDSIGN)
-> Maybe XPrv -> Maybe (SignKeyDSIGN ByronDSIGN)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Either String XPrv -> Maybe XPrv
forall a b. Either a b -> Maybe b
eitherToMaybe (Either String XPrv -> Maybe XPrv)
-> Either String XPrv -> Maybe XPrv
forall a b. (a -> b) -> a -> b
$ ByteString -> Either String XPrv
forall bin. ByteArrayAccess bin => bin -> Either String XPrv
CC.xprv ByteString
bs)
rawDeserialiseSigDSIGN :: ByteString -> Maybe (SigDSIGN ByronDSIGN)
rawDeserialiseSigDSIGN ByteString
bs =
Signature ToSign -> SigDSIGN ByronDSIGN
SigByronDSIGN (Signature ToSign -> SigDSIGN ByronDSIGN)
-> (XSignature -> Signature ToSign)
-> XSignature
-> SigDSIGN ByronDSIGN
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XSignature -> Signature ToSign
forall a. XSignature -> Signature a
Signature (XSignature -> SigDSIGN ByronDSIGN)
-> Maybe XSignature -> Maybe (SigDSIGN ByronDSIGN)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Either String XSignature -> Maybe XSignature
forall a b. Either a b -> Maybe b
eitherToMaybe (Either String XSignature -> Maybe XSignature)
-> Either String XSignature -> Maybe XSignature
forall a b. (a -> b) -> a -> b
$ ByteString -> Either String XSignature
CC.xsignature ByteString
bs)
instance Condense (SigDSIGN ByronDSIGN) where
condense :: SigDSIGN ByronDSIGN -> String
condense (SigByronDSIGN Signature ToSign
s) = Signature ToSign -> String
forall a. Show a => a -> String
show Signature ToSign
s