Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ledger blind sign #6264

Merged
merged 49 commits into from May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
54cf181
Update ledger wallet app scaffold
brianp Apr 8, 2024
9a9644e
Trim down the ledger app to needed functions
brianp Apr 10, 2024
9f831bb
update payload to ledger script key generation
brianp Apr 10, 2024
1f3ebc4
Only use ledger for outputs that have managed keys
brianp Apr 10, 2024
36418e5
Moved ledger device app to new folder
brianp Apr 19, 2024
946e38f
Add ledger interface library
brianp Apr 19, 2024
860a1d2
Add public key function to ledger
brianp Apr 19, 2024
2b0b10d
fetch the script key pair for derivation
brianp Apr 19, 2024
6608570
change script key derivation
SWvheerden Apr 19, 2024
069f963
Make the software wallet use priv and pub key types
brianp Apr 23, 2024
5a77d23
Code fork for script signing on the ledger
brianp Apr 23, 2024
9bd7b88
Allow the transport to be reused
brianp Apr 23, 2024
70b1a18
Generate the ComAndPubSig entirely on the ledger
brianp Apr 23, 2024
8f6b3ad
derive script key (#5)
SWvheerden Apr 24, 2024
b1454c0
minor changes
brianp Apr 24, 2024
a5ee627
fmt
brianp Apr 24, 2024
c922f0f
Only hit the ledger for derived keys
brianp Apr 24, 2024
34f03a9
Mask alpha on the ledger
brianp Apr 25, 2024
192a337
Move key derivation into helper
brianp Apr 25, 2024
0512bcc
Remove GetPrivateKey function at no point should the private key be r…
brianp Apr 25, 2024
ce695e5
Update script offset key manager function
brianp Apr 26, 2024
ec6974c
Only append and read the account once per process
brianp Apr 26, 2024
86eb90b
Update the key derivation params
brianp Apr 26, 2024
b14d4e0
Calculate offset from ledger
brianp Apr 26, 2024
29ae815
More offset key fixes as per review
brianp Apr 29, 2024
bf76040
Allow 0 values for offset keys, and commitments
brianp Apr 30, 2024
0a1d66a
Update dependencies like borsh for better version matching
brianp May 2, 2024
8699586
refactoring improvements and metadata signature signing
brianp May 2, 2024
50e1180
some change (#6)
SWvheerden May 3, 2024
197c74d
Enhance public none fetching and fix bugs
brianp May 3, 2024
a85ab69
refactoring
brianp May 3, 2024
4e41344
debugging
brianp May 3, 2024
caf235e
More debugging
brianp May 6, 2024
539635e
fix spelling
brianp May 6, 2024
9f4b028
pub key derive
brianp May 6, 2024
c1d01d6
Get proper account on script signature
brianp May 6, 2024
a30a182
Validate and correct the domain hashers
brianp May 7, 2024
a227d0d
Fix instructions issue to script offset function
brianp May 7, 2024
f41d5ec
Remove debug lines
brianp May 13, 2024
6aa5336
Fix clippy warnings and conditional compilation
brianp May 13, 2024
8cbfe10
machete warnings
brianp May 14, 2024
11edae5
Clean up ledger code debugs
brianp May 14, 2024
16648ce
Simplify the matching of public key fetching
brianp May 15, 2024
ee4f071
Remove panic for proper error
brianp May 15, 2024
6a814ec
Minor refactoring for readability and convention
brianp May 15, 2024
aa9cae0
Upgrade tari-crypto to 0.20.1
brianp May 15, 2024
5a04e0a
Zeroize all the secret keys
brianp May 15, 2024
43a1df5
Add additional custom error type
brianp May 15, 2024
147d5b9
update tests
brianp May 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 17 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -30,6 +30,7 @@ members = [
"applications/minotari_app_utilities",
"applications/minotari_merge_mining_proxy",
"applications/minotari_miner",
"applications/minotari_ledger_wallet/comms",
"integration_tests",
"hashing",
]
Expand Down
3 changes: 2 additions & 1 deletion applications/minotari_console_wallet/Cargo.toml
Expand Up @@ -8,6 +8,7 @@ license = "BSD-3-Clause"
[dependencies]
minotari_app_grpc = { path = "../minotari_app_grpc" }
minotari_app_utilities = { path = "../minotari_app_utilities" }
minotari_ledger_wallet_comms = { path = "../../applications/minotari_ledger_wallet/comms", version = "1.0.0-pre.13" }
tari_common = { path = "../../common" }
tari_common_types = { path = "../../base_layer/common_types" }
tari_comms = { path = "../../comms/core" }
Expand Down Expand Up @@ -88,7 +89,7 @@ tari_features = { path = "../../common/tari_features", version = "1.0.0-pre.13"
[features]
default = ["libtor"]
grpc = []
ledger = ["ledger-transport-hid"]
ledger = ["ledger-transport-hid", ]
libtor = ["tari_libtor"]

[package.metadata.cargo-machete]
Expand Down
59 changes: 46 additions & 13 deletions applications/minotari_console_wallet/src/init/mod.rs
Expand Up @@ -28,6 +28,10 @@ use std::{fs, io, path::PathBuf, str::FromStr, sync::Arc, time::Instant};
use ledger_transport_hid::{hidapi::HidApi, TransportNativeHID};
use log::*;
use minotari_app_utilities::{consts, identity_management::setup_node_identity};
use minotari_ledger_wallet_comms::{
error::LedgerDeviceError,
ledger_wallet::{get_transport, Instruction, LedgerWallet},
};
use minotari_wallet::{
error::{WalletError, WalletStorageError},
output_manager_service::storage::database::OutputManagerDatabase,
Expand All @@ -50,15 +54,21 @@ use tari_common::{
},
exit_codes::{ExitCode, ExitError},
};
use tari_common_types::wallet_types::WalletType;
use tari_common_types::{
types::{PrivateKey, PublicKey},
wallet_types::WalletType,
};
use tari_comms::{
multiaddr::Multiaddr,
peer_manager::{Peer, PeerFeatures, PeerQuery},
types::CommsPublicKey,
NodeIdentity,
};
use tari_core::{consensus::ConsensusManager, transactions::CryptoFactories};
use tari_crypto::keys::PublicKey;
use tari_core::{
consensus::ConsensusManager,
transactions::{transaction_components::TransactionError, CryptoFactories},
};
use tari_crypto::{keys::PublicKey as PublicKeyTrait, ristretto::RistrettoPublicKey};
use tari_key_manager::{cipher_seed::CipherSeed, mnemonic::MnemonicLanguage};
use tari_p2p::{peer_seeds::SeedPeer, TransportType};
use tari_shutdown::ShutdownSignal;
Expand Down Expand Up @@ -818,42 +828,65 @@ pub fn prompt_wallet_type(
non_interactive: bool,
) -> Option<WalletType> {
if non_interactive {
return Some(WalletType::Software);
return Some(WalletType::default());
}

if wallet_config.wallet_type.is_some() {
return wallet_config.wallet_type;
return wallet_config.wallet_type.clone();
}

match boot_mode {
WalletBoot::New => {
#[cfg(not(feature = "ledger"))]
return Some(WalletType::Software);
return Some(WalletType::default());

#[cfg(feature = "ledger")]
{
if prompt("\r\nWould you like to use a connected hardware wallet? (Supported types: Ledger)") {
print!("Scanning for connected Ledger hardware device... ");
let err = "No connected device was found. Please make sure the device is plugged in before
continuing.";
match TransportNativeHID::new(&HidApi::new().expect(err)) {
Ok(_) => {
match get_transport() {
Ok(hid) => {
println!("Device found.");
let account = prompt_ledger_account().expect("An account value");
Some(WalletType::Ledger(account))
let ledger = LedgerWallet::new(account, wallet_config.network, None);
SWvheerden marked this conversation as resolved.
Show resolved Hide resolved
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 key = match PublicKey::from_canonical_bytes(&result.data()[1..33]) {
Ok(k) => k,
Err(e) => panic!("{}", e),
};

let ledger = LedgerWallet::new(account, wallet_config.network, Some(key));
Some(WalletType::Ledger(ledger))
},
Err(e) => panic!("{}", e),
}
},
Err(e) => panic!("{}", e),
}
} else {
Some(WalletType::Software)
Some(WalletType::default())
}
}
},
_ => None,
}
}

pub fn prompt_ledger_account() -> Option<usize> {
pub fn prompt_ledger_account() -> Option<u64> {
let question =
"\r\nPlease enter an account number for your ledger. A simple 1-9, easily remembered numbers are suggested.";
println!("{}", question);
Expand Down
1 change: 0 additions & 1 deletion applications/minotari_console_wallet/src/lib.rs
Expand Up @@ -128,7 +128,6 @@ pub fn run_wallet_with_cli(

let recovery_seed = get_recovery_seed(boot_mode, &cli)?;

// This is deactivated at the moment as full support is not yet complete
let wallet_type = prompt_wallet_type(boot_mode, &config.wallet, cli.non_interactive_mode);
brianp marked this conversation as resolved.
Show resolved Hide resolved

// get command line password if provided
Expand Down