commit 1012b91e5537dff1f00b59ae2759b177f8a2ae31
parent 2ce742c04d9c794f6fb0dda3b631f3df4905201c
Author: Jared Tobin <jared@jtobin.io>
Date: Fri, 20 Jun 2025 16:46:51 +0400
lib: add utility read functions
Diffstat:
1 file changed, 20 insertions(+), 0 deletions(-)
diff --git a/lib/Crypto/HDKey/BIP32.hs b/lib/Crypto/HDKey/BIP32.hs
@@ -26,7 +26,11 @@ module Crypto.HDKey.BIP32 (
-- * Extended keys
, Extended(..)
, XPub
+ , xpub_key
+ , xpub_cod
, XPrv
+ , xprv_key
+ , xprv_cod
, X
, ckd_pub
, ckd_priv
@@ -110,10 +114,26 @@ ser32 w =
newtype XPub = XPub (X Secp256k1.Projective)
deriving (Eq, Show, Generic)
+-- | Read the raw public key from an 'XPub'.
+xpub_key :: XPub -> Secp256k1.Projective
+xpub_key (XPub (X pub _)) = pub
+
+-- | Read the raw chain code from an 'XPub'.
+xpub_cod :: XPub -> BS.ByteString
+xpub_cod (XPub (X _ cod)) = cod
+
-- | An extended private key.
newtype XPrv = XPrv (X Integer)
deriving (Eq, Show, Generic)
+-- | Read the raw private key from an 'XPrv'.
+xprv_key :: XPrv -> Integer
+xprv_key (XPrv (X sec _)) = sec
+
+-- | Read the raw chain code from an 'XPrv'.
+xprv_cod :: XPrv -> BS.ByteString
+xprv_cod (XPrv (X _ cod)) = cod
+
-- | A public or private key, extended with a chain code.
data X a = X !a !BS.ByteString
deriving (Eq, Show, Generic)