Skip to content

Commit

Permalink
Merge branch 'development' into sw_ad_zeroize
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler authored Aug 5, 2024
2 parents a73707c + 016ccf6 commit 06a720c
Show file tree
Hide file tree
Showing 15 changed files with 843 additions and 435 deletions.
163 changes: 56 additions & 107 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion applications/minotari_app_utilities/src/utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl FromStr for UniNodeId {
Ok(Self::PublicKey(public_key))
} else if let Ok(node_id) = NodeId::from_hex(key) {
Ok(Self::NodeId(node_id))
} else if let Ok(tari_address) = TariAddress::from_base58(key) {
} else if let Ok(tari_address) = TariAddress::from_str(key) {
Ok(Self::TariAddress(tari_address))
} else {
Err(UniIdError::UnknownIdType)
Expand Down
16 changes: 12 additions & 4 deletions applications/minotari_ledger_wallet/common/src/common_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ pub enum Instruction {
GetAppName = 0x02,
GetPublicSpendKey = 0x03,
GetPublicKey = 0x04,
GetScriptSignature = 0x05,
GetScriptSignatureDerived = 0x05,
GetScriptOffset = 0x06,
GetViewKey = 0x07,
GetDHSharedSecret = 0x08,
GetRawSchnorrSignature = 0x09,
GetScriptSchnorrSignature = 0x10,
GetOneSidedMetadataSignature = 0x11,
GetScriptSignatureManaged = 0x12,
}

impl Instruction {
Expand All @@ -96,13 +97,14 @@ impl Instruction {
0x02 => Some(Instruction::GetAppName),
0x03 => Some(Instruction::GetPublicSpendKey),
0x04 => Some(Instruction::GetPublicKey),
0x05 => Some(Instruction::GetScriptSignature),
0x05 => Some(Instruction::GetScriptSignatureDerived),
0x06 => Some(Instruction::GetScriptOffset),
0x07 => Some(Instruction::GetViewKey),
0x08 => Some(Instruction::GetDHSharedSecret),
0x09 => Some(Instruction::GetRawSchnorrSignature),
0x10 => Some(Instruction::GetScriptSchnorrSignature),
0x11 => Some(Instruction::GetOneSidedMetadataSignature),
0x12 => Some(Instruction::GetScriptSignatureManaged),
_ => None,
}
}
Expand Down Expand Up @@ -224,12 +226,14 @@ mod test {
(0x02, Instruction::GetAppName),
(0x03, Instruction::GetPublicSpendKey),
(0x04, Instruction::GetPublicKey),
(0x05, Instruction::GetScriptSignature),
(0x05, Instruction::GetScriptSignatureDerived),
(0x06, Instruction::GetScriptOffset),
(0x07, Instruction::GetViewKey),
(0x08, Instruction::GetDHSharedSecret),
(0x09, Instruction::GetRawSchnorrSignature),
(0x10, Instruction::GetScriptSchnorrSignature),
(0x11, Instruction::GetOneSidedMetadataSignature),
(0x12, Instruction::GetScriptSignatureManaged),
];

for (expected_byte, instruction) in &mappings {
Expand All @@ -250,7 +254,7 @@ mod test {
assert_eq!(instruction.as_byte(), *expected_byte);
assert_eq!(Instruction::from_byte(*expected_byte), Some(*instruction));
},
Instruction::GetScriptSignature => {
Instruction::GetScriptSignatureDerived => {
assert_eq!(instruction.as_byte(), *expected_byte);
assert_eq!(Instruction::from_byte(*expected_byte), Some(*instruction));
},
Expand Down Expand Up @@ -278,6 +282,10 @@ mod test {
assert_eq!(instruction.as_byte(), *expected_byte);
assert_eq!(Instruction::from_byte(*expected_byte), Some(*instruction));
},
Instruction::GetScriptSignatureManaged => {
assert_eq!(instruction.as_byte(), *expected_byte);
assert_eq!(Instruction::from_byte(*expected_byte), Some(*instruction));
},
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_ledger_wallet/comms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ ledger-transport-hid = { git = "https://github.com/Zondax/ledger-rs", rev = "20e
serde = { version = "1.0.106", features = ["derive"] }
thiserror = "1.0.26"

rand = "0.9.0-alpha.1"
rand = "0.8"
once_cell = "1.19.0"
log = "0.4.20"
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@

//! # Multi-party Ledger - command line example
/// This example demonstrates how to use the Ledger Nano S/X for the Tari wallet. In order to run the example, you
/// need to have the `MinoTari Wallet` application installed on your Ledger device. For that, please follow the
/// instructions in the [README](../../wallet/README.md) file.
/// With this example, you can:
/// - Detect the hardware wallet
/// - Verify that the Ledger application is installed and the version is correct
/// - TBD
///
/// -----------------------------------------------------------------------------------------------
/// Example use:
/// `cargo run --release --example ledger_demo`
/// -----------------------------------------------------------------------------------------------
use dialoguer::{theme::ColorfulTheme, Select};
use minotari_ledger_wallet_comms::{
accessor_methods::{
Expand All @@ -17,24 +29,12 @@ use minotari_ledger_wallet_comms::{
ledger_get_version,
ledger_get_view_key,
verify_ledger_application,
ScriptSignatureKey,
},
error::LedgerDeviceError,
ledger_wallet::get_transport,
};
use rand::rngs::OsRng;
/// This example demonstrates how to use the Ledger Nano S/X for the Tari wallet. In order to run the example, you
/// need to have the `MinoTari Wallet` application installed on your Ledger device. For that, please follow the
/// instructions in the [README](../../wallet/README.md) file.
/// With this example, you can:
/// - Detect the hardware wallet
/// - Verify that the Ledger application is installed and the version is correct
/// - TBD
///
/// -----------------------------------------------------------------------------------------------
/// Example use:
/// `cargo run --release --example ledger_demo`
/// -----------------------------------------------------------------------------------------------
use rand::RngCore;
use rand::{rngs::OsRng, RngCore};
use tari_common::configuration::Network;
use tari_common_types::{
key_branches::TransactionKeyManagerBranch,
Expand Down Expand Up @@ -148,51 +148,66 @@ fn main() {
println!("\ntest: GetScriptSignature");
let network = Network::LocalNet;
let version = 0u8;
let branch_key = get_random_nonce();
let value = PrivateKey::from(123456);
let spend_private_key = get_random_nonce();
let commitment = Commitment::from_public_key(&PublicKey::from_secret_key(&get_random_nonce()));
let mut script_message = [0u8; 32];
script_message.copy_from_slice(&get_random_nonce().to_vec());

match ledger_get_script_signature(
account,
network,
version,
&branch_key,
&value,
&spend_private_key,
&commitment,
script_message,
) {
Ok(signature) => println!(
"script_sig: ({},{},{},{},{})",
signature.ephemeral_commitment().to_hex(),
signature.ephemeral_pubkey().to_hex(),
signature.u_x().to_hex(),
signature.u_a().to_hex(),
signature.u_y().to_hex()
),
Err(e) => {
println!("\nError: {}\n", e);
return;
for branch_key in [
ScriptSignatureKey::Derived {
branch_key: get_random_nonce(),
},
ScriptSignatureKey::Managed {
branch: TransactionKeyManagerBranch::Spend,
index: OsRng.next_u64(),
},
] {
match ledger_get_script_signature(
account,
network,
version,
&branch_key,
&value,
&spend_private_key,
&commitment,
script_message,
) {
Ok(signature) => println!(
"script_sig: ({},{},{},{},{})",
signature.ephemeral_commitment().to_hex(),
signature.ephemeral_pubkey().to_hex(),
signature.u_x().to_hex(),
signature.u_a().to_hex(),
signature.u_y().to_hex()
),
Err(e) => {
println!("\nError: {}\n", e);
return;
},
}
}

// GetScriptOffset
println!("\ntest: GetScriptOffset");
let total_script_private_key = PrivateKey::default();
let mut derived_key_commitments = Vec::new();
let partial_script_offset = PrivateKey::default();
let mut derived_script_keys = Vec::new();
let mut script_key_indexes = Vec::new();
let mut derived_sender_offsets = Vec::new();
let mut sender_offset_indexes = Vec::new();
for _i in 0..5 {
derived_key_commitments.push(get_random_nonce());
sender_offset_indexes.push(OsRng.next_u64());
derived_script_keys.push(get_random_nonce());
script_key_indexes.push((TransactionKeyManagerBranch::Spend, OsRng.next_u64()));
derived_sender_offsets.push(get_random_nonce());
sender_offset_indexes.push((TransactionKeyManagerBranch::OneSidedSenderOffset, OsRng.next_u64()));
}

match ledger_get_script_offset(
account,
&total_script_private_key,
&derived_key_commitments,
&partial_script_offset,
&derived_script_keys,
&script_key_indexes,
&derived_sender_offsets,
&sender_offset_indexes,
) {
Ok(script_offset) => println!("script_offset: {}", script_offset.to_hex()),
Expand Down
Loading

0 comments on commit 06a720c

Please sign in to comment.