From 62a6c03bf414042161345903f4bfaf640633f7b2 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Tue, 27 Sep 2022 18:13:23 +0100 Subject: [PATCH 01/30] first commit, add handle to verify aggregate signatures --- infrastructure/tari_script/Cargo.toml | 2 - infrastructure/tari_script/src/op_codes.rs | 2 + infrastructure/tari_script/src/script.rs | 53 +++++++++++++++++++++- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/infrastructure/tari_script/Cargo.toml b/infrastructure/tari_script/Cargo.toml index 51b0cac28f..3f9a5694c3 100644 --- a/infrastructure/tari_script/Cargo.toml +++ b/infrastructure/tari_script/Cargo.toml @@ -21,6 +21,4 @@ serde = "1.0.136" sha2 = "0.9" sha3 = "0.9" thiserror = "1.0.30" - -[dev-dependencies] rand = "0.8.5" diff --git a/infrastructure/tari_script/src/op_codes.rs b/infrastructure/tari_script/src/op_codes.rs index 944fac641c..0c44dd10a6 100644 --- a/infrastructure/tari_script/src/op_codes.rs +++ b/infrastructure/tari_script/src/op_codes.rs @@ -232,6 +232,8 @@ pub enum Opcode { /// Identical to CheckMultiSig, except that nothing is pushed to the stack if the m signatures are valid, and the /// operation fails with VERIFY_FAILED if any of the signatures are invalid. CheckMultiSigVerify(u8, u8, Vec, Box), + /// Pop m signatures from the stack. A leader aggregates n public keys and adds them to the script. + CheckMultiSigVerifyAggregatePubKey(u8, u8, Vec, Box), // Miscellaneous /// Always fails with VERIFY_FAILED. diff --git a/infrastructure/tari_script/src/script.rs b/infrastructure/tari_script/src/script.rs index d3e4eeabba..9a3df65f71 100644 --- a/infrastructure/tari_script/src/script.rs +++ b/infrastructure/tari_script/src/script.rs @@ -19,14 +19,16 @@ use std::{cmp::Ordering, collections::HashSet, convert::TryFrom, fmt, ops::Deref}; use digest::Digest; +use rand::{distributions::Uniform, thread_rng, Rng}; use sha2::Sha256; use sha3::Sha3_256; use tari_crypto::{ hash::blake2::Blake256, - ristretto::{RistrettoPublicKey, RistrettoSchnorr, RistrettoSecretKey}, + ristretto::{RistrettoPublicKey, RistrettoSchnorr, RistrettoSecretKey}, signatures::CommitmentSignature, }; use tari_utilities::{ hex::{from_hex, to_hex, Hex, HexError}, + message_format, ByteArray, }; @@ -260,6 +262,12 @@ impl TariScript { Err(ScriptError::VerifyFailed) } }, + CheckMultiSigVerifyAggregatePubKey(m, n, public_keys, msg) => { + let mut rng = thread_rng(); + let leader_index = rng.sample::(Uniform::new(0, n)) as usize; + let leader_pubkey = public_keys[leader_index].clone(); + Ok(()) + }, Return => Err(ScriptError::Return), IfThen => TariScript::handle_if_then(stack, state), Else => TariScript::handle_else(state), @@ -537,6 +545,49 @@ impl TariScript { Ok(sig_set.len() == m) } + + fn handle_multisig_verify_aggregate_signature( + stack: &mut ExecutionStack, + m: u8, + n: u8, + public_keys: &[RistrettoPublicKey], + message: Message, + ) -> Result<(), ScriptError> { + if m == 0 || n == 0 || m > n || n > MAX_MULTISIG_LIMIT { + return Err(ScriptError::InvalidData); + } + + let mut rng = thread_rng(); + let leader_index = rng.sample::(Uniform::new(0, n)) as usize; + let leader_pubkey = public_keys[leader_index].clone(); + + let m = m as usize; + + let signatures = stack + .pop_num_items(m)? + .into_iter() + .map(|item| match item { + StackItem::Signature(s) => Ok(s), + _ => Err(ScriptError::IncompatibleTypes), + }) + .collect::, ScriptError>>(); + + let value = match stack.pop() { + Some(StackItem::Number(val)) => val, + Some(_) => return Err(ScriptError::IncompatibleTypes), + None => return Err(ScriptError::StackUnderflow), + }; + + let sender_key = match stack.pop() { + Some(StackItem::PublicKey(p)) => p, + Some(_) => return Err(ScriptError::IncompatibleTypes), + None => return Err(ScriptError::StackUnderflow), + }; + + // TODO: broadcast message among the m wallets + + Ok(()) + } } impl Hex for TariScript { From 061f5e2e2353b4d227fb6664cb5cbebd4b9583a6 Mon Sep 17 00:00:00 2001 From: Hansie Odendaal Date: Mon, 26 Sep 2022 17:58:06 +0200 Subject: [PATCH 02/30] Add multisig script with agg pk Added an m-of-n multisig TariScript that returns the aggregate public key of the signatories if successful and fails otherwise. --- infrastructure/tari_script/src/op_codes.rs | 35 ++++++++++- infrastructure/tari_script/src/script.rs | 70 +++++++++++++++++----- 2 files changed, 88 insertions(+), 17 deletions(-) diff --git a/infrastructure/tari_script/src/op_codes.rs b/infrastructure/tari_script/src/op_codes.rs index 944fac641c..c3df8b5de4 100644 --- a/infrastructure/tari_script/src/op_codes.rs +++ b/infrastructure/tari_script/src/op_codes.rs @@ -116,6 +116,7 @@ pub const OP_CHECK_MULTI_SIG_VERIFY: u8 = 0xaf; pub const OP_HASH_BLAKE256: u8 = 0xb0; pub const OP_HASH_SHA256: u8 = 0xb1; pub const OP_HASH_SHA3: u8 = 0xb2; +pub const OP_CHECK_MULTI_SIG_VERIFY_AGGREGATE_PUB_KEY: u8 = 0xb3; // Opcode constants: Miscellaneous pub const OP_RETURN: u8 = 0x60; @@ -232,6 +233,9 @@ pub enum Opcode { /// Identical to CheckMultiSig, except that nothing is pushed to the stack if the m signatures are valid, and the /// operation fails with VERIFY_FAILED if any of the signatures are invalid. CheckMultiSigVerify(u8, u8, Vec, Box), + /// Pop m signatures from the stack. If m signatures out of the provided n public keys sign the 32-byte message, + /// push the aggregate of the public keys to the stack, otherwise fails with VERIFY_FAILED. + CheckMultiSigVerifyAggregatePubKey(u8, u8, Vec, Box), // Miscellaneous /// Always fails with VERIFY_FAILED. @@ -350,6 +354,10 @@ impl Opcode { let (m, n, keys, msg, end) = Opcode::read_multisig_args(bytes)?; Ok((CheckMultiSigVerify(m, n, keys, msg), &bytes[end..])) }, + OP_CHECK_MULTI_SIG_VERIFY_AGGREGATE_PUB_KEY => { + let (m, n, keys, msg, end) = Opcode::read_multisig_args(bytes)?; + Ok((CheckMultiSigVerifyAggregatePubKey(m, n, keys, msg), &bytes[end..])) + }, OP_RETURN => Ok((Return, &bytes[1..])), OP_IF_THEN => Ok((IfThen, &bytes[1..])), OP_ELSE => Ok((Else, &bytes[1..])), @@ -458,6 +466,13 @@ impl Opcode { } array.extend_from_slice(msg.deref()); }, + CheckMultiSigVerifyAggregatePubKey(m, n, public_keys, msg) => { + array.extend_from_slice(&[OP_CHECK_MULTI_SIG_VERIFY_AGGREGATE_PUB_KEY, *m, *n]); + for public_key in public_keys { + array.extend(public_key.to_vec()); + } + array.extend_from_slice(msg.deref()); + }, Return => array.push(OP_RETURN), IfThen => array.push(OP_IF_THEN), Else => array.push(OP_ELSE), @@ -521,6 +536,16 @@ impl fmt::Display for Opcode { (*msg).to_hex() )) }, + CheckMultiSigVerifyAggregatePubKey(m, n, public_keys, msg) => { + let keys: Vec = public_keys.iter().map(|p| p.to_hex()).collect(); + fmt.write_str(&format!( + "CheckMultiSigVerifyAggregatePubKey({}, {}, [{}], {})", + *m, + *n, + keys.join(", "), + (*msg).to_hex() + )) + }, Return => fmt.write_str("Return"), IfThen => fmt.write_str("IfThen"), Else => fmt.write_str("Else"), @@ -761,12 +786,20 @@ mod test { 6c9cb4d3e57351462122310fa22c90b1e6dfb528d64615363d1261a75da3e401)", ); test_checkmultisig( - &Opcode::CheckMultiSigVerify(1, 2, keys, Box::new(*msg)), + &Opcode::CheckMultiSigVerify(1, 2, keys.clone(), Box::new(*msg)), OP_CHECK_MULTI_SIG_VERIFY, "CheckMultiSigVerify(1, 2, [9c8bc5f90d221191748e8dd7686f09e1114b4bada4c367ed58ae199c51eb100b, \ 56e9f018b138ba843521b3243a29d81730c3a4c25108b108b1ca47c2132db569], \ 6c9cb4d3e57351462122310fa22c90b1e6dfb528d64615363d1261a75da3e401)", ); + test_checkmultisig( + &Opcode::CheckMultiSigVerifyAggregatePubKey(1, 2, keys, Box::new(*msg)), + OP_CHECK_MULTI_SIG_VERIFY_AGGREGATE_PUB_KEY, + "CheckMultiSigVerifyAggregatePubKey(1, 2, \ + [9c8bc5f90d221191748e8dd7686f09e1114b4bada4c367ed58ae199c51eb100b, \ + 56e9f018b138ba843521b3243a29d81730c3a4c25108b108b1ca47c2132db569], \ + 6c9cb4d3e57351462122310fa22c90b1e6dfb528d64615363d1261a75da3e401)", + ); } #[test] diff --git a/infrastructure/tari_script/src/script.rs b/infrastructure/tari_script/src/script.rs index d3e4eeabba..1b275890a4 100644 --- a/infrastructure/tari_script/src/script.rs +++ b/infrastructure/tari_script/src/script.rs @@ -247,19 +247,26 @@ impl TariScript { } }, CheckMultiSig(m, n, public_keys, msg) => { - if self.check_multisig(stack, *m, *n, public_keys, *msg.deref())? { + if self.check_multisig(stack, *m, *n, public_keys, *msg.deref())?.is_some() { stack.push(Number(1)) } else { stack.push(Number(0)) } }, CheckMultiSigVerify(m, n, public_keys, msg) => { - if self.check_multisig(stack, *m, *n, public_keys, *msg.deref())? { + if self.check_multisig(stack, *m, *n, public_keys, *msg.deref())?.is_some() { Ok(()) } else { Err(ScriptError::VerifyFailed) } }, + CheckMultiSigVerifyAggregatePubKey(m, n, public_keys, msg) => { + if let Some(agg_pub_key) = self.check_multisig(stack, *m, *n, public_keys, *msg.deref())? { + stack.push(PublicKey(agg_pub_key)) + } else { + Err(ScriptError::VerifyFailed) + } + }, Return => Err(ScriptError::Return), IfThen => TariScript::handle_if_then(stack, state), Else => TariScript::handle_else(state), @@ -503,9 +510,9 @@ impl TariScript { n: u8, public_keys: &[RistrettoPublicKey], message: Message, - ) -> Result { - if m == 0 || n == 0 || m > n || n > MAX_MULTISIG_LIMIT { - return Err(ScriptError::InvalidData); + ) -> Result, ScriptError> { + if m == 0 || n == 0 || m > n || n > MAX_MULTISIG_LIMIT || public_keys.len() != n as usize { + return Err(ScriptError::ValueExceedsBounds); } // pop m sigs let m = m as usize; @@ -522,20 +529,25 @@ impl TariScript { #[allow(clippy::mutable_key_type)] let mut sig_set = HashSet::new(); + let mut agg_pub_key = RistrettoPublicKey::default(); for s in &signatures { for (i, pk) in public_keys.iter().enumerate() { if !sig_set.contains(s) && !key_signed[i] && s.verify_challenge(pk, &message) { key_signed[i] = true; sig_set.insert(s); + agg_pub_key = agg_pub_key + pk; break; } } if !sig_set.contains(s) { - return Ok(false); + return Ok(None); } } - - Ok(sig_set.len() == m) + if sig_set.len() == m { + Ok(Some(agg_pub_key)) + } else { + Ok(None) + } } } @@ -610,6 +622,7 @@ mod test { inputs, op_codes::{slice_to_boxed_hash, slice_to_boxed_message, HashValue, Message}, ExecutionStack, + Opcode::CheckMultiSigVerifyAggregatePubKey, ScriptContext, StackItem, StackItem::{Commitment, Hash, Number}, @@ -1130,21 +1143,21 @@ mod test { let script = TariScript::new(ops); let inputs = inputs!(s_alice.clone()); let err = script.execute(&inputs).unwrap_err(); - assert_eq!(err, ScriptError::InvalidData); + assert_eq!(err, ScriptError::ValueExceedsBounds); let keys = vec![p_alice.clone(), p_bob.clone()]; let ops = vec![CheckMultiSig(1, 0, keys, msg.clone())]; let script = TariScript::new(ops); let inputs = inputs!(s_alice.clone()); let err = script.execute(&inputs).unwrap_err(); - assert_eq!(err, ScriptError::InvalidData); + assert_eq!(err, ScriptError::ValueExceedsBounds); let keys = vec![p_alice, p_bob]; let ops = vec![CheckMultiSig(2, 1, keys, msg)]; let script = TariScript::new(ops); let inputs = inputs!(s_alice); let err = script.execute(&inputs).unwrap_err(); - assert_eq!(err, ScriptError::InvalidData); + assert_eq!(err, ScriptError::ValueExceedsBounds); // max n is 32 let (msg, data) = multisig_data(33); @@ -1154,7 +1167,7 @@ mod test { let items = sigs.map(StackItem::Signature).collect(); let inputs = ExecutionStack::new(items); let err = script.execute(&inputs).unwrap_err(); - assert_eq!(err, ScriptError::InvalidData); + assert_eq!(err, ScriptError::ValueExceedsBounds); // 3 of 4 let (msg, data) = multisig_data(4); @@ -1243,7 +1256,7 @@ mod test { // 1 of 3 let keys = vec![p_alice.clone(), p_bob.clone(), p_carol.clone()]; - let ops = vec![CheckMultiSigVerify(1, 2, keys, msg.clone())]; + let ops = vec![CheckMultiSigVerify(1, 3, keys, msg.clone())]; let script = TariScript::new(ops); let inputs = inputs!(Number(1), s_alice.clone()); @@ -1277,6 +1290,31 @@ mod test { let err = script.execute(&inputs).unwrap_err(); assert_eq!(err, ScriptError::VerifyFailed); + // 2 of 3 (returning the aggregate public key of the signatories) + let keys = vec![p_alice.clone(), p_bob.clone(), p_carol.clone()]; + let ops = vec![CheckMultiSigVerifyAggregatePubKey(2, 3, keys, msg.clone())]; + let script = TariScript::new(ops); + + let inputs = inputs!(s_alice.clone(), s_bob.clone()); + let agg_pub_key = script.execute(&inputs).unwrap(); + assert_eq!(agg_pub_key, StackItem::PublicKey(p_alice.clone() + p_bob.clone())); + + let inputs = inputs!(s_alice.clone(), s_carol.clone()); + let agg_pub_key = script.execute(&inputs).unwrap(); + assert_eq!(agg_pub_key, StackItem::PublicKey(p_alice.clone() + p_carol.clone())); + + let inputs = inputs!(s_bob.clone(), s_carol.clone()); + let agg_pub_key = script.execute(&inputs).unwrap(); + assert_eq!(agg_pub_key, StackItem::PublicKey(p_bob.clone() + p_carol.clone())); + + let inputs = inputs!(s_alice.clone(), s_carol.clone(), s_bob.clone()); + let err = script.execute(&inputs).unwrap_err(); + assert_eq!(err, ScriptError::NonUnitLengthStack); + + let inputs = inputs!(p_bob.clone()); + let err = script.execute(&inputs).unwrap_err(); + assert_eq!(err, ScriptError::StackUnderflow); + // 3 of 3 let keys = vec![p_alice.clone(), p_bob.clone(), p_carol]; let ops = vec![CheckMultiSigVerify(3, 3, keys, msg.clone())]; @@ -1298,21 +1336,21 @@ mod test { let script = TariScript::new(ops); let inputs = inputs!(s_alice.clone()); let err = script.execute(&inputs).unwrap_err(); - assert_eq!(err, ScriptError::InvalidData); + assert_eq!(err, ScriptError::ValueExceedsBounds); let keys = vec![p_alice.clone(), p_bob.clone()]; let ops = vec![CheckMultiSigVerify(1, 0, keys, msg.clone())]; let script = TariScript::new(ops); let inputs = inputs!(s_alice.clone()); let err = script.execute(&inputs).unwrap_err(); - assert_eq!(err, ScriptError::InvalidData); + assert_eq!(err, ScriptError::ValueExceedsBounds); let keys = vec![p_alice, p_bob]; let ops = vec![CheckMultiSigVerify(2, 1, keys, msg)]; let script = TariScript::new(ops); let inputs = inputs!(s_alice); let err = script.execute(&inputs).unwrap_err(); - assert_eq!(err, ScriptError::InvalidData); + assert_eq!(err, ScriptError::ValueExceedsBounds); // 3 of 4 let (msg, data) = multisig_data(4); From 40b3dee4f337891fcef60b73d6e5ba7efbdb264b Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Wed, 28 Sep 2022 17:06:16 +0100 Subject: [PATCH 03/30] add create_key_combo method for wallet cli --- .../src/automation/commands.rs | 29 ++++++++-- applications/tari_console_wallet/src/cli.rs | 6 +++ .../wallet/src/key_manager_service/handle.rs | 22 +++++++- .../src/key_manager_service/interface.rs | 5 +- .../wallet/src/key_manager_service/mock.rs | 6 ++- .../wallet/src/key_manager_service/mod.rs | 2 +- infrastructure/tari_script/src/op_codes.rs | 4 +- infrastructure/tari_script/src/script.rs | 53 +------------------ 8 files changed, 65 insertions(+), 62 deletions(-) diff --git a/applications/tari_console_wallet/src/automation/commands.rs b/applications/tari_console_wallet/src/automation/commands.rs index e3461968a6..858e52deef 100644 --- a/applications/tari_console_wallet/src/automation/commands.rs +++ b/applications/tari_console_wallet/src/automation/commands.rs @@ -49,10 +49,13 @@ use tari_comms::{ types::CommsPublicKey, }; use tari_comms_dht::{envelope::NodeDestination, DhtDiscoveryRequester}; -use tari_core::transactions::{ - tari_amount::{uT, MicroTari, Tari}, - transaction_components::{OutputFeatures, TransactionOutput, UnblindedOutput}, +use tari_core::{ + transactions::{ + tari_amount::{uT, MicroTari, Tari}, + transaction_components::{OutputFeatures, TransactionOutput, UnblindedOutput}, + }, }; +use tari_wallet::key_manager_service::{KeyManagerHandle, KeyComboPair, storage::database::KeyManagerBackend, KeyManagerInterface}; use tari_utilities::{hex::Hex, ByteArray}; use tari_wallet::{ connectivity_service::WalletConnectivityInterface, @@ -84,6 +87,7 @@ pub enum WalletCommand { GetBalance, SendTari, SendOneSided, + CreateKeyCombo, MakeItRain, CoinSplit, DiscoverPeer, @@ -139,6 +143,16 @@ pub async fn burn_tari( .map_err(CommandError::TransactionServiceError) } +pub async fn create_key_combo( + key_manager_service: KeyManagerHandle, + key_seed: String, +) -> Result { + 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, @@ -583,6 +597,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; @@ -637,6 +652,14 @@ 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(KeyComboPair { sk, pk }) => { + debug!(target: LOG_TARGET, "create new key combo pair: sk {:?}, pk {:?} ", sk, pk) + } + Err(e) => eprintln!("CreateKeyCombo error! {}", e), + } + }, SendTari(args) => { match send_tari( transaction_service.clone(), diff --git a/applications/tari_console_wallet/src/cli.rs b/applications/tari_console_wallet/src/cli.rs index 96b3faf5af..891b0511ff 100644 --- a/applications/tari_console_wallet/src/cli.rs +++ b/applications/tari_console_wallet/src/cli.rs @@ -116,6 +116,7 @@ pub enum CliCommands { GetBalance, SendTari(SendTariArgs), BurnTari(BurnTariArgs), + CreateKeyCombo(CreateKeyComboArgs), SendOneSided(SendTariArgs), SendOneSidedToStealthAddress(SendTariArgs), MakeItRain(MakeItRainArgs), @@ -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, diff --git a/base_layer/wallet/src/key_manager_service/handle.rs b/base_layer/wallet/src/key_manager_service/handle.rs index 78b1454e06..f26121168d 100644 --- a/base_layer/wallet/src/key_manager_service/handle.rs +++ b/base_layer/wallet/src/key_manager_service/handle.rs @@ -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; @@ -45,6 +45,12 @@ pub struct KeyManagerHandle { key_manager_inner: Arc>>, } +/// Simple structure to encapsulate a private/public pair +pub struct KeyComboPair { + pub sk: PrivateKey, + pub pk: PublicKey, +} + impl KeyManagerHandle where TBackend: KeyManagerBackend + 'static { @@ -73,6 +79,20 @@ where TBackend: KeyManagerBackend + 'static (*self.key_manager_inner).write().await.apply_encryption(cipher) } + async fn create_key_combo(&self, key_seed: String) -> Result { + (*self.key_manager_inner) + .write() + .await + .add_key_manager_branch(key_seed.clone())?; + + 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; + + Ok(KeyComboPair { sk, pk }) + } + async fn remove_encryption(&self) -> Result<(), KeyManagerServiceError> { (*self.key_manager_inner).write().await.remove_encryption() } diff --git a/base_layer/wallet/src/key_manager_service/interface.rs b/base_layer/wallet/src/key_manager_service/interface.rs index a03266e03c..e130469ed5 100644 --- a/base_layer/wallet/src/key_manager_service/interface.rs +++ b/base_layer/wallet/src/key_manager_service/interface.rs @@ -24,7 +24,7 @@ use chacha20poly1305::XChaCha20Poly1305; use tari_common_types::types::{PrivateKey, PublicKey}; use tari_crypto::keys::PublicKey as PublicKeyTrait; -use crate::key_manager_service::error::KeyManagerServiceError; +use crate::key_manager_service::{error::KeyManagerServiceError, handle::KeyComboPair}; /// The value returned from [add_new_branch]. `AlreadyExists` is returned if the branch was previously created, /// otherwise `NewEntry` is returned. @@ -72,6 +72,9 @@ pub trait KeyManagerInterface: Clone + Send + Sync + 'static { index: u64, ) -> Result; + /// Gets new key combo pair out of a key seed + async fn create_key_combo(&self, key_seed: String) -> Result; + /// Searches the branch to find the index used to generated the key, O(N) where N = index used. async fn find_key_index + Send>( &self, diff --git a/base_layer/wallet/src/key_manager_service/mock.rs b/base_layer/wallet/src/key_manager_service/mock.rs index 3a9ba2a3da..ca9ed06018 100644 --- a/base_layer/wallet/src/key_manager_service/mock.rs +++ b/base_layer/wallet/src/key_manager_service/mock.rs @@ -27,7 +27,7 @@ use tari_key_manager::{cipher_seed::CipherSeed, key_manager::KeyManager}; use tokio::sync::RwLock; use crate::{ - key_manager_service::{interface::NextKeyResult, AddResult, KeyManagerInterface}, + key_manager_service::{handle::KeyComboPair, interface::NextKeyResult, AddResult, KeyManagerInterface}, types::KeyDigest, }; @@ -162,6 +162,10 @@ impl KeyManagerInterface for KeyManagerMock { unimplemented!("Not supported"); } + async fn create_key_combo(&self, _key_seed: String) -> Result { + unimplemented!("Not supported"); + } + async fn find_key_index + Send>( &self, branch: T, diff --git a/base_layer/wallet/src/key_manager_service/mod.rs b/base_layer/wallet/src/key_manager_service/mod.rs index 5d4f8af137..3c657d0212 100644 --- a/base_layer/wallet/src/key_manager_service/mod.rs +++ b/base_layer/wallet/src/key_manager_service/mod.rs @@ -24,7 +24,7 @@ mod error; pub use error::KeyManagerServiceError; mod handle; -pub use handle::KeyManagerHandle; +pub use handle::{KeyComboPair, KeyManagerHandle}; mod initializer; pub use initializer::KeyManagerInitializer; diff --git a/infrastructure/tari_script/src/op_codes.rs b/infrastructure/tari_script/src/op_codes.rs index 0c44dd10a6..1916ce1a18 100644 --- a/infrastructure/tari_script/src/op_codes.rs +++ b/infrastructure/tari_script/src/op_codes.rs @@ -232,9 +232,7 @@ pub enum Opcode { /// Identical to CheckMultiSig, except that nothing is pushed to the stack if the m signatures are valid, and the /// operation fails with VERIFY_FAILED if any of the signatures are invalid. CheckMultiSigVerify(u8, u8, Vec, Box), - /// Pop m signatures from the stack. A leader aggregates n public keys and adds them to the script. - CheckMultiSigVerifyAggregatePubKey(u8, u8, Vec, Box), - + // Miscellaneous /// Always fails with VERIFY_FAILED. Return, diff --git a/infrastructure/tari_script/src/script.rs b/infrastructure/tari_script/src/script.rs index 9a3df65f71..d3e4eeabba 100644 --- a/infrastructure/tari_script/src/script.rs +++ b/infrastructure/tari_script/src/script.rs @@ -19,16 +19,14 @@ use std::{cmp::Ordering, collections::HashSet, convert::TryFrom, fmt, ops::Deref}; use digest::Digest; -use rand::{distributions::Uniform, thread_rng, Rng}; use sha2::Sha256; use sha3::Sha3_256; use tari_crypto::{ hash::blake2::Blake256, - ristretto::{RistrettoPublicKey, RistrettoSchnorr, RistrettoSecretKey}, signatures::CommitmentSignature, + ristretto::{RistrettoPublicKey, RistrettoSchnorr, RistrettoSecretKey}, }; use tari_utilities::{ hex::{from_hex, to_hex, Hex, HexError}, - message_format, ByteArray, }; @@ -262,12 +260,6 @@ impl TariScript { Err(ScriptError::VerifyFailed) } }, - CheckMultiSigVerifyAggregatePubKey(m, n, public_keys, msg) => { - let mut rng = thread_rng(); - let leader_index = rng.sample::(Uniform::new(0, n)) as usize; - let leader_pubkey = public_keys[leader_index].clone(); - Ok(()) - }, Return => Err(ScriptError::Return), IfThen => TariScript::handle_if_then(stack, state), Else => TariScript::handle_else(state), @@ -545,49 +537,6 @@ impl TariScript { Ok(sig_set.len() == m) } - - fn handle_multisig_verify_aggregate_signature( - stack: &mut ExecutionStack, - m: u8, - n: u8, - public_keys: &[RistrettoPublicKey], - message: Message, - ) -> Result<(), ScriptError> { - if m == 0 || n == 0 || m > n || n > MAX_MULTISIG_LIMIT { - return Err(ScriptError::InvalidData); - } - - let mut rng = thread_rng(); - let leader_index = rng.sample::(Uniform::new(0, n)) as usize; - let leader_pubkey = public_keys[leader_index].clone(); - - let m = m as usize; - - let signatures = stack - .pop_num_items(m)? - .into_iter() - .map(|item| match item { - StackItem::Signature(s) => Ok(s), - _ => Err(ScriptError::IncompatibleTypes), - }) - .collect::, ScriptError>>(); - - let value = match stack.pop() { - Some(StackItem::Number(val)) => val, - Some(_) => return Err(ScriptError::IncompatibleTypes), - None => return Err(ScriptError::StackUnderflow), - }; - - let sender_key = match stack.pop() { - Some(StackItem::PublicKey(p)) => p, - Some(_) => return Err(ScriptError::IncompatibleTypes), - None => return Err(ScriptError::StackUnderflow), - }; - - // TODO: broadcast message among the m wallets - - Ok(()) - } } impl Hex for TariScript { From fc29b2f0359be244caf1852ac6bc53bcd7de41b8 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Wed, 28 Sep 2022 17:19:53 +0100 Subject: [PATCH 04/30] execute cargo fmt --- .../src/automation/commands.rs | 32 +++++++++++-------- infrastructure/tari_script/src/op_codes.rs | 2 +- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/applications/tari_console_wallet/src/automation/commands.rs b/applications/tari_console_wallet/src/automation/commands.rs index 858e52deef..665f4df3de 100644 --- a/applications/tari_console_wallet/src/automation/commands.rs +++ b/applications/tari_console_wallet/src/automation/commands.rs @@ -49,18 +49,21 @@ use tari_comms::{ types::CommsPublicKey, }; use tari_comms_dht::{envelope::NodeDestination, DhtDiscoveryRequester}; -use tari_core::{ - transactions::{ - tari_amount::{uT, MicroTari, Tari}, - transaction_components::{OutputFeatures, TransactionOutput, UnblindedOutput}, - }, +use tari_core::transactions::{ + tari_amount::{uT, MicroTari, Tari}, + transaction_components::{OutputFeatures, TransactionOutput, UnblindedOutput}, }; -use tari_wallet::key_manager_service::{KeyManagerHandle, KeyComboPair, storage::database::KeyManagerBackend, KeyManagerInterface}; use tari_utilities::{hex::Hex, ByteArray}; use tari_wallet::{ connectivity_service::WalletConnectivityInterface, error::WalletError, - key_manager_service::NextKeyResult, + key_manager_service::{ + storage::database::KeyManagerBackend, + KeyComboPair, + KeyManagerHandle, + KeyManagerInterface, + NextKeyResult, + }, output_manager_service::{handle::OutputManagerHandle, UtxoSelectionCriteria}, transaction_service::handle::{TransactionEvent, TransactionServiceHandle}, TransactionStage, @@ -652,13 +655,14 @@ 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(KeyComboPair { sk, pk }) => { - debug!(target: LOG_TARGET, "create new key combo pair: sk {:?}, pk {:?} ", sk, pk) - } - Err(e) => eprintln!("CreateKeyCombo error! {}", e), - } + CreateKeyCombo(args) => match create_key_combo(key_manager_service.clone(), args.key_seed).await { + Ok(KeyComboPair { sk, pk }) => { + debug!( + target: LOG_TARGET, + "create new key combo pair: sk {:?}, pk {:?} ", sk, pk + ) + }, + Err(e) => eprintln!("CreateKeyCombo error! {}", e), }, SendTari(args) => { match send_tari( diff --git a/infrastructure/tari_script/src/op_codes.rs b/infrastructure/tari_script/src/op_codes.rs index 1916ce1a18..944fac641c 100644 --- a/infrastructure/tari_script/src/op_codes.rs +++ b/infrastructure/tari_script/src/op_codes.rs @@ -232,7 +232,7 @@ pub enum Opcode { /// Identical to CheckMultiSig, except that nothing is pushed to the stack if the m signatures are valid, and the /// operation fails with VERIFY_FAILED if any of the signatures are invalid. CheckMultiSigVerify(u8, u8, Vec, Box), - + // Miscellaneous /// Always fails with VERIFY_FAILED. Return, From d41e44a799b813a8307bebe33fd78ad6cb4cb650 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Wed, 28 Sep 2022 17:42:35 +0100 Subject: [PATCH 05/30] add refactor on PR comments plus add test --- .../src/automation/commands.rs | 19 +++++-------------- .../tari_console_wallet/src/wallet_modes.rs | 15 ++++++++++++++- .../wallet/src/key_manager_service/handle.rs | 10 ++-------- .../src/key_manager_service/interface.rs | 4 ++-- .../wallet/src/key_manager_service/mock.rs | 6 +++--- .../wallet/src/key_manager_service/mod.rs | 2 +- 6 files changed, 27 insertions(+), 29 deletions(-) diff --git a/applications/tari_console_wallet/src/automation/commands.rs b/applications/tari_console_wallet/src/automation/commands.rs index 665f4df3de..a4805b275d 100644 --- a/applications/tari_console_wallet/src/automation/commands.rs +++ b/applications/tari_console_wallet/src/automation/commands.rs @@ -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}, @@ -57,13 +57,7 @@ use tari_utilities::{hex::Hex, ByteArray}; use tari_wallet::{ connectivity_service::WalletConnectivityInterface, error::WalletError, - key_manager_service::{ - storage::database::KeyManagerBackend, - KeyComboPair, - KeyManagerHandle, - KeyManagerInterface, - NextKeyResult, - }, + key_manager_service::{storage::database::KeyManagerBackend, KeyManagerHandle, KeyManagerInterface, NextKeyResult}, output_manager_service::{handle::OutputManagerHandle, UtxoSelectionCriteria}, transaction_service::handle::{TransactionEvent, TransactionServiceHandle}, TransactionStage, @@ -149,7 +143,7 @@ pub async fn burn_tari( pub async fn create_key_combo( key_manager_service: KeyManagerHandle, key_seed: String, -) -> Result { +) -> Result<(PrivateKey, PublicKey), CommandError> { key_manager_service .create_key_combo(key_seed) .await @@ -656,11 +650,8 @@ pub async fn command_runner( } }, CreateKeyCombo(args) => match create_key_combo(key_manager_service.clone(), args.key_seed).await { - Ok(KeyComboPair { sk, pk }) => { - debug!( - target: LOG_TARGET, - "create new key combo pair: sk {:?}, pk {:?} ", sk, pk - ) + Ok((sk, pk)) => { + println!("create new key combo pair: sk {:?}, pk {:?} ", sk, pk) }, Err(e) => eprintln!("CreateKeyCombo error! {}", e), }, diff --git a/applications/tari_console_wallet/src/wallet_modes.rs b/applications/tari_console_wallet/src/wallet_modes.rs index 9bf3e65b38..554563a6a2 100644 --- a/applications/tari_console_wallet/src/wallet_modes.rs +++ b/applications/tari_console_wallet/src/wallet_modes.rs @@ -429,6 +429,8 @@ mod test { burn-tari --message Ups_these_funds_will_be_burned! 100T + create-key-combo --key_seed 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 \ @@ -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; @@ -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, @@ -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 + ); } } diff --git a/base_layer/wallet/src/key_manager_service/handle.rs b/base_layer/wallet/src/key_manager_service/handle.rs index f26121168d..2a6e8d237a 100644 --- a/base_layer/wallet/src/key_manager_service/handle.rs +++ b/base_layer/wallet/src/key_manager_service/handle.rs @@ -45,12 +45,6 @@ pub struct KeyManagerHandle { key_manager_inner: Arc>>, } -/// Simple structure to encapsulate a private/public pair -pub struct KeyComboPair { - pub sk: PrivateKey, - pub pk: PublicKey, -} - impl KeyManagerHandle where TBackend: KeyManagerBackend + 'static { @@ -79,7 +73,7 @@ where TBackend: KeyManagerBackend + 'static (*self.key_manager_inner).write().await.apply_encryption(cipher) } - async fn create_key_combo(&self, key_seed: String) -> Result { + async fn create_key_combo(&self, key_seed: String) -> Result<(PrivateKey, PublicKey), KeyManagerServiceError> { (*self.key_manager_inner) .write() .await @@ -90,7 +84,7 @@ where TBackend: KeyManagerBackend + 'static let pk = next_key.to_public_key(); // (*self.key_manager_inner).read().await.get_next_key(branch).await; - Ok(KeyComboPair { sk, pk }) + Ok((sk, pk)) } async fn remove_encryption(&self) -> Result<(), KeyManagerServiceError> { diff --git a/base_layer/wallet/src/key_manager_service/interface.rs b/base_layer/wallet/src/key_manager_service/interface.rs index e130469ed5..9719c7b882 100644 --- a/base_layer/wallet/src/key_manager_service/interface.rs +++ b/base_layer/wallet/src/key_manager_service/interface.rs @@ -24,7 +24,7 @@ use chacha20poly1305::XChaCha20Poly1305; use tari_common_types::types::{PrivateKey, PublicKey}; use tari_crypto::keys::PublicKey as PublicKeyTrait; -use crate::key_manager_service::{error::KeyManagerServiceError, handle::KeyComboPair}; +use crate::key_manager_service::error::KeyManagerServiceError; /// The value returned from [add_new_branch]. `AlreadyExists` is returned if the branch was previously created, /// otherwise `NewEntry` is returned. @@ -73,7 +73,7 @@ pub trait KeyManagerInterface: Clone + Send + Sync + 'static { ) -> Result; /// Gets new key combo pair out of a key seed - async fn create_key_combo(&self, key_seed: String) -> Result; + 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 + Send>( diff --git a/base_layer/wallet/src/key_manager_service/mock.rs b/base_layer/wallet/src/key_manager_service/mock.rs index ca9ed06018..dde4ae1db3 100644 --- a/base_layer/wallet/src/key_manager_service/mock.rs +++ b/base_layer/wallet/src/key_manager_service/mock.rs @@ -22,12 +22,12 @@ 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; use crate::{ - key_manager_service::{handle::KeyComboPair, interface::NextKeyResult, AddResult, KeyManagerInterface}, + key_manager_service::{interface::NextKeyResult, AddResult, KeyManagerInterface}, types::KeyDigest, }; @@ -162,7 +162,7 @@ impl KeyManagerInterface for KeyManagerMock { unimplemented!("Not supported"); } - async fn create_key_combo(&self, _key_seed: String) -> Result { + async fn create_key_combo(&self, _key_seed: String) -> Result<(PrivateKey, PublicKey), KeyManagerServiceError> { unimplemented!("Not supported"); } diff --git a/base_layer/wallet/src/key_manager_service/mod.rs b/base_layer/wallet/src/key_manager_service/mod.rs index 3c657d0212..5d4f8af137 100644 --- a/base_layer/wallet/src/key_manager_service/mod.rs +++ b/base_layer/wallet/src/key_manager_service/mod.rs @@ -24,7 +24,7 @@ mod error; pub use error::KeyManagerServiceError; mod handle; -pub use handle::{KeyComboPair, KeyManagerHandle}; +pub use handle::KeyManagerHandle; mod initializer; pub use initializer::KeyManagerInitializer; From a2f01adbc6789255d86604fc9c05ba2b04c8ac0f Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Wed, 28 Sep 2022 17:44:51 +0100 Subject: [PATCH 06/30] refactor message for create key combo --- .../tari_console_wallet/src/automation/commands.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/applications/tari_console_wallet/src/automation/commands.rs b/applications/tari_console_wallet/src/automation/commands.rs index a4805b275d..c88fe779ac 100644 --- a/applications/tari_console_wallet/src/automation/commands.rs +++ b/applications/tari_console_wallet/src/automation/commands.rs @@ -651,7 +651,12 @@ pub async fn command_runner( }, CreateKeyCombo(args) => match create_key_combo(key_manager_service.clone(), args.key_seed).await { Ok((sk, pk)) => { - println!("create new key combo pair: sk {:?}, pk {:?} ", sk, pk) + println!( + "create new key combo pair: + 1. secret key: {:?}, + 2. public key {:?}", + sk, pk + ) }, Err(e) => eprintln!("CreateKeyCombo error! {}", e), }, From e79acc4497d1fb19c50fe0720ce4ea6ea216f398 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Wed, 28 Sep 2022 22:51:38 +0100 Subject: [PATCH 07/30] refactor clap_parses_user_defined_commands_as_expected --- applications/tari_console_wallet/src/wallet_modes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/tari_console_wallet/src/wallet_modes.rs b/applications/tari_console_wallet/src/wallet_modes.rs index 554563a6a2..c410769f5f 100644 --- a/applications/tari_console_wallet/src/wallet_modes.rs +++ b/applications/tari_console_wallet/src/wallet_modes.rs @@ -429,7 +429,7 @@ mod test { burn-tari --message Ups_these_funds_will_be_burned! 100T - create-key-combo --key_seed pie + create-key-combo pie coin-split --message Make_many_dust_UTXOs! --fee-per-gram 2 0.001T 499 From e11ee31aa5c644ecb8358f434dd01a8e089af647 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Thu, 29 Sep 2022 09:28:07 +0100 Subject: [PATCH 08/30] address PR comments --- applications/tari_console_wallet/src/automation/commands.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/tari_console_wallet/src/automation/commands.rs b/applications/tari_console_wallet/src/automation/commands.rs index c88fe779ac..9415254df0 100644 --- a/applications/tari_console_wallet/src/automation/commands.rs +++ b/applications/tari_console_wallet/src/automation/commands.rs @@ -655,7 +655,7 @@ pub async fn command_runner( "create new key combo pair: 1. secret key: {:?}, 2. public key {:?}", - sk, pk + sk.to_hex(), pk.to_hex() ) }, Err(e) => eprintln!("CreateKeyCombo error! {}", e), From 4069ab88b4ce88ec56383e9d068893bf4483424e Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Thu, 29 Sep 2022 10:06:57 +0100 Subject: [PATCH 09/30] fix clippy --- applications/tari_console_wallet/src/automation/commands.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/applications/tari_console_wallet/src/automation/commands.rs b/applications/tari_console_wallet/src/automation/commands.rs index 9415254df0..7f99780044 100644 --- a/applications/tari_console_wallet/src/automation/commands.rs +++ b/applications/tari_console_wallet/src/automation/commands.rs @@ -655,7 +655,8 @@ pub async fn command_runner( "create new key combo pair: 1. secret key: {:?}, 2. public key {:?}", - sk.to_hex(), pk.to_hex() + sk.to_hex(), + pk.to_hex() ) }, Err(e) => eprintln!("CreateKeyCombo error! {}", e), From 6d804227dca6b36397445b252f61d142b5a4f506 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Thu, 29 Sep 2022 10:13:31 +0100 Subject: [PATCH 10/30] replace debug with {} --- applications/tari_console_wallet/src/automation/commands.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/applications/tari_console_wallet/src/automation/commands.rs b/applications/tari_console_wallet/src/automation/commands.rs index 7f99780044..49e22948c2 100644 --- a/applications/tari_console_wallet/src/automation/commands.rs +++ b/applications/tari_console_wallet/src/automation/commands.rs @@ -653,8 +653,8 @@ pub async fn command_runner( Ok((sk, pk)) => { println!( "create new key combo pair: - 1. secret key: {:?}, - 2. public key {:?}", + 1. secret key: {}, + 2. public key {}", sk.to_hex(), pk.to_hex() ) From b8e40cada9383e828dc4121bf6501d84a840b822 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Fri, 30 Sep 2022 11:32:06 +0100 Subject: [PATCH 11/30] add create-n-m-utxo cli command --- .../src/automation/commands.rs | 32 +++ applications/tari_console_wallet/src/cli.rs | 10 + .../tari_console_wallet/src/wallet_modes.rs | 3 + .../wallet/src/transaction_service/handle.rs | 45 ++++ .../wallet/src/transaction_service/service.rs | 210 +++++++++++++++++- infrastructure/tari_script/src/lib.rs | 2 +- 6 files changed, 294 insertions(+), 8 deletions(-) diff --git a/applications/tari_console_wallet/src/automation/commands.rs b/applications/tari_console_wallet/src/automation/commands.rs index 49e22948c2..f4aef97699 100644 --- a/applications/tari_console_wallet/src/automation/commands.rs +++ b/applications/tari_console_wallet/src/automation/commands.rs @@ -85,6 +85,7 @@ pub enum WalletCommand { SendTari, SendOneSided, CreateKeyCombo, + CreateNMUtxo, MakeItRain, CoinSplit, DiscoverPeer, @@ -150,6 +151,21 @@ pub async fn create_key_combo( .map_err(CommandError::KeyManagerError) } +pub async fn create_n_m_utxo( + mut wallet_transaction_service: TransactionServiceHandle, + amount: MicroTari, + fee_per_gram: MicroTari, + n: u8, + m: u8, + public_keys: Vec, + message: String, +) -> Result { + wallet_transaction_service + .create_n_m_utxo(amount, fee_per_gram, n, m, public_keys, message) + .await + .map_err(CommandError::TransactionServiceError) +} + /// publishes a tari-SHA atomic swap HTLC transaction pub async fn init_sha_atomic_swap( mut wallet_transaction_service: TransactionServiceHandle, @@ -661,6 +677,22 @@ pub async fn command_runner( }, Err(e) => eprintln!("CreateKeyCombo error! {}", e), }, + CreateNMUtxo(args) => match create_n_m_utxo( + transaction_service.clone(), + args.amount, + args.fee_per_gram, + args.n, + args.m, + args.public_keys, + args.message, + ) + .await + { + Ok(pk) => { + println!() + }, + Err(e) => {}, + }, SendTari(args) => { match send_tari( transaction_service.clone(), diff --git a/applications/tari_console_wallet/src/cli.rs b/applications/tari_console_wallet/src/cli.rs index 891b0511ff..f9f561f941 100644 --- a/applications/tari_console_wallet/src/cli.rs +++ b/applications/tari_console_wallet/src/cli.rs @@ -117,6 +117,7 @@ pub enum CliCommands { SendTari(SendTariArgs), BurnTari(BurnTariArgs), CreateKeyCombo(CreateKeyComboArgs), + CreateNMUtxo(CreateNMUtxoArgs), SendOneSided(SendTariArgs), SendOneSidedToStealthAddress(SendTariArgs), MakeItRain(MakeItRainArgs), @@ -161,6 +162,15 @@ pub struct CreateKeyComboArgs { pub key_seed: String, } +#[derive(Debug, Args, Clone)] +pub struct CreateNMUtxoArgs { + pub amount: MicroTari, + pub n: u8, + pub m: u8, + pub public_keys: Vec, + pub message: String, +} + #[derive(Debug, Args, Clone)] pub struct MakeItRainArgs { pub destination: UniPublicKey, diff --git a/applications/tari_console_wallet/src/wallet_modes.rs b/applications/tari_console_wallet/src/wallet_modes.rs index c410769f5f..6ead6f9558 100644 --- a/applications/tari_console_wallet/src/wallet_modes.rs +++ b/applications/tari_console_wallet/src/wallet_modes.rs @@ -447,6 +447,7 @@ mod test { let mut send_tari = false; let mut burn_tari = false; let mut create_key_combo = false; + let mut create_n_m_utxo = false; let mut make_it_rain = false; let mut coin_split = false; let mut discover_peer = false; @@ -457,6 +458,7 @@ mod test { CliCommands::SendTari(_) => send_tari = true, CliCommands::BurnTari(_) => burn_tari = true, CliCommands::CreateKeyCombo(_) => create_key_combo = true, + CliCommands::CreateNMUtxo(_) => create_n_m_utxo = true, CliCommands::SendOneSided(_) => {}, CliCommands::SendOneSidedToStealthAddress(_) => {}, CliCommands::MakeItRain(_) => make_it_rain = true, @@ -481,6 +483,7 @@ mod test { send_tari && burn_tari && create_key_combo && + create_n_m_utxo && make_it_rain && coin_split && discover_peer && diff --git a/base_layer/wallet/src/transaction_service/handle.rs b/base_layer/wallet/src/transaction_service/handle.rs index fda68fc370..b7f71695a5 100644 --- a/base_layer/wallet/src/transaction_service/handle.rs +++ b/base_layer/wallet/src/transaction_service/handle.rs @@ -88,6 +88,14 @@ pub enum TransactionServiceRequest { fee_per_gram: MicroTari, message: String, }, + CreateNMUtxo { + amount: MicroTari, + fee_per_gram: MicroTari, + n: u8, + m: u8, + public_keys: Vec, + message: [u8; 32], + }, SendOneSidedTransaction { dest_pubkey: CommsPublicKey, amount: MicroTari, @@ -156,6 +164,17 @@ impl fmt::Display for TransactionServiceRequest { message )), Self::BurnTari { amount, message, .. } => f.write_str(&format!("Burning Tari ({}, {})", amount, message)), + Self::CreateNMUtxo { + amount, + fee_per_gram, + n, + m, + public_keys, + message, + } => f.write_str(&format!( + "Creating a new n-of-m aggregate uxto with: amount = {}, n = {}, m = {}", + amount, n, m + )), Self::SendOneSidedTransaction { dest_pubkey, amount, @@ -504,6 +523,32 @@ impl TransactionServiceHandle { } } + pub async fn create_n_m_utxo( + &mut self, + amount: MicroTari, + fee_per_gram: MicroTari, + n: u8, + m: u8, + public_keys: Vec, + message: [u8; 32], + ) -> Result { + match self + .handle + .call(TransactionServiceRequest::CreateNMUtxo { + amount, + fee_per_gram, + n, + m, + public_keys, + message, + }) + .await?? + { + TransactionServiceResponse::TransactionSent(tx_id) => Ok(tx_id), + _ => Err(TransactionServiceError::UnexpectedApiResponse), + } + } + pub async fn send_one_sided_to_stealth_address_transaction( &mut self, dest_pubkey: CommsPublicKey, diff --git a/base_layer/wallet/src/transaction_service/service.rs b/base_layer/wallet/src/transaction_service/service.rs index 33f484398b..f46cd76136 100644 --- a/base_layer/wallet/src/transaction_service/service.rs +++ b/base_layer/wallet/src/transaction_service/service.rs @@ -35,7 +35,7 @@ use rand::rngs::OsRng; use sha2::Sha256; use tari_common_types::{ transaction::{ImportStatus, TransactionDirection, TransactionStatus, TxId}, - types::{PrivateKey, PublicKey}, + types::{FixedHash, PrivateKey, PublicKey}, }; use tari_comms::{peer_manager::NodeIdentity, types::CommsPublicKey}; use tari_comms_dht::outbound::OutboundMessageRequester; @@ -70,7 +70,7 @@ use tari_crypto::{ tari_utilities::ByteArray, }; use tari_p2p::domain_message::DomainMessage; -use tari_script::{inputs, script, TariScript}; +use tari_script::{inputs, script, slice_to_boxed_message, Opcode, TariScript}; use tari_service_framework::{reply_channel, reply_channel::Receiver}; use tari_shutdown::ShutdownSignal; use tokio::{ @@ -649,6 +649,25 @@ where ) .await .map(TransactionServiceResponse::TransactionSent), + TransactionServiceRequest::CreateNMUtxo { + amount, + fee_per_gram, + n, + m, + public_keys, + message, + } => self + .create_n_m_utxo( + amount, + fee_per_gram, + n, + m, + public_keys, + message, + transaction_broadcast_join_handles, + ) + .await + .map(|(tx_id, _)| TransactionServiceResponse::TransactionSent(tx_id)), TransactionServiceRequest::SendShaAtomicSwapTransaction( dest_pubkey, amount, @@ -986,6 +1005,180 @@ where Ok(()) } + /// Creates a utxo with aggregate public key out of m-of-n public keys + pub async fn create_n_m_utxo( + &mut self, + amount: MicroTari, + fee_per_gram: MicroTari, + n: u8, + m: u8, + public_keys: Vec, + message: [u8; 32], + transaction_broadcast_join_handles: &mut FuturesUnordered< + JoinHandle>>, + >, + ) -> Result<(TxId, FixedHash), TransactionServiceError> { + let tx_id = TxId::new_random(); + + // CreateAggregatePublicKey + Number(m) + Number(n) + PushPubKey(...) + PushString(message) + let capacity = 1 + 1 + 1 + public_keys.len() + 1; + let mut opcodes = Vec::::with_capacity(capacity); + + let msg = slice_to_boxed_message(message.as_bytes()); + let script = script!(CheckMultiSigVerifyAggregatePubKey(n, m, public_keys, Box::new(message))); + + // Empty covenant + let covenant = Covenant::default(); + + // Default range proof + let minimum_value_promise = MicroTari::zero(); + + // Prepare sender part of transaction + let stp = self + .output_manager_service + .prepare_transaction_to_send( + tx_id, + amount, + UtxoSelectionCriteria::default(), + OutputFeatures::default(), + fee_per_gram, + TransactionMetadata::default(), + "".to_string(), + script, + covenant, + minimum_value_promise, + ) + .await?; + + // This call is needed to advance the state from `SingleRoundMessageReady` to `CollectingSingleSignature`, + // but the returned value is not used + let _single_round_sender_data = stp + .build_single_round_message() + .map_err(|e| TransactionServiceProtocolError::new(tx_id, e.into()))?; + + self.output_manager_service + .confirm_pending_transaction(tx_id) + .await + .map_err(|e| TransactionServiceProtocolError::new(tx_id, e.into()))?; + + // Prepare receiver part of the transaction + + // In generating a aggregate public key utxo, we can use a randomly generated sender offset private key + let sender_offset_private_key = PrivateKey::random(&mut OsRng); + + // In generating an aggregate public key utxo, we can use a randomly generated spend key + let spend_key = PrivateKey::random(&mut OsRng); + + let sender_message = TransactionSenderMessage::new_single_round_message(stp.get_single_round_message()?); + let rewind_blinding_key = PrivateKey::from_bytes(&hash_secret_key(&spend_key))?; + let encryption_key = PrivateKey::from_bytes(&hash_secret_key(&rewind_blinding_key))?; + + let rewind_data = RewindData { + rewind_blinding_key: rewind_blinding_key.clone(), + encryption_key: encryption_key.clone(), + }; + + let rtp = ReceiverTransactionProtocol::new_with_rewindable_output( + sender_message, + PrivateKey::random(&mut OsRng), + spend_key.clone(), + &self.resources.factories, + &rewind_data, + ); + + // we don't want the given utxo to be spendable as an input to a later transaction, so we set + // spendable height of the current utxo to be u64::MAx + let height = u64::MAX; + + let recipient_reply = rtp.get_signed_data()?.clone(); + let output = recipient_reply.output.clone(); + let commitment = self + .resources + .factories + .commitment + .commit_value(&spend_key, amount.into()); + + let encrypted_value = EncryptedValue::encrypt_value(&rewind_data.encryption_key, &commitment, amount)?; + let minimum_value_promise = MicroTari::zero(); + + let unblinded_output = UnblindedOutput::new_current_version( + amount, + spend_key, + output.features.clone(), + script, + inputs!(spend_key), // TODO: refactor this, when we have implemented the necessary logic + self.node_identity.secret_key().clone(), + output.sender_offset_public_key.clone(), + output.metadata_signature.clone(), + height, + covenant, + encrypted_value, + minimum_value_promise, + ); + + // Start finalize + stp.add_single_recipient_info(recipient_reply, &self.resources.factories.range_proof) + .map_err(|e| TransactionServiceProtocolError::new(tx_id, e.into()))?; + + // Finalize + stp.finalize(&self.resources.factories, None, height).map_err(|e| { + error!( + target: LOG_TARGET, + "Transaction (TxId: {}) could not be finalized. Failure error: {:?}", tx_id, e, + ); + TransactionServiceProtocolError::new(tx_id, e.into()) + })?; + info!( + target: LOG_TARGET, + "Finalized create n of m transaction TxId: {}", tx_id + ); + + // This event being sent is important, but not critical to the protocol being successful. Send only fails if + // there are no subscribers. + let _size = self + .event_publisher + .send(Arc::new(TransactionEvent::TransactionCompletedImmediately(tx_id))); + + // Broadcast create n of m aggregate public key transaction + let tx = stp + .get_transaction() + .map_err(|e| TransactionServiceProtocolError::new(tx_id, e.into()))?; + let fee = stp + .get_fee_amount() + .map_err(|e| TransactionServiceProtocolError::new(tx_id, e.into()))?; + self.output_manager_service + .add_rewindable_output_with_tx_id( + tx_id, + unblinded_output, + Some(SpendingPriority::Normal), + Some(rewind_data), + ) + .await?; + self.submit_transaction( + transaction_broadcast_join_handles, + CompletedTransaction::new( + tx_id, + self.resources.node_identity.public_key().clone(), + self.resources.node_identity.public_key().clone(), + amount, + fee, + tx.clone(), + TransactionStatus::Completed, + "".to_string(), + Utc::now().naive_utc(), + TransactionDirection::Outbound, + None, + None, + None, + ), + )?; + + let output_hash = output.hash(); + + // we want to print out the hash of the utxo + Ok((tx_id, output_hash)) + } + /// broadcasts a SHA-XTR atomic swap transaction /// # Arguments /// 'dest_pubkey': The Comms pubkey of the recipient node @@ -1043,7 +1236,7 @@ where ) .await?; - // This call is needed to advance the state from `SingleRoundMessageReady` to `SingleRoundMessageReady`, + // This call is needed to advance the state from `SingleRoundMessageReady` to `CollectingSingleSignature`, // but the returned value is not used let _single_round_sender_data = stp .build_single_round_message() @@ -1127,7 +1320,10 @@ where ); TransactionServiceProtocolError::new(tx_id, e.into()) })?; - info!(target: LOG_TARGET, "Finalized one-side transaction TxId: {}", tx_id); + info!( + target: LOG_TARGET, + "Finalized sha atomic swap transaction TxId: {}", tx_id + ); // This event being sent is important, but not critical to the protocol being successful. Send only fails if // there are no subscribers. @@ -1135,7 +1331,7 @@ where .event_publisher .send(Arc::new(TransactionEvent::TransactionCompletedImmediately(tx_id))); - // Broadcast one-sided transaction + // Broadcast sha atomic swap transaction let tx = stp .get_transaction() @@ -1205,7 +1401,7 @@ where ) .await?; - // This call is needed to advance the state from `SingleRoundMessageReady` to `SingleRoundMessageReady`, + // This call is needed to advance the state from `SingleRoundMessageReady` to `CollectingSingleSignature`, // but the returned value is not used let _single_round_sender_data = stp .build_single_round_message() @@ -1373,7 +1569,7 @@ where ) .await?; - // This call is needed to advance the state from `SingleRoundMessageReady` to `SingleRoundMessageReady`, + // This call is needed to advance the state from `SingleRoundMessageReady` to `CollectingSingleSignature`, // but the returned value is not used let _single_round_sender_data = stp .build_single_round_message() diff --git a/infrastructure/tari_script/src/lib.rs b/infrastructure/tari_script/src/lib.rs index e796c55a4d..5a50a52b72 100644 --- a/infrastructure/tari_script/src/lib.rs +++ b/infrastructure/tari_script/src/lib.rs @@ -24,7 +24,7 @@ mod serde; mod stack; pub use error::ScriptError; -pub use op_codes::{slice_to_boxed_hash, slice_to_hash, HashValue, Opcode}; +pub use op_codes::{slice_to_boxed_hash, slice_to_boxed_message, slice_to_hash, HashValue, Opcode}; pub use script::TariScript; pub use script_commitment::{ScriptCommitment, ScriptCommitmentError, ScriptCommitmentFactory}; pub use script_context::ScriptContext; From f850b11a4bb3de58d9a436de00e69bab5422f8e2 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Fri, 30 Sep 2022 17:58:52 +0100 Subject: [PATCH 12/30] refactor and clean code --- .../src/automation/commands.rs | 27 ++++++++++++++----- applications/tari_console_wallet/src/cli.rs | 1 + .../wallet/src/transaction_service/handle.rs | 13 ++++----- .../wallet/src/transaction_service/service.rs | 26 ++++++++---------- 4 files changed, 39 insertions(+), 28 deletions(-) diff --git a/applications/tari_console_wallet/src/automation/commands.rs b/applications/tari_console_wallet/src/automation/commands.rs index f4aef97699..c083c27b8d 100644 --- a/applications/tari_console_wallet/src/automation/commands.rs +++ b/applications/tari_console_wallet/src/automation/commands.rs @@ -21,7 +21,7 @@ // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. use std::{ - convert::TryInto, + convert::{From, TryInto}, fs, fs::File, io, @@ -159,9 +159,12 @@ pub async fn create_n_m_utxo( m: u8, public_keys: Vec, message: String, -) -> Result { +) -> Result<(TxId, FixedHash), CommandError> { + let mut msg = [0u8; 32]; + msg.copy_from_slice(message.as_bytes()); + wallet_transaction_service - .create_n_m_utxo(amount, fee_per_gram, n, m, public_keys, message) + .create_n_m_utxo(amount, fee_per_gram, n, m, public_keys, msg) .await .map_err(CommandError::TransactionServiceError) } @@ -683,15 +686,25 @@ pub async fn command_runner( args.fee_per_gram, args.n, args.m, - args.public_keys, + args.public_keys + .iter() + .map(|pk| (PublicKey::from(pk.clone()))) + .collect(), args.message, ) .await { - Ok(pk) => { - println!() + Ok((tx_id, output_hash)) => { + println!( + "Create a utxo with n-of-m aggregate public key, with: + 1. n = {}, + 2. m = {}, + 3. tx id = {}, + 4. output hash = {}", + args.n, args.m, tx_id, output_hash + ) }, - Err(e) => {}, + Err(e) => eprintln!("CreateNMUtxo error! {}", e), }, SendTari(args) => { match send_tari( diff --git a/applications/tari_console_wallet/src/cli.rs b/applications/tari_console_wallet/src/cli.rs index f9f561f941..5c3765730a 100644 --- a/applications/tari_console_wallet/src/cli.rs +++ b/applications/tari_console_wallet/src/cli.rs @@ -165,6 +165,7 @@ pub struct CreateKeyComboArgs { #[derive(Debug, Args, Clone)] pub struct CreateNMUtxoArgs { pub amount: MicroTari, + pub fee_per_gram: MicroTari, pub n: u8, pub m: u8, pub public_keys: Vec, diff --git a/base_layer/wallet/src/transaction_service/handle.rs b/base_layer/wallet/src/transaction_service/handle.rs index b7f71695a5..3b14844b9a 100644 --- a/base_layer/wallet/src/transaction_service/handle.rs +++ b/base_layer/wallet/src/transaction_service/handle.rs @@ -31,7 +31,7 @@ use chacha20poly1305::XChaCha20Poly1305; use chrono::NaiveDateTime; use tari_common_types::{ transaction::{ImportStatus, TxId}, - types::PublicKey, + types::{FixedHash, PublicKey}, }; use tari_comms::types::CommsPublicKey; use tari_core::{ @@ -166,11 +166,11 @@ impl fmt::Display for TransactionServiceRequest { Self::BurnTari { amount, message, .. } => f.write_str(&format!("Burning Tari ({}, {})", amount, message)), Self::CreateNMUtxo { amount, - fee_per_gram, + fee_per_gram: _, n, m, - public_keys, - message, + public_keys: _, + message: _, } => f.write_str(&format!( "Creating a new n-of-m aggregate uxto with: amount = {}, n = {}, m = {}", amount, n, m @@ -247,6 +247,7 @@ impl fmt::Display for TransactionServiceRequest { #[derive(Debug)] pub enum TransactionServiceResponse { TransactionSent(TxId), + TransactionSentWithOutputHash(TxId, FixedHash), TransactionCancelled, PendingInboundTransactions(HashMap), PendingOutboundTransactions(HashMap), @@ -531,7 +532,7 @@ impl TransactionServiceHandle { m: u8, public_keys: Vec, message: [u8; 32], - ) -> Result { + ) -> Result<(TxId, FixedHash), TransactionServiceError> { match self .handle .call(TransactionServiceRequest::CreateNMUtxo { @@ -544,7 +545,7 @@ impl TransactionServiceHandle { }) .await?? { - TransactionServiceResponse::TransactionSent(tx_id) => Ok(tx_id), + TransactionServiceResponse::TransactionSentWithOutputHash(tx_id, output_hash) => Ok((tx_id, output_hash)), _ => Err(TransactionServiceError::UnexpectedApiResponse), } } diff --git a/base_layer/wallet/src/transaction_service/service.rs b/base_layer/wallet/src/transaction_service/service.rs index f46cd76136..53f9904b78 100644 --- a/base_layer/wallet/src/transaction_service/service.rs +++ b/base_layer/wallet/src/transaction_service/service.rs @@ -70,7 +70,7 @@ use tari_crypto::{ tari_utilities::ByteArray, }; use tari_p2p::domain_message::DomainMessage; -use tari_script::{inputs, script, slice_to_boxed_message, Opcode, TariScript}; +use tari_script::{inputs, script, slice_to_boxed_message, TariScript}; use tari_service_framework::{reply_channel, reply_channel::Receiver}; use tari_shutdown::ShutdownSignal; use tokio::{ @@ -1020,12 +1020,8 @@ where ) -> Result<(TxId, FixedHash), TransactionServiceError> { let tx_id = TxId::new_random(); - // CreateAggregatePublicKey + Number(m) + Number(n) + PushPubKey(...) + PushString(message) - let capacity = 1 + 1 + 1 + public_keys.len() + 1; - let mut opcodes = Vec::::with_capacity(capacity); - let msg = slice_to_boxed_message(message.as_bytes()); - let script = script!(CheckMultiSigVerifyAggregatePubKey(n, m, public_keys, Box::new(message))); + let script = script!(CheckMultiSigVerifyAggregatePubKey(n, m, public_keys, msg)); // Empty covenant let covenant = Covenant::default(); @@ -1034,7 +1030,7 @@ where let minimum_value_promise = MicroTari::zero(); // Prepare sender part of transaction - let stp = self + let mut stp = self .output_manager_service .prepare_transaction_to_send( tx_id, @@ -1044,7 +1040,7 @@ where fee_per_gram, TransactionMetadata::default(), "".to_string(), - script, + script.clone(), covenant, minimum_value_promise, ) @@ -1063,14 +1059,11 @@ where // Prepare receiver part of the transaction - // In generating a aggregate public key utxo, we can use a randomly generated sender offset private key - let sender_offset_private_key = PrivateKey::random(&mut OsRng); - // In generating an aggregate public key utxo, we can use a randomly generated spend key let spend_key = PrivateKey::random(&mut OsRng); let sender_message = TransactionSenderMessage::new_single_round_message(stp.get_single_round_message()?); - let rewind_blinding_key = PrivateKey::from_bytes(&hash_secret_key(&spend_key))?; + let rewind_blinding_key = PrivateKey::from_bytes(&hash_secret_key(&spend_key.clone()))?; let encryption_key = PrivateKey::from_bytes(&hash_secret_key(&rewind_blinding_key))?; let rewind_data = RewindData { @@ -1096,17 +1089,20 @@ where .resources .factories .commitment - .commit_value(&spend_key, amount.into()); + .commit_value(&spend_key.clone(), amount.into()); let encrypted_value = EncryptedValue::encrypt_value(&rewind_data.encryption_key, &commitment, amount)?; let minimum_value_promise = MicroTari::zero(); + let covenant = Covenant::default(); + let unblinded_output = UnblindedOutput::new_current_version( amount, - spend_key, + spend_key.clone(), output.features.clone(), script, - inputs!(spend_key), // TODO: refactor this, when we have implemented the necessary logic + inputs!(PublicKey::from_secret_key(&spend_key)), /* TODO: refactor this, when we have implemented the + * necessary logic */ self.node_identity.secret_key().clone(), output.sender_offset_public_key.clone(), output.metadata_signature.clone(), From b9079628c5057f2f7235f1d33c5e5c50f067ed1a Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Fri, 30 Sep 2022 18:08:49 +0100 Subject: [PATCH 13/30] add test --- applications/tari_console_wallet/src/wallet_modes.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/applications/tari_console_wallet/src/wallet_modes.rs b/applications/tari_console_wallet/src/wallet_modes.rs index 6ead6f9558..049d7025aa 100644 --- a/applications/tari_console_wallet/src/wallet_modes.rs +++ b/applications/tari_console_wallet/src/wallet_modes.rs @@ -431,6 +431,8 @@ mod test { create-key-combo pie + create-n-m-utxo 1 1 5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d61 --message signing + 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 \ From f783536465e69ffed38c5e7867eb2bf26bde9064 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Fri, 30 Sep 2022 18:13:33 +0100 Subject: [PATCH 14/30] address some comments on PR --- .../tari_console_wallet/src/automation/commands.rs | 10 +++++----- applications/tari_console_wallet/src/cli.rs | 4 ++-- applications/tari_console_wallet/src/wallet_modes.rs | 6 +++--- base_layer/wallet/src/key_manager_service/handle.rs | 3 +-- base_layer/wallet/src/key_manager_service/interface.rs | 2 +- base_layer/wallet/src/key_manager_service/mock.rs | 2 +- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/applications/tari_console_wallet/src/automation/commands.rs b/applications/tari_console_wallet/src/automation/commands.rs index 49e22948c2..34583e9b18 100644 --- a/applications/tari_console_wallet/src/automation/commands.rs +++ b/applications/tari_console_wallet/src/automation/commands.rs @@ -84,7 +84,7 @@ pub enum WalletCommand { GetBalance, SendTari, SendOneSided, - CreateKeyCombo, + CreateKeyPair, MakeItRain, CoinSplit, DiscoverPeer, @@ -140,12 +140,12 @@ pub async fn burn_tari( .map_err(CommandError::TransactionServiceError) } -pub async fn create_key_combo( +pub async fn create_key_pair( key_manager_service: KeyManagerHandle, key_seed: String, ) -> Result<(PrivateKey, PublicKey), CommandError> { key_manager_service - .create_key_combo(key_seed) + .create_key_pair(key_seed) .await .map_err(CommandError::KeyManagerError) } @@ -649,7 +649,7 @@ 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 { + CreateKeyPair(args) => match create_key_pair(key_manager_service.clone(), args.key_seed).await { Ok((sk, pk)) => { println!( "create new key combo pair: @@ -659,7 +659,7 @@ pub async fn command_runner( pk.to_hex() ) }, - Err(e) => eprintln!("CreateKeyCombo error! {}", e), + Err(e) => eprintln!("CreateKeyPair error! {}", e), }, SendTari(args) => { match send_tari( diff --git a/applications/tari_console_wallet/src/cli.rs b/applications/tari_console_wallet/src/cli.rs index 891b0511ff..6c64db5dc5 100644 --- a/applications/tari_console_wallet/src/cli.rs +++ b/applications/tari_console_wallet/src/cli.rs @@ -116,7 +116,7 @@ pub enum CliCommands { GetBalance, SendTari(SendTariArgs), BurnTari(BurnTariArgs), - CreateKeyCombo(CreateKeyComboArgs), + CreateKeyPair(CreateKeyPairArgs), SendOneSided(SendTariArgs), SendOneSidedToStealthAddress(SendTariArgs), MakeItRain(MakeItRainArgs), @@ -157,7 +157,7 @@ pub struct BurnTariArgs { } #[derive(Debug, Args, Clone)] -pub struct CreateKeyComboArgs { +pub struct CreateKeyPairArgs { pub key_seed: String, } diff --git a/applications/tari_console_wallet/src/wallet_modes.rs b/applications/tari_console_wallet/src/wallet_modes.rs index c410769f5f..9a7f72654f 100644 --- a/applications/tari_console_wallet/src/wallet_modes.rs +++ b/applications/tari_console_wallet/src/wallet_modes.rs @@ -446,7 +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 create_key_pair = false; let mut make_it_rain = false; let mut coin_split = false; let mut discover_peer = false; @@ -456,7 +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::CreateKeyPair(_) => create_key_pair = true, CliCommands::SendOneSided(_) => {}, CliCommands::SendOneSidedToStealthAddress(_) => {}, CliCommands::MakeItRain(_) => make_it_rain = true, @@ -480,7 +480,7 @@ mod test { get_balance && send_tari && burn_tari && - create_key_combo && + create_key_pair && make_it_rain && coin_split && discover_peer && diff --git a/base_layer/wallet/src/key_manager_service/handle.rs b/base_layer/wallet/src/key_manager_service/handle.rs index 2a6e8d237a..4496f727fa 100644 --- a/base_layer/wallet/src/key_manager_service/handle.rs +++ b/base_layer/wallet/src/key_manager_service/handle.rs @@ -73,7 +73,7 @@ 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> { + async fn create_key_pair(&self, key_seed: String) -> Result<(PrivateKey, PublicKey), KeyManagerServiceError> { (*self.key_manager_inner) .write() .await @@ -82,7 +82,6 @@ where TBackend: KeyManagerBackend + 'static 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; Ok((sk, pk)) } diff --git a/base_layer/wallet/src/key_manager_service/interface.rs b/base_layer/wallet/src/key_manager_service/interface.rs index 9719c7b882..62fdbe955f 100644 --- a/base_layer/wallet/src/key_manager_service/interface.rs +++ b/base_layer/wallet/src/key_manager_service/interface.rs @@ -73,7 +73,7 @@ pub trait KeyManagerInterface: Clone + Send + Sync + 'static { ) -> Result; /// Gets new key combo pair out of a key seed - async fn create_key_combo(&self, key_seed: String) -> Result<(PrivateKey, PublicKey), KeyManagerServiceError>; + async fn create_key_pair(&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 + Send>( diff --git a/base_layer/wallet/src/key_manager_service/mock.rs b/base_layer/wallet/src/key_manager_service/mock.rs index dde4ae1db3..3b82eb46c5 100644 --- a/base_layer/wallet/src/key_manager_service/mock.rs +++ b/base_layer/wallet/src/key_manager_service/mock.rs @@ -162,7 +162,7 @@ impl KeyManagerInterface for KeyManagerMock { unimplemented!("Not supported"); } - async fn create_key_combo(&self, _key_seed: String) -> Result<(PrivateKey, PublicKey), KeyManagerServiceError> { + async fn create_key_pair(&self, _key_seed: String) -> Result<(PrivateKey, PublicKey), KeyManagerServiceError> { unimplemented!("Not supported"); } From 676cfc3ec1b7520b4e305f23797b8792d3151547 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Fri, 30 Sep 2022 18:27:29 +0100 Subject: [PATCH 15/30] refactor failing test --- applications/tari_console_wallet/src/wallet_modes.rs | 2 +- infrastructure/tari_script/Cargo.toml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/applications/tari_console_wallet/src/wallet_modes.rs b/applications/tari_console_wallet/src/wallet_modes.rs index 9a7f72654f..c06c635fb6 100644 --- a/applications/tari_console_wallet/src/wallet_modes.rs +++ b/applications/tari_console_wallet/src/wallet_modes.rs @@ -429,7 +429,7 @@ mod test { burn-tari --message Ups_these_funds_will_be_burned! 100T - create-key-combo pie + create-key-pair pie coin-split --message Make_many_dust_UTXOs! --fee-per-gram 2 0.001T 499 diff --git a/infrastructure/tari_script/Cargo.toml b/infrastructure/tari_script/Cargo.toml index 3f9a5694c3..636fd480e5 100644 --- a/infrastructure/tari_script/Cargo.toml +++ b/infrastructure/tari_script/Cargo.toml @@ -22,3 +22,4 @@ sha2 = "0.9" sha3 = "0.9" thiserror = "1.0.30" rand = "0.8.5" + From 2948a6d82b8613cccd7d28078bce2d46d86482f3 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Mon, 3 Oct 2022 10:20:35 +0100 Subject: [PATCH 16/30] refactor code according to PR comments --- Cargo.lock | 1 + applications/tari_console_wallet/Cargo.toml | 1 + .../src/automation/commands.rs | 25 ++++++------------- applications/tari_console_wallet/src/cli.rs | 2 +- .../wallet/src/key_manager_service/handle.rs | 11 +++++--- .../src/key_manager_service/interface.rs | 5 +++- .../wallet/src/key_manager_service/mock.rs | 5 +++- 7 files changed, 26 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 577db90300..6b6b82b193 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4909,6 +4909,7 @@ dependencies = [ "tui", "unicode-segmentation", "unicode-width", + "zeroize", ] [[package]] diff --git a/applications/tari_console_wallet/Cargo.toml b/applications/tari_console_wallet/Cargo.toml index 906ffa9f28..3a6c948589 100644 --- a/applications/tari_console_wallet/Cargo.toml +++ b/applications/tari_console_wallet/Cargo.toml @@ -19,6 +19,7 @@ tari_app_grpc = { path = "../tari_app_grpc" } tari_shutdown = { path = "../../infrastructure/shutdown" } tari_key_manager = { path = "../../base_layer/key_manager" } tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag = "v0.4.5" } +zeroize = "1.5" # Uncomment for tokio tracing via tokio-console (needs "tracing" featurs) #console-subscriber = "0.1.3" diff --git a/applications/tari_console_wallet/src/automation/commands.rs b/applications/tari_console_wallet/src/automation/commands.rs index 34583e9b18..4ab7b5a5ae 100644 --- a/applications/tari_console_wallet/src/automation/commands.rs +++ b/applications/tari_console_wallet/src/automation/commands.rs @@ -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, PrivateKey, PublicKey}, + types::{CommitmentFactory, FixedHash, PublicKey}, }; use tari_comms::{ connectivity::{ConnectivityEvent, ConnectivityRequester}, @@ -57,7 +57,7 @@ use tari_utilities::{hex::Hex, ByteArray}; use tari_wallet::{ connectivity_service::WalletConnectivityInterface, error::WalletError, - key_manager_service::{storage::database::KeyManagerBackend, KeyManagerHandle, KeyManagerInterface, NextKeyResult}, + key_manager_service::{KeyManagerInterface, NextKeyResult}, output_manager_service::{handle::OutputManagerHandle, UtxoSelectionCriteria}, transaction_service::handle::{TransactionEvent, TransactionServiceHandle}, TransactionStage, @@ -68,6 +68,7 @@ use tokio::{ sync::{broadcast, mpsc}, time::{sleep, timeout}, }; +use zeroize::Zeroizing; use super::error::CommandError; use crate::{ @@ -140,16 +141,6 @@ pub async fn burn_tari( .map_err(CommandError::TransactionServiceError) } -pub async fn create_key_pair( - key_manager_service: KeyManagerHandle, - key_seed: String, -) -> Result<(PrivateKey, PublicKey), CommandError> { - key_manager_service - .create_key_pair(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, @@ -649,13 +640,13 @@ pub async fn command_runner( Err(e) => eprintln!("BurnTari error! {}", e), } }, - CreateKeyPair(args) => match create_key_pair(key_manager_service.clone(), args.key_seed).await { + CreateKeyPair(args) => match key_manager_service.create_key_pair(args.key_branch).await { Ok((sk, pk)) => { println!( - "create new key combo pair: - 1. secret key: {}, - 2. public key {}", - sk.to_hex(), + "New key pair: + 1. secret key: {:?}, + 2. public key: {}", + Zeroizing::new(sk.to_hex()), pk.to_hex() ) }, diff --git a/applications/tari_console_wallet/src/cli.rs b/applications/tari_console_wallet/src/cli.rs index 6c64db5dc5..6cc735be6b 100644 --- a/applications/tari_console_wallet/src/cli.rs +++ b/applications/tari_console_wallet/src/cli.rs @@ -158,7 +158,7 @@ pub struct BurnTariArgs { #[derive(Debug, Args, Clone)] pub struct CreateKeyPairArgs { - pub key_seed: String, + pub key_branch: String, } #[derive(Debug, Args, Clone)] diff --git a/base_layer/wallet/src/key_manager_service/handle.rs b/base_layer/wallet/src/key_manager_service/handle.rs index 4496f727fa..e0858bbdcb 100644 --- a/base_layer/wallet/src/key_manager_service/handle.rs +++ b/base_layer/wallet/src/key_manager_service/handle.rs @@ -73,13 +73,16 @@ where TBackend: KeyManagerBackend + 'static (*self.key_manager_inner).write().await.apply_encryption(cipher) } - async fn create_key_pair(&self, key_seed: String) -> Result<(PrivateKey, PublicKey), KeyManagerServiceError> { - (*self.key_manager_inner) + async fn create_key_pair + Send>( + &self, + branch: T, + ) -> Result<(PrivateKey, PublicKey), KeyManagerServiceError> { + self.key_manager_inner .write() .await - .add_key_manager_branch(key_seed.clone())?; + .add_key_manager_branch(branch.clone().into())?; - let next_key = self.get_next_key(key_seed).await?; + let next_key = self.get_next_key(branch).await?; let sk = next_key.key.clone(); let pk = next_key.to_public_key(); diff --git a/base_layer/wallet/src/key_manager_service/interface.rs b/base_layer/wallet/src/key_manager_service/interface.rs index 62fdbe955f..c9b2c42f45 100644 --- a/base_layer/wallet/src/key_manager_service/interface.rs +++ b/base_layer/wallet/src/key_manager_service/interface.rs @@ -73,7 +73,10 @@ pub trait KeyManagerInterface: Clone + Send + Sync + 'static { ) -> Result; /// Gets new key combo pair out of a key seed - async fn create_key_pair(&self, key_seed: String) -> Result<(PrivateKey, PublicKey), KeyManagerServiceError>; + async fn create_key_pair + Send>( + &self, + branch: T, + ) -> 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 + Send>( diff --git a/base_layer/wallet/src/key_manager_service/mock.rs b/base_layer/wallet/src/key_manager_service/mock.rs index 3b82eb46c5..4ed3a8b7db 100644 --- a/base_layer/wallet/src/key_manager_service/mock.rs +++ b/base_layer/wallet/src/key_manager_service/mock.rs @@ -162,7 +162,10 @@ impl KeyManagerInterface for KeyManagerMock { unimplemented!("Not supported"); } - async fn create_key_pair(&self, _key_seed: String) -> Result<(PrivateKey, PublicKey), KeyManagerServiceError> { + async fn create_key_pair + Send>( + &self, + _branch: T, + ) -> Result<(PrivateKey, PublicKey), KeyManagerServiceError> { unimplemented!("Not supported"); } From 18c915dc87a65f218389220c075a4cc9ca0dfa51 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Mon, 3 Oct 2022 10:48:02 +0100 Subject: [PATCH 17/30] add further sugggestions impls --- applications/tari_console_wallet/src/automation/commands.rs | 4 ++-- base_layer/wallet/src/key_manager_service/handle.rs | 6 ++++-- base_layer/wallet/src/key_manager_service/interface.rs | 2 +- base_layer/wallet/src/key_manager_service/mock.rs | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/applications/tari_console_wallet/src/automation/commands.rs b/applications/tari_console_wallet/src/automation/commands.rs index 4ab7b5a5ae..8eda5cb36e 100644 --- a/applications/tari_console_wallet/src/automation/commands.rs +++ b/applications/tari_console_wallet/src/automation/commands.rs @@ -644,9 +644,9 @@ pub async fn command_runner( Ok((sk, pk)) => { println!( "New key pair: - 1. secret key: {:?}, + 1. secret key: {}, 2. public key: {}", - Zeroizing::new(sk.to_hex()), + *Zeroizing::new(sk.to_hex()), pk.to_hex() ) }, diff --git a/base_layer/wallet/src/key_manager_service/handle.rs b/base_layer/wallet/src/key_manager_service/handle.rs index e0858bbdcb..d53be0e37b 100644 --- a/base_layer/wallet/src/key_manager_service/handle.rs +++ b/base_layer/wallet/src/key_manager_service/handle.rs @@ -73,14 +73,16 @@ where TBackend: KeyManagerBackend + 'static (*self.key_manager_inner).write().await.apply_encryption(cipher) } - async fn create_key_pair + Send>( + async fn create_key_pair + Send>( &self, branch: T, ) -> Result<(PrivateKey, PublicKey), KeyManagerServiceError> { + let branch: String = branch.into(); + self.key_manager_inner .write() .await - .add_key_manager_branch(branch.clone().into())?; + .add_key_manager_branch(branch.clone())?; let next_key = self.get_next_key(branch).await?; let sk = next_key.key.clone(); diff --git a/base_layer/wallet/src/key_manager_service/interface.rs b/base_layer/wallet/src/key_manager_service/interface.rs index c9b2c42f45..fed1c2d680 100644 --- a/base_layer/wallet/src/key_manager_service/interface.rs +++ b/base_layer/wallet/src/key_manager_service/interface.rs @@ -73,7 +73,7 @@ pub trait KeyManagerInterface: Clone + Send + Sync + 'static { ) -> Result; /// Gets new key combo pair out of a key seed - async fn create_key_pair + Send>( + async fn create_key_pair + Send>( &self, branch: T, ) -> Result<(PrivateKey, PublicKey), KeyManagerServiceError>; diff --git a/base_layer/wallet/src/key_manager_service/mock.rs b/base_layer/wallet/src/key_manager_service/mock.rs index 4ed3a8b7db..c1f737126d 100644 --- a/base_layer/wallet/src/key_manager_service/mock.rs +++ b/base_layer/wallet/src/key_manager_service/mock.rs @@ -162,7 +162,7 @@ impl KeyManagerInterface for KeyManagerMock { unimplemented!("Not supported"); } - async fn create_key_pair + Send>( + async fn create_key_pair + Send>( &self, _branch: T, ) -> Result<(PrivateKey, PublicKey), KeyManagerServiceError> { From 547caab013cadc2f62cdeacedb040e0e7a6153db Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Mon, 3 Oct 2022 11:06:13 +0100 Subject: [PATCH 18/30] add rand to [dev-dependencies] instead --- infrastructure/tari_script/Cargo.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/infrastructure/tari_script/Cargo.toml b/infrastructure/tari_script/Cargo.toml index 636fd480e5..7d08b798f8 100644 --- a/infrastructure/tari_script/Cargo.toml +++ b/infrastructure/tari_script/Cargo.toml @@ -21,5 +21,7 @@ serde = "1.0.136" sha2 = "0.9" sha3 = "0.9" thiserror = "1.0.30" + +[dev-dependencies] rand = "0.8.5" From 1b2c5731c3055448df31b7d9a9f48208dd8af65a Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Mon, 3 Oct 2022 11:06:56 +0100 Subject: [PATCH 19/30] remove line --- infrastructure/tari_script/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/infrastructure/tari_script/Cargo.toml b/infrastructure/tari_script/Cargo.toml index 7d08b798f8..51b0cac28f 100644 --- a/infrastructure/tari_script/Cargo.toml +++ b/infrastructure/tari_script/Cargo.toml @@ -24,4 +24,3 @@ thiserror = "1.0.30" [dev-dependencies] rand = "0.8.5" - From 28dbddbc446eafe2416b13d328d8fb0bd32a92ed Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Tue, 4 Oct 2022 10:11:31 +0100 Subject: [PATCH 20/30] add renaming of create key combo -> create key pair --- .../tari_console_wallet/src/automation/commands.rs | 10 +++++----- applications/tari_console_wallet/src/cli.rs | 4 ++-- applications/tari_console_wallet/src/wallet_modes.rs | 6 +++--- base_layer/wallet/src/key_manager_service/handle.rs | 2 +- base_layer/wallet/src/key_manager_service/interface.rs | 2 +- base_layer/wallet/src/key_manager_service/mock.rs | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/applications/tari_console_wallet/src/automation/commands.rs b/applications/tari_console_wallet/src/automation/commands.rs index c083c27b8d..cf82ccdbc7 100644 --- a/applications/tari_console_wallet/src/automation/commands.rs +++ b/applications/tari_console_wallet/src/automation/commands.rs @@ -84,7 +84,7 @@ pub enum WalletCommand { GetBalance, SendTari, SendOneSided, - CreateKeyCombo, + CreateKeyPair, CreateNMUtxo, MakeItRain, CoinSplit, @@ -141,12 +141,12 @@ pub async fn burn_tari( .map_err(CommandError::TransactionServiceError) } -pub async fn create_key_combo( +pub async fn create_key_pair( key_manager_service: KeyManagerHandle, key_seed: String, ) -> Result<(PrivateKey, PublicKey), CommandError> { key_manager_service - .create_key_combo(key_seed) + .create_key_pair(key_seed) .await .map_err(CommandError::KeyManagerError) } @@ -668,7 +668,7 @@ 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 { + CreateKeyPair(args) => match create_key_pair(key_manager_service.clone(), args.key_seed).await { Ok((sk, pk)) => { println!( "create new key combo pair: @@ -678,7 +678,7 @@ pub async fn command_runner( pk.to_hex() ) }, - Err(e) => eprintln!("CreateKeyCombo error! {}", e), + Err(e) => eprintln!("CreateKeyPair error! {}", e), }, CreateNMUtxo(args) => match create_n_m_utxo( transaction_service.clone(), diff --git a/applications/tari_console_wallet/src/cli.rs b/applications/tari_console_wallet/src/cli.rs index 5c3765730a..e97c4da9d4 100644 --- a/applications/tari_console_wallet/src/cli.rs +++ b/applications/tari_console_wallet/src/cli.rs @@ -116,7 +116,7 @@ pub enum CliCommands { GetBalance, SendTari(SendTariArgs), BurnTari(BurnTariArgs), - CreateKeyCombo(CreateKeyComboArgs), + CreateKeyPair(CreateKeyPairArgs), CreateNMUtxo(CreateNMUtxoArgs), SendOneSided(SendTariArgs), SendOneSidedToStealthAddress(SendTariArgs), @@ -158,7 +158,7 @@ pub struct BurnTariArgs { } #[derive(Debug, Args, Clone)] -pub struct CreateKeyComboArgs { +pub struct CreateKeyPairArgs { pub key_seed: String, } diff --git a/applications/tari_console_wallet/src/wallet_modes.rs b/applications/tari_console_wallet/src/wallet_modes.rs index 54a7a900f0..e2411ad685 100644 --- a/applications/tari_console_wallet/src/wallet_modes.rs +++ b/applications/tari_console_wallet/src/wallet_modes.rs @@ -446,7 +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 create_key_pair = false; let mut create_n_m_utxo = false; let mut make_it_rain = false; let mut coin_split = false; @@ -457,7 +457,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::CreateKeyPair(_) => create_key_pair = true, CliCommands::CreateNMUtxo(_) => create_n_m_utxo = true, CliCommands::SendOneSided(_) => {}, CliCommands::SendOneSidedToStealthAddress(_) => {}, @@ -482,7 +482,7 @@ mod test { get_balance && send_tari && burn_tari && - create_key_combo && + create_key_pair && create_n_m_utxo && make_it_rain && coin_split && diff --git a/base_layer/wallet/src/key_manager_service/handle.rs b/base_layer/wallet/src/key_manager_service/handle.rs index 2a6e8d237a..524ab2573b 100644 --- a/base_layer/wallet/src/key_manager_service/handle.rs +++ b/base_layer/wallet/src/key_manager_service/handle.rs @@ -73,7 +73,7 @@ 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> { + async fn create_key_pair(&self, key_seed: String) -> Result<(PrivateKey, PublicKey), KeyManagerServiceError> { (*self.key_manager_inner) .write() .await diff --git a/base_layer/wallet/src/key_manager_service/interface.rs b/base_layer/wallet/src/key_manager_service/interface.rs index 9719c7b882..62fdbe955f 100644 --- a/base_layer/wallet/src/key_manager_service/interface.rs +++ b/base_layer/wallet/src/key_manager_service/interface.rs @@ -73,7 +73,7 @@ pub trait KeyManagerInterface: Clone + Send + Sync + 'static { ) -> Result; /// Gets new key combo pair out of a key seed - async fn create_key_combo(&self, key_seed: String) -> Result<(PrivateKey, PublicKey), KeyManagerServiceError>; + async fn create_key_pair(&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 + Send>( diff --git a/base_layer/wallet/src/key_manager_service/mock.rs b/base_layer/wallet/src/key_manager_service/mock.rs index dde4ae1db3..3b82eb46c5 100644 --- a/base_layer/wallet/src/key_manager_service/mock.rs +++ b/base_layer/wallet/src/key_manager_service/mock.rs @@ -162,7 +162,7 @@ impl KeyManagerInterface for KeyManagerMock { unimplemented!("Not supported"); } - async fn create_key_combo(&self, _key_seed: String) -> Result<(PrivateKey, PublicKey), KeyManagerServiceError> { + async fn create_key_pair(&self, _key_seed: String) -> Result<(PrivateKey, PublicKey), KeyManagerServiceError> { unimplemented!("Not supported"); } From cad4fb5ca3565db2351660b0663c74fe1cdc6d48 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Tue, 4 Oct 2022 10:56:34 +0100 Subject: [PATCH 21/30] add changes --- applications/tari_console_wallet/src/wallet_modes.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/applications/tari_console_wallet/src/wallet_modes.rs b/applications/tari_console_wallet/src/wallet_modes.rs index e2411ad685..55dbc5cc67 100644 --- a/applications/tari_console_wallet/src/wallet_modes.rs +++ b/applications/tari_console_wallet/src/wallet_modes.rs @@ -427,9 +427,9 @@ mod test { burn-tari --message Ups_these_funds_will_be_burned! 100T - create-key-combo pie + create-key-pair pie - create-n-m-utxo 1 1 5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d61 --message signing + create-n-m-utxo --amount 125T --fee-per-gram 1T --n 1 --m 1 --public-keys 5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d61 --message Our_secret! coin-split --message Make_many_dust_UTXOs! --fee-per-gram 2 0.001T 499 From 2e3038f36a280d60894a6bf4f8485a554d4cb55c Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Tue, 4 Oct 2022 15:05:03 +0100 Subject: [PATCH 22/30] run cargo fmt --- applications/tari_console_wallet/src/wallet_modes.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/applications/tari_console_wallet/src/wallet_modes.rs b/applications/tari_console_wallet/src/wallet_modes.rs index 55dbc5cc67..1d282672e6 100644 --- a/applications/tari_console_wallet/src/wallet_modes.rs +++ b/applications/tari_console_wallet/src/wallet_modes.rs @@ -429,7 +429,8 @@ mod test { create-key-pair pie - create-n-m-utxo --amount 125T --fee-per-gram 1T --n 1 --m 1 --public-keys 5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d61 --message Our_secret! + create-n-m-utxo --amount 125T --fee-per-gram 1T --n 1 --m 1 --public-keys \ + 5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d61 --message Our_secret! coin-split --message Make_many_dust_UTXOs! --fee-per-gram 2 0.001T 499 From 2e4f7cc13ac7c25e49aa8f10140bfb78b7480766 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Tue, 4 Oct 2022 15:20:43 +0100 Subject: [PATCH 23/30] add clippy allowance for many lines in create_n_m_utxo --- base_layer/wallet/src/transaction_service/service.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/base_layer/wallet/src/transaction_service/service.rs b/base_layer/wallet/src/transaction_service/service.rs index 53f9904b78..153d2f290d 100644 --- a/base_layer/wallet/src/transaction_service/service.rs +++ b/base_layer/wallet/src/transaction_service/service.rs @@ -1006,6 +1006,7 @@ where } /// Creates a utxo with aggregate public key out of m-of-n public keys + #[allow(clippy::too_many_lines)] pub async fn create_n_m_utxo( &mut self, amount: MicroTari, From 306e643725d262dcd87870df38a576eabdf98821 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Tue, 4 Oct 2022 16:28:20 +0100 Subject: [PATCH 24/30] refactor test --- applications/tari_console_wallet/src/wallet_modes.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/applications/tari_console_wallet/src/wallet_modes.rs b/applications/tari_console_wallet/src/wallet_modes.rs index 1d282672e6..045d02ea82 100644 --- a/applications/tari_console_wallet/src/wallet_modes.rs +++ b/applications/tari_console_wallet/src/wallet_modes.rs @@ -429,8 +429,7 @@ mod test { create-key-pair pie - create-n-m-utxo --amount 125T --fee-per-gram 1T --n 1 --m 1 --public-keys \ - 5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d61 --message Our_secret! + create-n-m-utxo 125T 100 10 1 5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d61 ff coin-split --message Make_many_dust_UTXOs! --fee-per-gram 2 0.001T 499 From 2e2ddc6a9ba62828522b5289de0815c5d7396220 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Thu, 6 Oct 2022 09:32:25 +0100 Subject: [PATCH 25/30] minor changes --- applications/tari_app_grpc/Cargo.toml | 1 - .../tari_console_wallet/src/automation/commands.rs | 10 +++++----- applications/tari_console_wallet/src/cli.rs | 4 ++-- applications/tari_console_wallet/src/wallet_modes.rs | 8 ++++---- base_layer/wallet/src/transaction_service/handle.rs | 8 ++++---- base_layer/wallet/src/transaction_service/service.rs | 6 +++--- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/applications/tari_app_grpc/Cargo.toml b/applications/tari_app_grpc/Cargo.toml index 002eefa59c..f60e707bcb 100644 --- a/applications/tari_app_grpc/Cargo.toml +++ b/applications/tari_app_grpc/Cargo.toml @@ -30,4 +30,3 @@ zeroize = "1.3" [build-dependencies] tonic-build = "0.6.2" - diff --git a/applications/tari_console_wallet/src/automation/commands.rs b/applications/tari_console_wallet/src/automation/commands.rs index cf82ccdbc7..31843fb726 100644 --- a/applications/tari_console_wallet/src/automation/commands.rs +++ b/applications/tari_console_wallet/src/automation/commands.rs @@ -85,7 +85,7 @@ pub enum WalletCommand { SendTari, SendOneSided, CreateKeyPair, - CreateNMUtxo, + CreateAggregateSignatureUtxo, MakeItRain, CoinSplit, DiscoverPeer, @@ -151,7 +151,7 @@ pub async fn create_key_pair( .map_err(CommandError::KeyManagerError) } -pub async fn create_n_m_utxo( +pub async fn create_aggregate_signature_utxo( mut wallet_transaction_service: TransactionServiceHandle, amount: MicroTari, fee_per_gram: MicroTari, @@ -164,7 +164,7 @@ pub async fn create_n_m_utxo( msg.copy_from_slice(message.as_bytes()); wallet_transaction_service - .create_n_m_utxo(amount, fee_per_gram, n, m, public_keys, msg) + .create_aggregate_signature_utxo(amount, fee_per_gram, n, m, public_keys, msg) .await .map_err(CommandError::TransactionServiceError) } @@ -680,7 +680,7 @@ pub async fn command_runner( }, Err(e) => eprintln!("CreateKeyPair error! {}", e), }, - CreateNMUtxo(args) => match create_n_m_utxo( + CreateAggregateSignatureUtxo(args) => match create_aggregate_signature_utxo( transaction_service.clone(), args.amount, args.fee_per_gram, @@ -704,7 +704,7 @@ pub async fn command_runner( args.n, args.m, tx_id, output_hash ) }, - Err(e) => eprintln!("CreateNMUtxo error! {}", e), + Err(e) => eprintln!("CreateAggregateSignatureUtxo error! {}", e), }, SendTari(args) => { match send_tari( diff --git a/applications/tari_console_wallet/src/cli.rs b/applications/tari_console_wallet/src/cli.rs index e97c4da9d4..7922055373 100644 --- a/applications/tari_console_wallet/src/cli.rs +++ b/applications/tari_console_wallet/src/cli.rs @@ -117,7 +117,7 @@ pub enum CliCommands { SendTari(SendTariArgs), BurnTari(BurnTariArgs), CreateKeyPair(CreateKeyPairArgs), - CreateNMUtxo(CreateNMUtxoArgs), + CreateAggregateSignatureUtxo(CreateAggregateSignatureUtxoArgs), SendOneSided(SendTariArgs), SendOneSidedToStealthAddress(SendTariArgs), MakeItRain(MakeItRainArgs), @@ -163,7 +163,7 @@ pub struct CreateKeyPairArgs { } #[derive(Debug, Args, Clone)] -pub struct CreateNMUtxoArgs { +pub struct CreateAggregateSignatureUtxoArgs { pub amount: MicroTari, pub fee_per_gram: MicroTari, pub n: u8, diff --git a/applications/tari_console_wallet/src/wallet_modes.rs b/applications/tari_console_wallet/src/wallet_modes.rs index 045d02ea82..34205a48e8 100644 --- a/applications/tari_console_wallet/src/wallet_modes.rs +++ b/applications/tari_console_wallet/src/wallet_modes.rs @@ -429,7 +429,7 @@ mod test { create-key-pair pie - create-n-m-utxo 125T 100 10 1 5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d61 ff + create-aggregate-signature-utxo 125T 100 10 1 5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d61 ff coin-split --message Make_many_dust_UTXOs! --fee-per-gram 2 0.001T 499 @@ -447,7 +447,7 @@ mod test { let mut send_tari = false; let mut burn_tari = false; let mut create_key_pair = false; - let mut create_n_m_utxo = false; + let mut create_aggregate_signature_utxo = false; let mut make_it_rain = false; let mut coin_split = false; let mut discover_peer = false; @@ -458,7 +458,7 @@ mod test { CliCommands::SendTari(_) => send_tari = true, CliCommands::BurnTari(_) => burn_tari = true, CliCommands::CreateKeyPair(_) => create_key_pair = true, - CliCommands::CreateNMUtxo(_) => create_n_m_utxo = true, + CliCommands::CreateAggregateSignatureUtxo(_) => create_aggregate_signature_utxo = true, CliCommands::SendOneSided(_) => {}, CliCommands::SendOneSidedToStealthAddress(_) => {}, CliCommands::MakeItRain(_) => make_it_rain = true, @@ -483,7 +483,7 @@ mod test { send_tari && burn_tari && create_key_pair && - create_n_m_utxo && + create_aggregate_signature_utxo && make_it_rain && coin_split && discover_peer && diff --git a/base_layer/wallet/src/transaction_service/handle.rs b/base_layer/wallet/src/transaction_service/handle.rs index 3b14844b9a..24ff687639 100644 --- a/base_layer/wallet/src/transaction_service/handle.rs +++ b/base_layer/wallet/src/transaction_service/handle.rs @@ -88,7 +88,7 @@ pub enum TransactionServiceRequest { fee_per_gram: MicroTari, message: String, }, - CreateNMUtxo { + CreateAggregateSignatureUtxo { amount: MicroTari, fee_per_gram: MicroTari, n: u8, @@ -164,7 +164,7 @@ impl fmt::Display for TransactionServiceRequest { message )), Self::BurnTari { amount, message, .. } => f.write_str(&format!("Burning Tari ({}, {})", amount, message)), - Self::CreateNMUtxo { + Self::CreateAggregateSignatureUtxo { amount, fee_per_gram: _, n, @@ -524,7 +524,7 @@ impl TransactionServiceHandle { } } - pub async fn create_n_m_utxo( + pub async fn create_aggregate_signature_utxo( &mut self, amount: MicroTari, fee_per_gram: MicroTari, @@ -535,7 +535,7 @@ impl TransactionServiceHandle { ) -> Result<(TxId, FixedHash), TransactionServiceError> { match self .handle - .call(TransactionServiceRequest::CreateNMUtxo { + .call(TransactionServiceRequest::CreateAggregateSignatureUtxo { amount, fee_per_gram, n, diff --git a/base_layer/wallet/src/transaction_service/service.rs b/base_layer/wallet/src/transaction_service/service.rs index 153d2f290d..02b614b13f 100644 --- a/base_layer/wallet/src/transaction_service/service.rs +++ b/base_layer/wallet/src/transaction_service/service.rs @@ -649,7 +649,7 @@ where ) .await .map(TransactionServiceResponse::TransactionSent), - TransactionServiceRequest::CreateNMUtxo { + TransactionServiceRequest::CreateAggregateSignatureUtxo { amount, fee_per_gram, n, @@ -657,7 +657,7 @@ where public_keys, message, } => self - .create_n_m_utxo( + .create_aggregate_signature_utxo( amount, fee_per_gram, n, @@ -1007,7 +1007,7 @@ where /// Creates a utxo with aggregate public key out of m-of-n public keys #[allow(clippy::too_many_lines)] - pub async fn create_n_m_utxo( + pub async fn create_aggregate_signature_utxo( &mut self, amount: MicroTari, fee_per_gram: MicroTari, From 9afb5ac183dde2ec1d768f3410b9e529ea2765bb Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Thu, 6 Oct 2022 09:48:25 +0100 Subject: [PATCH 26/30] resolve further merge conflicts --- Cargo.lock | 2 +- applications/tari_console_wallet/src/automation/commands.rs | 4 ++-- applications/tari_console_wallet/src/wallet_modes.rs | 2 ++ infrastructure/tari_script/Cargo.toml | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 57f6731910..0997c208ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5262,7 +5262,7 @@ dependencies = [ "blake2 0.9.2", "digest 0.9.0", "integer-encoding 3.0.4", - "rand 0.8.5", + "rand 0.7.3", "serde", "sha2 0.9.9", "sha3", diff --git a/applications/tari_console_wallet/src/automation/commands.rs b/applications/tari_console_wallet/src/automation/commands.rs index feed6472fe..2cce156d84 100644 --- a/applications/tari_console_wallet/src/automation/commands.rs +++ b/applications/tari_console_wallet/src/automation/commands.rs @@ -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, PublicKey, PrivateKey}, }; use tari_comms::{ connectivity::{ConnectivityEvent, ConnectivityRequester}, @@ -57,7 +57,7 @@ use tari_utilities::{hex::Hex, ByteArray}; use tari_wallet::{ connectivity_service::WalletConnectivityInterface, error::WalletError, - key_manager_service::{KeyManagerInterface, NextKeyResult}, + key_manager_service::{KeyManagerInterface, NextKeyResult, storage::database::KeyManagerBackend, KeyManagerHandle}, output_manager_service::{handle::OutputManagerHandle, UtxoSelectionCriteria}, transaction_service::handle::{TransactionEvent, TransactionServiceHandle}, TransactionStage, diff --git a/applications/tari_console_wallet/src/wallet_modes.rs b/applications/tari_console_wallet/src/wallet_modes.rs index fc937e4cdb..3875c08fbc 100644 --- a/applications/tari_console_wallet/src/wallet_modes.rs +++ b/applications/tari_console_wallet/src/wallet_modes.rs @@ -450,6 +450,8 @@ mod test { let mut create_key_pair = false; let mut create_aggregate_signature_utxo = false; let mut make_it_rain = false; + let mut coin_split = false; + let mut discover_peer = false; let mut whois = false; for command in commands { match command { diff --git a/infrastructure/tari_script/Cargo.toml b/infrastructure/tari_script/Cargo.toml index 6e20411f61..c0f5e1af53 100644 --- a/infrastructure/tari_script/Cargo.toml +++ b/infrastructure/tari_script/Cargo.toml @@ -23,4 +23,4 @@ sha3 = "0.9" thiserror = "1.0.30" [dev-dependencies] -rand = "0.8.5" +rand = "0.7.3" From ea75fbe509d3c315f79e5eee6dcbec6ea3e6fd41 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Thu, 6 Oct 2022 10:36:43 +0100 Subject: [PATCH 27/30] resolve args --- .../tari_console_wallet/src/automation/commands.rs | 8 ++++---- applications/tari_console_wallet/src/cli.rs | 1 + applications/tari_console_wallet/src/wallet_modes.rs | 4 ++-- base_layer/wallet/src/transaction_service/handle.rs | 6 +++--- base_layer/wallet/src/transaction_service/service.rs | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/applications/tari_console_wallet/src/automation/commands.rs b/applications/tari_console_wallet/src/automation/commands.rs index 2cce156d84..cf7d40cbf9 100644 --- a/applications/tari_console_wallet/src/automation/commands.rs +++ b/applications/tari_console_wallet/src/automation/commands.rs @@ -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, PrivateKey}, + types::{CommitmentFactory, FixedHash, PrivateKey, PublicKey}, }; use tari_comms::{ connectivity::{ConnectivityEvent, ConnectivityRequester}, @@ -57,7 +57,7 @@ use tari_utilities::{hex::Hex, ByteArray}; use tari_wallet::{ connectivity_service::WalletConnectivityInterface, error::WalletError, - key_manager_service::{KeyManagerInterface, NextKeyResult, storage::database::KeyManagerBackend, KeyManagerHandle}, + key_manager_service::{storage::database::KeyManagerBackend, KeyManagerHandle, KeyManagerInterface, NextKeyResult}, output_manager_service::{handle::OutputManagerHandle, UtxoSelectionCriteria}, transaction_service::handle::{TransactionEvent, TransactionServiceHandle}, TransactionStage, @@ -689,8 +689,8 @@ pub async fn command_runner( args.m, args.public_keys .iter() - .map(|pk| (PublicKey::from(pk.clone()))) - .collect(), + .map(|pk| PublicKey::from(pk.clone())) + .collect::>(), args.message, ) .await diff --git a/applications/tari_console_wallet/src/cli.rs b/applications/tari_console_wallet/src/cli.rs index 25baa7574d..6200607a70 100644 --- a/applications/tari_console_wallet/src/cli.rs +++ b/applications/tari_console_wallet/src/cli.rs @@ -168,6 +168,7 @@ pub struct CreateAggregateSignatureUtxoArgs { pub fee_per_gram: MicroTari, pub n: u8, pub m: u8, + #[clap(last = true)] pub public_keys: Vec, pub message: String, } diff --git a/applications/tari_console_wallet/src/wallet_modes.rs b/applications/tari_console_wallet/src/wallet_modes.rs index 3875c08fbc..0dc66f7c02 100644 --- a/applications/tari_console_wallet/src/wallet_modes.rs +++ b/applications/tari_console_wallet/src/wallet_modes.rs @@ -429,8 +429,8 @@ mod test { create-key-pair pie - create-aggregate-signature-utxo 125T 100 10 1 \ - 5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d61 ff + create-aggregate-signature-utxo 125T 100 10 1 ff \ + [5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d61] coin-split --message Make_many_dust_UTXOs! --fee-per-gram 2 0.001T 499 diff --git a/base_layer/wallet/src/transaction_service/handle.rs b/base_layer/wallet/src/transaction_service/handle.rs index 24ff687639..5275806912 100644 --- a/base_layer/wallet/src/transaction_service/handle.rs +++ b/base_layer/wallet/src/transaction_service/handle.rs @@ -88,7 +88,7 @@ pub enum TransactionServiceRequest { fee_per_gram: MicroTari, message: String, }, - CreateAggregateSignatureUtxo { + CreateNMUtxo { amount: MicroTari, fee_per_gram: MicroTari, n: u8, @@ -164,7 +164,7 @@ impl fmt::Display for TransactionServiceRequest { message )), Self::BurnTari { amount, message, .. } => f.write_str(&format!("Burning Tari ({}, {})", amount, message)), - Self::CreateAggregateSignatureUtxo { + Self::CreateNMUtxo { amount, fee_per_gram: _, n, @@ -535,7 +535,7 @@ impl TransactionServiceHandle { ) -> Result<(TxId, FixedHash), TransactionServiceError> { match self .handle - .call(TransactionServiceRequest::CreateAggregateSignatureUtxo { + .call(TransactionServiceRequest::CreateNMUtxo { amount, fee_per_gram, n, diff --git a/base_layer/wallet/src/transaction_service/service.rs b/base_layer/wallet/src/transaction_service/service.rs index 02b614b13f..474b87869a 100644 --- a/base_layer/wallet/src/transaction_service/service.rs +++ b/base_layer/wallet/src/transaction_service/service.rs @@ -649,7 +649,7 @@ where ) .await .map(TransactionServiceResponse::TransactionSent), - TransactionServiceRequest::CreateAggregateSignatureUtxo { + TransactionServiceRequest::CreateNMUtxo { amount, fee_per_gram, n, From 9346207a1227cac32fabc1436d8a079d7b5482e8 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Thu, 6 Oct 2022 10:54:32 +0100 Subject: [PATCH 28/30] correct remaining test --- .../tari_console_wallet/src/automation/commands.rs | 14 ++------------ applications/tari_console_wallet/src/cli.rs | 3 +-- .../tari_console_wallet/src/wallet_modes.rs | 3 ++- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/applications/tari_console_wallet/src/automation/commands.rs b/applications/tari_console_wallet/src/automation/commands.rs index cf7d40cbf9..a8e3f28f2c 100644 --- a/applications/tari_console_wallet/src/automation/commands.rs +++ b/applications/tari_console_wallet/src/automation/commands.rs @@ -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, PrivateKey, PublicKey}, + types::{CommitmentFactory, FixedHash, PublicKey}, }; use tari_comms::{ connectivity::{ConnectivityEvent, ConnectivityRequester}, @@ -57,7 +57,7 @@ use tari_utilities::{hex::Hex, ByteArray}; use tari_wallet::{ connectivity_service::WalletConnectivityInterface, error::WalletError, - key_manager_service::{storage::database::KeyManagerBackend, KeyManagerHandle, KeyManagerInterface, NextKeyResult}, + key_manager_service::{KeyManagerInterface, NextKeyResult}, output_manager_service::{handle::OutputManagerHandle, UtxoSelectionCriteria}, transaction_service::handle::{TransactionEvent, TransactionServiceHandle}, TransactionStage, @@ -142,16 +142,6 @@ pub async fn burn_tari( .map_err(CommandError::TransactionServiceError) } -pub async fn create_key_pair( - key_manager_service: KeyManagerHandle, - key_seed: String, -) -> Result<(PrivateKey, PublicKey), CommandError> { - key_manager_service - .create_key_pair(key_seed) - .await - .map_err(CommandError::KeyManagerError) -} - pub async fn create_aggregate_signature_utxo( mut wallet_transaction_service: TransactionServiceHandle, amount: MicroTari, diff --git a/applications/tari_console_wallet/src/cli.rs b/applications/tari_console_wallet/src/cli.rs index 6200607a70..30b1115e71 100644 --- a/applications/tari_console_wallet/src/cli.rs +++ b/applications/tari_console_wallet/src/cli.rs @@ -168,9 +168,8 @@ pub struct CreateAggregateSignatureUtxoArgs { pub fee_per_gram: MicroTari, pub n: u8, pub m: u8, - #[clap(last = true)] - pub public_keys: Vec, pub message: String, + pub public_keys: Vec, } #[derive(Debug, Args, Clone)] diff --git a/applications/tari_console_wallet/src/wallet_modes.rs b/applications/tari_console_wallet/src/wallet_modes.rs index 0dc66f7c02..a1e902fd54 100644 --- a/applications/tari_console_wallet/src/wallet_modes.rs +++ b/applications/tari_console_wallet/src/wallet_modes.rs @@ -430,7 +430,8 @@ mod test { create-key-pair pie create-aggregate-signature-utxo 125T 100 10 1 ff \ - [5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d61] + 5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d61 \ + f6b2ca781342a3ebe30ee1643655c96f1d7c14f4d49f077695395de98ae73665 coin-split --message Make_many_dust_UTXOs! --fee-per-gram 2 0.001T 499 From b4236310682207f938aee5b6fb53aec0bc5a97fc Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Thu, 6 Oct 2022 11:01:22 +0100 Subject: [PATCH 29/30] refactor cargo toml --- applications/tari_console_wallet/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/applications/tari_console_wallet/Cargo.toml b/applications/tari_console_wallet/Cargo.toml index ff4fbccfc8..1b0f1d5ea2 100644 --- a/applications/tari_console_wallet/Cargo.toml +++ b/applications/tari_console_wallet/Cargo.toml @@ -19,7 +19,6 @@ tari_app_grpc = { path = "../tari_app_grpc" } tari_shutdown = { path = "../../infrastructure/shutdown" } tari_key_manager = { path = "../../base_layer/key_manager" } tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag = "v0.4.7" } -zeroize = "1.3" # Uncomment for tokio tracing via tokio-console (needs "tracing" featurs) #console-subscriber = "0.1.3" From c82ea6e54c5ad56e139c7f3d9941a9f428992b24 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Thu, 6 Oct 2022 16:04:22 +0100 Subject: [PATCH 30/30] refactor cucumber test --- integration_tests/features/WalletCli.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_tests/features/WalletCli.feature b/integration_tests/features/WalletCli.feature index f53669e00d..5dc8fdcd19 100644 --- a/integration_tests/features/WalletCli.feature +++ b/integration_tests/features/WalletCli.feature @@ -66,7 +66,7 @@ Feature: Wallet CLI When I create a burn transaction of 201552500000 uT from WALLET via command line When I mine 5 blocks on BASE Then all nodes are at height 20 - Then I get balance of wallet WALLET is at least 20000000000 uT via command line + Then I get balance of wallet WALLET is at least 15000000000 uT via command line # TODO: verify the actual burned kernel @long-running