Safe Haskell | None |
---|---|
Language | Haskell2010 |
Cardano.Ledger.SafeHash
Synopsis
- data SafeHash crypto index
-
class
SafeToHash
t
where
- originalBytes :: t -> ByteString
- makeHashWithExplicitProxys :: HasAlgorithm c => Proxy c -> Proxy index -> t -> SafeHash c index
- castSafeHash :: forall i j c. SafeHash c i -> SafeHash c j
- class SafeToHash x => HashAnnotated x index crypto | x -> index crypto
- hashAnnotated :: forall c i x. ( HasAlgorithm c, HashAnnotated x i c) => x -> SafeHash c i
- indexProxy :: HashAnnotated x index crypto => x -> Proxy index
-
class
SafeToHash
x =>
HashWithCrypto
x index | x -> index
where
- hashWithCrypto :: forall crypto. HasAlgorithm crypto => Proxy crypto -> x -> SafeHash crypto index
- type HasAlgorithm c = HashAlgorithm ( HASH c)
- extractHash :: SafeHash crypto i -> Hash ( HASH crypto) i
- hashSafeList :: HasAlgorithm c => Proxy c -> Proxy index -> [ Safe ] -> SafeHash c index
-
data
Safe
where
- Safe :: SafeToHash x => x -> Safe
- unsafeMakeSafeHash :: Hash ( HASH crypto) index -> SafeHash crypto index
Documentation
data SafeHash crypto index Source #
A SafeHash is a hash of something that is safe to hash. Such types store their own serialisation bytes. The prime example is (MemoBytes t), but other examples are things that consist of only ByteStrings.
We do NOT export the constructor SafeHash, but instead export other functions
such as 'hashWithCrypto,
hashAnnotated
and
extractHash
which have constraints
that limit their application to types which preserve their original serialization
bytes.
Instances
Eq ( SafeHash crypto index) Source # | |
Ord ( SafeHash crypto index) Source # | |
Defined in Cardano.Ledger.SafeHash Methods compare :: SafeHash crypto index -> SafeHash crypto index -> Ordering Source # (<) :: SafeHash crypto index -> SafeHash crypto index -> Bool Source # (<=) :: SafeHash crypto index -> SafeHash crypto index -> Bool Source # (>) :: SafeHash crypto index -> SafeHash crypto index -> Bool Source # (>=) :: SafeHash crypto index -> SafeHash crypto index -> Bool Source # max :: SafeHash crypto index -> SafeHash crypto index -> SafeHash crypto index Source # min :: SafeHash crypto index -> SafeHash crypto index -> SafeHash crypto index Source # |
|
Show ( SafeHash crypto index) Source # | |
NFData ( SafeHash crypto index) Source # | |
Defined in Cardano.Ledger.SafeHash |
|
( Typeable index, Crypto c) => ToCBOR ( SafeHash c index) Source # | |
Defined in Cardano.Ledger.SafeHash |
|
( Typeable index, Crypto c) => FromCBOR ( SafeHash c index) Source # | |
HeapWords ( Hash ( HASH c) i) => HeapWords ( SafeHash c i) Source # | |
NoThunks ( SafeHash crypto index) Source # | |
HashAlgorithm ( HASH crypto) => SafeToHash ( SafeHash crypto index) Source # | |
Defined in Cardano.Ledger.SafeHash Methods originalBytes :: SafeHash crypto index -> ByteString Source # makeHashWithExplicitProxys :: HasAlgorithm c => Proxy c -> Proxy index0 -> SafeHash crypto index -> SafeHash c index0 Source # |
class SafeToHash t where Source #
Only Types that preserve their serialisation bytes are members of the class SafeToHash. There are only a limited number of primitive direct instances of SafeToHash, all but two of them are present in this file. Instead of making explicit instances, we almost always use a newtype (around a type S) where their is already an instance (SafeToHash S). In that case the newtype has its SafeToHash instance derived using newtype deriving. The only exceptions are the legacy Shelley types: Metadata and Tx, that preserve their serialisation bytes using a different mechanism than MemoBytes. SafeToHash is a superclass requirement of the classes HashAnnotated and HashWithCrypto (below) which provide more convenient ways to construct SafeHashes than using makeHashWithExplicitProxys.
Minimal complete definition
Methods
originalBytes :: t -> ByteString Source #
makeHashWithExplicitProxys :: HasAlgorithm c => Proxy c -> Proxy index -> t -> SafeHash c index Source #
Instances
castSafeHash :: forall i j c. SafeHash c i -> SafeHash c j Source #
To change the index parameter of SafeHash (which is a phantom type) use castSafeHash
class SafeToHash x => HashAnnotated x index crypto | x -> index crypto Source #
Determine the index from the type
x
hashAnnotated :: forall c i x. ( HasAlgorithm c, HashAnnotated x i c) => x -> SafeHash c i Source #
indexProxy :: HashAnnotated x index crypto => x -> Proxy index Source #
class SafeToHash x => HashWithCrypto x index | x -> index where Source #
When the type being hashed:
x
determines the
index
tag but not the
crypto
Minimal complete definition
Nothing
Methods
hashWithCrypto :: forall crypto. HasAlgorithm crypto => Proxy crypto -> x -> SafeHash crypto index Source #
type HasAlgorithm c = HashAlgorithm ( HASH c) Source #
hashSafeList :: HasAlgorithm c => Proxy c -> Proxy index -> [ Safe ] -> SafeHash c index Source #
Sometimes one wants to hash multiple things, simply by concatenating all the bytes. This abstraction allows one to do that safely.
Constructors
Safe :: SafeToHash x => x -> Safe |
Instances
SafeToHash Safe Source # | |
Defined in Cardano.Ledger.SafeHash Methods originalBytes :: Safe -> ByteString Source # makeHashWithExplicitProxys :: HasAlgorithm c => Proxy c -> Proxy index -> Safe -> SafeHash c index Source # |