{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Cardano.Ledger.Keys.Bootstrap (
BootstrapWitness (..),
ChainCode (..),
bootstrapWitKeyHash,
unpackByronVKey,
makeBootstrapWitness,
verifyBootstrapWit,
) where
import qualified Cardano.Chain.Common as Byron
import Cardano.Crypto.DSIGN (SignedDSIGN (..))
import qualified Cardano.Crypto.DSIGN as DSIGN
import qualified Cardano.Crypto.DSIGN.Class as C
import qualified Cardano.Crypto.Hash as Hash
import qualified Cardano.Crypto.Signing as Byron
import qualified Cardano.Crypto.Wallet as WC
import Cardano.Ledger.Binary (DecCBOR (..), EncCBOR (..))
import Cardano.Ledger.Binary.Plain (
FromCBOR (..),
ToCBOR (..),
decodeRecordNamed,
encodeListLen,
serialize',
)
import Cardano.Ledger.Hashes (ADDRHASH, EraIndependentTxBody, HASH, Hash, KeyHash (..))
import Cardano.Ledger.Keys.Internal (
DSIGN,
KeyRole (..),
VKey (..),
verifySignedDSIGN,
)
import Control.DeepSeq (NFData (..), rwhnf)
import Data.ByteString (ByteString)
import Data.Coerce (coerce)
import Data.Maybe (fromMaybe)
import Data.Ord (comparing)
import Data.Proxy (Proxy (..))
import GHC.Generics (Generic)
import NoThunks.Class (NoThunks (..))
import Quiet
newtype ChainCode = ChainCode {ChainCode -> ByteString
unChainCode :: ByteString}
deriving (ChainCode -> ChainCode -> Bool
(ChainCode -> ChainCode -> Bool)
-> (ChainCode -> ChainCode -> Bool) -> Eq ChainCode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChainCode -> ChainCode -> Bool
== :: ChainCode -> ChainCode -> Bool
$c/= :: ChainCode -> ChainCode -> Bool
/= :: ChainCode -> ChainCode -> Bool
Eq, (forall x. ChainCode -> Rep ChainCode x)
-> (forall x. Rep ChainCode x -> ChainCode) -> Generic ChainCode
forall x. Rep ChainCode x -> ChainCode
forall x. ChainCode -> Rep ChainCode x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ChainCode -> Rep ChainCode x
from :: forall x. ChainCode -> Rep ChainCode x
$cto :: forall x. Rep ChainCode x -> ChainCode
to :: forall x. Rep ChainCode x -> ChainCode
Generic)
deriving (Int -> ChainCode -> ShowS
[ChainCode] -> ShowS
ChainCode -> String
(Int -> ChainCode -> ShowS)
-> (ChainCode -> String)
-> ([ChainCode] -> ShowS)
-> Show ChainCode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChainCode -> ShowS
showsPrec :: Int -> ChainCode -> ShowS
$cshow :: ChainCode -> String
show :: ChainCode -> String
$cshowList :: [ChainCode] -> ShowS
showList :: [ChainCode] -> ShowS
Show) via Quiet ChainCode
deriving newtype (Context -> ChainCode -> IO (Maybe ThunkInfo)
Proxy ChainCode -> String
(Context -> ChainCode -> IO (Maybe ThunkInfo))
-> (Context -> ChainCode -> IO (Maybe ThunkInfo))
-> (Proxy ChainCode -> String)
-> NoThunks ChainCode
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: Context -> ChainCode -> IO (Maybe ThunkInfo)
noThunks :: Context -> ChainCode -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> ChainCode -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> ChainCode -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy ChainCode -> String
showTypeOf :: Proxy ChainCode -> String
NoThunks, Typeable ChainCode
Typeable ChainCode =>
(ChainCode -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size)
-> Proxy ChainCode -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [ChainCode] -> Size)
-> ToCBOR ChainCode
ChainCode -> Encoding
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [ChainCode] -> Size
(forall t. ToCBOR t => Proxy t -> Size) -> Proxy ChainCode -> Size
forall a.
Typeable a =>
(a -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy a -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy [a] -> Size)
-> ToCBOR a
$ctoCBOR :: ChainCode -> Encoding
toCBOR :: ChainCode -> Encoding
$cencodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy ChainCode -> Size
encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy ChainCode -> Size
$cencodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [ChainCode] -> Size
encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [ChainCode] -> Size
ToCBOR, Typeable ChainCode
Typeable ChainCode =>
(forall s. Decoder s ChainCode)
-> (Proxy ChainCode -> Text) -> FromCBOR ChainCode
Proxy ChainCode -> Text
forall s. Decoder s ChainCode
forall a.
Typeable a =>
(forall s. Decoder s a) -> (Proxy a -> Text) -> FromCBOR a
$cfromCBOR :: forall s. Decoder s ChainCode
fromCBOR :: forall s. Decoder s ChainCode
$clabel :: Proxy ChainCode -> Text
label :: Proxy ChainCode -> Text
FromCBOR, Typeable ChainCode
Typeable ChainCode =>
(ChainCode -> Encoding)
-> ((forall t. EncCBOR t => Proxy t -> Size)
-> Proxy ChainCode -> Size)
-> ((forall t. EncCBOR t => Proxy t -> Size)
-> Proxy [ChainCode] -> Size)
-> EncCBOR ChainCode
ChainCode -> Encoding
(forall t. EncCBOR t => Proxy t -> Size)
-> Proxy [ChainCode] -> Size
(forall t. EncCBOR t => Proxy t -> Size) -> Proxy ChainCode -> Size
forall a.
Typeable a =>
(a -> Encoding)
-> ((forall t. EncCBOR t => Proxy t -> Size) -> Proxy a -> Size)
-> ((forall t. EncCBOR t => Proxy t -> Size) -> Proxy [a] -> Size)
-> EncCBOR a
$cencCBOR :: ChainCode -> Encoding
encCBOR :: ChainCode -> Encoding
$cencodedSizeExpr :: (forall t. EncCBOR t => Proxy t -> Size) -> Proxy ChainCode -> Size
encodedSizeExpr :: (forall t. EncCBOR t => Proxy t -> Size) -> Proxy ChainCode -> Size
$cencodedListSizeExpr :: (forall t. EncCBOR t => Proxy t -> Size)
-> Proxy [ChainCode] -> Size
encodedListSizeExpr :: (forall t. EncCBOR t => Proxy t -> Size)
-> Proxy [ChainCode] -> Size
EncCBOR, Typeable ChainCode
Typeable ChainCode =>
(forall s. Decoder s ChainCode)
-> (forall s. Proxy ChainCode -> Decoder s ())
-> (Proxy ChainCode -> Text)
-> DecCBOR ChainCode
Proxy ChainCode -> Text
forall s. Decoder s ChainCode
forall a.
Typeable a =>
(forall s. Decoder s a)
-> (forall s. Proxy a -> Decoder s ())
-> (Proxy a -> Text)
-> DecCBOR a
forall s. Proxy ChainCode -> Decoder s ()
$cdecCBOR :: forall s. Decoder s ChainCode
decCBOR :: forall s. Decoder s ChainCode
$cdropCBOR :: forall s. Proxy ChainCode -> Decoder s ()
dropCBOR :: forall s. Proxy ChainCode -> Decoder s ()
$clabel :: Proxy ChainCode -> Text
label :: Proxy ChainCode -> Text
DecCBOR, ChainCode -> ()
(ChainCode -> ()) -> NFData ChainCode
forall a. (a -> ()) -> NFData a
$crnf :: ChainCode -> ()
rnf :: ChainCode -> ()
NFData)
data BootstrapWitness = BootstrapWitness
{ BootstrapWitness -> VKey 'Witness
bwKey :: !(VKey 'Witness)
, BootstrapWitness
-> SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
bwSignature :: !(SignedDSIGN DSIGN (Hash HASH EraIndependentTxBody))
, BootstrapWitness -> ChainCode
bwChainCode :: !ChainCode
, BootstrapWitness -> ByteString
bwAttributes :: !ByteString
}
deriving ((forall x. BootstrapWitness -> Rep BootstrapWitness x)
-> (forall x. Rep BootstrapWitness x -> BootstrapWitness)
-> Generic BootstrapWitness
forall x. Rep BootstrapWitness x -> BootstrapWitness
forall x. BootstrapWitness -> Rep BootstrapWitness x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. BootstrapWitness -> Rep BootstrapWitness x
from :: forall x. BootstrapWitness -> Rep BootstrapWitness x
$cto :: forall x. Rep BootstrapWitness x -> BootstrapWitness
to :: forall x. Rep BootstrapWitness x -> BootstrapWitness
Generic, Int -> BootstrapWitness -> ShowS
[BootstrapWitness] -> ShowS
BootstrapWitness -> String
(Int -> BootstrapWitness -> ShowS)
-> (BootstrapWitness -> String)
-> ([BootstrapWitness] -> ShowS)
-> Show BootstrapWitness
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BootstrapWitness -> ShowS
showsPrec :: Int -> BootstrapWitness -> ShowS
$cshow :: BootstrapWitness -> String
show :: BootstrapWitness -> String
$cshowList :: [BootstrapWitness] -> ShowS
showList :: [BootstrapWitness] -> ShowS
Show, BootstrapWitness -> BootstrapWitness -> Bool
(BootstrapWitness -> BootstrapWitness -> Bool)
-> (BootstrapWitness -> BootstrapWitness -> Bool)
-> Eq BootstrapWitness
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BootstrapWitness -> BootstrapWitness -> Bool
== :: BootstrapWitness -> BootstrapWitness -> Bool
$c/= :: BootstrapWitness -> BootstrapWitness -> Bool
/= :: BootstrapWitness -> BootstrapWitness -> Bool
Eq)
instance NFData BootstrapWitness where
rnf :: BootstrapWitness -> ()
rnf = BootstrapWitness -> ()
forall a. a -> ()
rwhnf
instance NoThunks BootstrapWitness
instance ToCBOR BootstrapWitness where
toCBOR :: BootstrapWitness -> Encoding
toCBOR cwr :: BootstrapWitness
cwr@(BootstrapWitness VKey 'Witness
_ SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
_ ChainCode
_ ByteString
_) =
let BootstrapWitness {ByteString
SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
VKey 'Witness
ChainCode
bwKey :: BootstrapWitness -> VKey 'Witness
bwSignature :: BootstrapWitness
-> SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
bwChainCode :: BootstrapWitness -> ChainCode
bwAttributes :: BootstrapWitness -> ByteString
bwKey :: VKey 'Witness
bwSignature :: SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
bwChainCode :: ChainCode
bwAttributes :: ByteString
..} = BootstrapWitness
cwr
in Word -> Encoding
encodeListLen Word
4
Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> VKey 'Witness -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR VKey 'Witness
bwKey
Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
-> Encoding
forall v a. DSIGNAlgorithm v => SignedDSIGN v a -> Encoding
C.encodeSignedDSIGN SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
bwSignature
Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> ChainCode -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR ChainCode
bwChainCode
Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> ByteString -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR ByteString
bwAttributes
instance EncCBOR BootstrapWitness
instance FromCBOR BootstrapWitness where
fromCBOR :: forall s. Decoder s BootstrapWitness
fromCBOR =
Text
-> (BootstrapWitness -> Int)
-> Decoder s BootstrapWitness
-> Decoder s BootstrapWitness
forall a s. Text -> (a -> Int) -> Decoder s a -> Decoder s a
decodeRecordNamed Text
"BootstrapWitnessRaw" (Int -> BootstrapWitness -> Int
forall a b. a -> b -> a
const Int
4) (Decoder s BootstrapWitness -> Decoder s BootstrapWitness)
-> Decoder s BootstrapWitness -> Decoder s BootstrapWitness
forall a b. (a -> b) -> a -> b
$
VKey 'Witness
-> SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
-> ChainCode
-> ByteString
-> BootstrapWitness
BootstrapWitness (VKey 'Witness
-> SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
-> ChainCode
-> ByteString
-> BootstrapWitness)
-> Decoder s (VKey 'Witness)
-> Decoder
s
(SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
-> ChainCode -> ByteString -> BootstrapWitness)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s (VKey 'Witness)
forall s. Decoder s (VKey 'Witness)
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder
s
(SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
-> ChainCode -> ByteString -> BootstrapWitness)
-> Decoder
s (SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody))
-> Decoder s (ChainCode -> ByteString -> BootstrapWitness)
forall a b. Decoder s (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder
s (SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody))
forall v s a. DSIGNAlgorithm v => Decoder s (SignedDSIGN v a)
C.decodeSignedDSIGN Decoder s (ChainCode -> ByteString -> BootstrapWitness)
-> Decoder s ChainCode
-> Decoder s (ByteString -> BootstrapWitness)
forall a b. Decoder s (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s ChainCode
forall s. Decoder s ChainCode
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder s (ByteString -> BootstrapWitness)
-> Decoder s ByteString -> Decoder s BootstrapWitness
forall a b. Decoder s (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s ByteString
forall s. Decoder s ByteString
forall a s. FromCBOR a => Decoder s a
fromCBOR
instance DecCBOR BootstrapWitness
instance Ord BootstrapWitness where
compare :: BootstrapWitness -> BootstrapWitness -> Ordering
compare = (BootstrapWitness -> KeyHash 'Witness)
-> BootstrapWitness -> BootstrapWitness -> Ordering
forall a b. Ord a => (b -> a) -> b -> b -> Ordering
comparing BootstrapWitness -> KeyHash 'Witness
bootstrapWitKeyHash
bootstrapWitKeyHash ::
BootstrapWitness ->
KeyHash 'Witness
bootstrapWitKeyHash :: BootstrapWitness -> KeyHash 'Witness
bootstrapWitKeyHash (BootstrapWitness (VKey VerKeyDSIGN Ed25519DSIGN
key) SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
_ (ChainCode ByteString
cc) ByteString
attributes) =
Hash ADDRHASH (VerKeyDSIGN Ed25519DSIGN) -> KeyHash 'Witness
forall (r :: KeyRole).
Hash ADDRHASH (VerKeyDSIGN Ed25519DSIGN) -> KeyHash r
KeyHash (Hash ADDRHASH (VerKeyDSIGN Ed25519DSIGN) -> KeyHash 'Witness)
-> (ByteString -> Hash ADDRHASH (VerKeyDSIGN Ed25519DSIGN))
-> ByteString
-> KeyHash 'Witness
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Hash ADDRHASH (VerKeyDSIGN Ed25519DSIGN)
forall a. ByteString -> Hash ADDRHASH a
hash_crypto (ByteString -> Hash ADDRHASH (VerKeyDSIGN Ed25519DSIGN))
-> (ByteString -> ByteString)
-> ByteString
-> Hash ADDRHASH (VerKeyDSIGN Ed25519DSIGN)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
hash_SHA3_256 (ByteString -> KeyHash 'Witness) -> ByteString -> KeyHash 'Witness
forall a b. (a -> b) -> a -> b
$ ByteString
bytes
where
prefix :: ByteString
prefix :: ByteString
prefix = ByteString
"\131\00\130\00\88\64"
keyBytes :: ByteString
keyBytes = VerKeyDSIGN Ed25519DSIGN -> ByteString
forall v. DSIGNAlgorithm v => VerKeyDSIGN v -> ByteString
DSIGN.rawSerialiseVerKeyDSIGN VerKeyDSIGN Ed25519DSIGN
key
bytes :: ByteString
bytes = ByteString
prefix ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
keyBytes ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
cc ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
attributes
hash_SHA3_256 :: ByteString -> ByteString
hash_SHA3_256 :: ByteString -> ByteString
hash_SHA3_256 = Proxy SHA3_256 -> ByteString -> ByteString
forall h (proxy :: * -> *).
HashAlgorithm h =>
proxy h -> ByteString -> ByteString
forall (proxy :: * -> *).
proxy SHA3_256 -> ByteString -> ByteString
Hash.digest (Proxy SHA3_256
forall {k} (t :: k). Proxy t
Proxy :: Proxy Hash.SHA3_256)
hash_crypto :: ByteString -> Hash.Hash ADDRHASH a
hash_crypto :: forall a. ByteString -> Hash ADDRHASH a
hash_crypto = Hash ADDRHASH ByteString -> Hash ADDRHASH a
forall h a b. Hash h a -> Hash h b
Hash.castHash (Hash ADDRHASH ByteString -> Hash ADDRHASH a)
-> (ByteString -> Hash ADDRHASH ByteString)
-> ByteString
-> Hash ADDRHASH a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall h a. HashAlgorithm h => (a -> ByteString) -> a -> Hash h a
Hash.hashWith @ADDRHASH ByteString -> ByteString
forall a. a -> a
id
unpackByronVKey ::
Byron.VerificationKey ->
(VKey 'Witness, ChainCode)
unpackByronVKey :: VerificationKey -> (VKey 'Witness, ChainCode)
unpackByronVKey
( Byron.VerificationKey
(WC.XPub ByteString
vkeyBytes (WC.ChainCode ByteString
chainCodeBytes))
) = case ByteString -> Maybe (VerKeyDSIGN Ed25519DSIGN)
forall v. DSIGNAlgorithm v => ByteString -> Maybe (VerKeyDSIGN v)
DSIGN.rawDeserialiseVerKeyDSIGN ByteString
vkeyBytes of
Maybe (VerKeyDSIGN Ed25519DSIGN)
Nothing -> String -> (VKey 'Witness, ChainCode)
forall a. HasCallStack => String -> a
error String
"unpackByronVKey: impossible!"
Just VerKeyDSIGN Ed25519DSIGN
vk -> (VerKeyDSIGN Ed25519DSIGN -> VKey 'Witness
forall (kd :: KeyRole). VerKeyDSIGN Ed25519DSIGN -> VKey kd
VKey VerKeyDSIGN Ed25519DSIGN
vk, ByteString -> ChainCode
ChainCode ByteString
chainCodeBytes)
verifyBootstrapWit ::
Hash HASH EraIndependentTxBody ->
BootstrapWitness ->
Bool
verifyBootstrapWit :: Hash HASH EraIndependentTxBody -> BootstrapWitness -> Bool
verifyBootstrapWit Hash HASH EraIndependentTxBody
txbodyHash BootstrapWitness
witness =
VKey 'Witness
-> Hash HASH EraIndependentTxBody
-> SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
-> Bool
forall a (kd :: KeyRole).
Signable Ed25519DSIGN a =>
VKey kd -> a -> SignedDSIGN Ed25519DSIGN a -> Bool
verifySignedDSIGN
(BootstrapWitness -> VKey 'Witness
bwKey BootstrapWitness
witness)
Hash HASH EraIndependentTxBody
txbodyHash
(SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
-> SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
forall a b. Coercible a b => a -> b
coerce (SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
-> SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody))
-> SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
-> SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
forall a b. (a -> b) -> a -> b
$ BootstrapWitness
-> SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
bwSignature BootstrapWitness
witness)
coerceSignature :: WC.XSignature -> DSIGN.SigDSIGN DSIGN.Ed25519DSIGN
coerceSignature :: XSignature -> SigDSIGN Ed25519DSIGN
coerceSignature XSignature
sig =
SigDSIGN Ed25519DSIGN
-> Maybe (SigDSIGN Ed25519DSIGN) -> SigDSIGN Ed25519DSIGN
forall a. a -> Maybe a -> a
fromMaybe (String -> SigDSIGN Ed25519DSIGN
forall a. HasCallStack => String -> a
error String
"coerceSignature: impossible! signature size mismatch") (Maybe (SigDSIGN Ed25519DSIGN) -> SigDSIGN Ed25519DSIGN)
-> Maybe (SigDSIGN Ed25519DSIGN) -> SigDSIGN Ed25519DSIGN
forall a b. (a -> b) -> a -> b
$
ByteString -> Maybe (SigDSIGN Ed25519DSIGN)
forall v. DSIGNAlgorithm v => ByteString -> Maybe (SigDSIGN v)
DSIGN.rawDeserialiseSigDSIGN (XSignature -> ByteString
WC.unXSignature XSignature
sig)
makeBootstrapWitness ::
Hash HASH EraIndependentTxBody ->
Byron.SigningKey ->
Byron.Attributes Byron.AddrAttributes ->
BootstrapWitness
makeBootstrapWitness :: Hash HASH EraIndependentTxBody
-> SigningKey -> Attributes AddrAttributes -> BootstrapWitness
makeBootstrapWitness Hash HASH EraIndependentTxBody
txBodyHash SigningKey
byronSigningKey Attributes AddrAttributes
addrAttributes =
VKey 'Witness
-> SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
-> ChainCode
-> ByteString
-> BootstrapWitness
BootstrapWitness VKey 'Witness
vk SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
signature ChainCode
cc (Attributes AddrAttributes -> ByteString
forall a. ToCBOR a => a -> ByteString
serialize' Attributes AddrAttributes
addrAttributes)
where
(VKey 'Witness
vk, ChainCode
cc) = VerificationKey -> (VKey 'Witness, ChainCode)
unpackByronVKey (VerificationKey -> (VKey 'Witness, ChainCode))
-> VerificationKey -> (VKey 'Witness, ChainCode)
forall a b. (a -> b) -> a -> b
$ SigningKey -> VerificationKey
Byron.toVerification SigningKey
byronSigningKey
signature :: SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
signature =
SigDSIGN Ed25519DSIGN
-> SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
forall v a. SigDSIGN v -> SignedDSIGN v a
SignedDSIGN (SigDSIGN Ed25519DSIGN
-> SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody))
-> (XSignature -> SigDSIGN Ed25519DSIGN)
-> XSignature
-> SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XSignature -> SigDSIGN Ed25519DSIGN
coerceSignature (XSignature
-> SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody))
-> XSignature
-> SignedDSIGN Ed25519DSIGN (Hash HASH EraIndependentTxBody)
forall a b. (a -> b) -> a -> b
$
ByteString -> XPrv -> ByteString -> XSignature
forall passPhrase msg.
(ByteArrayAccess passPhrase, ByteArrayAccess msg) =>
passPhrase -> XPrv -> msg -> XSignature
WC.sign
(ByteString
forall a. Monoid a => a
mempty :: ByteString)
(SigningKey -> XPrv
Byron.unSigningKey SigningKey
byronSigningKey)
(Hash HASH EraIndependentTxBody -> ByteString
forall h a. Hash h a -> ByteString
Hash.hashToBytes Hash HASH EraIndependentTxBody
txBodyHash)