Skip to content
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

QA: Generate ED25519 recovery phrase #599

Open
2 of 6 tasks
Tracked by #591
SimiHunjan opened this issue Nov 9, 2023 · 3 comments
Open
2 of 6 tasks
Tracked by #591

QA: Generate ED25519 recovery phrase #599

SimiHunjan opened this issue Nov 9, 2023 · 3 comments
Assignees

Comments

@SimiHunjan
Copy link
Contributor

SimiHunjan commented Nov 9, 2023

Generate a recovery phrase that results in deriving ED25519 key types.

  • Generate a 12 word recovery phrase
  • Generate a 24 word recovery phrase
  • Generate a private key from the 12 word recovery phrase
  • Generate a private key from the 24 word recovery phrase
  • Use the 12 word recovery phrase to regenerate a key
  • Use the 24 word recovery phrase to regenerate a key
@SimiHunjan SimiHunjan mentioned this issue Nov 9, 2023
39 tasks
@SimiHunjan
Copy link
Contributor Author

I am little unclear on the mnemonic feature we have support for (in general as this question is applicable to all SDKs). I can see we support 12 and 24 word mnemonic phrase generation. Initially we only supported ED25519 keys so it was obvious the recovery phrase feature would generate a recovery phrase and then you could generate an associated ED25519 key. Now we support both ED25519 and ECSDA. What I am unclear on is when I use:

const MnemonicBIP39 mmneumonic = MnemonicBIP39::generate12WordBIP39Mnemonic();
std::cout << "Generate a 12 word recovery phrase: " << mmneumonic.toString() << std::endl;

How do I know which key type this mnemonic is going to generate keys for? Or do I specify that after I create the mnemonic/recovery phrase? I know that for ED key generation there is an index for every key and if you want to regenerate keys from a recovery phrase you have to also provide the index. Also is the above code snippet correct in what I am trying to achieve.

@SimiHunjan SimiHunjan self-assigned this Nov 10, 2023
@SimiHunjan
Copy link
Contributor Author

SimiHunjan commented Nov 10, 2023

Code Example

  // Generate a ED25519 recovery phrase
  const MnemonicBIP39 mneumonic1 = MnemonicBIP39::generate12WordBIP39Mnemonic();

  std::cout << "Generated a 12 word recovery phrase: " << mneumonic1.toString() << std::endl;

  const MnemonicBIP39 mneumonic2 = MnemonicBIP39::generate24WordBIP39Mnemonic();
  std::cout << "Generated a 24 word recovery phrase: " << mneumonic2.toString() << std::endl;

Output

Generated a 12 word recovery phrase: install recipe barely viable bring diesel dash obscure ship dignity tomorrow reform

Generated a 12 word recovery phrase: man smile grief seed property pear exclude rib when always mosquito honey plate tennis reward extend potato matrix bag cream couch outdoor course action

@rwalworth
Copy link
Contributor

rwalworth commented Nov 10, 2023

One mnemonic can generate ED25519 and ECDSAsecp256k1 keys; mnemonics aren't specific to one type of key. In the MnemonicBIP39 object, there are toStandardEd25519PrivateKey and toStandardECDSAsecp256k1PrivateKey functions that can generate the SLIP-44 standard private keys for those mnemonics. So it would look something like (using ED25519):

const MnemonicBIP39 mnemonic = MnemonicBIP39::generate12WordBIP39Mnemonic();
const std::shared_ptr<PrivateKey> privateKey = mnemonic.toStandardED25519PrivateKey();

As for the index, it's just the final derivation in the full SLIP-44 standard deviation path. It can be used to generate multiple different keys from the same mnemonic. It is defaulted in the C++ SDK to 0, but a user can provide a specific index if they so like. So that would look something like (using ECDSA this time):

const std::shared_ptr<PrivateKey> privateKeyIndex0 = mnemonic.toStandardECDSAsecp256k1PrivateKey();
const std::shared_ptr<PrivateKey> privateKeyIndex1 = mnemonic.toStandardECDSAsecp256k1PrivateKey("", 1);

The "" is an optional passphrase as well that you can provide.

const std::shared_ptr<PrivateKey> privateKeyNoPassphraseOrIndex = mnemonic.toStandardECDSAsecp256k1PrivateKey();
const std::shared_ptr<PrivateKey> privateKeyPassPhraseNoIndex = mnemonic.toStandardECDSAsecp256k1PrivateKey("passphrase");
const std::shared_ptr<PrivateKey> privateKeyNoPassphraseIndex = mnemonic.toStandardECDSAsecp256k1PrivateKey("", index);
const std::shared_ptr<PrivateKey> privateKeyPassphraseAndIndex = mnemonic.toStandardECDSAsecp256k1PrivateKey("passphrase", index);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants