cardano-addresses
Copyright2020 Input Output (Hong Kong) Ltd. 2021-2022 Input Output Global Inc. (IOG) 2023-2025 Intersect
LicenseApache-2.0
Safe HaskellNone
LanguageHaskell2010

Cardano.Address.Style.Byron

Description

 
Synopsis

Documentation

This module provides an implementation of:

We call Byron addresses the old address type used by Daedalus in the early days of Cardano. Using this type of addresses and underlying key scheme is now considered deprecated because of some security implications.

The internals of the Byron does not matter for the reader, but basically contains what is necessary to perform key derivation and generate addresses from a Byron type.

Byron uses WholeDomain (meaning Soft+Hardened) for account key and payment key derivation. It should use Hardened for account and Soft for payment as design, but due to the error made prior 2019 in cardano-sl implementation WholeDomain was adopted to handle all the keys. Nevertheless, it was recommended and enforced to use Hardened for account derivation and Soft for payment key derivation from 2019 onwards. To sum up both account index and payment index can assume values from 0 to 4294967295 (ie. 0xFFFFFFFF)

Deprecation Notice

Unless you have good reason to do so (like writing backward-compatible code with an existing piece), any new implementation should use the Icarus style for key and addresses.

Byron

data Byron (depth :: Depth) key #

Deprecated: see Icarus

Material for deriving HD random scheme keys, which can be used for making addresses.

Since: 1.0.0

Instances

Instances details
HasNetworkDiscriminant Byron # 
Instance details

Defined in Cardano.Address.Style.Byron

PaymentAddress Byron # 
Instance details

Defined in Cardano.Address.Style.Byron

GenMasterKey Byron #

Key Derivation

Example:

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.Byron as Byron

>>> let (Right mw) = mkSomeMnemonic @'[12] ["moon","fox","ostrich","quick","cactus","raven","wasp","intact","first","ring","crumble","error"]
>>> let rootK = Byron.genMasterKeyFromMnemonic mw :: Byron 'RootK XPrv

Deriving child keys

Both accIx and addIx assume values from 0 to 4294967295 (ie. 0xFFFFFFFF) In case of account one can get this bound via

let accIxMin = minBound (Index 'WholeDomain 'AccountK)
let accIxMax = maxBound (Index 'WholeDomain 'AccountK)

>>> let Just accIx = wholeDomainIndex 0x80000000
>>> let acctK = Byron.deriveAccountPrivateKey rootK accIx

>>> let Just addIx = wholeDomainIndex 0x80000014
>>> let addrK = Byron.deriveAddressPrivateKey acctK addIx

>>> base58 $ Byron.paymentAddress Byron.byronMainnet (toXPub $ addrK)
DdzFFzCqrhsq3KjLtT51mESbZ4RepiHPzLqEhamexVFTJpGbCXmh7qSxnHvaL88QmtVTD1E1sjx8Z1ZNDhYmcBV38ZjDST9kYVxSkhcw
Instance details

Defined in Cardano.Address.Style.Byron

Associated Types

type SecondFactor Byron 
Instance details

Defined in Cardano.Address.Style.Byron

HardDerivation Byron # 
Instance details

Defined in Cardano.Address.Style.Byron

Functor (Byron depth) # 
Instance details

Defined in Cardano.Address.Style.Byron

Methods

fmap :: (a -> b) -> Byron depth a -> Byron depth b #

(<$) :: a -> Byron depth b -> Byron depth a #

(NFData key, NFData (DerivationPath depth)) => NFData (Byron depth key) # 
Instance details

Defined in Cardano.Address.Style.Byron

Methods

rnf :: Byron depth key -> () #

Generic (Byron depth key) # 
Instance details

Defined in Cardano.Address.Style.Byron

Associated Types

type Rep (Byron depth key) 
Instance details

Defined in Cardano.Address.Style.Byron

type Rep (Byron depth key) = D1 ('MetaData "Byron" "Cardano.Address.Style.Byron" "cardano-addresses-4.0.2-inplace" 'False) (C1 ('MetaCons "Byron" 'PrefixI 'True) (S1 ('MetaSel ('Just "getKey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 key) :*: (S1 ('MetaSel ('Just "derivationPath") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (DerivationPath depth)) :*: S1 ('MetaSel ('Just "payloadPassphrase") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ScrubbedBytes))))

Methods

from :: Byron depth key -> Rep (Byron depth key) x #

to :: Rep (Byron depth key) x -> Byron depth key #

(Show key, Show (DerivationPath depth)) => Show (Byron depth key) # 
Instance details

Defined in Cardano.Address.Style.Byron

Methods

showsPrec :: Int -> Byron depth key -> ShowS #

show :: Byron depth key -> String #

showList :: [Byron depth key] -> ShowS #

(Eq key, Eq (DerivationPath depth)) => Eq (Byron depth key) # 
Instance details

Defined in Cardano.Address.Style.Byron

Methods

(==) :: Byron depth key -> Byron depth key -> Bool #

(/=) :: Byron depth key -> Byron depth key -> Bool #

type NetworkDiscriminant Byron # 
Instance details

Defined in Cardano.Address.Style.Byron

type AccountIndexDerivationType Byron # 
Instance details

Defined in Cardano.Address.Style.Byron

type AddressIndexDerivationType Byron # 
Instance details

Defined in Cardano.Address.Style.Byron

type SecondFactor Byron # 
Instance details

Defined in Cardano.Address.Style.Byron

type WithRole Byron # 
Instance details

Defined in Cardano.Address.Style.Byron

type WithRole Byron = ()
type Rep (Byron depth key) # 
Instance details

Defined in Cardano.Address.Style.Byron

type Rep (Byron depth key) = D1 ('MetaData "Byron" "Cardano.Address.Style.Byron" "cardano-addresses-4.0.2-inplace" 'False) (C1 ('MetaCons "Byron" 'PrefixI 'True) (S1 ('MetaSel ('Just "getKey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 key) :*: (S1 ('MetaSel ('Just "derivationPath") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (DerivationPath depth)) :*: S1 ('MetaSel ('Just "payloadPassphrase") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ScrubbedBytes))))

type family DerivationPath (depth :: Depth) where ... #

Deprecated: see Icarus

The hierarchical derivation indices for a given level/depth.

Since: 1.0.0

payloadPassphrase :: Byron depth key -> ScrubbedBytes #

Deprecated: see Icarus

Used for encryption of the derivation path payload within an address.

Since: 1.0.0

derivationPath :: Byron depth key -> DerivationPath depth #

Deprecated: see Icarus

The address derivation indices for the level of this key.

Since: 1.0.0

getKey :: Byron depth key -> key #

Deprecated: see Icarus

The raw private or public key.

Since: 1.0.0

Key Derivation

genMasterKeyFromXPrv :: XPrv -> Byron 'RootK XPrv #

Deprecated: see Icarus

Generate a root key from a corresponding root XPrv

Since: 1.0.0

genMasterKeyFromMnemonic #

Arguments

:: SomeMnemonic

Some valid mnemonic sentence.

-> Byron 'RootK XPrv 

Deprecated: see Icarus

Generate a root key from a corresponding mnemonic.

Since: 1.0.0

deriveAccountPrivateKey :: Byron 'RootK XPrv -> Index 'WholeDomain 'AccountK -> Byron 'AccountK XPrv #

Deprecated: see Icarus

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

Since: 1.0.0

deriveAddressPrivateKey :: Byron 'AccountK XPrv -> Index 'WholeDomain 'PaymentK -> Byron 'PaymentK XPrv #

Deprecated: see Icarus

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

Since: 1.0.0

Addresses

 

data AddressInfo #

The result of eitherInspectAddress for Byron addresses.

Since: 3.4.0

Constructors

AddressInfo 

Instances

Instances details
ToJSON AddressInfo # 
Instance details

Defined in Cardano.Address.Style.Byron

Generic AddressInfo # 
Instance details

Defined in Cardano.Address.Style.Byron

Associated Types

type Rep AddressInfo 
Instance details

Defined in Cardano.Address.Style.Byron

Show AddressInfo # 
Instance details

Defined in Cardano.Address.Style.Byron

Eq AddressInfo # 
Instance details

Defined in Cardano.Address.Style.Byron

type Rep AddressInfo # 
Instance details

Defined in Cardano.Address.Style.Byron

eitherInspectAddress :: Maybe XPub -> Address -> Either ErrInspectAddress AddressInfo #

Determines whether an Address is a Byron address.

Returns either details about the Address, or ErrInspectAddress if it's not a valid address.

Since: 3.4.0

inspectAddress :: MonadThrow m => Maybe XPub -> Address -> m Value #

Determines whether an Address is a Byron address.

Returns a JSON object with information about the address, or throws ErrInspectAddress if the address isn't a byron address.

Since: 3.0.0

inspectByronAddress :: MonadThrow m => Maybe XPub -> Address -> m Value #

Deprecated: use qualified inspectAddress instead.

Determines whether an Address is a Byron address.

Returns a JSON object with information about the address, or throws ErrInspectAddress if the address isn't a byron address.

Since: 2.0.0

paymentAddress :: NetworkDiscriminant Byron -> Byron 'PaymentK XPub -> Address #

Convert a public key to a payment Address valid for the given network discrimination.

Since: 1.0.0

data ErrInspectAddress #

Possible errors from inspecting a Byron address

Since: 3.0.0

Instances

Instances details
ToJSON ErrInspectAddress # 
Instance details

Defined in Cardano.Address.Style.Byron

Exception ErrInspectAddress # 
Instance details

Defined in Cardano.Address.Style.Byron

Generic ErrInspectAddress # 
Instance details

Defined in Cardano.Address.Style.Byron

Associated Types

type Rep ErrInspectAddress 
Instance details

Defined in Cardano.Address.Style.Byron

type Rep ErrInspectAddress = D1 ('MetaData "ErrInspectAddress" "Cardano.Address.Style.Byron" "cardano-addresses-4.0.2-inplace" 'False) (C1 ('MetaCons "MissingExpectedDerivationPath" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "DeserialiseError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 DeserialiseFailure)) :+: C1 ('MetaCons "FailedToDecryptPath" 'PrefixI 'False) (U1 :: Type -> Type)))
Show ErrInspectAddress # 
Instance details

Defined in Cardano.Address.Style.Byron

Eq ErrInspectAddress # 
Instance details

Defined in Cardano.Address.Style.Byron

type Rep ErrInspectAddress # 
Instance details

Defined in Cardano.Address.Style.Byron

type Rep ErrInspectAddress = D1 ('MetaData "ErrInspectAddress" "Cardano.Address.Style.Byron" "cardano-addresses-4.0.2-inplace" 'False) (C1 ('MetaCons "MissingExpectedDerivationPath" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "DeserialiseError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 DeserialiseFailure)) :+: C1 ('MetaCons "FailedToDecryptPath" 'PrefixI 'False) (U1 :: Type -> Type)))

Network Discrimination

byronMainnet :: NetworkDiscriminant Byron #

NetworkDiscriminant for Cardano MainNet & Byron

Since: 2.0.0

byronStaging :: NetworkDiscriminant Byron #

NetworkDiscriminant for Cardano Staging & Byron

Since: 2.0.0

byronTestnet :: NetworkDiscriminant Byron #

NetworkDiscriminant for Cardano Testnet & Byron

Since: 2.0.0

byronPreprod :: NetworkDiscriminant Byron #

NetworkDiscriminant for Cardano Preprod & Byron

Since: 3.13.0

byronPreview :: NetworkDiscriminant Byron #

NetworkDiscriminant for Cardano Preview & Byron

Since: 3.13.0

Unsafe

liftXPrv #

Arguments

:: forall (depth :: Depth). XPub

A root public key

-> DerivationPath depth 
-> XPrv 
-> Byron depth XPrv 

Deprecated: see Icarus

Backdoor for generating a new key from a raw XPrv.

Note that the depth is left open so that the caller gets to decide what type of key this is. This is mostly for testing, in practice, seeds are used to represent root keys, and one should genMasterKeyFromXPrv

The first argument is a type-family DerivationPath and its type depends on the depth of the key.

examples:

>>> liftXPrv rootPrv () prv
_ :: Byron RootK XPrv
>>> liftXPrv rootPrv minBound prv
_ :: Byron AccountK XPrv
>>> liftXPrv rootPrv (minBound, minBound) prv
_ :: Byron PaymentK XPrv

Since: 2.0.0

liftXPub #

Arguments

:: forall (depth :: Depth). XPub

A root public key

-> DerivationPath depth 
-> XPub 
-> Byron depth XPub 

Deprecated: see Icarus

Backdoor for generating a new key from a raw XPub.

Note that the depth is left open so that the caller gets to decide what type of key this is. This is mostly for testing, in practice, seeds are used to represent root keys, and one should genMasterKeyFromXPrv

see also liftXPrv

Since: 2.0.0