use cosmrs::bip32;
use crate::client::error::ClientError;
const DERVIATION_PATH: &str = "m/44'/118'/0'/0/0";
#[derive(Debug, Clone)]
pub struct SigningKey {
pub name: String,
pub key: Key,
}
#[derive(Debug, Clone)]
pub enum Key {
Mnemonic(String),
}
impl TryFrom<SigningKey> for cosmrs::crypto::secp256k1::SigningKey {
type Error = ClientError;
fn try_from(signer: SigningKey) -> Result<cosmrs::crypto::secp256k1::SigningKey, ClientError> {
match signer.key {
Key::Mnemonic(key) => {
let seed = bip32::Mnemonic::new(key, bip32::Language::English)
.map_err(|_| ClientError::Mnemonic)?
.to_seed("");
Ok(
bip32::XPrv::derive_from_path(seed, &DERVIATION_PATH.parse().unwrap())
.map_err(|_| ClientError::DerviationPath)?
.into(),
)
}
}
}
}