Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Nov 23, 2021
1 parent 93fb830 commit e91e807
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 39 deletions.
4 changes: 2 additions & 2 deletions cabal.project
Expand Up @@ -5,9 +5,9 @@ packages:
cardano-cli
cardano-client-demo
cardano-node
cardano-node-chairman
-- cardano-node-chairman
cardano-submit-api
cardano-testnet
-- cardano-testnet
bench/cardano-topology
bench/locli
bench/tx-generator
Expand Down
2 changes: 2 additions & 0 deletions cardano-api/src/Cardano/Api/KeysShelley.hs
Expand Up @@ -310,6 +310,8 @@ instance CastVerificationKeyRole PaymentExtendedKey PaymentKey where
impossible =
error "castVerificationKey: byron and shelley key sizes do not match!"

instance CastHash PaymentExtendedKey PaymentKey where
castHash (PaymentExtendedKeyHash h) = PaymentKeyHash h

--
-- Stake keys
Expand Down
16 changes: 8 additions & 8 deletions cardano-cli/src/Cardano/CLI/Shelley/Commands.hs
Expand Up @@ -538,14 +538,14 @@ newtype VerificationKeyBase64

-- | Data required to construct a witness.
data WitnessSigningData
= KeyWitnessSigningData
!SigningKeyFile
-- ^ Path to a file that should contain a signing key.
!(Maybe (Address ByronAddr))
-- ^ An optionally specified Byron address.
--
-- If specified, both the network ID and derivation path are extracted
-- from the address and used in the construction of the Byron witness.
= KeyWitnessSigningData
!SigningKeyFile
-- ^ Path to a file that should contain a signing key.
!(Maybe (Address ByronAddr))
-- ^ An optionally specified Byron address.
--
-- If specified, both the network ID and derivation path are extracted
-- from the address and used in the construction of the Byron witness.
deriving Show

-- | Either a stake pool verification key, genesis delegate verification key,
Expand Down
1 change: 0 additions & 1 deletion cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Expand Up @@ -1453,7 +1453,6 @@ pRequiredSigner =
<> Opt.help "Hash of the signing key (zero or more) whose \
\signature is required."
)

sExtendedPayKeyHash :: Parser (Hash PaymentExtendedKey)
sExtendedPayKeyHash =
Opt.option (readerFromParsecParser $ parseHash (AsHash AsPaymentExtendedKey))
Expand Down
52 changes: 24 additions & 28 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs
Expand Up @@ -67,6 +67,7 @@ data ShelleyTxCmdError
| ShelleyTxCmdScriptFileError (FileError ScriptDecodeError)
| ShelleyTxCmdReadTextViewFileError !(FileError TextEnvelopeError)
| ShelleyTxCmdReadWitnessSigningDataError !ReadWitnessSigningDataError
| ShelleyTxCmdReadRequiredSignerError !(FileError InputDecodeError)
| ShelleyTxCmdWriteFileError !(FileError ())
| ShelleyTxCmdEraConsensusModeMismatch
!(Maybe FilePath)
Expand Down Expand Up @@ -708,20 +709,22 @@ validateRequiredSigners era reqSigs =
case extraKeyWitnessesSupportedInEra era of
Nothing -> txFeatureMismatch era TxFeatureExtraKeyWits
Just supported -> do
keyWits <- firstExceptT ShelleyTxCmdReadWitnessSigningDataError
$ mapM readWitnessSigningData reqSigs
let (_sksByron, sksShelley) = partitionSomeWitnesses $ map categoriseSomeWitness keyWits
shelleySigningKeys = map toShelleySigningKey sksShelley
paymentKeyHashes = map getHash shelleySigningKeys
rSigners <- mapM readRequiredSigner reqSigs
paymentKeyHashes <- mapM getHash rSigners

return $ TxExtraKeyWitnesses supported paymentKeyHashes
where
getHash :: ShelleySigningKey -> Hash PaymentKey
getHash (ShelleyExtendedSigningKey sk) =
let extSKey = PaymentExtendedSigningKey sk
payVKey = castVerificationKey $ getVerificationKey extSKey
in verificationKeyHash payVKey
getHash (ShelleyNormalSigningKey sk) =
verificationKeyHash . getVerificationKey $ PaymentSigningKey sk
getHash :: AnyHash -> ExceptT ShelleyTxCmdError IO (Hash PaymentKey)
getHash (AnyPaymentKeyHash h) = return h
getHash (AnyExtendedPaymentKeyHash h) = return $ castHash h

-- getHash :: ShelleySigningKey -> Hash PaymentKey
-- getHash (ShelleyExtendedSigningKey sk) =
-- let extSKey = PaymentExtendedSigningKey sk
-- payVKey = castVerificationKey $ getVerificationKey extSKey
-- in verificationKeyHash payVKey
-- getHash (ShelleyNormalSigningKey sk) =
-- verificationKeyHash . getVerificationKey $ PaymentSigningKey sk

validateTxWithdrawals
:: forall era.
Expand Down Expand Up @@ -1437,27 +1440,20 @@ readFileInAnyCardanoEra asThing file =

readRequiredSigner :: RequiredSigner -> ExceptT ShelleyTxCmdError IO AnyHash
readRequiredSigner (RequiredSignerHash h) =
return $ RequiredSignerHash h
return $ AnyPaymentKeyHash h
readRequiredSigner (RequiredSignerHashExtended h) =
return $ RequiredSignerHashExtended h
return $ AnyExtendedPaymentKeyHash h
readRequiredSigner (RequiredSignerSkeyFile skFile) = do
firstExceptT ReadWitnessSigningDataSigningKeyDecodeError
. newExceptT
$ readSigningKeyFileAnyOf bech32FileTypes textEnvFileTypes skFile
--TODO: Left off here. We need to replace id with a function that converts the signing key to a hash, and wraps that hash in AnyHash
firstExceptT ShelleyTxCmdReadWitnessSigningDataError
. newExceptT
$ readSigningKeyFileAnyOf bech32FileTypes textEnvFileTypes skFile
where
textEnvFileTypes =
[ FromSomeType (AsSigningKey AsPaymentKey) id
, FromSomeType (AsSigningKey AsPaymentExtendedKey) id
, FromSomeType (AsSigningKey AsGenesisKey) id
, FromSomeType (AsSigningKey AsGenesisExtendedKey) id
, FromSomeType (AsSigningKey AsGenesisUTxOKey) id
]

bech32FileTypes =
[ FromSomeType (AsSigningKey AsPaymentKey) id
, FromSomeType (AsSigningKey AsPaymentExtendedKey) id
[ FromSomeType (AsSigningKey AsPaymentKey) APaymentSigningKey
, FromSomeType (AsSigningKey AsPaymentExtendedKey)
APaymentExtendedSigningKey
]
bech32FileTypes = []

-- | Constrain the era to be Shelley based. Fail for the Byron era.
--
Expand Down

0 comments on commit e91e807

Please sign in to comment.