Skip to content

Commit d482b8f

Browse files
committed
Make show and pretty for BlsPossessionProof produce something that evaluates to the actual term
1 parent 0c4dcb6 commit d482b8f

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

cardano-api/src/Cardano/Api/Key.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ module Cardano.Api.Key
7373
-- | BLS12-381 key type
7474
, BlsKey
7575
, BlsPossessionProof
76+
, blsPossessionProof
7677
, createBlsPossessionProof
7778

7879
-- ** Type proxy

cardano-api/src/Cardano/Api/Key/Internal/Leios.hs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module Cardano.Api.Key.Internal.Leios
2020

2121
-- * Possession proof
2222
, BlsPossessionProof
23+
, blsPossessionProof
2324
, createBlsPossessionProof
2425
)
2526
where
@@ -165,10 +166,29 @@ newtype BlsPossessionProof = BlsPossessionProof (Crypto.PossessionProofDSIGN Cry
165166
deriving anyclass SerialiseAsCBOR
166167

167168
instance Show BlsPossessionProof where
168-
show _ = "BlsPossessionProof"
169+
show p = "blsPossessionProof " ++ show (serialiseToRawBytesHex p)
169170

170171
instance Pretty BlsPossessionProof where
171-
pretty _ = "BlsPossessionProof"
172+
pretty p = "blsPossessionProof" <+> pretty (serialiseToRawBytesHexText p)
173+
174+
instance SerialiseAsRawBytes BlsPossessionProof where
175+
serialiseToRawBytes (BlsPossessionProof proof) =
176+
Crypto.rawSerialisePossessionProofDSIGN proof
177+
178+
deserialiseFromRawBytes AsBlsPossessionProof bs =
179+
maybeToRight (SerialiseAsRawBytesError "Unable to deserialise BlsPossessionProof") $
180+
BlsPossessionProof <$> Crypto.rawDeserialisePossessionProofDSIGN bs
181+
182+
-- | Construct a 'BlsPossessionProof' from a hex-encoded raw 'ByteString'.
183+
--
184+
-- This is a partial function that calls 'error' if the input is not valid.
185+
-- It is intended to be used with the output of 'show' or 'pretty' to
186+
-- reconstruct a 'BlsPossessionProof' value.
187+
blsPossessionProof :: ByteString -> BlsPossessionProof
188+
blsPossessionProof hexBs =
189+
case deserialiseFromRawBytesHex hexBs of
190+
Left e -> error $ "blsPossessionProof: " ++ show e
191+
Right p -> p
172192

173193
-- | Proof-of-possession ciphersuite DST for the minimal-signature-size BLS12-381 variant.
174194
--

0 commit comments

Comments
 (0)