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

Add a HasTypeProxy constraint to getVerificationKey #122

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Changes from 1 commit
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
Next Next commit
Add a HasTypeProxy constraint to getVerificationKey
This constraint is needed in `cardano-cli`.

Annoyingly, `ghc-8.10` considers this constraint redundant while
`ghc-9.2` and later complains if its absent.
  • Loading branch information
erikd committed Jul 17, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 9e018cc133bafaf9be899087d27199e6bdb5b3de
21 changes: 19 additions & 2 deletions cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
@@ -746,10 +747,26 @@ genWitnesses era =
(genShelleyKeyWitness era)
return $ bsWits ++ keyWits

genVerificationKey :: Key keyrole => AsType keyrole -> Gen (VerificationKey keyrole)
genVerificationKey ::
#if __GLASGOW_HASKELL__ >= 902
-- GHC 8.10 considers the HasTypeProxy constraint redundant but ghc-9.6 complains if its not
-- present.
(Key keyrole, HasTypeProxy keyrole) =>
#else
Key keyrole =>
#endif
AsType keyrole -> Gen (VerificationKey keyrole)
genVerificationKey roletoken = getVerificationKey <$> genSigningKey roletoken

genVerificationKeyHash :: Key keyrole => AsType keyrole -> Gen (Hash keyrole)
genVerificationKeyHash ::
#if __GLASGOW_HASKELL__ >= 902
-- GHC 8.10 considers the HasTypeProxy constraint redundant but ghc-9.6 complains if its not
-- present.
(Key keyrole, HasTypeProxy keyrole) =>
#else
Key keyrole =>
#endif
AsType keyrole -> Gen (Hash keyrole)
genVerificationKeyHash roletoken =
verificationKeyHash <$> genVerificationKey roletoken

10 changes: 9 additions & 1 deletion cardano-api/internal/Cardano/Api/Keys/Class.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
@@ -44,7 +45,14 @@ class (Eq (VerificationKey keyrole),
data SigningKey keyrole :: Type

-- | Get the corresponding verification key from a signing key.
getVerificationKey :: SigningKey keyrole -> VerificationKey keyrole
getVerificationKey ::
#if __GLASGOW_HASKELL__ >= 902
-- GHC 8.10 considers this constraint redundant but ghc-9.6 complains if its not present.
-- More annoyingly, absence of this constraint does not manifest in this repo, but in
-- `cardano-cli` :facepalm:.
HasTypeProxy keyrole =>
#endif
SigningKey keyrole -> VerificationKey keyrole

-- | Generate a 'SigningKey' deterministically, given a 'Crypto.Seed'. The
-- required size of the seed is given by 'deterministicSigningKeySeedSize'.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}

module Test.Cardano.Api.Typed.Envelope
@@ -89,8 +90,15 @@ prop_roundtrip_VrfSigningKey_envelope =

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

roundtrip_VerificationKey_envelope :: Key keyrole
=> AsType keyrole -> Property
roundtrip_VerificationKey_envelope ::
#if __GLASGOW_HASKELL__ >= 902
-- GHC 8.10 considers the HasTypeProxy constraint redundant but ghc-9.2 and above complains if its
-- not present.
(Key keyrole, HasTypeProxy keyrole) =>
#else
Key keyrole =>
#endif
AsType keyrole -> Property
roundtrip_VerificationKey_envelope roletoken =
H.property $ do
vkey <- H.forAll (genVerificationKey roletoken)
Original file line number Diff line number Diff line change
@@ -85,10 +85,10 @@ roundtrip_raw_bytes asType g =
H.tripping v serialiseToRawBytes (deserialiseFromRawBytes asType)

roundtrip_verification_key_hash_raw
#if __GLASGOW_HASKELL__ < 906
#if __GLASGOW_HASKELL__ < 902
:: (Key keyrole, Eq (Hash keyrole), Show (Hash keyrole))
#else
-- GHC 9.6 needs an extra constraint.
-- GHC 9.2 and above needs an extra constraint.
:: (Key keyrole, Eq (Hash keyrole), Show (Hash keyrole), HasTypeProxy keyrole)
#endif
=> AsType keyrole -> Property