bip32

Pure Haskell BIP32 hierarchical deterministic wallets.
git clone git://git.ppad.tech/bip32.git
Log | Files | Refs | LICENSE

commit 1034b9f27ba6a80a971925bb8a7880c7e579e51d
parent a787932e2836752bb2e12baaffd7ef79ddb19b37
Author: Jared Tobin <jared@jtobin.io>
Date:   Fri, 21 Feb 2025 10:04:11 +0400

lib: basic derivation path expression

Diffstat:
Mlib/Crypto/HDKey/BIP32.hs | 19+++++++++++++++++++
1 file changed, 19 insertions(+), 0 deletions(-)

diff --git a/lib/Crypto/HDKey/BIP32.hs b/lib/Crypto/HDKey/BIP32.hs @@ -186,6 +186,25 @@ derive_pub HDKey {..} i = do child = ser32 i pure $ HDKey (Left key) depth (Just parent) child +-- derivation path expression ------------------------------------------------- + +data Path = + M + | !Path :| !Word32 -- hardened + | !Path :/ !Word32 + deriving (Eq, Show) + +derive :: HDKey -> Path -> Maybe HDKey +derive hd = go where + go = \case + M -> pure hd + pat :| i -> do + hdkey <- go pat + derive_priv hdkey (0x8000_0000 + i) -- 2 ^ 31 + pat :/ i -> do + hdkey <- go pat + derive_priv hdkey i + -- serialization -------------------------------------------------------------- xpub :: HDKey -> BS.ByteString