HORIZON HASKELLDocslts/ghc-9.14.xd82dee82026-10-12Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · d82dee8 · 2026-10-12

Modulecardano-addresses-4.0.2Haskell2010

Cardano.Address.Style.Shelley

  • 10 types
  • 37 values

This module provides an implementation of:

  • GenMasterKey: for generating Shelley master keys from mnemonic sentences

  • HardDerivation: for hierarchical hard derivation of parent to child keys

  • SoftDerivation: for hierarchical soft derivation of parent to child keys

  • paymentAddress: for constructing payment addresses from a address public key or a script

  • delegationAddress: for constructing delegation addresses from payment credential (public key or script) and stake credential (public key or script)

  • pointerAddress: for constructing delegation addresses from payment credential (public key or script) and chain pointer

  • stakeAddress: for constructing reward accounts from stake credential (public key or script)

Shelley

19 declarations
newtypenewtype Shelley (depth :: Depth) key
#

A cryptographic key for sequential-scheme address derivation, with phantom-types to disambiguate key types.

let rootPrivateKey = Shelley 'RootK XPrv
let accountPubKey  = Shelley 'AccountK XPub
let addressPubKey  = Shelley 'PaymentK XPub
Instances15HasNetworkDiscriminant, GenMasterKey, HardDerivation, SoftDerivation, Functor, Eq, …
datadata Role
#

Describe what the keys within an account are used for.

Constructors

  • UTxOExternal

    Used for public addresses sent to other parties for receiving money.

  • UTxOInternal

    Generated by wallet software to send change back to the wallet.

  • Stake

    Used for stake key(s) and delegation.

  • DRep

    Used for DRep key derivation.

  • CCCold

    Used for constitutional committee cold key derivation

  • CCHot

    Used for constitutional committee hot key derivation

Instances7Bounded, Eq, Ord, Show, Generic, NFData, …
data familydata family Credential (purpose :: Depth)
#

Shelley offers several ways to identify ownership of entities on chain.

This data-family has two instances, depending on whether the key is used for payment or for delegation.

Instances4Show, Credential

Key Derivation

10 declarations
Generating a root key from SomeMnemonic
>>> :set -XOverloadedStrings
>>> :set -XTypeApplications
>>> :set -XDataKinds
>>> import Cardano.Mnemonic ( mkSomeMnemonic )

>>> let (Right mw) = mkSomeMnemonic @'[15] ["network","empty","cause","mean","expire","private","finger","accident","session","problem","absurd","banner","stage","void","what"]
>>> let sndFactor = mempty -- Or alternatively, a second factor mnemonic transformed to bytes via someMnemonicToBytes
>>> let rootK = genMasterKeyFromMnemonic mw sndFactor :: Shelley 'RootK XPrv
Deriving child keys

Let's consider the following 3rd, 4th and 5th derivation paths 0'/0/14

>>> let Just accIx = indexFromWord32 0x80000000
>>> let acctK = deriveAccountPrivateKey rootK accIx

>>> let Just addIx = indexFromWord32 0x00000014
>>> let addrK = deriveAddressPrivateKey acctK UTxOExternal addIx

>>> let stakeK = deriveDelegationPrivateKey acctK

Derive a delegation key for a corresponding AccountK. Note that wallet software are by convention only using one delegation key per account, and always the first account (with index 0').

Deriving delegation keys for something else than the initial account is not recommended and can lead to incompatibility with existing wallet softwares (Daedalus, Yoroi, Adalite...).

Derive a DRep key for a corresponding AccountK. Note that wallet software are by convention only using one delegation key per account, and always the first account (with index 0').

Deriving DRep keys for something else than the initial account is not recommended and can lead to incompatibility with existing wallet softwares (Daedalus, Yoroi, Adalite...).

Derive a CCCold key for a corresponding AccountK. Note that wallet software are by convention only using one delegation key per account, and always the first account (with index 0').

Deriving CCCold keys for something else than the initial account is not recommended and can lead to incompatibility with existing wallet softwares (Daedalus, Yoroi, Adalite...).

Derive a CCHot key for a corresponding AccountK. Note that wallet software are by convention only using one delegation key per account, and always the first account (with index 0').

Deriving CCHot keys for something else than the initial account is not recommended and can lead to incompatibility with existing wallet softwares (Daedalus, Yoroi, Adalite...).

Addresses

16 declarations
Generating a PaymentAddress from public key credential
>>> import Cardano.Address ( bech32 )
>>> import Cardano.Address.Derivation ( toXPub )
>>> let (Right tag) = mkNetworkDiscriminant 1
>>> let paymentCredential = PaymentFromExtendedKey $ (toXPub $ addrK)
>>> bech32 $ paymentAddress tag paymentCredential
>>> "addr1vxpfffuj3zkp5g7ct6h4va89caxx9ayq2gvkyfvww48sdncxsce5t"
Generating a PaymentAddress from script credential
>>> import Cardano.Address.Script.Parser ( scriptFromString )
>>> import Cardano.Address.Script ( toScriptHash )
>>> import Codec.Binary.Encoding ( encode )
>>> import Data.Text.Encoding ( decodeUtf8 )
>>> let (Right tag) = mkNetworkDiscriminant 1
>>> let verKey1 = "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt36ms"
>>> let verKey2 = "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyrenxv223vj"
>>> let scriptStr = "all [" ++ verKey1 ++ ", " ++ verKey2 ++ "]"
>>> let (Right script) = scriptFromString scriptStr
>>> let infoSpendingScriptHash@(ScriptHash bytes) = toScriptHash script
>>> decodeUtf8 (encode EBase16 bytes)
"a015ae61075e25c3d9250bdcbc35c6557272127927ecf2a2d716e29f"
>>> bech32 $ paymentAddress tag (PaymentFromScriptHash infoSpendingScriptHash)
"addr1wxspttnpqa0zts7ey59ae0p4ce2hyusj0yn7eu4z6utw98c9uxm83"
Generating a DelegationAddress
>>> let (Right tag) = mkNetworkDiscriminant 1
>>> let paymentCredential = PaymentFromExtendedKey $ (toXPub $ addrK)
>>> let delegationCredential = DelegationFromExtendedKey $ (toXPub $ stakeK)
>>> bech32 $ delegationAddress tag paymentCredential delegationCredential
"addr1qxpfffuj3zkp5g7ct6h4va89caxx9ayq2gvkyfvww48sdn7nudck0fzve4346yytz3wpwv9yhlxt7jwuc7ytwx2vfkyqmkc5xa"
Generating a PointerAddress
>>> import Cardano.Address ( ChainPointer (..) )
>>> let (Right tag) = mkNetworkDiscriminant 1
>>> let ptr = ChainPointer 123 1 2
>>> let paymentCredential = PaymentFromExtendedKey $ (toXPub $ addrK)
>>> bech32 $ pointerAddress tag paymentCredential ptr
"addr1gxpfffuj3zkp5g7ct6h4va89caxx9ayq2gvkyfvww48sdnmmqypqfcp5um"
Generating a DelegationAddress from using the same script credential in both payment and delegation
>>> bech32 $ delegationAddress tag (PaymentFromScriptHash infoSpendingScriptHash) (DelegationFromScript infoSpendingScriptHash)
"addr1xxspttnpqa0zts7ey59ae0p4ce2hyusj0yn7eu4z6utw98aqzkhxzp67yhpajfgtmj7rt3j4wfepy7f8ane294cku20swucnrl"
datadata InspectAddress
#
Instances5Eq, Show, Generic, ToJSON, Rep
datadata AddressInfo
#
Instances5Eq, Show, Generic, ToJSON, Rep
datadata ReferenceInfo
#

Info from Address about how delegation keys are located.

Instances4Eq, Show, Generic, Rep

Possible errors from inspecting a Shelley address

Constructors

Instances6Eq, Show, Generic, Exception, ToJSON, Rep
datadata ErrInspectAddress
#

Possible errors from inspecting a Shelley, Icarus, or Byron address.

Instances6Eq, Show, Generic, Exception, ToJSON, Rep

Network Discrimination

5 declarations

Unsafe

9 declarations
valueliftXPrv :: XPrv -> Shelley depth XPrv
#

Unsafe backdoor for constructing an Shelley key from a raw XPrv. this is unsafe because it lets the caller choose the actually derivation depth.

This can be useful however when serializing / deserializing such a type, or to speed up test code (and avoid having to do needless derivations from a master key down to an address key for instance).

valueliftXPub :: XPub -> Shelley depth XPub
#

Unsafe backdoor for constructing an Shelley key from a raw XPub. this is unsafe because it lets the caller choose the actually derivation depth.

This can be useful however when serializing / deserializing such a type, or to speed up test code (and avoid having to do needless derivations from a master key down to an address key for instance).

valueliftPub :: Pub -> Shelley depth Pub
#

Unsafe backdoor for constructing an Shelley key from a raw Pub. this is unsafe because it lets the caller choose the actually derivation depth.

This can be useful however when serializing / deserializing such a type, or to speed up test code (and avoid having to do needless derivations from a master key down to an address key for instance).