Skip to content
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
3 changes: 3 additions & 0 deletions cardano-crypto-class/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## 2.5.0.0

* Add `Ord` superclass constraint for the `CertVRF` associated type in `VRFAlgorithm`
* Add `Ord` instances for `CertVRF {SimpleVRF,PraosVRF,PraosBatchCompatVRF}`
* Add `Ord` instances for `Cardano.Crypto.VRF.Praos{,BatchCompat}.Proof`
* Add `NFData` superclass constraints for the `VerKeyVRF`, `SignKeyVRF`,
and `CertVRF` associated types in `VRFAlgorithm`.
* Remove constructors of `BLS12381SignContext` from export; use `minSigPoPDST` or `minVerKeyPoPDST` for the standard PoP ciphersuites.
Expand Down
5 changes: 3 additions & 2 deletions cardano-crypto-class/src/Cardano/Crypto/VRF/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class
, Show (SignKeyVRF v)
, NFData (SignKeyVRF v)
, Show (CertVRF v)
, Eq (CertVRF v)
, Ord (CertVRF v)
, NFData (CertVRF v)
, NoThunks (CertVRF v)
, NoThunks (VerKeyVRF v)
Expand Down Expand Up @@ -321,8 +321,9 @@ data CertifiedVRF v a = CertifiedVRF
}
deriving (Generic)

deriving instance VRFAlgorithm v => Show (CertifiedVRF v a)
deriving instance VRFAlgorithm v => Eq (CertifiedVRF v a)
deriving instance VRFAlgorithm v => Ord (CertifiedVRF v a)
deriving instance VRFAlgorithm v => Show (CertifiedVRF v a)

instance VRFAlgorithm v => NoThunks (CertifiedVRF v a)

Expand Down
6 changes: 5 additions & 1 deletion cardano-crypto-class/src/Cardano/Crypto/VRF/Simple.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ instance ToCBOR Point where
instance FromCBOR Point where
fromCBOR = Point . pointFromMaybe <$> fromCBOR

-- This isn't mathematically meaningful, but we want to be able to store Points in a Set
instance Ord Point where
compare (Point p) (Point r) = compare (pointToMaybe p) (pointToMaybe r)

instance Semigroup Point where
Point p <> Point r = Point $ C.pointAdd curve p r

Expand Down Expand Up @@ -118,7 +122,7 @@ instance VRFAlgorithm SimpleVRF where
, certC :: !Natural -- md5 hash, so 16 bytes
, certS :: !Integer -- at most q, so 15 bytes, round up to 16
}
deriving stock (Show, Eq, Generic)
deriving stock (Show, Eq, Ord, Generic)
deriving anyclass (NoThunks)
deriving anyclass (NFData)

Expand Down
6 changes: 5 additions & 1 deletion cardano-crypto-praos/src/Cardano/Crypto/VRF/Praos.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Unsafe as BS
import Data.Coerce (coerce)
import Data.Ord (comparing)
import Data.Primitive.ByteArray (
ByteArray,
copyPtrToMutableByteArray,
Expand Down Expand Up @@ -292,6 +293,9 @@ instance Show Proof where
instance Eq Proof where
a == b = proofBytes a == proofBytes b

instance Ord Proof where
compare = comparing proofBytes

instance ToCBOR Proof where
toCBOR = toCBOR . proofBytes
encodedSizeExpr _ _ =
Expand Down Expand Up @@ -526,7 +530,7 @@ instance VRFAlgorithm PraosVRF where
deriving newtype (NFData)

newtype CertVRF PraosVRF = CertPraosVRF Proof
deriving stock (Show, Eq, Generic)
deriving stock (Show, Eq, Ord, Generic)
deriving newtype (ToCBOR, FromCBOR)
deriving (NoThunks) via OnlyCheckWhnfNamed "CertKeyVRF PraosVRF" Proof
deriving newtype (NFData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import Control.Monad (void, (<$!>))
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import Data.Coerce (coerce)
import Data.Ord (comparing)
import Data.Primitive.ByteArray (
ByteArray,
copyPtrToMutableByteArray,
Expand Down Expand Up @@ -314,6 +315,9 @@ instance Show Proof where
instance Eq Proof where
a == b = proofBytes a == proofBytes b

instance Ord Proof where
compare = comparing proofBytes

instance ToCBOR Proof where
toCBOR = toCBOR . proofBytes
encodedSizeExpr _ _ =
Expand Down Expand Up @@ -537,7 +541,7 @@ instance VRFAlgorithm PraosBatchCompatVRF where
deriving newtype (NFData)

newtype CertVRF PraosBatchCompatVRF = CertPraosBatchCompatVRF Proof
deriving stock (Show, Eq, Generic)
deriving stock (Show, Eq, Ord, Generic)
deriving newtype (ToCBOR, FromCBOR)
deriving (NoThunks) via OnlyCheckWhnfNamed "CertKeyVRF PraosBatchCompatVRF" Proof
deriving newtype (NFData)
Expand Down
Loading