Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Hash h a
- class (KnownNat (SizeHash h), Typeable h) ⇒ HashAlgorithm h
- type HASH = Blake2b_256
- type ADDRHASH = Blake2b_224
- data EraIndependentTxBody
- data EraIndependentBlockHeader
- data EraIndependentBlockBody
- data EraIndependentMetadata
- data EraIndependentScript
- data EraIndependentData
- data EraIndependentScriptData
- data EraIndependentTxAuxData
- data EraIndependentPParamView
- data EraIndependentScriptIntegrity
- newtype KeyHash (r ∷ KeyRole) = KeyHash {}
- data KeyRole
- hashKey ∷ VKey kd → KeyHash kd
- hashTxBodySignature ∷ SignedDSIGN DSIGN (Hash HASH EraIndependentTxBody) → Hash HASH (SignedDSIGN DSIGN (Hash HASH EraIndependentTxBody))
- newtype ScriptHash = ScriptHash (Hash ADDRHASH EraIndependentScript)
- type DataHash = SafeHash EraIndependentData
- newtype TxAuxDataHash = TxAuxDataHash {}
- data KeyRoleVRF
- newtype VRFVerKeyHash (r ∷ KeyRoleVRF) = VRFVerKeyHash {}
- toVRFVerKeyHash ∷ Hash HASH (VerKeyVRF v) → VRFVerKeyHash (r ∷ KeyRoleVRF)
- fromVRFVerKeyHash ∷ VRFVerKeyHash (r ∷ KeyRoleVRF) → Hash HASH (VerKeyVRF v)
- data GenDelegPair = GenDelegPair {}
- newtype GenDelegs = GenDelegs {}
- 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
Hashing algorithms
Instances
HashAlgorithm h ⇒ IsString (Q (TExp (Hash h a))) | This instance is meant to be used with
|
Defined in Cardano.Crypto.Hash.Class | |
HashAlgorithm h ⇒ FromJSON (Hash h a) | |
HashAlgorithm h ⇒ FromJSONKey (Hash h a) | |
Defined in Cardano.Crypto.Hash.Class fromJSONKey ∷ FromJSONKeyFunction (Hash h a) Source # fromJSONKeyList ∷ FromJSONKeyFunction [Hash h a] Source # | |
HashAlgorithm h ⇒ ToJSON (Hash h a) | |
HashAlgorithm h ⇒ ToJSONKey (Hash h a) | |
Defined in Cardano.Crypto.Hash.Class toJSONKey ∷ ToJSONKeyFunction (Hash h a) Source # toJSONKeyList ∷ ToJSONKeyFunction [Hash h a] Source # | |
HashAlgorithm h ⇒ IsString (Hash h a) | |
Defined in Cardano.Crypto.Hash.Class fromString ∷ String → Hash h a Source # | |
Generic (Hash h a) | |
HashAlgorithm h ⇒ Read (Hash h a) | |
Show (Hash h a) | |
(HashAlgorithm h, Typeable a) ⇒ FromCBOR (Hash h a) | |
(HashAlgorithm h, Typeable a) ⇒ ToCBOR (Hash h a) | |
SignableRepresentation (Hash a b) Source # | |
Defined in Cardano.Ledger.Orphans getSignableRepresentation ∷ Hash a b → ByteString Source # | |
(HashAlgorithm h, Typeable a) ⇒ DecCBOR (Hash h a) | |
(HashAlgorithm h, Typeable a) ⇒ EncCBOR (Hash h a) | |
HashAlgorithm h ⇒ SafeToHash (Hash h i) Source # | Hash of a hash. Hash is always safe to hash. Do you even hash? |
Defined in Cardano.Ledger.Hashes originalBytes ∷ Hash h i → ByteString Source # originalBytesSize ∷ Hash h i → Int Source # makeHashWithExplicitProxys ∷ Proxy i0 → Hash h i → SafeHash i0 Source # | |
HashAlgorithm h ⇒ Default (Hash h b) Source # | |
Defined in Cardano.Ledger.Orphans | |
NFData (Hash h a) | |
Defined in Cardano.Crypto.Hash.Class | |
Eq (Hash h a) | |
Ord (Hash h a) | |
HeapWords (Hash h a) | |
HashAlgorithm h ⇒ MemPack (Hash h a) | |
NoThunks (Hash h a) | |
HashAlgorithm h ⇒ IsString (Code Q (Hash h a)) | |
Defined in Cardano.Crypto.Hash.Class | |
type Rep (Hash h a) | |
Defined in Cardano.Crypto.Hash.Class type Rep (Hash h a) = D1 ('MetaData "Hash" "Cardano.Crypto.Hash.Class" "cardano-crypto-class-2.2.0.0-26c5fd30d06a5d79fe778ccc9b3b70cb764a47cb3e1af3de4f34878e2972d13e" 'True) (C1 ('MetaCons "UnsafeHashRep" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (PackedBytes (SizeHash h))))) |
class (KnownNat (SizeHash h), Typeable h) ⇒ HashAlgorithm h Source #
Instances
type HASH = Blake2b_256 Source #
Hashing algorithm used for hashing everything, except addresses, for which ADDRHASH
is used.
type ADDRHASH = Blake2b_224 Source #
Hashing algorithm used for hashing cryptographic keys and scripts. As the type synonym name alludes, this is the hashing algorithm used for addresses.
Era-independent hash type identifiers.
Various identifiers in the ledger are hashes of particular structures. While the structures may change from era to era, the hash will remain the same, and we can refer to the hash of, say, a transaction, without knowing the actual transaction type. As such, we define a number of these hashes here.
data EraIndependentTxBody Source #
data EraIndependentScript Source #
data EraIndependentData Source #
Instances
HeapWords (StrictMaybe DataHash) Source # | |
Defined in Cardano.Ledger.Plutus.Data | |
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 # |
Hashes
`DSIGN
Verification Key Hashes
newtype KeyHash (r ∷ KeyRole) Source #
Discriminated hash of public Key
Instances
HasKeyRole KeyHash Source # | |
Defined in Cardano.Ledger.Hashes | |
FromJSON (KeyHash r) Source # | |
FromJSONKey (KeyHash r) Source # | |
Defined in Cardano.Ledger.Hashes | |
ToJSON (KeyHash r) Source # | |
ToJSONKey (KeyHash r) Source # | |
Defined in Cardano.Ledger.Hashes | |
Generic (KeyHash r) Source # | |
Show (KeyHash r) Source # | |
Typeable r ⇒ FromCBOR (KeyHash r) Source # | |
Typeable r ⇒ ToCBOR (KeyHash r) Source # | |
Typeable r ⇒ DecCBOR (KeyHash r) Source # | |
Typeable r ⇒ EncCBOR (KeyHash r) Source # | |
Default (KeyHash r) Source # | |
Defined in Cardano.Ledger.Hashes | |
NFData (KeyHash r) Source # | |
Defined in Cardano.Ledger.Hashes | |
Eq (KeyHash r) Source # | |
Ord (KeyHash r) Source # | |
Defined in Cardano.Ledger.Hashes | |
NoThunks (KeyHash r) Source # | |
type Rep (KeyHash r) Source # | |
Defined in Cardano.Ledger.Hashes |
The role of a key.
All key roles are fixed and unique, except for the Witness
role. In particular,
keys can be cast to a Witness
role with the help of asWitness
, because same witness
can be valid for many roles.
In fact, it is perfectly allowable for a key to be used in many roles by the end user; there is nothing prohibiting somebody using the same underlying key or a script as their payment and staking credential, as well as the key for their stake pool. However, in the ledger code mixing up keys with different roles could be catastrophic, that is why we have this separation.
hashTxBodySignature ∷ SignedDSIGN DSIGN (Hash HASH EraIndependentTxBody) → Hash HASH (SignedDSIGN DSIGN (Hash HASH EraIndependentTxBody)) Source #
Hash a given signature
Script Hashes
newtype ScriptHash Source #
Instances
type DataHash = SafeHash EraIndependentData Source #
AuxiliaryData
newtype TxAuxDataHash Source #
Instances
VRF
Verification Key Hashes
newtype VRFVerKeyHash (r ∷ KeyRoleVRF) Source #
Discriminated hash of VRF Verification Key
Instances
toVRFVerKeyHash ∷ Hash HASH (VerKeyVRF v) → VRFVerKeyHash (r ∷ KeyRoleVRF) Source #
fromVRFVerKeyHash ∷ VRFVerKeyHash (r ∷ KeyRoleVRF) → Hash HASH (VerKeyVRF v) Source #
Genesis DSIGN
and VRF
Verification Key Hashes
data GenDelegPair Source #
Instances
Instances
FromJSON GenDelegs Source # | |
ToJSON GenDelegs Source # | |
Generic GenDelegs Source # | |
Show GenDelegs Source # | |
DecCBOR GenDelegs Source # | |
EncCBOR GenDelegs Source # | |
NFData GenDelegs Source # | |
Defined in Cardano.Ledger.Hashes | |
Eq GenDelegs Source # | |
NoThunks GenDelegs Source # | |
type Rep GenDelegs Source # | |
Defined in Cardano.Ledger.Hashes type Rep GenDelegs = D1 ('MetaData "GenDelegs" "Cardano.Ledger.Hashes" "cardano-ledger-core-1.17.0.0-inplace" 'True) (C1 ('MetaCons "GenDelegs" 'PrefixI 'True) (S1 ('MetaSel ('Just "unGenDelegs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map (KeyHash 'Genesis) GenDelegPair)))) |
SafeHash
In cardano-ledger, hashing a type X
is based upon the serialization of
X
. Serialization is based upon the EncCBOR
and DecCBOR
type classes, and the
serialization that can be handled by DecCBOR
instances for a particular type, are not
necessarily unique. For this reason, when an X
object comes over the network in
serialized form, we must preserve the original bytes that arrived over the network,
otherwise when the system hashes that object, the hash in the ledger, and the hash of
that object from the other side of the network may not agree. In otherwords
reserialization for the purpose of hash calculation is not an option. The SafeToHash
type class ensures that types with a (SafeToHash X)
instance store the original bytes
that arrived over the network for the value of X
. The recommended way to store the
original bytes is to use the type MemoBytes
, although there are a few types that
store their original bytes in other ways. In order to encourage the use of newtype over
MemoBytes
newtype defined as a MemoBytes
, which would get
the functionality of retaining bytes and deriving of SafeToHash
instance for free.
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