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.Shared

  • 1 type
  • 12 values

This module provides an implementation of:

  • GenMasterKey: for generating Shared 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)

Shared

5 declarations
newtypenewtype Shared (depth :: Depth) key
#

A cryptographic key for sequential-scheme address derivation, with phantom-types to disambiguate key types. The derivation is mostly like Shelley, except the used purpose index (here 1854H rather than Shelley's 1852H)

let rootPrivateKey = Shared 'RootK XPrv
let accountPubKey  = Shared 'AccountK XPub
let addressPubKey  = Shared 'PaymentK XPub
Instances13GenMasterKey, HardDerivation, SoftDerivation, Functor, Eq, Show, …
valueliftXPrv :: XPrv -> Shared depth XPrv
#

Unsafe backdoor for constructing an Shared 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 -> Shared depth XPub
#

Unsafe backdoor for constructing an Shared 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).

Key Derivation

8 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 :: Shared '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