diff --git a/rust/trezor-client/Cargo.toml b/rust/trezor-client/Cargo.toml index d37aec666..0cf796553 100644 --- a/rust/trezor-client/Cargo.toml +++ b/rust/trezor-client/Cargo.toml @@ -49,7 +49,7 @@ tracing-subscriber = "0.3" serial_test = "2.0.0" [features] -default = ["bitcoin", "ethereum"] +default = ["bitcoin", "ethereum", "solana"] # Client implementations bitcoin = ["dep:bitcoin", "unicode-normalization"] diff --git a/rust/trezor-client/examples/solana.rs b/rust/trezor-client/examples/solana.rs new file mode 100644 index 000000000..9f943c082 --- /dev/null +++ b/rust/trezor-client/examples/solana.rs @@ -0,0 +1,17 @@ +use std::str::FromStr; + +use bitcoin::bip32::DerivationPath; +use trezor_client::utils::convert_path; + +fn do_main() -> Result<(), trezor_client::Error> { + let mut trezor = trezor_client::unique(false)?; + trezor.init_device(None)?; + let path = DerivationPath::from_str("m/44'/501'/0'/0'").expect("Hardended Derivation Path"); + let solana_address = trezor.solana_get_address(convert_path(&path))?; + println!("solana address: {:?}", solana_address); + Ok(()) +} + +fn main() { + do_main().unwrap() +} diff --git a/rust/trezor-client/src/client/mod.rs b/rust/trezor-client/src/client/mod.rs index f541883df..052a2fa8a 100644 --- a/rust/trezor-client/src/client/mod.rs +++ b/rust/trezor-client/src/client/mod.rs @@ -8,6 +8,11 @@ mod ethereum; #[cfg(feature = "ethereum")] pub use ethereum::*; +#[cfg(feature = "solana")] +mod solana; +#[cfg(feature = "solana")] +pub use solana::*; + pub mod common; pub use common::*; diff --git a/rust/trezor-client/src/client/solana.rs b/rust/trezor-client/src/client/solana.rs new file mode 100644 index 000000000..15e3358e8 --- /dev/null +++ b/rust/trezor-client/src/client/solana.rs @@ -0,0 +1,15 @@ +use super::{handle_interaction, Trezor}; +use crate::{error::Result, protos}; + +impl Trezor { + // SOLANA + pub fn solana_get_address(&mut self, path: Vec) -> Result { + let mut req = protos::SolanaGetAddress::new(); + req.address_n = path; + req.show_display = Some(true); + let address = handle_interaction( + self.call(req, Box::new(|_, m: protos::SolanaAddress| Ok(m.address().into())))?, + )?; + Ok(address) + } +}