Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Deprecated: Use Hashes
instead
Synopsis
- data SafeHash i
- class SafeToHash t where
- originalBytes ∷ t → ByteString
- originalBytesSize ∷ t → Int
- makeHashWithExplicitProxys ∷ Proxy i → t → SafeHash i
- class SafeToHash x ⇒ HashAnnotated x i | x → i
- hashAnnotated ∷ HashAnnotated x i ⇒ x → SafeHash i
- unsafeMakeSafeHash ∷ Hash HASH i → SafeHash i
- castSafeHash ∷ ∀ i j. SafeHash i → SafeHash j
- extractHash ∷ SafeHash i → Hash HASH i
- indexProxy ∷ ∀ x i. HashAnnotated x i ⇒ x → Proxy i
SafeHash and SafeToHash
A SafeHash
is a hash of something that is safe to hash. Such types store their own
serialisation bytes. The prime example is (
, but other examples are
things that consist of only ByteStrings (i.e. they are their own serialization) or for
some other reason store their original bytes.MemoBytes
t)
We do NOT export the constructor SafeHash
, but instead export other functions such as
hashAnnotated
and extractHash
which have constraints that limit their application
to types which preserve their original serialization bytes.
Instances
FromJSON (SafeHash i) Source # | |
ToJSON (SafeHash i) Source # | |
Show (SafeHash i) Source # | |
Typeable i ⇒ FromCBOR (SafeHash i) Source # | |
Typeable i ⇒ ToCBOR (SafeHash i) Source # | |
Typeable i ⇒ DecCBOR (SafeHash i) Source # | |
Typeable i ⇒ EncCBOR (SafeHash i) Source # | |
SafeToHash (SafeHash i) Source # | |
Defined in Cardano.Ledger.Hashes originalBytes ∷ SafeHash i → ByteString Source # originalBytesSize ∷ SafeHash i → Int Source # makeHashWithExplicitProxys ∷ Proxy i0 → SafeHash i → SafeHash i0 Source # | |
Default (SafeHash i) Source # | |
Defined in Cardano.Ledger.Hashes | |
NFData (SafeHash i) Source # | |
Defined in Cardano.Ledger.Hashes | |
Eq (SafeHash i) Source # | |
Ord (SafeHash i) Source # | |
Defined in Cardano.Ledger.Hashes | |
HeapWords (SafeHash i) Source # | |
HeapWords (StrictMaybe DataHash) Source # | |
Defined in Cardano.Ledger.Plutus.Data | |
NoThunks (SafeHash i) 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 prime example of s
is MemoBytes
.
The only exceptions are the legacy Shelley types: Metadata
and ShelleyTx
, that
preserve their serialization bytes
using a different mechanism than the use of MemoBytes
. SafeToHash
is a superclass
requirement of the classes HashAnnotated
which
provide more convenient ways to construct SafeHashes than using makeHashWithExplicitProxys
.
originalBytes ∷ t → ByteString Source #
Extract the original bytes from t
originalBytesSize ∷ t → Int Source #
makeHashWithExplicitProxys ∷ Proxy i → t → SafeHash i Source #
Instances
Creating SafeHash
class SafeToHash x ⇒ HashAnnotated x i | x → i Source #
Types that are SafeToHash
AND have the type uniquely determines the index
type
tag of SafeHash
index
The SafeToHash
and the HashAnnotated
classes are designed so that their instances
can be easily derived (because their methods have default methods when the type is a
newtype around a type that is SafeToHash
). For example,
Instances
HashAnnotated AnchorData AnchorData Source # | |
Defined in Cardano.Ledger.BaseTypes | |
HashAnnotated (BinaryData era) EraIndependentData Source # | |
Defined in Cardano.Ledger.Plutus.Data | |
HashAnnotated (Data era) EraIndependentData Source # | |
Defined in Cardano.Ledger.Plutus.Data hashAnnotated ∷ Data era → SafeHash EraIndependentData Source # |
hashAnnotated ∷ HashAnnotated x i ⇒ x → SafeHash i Source #
Create a (
, given SafeHash
i)(
instance.HashAnnotated
x i)
unsafeMakeSafeHash ∷ Hash HASH i → SafeHash i Source #
Don't use this except in Testing to make Arbitrary instances, etc. or in cases when it can be guaranteed that original bytes were used for computing the hash.
Other operations
castSafeHash ∷ ∀ i j. SafeHash i → SafeHash j Source #
To change the index parameter of SafeHash (which is a phantom type) use castSafeHash
indexProxy ∷ ∀ x i. HashAnnotated x i ⇒ x → Proxy i Source #