mosaicnetworks / monetd

Distributed smart-contract platform based on EVM-Lite and Babble
MIT License
12 stars 4 forks source link

BIP39 Wallet #17

Open arrivets opened 5 years ago

arrivets commented 5 years ago

Implement a way to backup/restore keys using a seed phrase (BIP39).

BIP39 covers more than seed phrases, it also covers HD wallets (BIP32), which enables generating multiple keys using the same seed-phrase. The same seed-phrase can be used to recover all the keys that were generated with it.

We could do something similar to Cosmos gaiacli:

# produce a seed phrase, generate the fist key following BIP39(index 0),
# prompt password to encrypt key, save encrypted keyfile.
monetd keys add [name] 

# prompt seed phrase, and recover the i'th key
# prompt password to encrypt key, save encrypted keyfile
monetd keys add [name] --recover --index [i]

So for example:

monetd keys add key0
monetd keys add key0-recovered --recover

Produces two identical keys key0 and key0-recovered provided that the seed-phrase given to the second command is the same as the seed-phrase produced by the first command.

Then, create a second key using the same seed-phrase:

monetd keys add key1 --recover --index 1

And recover it:

monetd keys add key1-recovered --recover --index 1

key1-recovered equals key1.

arrivets commented 5 years ago

If we allow ourselves to deviate from gaiacli's API, we could have:

To generate a new keyfile from a new seed-phrase:

monetd keys new [name]

To generate a new keyfile from an existing seed-phrase (which it prompts for interactively):

monetd keys new [name] --seed

To recover a key from a seed-phrase:

monetd keys recover [name]

At this stage, there would be no support for HD wallets. Only one key per seed-phrase.

Full BIP39 would be implemented in monetcli later.