@@ -12,21 +12,27 @@ import Data.Aeson
12
12
import Data.Aeson qualified as Aeson
13
13
import Data.ByteString.Lazy qualified as BL
14
14
import Data.Text (Text )
15
+ import Data.Text qualified as T
15
16
import OptEnvConf
16
17
( Alternative ((<|>) )
17
- , Builder
18
18
, Parser
19
+ , checkEither
19
20
, checkMapIO
20
21
, conf
21
22
, env
22
23
, help
24
+ , long
23
25
, mapIO
24
26
, metavar
27
+ , option
25
28
, reader
26
29
, setting
30
+ , short
27
31
, str
32
+ , switch
28
33
, withConfig
29
34
)
35
+ import System.Console.Haskeline
30
36
31
37
mnemonicsClearTextOption :: Parser Text
32
38
mnemonicsClearTextOption =
@@ -43,33 +49,48 @@ mnemonicsEncryptedOption =
43
49
, conf " encryptedMnemonics"
44
50
, metavar " ENCRYPTED_MNEMONICS"
45
51
]
46
- walletPassphraseCommon :: [Builder a ]
52
+
53
+ walletPassphraseCommon :: Parser Text
47
54
walletPassphraseCommon =
48
- [ env " ANTI_WALLET_PASSPHRASE"
49
- , metavar " PASSPHRASE"
50
- , help " The passphrase for the encrypted mnemonics"
51
- ]
52
- walletPassphraseOption
53
- :: Parser (Text -> IO Text )
54
- walletPassphraseOption =
55
- fmap decryptText
55
+ mapIO id
56
56
$ setting
57
- $ reader str : walletPassphraseCommon
57
+ [ help " Prompt for the passphrase for the encrypted mnemonics"
58
+ , long " interactive-wallet-passphrase"
59
+ , switch $ queryConsole " Enter passphrase for encrypted mnemonics"
60
+ ]
61
+ <|> setting
62
+ [ env " ANTI_WALLET_PASSPHRASE"
63
+ , metavar " PASSPHRASE"
64
+ , help " The passphrase for the encrypted mnemonics"
65
+ , reader $ fmap (pure . T. pack) str
66
+ ]
67
+
68
+ queryConsole :: String -> IO Text
69
+ queryConsole prompt = runInputT defaultSettings $ do
70
+ pw <- getPassword (Just ' *' ) (prompt <> " : " )
71
+ case pw of
72
+ Nothing -> pure " "
73
+ Just pw' -> pure $ T. pack pw'
58
74
59
75
walletFileOption :: Parser FilePath
60
76
walletFileOption =
61
77
setting
62
78
[ env " ANTI_WALLET_FILE"
63
79
, metavar " FILEPATH"
64
- , help " The file path to the wallet secrets mnemonics"
80
+ , help " The file path to the wallet secret mnemonics"
81
+ , long " wallet"
82
+ , short ' w'
65
83
, reader str
84
+ , option
66
85
]
67
86
68
87
coreMnemonicsParser :: Parser (Mnemonics 'DecryptedS)
69
88
coreMnemonicsParser =
70
89
fmap ClearText
71
90
$ mnemonicsClearTextOption
72
- <|> mapIO id (walletPassphraseOption <*> mnemonicsEncryptedOption)
91
+ <|> checkEither
92
+ id
93
+ (decryptText <$> walletPassphraseCommon <*> mnemonicsEncryptedOption)
73
94
74
95
mnemonicsObject :: Parser Object
75
96
mnemonicsObject =
0 commit comments