1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-19 14:08:11 +00:00
trezor-firmware/rust/trezor-client/examples/sign_message.rs

41 lines
1.2 KiB
Rust
Raw Normal View History

use std::str::FromStr;
2023-06-05 05:50:39 +00:00
use bitcoin::{bip32::DerivationPath, network::Network, Address};
use trezor_client::{client::common::handle_interaction, InputScriptType};
2023-06-05 05:50:39 +00:00
fn main() {
tracing_subscriber::fmt().with_max_level(tracing::Level::TRACE).init();
// init with debugging
let mut trezor = trezor_client::unique(false).unwrap();
trezor.init_device(None).unwrap();
let pubkey = handle_interaction(
trezor
.get_public_key(
&DerivationPath::from_str("m/44h/1h/0h/0/0").unwrap(),
2023-06-05 05:50:39 +00:00
trezor_client::protos::InputScriptType::SPENDADDRESS,
Network::Testnet,
true,
)
.unwrap(),
)
.unwrap();
2023-06-05 05:50:39 +00:00
let addr = Address::p2pkh(&pubkey.to_pub(), Network::Testnet);
println!("address: {}", addr);
let (addr, signature) = handle_interaction(
trezor
.sign_message(
"regel het".to_owned(),
&DerivationPath::from_str("m/44h/1h/0h/0/0").unwrap(),
2023-06-05 05:50:39 +00:00
InputScriptType::SPENDADDRESS,
Network::Testnet,
)
.unwrap(),
)
.unwrap();
2023-06-05 05:50:39 +00:00
println!("Addr from device: {}", addr);
println!("Signature: {:?}", signature);
}