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
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: 1 addition & 1 deletion cardano-api-gen/cardano-api-gen.cabal
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cabal-version: 3.0

name: cardano-api-gen
version: 8.1.1.0
version: 8.1.1.1
synopsis: Generators for the cardano api
description: Generators for the cardano api.
category: Cardano,
Expand Down
6 changes: 6 additions & 0 deletions cardano-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog for cardano-api

## 8.8.1.1

- Add a HasTypeProxy constraint to getVerificationKey
(feature; compatible)
[PR 122](https://github.com/input-output-hk/cardano-api/pull/122)

## 8.8.1.0

- Make it build with ghc-9.6
Expand Down
2 changes: 1 addition & 1 deletion cardano-api/cardano-api.cabal
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cabal-version: 3.4

name: cardano-api
version: 8.8.1.0
version: 8.8.1.1
synopsis: The cardano api
description: The cardano api.
category: Cardano,
Expand Down
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 #-}
Expand Down Expand Up @@ -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

Expand Down
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 #-}
Expand Down Expand Up @@ -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'.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}

module Test.Cardano.Api.Typed.Envelope
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down