Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAD-1347 cli: new key hashing commands #1407

Merged
merged 2 commits into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cardano-cli/src/Cardano/CLI/Shelley/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ data AddressCmd

data StakeAddressCmd
= StakeAddressKeyGen VerificationKeyFile SigningKeyFile
| StakeAddressKeyHash VerificationKeyFile (Maybe OutputFile)
| StakeAddressBuild VerificationKeyFile NetworkId (Maybe OutputFile)
| StakeKeyRegister PrivKeyFile NodeAddress
| StakeKeyDelegate PrivKeyFile PoolId Lovelace NodeAddress
Expand Down Expand Up @@ -124,6 +125,7 @@ data NodeCmd
= NodeKeyGenCold VerificationKeyFile SigningKeyFile OpCertCounterFile
| NodeKeyGenKES VerificationKeyFile SigningKeyFile
| NodeKeyGenVRF VerificationKeyFile SigningKeyFile
| NodeKeyHashVRF VerificationKeyFile (Maybe OutputFile)
| NodeIssueOpCert VerificationKeyFile SigningKeyFile OpCertCounterFile
KESPeriod OutputFile
deriving (Eq, Show)
Expand Down
14 changes: 13 additions & 1 deletion cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pAddressCmd =
[ Opt.command "key-gen"
(Opt.info pAddressKeyGen $ Opt.progDesc "Create an address key pair.")
, Opt.command "key-hash"
(Opt.info pAddressKeyHash $ Opt.progDesc "Print the hash of an address key to stdout.")
(Opt.info pAddressKeyHash $ Opt.progDesc "Print the hash of an address key.")
, Opt.command "build"
(Opt.info pAddressBuild $ Opt.progDesc "Build a Shelley payment address, with optional delegation to a stake address.")
, Opt.command "build-multisig"
Expand Down Expand Up @@ -183,6 +183,8 @@ pStakeAddress =
(Opt.info pStakeAddressKeyGen $ Opt.progDesc "Create a stake address key pair")
, Opt.command "build"
(Opt.info pStakeAddressBuild $ Opt.progDesc "Build a stake address")
, Opt.command "key-hash"
(Opt.info pStakeAddressKeyHash $ Opt.progDesc "Print the hash of a stake address key.")
, Opt.command "register"
(Opt.info pStakeAddressRegister $ Opt.progDesc "Register a stake address")
, Opt.command "delegate"
Expand All @@ -204,6 +206,9 @@ pStakeAddress =
<$> pVerificationKeyFile Output
<*> pSigningKeyFile Output

pStakeAddressKeyHash :: Parser StakeAddressCmd
pStakeAddressKeyHash = StakeAddressKeyHash <$> pStakeVerificationKeyFile <*> pMaybeOutputFile

pStakeAddressBuild :: Parser StakeAddressCmd
pStakeAddressBuild = StakeAddressBuild <$> pStakeVerificationKeyFile
<*> pNetworkId
Expand Down Expand Up @@ -338,6 +343,9 @@ pNodeCmd =
, Opt.command "key-gen-VRF"
(Opt.info pKeyGenVRF $
Opt.progDesc "Create a key pair for a node VRF operational key")
, Opt.command "key-hash-VRF"
(Opt.info pKeyHashVRF $
Opt.progDesc "Print hash of a node's operational VRF key.")
, Opt.command "issue-op-cert"
(Opt.info pIssueOpCert $
Opt.progDesc "Issue a node operational certificate")
Expand All @@ -357,6 +365,10 @@ pNodeCmd =
pKeyGenVRF =
NodeKeyGenVRF <$> pVerificationKeyFile Output <*> pSigningKeyFile Output

pKeyHashVRF :: Parser NodeCmd
pKeyHashVRF =
NodeKeyHashVRF <$> pVerificationKeyFile Input <*> pMaybeOutputFile

pIssueOpCert :: Parser NodeCmd
pIssueOpCert =
NodeIssueOpCert <$> pKESVerificationKeyFile
Expand Down
14 changes: 14 additions & 0 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Node.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ runNodeCmd :: NodeCmd -> ExceptT ShelleyNodeCmdError IO ()
runNodeCmd (NodeKeyGenCold vk sk ctr) = runNodeKeyGenCold vk sk ctr
runNodeCmd (NodeKeyGenKES vk sk) = runNodeKeyGenKES vk sk
runNodeCmd (NodeKeyGenVRF vk sk) = runNodeKeyGenVRF vk sk
runNodeCmd (NodeKeyHashVRF vk mOutFp) = runNodeKeyHashVRF vk mOutFp
runNodeCmd (NodeIssueOpCert vk sk ctr p out) =
runNodeIssueOpCert vk sk ctr p out

Expand Down Expand Up @@ -113,6 +114,19 @@ runNodeKeyGenVRF (VerificationKeyFile vkeyPath) (SigningKeyFile skeyPath) = do
skeyDesc = TextViewDescription "VRF Signing Key"
vkeyDesc = TextViewDescription "VRF Verification Key"

runNodeKeyHashVRF :: VerificationKeyFile -> Maybe OutputFile
-> ExceptT ShelleyNodeCmdError IO ()
runNodeKeyHashVRF (VerificationKeyFile vkeyPath) mOutputFp = do
vkey <- firstExceptT ShelleyNodeReadFileError
. newExceptT
$ readFileTextEnvelope (AsVerificationKey AsVrfKey) vkeyPath

let hexKeyHash = serialiseToRawBytesHex (verificationKeyHash vkey)

case mOutputFp of
Just (OutputFile fpath) -> liftIO $ BS.writeFile fpath hexKeyHash
Nothing -> liftIO $ BS.putStrLn hexKeyHash

runNodeIssueOpCert :: VerificationKeyFile
-- ^ This is the hot KES verification key.
-> SigningKeyFile
Expand Down
14 changes: 14 additions & 0 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/StakeAddress.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Cardano.CLI.Shelley.Run.StakeAddress

import Cardano.Prelude

import qualified Data.ByteString.Char8 as BS
import qualified Data.Text as Text
import qualified Data.Text.IO as Text

Expand Down Expand Up @@ -42,6 +43,7 @@ renderShelleyStakeAddressCmdError err =

runStakeAddressCmd :: StakeAddressCmd -> ExceptT ShelleyStakeAddressCmdError IO ()
runStakeAddressCmd (StakeAddressKeyGen vk sk) = runStakeAddressKeyGen vk sk
runStakeAddressCmd (StakeAddressKeyHash vk mOutputFp) = runStakeAddressKeyHash vk mOutputFp
runStakeAddressCmd (StakeAddressBuild vk nw mOutputFp) = runStakeAddressBuild vk nw mOutputFp
runStakeAddressCmd (StakeKeyRegistrationCert stkKeyVerKeyFp outputFp) =
runStakeKeyRegistrationCert stkKeyVerKeyFp outputFp
Expand Down Expand Up @@ -72,6 +74,18 @@ runStakeAddressKeyGen (VerificationKeyFile vkFp) (SigningKeyFile skFp) = do
skeyDesc = TextViewDescription "Stake Signing Key"
vkeyDesc = TextViewDescription "Stake Verification Key"

runStakeAddressKeyHash :: VerificationKeyFile -> Maybe OutputFile -> ExceptT ShelleyStakeAddressCmdError IO ()
runStakeAddressKeyHash (VerificationKeyFile vkeyPath) mOutputFp = do
vkey <- firstExceptT ShelleyStakeAddressReadFileError
. newExceptT
$ readFileTextEnvelope (AsVerificationKey AsStakeKey) vkeyPath

let hexKeyHash = serialiseToRawBytesHex (verificationKeyHash vkey)

case mOutputFp of
Just (OutputFile fpath) -> liftIO $ BS.writeFile fpath hexKeyHash
Nothing -> liftIO $ BS.putStrLn hexKeyHash

runStakeAddressBuild :: VerificationKeyFile -> NetworkId -> Maybe OutputFile
-> ExceptT ShelleyStakeAddressCmdError IO ()
runStakeAddressBuild (VerificationKeyFile stkVkeyFp) network mOutputFp = do
Expand Down