Plutus.V1.Ledger.Crypto
1. 📜 Overview
2. đź”§ LANGUAGE EXTENSIONS AND IMPORTS
3. 🗄️ Data Structures
3.1 🔑 PubKeyHash (newtype)
4. 🤝 Typeclass Instances
5. 🏠On‑chain Derivations
6. 📚 Glossary
1 📜 Overview
The Plutus.V1.Ledger.Crypto
module introduces the PubKeyHash
type, a lightweight wrapper around a built‑in byte string used to identify public keys on‑chain.
It covers:
A zero‑cost
newtype
for public key hashesDerivations for on‑chain and off‑chain typeclasses (
Eq
,Ord
,ToData
, etc.)IsString
and pretty printing viaLedgerBytes
On‑chain lifting with
makeLift
2 đź”§ LANGUAGE EXTENSIONS AND IMPORTS
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -fno-omit-interface-pragmas #-}
module Plutus.V1.Ledger.Crypto (
PubKeyHash(..)
) where
import Control.DeepSeq (NFData)
import Data.String (IsString)
import GHC.Generics (Generic)
import Plutus.V1.Ledger.Bytes (LedgerBytes(..))
import PlutusTx qualified
import PlutusTx.Lift (makeLift)
import PlutusTx.Prelude qualified as PlutusTx
import Prettyprinter (Pretty)
LANGUAGE pragmas:
DataKinds
,DeriveAnyClass
,DeriveGeneric
,DerivingVia
,OverloadedStrings
,TemplateHaskell
,TypeApplications
OPTIONS_GHC: suppresses interface pragma omissions.
Imports:
NFData
andGeneric
for deep evaluation and generics.IsString
for string literal conversion viaLedgerBytes
.PlutusTx
modules for on‑chain typeclasses and utilities.Prettyprinter
for human‑readable instances.
3 🗄️ Data Structures
3.1 🔑 PubKeyHash (newtype)
newtype PubKeyHash = PubKeyHash { getPubKeyHash :: PlutusTx.BuiltinByteString }
deriving stock (Eq, Ord, Generic)
deriving anyclass (NFData)
deriving newtype (PlutusTx.Eq, PlutusTx.Ord, PlutusTx.ToData, PlutusTx.FromData, PlutusTx.UnsafeFromData)
deriving IsString via LedgerBytes
deriving (Show, Pretty) via LedgerBytes
Field:
getPubKeyHash
unwraps the underlyingBuiltinByteString
.Deriving strategies: separates stock, anyclass, newtype, and
via
approaches.
Example usage:
let pkh = "aabbcc" :: PubKeyHash -- via IsString
print pkh -- via Pretty (hex display)
4 🤝 Typeclass Instances
Eq
,Ord
(stock) for equality and ordering.NFData
(anyclass) for deep evaluation.PlutusTx.Eq
,PlutusTx.Ord
,PlutusTx.ToData
,PlutusTx.FromData
,PlutusTx.UnsafeFromData
(newtype) for on‑chain serialization and comparison.IsString
(viaLedgerBytes
) to parse hex string literals.Show
,Pretty
(viaLedgerBytes
) to display as hex text.
5 🏠On‑chain Derivations
makeLift ''PubKeyHash
makeLift: generates the
Lift
instance allowing embedding ofPubKeyHash
values in PlutusTx code.
6 📚 Glossary
PubKeyHash: hashed public key identifier for on‑chain use.
BuiltinByteString: Plutus’s representation of raw bytes.
newtype: zero‑cost Haskell wrapper for a single field.
DerivingVia: uses an existing type’s instances (
LedgerBytes
) to derive for a new type.IsString: typeclass for conversion from string literals.
makeLift: Template Haskell function to create
Lift
instances for on‑chain embedding.PlutusTx.ToData / FromData: on‑chain serialization for
BuiltinData
.NFData: class for deep (normal form) evaluation.
Pretty: pretty‑printing class from
Prettyprinter
.
Last updated