Generating mnemonic phrase through CLI

It seems like I can generate a wallet using the Cardano SL API by feeding an existing 12 word mnemonic string to it and using this module: https://cardanodocs.com/technical/wallet/api/#/default/post_api_wallets_new

If you use the Daedalus GUI, it generates a 12 word mnemonic for you.

Is there a way to generate the mnemonic through the Cardano SL without using a GUI? Or do I need to build my own function outside of the official tools which will generate a 12 word mnemonic that works with Cardano?

As far as I can tell, the “–backup-phrase PHRASE” option is just for implementing an already existing mnemonic.

1 Like

Yes. There is a static mnemonic’s set https://github.com/input-output-hk/cardano-sl/blob/develop/wallet/src/Pos/Util/Mnemonics.hs#L142-L485

2 Likes

Awesome! Thank you!

So, I should be able to write a function that randomly chooses 12 of these words to create wallet phrase strings, right?

I think so.

I just came across this:
https://cardanodocs.com/technical/wallet/api/v1/#section/Mnemonic-Codes

It states, “Note that picking up 12 random words from the list is not enough and leads to poor security”. So, I guess this is not advised? Although I’m a little confused as to why the list even exists in that case.

It’s not recommended at all. You need proper randomness to protect your wallet. Choosing 12 words by yourself is not a proper one.

1 Like

So, the preferred method is to use a larger dictionary then?

What do you mean by “larger dictionary”? There are exactly 2048 words that may be used as a mnemonic, as can be seen in this list: https://github.com/bitcoin/bips/blob/master/bip-0039/english.txt

Furthermore - not all word combinations may be used as a wallet. There’s a special property of the checksum that must be held. Only about 1 in each 256 combinations may be used as a valid wallet.

BIP39 mnemonics are secondary and are obtained from generated randomness as explained in this document: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki

So just trying to select 12 words from the list might work, but not a proper way to create wallets. Proper algorithm looks somewhat like this:

  1. Generate 128 bits of randomness
  2. Calculate checksum of the resulting bytestring
  3. Take first 4 bits of the checksum and append them to the original randomness
  4. That will give you the bytestring of 132 bits
  5. Split 132 bits into 12 groups of 11 bits
  6. Convert each 11-bit word to a decimal number
  7. That will give you 12 numbers between 0 and 2047
  8. Use standard list or words to select 12 mnemonic words for each number (by index)

That will give you 12 words that you can send to the wallet creation API. You probably might easily find existing BIP39 library for any language of your choice that will allow you to generate those words, or at least indexes.

Generating proper randomness is not that trivial! Put some thought into how you’re going to to this part.

6 Likes

Print out a program called diceware. It is a lot of pages. You roll dice to generate random phrases. I recommend printing it and actually rolling dice rather than using the online generator. I sometimes do that to create high entropy pass phrases since keefox doesn’t have that option.
Of course Daedalus creates a secure mnemonic for you anyway - so why bother ?

http://world.std.com/~reinhold/diceware.html

That will be random but as per

1 Like

I appreciate the helpful responses!

https://github.com/input-output-hk/cardano-sl/blob/develop/wallet/src/Pos/Util/Mnemonic.hs is the updated link.

Is this still possible? I’m trying to generate a key pair (with mnemonic) for a stake pool pledge so i can back it up with a cold storage solution like cryptosteel.

Hey, @marty this thread is super-outdated. I recommend to start a new topic in the stake pool operator category here:

1 Like

Thank you!

1 Like

Hi, I generated my payment and stake keys through CLI method (Coincashew instruction) on TESTNET. Now, I am wondering if I can create a mnemonic phrase for it to monitor the rewards easier.
on another note, does wallet that is created by mnemonic phrase help you control both pledge and stake rewards?
Thanks!!

You cannot generate a mnemonic for random keys after the fact. The keys are derived from the mnemonic used as a master secret.

But if you setup with a mnemonic from the beginning, you should be able to derive all keys from that mnemonic.

https://www.coincashew.com/coins/overview-ada/guide-how-to-build-a-haskell-stakepool-node/part-iii-operation/setting-up-payment-and-stake-keys also has a tab, how to do it with a mnenomic seed phrase, but I don’t know if that is the best way to do it. (I tend to like cardano-address more than cardano-wallet, because I do not see, why I should run another server just to derive some keys.)

1 Like