Skip to content

Commit

Permalink
Apply m_of_n_feature branch
Browse files Browse the repository at this point in the history
  • Loading branch information
hansieodendaal committed Jun 24, 2024
1 parent fbcc80c commit c8009c1
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 0 deletions.
14 changes: 14 additions & 0 deletions applications/minotari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ use tari_comms::{
};
use tari_comms_dht::{envelope::NodeDestination, DhtDiscoveryRequester};
use tari_core::transactions::{
key_manager::TransactionKeyManagerInterface,
tari_amount::{uT, MicroMinotari, Minotari},
transaction_components::{
encrypted_data::PaymentId,
Expand Down Expand Up @@ -617,6 +618,7 @@ pub async fn command_runner(
let mut output_service = wallet.output_manager_service.clone();
let dht_service = wallet.dht_service.discovery_service_requester().clone();
let connectivity_requester = wallet.comms.connectivity();
let key_manager_service = wallet.key_manager_service.clone();
let mut online = false;

let mut tx_ids = Vec::new();
Expand Down Expand Up @@ -676,6 +678,18 @@ pub async fn command_runner(
Err(e) => eprintln!("BurnMinotari error! {}", e),
}
},
CreateKeyPair(args) => match key_manager_service.create_key_pair(args.key_branch).await {
Ok((sk, pk)) => {
println!(
"New key pair:
1. secret key: {},
2. public key: {}",
sk.to_hex(),
pk.to_hex()
)
},
Err(e) => eprintln!("CreateKeyPair error! {}", e),
},
SendMinotari(args) => {
match send_tari(
transaction_service.clone(),
Expand Down
7 changes: 7 additions & 0 deletions applications/minotari_console_wallet/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ pub enum CliCommands {
GetBalance,
SendMinotari(SendMinotariArgs),
BurnMinotari(BurnMinotariArgs),
CreateKeyPair(CreateKeyPairArgs),
SendOneSided(SendMinotariArgs),
SendOneSidedToStealthAddress(SendMinotariArgs),
MakeItRain(MakeItRainArgs),
CoinSplit(CoinSplitArgs),
Expand Down Expand Up @@ -157,6 +159,11 @@ pub struct BurnMinotariArgs {
pub message: String,
}

#[derive(Debug, Args, Clone)]
pub struct CreateKeyPairArgs {
#[clap(short, long, default_value = "Burn funds")]
pub key_branch: String,
}
#[derive(Debug, Args, Clone)]
pub struct MakeItRainArgs {
pub destination: TariAddress,
Expand Down
6 changes: 6 additions & 0 deletions applications/minotari_console_wallet/src/wallet_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,8 @@ mod test {
burn-minotari --message Ups_these_funds_will_be_burned! 100T
create-key-pair --key-branch pie
coin-split --message Make_many_dust_UTXOs! --fee-per-gram 2 0.001T 499
make-it-rain --duration 100 --transactions-per-second 10 --start-amount 0.009200T --increase-amount 0T \
Expand All @@ -514,6 +516,7 @@ mod test {
let mut get_balance = false;
let mut send_tari = false;
let mut burn_tari = false;
let mut create_key_pair = false;
let mut make_it_rain = false;
let mut coin_split = false;
let mut discover_peer = false;
Expand All @@ -525,6 +528,8 @@ mod test {
CliCommands::GetBalance => get_balance = true,
CliCommands::SendMinotari(_) => send_tari = true,
CliCommands::BurnMinotari(_) => burn_tari = true,
CliCommands::CreateKeyPair(_) => create_key_pair = true,
CliCommands::SendOneSided(_) => {},
CliCommands::SendOneSidedToStealthAddress(_) => {},
CliCommands::MakeItRain(_) => make_it_rain = true,
CliCommands::CoinSplit(_) => coin_split = true,
Expand Down Expand Up @@ -558,6 +563,7 @@ mod test {
get_balance &&
send_tari &&
burn_tari &&
create_key_pair &&
make_it_rain &&
coin_split &&
discover_peer &&
Expand Down
11 changes: 11 additions & 0 deletions base_layer/core/src/transactions/key_manager/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ use tari_key_manager::{
};
use tari_utilities::{hex::Hex, ByteArray};
use tokio::sync::RwLock;
use zeroize::Zeroizing;

const LOG_TARGET: &str = "c::bn::key_manager::key_manager_service";
const TRANSACTION_KEY_MANAGER_MAX_SEARCH_DEPTH: u64 = 1_000_000;
Expand Down Expand Up @@ -179,6 +180,16 @@ where TBackend: KeyManagerBackend<PublicKey> + 'static
Ok((key_id, key))
}

pub async fn create_key_pair(
&mut self,
branch: &str,
) -> Result<(Zeroizing<PrivateKey>, PublicKey), KeyManagerServiceError> {
self.add_key_manager_branch(branch)?;
let (key_id, public_key) = self.get_next_key(branch).await?;
let private_key = Zeroizing::new(self.get_private_key(&key_id).await?);
Ok((private_key, public_key))
}

pub async fn get_static_key(&self, branch: &str) -> Result<TariKeyId, KeyManagerServiceError> {
match self.key_managers.get(branch) {
None => Err(KeyManagerServiceError::UnknownKeyBranch),
Expand Down
6 changes: 6 additions & 0 deletions base_layer/core/src/transactions/key_manager/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use tari_common_types::types::{ComAndPubSignature, Commitment, PrivateKey, Publi
use tari_comms::types::CommsDHKE;
use tari_crypto::{hashing::DomainSeparatedHash, ristretto::RistrettoComSig};
use tari_key_manager::key_manager_service::{KeyId, KeyManagerInterface, KeyManagerServiceError};
use zeroize::Zeroizing;

use crate::transactions::{
tari_amount::MicroMinotari,
Expand Down Expand Up @@ -274,6 +275,11 @@ pub trait TransactionKeyManagerInterface: KeyManagerInterface<PublicKey> {
amount: &PrivateKey,
claim_public_key: &PublicKey,
) -> Result<RistrettoComSig, TransactionError>;

async fn create_key_pair<T: Into<String> + Send>(
&self,
branch: T,
) -> Result<(Zeroizing<PrivateKey>, PublicKey), KeyManagerServiceError>;
}

#[async_trait::async_trait]
Expand Down
12 changes: 12 additions & 0 deletions base_layer/core/src/transactions/key_manager/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use tari_key_manager::{
},
};
use tokio::sync::RwLock;
use zeroize::Zeroizing;

use crate::transactions::{
key_manager::{
Expand Down Expand Up @@ -480,6 +481,17 @@ where TBackend: KeyManagerBackend<PublicKey> + 'static
.generate_burn_proof(spending_key, amount, claim_public_key)
.await
}

async fn create_key_pair<T: Into<String> + Send>(
&self,
branch: T,
) -> Result<(Zeroizing<PrivateKey>, PublicKey), KeyManagerServiceError> {
self.transaction_key_manager_inner
.write()
.await
.create_key_pair(&branch.into())
.await
}
}

#[async_trait::async_trait]
Expand Down

0 comments on commit c8009c1

Please sign in to comment.