Skip to content

Commit

Permalink
Provide To/FromCBOR and SerialiseAsCBOR instances for all key hash types
Browse files Browse the repository at this point in the history
deriving via UsingRawBytes
  • Loading branch information
dcoutts committed Jun 8, 2021
1 parent 6af7bfd commit 6a8928b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
4 changes: 4 additions & 0 deletions cardano-api/src/Cardano/Api/KeysByron.hs
Expand Up @@ -155,6 +155,8 @@ instance SerialiseAsRawBytes (SigningKey ByronKey) where
newtype instance Hash ByronKey = ByronKeyHash Byron.KeyHash
deriving (Eq, Ord)
deriving (Show, IsString) via UsingRawBytesHex (Hash ByronKey)
deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash ByronKey)
deriving anyclass SerialiseAsCBOR

instance SerialiseAsRawBytes (Hash ByronKey) where
serialiseToRawBytes (ByronKeyHash (Byron.KeyHash vkh)) =
Expand Down Expand Up @@ -224,6 +226,8 @@ instance HasTextEnvelope (SigningKey ByronKeyLegacy) where
newtype instance Hash ByronKeyLegacy = ByronKeyHashLegacy Byron.KeyHash
deriving (Eq, Ord)
deriving (Show, IsString) via UsingRawBytesHex (Hash ByronKeyLegacy)
deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash ByronKeyLegacy)
deriving anyclass SerialiseAsCBOR

instance SerialiseAsRawBytes (Hash ByronKeyLegacy) where
serialiseToRawBytes (ByronKeyHashLegacy (Byron.KeyHash vkh)) =
Expand Down
6 changes: 5 additions & 1 deletion cardano-api/src/Cardano/Api/KeysPraos.hs
Expand Up @@ -118,7 +118,9 @@ newtype instance Hash KesKey =
KesKeyHash (Shelley.Hash StandardCrypto
(Shelley.VerKeyKES StandardCrypto))
deriving stock (Eq, Ord)
deriving (Show, IsString) via UsingRawBytesHex (Hash VrfKey)
deriving (Show, IsString) via UsingRawBytesHex (Hash KesKey)
deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash KesKey)
deriving anyclass SerialiseAsCBOR

instance SerialiseAsRawBytes (Hash KesKey) where
serialiseToRawBytes (KesKeyHash vkh) =
Expand Down Expand Up @@ -213,6 +215,8 @@ newtype instance Hash VrfKey =
(Shelley.VerKeyVRF StandardCrypto))
deriving stock (Eq, Ord)
deriving (Show, IsString) via UsingRawBytesHex (Hash VrfKey)
deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash VrfKey)
deriving anyclass SerialiseAsCBOR

instance SerialiseAsRawBytes (Hash VrfKey) where
serialiseToRawBytes (VrfKeyHash vkh) =
Expand Down
38 changes: 29 additions & 9 deletions cardano-api/src/Cardano/Api/KeysShelley.hs
Expand Up @@ -139,6 +139,8 @@ newtype instance Hash PaymentKey =
PaymentKeyHash (Shelley.KeyHash Shelley.Payment StandardCrypto)
deriving stock (Eq, Ord)
deriving (Show, IsString) via UsingRawBytesHex (Hash PaymentKey)
deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash PaymentKey)
deriving anyclass SerialiseAsCBOR

instance SerialiseAsRawBytes (Hash PaymentKey) where
serialiseToRawBytes (PaymentKeyHash (Shelley.KeyHash vkh)) =
Expand Down Expand Up @@ -278,7 +280,9 @@ instance SerialiseAsBech32 (SigningKey PaymentExtendedKey) where
newtype instance Hash PaymentExtendedKey =
PaymentExtendedKeyHash (Shelley.KeyHash Shelley.Payment StandardCrypto)
deriving stock (Eq, Ord)
deriving (Show, IsString) via UsingRawBytesHex (Hash PaymentKey)
deriving (Show, IsString) via UsingRawBytesHex (Hash PaymentExtendedKey)
deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash PaymentExtendedKey)
deriving anyclass SerialiseAsCBOR

instance SerialiseAsRawBytes (Hash PaymentExtendedKey) where
serialiseToRawBytes (PaymentExtendedKeyHash (Shelley.KeyHash vkh)) =
Expand Down Expand Up @@ -378,7 +382,9 @@ instance SerialiseAsBech32 (SigningKey StakeKey) where
newtype instance Hash StakeKey =
StakeKeyHash (Shelley.KeyHash Shelley.Staking StandardCrypto)
deriving stock (Eq, Ord)
deriving (Show, IsString) via UsingRawBytesHex (Hash PaymentKey)
deriving (Show, IsString) via UsingRawBytesHex (Hash StakeKey)
deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash StakeKey)
deriving anyclass SerialiseAsCBOR

instance SerialiseAsRawBytes (Hash StakeKey) where
serialiseToRawBytes (StakeKeyHash (Shelley.KeyHash vkh)) =
Expand Down Expand Up @@ -518,7 +524,9 @@ instance SerialiseAsBech32 (SigningKey StakeExtendedKey) where
newtype instance Hash StakeExtendedKey =
StakeExtendedKeyHash (Shelley.KeyHash Shelley.Staking StandardCrypto)
deriving stock (Eq, Ord)
deriving (Show, IsString) via UsingRawBytesHex (Hash PaymentKey)
deriving (Show, IsString) via UsingRawBytesHex (Hash StakeExtendedKey)
deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash StakeExtendedKey)
deriving anyclass SerialiseAsCBOR

instance SerialiseAsRawBytes (Hash StakeExtendedKey) where
serialiseToRawBytes (StakeExtendedKeyHash (Shelley.KeyHash vkh)) =
Expand Down Expand Up @@ -610,7 +618,9 @@ instance SerialiseAsRawBytes (SigningKey GenesisKey) where
newtype instance Hash GenesisKey =
GenesisKeyHash (Shelley.KeyHash Shelley.Genesis StandardCrypto)
deriving stock (Eq, Ord)
deriving (Show, IsString) via UsingRawBytesHex (Hash PaymentKey)
deriving (Show, IsString) via UsingRawBytesHex (Hash GenesisKey)
deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash GenesisKey)
deriving anyclass SerialiseAsCBOR

instance SerialiseAsRawBytes (Hash GenesisKey) where
serialiseToRawBytes (GenesisKeyHash (Shelley.KeyHash vkh)) =
Expand Down Expand Up @@ -739,7 +749,9 @@ instance SerialiseAsRawBytes (SigningKey GenesisExtendedKey) where
newtype instance Hash GenesisExtendedKey =
GenesisExtendedKeyHash (Shelley.KeyHash Shelley.Staking StandardCrypto)
deriving stock (Eq, Ord)
deriving (Show, IsString) via UsingRawBytesHex (Hash PaymentKey)
deriving (Show, IsString) via UsingRawBytesHex (Hash GenesisExtendedKey)
deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash GenesisExtendedKey)
deriving anyclass SerialiseAsCBOR

instance SerialiseAsRawBytes (Hash GenesisExtendedKey) where
serialiseToRawBytes (GenesisExtendedKeyHash (Shelley.KeyHash vkh)) =
Expand Down Expand Up @@ -832,7 +844,9 @@ instance SerialiseAsRawBytes (SigningKey GenesisDelegateKey) where
newtype instance Hash GenesisDelegateKey =
GenesisDelegateKeyHash (Shelley.KeyHash Shelley.GenesisDelegate StandardCrypto)
deriving stock (Eq, Ord)
deriving (Show, IsString) via UsingRawBytesHex (Hash PaymentKey)
deriving (Show, IsString) via UsingRawBytesHex (Hash GenesisDelegateKey)
deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash GenesisDelegateKey)
deriving anyclass SerialiseAsCBOR

instance SerialiseAsRawBytes (Hash GenesisDelegateKey) where
serialiseToRawBytes (GenesisDelegateKeyHash (Shelley.KeyHash vkh)) =
Expand Down Expand Up @@ -969,7 +983,9 @@ instance SerialiseAsRawBytes (SigningKey GenesisDelegateExtendedKey) where
newtype instance Hash GenesisDelegateExtendedKey =
GenesisDelegateExtendedKeyHash (Shelley.KeyHash Shelley.Staking StandardCrypto)
deriving stock (Eq, Ord)
deriving (Show, IsString) via UsingRawBytesHex (Hash PaymentKey)
deriving (Show, IsString) via UsingRawBytesHex (Hash GenesisDelegateExtendedKey)
deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash GenesisDelegateExtendedKey)
deriving anyclass SerialiseAsCBOR

instance SerialiseAsRawBytes (Hash GenesisDelegateExtendedKey) where
serialiseToRawBytes (GenesisDelegateExtendedKeyHash (Shelley.KeyHash vkh)) =
Expand Down Expand Up @@ -1062,7 +1078,9 @@ instance SerialiseAsRawBytes (SigningKey GenesisUTxOKey) where
newtype instance Hash GenesisUTxOKey =
GenesisUTxOKeyHash (Shelley.KeyHash Shelley.Payment StandardCrypto)
deriving stock (Eq, Ord)
deriving (Show, IsString) via UsingRawBytesHex (Hash PaymentKey)
deriving (Show, IsString) via UsingRawBytesHex (Hash GenesisUTxOKey)
deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash GenesisUTxOKey)
deriving anyclass SerialiseAsCBOR

instance SerialiseAsRawBytes (Hash GenesisUTxOKey) where
serialiseToRawBytes (GenesisUTxOKeyHash (Shelley.KeyHash vkh)) =
Expand Down Expand Up @@ -1166,7 +1184,9 @@ instance SerialiseAsBech32 (SigningKey StakePoolKey) where
newtype instance Hash StakePoolKey =
StakePoolKeyHash (Shelley.KeyHash Shelley.StakePool StandardCrypto)
deriving stock (Eq, Ord)
deriving (Show, IsString) via UsingRawBytesHex (Hash PaymentKey)
deriving (Show, IsString) via UsingRawBytesHex (Hash StakePoolKey)
deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash StakePoolKey)
deriving anyclass SerialiseAsCBOR

instance SerialiseAsRawBytes (Hash StakePoolKey) where
serialiseToRawBytes (StakePoolKeyHash (Shelley.KeyHash vkh)) =
Expand Down

0 comments on commit 6a8928b

Please sign in to comment.