From 3fe02217a185bc76eef917b7af479f39fb07d90a Mon Sep 17 00:00:00 2001 From: Neil Mayhew Date: Tue, 3 Dec 2024 08:11:23 -0700 Subject: [PATCH] Add functions to convert hashes to and from VRFVerKeyHash --- libs/cardano-ledger-core/CHANGELOG.md | 1 + .../src/Cardano/Ledger/Keys/Internal.hs | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libs/cardano-ledger-core/CHANGELOG.md b/libs/cardano-ledger-core/CHANGELOG.md index aff58b96c61..e2629e42497 100644 --- a/libs/cardano-ledger-core/CHANGELOG.md +++ b/libs/cardano-ledger-core/CHANGELOG.md @@ -2,6 +2,7 @@ ## 1.16.0.0 +* Add `toVRFVerKeyHash` and `fromVRFVerKeyHash` * Change lens type of `hkdNOptL`, `ppNOptL`, and `ppuNOptL` to `Word16` * Add `epochFromSlot` * Remove usage of a `Reader` monad in `epochInfoEpoch`, `epochInfoFirst` and `epochInfoSize`. diff --git a/libs/cardano-ledger-core/src/Cardano/Ledger/Keys/Internal.hs b/libs/cardano-ledger-core/src/Cardano/Ledger/Keys/Internal.hs index 8090fa12811..c6943b5bc1a 100644 --- a/libs/cardano-ledger-core/src/Cardano/Ledger/Keys/Internal.hs +++ b/libs/cardano-ledger-core/src/Cardano/Ledger/Keys/Internal.hs @@ -35,6 +35,8 @@ module Cardano.Ledger.Keys.Internal ( KeyRoleVRF (..), VRFVerKeyHash (..), hashVerKeyVRF, + toVRFVerKeyHash, + fromVRFVerKeyHash, -- * Genesis delegations GenDelegPair (..), @@ -373,4 +375,12 @@ deriving newtype instance Crypto c => Default (VRFVerKeyHash r c) hashVerKeyVRF :: Crypto c => VerKeyVRF c -> VRFVerKeyHash (r :: KeyRoleVRF) c -hashVerKeyVRF = VRFVerKeyHash . Hash.castHash . VRF.hashVerKeyVRF +hashVerKeyVRF = toVRFVerKeyHash . VRF.hashVerKeyVRF + +toVRFVerKeyHash :: + Hash.Hash (HASH c) (VRF.VerKeyVRF v) -> VRFVerKeyHash (r :: KeyRoleVRF) c +toVRFVerKeyHash = VRFVerKeyHash . Hash.castHash + +fromVRFVerKeyHash :: + VRFVerKeyHash (r :: KeyRoleVRF) c -> Hash.Hash (HASH c) (VRF.VerKeyVRF v) +fromVRFVerKeyHash = Hash.castHash . unVRFVerKeyHash