Skip to content
This repository was archived by the owner on Sep 13, 2022. It is now read-only.
This repository was archived by the owner on Sep 13, 2022. It is now read-only.

add support of mnemonics (bip39) #14

@stepansnigirev

Description

@stepansnigirev

Currently, we are using master private keys. It's ok, but it would be much more convenient to add mnemonic support (bip39).

Mnemonic generation can be done only if we have a wordlist somewhere.
I think having the wordlist on SD card is ok as soon as we check that the wordlist is correct.
To check the wordlist we need to calculate it's hash and compare with a hardcoded value.

Generating master private key from mnemonic can be done like this:

char mnemonic[] = "here is our mnemonic phrase with 12 words from the wordlist";
char password[] = ""; // we are not using passwords for now
HDPrivateKey key;
key.fromMnemonic(mnemonic, strlen(mnemonic), password, strlen(password), USE_TESTNET);

This procedure doesn't check if the mnemonic is correct - it only hashes it 2048 times and gets the seed. If we want to check the mnemonic we need a wordlist and a function for that. Mnemonic generation from random bytes is also not implemented yet.

Also, calculation of the seed from the mnemonic is extremely slow (can take up to several seconds) so it makes sense to calculate it once and then store in the file together with mnemonic.

Our saved key file will have the following content then:

mnemonic
seed
master private key
bip44 key (legacy addresses, m/44'/coin'/0'/)
bip49 key (segwit in p2sh addresses, m/49'/coin'/0'/)
bip84 key (segwit bech32 addresses, m/84'/coin'/0'/)

Currently, I think we don't want to support more than 1 coin and more than 1 account at the same time, so it will be good enough.

Metadata

Metadata

Assignees

No one assigned

    Labels

    arduinoArduino firmware related issueenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions