bip32-0.2: BIP-0032: Hierarchical Deterministic Wallets for Bitcoin and other cryptocurrencies
Safe HaskellNone
LanguageHaskell2010

BIP32

Description

BIP-0032 Hierarchical Deterministic Wallets, for bitcoin and other cryptocurrencies.

Synopsis

Base58 serialization

encodeXPrv :: XPrv -> ByteString Source #

Obtain the Base58 representation for an XPrv.

It can be either 111 or 112 bytes in length, and when rendered as ASCII it looks something like this:

xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi

encodeXPub :: XPub -> ByteString Source #

Obtain the Base58 representation for an XPub.

It can be either 111 or 112 bytes in length, and when rendered as ASCII it looks something like this:

xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8

decodeXPrv :: ByteString -> Maybe XPrv Source #

Decode the Base58-encoded XPrv representation. See encodeXPrv.

decodeXPub :: ByteString -> Maybe XPub Source #

Decode the Base58-encoded XPub representation. See encodeXPub.

decode :: ByteString -> Maybe (Either XPub XPrv) Source #

Decode the Base58-encoded representation of either and XPub or an XPub.

Raw serialization

encodeXPrvRaw :: XPrv -> ByteString Source #

Encode the 78 raw XPrv bytes.

encodeXPubRaw :: XPub -> ByteString Source #

Encode the 78 raw XPub bytes.

decodeXPrvRaw :: ByteString -> Maybe XPrv Source #

Decode the 78 raw XPrv bytes.

decodeXPubRaw :: ByteString -> Maybe XPub Source #

Decode the 78 raw XPub bytes.

decodeRaw :: ByteString -> Maybe (Either XPub XPrv) Source #

Encode the 78 raw XPub or XPrv bytes.

Private key

data XPrv Source #

Extended private key.

Instances

Instances details
Eq XPrv Source # 
Instance details

Defined in BIP32

Methods

(==) :: XPrv -> XPrv -> Bool #

(/=) :: XPrv -> XPrv -> Bool #

Show XPrv Source # 
Instance details

Defined in BIP32

Methods

showsPrec :: Int -> XPrv -> ShowS #

show :: XPrv -> String #

showList :: [XPrv] -> ShowS #

xprvToXPub :: Version -> XPrv -> XPub Source #

Obtain the XPub corresponding to a particular XPrv, at a particular Version.

Single private subkey

subXPrvXPrv :: XPrv -> Index -> Maybe XPrv Source #

Derive a XPrv subkey from a parent XPrv key.

Returns Nothing if the given inputs result in an invalid key.

subPrvPrv :: Chain -> Prv -> Index -> Maybe (Chain, Prv) Source #

Behaves exactly like subXPrvXPrv, but deals with Chain and Prv, rather than an XPrv.

Multiple private subkeys

subsXPrvXPrv :: XPrv -> Index -> [XPrv] Source #

Lazily derive all the child XPrv subkeys from a parent's XPrv.

The first child returned is the one at the given Index, if any, and the subsequent childs are those immediately after it (see indexNext).

The returned Indexes are not necessarily consecutive, since not all XPrv and Index combinations are able to derive valid keys. However, the produced Indexes do increase monotonically.

If the given Index is hardened, then all produced children will have hardened Indexes too. If the given Index is normal, then all children will have normal Indexes too. That is, this function will never produce children with Indexes belonging to another group (normal vs. hardened).

subsPrvPrv :: Chain -> Prv -> Index -> [(Index, Chain, Prv)] Source #

Behaves exactly like subsXPrvXPrv, but deals with Chain and Prv, rather than an XPrv.

Single public subkey

subXPrvXPub :: Version -> XPrv -> Index -> Maybe XPub Source #

Derive XPub subkey from a parent XPrv key.

Notice that while subXPubXPub (xprvToXPub v) xprv i will fail with a hardened Index, subXPrvXPub v xprv i may succeed.

Returns Nothing if the given inputs result in an invalid key.

subPrvPub :: Chain -> Prv -> Index -> Maybe (Chain, Pub) Source #

Behaves exactly like subXPrvXPub, but deals with Chain, Prv and Pub, rather than an XPrv and XPub.

Multiple public subkeys

subsXPrvXPub :: Version -> XPrv -> Index -> [XPub] Source #

Lazily derive all the XPub subkeys from a parent XPrv key.

The first child returned is the one at the given Index, if any, and the subsequent childs are those immediately after it (see indexNext).

The returned Indexes are not necessarily consecutive, since not all XPrv and Index combinations are able to derive valid keys. However, the produced Indexes do increase monotonically.

If the given Index is hardened, then all produced children will have hardened Indexes too. If the given Index is normal, then all children will have normal Indexes too. That is, this function will never produce children with Indexes belonging to another group (normal vs. hardened).

Notice that while subsXPubXPub (xprvToXPub v) xprv i will fail with a hardened Index, subsXPrvXPub v xprv i may succeed.

subsPrvPub :: Chain -> Prv -> Index -> [(Index, Chain, Pub)] Source #

Behaves exactly like subsXPrvXPub, but deals with Chain, Prv and Pub, rather than an XPrv and XPub.

Public key

data XPub Source #

Extended private key.

Instances

Instances details
Eq XPub Source # 
Instance details

Defined in BIP32

Methods

(==) :: XPub -> XPub -> Bool #

(/=) :: XPub -> XPub -> Bool #

Show XPub Source # 
Instance details

Defined in BIP32

Methods

showsPrec :: Int -> XPub -> ShowS #

show :: XPub -> String #

showList :: [XPub] -> ShowS #

Single public subkey

subXPubXPub :: XPub -> Index -> Maybe XPub Source #

Derive a XPub subkey from a parent XPub key.

The given Index is expected to not be hardened.

Returns Nothing if the given inputs result in an invalid key.

subPubPub :: Chain -> Pub -> Index -> Maybe (Chain, Pub) Source #

Behaves exactly like subXPubXPub, but deals with Chain and Pub, rather than an XPub.

Multiple public subkeys

subsXPubXPub :: XPub -> Index -> [XPub] Source #

Lazily derive all the XPub subkeys from a parent's XPub.

The first child returned is the one at the given Index, if any, and the subsequent childs are those immediately after it (see indexNext).

The returned Indexes are not necessarily consecutive, since not all XPub and Index combinations are able to derive valid keys. However, the produced Indexes do increase monotonically.

The produced list will never include a hardened Index. If a hardened Index is provided as input, the produced list will be empty.

subsPubPub :: Chain -> Pub -> Index -> [(Index, Chain, Pub)] Source #

Behaves exactly like subsXPubXPub, but deals with Chain and Pub, rather than an XPub.

Chain code

data Chain Source #

Chain code.

Construct with chain.

Instances

Instances details
Eq Chain Source # 
Instance details

Defined in BIP32

Methods

(==) :: Chain -> Chain -> Bool #

(/=) :: Chain -> Chain -> Bool #

Show Chain Source # 
Instance details

Defined in BIP32

Methods

showsPrec :: Int -> Chain -> ShowS #

show :: Chain -> String #

showList :: [Chain] -> ShowS #

chain :: ByteString -> Maybe Chain Source #

Construct a Chain code.

See Bitcoin's BIP-0032 for details.

Nothing if the ByteString length is not 32.

unChain :: Chain -> ByteString Source #

Obtain the 32 raw bytes inside a Chain.

Derivation path

newtype Index Source #

A derivation path Index.

Constructors

Index 

Fields

Instances

Instances details
Eq Index Source # 
Instance details

Defined in BIP32

Methods

(==) :: Index -> Index -> Bool #

(/=) :: Index -> Index -> Bool #

Ord Index Source # 
Instance details

Defined in BIP32

Methods

compare :: Index -> Index -> Ordering #

(<) :: Index -> Index -> Bool #

(<=) :: Index -> Index -> Bool #

(>) :: Index -> Index -> Bool #

(>=) :: Index -> Index -> Bool #

max :: Index -> Index -> Index #

min :: Index -> Index -> Index #

Show Index Source # 
Instance details

Defined in BIP32

Methods

showsPrec :: Int -> Index -> ShowS #

show :: Index -> String #

showList :: [Index] -> ShowS #

indexIsHardened :: Index -> Bool Source #

Whether a derivation path Index is hardened. That is, \(2^{31}\) or larger.

indexNext :: Index -> Maybe Index Source #

Increment the given Index by one, but only if doing so would result in a new Index in the same index group (normal vs. hardened). Otherwise, returns Nothing.

Depth

newtype Depth Source #

Derivation path depth.

  • 0 for master nodes — m
  • 1 for level-1 derived keys — m/0', or m/13, or …
  • 2 for level-2 derived keys — m/0'/28, or m/44'/0', or …
  • … up to 255.

Constructors

Depth 

Fields

Instances

Instances details
Eq Depth Source # 
Instance details

Defined in BIP32

Methods

(==) :: Depth -> Depth -> Bool #

(/=) :: Depth -> Depth -> Bool #

Show Depth Source # 
Instance details

Defined in BIP32

Methods

showsPrec :: Int -> Depth -> ShowS #

show :: Depth -> String #

showList :: [Depth] -> ShowS #

Fingerprint

newtype Fingerprint Source #

4-byte fingerprint of a Pub key.

Constructors

Fingerprint 

Instances

Instances details
Eq Fingerprint Source # 
Instance details

Defined in BIP32

Show Fingerprint Source # 
Instance details

Defined in BIP32

Version

newtype Version Source #

Version bytes.

Constructors

Version 

Fields

Instances

Instances details
Eq Version Source # 
Instance details

Defined in BIP32

Methods

(==) :: Version -> Version -> Bool #

(/=) :: Version -> Version -> Bool #

Show Version Source # 
Instance details

Defined in BIP32

Example versions

version_xprv :: Version Source #

0x0488ade4, “xprv”, Bitcoin mainnet private.

version_xpub :: Version Source #

0x0488b21e, “xpub”, Bitcoin mainnet public.

version_tprv :: Version Source #

0x04358394, “tprv”, Bitcoin testnet private.

version_tpub :: Version Source #

0x043587cf, “tpub”, Bitcoin testnet public.

version_Ltpv :: Version Source #

0x019d9cfe, “Ltpv”, Litecoin mainnet private.

version_Ltub :: Version Source #

0x019da462, “Ltub”, Litecoin mainnet public.

version_ttpv :: Version Source #

0x0436ef7d, “ttpv”, Litecoin testnet private.

version_ttub :: Version Source #

0x0436f6e1, “ttub”, Litecoin testnet public.