Copyright | © 2018-2021 IOHK |
---|---|
License | Apache-2.0 |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- data Shared (depth :: Depth) key
- getKey :: Shared depth key -> key
- liftXPrv :: XPrv -> Shared depth XPrv
- liftXPub :: XPub -> Shared depth XPub
- sharedWalletId :: ByteString -> Script Cosigner -> Maybe (Script Cosigner) -> ByteString
- genMasterKeyFromXPrv :: XPrv -> Shared 'RootK XPrv
- genMasterKeyFromMnemonic :: SomeMnemonic -> ScrubbedBytes -> Shared 'RootK XPrv
- deriveAccountPrivateKey :: Shared 'RootK XPrv -> Index 'Hardened 'AccountK -> Shared 'AccountK XPrv
- deriveAddressPrivateKey :: Shared 'AccountK XPrv -> Role -> Index 'Soft 'PaymentK -> Shared 'ScriptK XPrv
- deriveAddressPublicKey :: Shared 'AccountK XPub -> Role -> Index 'Soft 'PaymentK -> Shared 'ScriptK XPub
- deriveDelegationPrivateKey :: Shared 'AccountK XPrv -> Index 'Soft 'PaymentK -> Shared 'ScriptK XPrv
- deriveDelegationPublicKey :: Shared 'AccountK XPub -> Index 'Soft 'PaymentK -> Shared 'ScriptK XPub
Documentation
This module provides an implementation of:
GenMasterKey
: for generating Shared 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 payment addresses from a address public key or a scriptdelegationAddress
: 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 pointerstakeAddress
: 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
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 #
:: SomeMnemonic | Some valid mnemonic sentence. |
-> ScrubbedBytes | An optional second-factor passphrase (or |
-> 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