Skip to content

Commit

Permalink
Add ledger methods
Browse files Browse the repository at this point in the history
- Added ledger methods to support faucet spending.
- Consolidated h/w ledger support into the `minotari_ledger_wallet_comms` crate.
- Added test methods for all h/w ledger functions in the form of an example.
  • Loading branch information
hansieodendaal committed Jul 23, 2024
1 parent 1bd2fde commit 6ad33e0
Show file tree
Hide file tree
Showing 47 changed files with 1,621 additions and 564 deletions.
167 changes: 111 additions & 56 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions applications/minotari_console_wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ dirs = "5.0"
futures = { version = "^0.3.16", default-features = false, features = [
"alloc",
] }
ledger-transport-hid = { git = "https://github.com/Zondax/ledger-rs", rev = "20e2a20", optional = true }
log = { version = "0.4.8", features = ["std"] }
log4rs = { version = "1.3.0", default-features = false, features = [
"config_parsing",
Expand Down Expand Up @@ -89,7 +88,7 @@ tari_features = { path = "../../common/tari_features", version = "1.0.0-pre.16"
[features]
default = ["libtor", "ledger"]
grpc = []
ledger = ["ledger-transport-hid", "minotari_ledger_wallet_comms"]
ledger = ["minotari_ledger_wallet_comms"]
libtor = ["tari_libtor"]

[package.metadata.cargo-machete]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ pub async fn command_runner(

let mut script_signature = Signature::default();
match key_manager_service
.sign_with_nonce_and_message(
.sign_with_challenge_and_message(
&party_info.wallet_spend_key_id,
&party_info.script_nonce_key_id,
&challenge,
Expand Down Expand Up @@ -1007,7 +1007,7 @@ pub async fn command_runner(

let mut metadata_signature = Signature::default();
match key_manager_service
.sign_with_nonce_and_message(
.sign_with_challenge_and_message(
&party_info.sender_offset_key_id,
&party_info.sender_offset_nonce_key_id,
&challenge,
Expand Down
82 changes: 14 additions & 68 deletions applications/minotari_console_wallet/src/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,10 @@

use std::{fs, io, path::PathBuf, str::FromStr, sync::Arc, time::Instant};

#[cfg(feature = "ledger")]
use ledger_transport_hid::{hidapi::HidApi, TransportNativeHID};
use log::*;
use minotari_app_utilities::{consts, identity_management::setup_node_identity};
#[cfg(feature = "ledger")]
use minotari_ledger_wallet_comms::ledger_wallet::LedgerCommands;
#[cfg(feature = "ledger")]
use minotari_ledger_wallet_comms::{
error::LedgerDeviceError,
ledger_wallet::{get_transport, Instruction},
};
use minotari_ledger_wallet_comms::accessor_methods::{ledger_get_public_alpha, ledger_get_view_key};
use minotari_wallet::{
error::{WalletError, WalletStorageError},
output_manager_service::storage::database::OutputManagerDatabase,
Expand Down Expand Up @@ -833,66 +826,19 @@ pub fn prompt_wallet_type(
};
if prompt(connected_hardware_msg) {
print!("Scanning for connected Ledger hardware device... ");
match get_transport() {
Ok(hid) => {
println!("Device found.");
let account = prompt_ledger_account(boot_mode).expect("An account value");
let ledger = LedgerWallet::new(account, wallet_config.network, None, None);
match ledger
.build_command(Instruction::GetPublicAlpha, vec![])
.execute_with_transport(&hid)
{
Ok(result) => {
debug!(target: LOG_TARGET, "result length: {}, data: {:?}", result.data().len(), result.data());
if result.data().len() < 33 {
debug!(target: LOG_TARGET, "result less than 33");
panic!(
"'get_public_key' insufficient data - expected 33 got {} bytes ({:?})",
result.data().len(),
result
);
}

let public_alpha = match PublicKey::from_canonical_bytes(&result.data()[1..33]) {
Ok(k) => k,
Err(e) => panic!("{}", e),
};

match ledger
.build_command(Instruction::GetViewKey, vec![])
.execute_with_transport(&hid)
{
Ok(result) => {
debug!(target: LOG_TARGET, "result length: {}, data: {:?}", result.data().len(), result.data());
if result.data().len() < 33 {
debug!(target: LOG_TARGET, "result less than 33");
panic!(
"'get_view_key' insufficient data - expected 33 got {} bytes \
({:?})",
result.data().len(),
result
);
}

let view_key = match PrivateKey::from_canonical_bytes(&result.data()[1..33])
{
Ok(k) => k,
Err(e) => panic!("{}", e),
};

let ledger = LedgerWallet::new(
account,
wallet_config.network,
Some(public_alpha),
Some(view_key),
);
Some(WalletType::Ledger(ledger))
},
Err(e) => panic!("{}", e),
}
},
Err(e) => panic!("{}", e),
}
let account = prompt_ledger_account(boot_mode).expect("An account value");
match ledger_get_public_alpha(account) {
Ok(public_alpha) => match ledger_get_view_key(account) {
Ok(view_key) => {
let ledger = LedgerWallet::new(
account,
wallet_config.network,
Some(public_alpha),
Some(view_key),
);
Some(WalletType::Ledger(ledger))
},
Err(e) => panic!("{}", e),
},
Err(e) => panic!("{}", e),
}
Expand Down
11 changes: 9 additions & 2 deletions applications/minotari_ledger_wallet/comms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ edition = "2021"

[dependencies]
tari_crypto = { version = "0.20.2", default-features = false }
tari_common_types = { path = "../../../base_layer/common_types", version = "1.0.0-pre.16" }
tari_utilities = { version = "0.7" }
tari_common = { path = "../../../common" }
tari_common_types = { path = "../../../base_layer/common_types" }
tari_script = { path = "../../../infrastructure/tari_script" }

ledger-transport = { git = "https://github.com/Zondax/ledger-rs", rev = "20e2a20" }
ledger-transport-hid = { git = "https://github.com/Zondax/ledger-rs", rev = "20e2a20" }
num-derive = "0.4.2"
num-traits = "0.2.15"
serde = { version = "1.0.106", features = ["derive"] }
thiserror = "1.0.26"
thiserror = "1.0.26"

rand = "0.9.0-alpha.1"
once_cell = "1.19.0"
Loading

0 comments on commit 6ad33e0

Please sign in to comment.