cosmrs: better document BIP-32 `SigningKey` derivation
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.
This is the relevant method: https://docs.rs/cosmrs/latest/cosmrs/crypto/secp256k1/struct.SigningKey.html#method.derive_from_path
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();
@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
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();
The last two lines need to be:
let signing_key = cosmrs::crypto::secp256k1::SigningKey::derive_from_path(&seed, child_path.parse()?)?);
Gotcha! Thanks for the help! Appreciate it!
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..
@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.