Copyright | © 2018-2020 IOHK |
---|---|
License | Apache-2.0 |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- data Icarus (depth :: Depth) key
- getKey :: Icarus depth key -> key
- genMasterKeyFromXPrv :: XPrv -> Icarus 'RootK XPrv
- genMasterKeyFromMnemonic :: SomeMnemonic -> ScrubbedBytes -> Icarus 'RootK XPrv
- deriveAccountPrivateKey :: Icarus 'RootK XPrv -> Index 'Hardened 'AccountK -> Icarus 'AccountK XPrv
- deriveAddressPrivateKey :: Icarus 'AccountK XPrv -> Role -> Index 'Soft 'PaymentK -> Icarus 'PaymentK XPrv
- deriveAddressPublicKey :: Icarus 'AccountK XPub -> Role -> Index 'Soft 'PaymentK -> Icarus 'PaymentK XPub
- data AddressInfo = AddressInfo {}
- eitherInspectAddress :: Address -> Either ErrInspectAddress AddressInfo
- paymentAddress :: NetworkDiscriminant Icarus -> Icarus 'PaymentK XPub -> Address
- prettyErrInspectAddress :: ErrInspectAddress -> String
- icarusMainnet :: NetworkDiscriminant Icarus
- icarusStaging :: NetworkDiscriminant Icarus
- icarusTestnet :: NetworkDiscriminant Icarus
- icarusPreview :: NetworkDiscriminant Icarus
- icarusPreprod :: NetworkDiscriminant Icarus
- liftXPrv :: XPrv -> Icarus depth XPrv
- liftXPub :: XPub -> Icarus depth XPub
Documentation
This module provides an implementation of:
GenMasterKey
: for generating Icarus master keys from mnemonic sentencesHardDerivation
: for hierarchical hard derivation of parent to child keysSoftDerivation
: for hierarchical soft derivation of parent to child keysPaymentAddress
: 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.
Icarus
data Icarus (depth :: Depth) key Source #
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
Since: 1.0.0
Instances
Key Derivation
Generating a root key from SomeMnemonic
: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
genMasterKeyFromXPrv :: XPrv -> Icarus 'RootK XPrv Source #
Generate a root key from a corresponding root XPrv
Since: 1.0.0
genMasterKeyFromMnemonic Source #
:: SomeMnemonic | Some valid mnemonic sentence. |
-> ScrubbedBytes | An optional second-factor passphrase (or |
-> Icarus 'RootK XPrv |
Generate a root key from a corresponding mnemonic.
Since: 1.0.0
deriveAccountPrivateKey :: Icarus 'RootK XPrv -> Index 'Hardened 'AccountK -> Icarus 'AccountK XPrv Source #
Derives an account private key from the given root private key.
Since: 1.0.0
deriveAddressPrivateKey :: Icarus 'AccountK XPrv -> Role -> Index 'Soft 'PaymentK -> Icarus 'PaymentK XPrv Source #
Derives an address private key from the given account private key.
Since: 1.0.0
deriveAddressPublicKey :: Icarus 'AccountK XPub -> Role -> Index 'Soft 'PaymentK -> Icarus 'PaymentK XPub Source #
Derives an address public key from the given account public key.
Since: 1.0.0
Addresses
Generating a PaymentAddress
| Possible errors from inspecting a Shelley address
Since: 3.0.0
data AddressInfo Source #
The result of eitherInspectAddress
for Icarus addresses.
Since: 3.4.0
Instances
eitherInspectAddress :: Address -> Either ErrInspectAddress AddressInfo Source #
Determines whether an Address
is an Icarus address.
Returns either details about the Address
, or ErrInspectAddress
if it's
not a valid icarus address.
Since: 3.4.0
paymentAddress :: NetworkDiscriminant Icarus -> Icarus 'PaymentK XPub -> Address Source #
Convert a public key to a payment Address
valid for the given
network discrimination.
Since: 1.0.0
prettyErrInspectAddress :: ErrInspectAddress -> String Source #
Pretty-print an ErrInspectAddress
Since: 3.0.0
Network Discrimination
icarusMainnet :: NetworkDiscriminant Icarus Source #
NetworkDiscriminant
for Cardano MainNet & Icarus
Since: 2.0.0
icarusStaging :: NetworkDiscriminant Icarus Source #
NetworkDiscriminant
for Cardano Staging & Icarus
Since: 2.0.0
icarusTestnet :: NetworkDiscriminant Icarus Source #
NetworkDiscriminant
for Cardano Testnet & Icarus
Since: 2.0.0
icarusPreview :: NetworkDiscriminant Icarus Source #
NetworkDiscriminant
for Cardano Preview & Icarus
Since: 3.13.0
icarusPreprod :: NetworkDiscriminant Icarus Source #
NetworkDiscriminant
for Cardano Preprod & Icarus
Since: 3.13.0
Unsafe
liftXPrv :: XPrv -> Icarus depth XPrv Source #
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).
Since: 1.0.0
liftXPub :: XPub -> Icarus depth XPub Source #
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).
Since: 2.0.0