micro-bitcoin / uBitcoin

Bitcoin library for microcontrollers. Supports Arduino, mbed, bare metal.
https://micro-bitcoin.github.io/
MIT License
166 stars 34 forks source link

Output phrase not the same as entropy #16

Closed svenvinicius closed 2 years ago

svenvinicius commented 2 years ago

Hi,

I'm trying out the tutorial from the docs and I'm little bit confused.

Recovery phrase:

// our random data from good random sources or user String entropy = "h3iq7fqj3f7yowu3849uqomfiq3984"; // generating 12 words (first parameter, 24 by default) String phrase = generateMnemonic(12, entropy); // phrase: habit opera fox human grow relax snow shoulder just knife tail guilt Serial.println(phrase);

I don't get the same phrase as specified in the docs. What could be the problem?

Greetings

stepansnigirev commented 2 years ago

Hi. Thanks for noticing. Some time ago I've added an additional sha256 into the generateMnemonic function, so the recovery phrase in the code from docs is different now. I updated the docs to reflect the current implementation. Please let me know if you find more places like that.

Sidenote: generateMnemonic can accept a string or byte array of any length, then it hashes the data, takes a part of the resulting hash and converts it to mnemonic. As it hashes the incoming data this function is not reversable. mnemonicToEntropy and mnemonicFromEntropy are actually reversible and act according to bip39 - therefore you need to have exactly 16 or 32-byte entropy to get a 12 or 24 word recovery phrase.