Skip to content

Commit

Permalink
Apply formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Jul 15, 2024
1 parent 01d6403 commit 9d1fd09
Show file tree
Hide file tree
Showing 234 changed files with 20,529 additions and 15,844 deletions.
864 changes: 441 additions & 423 deletions cardano-cli/cardano-cli.cabal

Large diffs are not rendered by default.

148 changes: 69 additions & 79 deletions cardano-cli/src/Cardano/CLI/Byron/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module Cardano.CLI.Byron.Commands
, NewVerificationKeyFile (..)
, CertificateFile (..)
, NewCertificateFile (..)
) where
)
where

import Cardano.Api hiding (GenesisParameters)
import Cardano.Api.Byron hiding (GenesisParameters)
Expand All @@ -22,95 +23,82 @@ import Cardano.CLI.Types.Common

import Data.String (IsString)

data ByronCommand =

--- Node Related Commands ---
data ByronCommand
= --- Node Related Commands ---
NodeCmds
NodeCmds

--- Genesis Related Commands ---
| Genesis
NewDirectory
GenesisParameters

NodeCmds
| --- Genesis Related Commands ---
Genesis
NewDirectory
GenesisParameters
| PrintGenesisHash
GenesisFile

--- Key Related Commands ---
| Keygen
NewSigningKeyFile

GenesisFile
| --- Key Related Commands ---
Keygen
NewSigningKeyFile
| ToVerification
ByronKeyFormat
(SigningKeyFile In)
NewVerificationKeyFile

ByronKeyFormat
(SigningKeyFile In)
NewVerificationKeyFile
| PrettySigningKeyPublic
ByronKeyFormat
(SigningKeyFile In)

ByronKeyFormat
(SigningKeyFile In)
| MigrateDelegateKeyFrom
(SigningKeyFile In)
-- ^ Old key
NewSigningKeyFile
-- ^ New Key

(SigningKeyFile In)
-- ^ Old key
NewSigningKeyFile
-- ^ New Key
| PrintSigningKeyAddress
ByronKeyFormat
NetworkId
(SigningKeyFile In)

-----------------------------------

| SubmitTx
SocketPath
NetworkId
(TxFile In)
-- ^ Filepath of transaction to submit.
ByronKeyFormat
NetworkId
(SigningKeyFile In)
| -----------------------------------

-- | Filepath of transaction to submit.
SubmitTx
SocketPath
NetworkId
(TxFile In)
| SpendGenesisUTxO
GenesisFile
NetworkId
ByronKeyFormat
NewTxFile
-- ^ Filepath of the newly created transaction.
(SigningKeyFile In)
-- ^ Signing key of genesis UTxO owner.
(Address ByronAddr)
-- ^ Genesis UTxO address.
[TxOut CtxTx ByronEra]
-- ^ Tx output.
GenesisFile
NetworkId
ByronKeyFormat
NewTxFile
-- ^ Filepath of the newly created transaction.
(SigningKeyFile In)
-- ^ Signing key of genesis UTxO owner.
(Address ByronAddr)
-- ^ Genesis UTxO address.
[TxOut CtxTx ByronEra]
-- ^ Tx output.
| SpendUTxO
NetworkId
ByronKeyFormat
NewTxFile
-- ^ Filepath of the newly created transaction.
(SigningKeyFile In)
-- ^ Signing key of Tx underwriter.
[TxIn]
-- ^ Inputs available for spending to the Tx underwriter's key.
[TxOut CtxTx ByronEra]
-- ^ Genesis UTxO output Address.

NetworkId
ByronKeyFormat
NewTxFile
-- ^ Filepath of the newly created transaction.
(SigningKeyFile In)
-- ^ Signing key of Tx underwriter.
[TxIn]
-- ^ Inputs available for spending to the Tx underwriter's key.
[TxOut CtxTx ByronEra]
-- ^ Genesis UTxO output Address.
| GetTxId (TxFile In)
| --- Misc Commands ---

--- Misc Commands ---

| ValidateCBOR
CBORObject
-- ^ Type of the CBOR object
FilePath

ValidateCBOR
CBORObject
-- ^ Type of the CBOR object
FilePath
| PrettyPrintCBOR
FilePath
FilePath
deriving Show


data NodeCmds =
CreateVote
data NodeCmds
= CreateVote
NetworkId
(SigningKeyFile In)
FilePath -- ^ filepath to update proposal
FilePath
-- ^ filepath to update proposal
Bool
FilePath
| UpdateProposal
Expand All @@ -122,16 +110,18 @@ data NodeCmds =
InstallerHash
FilePath
ByronProtocolParametersUpdate
| SubmitUpdateProposal
| -- | Update proposal filepath.
SubmitUpdateProposal
SocketPath
NetworkId
FilePath -- ^ Update proposal filepath.
| SubmitVote
FilePath
| -- | Vote filepath.
SubmitVote
SocketPath
NetworkId
FilePath -- ^ Vote filepath.
FilePath
deriving Show

newtype NewCertificateFile
= NewCertificateFile { nFp :: FilePath }
= NewCertificateFile {nFp :: FilePath}
deriving (Eq, Show, IsString)
70 changes: 40 additions & 30 deletions cardano-cli/src/Cardano/CLI/Byron/Delegation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{-# LANGUAGE ScopedTypeVariables #-}

module Cardano.CLI.Byron.Delegation
( ByronDelegationError(..)
( ByronDelegationError (..)
, checkByronGenesisDelegation
, issueByronGenesisDelegation
, renderByronDelegationError
Expand Down Expand Up @@ -49,6 +49,7 @@ renderByronDelegationError = \case
renderByronKeyFailure kerr

-- TODO: we need to support password-protected secrets.

-- | Issue a certificate for genesis delegation to a delegate key, signed by the
-- issuer key, for a given protocol magic and coming into effect at given epoch.
issueByronGenesisDelegation
Expand All @@ -59,7 +60,7 @@ issueByronGenesisDelegation
-> Dlg.Certificate
issueByronGenesisDelegation magic epoch issuerSK delegateVK =
Dlg.signCertificate magic delegateVK epoch $
Crypto.noPassSafeSigner issuerSK
Crypto.noPassSafeSigner issuerSK

-- | Verify that a certificate signifies genesis delegation by assumed genesis key
-- to a delegate key, for a given protocol magic.
Expand All @@ -77,44 +78,54 @@ checkByronGenesisDelegation (CertificateFile certF) magic issuer delegate = do
Right (cert :: Dlg.Certificate) -> do
let issues = checkDlgCert cert magic issuer delegate
unless (null issues) $
left $ CertificateValidationErrors certF issues
left $
CertificateValidationErrors certF issues

checkDlgCert
:: Dlg.ACertificate a
-> ProtocolMagicId
-> Crypto.VerificationKey
-> Crypto.VerificationKey -> [Text]
-> Crypto.VerificationKey
-> [Text]
checkDlgCert cert magic issuerVK' delegateVK' =
mconcat
[ [ sformat "Certificate does not have a valid signature."
[ [ sformat "Certificate does not have a valid signature."
| not (Dlg.isValid magic' cert')
]
, [ sformat ("Certificate issuer ".vkF." doesn't match expected: ".vkF)
( Dlg.issuerVK cert) issuerVK'
]
, [ sformat
("Certificate issuer " . vkF . " doesn't match expected: " . vkF)
(Dlg.issuerVK cert)
issuerVK'
| Dlg.issuerVK cert /= issuerVK'
]
, [ sformat ("Certificate delegate ".vkF." doesn't match expected: ".vkF)
( Dlg.delegateVK cert) delegateVK'
]
, [ sformat
("Certificate delegate " . vkF . " doesn't match expected: " . vkF)
(Dlg.delegateVK cert)
delegateVK'
| Dlg.delegateVK cert /= delegateVK'
]
]
]
where
magic' :: L.Annotated ProtocolMagicId ByteString
magic' = L.Annotated magic (L.serialize' L.byronProtVer magic)

epoch :: EpochNumber
epoch = L.unAnnotated $ Dlg.aEpoch cert

cert' :: Dlg.ACertificate ByteString
cert' =
let unannotated = cert { Dlg.aEpoch = L.Annotated epoch ()
, Dlg.annotation = () }
in unannotated { Dlg.annotation = L.serialize' L.byronProtVer unannotated
, Dlg.aEpoch = L.Annotated epoch (L.serialize' L.byronProtVer epoch) }

vkF :: forall r. Format r (Crypto.VerificationKey -> r)
vkF = Crypto.fullVerificationKeyF

where
magic' :: L.Annotated ProtocolMagicId ByteString
magic' = L.Annotated magic (L.serialize' L.byronProtVer magic)

epoch :: EpochNumber
epoch = L.unAnnotated $ Dlg.aEpoch cert

cert' :: Dlg.ACertificate ByteString
cert' =
let unannotated =
cert
{ Dlg.aEpoch = L.Annotated epoch ()
, Dlg.annotation = ()
}
in unannotated
{ Dlg.annotation = L.serialize' L.byronProtVer unannotated
, Dlg.aEpoch = L.Annotated epoch (L.serialize' L.byronProtVer epoch)
}

vkF :: forall r. Format r (Crypto.VerificationKey -> r)
vkF = Crypto.fullVerificationKeyF

serialiseDelegationCert :: Dlg.Certificate -> ByteString
serialiseDelegationCert = LB.toStrict . canonicalEncodePretty
Expand All @@ -124,4 +135,3 @@ serialiseByronWitness sk =
case sk of
AByronSigningKeyLegacy bSkey -> serialiseToRawBytes bSkey
AByronSigningKey legBKey -> serialiseToRawBytes legBKey

Loading

0 comments on commit 9d1fd09

Please sign in to comment.