Skip to content

Commit

Permalink
Merge pull request #514 from IntersectMBO/smelc/more-support-of-cc-keys
Browse files Browse the repository at this point in the history
Add support for CC keys in the SomeAddressVerificationKey type
  • Loading branch information
smelc authored Apr 10, 2024
2 parents 92068ee + 34b2e14 commit 0b091bd
Showing 1 changed file with 54 additions and 33 deletions.
87 changes: 54 additions & 33 deletions cardano-api/internal/Cardano/Api/DeserialiseAnyOf.hs
Original file line number Diff line number Diff line change
Expand Up @@ -235,43 +235,52 @@ deserialiseInputAnyOf bech32Types textEnvTypes inputBs =
Left err -> DeserialiseInputError $ InputBech32DecodeError err

data SomeAddressVerificationKey
= AByronVerificationKey (VerificationKey ByronKey)
| APaymentVerificationKey (VerificationKey PaymentKey)
| APaymentExtendedVerificationKey (VerificationKey PaymentExtendedKey)
| AGenesisUTxOVerificationKey (VerificationKey GenesisUTxOKey)
| AGenesisExtendedVerificationKey (VerificationKey GenesisExtendedKey)
= AByronVerificationKey (VerificationKey ByronKey)
| APaymentVerificationKey (VerificationKey PaymentKey)
| APaymentExtendedVerificationKey (VerificationKey PaymentExtendedKey)
| AGenesisUTxOVerificationKey (VerificationKey GenesisUTxOKey)
| AGenesisExtendedVerificationKey (VerificationKey GenesisExtendedKey)
| AGenesisDelegateExtendedVerificationKey
(VerificationKey GenesisDelegateExtendedKey)
| AKesVerificationKey (VerificationKey KesKey)
| AVrfVerificationKey (VerificationKey VrfKey)
| AStakeVerificationKey (VerificationKey StakeKey)
| AStakeExtendedVerificationKey (VerificationKey StakeExtendedKey)
| ADRepVerificationKey (VerificationKey DRepKey)
| ADRepExtendedVerificationKey (VerificationKey DRepExtendedKey)
(VerificationKey GenesisDelegateExtendedKey)
| AKesVerificationKey (VerificationKey KesKey)
| AVrfVerificationKey (VerificationKey VrfKey)
| AStakeVerificationKey (VerificationKey StakeKey)
| AStakeExtendedVerificationKey (VerificationKey StakeExtendedKey)
| ADRepVerificationKey (VerificationKey DRepKey)
| ADRepExtendedVerificationKey (VerificationKey DRepExtendedKey)
| ACommitteeColdVerificationKey (VerificationKey CommitteeColdKey)
| ACommitteeColdExtendedVerificationKey (VerificationKey CommitteeColdExtendedKey)
| ACommitteeHotVerificationKey (VerificationKey CommitteeHotKey)
| ACommitteeHotExtendedVerificationKey (VerificationKey CommitteeHotExtendedKey)
deriving (Show)

renderSomeAddressVerificationKey :: SomeAddressVerificationKey -> Text
renderSomeAddressVerificationKey (AByronVerificationKey vk) = prettyByronVerificationKey vk
renderSomeAddressVerificationKey (APaymentVerificationKey vk) = serialiseToBech32 vk
renderSomeAddressVerificationKey (APaymentExtendedVerificationKey vk) = serialiseToBech32 vk
renderSomeAddressVerificationKey (AGenesisUTxOVerificationKey vk) =
serialiseToBech32 (castVerificationKey vk :: VerificationKey PaymentKey)
renderSomeAddressVerificationKey (AGenesisExtendedVerificationKey vk) =
let genKey = (castVerificationKey vk :: VerificationKey GenesisKey)
payKey = (castVerificationKey genKey :: VerificationKey PaymentKey)
in serialiseToBech32 payKey
renderSomeAddressVerificationKey (AGenesisDelegateExtendedVerificationKey vk) =
-- TODO: We could implement a CastVerificationKeyRole GenesisDelegateKey PaymentKey
-- if we want to avoid casting twice.
let genDelegKey = (castVerificationKey vk :: VerificationKey GenesisDelegateKey)
stakePoolKey = castVerificationKey genDelegKey :: VerificationKey StakePoolKey
in serialiseToBech32 stakePoolKey
renderSomeAddressVerificationKey (AKesVerificationKey vk) = serialiseToBech32 vk
renderSomeAddressVerificationKey (AVrfVerificationKey vk) = serialiseToBech32 vk
renderSomeAddressVerificationKey (AStakeVerificationKey vk) = serialiseToBech32 vk
renderSomeAddressVerificationKey (AStakeExtendedVerificationKey vk) = serialiseToBech32 vk
renderSomeAddressVerificationKey (ADRepVerificationKey vk) = serialiseToBech32 vk
renderSomeAddressVerificationKey (ADRepExtendedVerificationKey vk) = serialiseToBech32 vk
renderSomeAddressVerificationKey =
\case
AByronVerificationKey vk -> prettyByronVerificationKey vk
APaymentVerificationKey vk -> serialiseToBech32 vk
APaymentExtendedVerificationKey vk -> serialiseToBech32 vk
AGenesisUTxOVerificationKey vk -> serialiseToBech32 (castVerificationKey vk :: VerificationKey PaymentKey)
AGenesisExtendedVerificationKey vk ->
let genKey = (castVerificationKey vk :: VerificationKey GenesisKey)
payKey = (castVerificationKey genKey :: VerificationKey PaymentKey)
in serialiseToBech32 payKey
AGenesisDelegateExtendedVerificationKey vk ->
-- TODO: We could implement a CastVerificationKeyRole GenesisDelegateKey PaymentKey
-- if we want to avoid casting twice.
let genDelegKey = (castVerificationKey vk :: VerificationKey GenesisDelegateKey)
stakePoolKey = castVerificationKey genDelegKey :: VerificationKey StakePoolKey
in serialiseToBech32 stakePoolKey
AKesVerificationKey vk -> serialiseToBech32 vk
AVrfVerificationKey vk -> serialiseToBech32 vk
AStakeVerificationKey vk -> serialiseToBech32 vk
AStakeExtendedVerificationKey vk -> serialiseToBech32 vk
ADRepVerificationKey vk -> serialiseToBech32 vk
ADRepExtendedVerificationKey vk -> serialiseToBech32 vk
ACommitteeColdVerificationKey vk -> serialiseToBech32 vk
ACommitteeColdExtendedVerificationKey vk -> serialiseToBech32 vk
ACommitteeHotVerificationKey vk -> serialiseToBech32 vk
ACommitteeHotExtendedVerificationKey vk -> serialiseToBech32 vk


mapSomeAddressVerificationKey :: ()
Expand All @@ -291,6 +300,10 @@ mapSomeAddressVerificationKey f = \case
AStakeExtendedVerificationKey vk -> f vk
ADRepVerificationKey vk -> f vk
ADRepExtendedVerificationKey vk -> f vk
ACommitteeColdVerificationKey vk -> f vk
ACommitteeColdExtendedVerificationKey vk -> f vk
ACommitteeHotVerificationKey vk -> f vk
ACommitteeHotExtendedVerificationKey vk -> f vk

-- | Internal function to pretty render byron keys
prettyByronVerificationKey :: VerificationKey ByronKey-> Text
Expand Down Expand Up @@ -320,6 +333,10 @@ deserialiseAnyVerificationKeyBech32 =
allBech32VerKey =
[ FromSomeType (AsVerificationKey AsDRepKey) ADRepVerificationKey
, FromSomeType (AsVerificationKey AsDRepExtendedKey) ADRepExtendedVerificationKey
, FromSomeType (AsVerificationKey AsCommitteeColdKey) ACommitteeColdVerificationKey
, FromSomeType (AsVerificationKey AsCommitteeColdExtendedKey) ACommitteeColdExtendedVerificationKey
, FromSomeType (AsVerificationKey AsCommitteeHotKey) ACommitteeHotVerificationKey
, FromSomeType (AsVerificationKey AsCommitteeHotExtendedKey) ACommitteeHotExtendedVerificationKey
, FromSomeType (AsVerificationKey AsPaymentKey) APaymentVerificationKey
, FromSomeType (AsVerificationKey AsPaymentExtendedKey) APaymentExtendedVerificationKey
, FromSomeType (AsVerificationKey AsKesKey) AKesVerificationKey
Expand All @@ -340,6 +357,10 @@ deserialiseAnyVerificationKeyTextEnvelope bs =
[ FromSomeType (AsVerificationKey AsByronKey) AByronVerificationKey
, FromSomeType (AsVerificationKey AsDRepKey) ADRepVerificationKey
, FromSomeType (AsVerificationKey AsDRepExtendedKey) ADRepExtendedVerificationKey
, FromSomeType (AsVerificationKey AsCommitteeColdKey) ACommitteeColdVerificationKey
, FromSomeType (AsVerificationKey AsCommitteeColdExtendedKey) ACommitteeColdExtendedVerificationKey
, FromSomeType (AsVerificationKey AsCommitteeHotKey) ACommitteeHotVerificationKey
, FromSomeType (AsVerificationKey AsCommitteeHotExtendedKey) ACommitteeHotExtendedVerificationKey
, FromSomeType (AsVerificationKey AsPaymentKey) APaymentVerificationKey
, FromSomeType (AsVerificationKey AsPaymentExtendedKey) APaymentExtendedVerificationKey
, FromSomeType (AsVerificationKey AsStakeExtendedKey) AStakeExtendedVerificationKey
Expand Down

0 comments on commit 0b091bd

Please sign in to comment.