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: adds a create combo key cli command for wallet #4751

Merged
Merged
Show file tree
Hide file tree
Changes from 10 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
28 changes: 26 additions & 2 deletions applications/tari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use tari_app_grpc::authentication::salted_password::create_salted_hashed_passwor
use tari_common_types::{
emoji::EmojiId,
transaction::TxId,
types::{CommitmentFactory, FixedHash, PublicKey},
types::{CommitmentFactory, FixedHash, PrivateKey, PublicKey},
};
use tari_comms::{
connectivity::{ConnectivityEvent, ConnectivityRequester},
Expand All @@ -57,7 +57,7 @@ use tari_utilities::{hex::Hex, ByteArray};
use tari_wallet::{
connectivity_service::WalletConnectivityInterface,
error::WalletError,
key_manager_service::NextKeyResult,
key_manager_service::{storage::database::KeyManagerBackend, KeyManagerHandle, KeyManagerInterface, NextKeyResult},
output_manager_service::{handle::OutputManagerHandle, UtxoSelectionCriteria},
transaction_service::handle::{TransactionEvent, TransactionServiceHandle},
TransactionStage,
Expand All @@ -84,6 +84,7 @@ pub enum WalletCommand {
GetBalance,
SendTari,
SendOneSided,
CreateKeyCombo,
MakeItRain,
CoinSplit,
DiscoverPeer,
Expand Down Expand Up @@ -139,6 +140,16 @@ pub async fn burn_tari(
.map_err(CommandError::TransactionServiceError)
}

pub async fn create_key_combo<TBackend: KeyManagerBackend + 'static>(
jorgeantonio21 marked this conversation as resolved.
Show resolved Hide resolved
key_manager_service: KeyManagerHandle<TBackend>,
key_seed: String,
) -> Result<(PrivateKey, PublicKey), CommandError> {
key_manager_service
.create_key_combo(key_seed)
.await
.map_err(CommandError::KeyManagerError)
}

/// publishes a tari-SHA atomic swap HTLC transaction
pub async fn init_sha_atomic_swap(
mut wallet_transaction_service: TransactionServiceHandle,
Expand Down Expand Up @@ -583,6 +594,7 @@ pub async fn command_runner(

let mut transaction_service = wallet.transaction_service.clone();
let mut output_service = wallet.output_manager_service.clone();
let key_manager_service = wallet.key_manager_service.clone();
let dht_service = wallet.dht_service.discovery_service_requester().clone();
let connectivity_requester = wallet.comms.connectivity();
let mut online = false;
Expand Down Expand Up @@ -637,6 +649,18 @@ pub async fn command_runner(
Err(e) => eprintln!("BurnTari error! {}", e),
}
},
CreateKeyCombo(args) => match create_key_combo(key_manager_service.clone(), args.key_seed).await {
Ok((sk, pk)) => {
println!(
"create new key combo pair:
1. secret key: {},
2. public key {}",
jorgeantonio21 marked this conversation as resolved.
Show resolved Hide resolved
sk.to_hex(),
pk.to_hex()
jorgeantonio21 marked this conversation as resolved.
Show resolved Hide resolved
)
},
Err(e) => eprintln!("CreateKeyCombo error! {}", e),
},
SendTari(args) => {
match send_tari(
transaction_service.clone(),
Expand Down
6 changes: 6 additions & 0 deletions applications/tari_console_wallet/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ pub enum CliCommands {
GetBalance,
SendTari(SendTariArgs),
BurnTari(BurnTariArgs),
CreateKeyCombo(CreateKeyComboArgs),
SendOneSided(SendTariArgs),
SendOneSidedToStealthAddress(SendTariArgs),
MakeItRain(MakeItRainArgs),
Expand Down Expand Up @@ -155,6 +156,11 @@ pub struct BurnTariArgs {
pub message: String,
}

#[derive(Debug, Args, Clone)]
pub struct CreateKeyComboArgs {
pub key_seed: String,
}

#[derive(Debug, Args, Clone)]
pub struct MakeItRainArgs {
pub destination: UniPublicKey,
Expand Down
15 changes: 14 additions & 1 deletion applications/tari_console_wallet/src/wallet_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ mod test {

burn-tari --message Ups_these_funds_will_be_burned! 100T

create-key-combo 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 @@ -444,6 +446,7 @@ mod test {
let mut get_balance = false;
let mut send_tari = false;
let mut burn_tari = false;
let mut create_key_combo = false;
let mut make_it_rain = false;
let mut coin_split = false;
let mut discover_peer = false;
Expand All @@ -453,6 +456,7 @@ mod test {
CliCommands::GetBalance => get_balance = true,
CliCommands::SendTari(_) => send_tari = true,
CliCommands::BurnTari(_) => burn_tari = true,
CliCommands::CreateKeyCombo(_) => create_key_combo = true,
CliCommands::SendOneSided(_) => {},
CliCommands::SendOneSidedToStealthAddress(_) => {},
CliCommands::MakeItRain(_) => make_it_rain = true,
Expand All @@ -472,6 +476,15 @@ mod test {
CliCommands::HashGrpcPassword(_) => {},
}
}
assert!(get_balance && send_tari && burn_tari && make_it_rain && coin_split && discover_peer && whois);
assert!(
get_balance &&
send_tari &&
burn_tari &&
create_key_combo &&
make_it_rain &&
coin_split &&
discover_peer &&
whois
);
}
}
16 changes: 15 additions & 1 deletion base_layer/wallet/src/key_manager_service/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use std::sync::Arc;

use chacha20poly1305::XChaCha20Poly1305;
use tari_common_types::types::PrivateKey;
use tari_common_types::types::{PrivateKey, PublicKey};
use tari_key_manager::cipher_seed::CipherSeed;
use tokio::sync::RwLock;

Expand Down Expand Up @@ -73,6 +73,20 @@ where TBackend: KeyManagerBackend + 'static
(*self.key_manager_inner).write().await.apply_encryption(cipher)
}

async fn create_key_combo(&self, key_seed: String) -> Result<(PrivateKey, PublicKey), KeyManagerServiceError> {
(*self.key_manager_inner)
jorgeantonio21 marked this conversation as resolved.
Show resolved Hide resolved
.write()
.await
.add_key_manager_branch(key_seed.clone())?;
jorgeantonio21 marked this conversation as resolved.
Show resolved Hide resolved

let next_key = self.get_next_key(key_seed).await?;
let sk = next_key.key.clone();
let pk = next_key.to_public_key();
// (*self.key_manager_inner).read().await.get_next_key(branch).await;
jorgeantonio21 marked this conversation as resolved.
Show resolved Hide resolved

Ok((sk, pk))
}

async fn remove_encryption(&self) -> Result<(), KeyManagerServiceError> {
(*self.key_manager_inner).write().await.remove_encryption()
}
Expand Down
3 changes: 3 additions & 0 deletions base_layer/wallet/src/key_manager_service/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ pub trait KeyManagerInterface: Clone + Send + Sync + 'static {
index: u64,
) -> Result<PrivateKey, KeyManagerServiceError>;

/// Gets new key combo pair out of a key seed
async fn create_key_combo(&self, key_seed: String) -> Result<(PrivateKey, PublicKey), KeyManagerServiceError>;

/// Searches the branch to find the index used to generated the key, O(N) where N = index used.
async fn find_key_index<T: Into<String> + Send>(
&self,
Expand Down
6 changes: 5 additions & 1 deletion base_layer/wallet/src/key_manager_service/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

use chacha20poly1305::XChaCha20Poly1305;
use log::*;
use tari_common_types::types::PrivateKey;
use tari_common_types::types::{PrivateKey, PublicKey};
use tari_key_manager::{cipher_seed::CipherSeed, key_manager::KeyManager};
use tokio::sync::RwLock;

Expand Down Expand Up @@ -162,6 +162,10 @@ impl KeyManagerInterface for KeyManagerMock {
unimplemented!("Not supported");
}

async fn create_key_combo(&self, _key_seed: String) -> Result<(PrivateKey, PublicKey), KeyManagerServiceError> {
unimplemented!("Not supported");
}

async fn find_key_index<T: Into<String> + Send>(
&self,
branch: T,
Expand Down
2 changes: 0 additions & 2 deletions infrastructure/tari_script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@ serde = "1.0.136"
sha2 = "0.9"
sha3 = "0.9"
thiserror = "1.0.30"

[dev-dependencies]
jorgeantonio21 marked this conversation as resolved.
Show resolved Hide resolved
rand = "0.8.5"