| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
BIP32
Description
BIP-0032 Hierarchical Deterministic Wallets, for bitcoin and other cryptocurrencies.
Synopsis
- encodeXPrv :: XPrv -> ByteString
- encodeXPub :: XPub -> ByteString
- decodeXPrv :: ByteString -> Maybe XPrv
- decodeXPub :: ByteString -> Maybe XPub
- decode :: ByteString -> Maybe (Either XPub XPrv)
- encodeXPrvRaw :: XPrv -> ByteString
- encodeXPubRaw :: XPub -> ByteString
- decodeXPrvRaw :: ByteString -> Maybe XPrv
- decodeXPubRaw :: ByteString -> Maybe XPub
- decodeRaw :: ByteString -> Maybe (Either XPub XPrv)
- data XPrv = XPrv {}
- xprvToXPub :: Version -> XPrv -> XPub
- subXPrvXPrv :: XPrv -> Index -> Maybe XPrv
- subPrvPrv :: Chain -> Prv -> Index -> Maybe (Chain, Prv)
- subsXPrvXPrv :: XPrv -> Index -> [XPrv]
- subsPrvPrv :: Chain -> Prv -> Index -> [(Index, Chain, Prv)]
- subXPrvXPub :: Version -> XPrv -> Index -> Maybe XPub
- subPrvPub :: Chain -> Prv -> Index -> Maybe (Chain, Pub)
- subsXPrvXPub :: Version -> XPrv -> Index -> [XPub]
- subsPrvPub :: Chain -> Prv -> Index -> [(Index, Chain, Pub)]
- data XPub = XPub {}
- subXPubXPub :: XPub -> Index -> Maybe XPub
- subPubPub :: Chain -> Pub -> Index -> Maybe (Chain, Pub)
- subsXPubXPub :: XPub -> Index -> [XPub]
- subsPubPub :: Chain -> Pub -> Index -> [(Index, Chain, Pub)]
- data Chain
- chain :: ByteString -> Maybe Chain
- unChain :: Chain -> ByteString
- newtype Index = Index {}
- indexIsHardened :: Index -> Bool
- indexNext :: Index -> Maybe Index
- newtype Depth = Depth {}
- newtype Fingerprint = Fingerprint {}
- fingerprint :: Pub -> Fingerprint
- newtype Version = Version {}
- version_xprv :: Version
- version_xpub :: Version
- version_tprv :: Version
- version_tpub :: Version
- version_Ltpv :: Version
- version_Ltub :: Version
- version_ttpv :: Version
- version_ttub :: Version
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.
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.
Private key
Extended private key.
Constructors
| XPrv | |
Fields
| |
Single private subkey
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 will fail with a
hardened subXPubXPub (xprvToXPub v) xprv iIndex, may succeed.subXPrvXPub v xprv i
Returns Nothing if the given inputs result in an invalid key.
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 will fail with a
hardened subsXPubXPub (xprvToXPub v) xprv iIndex, may succeed.subsXPrvXPub v xprv i
Public key
Extended private key.
Constructors
| XPub | |
Fields
| |
Single public subkey
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
Chain code.
Construct with chain.
chain :: ByteString -> Maybe Chain Source #
Construct a Chain code.
See Bitcoin's BIP-0032 for details.
Nothing if the ByteString length is not 32.
Derivation path
indexIsHardened :: Index -> Bool Source #
Whether a derivation path Index is hardened. That is, \(2^{31}\) or
larger.
Depth
Derivation path depth.
0for master nodes —m1for level-1 derived keys —m/0', orm/13, or …2for level-2 derived keys —m/0'/28, orm/44'/0', or …- … up to
255.
Fingerprint
newtype Fingerprint Source #
4-byte fingerprint of a Pub key.
Constructors
| Fingerprint | |
Fields | |
Instances
| Eq Fingerprint Source # | |
Defined in BIP32 | |
| Show Fingerprint Source # | |
Defined in BIP32 Methods showsPrec :: Int -> Fingerprint -> ShowS # show :: Fingerprint -> String # showList :: [Fingerprint] -> ShowS # | |
fingerprint :: Pub -> Fingerprint Source #
Version
Version bytes.
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.