GenMasterKey: for generating Icarus 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 addresses from a public key
We call Icarus addresses the new format of Cardano addresses which came
after Byron. This is the format initially used in Yoroi
and now also used by Daedalus.
A cryptographic key for sequential-scheme address derivation, with
phantom-types to disambiguate key types.
let rootPrivateKey = Icarus 'RootK XPrv
let accountPubKey = Icarus 'AccountK XPub
let addressPubKey = Icarus 'PaymentK XPub
>>> :set -XOverloadedStrings
>>> :set -XTypeApplications
>>> :set -XDataKinds
>>> :set -XFlexibleContexts
>>> import Cardano.Mnemonic ( mkSomeMnemonic )
>>> import Cardano.Address ( base58 )
>>> import Cardano.Address.Derivation ( toXPub )
>>> import qualified Cardano.Address.Style.Icarus as Icarus
>>>
>>> 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 = Icarus.genMasterKeyFromMnemonic mw sndFactor :: Icarus 'RootK XPrv
Deriving child keys
Let's consider the following 3rd, 4th and 5th derivation paths 0'/0/14
accIx assumes values from 2147483648 (ie. 0x80000000) to 4294967295 (ie. 0xFFFFFFFF)
addIx assume values from 0 to 2147483647 (ie. 7FFFFFFF)
>>> let Just accIx = indexFromWord32 0x80000000
// this is the same as
>>> let accIx = minBound @(Index 'Hardened 'AccountK)
>>> let acctK = Icarus.deriveAccountPrivateKey rootK accIx
>>> let Just addIx = indexFromWord32 0x00000014
>>> let addrK = Icarus.deriveAddressPrivateKey acctK Icarus.UTxOExternal addIx
>>> base58 $ Icarus.paymentAddress Icarus.icarusMainnet (toXPub $ addrK)
>>>Ae2tdPwUPEZ8XpsjgQPH2cJdtohkYrxJ3i5y6mVsrkZZkdpdn6mnr4Rt6wG
Unsafe backdoor for constructing an Icarus 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).
Unsafe backdoor for constructing an Icarus 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).