bip32-0.1: BIP-0032: Hierarchical Deterministic Wallets for Bitcoin and other cryptocurrencies

Safe HaskellNone
LanguageHaskell2010

BIP32

Contents

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

data Prv Source #

Private key.

Construct with prv.

Instances
Eq Prv Source # 
Instance details

Defined in BIP32.GHC

Methods

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

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

Show Prv Source # 
Instance details

Defined in BIP32.GHC

Methods

showsPrec :: Int -> Prv -> ShowS #

show :: Prv -> String #

showList :: [Prv] -> ShowS #

prv :: ByteString -> Maybe Prv Source #

Construct a Prv key from its raw bytes.

  • 32 bytes containing \(ser_{256}(k)\).

See Bitcoin's BIP-0032 for details.

Nothing if something is not satisfied.

unPrv :: Prv -> ByteString Source #

Obtain the 32 raw bytes inside a Prv. See prv.

prvToPub :: Prv -> Pub Source #

Obtain the Pub key for Prv.

Public key

data XPub Source #

Extended private key.

Instances
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 #

data Pub Source #

Public key.

Construct with pub.

Instances
Eq Pub Source # 
Instance details

Defined in BIP32.GHC

Methods

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

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

Show Pub Source # 
Instance details

Defined in BIP32.GHC

Methods

showsPrec :: Int -> Pub -> ShowS #

show :: Pub -> String #

showList :: [Pub] -> ShowS #

pub :: ByteString -> Maybe Pub Source #

Construct a Pub key from its raw bytes.

  • 33 bytes in total, containing \(ser_{P}(P)\).
  • The leftmost byte is either 0x02 or 0x03, depending on the parity of the omitted y coordinate.
  • The remaining 32 bytes are \(ser_{256}(x)\).

See Bitcoin's BIP-0032 for details.

Nothing if something is not satisfied.

unPub :: Pub -> ByteString Source #

Obtain the 33 raw bytes inside a Pub. See pub.

Corresponds to BIP-0032's \(ser_{P}(P)\).

Chain code

data Chain Source #

Chain code.

Construct with chain.

Instances
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 Word32 
Instances
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.

Subkeys

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

Derive a child XPub subkey from a parent a parent XPub key.

The given Index is expected to not be hardened.

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

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

Derive a child XPrv subkey from a parent a parent XPrv key.

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

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

Derive a child XPub subkey from a parent 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.

Bare

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

Derive a child Pub subkey and Chain code at a particular Index from a parent Pub and Chain code.

The given Index is expected to not be hardened.

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

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

Derive a child Prv subkey and Chain code at a particular Index from a parent Prv and Chain code.

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

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

Derive a child Pub subkey and Chain code at a particular Index from a parent Prv and Chain code.

Notice that while subPubPub (prvToPub prv) i will fail with a hardened Index, subPrvPub prv i may succeed.

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

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