cardano-addresses-3.11.0: Library utilities for mnemonic generation and address derivation.
Copyright © 2018-2021 IOHK
License Apache-2.0
Safe Haskell None
Language Haskell2010

Cardano.Address.Style.Shared

Description

Synopsis

Documentation

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

data Shared (depth :: Depth ) key Source #

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

Since: 3.4.0

Instances

Instances details
GenMasterKey Shared Source #
Instance details

Defined in Cardano.Address.Style.Shared

SoftDerivation Shared Source #
Instance details

Defined in Cardano.Address.Style.Shared

HardDerivation Shared Source #
Instance details

Defined in Cardano.Address.Style.Shared

Functor ( Shared depth) Source #
Instance details

Defined in Cardano.Address.Style.Shared

Methods

fmap :: (a -> b) -> Shared depth a -> Shared depth b Source #

(<$) :: a -> Shared depth b -> Shared depth a Source #

Eq key => Eq ( Shared depth key) Source #
Instance details

Defined in Cardano.Address.Style.Shared

Methods

(==) :: Shared depth key -> Shared depth key -> Bool Source #

(/=) :: Shared depth key -> Shared depth key -> Bool Source #

Show key => Show ( Shared depth key) Source #
Instance details

Defined in Cardano.Address.Style.Shared

Generic ( Shared depth key) Source #
Instance details

Defined in Cardano.Address.Style.Shared

Associated Types

type Rep ( Shared depth key) :: Type -> Type Source #

Methods

from :: Shared depth key -> Rep ( Shared depth key) x Source #

to :: Rep ( Shared depth key) x -> Shared depth key Source #

NFData key => NFData ( Shared depth key) Source #
Instance details

Defined in Cardano.Address.Style.Shared

Methods

rnf :: Shared depth key -> () Source #

type SecondFactor Shared Source #
Instance details

Defined in Cardano.Address.Style.Shared

type AccountIndexDerivationType Shared Source #
Instance details

Defined in Cardano.Address.Style.Shared

type AddressIndexDerivationType Shared Source #
Instance details

Defined in Cardano.Address.Style.Shared

type WithRole Shared Source #
Instance details

Defined in Cardano.Address.Style.Shared

type Rep ( Shared depth key) Source #
Instance details

Defined in Cardano.Address.Style.Shared

type Rep ( Shared depth key) = D1 (' MetaData "Shared" "Cardano.Address.Style.Shared" "cardano-addresses-3.11.0-D40zGSHo3QMFNy9OpWafYI" ' True ) ( C1 (' MetaCons "Shared" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "getKey") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 key)))

getKey :: Shared depth key -> key Source #

Extract the raw XPrv or XPub wrapped by this type.

Since: 3.4.0

liftXPrv :: XPrv -> Shared depth XPrv Source #

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

Since: 3.4.0

liftXPub :: XPub -> Shared depth XPub Source #

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

Since: 3.4.0

sharedWalletId :: ByteString -> Script Cosigner -> Maybe ( Script Cosigner ) -> ByteString Source #

Calculates wallet id of shared wallet It takes raw bytes of account public kye (64-bytes), spending script template, and optionally staking script template.

Since: 3.10.0

Key Derivation

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

genMasterKeyFromXPrv :: XPrv -> Shared ' RootK XPrv Source #

Generate a root key from a corresponding root XPrv

Since: 3.4.0

genMasterKeyFromMnemonic Source #

Arguments

:: SomeMnemonic

Some valid mnemonic sentence.

-> ScrubbedBytes

An optional second-factor passphrase (or mempty )

-> Shared ' RootK XPrv

Generate a root key from a corresponding mnemonic.

Since: 3.4.0

deriveAccountPrivateKey :: Shared ' RootK XPrv -> Index ' Hardened ' AccountK -> Shared ' AccountK XPrv Source #

Derives an account private key from the given root private key.

Since: 3.4.0

deriveAddressPrivateKey :: Shared ' AccountK XPrv -> Role -> Index ' Soft ' PaymentK -> Shared ' ScriptK XPrv Source #

Derives a multisig private key from the given account private key for payment credential.

Since: 3.4.0

deriveAddressPublicKey :: Shared ' AccountK XPub -> Role -> Index ' Soft ' PaymentK -> Shared ' ScriptK XPub Source #

Derives a multisig public key from the given account public key for payment credential.

Since: 3.4.0

deriveDelegationPrivateKey :: Shared ' AccountK XPrv -> Index ' Soft ' PaymentK -> Shared ' ScriptK XPrv Source #

Derives a multisig private key from the given account private key for delegation credential.

Since: 3.4.0

deriveDelegationPublicKey :: Shared ' AccountK XPub -> Index ' Soft ' PaymentK -> Shared ' ScriptK XPub Source #

Derives a multisig public key from the given account public key for delegation credential.

Since: 3.4.0