never executed always true always false
1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE LambdaCase #-}
3
4 {-# OPTIONS_HADDOCK hide #-}
5
6 module Command.Key
7 ( Cmd (..)
8 , mod
9 , run
10 ) where
11
12 import Prelude hiding
13 ( mod )
14
15 import Options.Applicative
16 ( CommandFields
17 , Mod
18 , command
19 , footerDoc
20 , helper
21 , info
22 , progDesc
23 , subparser
24 )
25 import Options.Applicative.Help.Pretty
26 ( bold, indent, string, vsep )
27 import System.IO.Extra
28 ( progName )
29
30 import qualified Command.Key.Child as Child
31 import qualified Command.Key.FromRecoveryPhrase as FromRecoveryPhrase
32 import qualified Command.Key.Hash as Hash
33 import qualified Command.Key.Inspect as Inspect
34 import qualified Command.Key.Public as Public
35 import qualified Command.Key.WalletId as WalletId
36
37 data Cmd
38 = FromRecoveryPhrase FromRecoveryPhrase.Cmd
39 | Child Child.Cmd
40 | Public Public.Cmd
41 | Inspect Inspect.Cmd
42 | Hash Hash.Cmd
43 | WalletId WalletId.Cmd
44 deriving (Show)
45
46 mod :: (Cmd -> parent) -> Mod CommandFields parent
47 mod liftCmd = command "key" $
48 info (helper <*> fmap liftCmd parser) $ mempty
49 <> progDesc "About public/private keys"
50 <> footerDoc (Just $ vsep
51 [ string "Example:"
52 , indent 2 $ bold $ string $ "$ "<>progName<>" recovery-phrase generate --size 15 \\"
53 , indent 4 $ bold $ string $ "| "<>progName<>" key from-recovery-phrase Shelley > root.prv"
54 , indent 2 $ string ""
55 , indent 2 $ bold $ string "$ cat root.prv \\"
56 , indent 4 $ bold $ string $ "| "<>progName<>" key child 1852H/1815H/0H \\"
57 , indent 4 $ bold $ string "| tee acct.prv \\"
58 , indent 4 $ bold $ string $ "| "<>progName<>" key public --with-chain-code > acct.pub"
59 , indent 2 $ string ""
60 , indent 2 $ bold $ string $ "$ "<>progName<>" key inspect <<< $(cat acct.prv)"
61 , indent 2 $ string "{"
62 , indent 2 $ string " \"key_type\": \"private\","
63 , indent 2 $ string " \"chain_code\": \"67bef6f80df02c7452e20e76ffb4bb57cae8aac2adf042b21a6b19e4f7b1f511\","
64 , indent 2 $ string " \"extended_key\": \"90ead3efad7aacac242705ede323665387f49ed847bed025eb333708ccf6aa54403482a867daeb18f38c57d6cddd7e6fd6aed4a3209f7425a3d1c5d9987a9c5f\""
65 , indent 2 $ string "}"
66 , indent 2 $ string ""
67 , indent 2 $ bold $ string $ "$ "<>progName<>" key inspect <<< $(cat acct.pub)"
68 , indent 2 $ string "{"
69 , indent 2 $ string " \"key_type\": \"public\","
70 , indent 2 $ string " \"chain_code\": \"67bef6f80df02c7452e20e76ffb4bb57cae8aac2adf042b21a6b19e4f7b1f511\","
71 , indent 2 $ string " \"extended_key\": \"d306350ee88f51fb710252e27f0c40006c58e994761b383e02d400e2be59b3cc\""
72 , indent 2 $ string "}"
73 ])
74 where
75 parser = subparser $ mconcat
76 [ FromRecoveryPhrase.mod FromRecoveryPhrase
77 , Child.mod Child
78 , Public.mod Public
79 , Inspect.mod Inspect
80 , Hash.mod Hash
81 , WalletId.mod WalletId
82 ]
83
84 run :: Cmd -> IO ()
85 run = \case
86 FromRecoveryPhrase sub -> FromRecoveryPhrase.run sub
87 Child sub -> Child.run sub
88 Public sub -> Public.run sub
89 Inspect sub -> Inspect.run sub
90 Hash sub -> Hash.run sub
91 WalletId sub -> WalletId.run sub