-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add mnemonic sentence support #975
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but I want feedback from the rest of the team before we approve and merge.
@@ -52,6 +56,24 @@ data KeyNonExtendedKeyCmdArgs = KeyNonExtendedKeyCmdArgs | |||
} | |||
deriving Show | |||
|
|||
-- | Get a verification key from a mnemonic. This supports all extended key types. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
verification key?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch
} | ||
deriving Show | ||
|
||
data ExtendedSigningType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DerivedExtendedSigningKeyType
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment saying something like "This is the key derived from the mnemonic"
-- | Get a verification key from a mnemonic. This supports all extended key types. | ||
data KeyExtendedSigningKeyFromMnemonicArgs = KeyExtendedSigningKeyFromMnemonicArgs | ||
{ keyOutputFormat :: !KeyOutputFormat | ||
, extendedSigningKeyType :: !ExtendedSigningType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
derivedExtendedSigningKeyType
?
@@ -64,6 +64,7 @@ Usage: cardano-cli address info --address ADDRESS [--out-file FILEPATH] | |||
Usage: cardano-cli key | |||
( verification-key | |||
| non-extended-key | |||
| key-from-mnemonic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"signing-key-from-mnemonic"?
@@ -85,6 +86,21 @@ Usage: cardano-cli key non-extended-key --extended-verification-key-file FILEPAT | |||
Get a non-extended verification key from an extended verification key. This | |||
supports all extended key types. | |||
|
|||
Usage: cardano-cli key key-from-mnemonic [--key-output-format STRING] | |||
( --payment-key | |||
--payment-address-number WORD32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can collapse to a single parser in the case of those with indexes. I.e: --payment-key-address-number
instead of --payment-key
and --payment-address-number
. We can add information in the help text explaining what the address number is.
) | ||
) | ||
where | ||
parseSize :: String -> Maybe MnemonicSize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use ReadM
so you can fail
with an appropriate error message?
@@ -205,6 +207,19 @@ runNonExtendedKeyCmd | |||
writeLazyByteStringFile vkf' $ | |||
textEnvelopeToJSON descr vk | |||
|
|||
runGenerateMnemonicCmd :: Cmd.KeyGenerateMnemonicCmdArgs -> ExceptT KeyCmdError IO () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think when writing to file we should at least set restrictive permissions. Can you get in touch with the wallet team and ask them what precautions they took when generating mnemonics?
{ mnemonicOutputFormat | ||
, mnemonicWords | ||
} = do | ||
mnemonic <- firstExceptT KeyCmdMnemonicError $ generateMnemonic mnemonicWords |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An extra validation step where we confirm the correct number of words have been generated also can't hurt here.
return $ map T.pack $ words $ T.unpack fileText | ||
readMnemonic Cmd.MnemonicFromInteractivePrompt = | ||
liftIO $ do | ||
putStrLn "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unlines
would be a good refactor here
@@ -1,6 +1,8 @@ | |||
Usage: cardano-cli key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if we should have a new command root-key
that has these commands underneath. We need to make a clear distinction between the root key and the derived keys. Putting the commands under key
makes this distinction a little less clear IMO.
putStrLn "" | ||
putStrLn "Please enter your mnemonic sentence." | ||
putStrLn "" | ||
putStrLn " - It should consist of either: 12, 15, 18, 21, or 24 words." | ||
putStrLn " - To terminate, press enter on an empty line." | ||
putStrLn " - To abort you can press CTRL+C." | ||
putStrLn "" | ||
putStrLn "(If your terminal supports it, you can use the TAB key for word completion.)" | ||
putStrLn "" | ||
runInputTBehaviorWithPrefs defaultBehavior defaultPrefs settings (inputT ("", "") []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks cool. Can we support non-interactive senario with reading of mnemonic from stdin here? I imagine the following example, when someone stores their mnemonic in bitwarden, and tries to generate key using the following snippet:
bw list items --search 'cardano super secret mnemonic' \
| jq -r '.[0].login.password' \
| cardano-cli latest key key-from-mnemonic ... --signing-key-file key.json
@CarlosLopezDeLara thoughts? do you think this could be useful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would actually work with the interactive one as is, I made it with that in mind, and I tested it feeding the output file of the generate-mnemonic command. But it may be a good idea to make one that is explicitly for that, or adding a comment, because the user may not know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those new additions are quite large so I'd suggest adding a new module for them. For example:
cardano-cli/src/Cardano/CLI/Run/Key/Mnemonic.hs
--signing-key-file FILEPATH | ||
Output filepath of the signing key. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--signing-key-file FILEPATH | |
Output filepath of the signing key. | |
--out-signing-key-file FILEPATH | |
Output filepath of the signing key. |
I would suggest marking output file so it stands out. It took me a moment to find out the right flag which saves a file.
@@ -1,6 +1,8 @@ | |||
Usage: cardano-cli allegra key | |||
( verification-key | |||
| non-extended-key | |||
| generate-mnemonic | |||
| key-from-mnemonic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This command feels a little odd: cardano-cli latest key key-from-mnemonic
I think this key prefix seems redundant.
| key-from-mnemonic | |
| from-mnemonic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we can call it derive-from-mnemonic
Changelog
Context
This PR is associated to: IntersectMBO/cardano-api#678.
It is part of an effort to integrate
cardano-addresses
functionalities into thecardano-cli
.How to trust this PR
I would look mainly at the logic, the changes in the help golden files, and probably testing it is the best way.
Checklist