View on GitHub
File Changes
{-# LANGUAGE AllowAmbiguousTypes #-}
+
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
    , unsafeFromText
    , unsafeRunExceptT
    , unsafeXPrv
-
    , unsafeMkMnemonic
-
    , unsafeMkEntropy
-
    , unsafeMkSomeMnemonicFromEntropy
    , unsafeDeserialiseCbor
    , unsafeBech32DecodeFile
    , unsafeBech32Decode
+

                      
+
    , someDummyMnemonic
+
    , unsafeMkMnemonic
+
    , unsafeMkEntropy
+
    , unsafeMkSomeMnemonicFromEntropy
    ) where

                      
import Prelude
import Data.Char
    ( isHexDigit )
import Data.Proxy
-
    ( Proxy )
+
    ( Proxy (..) )
import Data.Text
    ( Text )
import Data.Text.Class
    ( FromText (..) )
import GHC.Stack
    ( HasCallStack )
+
import GHC.TypeLits
+
    ( natVal )

                      
import qualified Cardano.Crypto.Wallet as CC
import qualified Codec.Binary.Bech32 as Bech32
import qualified Codec.CBOR.Decoding as CBOR
import qualified Codec.CBOR.Read as CBOR
+
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as B8
import qualified Data.ByteString.Lazy as BL
import qualified Data.Text as T
    . entropyToMnemonic
    . unsafeMkEntropy @ent

                      
+
-- | A dummy @[email protected] for testing.
+
--
+
-- Could have been named @[email protected], but this way it sounds more like
+
-- valid english.
+
someDummyMnemonic
+
    :: forall mw ent csz.
+
        ( HasCallStack
+
        , ValidEntropySize ent
+
        , ValidChecksumSize ent csz
+
        , ValidMnemonicSentence mw
+
        , ent ~ EntropySize mw
+
        , mw ~ MnemonicWords ent
+
        )
+
    => Proxy mw
+
    -> SomeMnemonic
+
someDummyMnemonic proxy =
+
    let
+
        n = fromIntegral $ natVal (Proxy @ent) `div` 8
+
        entropy = BS.replicate n 0
+
    in
+
        unsafeMkSomeMnemonicFromEntropy proxy entropy
+

                      
-- | Load the data part of a bech32-encoded string from file. These files often
-- come from @[email protected] Only the first line of the file is read.
unsafeBech32DecodeFile :: HasCallStack => FilePath -> IO BL.ByteString
    , fromFlatSlot
    )
import Cardano.Wallet.Unsafe
-
    ( unsafeMkSomeMnemonicFromEntropy, unsafeRunExceptT )
+
    ( someDummyMnemonic, unsafeRunExceptT )
import Control.DeepSeq
    ( NFData (..), force )
import Control.Exception
ourAccount :: ShelleyKey 'AccountK XPub
ourAccount = publicKey $ unsafeGenerateKeyFromSeed (seed, Nothing) mempty
  where
-
    seed = unsafeMkSomeMnemonicFromEntropy (Proxy @15) (BS.replicate 32 0)
+
    seed = someDummyMnemonic (Proxy @15)

                      
rewardAccount :: ShelleyKey 'AddressK XPub
rewardAccount = publicKey $ unsafeGenerateKeyFromSeed (seed, Nothing) mempty
  where
-
    seed = unsafeMkSomeMnemonicFromEntropy (Proxy @15) (BS.replicate 32 0)
+
    seed = someDummyMnemonic (Proxy @15)

                      
-- | Make a prefixed bytestring for use as a Hash or Address.
label :: Show n => String -> n -> B8.ByteString
    , wholeRange
    )
import Cardano.Wallet.Unsafe
-
    ( unsafeMkSomeMnemonicFromEntropy )
+
    ( someDummyMnemonic )
import Control.Arrow
    ( second )
import Control.DeepSeq
arbitrarySeqAccount =
    publicKey $ unsafeGenerateKeyFromSeed (mw, Nothing) mempty
  where
-
    mw = unsafeMkSomeMnemonicFromEntropy (Proxy @15) (BS.replicate 32 0)
+
    mw = someDummyMnemonic (Proxy @15)

                      
arbitraryRewardAccount
    :: ShelleyKey 'AddressK XPub
arbitraryRewardAccount =
    publicKey $ unsafeGenerateKeyFromSeed (mw, Nothing) mempty
  where
-
    mw = unsafeMkSomeMnemonicFromEntropy (Proxy @15) (BS.replicate 32 0)
+
    mw = someDummyMnemonic (Proxy @15)

                      
{-------------------------------------------------------------------------------
                                 Random State
import Cardano.Wallet.Primitive.Types
    ( Address (..), ShowFmt (..) )
import Cardano.Wallet.Unsafe
-
    ( unsafeMkSomeMnemonicFromEntropy )
+
    ( someDummyMnemonic )
import Control.Monad
    ( forM, forM_, unless )
import Control.Monad.IO.Class

                      
import qualified Cardano.Wallet.Primitive.AddressDerivation.Icarus as Icarus
import qualified Cardano.Wallet.Primitive.AddressDerivation.Shelley as Shelley
-
import qualified Data.ByteString as BS

                      
spec :: Spec
spec = do
prop_genChangeGap g =
    property prop
  where
-
    mw = unsafeMkSomeMnemonicFromEntropy (Proxy @12) "0000000000000000"
+
    mw = someDummyMnemonic (Proxy @12)
    key = Shelley.unsafeGenerateKeyFromSeed (mw, Nothing) mempty
    s0 = mkSeqState (key, mempty) g
    prop =
prop_lookupDiscovered (s0, addr) =
    let (ours, s) = isOurs addr s0 in ours ==> prop s
  where
-
    mw = unsafeMkSomeMnemonicFromEntropy (Proxy @12) "0000000000000000"
+
    mw = someDummyMnemonic (Proxy @12)
    key = Shelley.unsafeGenerateKeyFromSeed (mw, Nothing) mempty
    prop s = monadicIO $ liftIO $ do
        unless (isJust $ isOwned s (key, mempty) addr) $ do
    ourAccount = publicKey $
        Icarus.unsafeGenerateKeyFromSeed mw mempty
      where
-
        mw = unsafeMkSomeMnemonicFromEntropy (Proxy @12)
-
                (BS.pack $ replicate 16 0)
+
        mw = someDummyMnemonic (Proxy @12)

                      
    ourAddresses _proxy cc =
        mkAddress . deriveAddressPublicKey ourAccount cc <$> [minBound..maxBound]
    ourAccount = publicKey $
        Shelley.unsafeGenerateKeyFromSeed (mw, Nothing) mempty
      where
-
        mw = unsafeMkSomeMnemonicFromEntropy (Proxy @15)
-
                (BS.pack $ replicate 32 0)
+
        mw = someDummyMnemonic (Proxy @15)

                      
    ourAddresses _proxy cc =
        mkAddress . deriveAddressPublicKey ourAccount cc <$> [minBound..maxBound]
rewardAccount = publicKey $
    Shelley.unsafeGenerateKeyFromSeed (mw, Nothing) mempty
  where
-
    mw = unsafeMkSomeMnemonicFromEntropy (Proxy @15) (BS.pack $ replicate 32 0)
+
    mw = someDummyMnemonic (Proxy @15)

                      
changeAddresses
    :: [Address]
    , wholeRange
    )
import Cardano.Wallet.Unsafe
-
    ( unsafeFromHex, unsafeMkSomeMnemonicFromEntropy )
+
    ( someDummyMnemonic, unsafeFromHex )
import Control.DeepSeq
    ( deepseq )
import Control.Exception

                      
    describe "Buildable" $ do
        it "WalletId" $ do
-
            let mw = unsafeMkSomeMnemonicFromEntropy (Proxy @12)
-
                    "0000000000000000"
+
            let mw = someDummyMnemonic (Proxy @12)
            let xprv = generateKeyFromSeed
                    (mw, Nothing) mempty :: ShelleyKey 'RootK XPrv
            let wid = WalletId $ digest $ publicKey xprv