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

cosmrs: better document BIP-32 SigningKey derivation #300

Open
ewoolsey opened this issue Oct 27, 2022 · 8 comments
Open

cosmrs: better document BIP-32 SigningKey derivation #300

ewoolsey opened this issue Oct 27, 2022 · 8 comments

Comments

@ewoolsey
Copy link

As it stands there is very little documentation surrounding the SigningKey trait and the way you are supposed to use it with Bip32. I think a very common use case would be generating this from a mnemonic string, and as it stands there is no obvious way to go about that. An example of doing that would likely be very helpful for many.

@tony-iqlusion
Copy link
Member

@ewoolsey
Copy link
Author

This is the relevant method: https://docs.rs/cosmrs/latest/cosmrs/crypto/secp256k1/struct.SigningKey.html#method.derive_from_path

Is this not the correct way to do it?

        let mnemonic = bip32::Mnemonic::new(chain.private_key.clone(), Language::English).unwrap();
        let seed = mnemonic.to_seed("password");
        let xprv = XPrv::new(&seed)?;
        let signing_key: SigningKey = xprv.into();

@tony-iqlusion
Copy link
Member

@ewoolsey that's the correct way to get the seed, however you have no derivation path in your example.

You can pass the seed into derive_from_path, but you need a derivation path like m/44'/118'/0'/0

@ewoolsey
Copy link
Author

Ahhh so something like this?

        let mnemonic = bip32::Mnemonic::new(chain.mnemonic.clone(), Language::English).unwrap();
        let seed = mnemonic.to_seed("password");
        let child_path = "m/0/2147483647'/1/2147483646'";
        let child_xprv = XPrv::derive_from_path(&seed, &child_path.parse()?)?;        
        let signing_key: SigningKey = child_xprv.into();

@tony-iqlusion
Copy link
Member

The last two lines need to be:

let signing_key = cosmrs::crypto::secp256k1::SigningKey::derive_from_path(&seed, child_path.parse()?)?);

@ewoolsey
Copy link
Author

Gotcha! Thanks for the help! Appreciate it!

@tony-iqlusion tony-iqlusion changed the title Improve documentation surrounding SigningKey cosmrs: better document BIP-32 SigningKey derivation Oct 27, 2022
@meekteek
Copy link

Is this the only place for one to be able to get this knowledge?
There is still no good docs for this and I had to come here..

@tony-iqlusion
Copy link
Member

@meekteek this issue is still open to track updating the documentation because it hasn't been done yet.

Contributions to improve the documentation would be welcome.

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

3 participants