packages feed

slip32 0.2 → 0.2.1

raw patch · 4 files changed

+43/−25 lines, 4 filesdep +bitcoin-keysdep ~bip32

Dependencies added: bitcoin-keys

Dependency ranges changed: bip32

Files

CHANGELOG.md view
@@ -1,3 +1,10 @@+# Version 0.2.1++* Now compatible with `bip32-0.2`.++* Depend on the `bitcoin-keys` library.++ # Version 0.2  * COMPILER ASSISTED BREAKING CHANGE — Not exported anymore: `Pub`, `pub`,
lib/SLIP32.hs view
@@ -10,7 +10,11 @@ -- -- Please refer to the "BIP32" module from -- the [bip32 library](https://hackage.haskell.org/package/bip32) to--- find more about 'A.Pub', 'A.Prv', 'A.Index', 'A.Chain', etc.+-- find more about 'A.Index' and 'A.Chain'.+--+-- Please refer to the "Bitcoin.Keys" module from+-- the [bitcoin-keys library](https://hackage.haskell.org/package/bitcoin-keys) to+-- find more about 'K.Pub' and 'K.Prv'. module SLIP32   ( -- * Parsing     parse@@ -41,6 +45,7 @@   , unPath   ) where +import qualified Bitcoin.Keys as K import qualified BIP32 as A import Control.Applicative import Control.Monad@@ -56,11 +61,11 @@ --------------------------------------------------------------------------------  -- | Extended public key.-data XPub = XPub !Path !A.Chain !A.Pub+data XPub = XPub !Path !A.Chain !K.Pub   deriving (Eq, Show)  -- | Extended private key.-data XPrv = XPrv !Path !A.Chain !A.Prv+data XPrv = XPrv !Path !A.Chain !K.Prv   deriving (Eq, Show)  -- | Derivation path.@@ -167,20 +172,20 @@      Just b -> pure b      Nothing -> fail "Bad chain code" -getPrv :: Bin.Get A.Prv+getPrv :: Bin.Get K.Prv {-# INLINE getPrv #-} getPrv = do   0 <- Bin.getWord8   a <- Bin.getByteString 32-  case A.prv a of+  case K.parsePrv a of     Just b -> pure b     Nothing -> fail "Bad private key" -getPub :: Bin.Get A.Pub+getPub :: Bin.Get K.Pub {-# INLINE getPub #-} getPub = do   a <- Bin.getByteString 33-  case A.pub a of+  case K.parsePub a of     Just b -> pure b     Nothing -> fail "Bad public key" @@ -214,16 +219,16 @@  -------------------------------------------------------------------------------- --- | The 33-byte serialized contents of either 'A.Pub' or 'A.Prv'.+-- | The 33-byte serialized contents of either 'K.Pub' or 'K.Prv'. newtype Key = Key B.ByteString -keyPub :: A.Pub -> Key+keyPub :: K.Pub -> Key {-# INLINE keyPub #-}-keyPub = Key . A.unPub+keyPub = Key . K.pubCompressed -keyPrv :: A.Prv -> Key+keyPrv :: K.Prv -> Key {-# INLINE keyPrv #-}-keyPrv = Key . B.cons 0 . A.unPrv+keyPrv = Key . B.cons 0 . K.prvRaw  -------------------------------------------------------------------------------- 
slip32.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: slip32-version: 0.2+version: 0.2.1 license: Apache-2.0 license-file: LICENSE extra-source-files: README.md CHANGELOG.md@@ -19,7 +19,12 @@   default-language: Haskell2010   ghc-options: -O2 -Wall -Werror=incomplete-patterns   ghcjs-options: -O3 -Wall -Werror=incomplete-patterns-  build-depends: base == 4.*, bip32, bytestring, text+  build-depends:+    base == 4.*,+    bip32 >= 0.2,+    bitcoin-keys,+    bytestring,+    text  library   import: basic
test/Main.hs view
@@ -3,6 +3,8 @@  module Main (main) where +import qualified Bitcoin.Keys as K+import qualified BIP32 as A import qualified Data.ByteString as B import qualified Data.ByteString.Base16 as B16 import qualified Data.Text.Encoding as T@@ -16,7 +18,6 @@ import qualified Hedgehog.Gen as Gen import qualified Hedgehog.Range as Range -import qualified  BIP32 as A import qualified SLIP32 as S  --------------------------------------------------------------------------------@@ -189,20 +190,20 @@    , testCase "prv" $ do       Just (tv_prv x)-        @=? fmap (toBase16 . A.unPrv)-                 (A.prv (fromBase16 (tv_prv x)))+        @=? fmap (toBase16 . K.prvRaw)+                 (K.parsePrv (fromBase16 (tv_prv x)))    , testCase "pub" $ do       Just (tv_pub x)-        @=? fmap (toBase16 . A.unPub)-                 (A.pub (fromBase16 (tv_pub x)))+        @=? fmap (toBase16 . K.pubCompressed)+                 (K.parsePub (fromBase16 (tv_pub x)))    , testCase "xprv" $ do       Just xprv@(S.XPrv p c k) <- pure $ S.parseXPrv (tv_xprv x)       S.parse (tv_xprv x) @?= Just (Right xprv)       S.unPath p @?= tv_pathI x       toBase16 (A.unChain c) @?= tv_chain x-      toBase16 (A.unPrv k) @?= tv_prv x+      toBase16 (K.prvRaw k) @?= tv_prv x       S.renderXPrv xprv @?= tv_xprv x    , testCase "xpub" $ do@@ -210,7 +211,7 @@       S.parse (tv_xpub x) @?= Just (Left xpub)       S.unPath p @?= tv_pathI x       toBase16 (A.unChain c) @?= tv_chain x-      toBase16 (A.unPub k) @?= tv_pub x+      toBase16 (K.pubCompressed k) @?= tv_pub x       S.renderXPub xpub @?= tv_xpub x   ] @@ -232,19 +233,19 @@   let Just c = A.chain b   pure c -genPrv :: MonadGen m => m A.Prv+genPrv :: MonadGen m => m K.Prv genPrv = do   b <- Gen.bytes (Range.singleton 32)-  let Just k = A.prv b+  let Just k = K.parsePrv b   pure k -genPub :: MonadGen m => m A.Pub+genPub :: MonadGen m => m K.Pub genPub = go 10000 where   go 0 = error "genPub: too many attempts"   go n = do     h <- Gen.element [2, 3 :: Word8]     b <- Gen.bytes (Range.singleton 32)-    case A.pub (B.cons h b) of+    case K.parsePub (B.cons h b) of       Just k -> pure k       Nothing -> go (n - 1)