Skip to content

Commit

Permalink
testing spend
Browse files Browse the repository at this point in the history
  • Loading branch information
hansieodendaal committed Jul 31, 2024
1 parent 5717c6e commit d79fa5b
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 341 deletions.
53 changes: 47 additions & 6 deletions applications/minotari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ async fn finalise_aggregate_utxo(
script_signatures: Vec<Signature>,
wallet_script_secret_key: PrivateKey,
) -> Result<TxId, CommandError> {
trace!(target: LOG_TARGET, "finalise_aggregate_utxo: start");

let mut meta_sig = Signature::default();
for sig in &meta_signatures {
meta_sig = &meta_sig + sig;
Expand All @@ -229,6 +231,7 @@ async fn finalise_aggregate_utxo(
for sig in &script_signatures {
script_sig = &script_sig + sig;
}
trace!(target: LOG_TARGET, "finalise_aggregate_utxo: aggregated signatures");

wallet_transaction_service
.finalize_aggregate_utxo(tx_id, meta_sig, script_sig, wallet_script_secret_key)
Expand Down Expand Up @@ -807,7 +810,7 @@ pub async fn command_runner(
break;
},
};
let signature = match key_manager_service
let verification_signature = match key_manager_service
.sign_script_message(&key_id, PrivateKey::from(index).as_bytes())
.await
{
Expand All @@ -821,7 +824,7 @@ pub async fn command_runner(
outputs_for_leader.push(PreMineCreateStep1ForLeader {
index,
script_public_key,
verification_signature: signature,
verification_signature,
});
}
if error {
Expand Down Expand Up @@ -1186,6 +1189,14 @@ pub async fn command_runner(
println!();
},
PreMineSpendSessionInfo(args) => {
match key_manager_service.get_wallet_type().await {
WalletType::Ledger(_) => {},
_ => {
eprintln!("\nError: Wallet type must be 'Ledger' to spend pre-mine outputs!\n");
break;
},
}

let embedded_output = match get_embedded_pre_mine_outputs(vec![args.output_index]) {
Ok(outputs) => outputs[0].clone(),
Err(e) => {
Expand Down Expand Up @@ -1240,6 +1251,14 @@ pub async fn command_runner(
println!();
},
PreMineSpendPartyDetails(args) => {
match key_manager_service.get_wallet_type().await {
WalletType::Ledger(_) => {},
_ => {
eprintln!("\nError: Wallet type must be 'Ledger' to spend pre-mine outputs!\n");
break;
},
}

if args.alias.is_empty() || args.alias.contains(" ") {
eprintln!("\nError: Alias cannot contain spaces!\n");
break;
Expand Down Expand Up @@ -1313,15 +1332,13 @@ pub async fn command_runner(
break;
},
};

let script_input_signature = key_manager_service
.sign_script_message(&wallet_spend_key.key_id, commitment.as_bytes())
.sign_script_message(&pre_mine_script_key_id, commitment.as_bytes())
.await?;

let out_dir = out_dir(&session_info.session_id, Context::Spend)?;
let step_2_outputs_for_leader = PreMineSpendStep2OutputsForLeader {
script_input_signature,
wallet_public_spend_key: wallet_spend_key.pub_key,
public_script_nonce_key: script_nonce_key.pub_key,
public_sender_offset_key: sender_offset_key.pub_key,
public_sender_offset_nonce_key: sender_offset_nonce.pub_key,
Expand Down Expand Up @@ -1355,6 +1372,14 @@ pub async fn command_runner(
println!();
},
PreMineSpendEncumberAggregateUtxo(args) => {
match key_manager_service.get_wallet_type().await {
WalletType::Ledger(_) => {},
_ => {
eprintln!("\nError: Wallet type must be 'Ledger' to spend pre-mine outputs!\n");
break;
},
}

// Read session info
let session_info = read_verify_session_info::<PreMineSpendStep1SessionInfo>(&args.session_id)?;

Expand Down Expand Up @@ -1441,6 +1466,14 @@ pub async fn command_runner(
}
},
PreMineSpendInputOutputSigs(args) => {
match key_manager_service.get_wallet_type().await {
WalletType::Ledger(_) => {},
_ => {
eprintln!("\nError: Wallet type must be 'Ledger' to spend pre-mine outputs!\n");
break;
},
}

// Read session info
let session_info = read_verify_session_info::<PreMineSpendStep1SessionInfo>(&args.session_id)?;
// Read leader input
Expand Down Expand Up @@ -1484,7 +1517,7 @@ pub async fn command_runner(

// Metadata signature
let script_offset = key_manager_service
.get_script_offset(&vec![party_info.wallet_spend_key_id], &vec![party_info
.get_script_offset(&vec![party_info.pre_mine_script_key_id], &vec![party_info
.sender_offset_key_id
.clone()])
.await?;
Expand Down Expand Up @@ -1545,6 +1578,14 @@ pub async fn command_runner(
}
},
PreMineSpendAggregateTransaction(args) => {
match key_manager_service.get_wallet_type().await {
WalletType::Ledger(_) => {},
_ => {
eprintln!("\nError: Wallet type must be 'Ledger' to spend pre-mine outputs!\n");
break;
},
}

// Read session info
let session_info = read_verify_session_info::<PreMineSpendStep1SessionInfo>(&args.session_id)?;

Expand Down
1 change: 0 additions & 1 deletion applications/minotari_console_wallet/src/automation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ struct PreMineSpendStep2OutputsForSelf {
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
struct PreMineSpendStep2OutputsForLeader {
script_input_signature: CheckSigSchnorrSignature,
wallet_public_spend_key: PublicKey,
public_script_nonce_key: PublicKey,
public_sender_offset_key: PublicKey,
public_sender_offset_nonce_key: PublicKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ pub fn verify_ledger_application() -> Result<(), LedgerDeviceError> {
if let Ok(mut verified) = VERIFIED.try_lock() {
if verified.is_none() {
match verify() {
Ok(_) => *verified = Some(Ok(())),
Ok(_) => {
debug!(target: LOG_TARGET, "Ledger application 'Minotari Wallet' running and verified");
*verified = Some(Ok(()))
},
Err(e) => return Err(e),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use derivative::Derivative;
use tari_common_types::{
key_branches::TransactionKeyManagerBranch,
types::{ComAndPubSignature, PublicKey},
};
use tari_common_types::types::{ComAndPubSignature, PublicKey};
use tari_script::{ExecutionStack, TariScript};

use crate::{
Expand Down Expand Up @@ -229,9 +226,7 @@ impl WalletOutputBuilder {
let aggregate_sender_offset_public_key =
aggregated_sender_offset_public_key_shares + &sender_offset_public_key_self;

let ephemeral_pubkey_self = key_manager
.get_next_key(TransactionKeyManagerBranch::MetadataEphemeralNonce.get_branch_key())
.await?;
let ephemeral_pubkey_self = key_manager.get_random_key().await?;
let aggregate_ephemeral_pubkey = aggregated_ephemeral_public_key_shares + &ephemeral_pubkey_self.pub_key;

let receiver_partial_metadata_signature = key_manager
Expand Down Expand Up @@ -314,6 +309,7 @@ impl WalletOutputBuilder {

#[cfg(test)]
mod test {
use tari_common_types::key_branches::TransactionKeyManagerBranch;
use tari_key_manager::key_manager_service::KeyManagerInterface;

use super::*;
Expand Down
Loading

0 comments on commit d79fa5b

Please sign in to comment.