-- | Functions that are intended to be used in tests, but not in the executable
-- specifications. These functions are not possible in practice (like recovering
-- the signed data from the signature only), but are possible for the abstract
-- data we use in the specifications.
module Byron.Spec.Ledger.Core.Omniscient where

import Byron.Spec.Ledger.Core (
  SKey (SKey),
  Sig (Sig),
  VKey (VKey),
  VKeyGenesis,
  owner,
  sign,
  unVKeyGenesis,
 )

-- | Extract the verifying key of a signature. This is useful when elaborating
-- an abstract signature into a concrete one.
signatureVKey :: Sig a -> VKey
signatureVKey :: forall a. Sig a -> VKey
signatureVKey (Sig a
_someData Owner
someOwner) = Owner -> VKey
VKey Owner
someOwner

-- | Extract the signature data.
signatureData :: Sig a -> a
signatureData :: forall a. Sig a -> a
signatureData (Sig a
someData Owner
_someOwner) = a
someData

-- | Get the signing key from the verification key. We use this in the
-- generators, where we need to generate signed data for a given verification
-- key (e.g. one that appears in the delegation map) for which we don't have
-- the signing key.
skey :: VKey -> SKey
skey :: VKey -> SKey
skey = Owner -> SKey
SKey forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. HasOwner a => a -> Owner
owner

-- | Sign using a genesis verifying key.
--
-- See 'skey' for details about situations where this function is used.
signWithGenesisKey :: VKeyGenesis -> a -> Sig a
signWithGenesisKey :: forall a. VKeyGenesis -> a -> Sig a
signWithGenesisKey VKeyGenesis
vkg = forall a. SKey -> a -> Sig a
sign (VKey -> SKey
skey (VKeyGenesis -> VKey
unVKeyGenesis VKeyGenesis
vkg))