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: add pre-mine spend #6442

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading