{-# LANGUAGE ConstraintKinds            #-}
{-# LANGUAGE DataKinds                  #-}
{-# LANGUAGE DeriveGeneric              #-}
{-# LANGUAGE DerivingStrategies         #-}
{-# LANGUAGE DerivingVia                #-}
{-# LANGUAGE FlexibleContexts           #-}
{-# LANGUAGE FlexibleInstances          #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses      #-}
{-# LANGUAGE ScopedTypeVariables        #-}
{-# LANGUAGE TypeApplications           #-}
{-# LANGUAGE TypeFamilies               #-}
{-# LANGUAGE TypeOperators              #-}
{-# LANGUAGE UndecidableInstances       #-}

-- | Byron digital signatures.
module Ouroboros.Consensus.Byron.Crypto.DSIGN (
    ByronDSIGN
  , HasSignTag (..)
  , SigDSIGN (..)
  , SignKeyDSIGN (..)
  , VerKeyDSIGN (..)
  ) where


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           Cardano.Binary
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           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 :: VerKeyDSIGN ByronDSIGN -> a -> SignTag
signTagFor VerKeyDSIGN ByronDSIGN
genKey a
_ = VerKeyDSIGN ByronDSIGN -> Proxy a -> SignTag
forall a (proxy :: * -> *).
HasSignTag a =>
VerKeyDSIGN ByronDSIGN -> proxy a -> SignTag
signTag VerKeyDSIGN ByronDSIGN
genKey (Proxy a
forall k (t :: k). Proxy t
Proxy @a)

instance HasSignTag CC.UTxO.TxSigData where
  signTag :: 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 :: VerKeyDSIGN ByronDSIGN
-> proxy (Annotated ToSign ByteString) -> SignTag
signTag (VerKeyByronDSIGN 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 :: proxy ByronDSIGN -> String
algorithmNameDSIGN proxy ByronDSIGN
_ = String
"ByronDSIGN"

    -- Context required for Byron digital signatures
    --
    -- We require the the protocol magic as well as the verification key of the
    -- genesis stakeholder of which the signing node is a delegate, which is
    -- required for signing blocks.
    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
showList :: [VerKeyDSIGN ByronDSIGN] -> ShowS
$cshowList :: [VerKeyDSIGN ByronDSIGN] -> ShowS
show :: VerKeyDSIGN ByronDSIGN -> String
$cshow :: VerKeyDSIGN ByronDSIGN -> String
showsPrec :: Int -> VerKeyDSIGN ByronDSIGN -> ShowS
$cshowsPrec :: Int -> 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
/= :: VerKeyDSIGN ByronDSIGN -> VerKeyDSIGN ByronDSIGN -> Bool
$c/= :: VerKeyDSIGN ByronDSIGN -> VerKeyDSIGN ByronDSIGN -> Bool
== :: VerKeyDSIGN ByronDSIGN -> VerKeyDSIGN ByronDSIGN -> Bool
$c== :: 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
$cto :: forall x. Rep (VerKeyDSIGN ByronDSIGN) x -> VerKeyDSIGN ByronDSIGN
$cfrom :: forall x. VerKeyDSIGN ByronDSIGN -> Rep (VerKeyDSIGN ByronDSIGN) x
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
showTypeOf :: Proxy (VerKeyDSIGN ByronDSIGN) -> String
$cshowTypeOf :: Proxy (VerKeyDSIGN ByronDSIGN) -> String
wNoThunks :: Context -> VerKeyDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> VerKeyDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
noThunks :: Context -> VerKeyDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> VerKeyDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
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
showList :: [SignKeyDSIGN ByronDSIGN] -> ShowS
$cshowList :: [SignKeyDSIGN ByronDSIGN] -> ShowS
show :: SignKeyDSIGN ByronDSIGN -> String
$cshow :: SignKeyDSIGN ByronDSIGN -> String
showsPrec :: Int -> SignKeyDSIGN ByronDSIGN -> ShowS
$cshowsPrec :: Int -> 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
$cto :: forall x.
Rep (SignKeyDSIGN ByronDSIGN) x -> SignKeyDSIGN ByronDSIGN
$cfrom :: forall x.
SignKeyDSIGN ByronDSIGN -> Rep (SignKeyDSIGN ByronDSIGN) x
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
showTypeOf :: Proxy (SignKeyDSIGN ByronDSIGN) -> String
$cshowTypeOf :: Proxy (SignKeyDSIGN ByronDSIGN) -> String
wNoThunks :: Context -> SignKeyDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> SignKeyDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
noThunks :: Context -> SignKeyDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> SignKeyDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
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
showList :: [SigDSIGN ByronDSIGN] -> ShowS
$cshowList :: [SigDSIGN ByronDSIGN] -> ShowS
show :: SigDSIGN ByronDSIGN -> String
$cshow :: SigDSIGN ByronDSIGN -> String
showsPrec :: Int -> SigDSIGN ByronDSIGN -> ShowS
$cshowsPrec :: Int -> 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
/= :: SigDSIGN ByronDSIGN -> SigDSIGN ByronDSIGN -> Bool
$c/= :: SigDSIGN ByronDSIGN -> SigDSIGN ByronDSIGN -> Bool
== :: SigDSIGN ByronDSIGN -> SigDSIGN ByronDSIGN -> Bool
$c== :: 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
$cto :: forall x. Rep (SigDSIGN ByronDSIGN) x -> SigDSIGN ByronDSIGN
$cfrom :: forall x. SigDSIGN ByronDSIGN -> Rep (SigDSIGN ByronDSIGN) x
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
showTypeOf :: Proxy (SigDSIGN ByronDSIGN) -> String
$cshowTypeOf :: Proxy (SigDSIGN ByronDSIGN) -> String
wNoThunks :: Context -> SigDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> SigDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
noThunks :: Context -> SigDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> SigDSIGN ByronDSIGN -> IO (Maybe ThunkInfo)
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) -- TODO We can't get the seed size!

    deriveVerKeyDSIGN :: SignKeyDSIGN ByronDSIGN -> VerKeyDSIGN ByronDSIGN
deriveVerKeyDSIGN (SignKeyByronDSIGN sk) = VerificationKey -> VerKeyDSIGN ByronDSIGN
VerKeyByronDSIGN (VerificationKey -> VerKeyDSIGN ByronDSIGN)
-> VerificationKey -> VerKeyDSIGN ByronDSIGN
forall a b. (a -> b) -> a -> b
$ SigningKey -> VerificationKey
toVerification SigningKey
sk

    signDSIGN :: ContextDSIGN ByronDSIGN
-> a -> SignKeyDSIGN ByronDSIGN -> SigDSIGN ByronDSIGN
signDSIGN (magic, genKey) a
a (SignKeyByronDSIGN 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
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 :: ContextDSIGN ByronDSIGN
-> VerKeyDSIGN ByronDSIGN
-> a
-> SigDSIGN ByronDSIGN
-> Either String ()
verifyDSIGN (magic, genKey) (VerKeyByronDSIGN vk) a
a (SigByronDSIGN 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
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 vk)) = XPub -> ByteString
CC.unXPub XPub
vk
    rawSerialiseSignKeyDSIGN :: SignKeyDSIGN ByronDSIGN -> ByteString
rawSerialiseSignKeyDSIGN (SignKeyByronDSIGN (SigningKey sk)) = XPrv -> ByteString
CC.unXPrv XPrv
sk
    rawSerialiseSigDSIGN :: SigDSIGN ByronDSIGN -> ByteString
rawSerialiseSigDSIGN (SigByronDSIGN (Signature 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 s) = Signature ToSign -> String
forall a. Show a => a -> String
show Signature ToSign
s