Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add encumber aggregate utxo creation method for wallet cli #4798

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
62a6c03
first commit, add handle to verify aggregate signatures
jorgeantonio21 Sep 27, 2022
061f5e2
Add multisig script with agg pk
hansieodendaal Sep 26, 2022
40b3dee
add create_key_combo method for wallet cli
jorgeantonio21 Sep 28, 2022
f05444e
Merge branch 'development' into ja-multisig-op
jorgeantonio21 Sep 28, 2022
fc29b2f
execute cargo fmt
jorgeantonio21 Sep 28, 2022
d41e44a
add refactor on PR comments plus add test
jorgeantonio21 Sep 28, 2022
a2f01ad
refactor message for create key combo
jorgeantonio21 Sep 28, 2022
e79acc4
refactor clap_parses_user_defined_commands_as_expected
jorgeantonio21 Sep 28, 2022
e11ee31
address PR comments
jorgeantonio21 Sep 29, 2022
4069ab8
fix clippy
jorgeantonio21 Sep 29, 2022
6d80422
replace debug with {}
jorgeantonio21 Sep 29, 2022
45ad9df
Merge remote-tracking branch 'hansieodendaal/ho_CheckMultiSigVerifyAg…
jorgeantonio21 Sep 29, 2022
b8e40ca
add create-n-m-utxo cli command
jorgeantonio21 Sep 30, 2022
86c7017
Merge branch 'development' into ja-multisig-signature-utxo
jorgeantonio21 Sep 30, 2022
f850b11
refactor and clean code
jorgeantonio21 Sep 30, 2022
b907962
add test
jorgeantonio21 Sep 30, 2022
f783536
address some comments on PR
jorgeantonio21 Sep 30, 2022
676cfc3
refactor failing test
jorgeantonio21 Sep 30, 2022
2948a6d
refactor code according to PR comments
jorgeantonio21 Oct 3, 2022
18c915d
add further sugggestions impls
jorgeantonio21 Oct 3, 2022
547caab
add rand to [dev-dependencies] instead
jorgeantonio21 Oct 3, 2022
1b2c573
remove line
jorgeantonio21 Oct 3, 2022
717981c
resolve merge conflicts
jorgeantonio21 Oct 3, 2022
29796e1
add skeleton of sign-message cli command
jorgeantonio21 Oct 3, 2022
ee4776d
make changes to SignMessageArgs
jorgeantonio21 Oct 4, 2022
cc4b071
refactor code to print signature correctly
jorgeantonio21 Oct 4, 2022
d5b3196
Merge branch 'development' into ja-multisig-sign-message
jorgeantonio21 Oct 4, 2022
57b510b
resolve conflicts
jorgeantonio21 Oct 4, 2022
28dbddb
add renaming of create key combo -> create key pair
jorgeantonio21 Oct 4, 2022
cad4fb5
add changes
jorgeantonio21 Oct 4, 2022
ea17fca
add clippy
jorgeantonio21 Oct 4, 2022
2e3038f
run cargo fmt
jorgeantonio21 Oct 4, 2022
2e4f7cc
add clippy allowance for many lines in create_n_m_utxo
jorgeantonio21 Oct 4, 2022
306e643
refactor test
jorgeantonio21 Oct 4, 2022
cc39ac4
refactor parsing test
jorgeantonio21 Oct 5, 2022
2f547f2
Merge branch 'development' into ja-multisig-sign-message
jorgeantonio21 Oct 5, 2022
e9cd61a
Merge branch 'development' into ja-multisig-signature-utxo
jorgeantonio21 Oct 6, 2022
90def27
merge files
jorgeantonio21 Oct 6, 2022
2e2ddc6
minor changes
jorgeantonio21 Oct 6, 2022
3a137c4
merge and resolve conflicts
jorgeantonio21 Oct 6, 2022
9afb5ac
resolve further merge conflicts
jorgeantonio21 Oct 6, 2022
ea75fbe
resolve args
jorgeantonio21 Oct 6, 2022
9346207
correct remaining test
jorgeantonio21 Oct 6, 2022
dfcd081
Merge branch 'feature-m-of-n' into ja-multisig-signature-utxo
jorgeantonio21 Oct 6, 2022
b423631
refactor cargo toml
jorgeantonio21 Oct 6, 2022
b04b627
Merge branch 'feature-m-of-n' into ja-multisig-signature-utxo
jorgeantonio21 Oct 6, 2022
e59be99
fix(p2p/liveness): remove fallible unwrap (#4784)
sdbondi Oct 6, 2022
c82ea6e
refactor cucumber test
jorgeantonio21 Oct 6, 2022
52f5466
merge conflicts
jorgeantonio21 Oct 6, 2022
a31a3ab
cargo fmt
jorgeantonio21 Oct 6, 2022
604657f
cargo clippy
jorgeantonio21 Oct 6, 2022
6ec6902
cargo fmt
jorgeantonio21 Oct 6, 2022
8ae81dd
refactor code after PR comments
jorgeantonio21 Oct 10, 2022
e103f7d
run cargo fmt
jorgeantonio21 Oct 10, 2022
e228806
Merge branch 'development' into ja-multisig-sign-message
jorgeantonio21 Oct 10, 2022
a79e644
squase commits
jorgeantonio21 Oct 12, 2022
bf7c7ba
rebase
jorgeantonio21 Oct 12, 2022
0295c44
rebase v2
jorgeantonio21 Oct 12, 2022
54f72d6
Merge branch 'feature-m-of-n' into ja-multisig-metadata-signature-utxo
jorgeantonio21 Oct 12, 2022
2c43a19
rebase file that should have not been changed
jorgeantonio21 Oct 12, 2022
9795a48
cargo clippy
jorgeantonio21 Oct 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions applications/tari_app_utilities/src/utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ use log::*;
use tari_common::exit_codes::{ExitCode, ExitError};
use tari_common_types::{
emoji::EmojiId,
types::{BlockHash, PublicKey},
types::{BlockHash, PrivateKey, PublicKey, Signature},
};
use tari_comms::{peer_manager::NodeId, types::CommsPublicKey};
use tari_utilities::hex::Hex;
use tari_utilities::hex::{Hex, HexError};
use thiserror::Error;
use tokio::{runtime, runtime::Runtime};

Expand Down Expand Up @@ -96,6 +96,28 @@ impl From<UniPublicKey> for PublicKey {
}
}

#[derive(Debug, Clone)]
pub struct UniSignature(Signature);

impl FromStr for UniSignature {
type Err = HexError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let data = s.split(',').collect::<Vec<_>>();
let signature = PrivateKey::from_hex(data[0])?;
let public_nonce = PublicKey::from_hex(data[1])?;

let signature = Signature::new(public_nonce, signature);
Ok(Self(signature))
}
}

impl From<UniSignature> for Signature {
fn from(id: UniSignature) -> Self {
id.0
}
}

#[derive(Debug)]
pub enum UniNodeId {
PublicKey(PublicKey),
Expand Down
74 changes: 71 additions & 3 deletions applications/tari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,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, Signature},
types::{Commitment, CommitmentFactory, FixedHash, PrivateKey, PublicKey, Signature},
};
use tari_comms::{
connectivity::{ConnectivityEvent, ConnectivityRequester},
Expand All @@ -54,7 +54,7 @@ use tari_core::transactions::{
tari_amount::{uT, MicroTari, Tari},
transaction_components::{OutputFeatures, TransactionOutput, UnblindedOutput},
};
use tari_crypto::keys::{PublicKey as TraitPublicKey, SecretKey};
use tari_crypto::keys::SecretKey;
use tari_utilities::{hex::Hex, ByteArray};
use tari_wallet::{
connectivity_service::WalletConnectivityInterface,
Expand Down Expand Up @@ -90,6 +90,7 @@ pub enum WalletCommand {
CreateKeyPair,
CreateAggregateSignatureUtxo,
SignMessage,
EncumberAggregateUtxo,
MakeItRain,
CoinSplit,
DiscoverPeer,
Expand Down Expand Up @@ -163,6 +164,33 @@ pub async fn create_aggregate_signature_utxo(
.map_err(CommandError::TransactionServiceError)
}

/// creates a metadata signature utxo
async fn encumber_aggregate_utxo(
mut wallet_transaction_service: TransactionServiceHandle,
fee_per_gram: MicroTari,
output_hash: String,
signatures: Vec<Signature>,
total_script_pubkey: PublicKey,
total_offset_pubkey: PublicKey,
total_signature_nonce: PublicKey,
metadata_signature_nonce: PublicKey,
wallet_script_secret_key: String,
) -> Result<(TxId, Commitment, FixedHash, Commitment, String, String, PublicKey), CommandError> {
wallet_transaction_service
.encumber_aggregate_utxo(
fee_per_gram,
output_hash,
signatures,
total_script_pubkey,
total_offset_pubkey,
total_signature_nonce,
metadata_signature_nonce,
wallet_script_secret_key,
)
.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,
Expand Down Expand Up @@ -281,7 +309,7 @@ pub fn sign_message(private_key: String, challenge: String) -> Result<Signature,
let challenge = challenge.as_bytes();

let nonce = PrivateKey::random(&mut OsRng);
let signature = Signature::sign(private_key, nonce.clone(), challenge).map_err(CommandError::FailedSignature)?;
let signature = Signature::sign(private_key, nonce, challenge).map_err(CommandError::FailedSignature)?;

Ok(signature)
}
Expand Down Expand Up @@ -723,6 +751,46 @@ pub async fn command_runner(
},
Err(e) => eprintln!("SignMessage error! {}", e),
},
EncumberAggregateUtxo(args) => match encumber_aggregate_utxo(
transaction_service.clone(),
args.fee_per_gram,
args.output_hash,
args.signatures.iter().map(|sgn| sgn.clone().into()).collect::<Vec<_>>(),
args.total_script_pubkey.into(),
args.total_offset_pubkey.into(),
args.total_signature_nonce.into(),
args.metadata_signature_nonce.into(),
args.wallet_script_secret_key,
)
.await
{
Ok((
_tx_id,
output_commitment,
output_hash,
input_commitment,
input_script_hex,
input_commitment_hex,
total_public_offset,
)) => {
println!(
"Encumber aggregate utxo:
1. output_commitment: {},
2. output_hash: {},
3. input_commitment: {},
4. input_stack_hex: {},
5. input_script_hex: {},
6. total_public_offes: {}",
output_commitment.to_hex(),
output_hash.to_hex(),
input_commitment.to_hex(),
input_script_hex,
input_commitment_hex,
total_public_offset.to_hex(),
)
},
Err(e) => eprintln!("Encumber aggregate utxo! {}", e),
},
SendTari(args) => {
match send_tari(
transaction_service.clone(),
Expand Down
20 changes: 18 additions & 2 deletions applications/tari_console_wallet/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ use std::{

use chrono::{DateTime, Utc};
use clap::{Args, Parser, Subcommand};
use tari_app_utilities::{common_cli_args::CommonCliArgs, utilities::UniPublicKey};
use tari_app_utilities::{
common_cli_args::CommonCliArgs,
utilities::{UniPublicKey, UniSignature},
};
use tari_common::configuration::{ConfigOverrideProvider, Network};
use tari_comms::multiaddr::Multiaddr;
use tari_core::transactions::{tari_amount, tari_amount::MicroTari};
Expand Down Expand Up @@ -116,8 +119,9 @@ pub enum CliCommands {
GetBalance,
SendTari(SendTariArgs),
BurnTari(BurnTariArgs),
CreateKeyPair(CreateKeyPairArgs),
CreateAggregateSignatureUtxo(CreateAggregateSignatureUtxoArgs),
CreateKeyPair(CreateKeyPairArgs),
EncumberAggregateUtxo(EncumberAggregateUtxoArgs),
SignMessage(SignMessageArgs),
SendOneSided(SendTariArgs),
SendOneSidedToStealthAddress(SendTariArgs),
Expand Down Expand Up @@ -180,6 +184,18 @@ pub struct SignMessageArgs {
pub challenge: String,
}

#[derive(Debug, Args, Clone)]
pub struct EncumberAggregateUtxoArgs {
pub fee_per_gram: MicroTari,
pub output_hash: String,
pub signatures: Vec<UniSignature>,
pub total_script_pubkey: UniPublicKey,
pub total_offset_pubkey: UniPublicKey,
pub total_signature_nonce: UniPublicKey,
pub metadata_signature_nonce: UniPublicKey,
pub wallet_script_secret_key: String,
}

#[derive(Debug, Args, Clone)]
pub struct MakeItRainArgs {
pub destination: UniPublicKey,
Expand Down
2 changes: 2 additions & 0 deletions applications/tari_console_wallet/src/wallet_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ mod test {
let mut create_key_pair = false;
let mut create_aggregate_signature_utxo = false;
let mut sign_message = false;
let mut _encumbered_aggregate_utxo = false;
let mut make_it_rain = false;
let mut coin_split = false;
let mut discover_peer = false;
Expand All @@ -465,6 +466,7 @@ mod test {
CliCommands::CreateKeyPair(_) => create_key_pair = true,
CliCommands::CreateAggregateSignatureUtxo(_) => create_aggregate_signature_utxo = true,
CliCommands::SignMessage(_) => sign_message = true,
CliCommands::EncumberAggregateUtxo(_) => _encumbered_aggregate_utxo = true,
CliCommands::SendOneSided(_) => {},
CliCommands::SendOneSidedToStealthAddress(_) => {},
CliCommands::MakeItRain(_) => make_it_rain = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ impl TransactionOutput {
}

// Create commitment signature for the metadata

fn create_metadata_signature(
pub fn create_metadata_signature(
version: TransactionOutputVersion,
value: MicroTari,
spending_key: &BlindingFactor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,53 @@ impl UnblindedOutput {
))
}

/// it creates a transaction input given a partial script signature. The public keys
/// partial_script_public_key and partial_total_nonce exclude callers private keys use
pub fn as_transaction_input_with_partial_signature(
jorgeantonio21 marked this conversation as resolved.
Show resolved Hide resolved
&self,
factory: &CommitmentFactory,
partial_script_public_key: PublicKey,
partial_total_nonce: PublicKey,
) -> Result<TransactionInput, TransactionError> {
let commitment = factory.commit(&self.spending_key, &self.value.into());
let script_nonce_a = PrivateKey::random(&mut OsRng);
let script_nonce_b = PrivateKey::random(&mut OsRng);
let nonce_commitment = factory.commit(&script_nonce_b, &script_nonce_a);

let challenge = TransactionInput::build_script_challenge(
TransactionInputVersion::get_current_version(),
&(&nonce_commitment + &partial_total_nonce),
&self.script,
&self.input_data,
&(&PublicKey::from_secret_key(&self.script_private_key) + &partial_script_public_key),
&commitment,
);
let script_signature = ComSignature::sign(
&self.value.into(),
&(&self.script_private_key + &self.spending_key),
&script_nonce_a,
&script_nonce_b,
&challenge,
factory,
)
.map_err(|_| TransactionError::InvalidSignatureError("Generating script signature".to_string()))?;

Ok(TransactionInput::new_current_version(
SpentOutput::OutputData {
features: self.features.clone(),
commitment,
script: self.script.clone(),
sender_offset_public_key: self.sender_offset_public_key.clone(),
covenant: self.covenant.clone(),
version: self.version,
encrypted_value: self.encrypted_value.clone(),
minimum_value_promise: self.minimum_value_promise,
},
self.input_data.clone(),
script_signature,
))
}

/// Commits an UnblindedOutput into a TransactionInput that only contains the hash of the spent output data
pub fn as_compact_transaction_input(
&self,
Expand Down
53 changes: 52 additions & 1 deletion base_layer/wallet/src/output_manager_service/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::{fmt, fmt::Formatter, sync::Arc};
use chacha20poly1305::XChaCha20Poly1305;
use tari_common_types::{
transaction::TxId,
types::{Commitment, HashOutput, PublicKey},
types::{Commitment, HashOutput, PublicKey, Signature},
};
use tari_core::{
covenants::Covenant,
Expand Down Expand Up @@ -75,6 +75,17 @@ pub enum OutputManagerRequest {
GetRecipientTransaction(TransactionSenderMessage),
GetCoinbaseTransaction((TxId, MicroTari, MicroTari, u64)),
ConfirmPendingTransaction(TxId),
EncumberAggregateUtxo {
tx_id: TxId,
fee_per_gram: MicroTari,
output_hash: String,
signatures: Vec<Signature>,
total_script_pubkey: PublicKey,
total_offset_pubkey: PublicKey,
total_signature_nonce: PublicKey,
metadata_signature_nonce: PublicKey,
wallet_script_secret_key: String,
},
PrepareToSendTransaction {
tx_id: TxId,
amount: MicroTari,
Expand Down Expand Up @@ -142,6 +153,7 @@ pub enum OutputManagerRequest {
}

impl fmt::Display for OutputManagerRequest {
#[allow(clippy::too_many_lines)]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
#[allow(clippy::enum_glob_use)]
use OutputManagerRequest::*;
Expand All @@ -162,6 +174,11 @@ impl fmt::Display for OutputManagerRequest {
v.metadata_signature.u().to_hex(),
v.metadata_signature.v().to_hex()
),
EncumberAggregateUtxo { tx_id, output_hash, .. } => write!(
f,
"Encumber aggregate utxo with tx_id: {} and output_hash: {}",
tx_id, output_hash
),
GetRecipientTransaction(_) => write!(f, "GetRecipientTransaction"),
ConfirmPendingTransaction(v) => write!(f, "ConfirmPendingTransaction ({})", v),
PrepareToSendTransaction { message, .. } => write!(f, "PrepareToSendTransaction ({})", message),
Expand Down Expand Up @@ -241,8 +258,10 @@ pub enum OutputManagerResponse {
Balance(Balance),
OutputAdded,
ConvertedToTransactionOutput(Box<TransactionOutput>),
ConvertedToTransaction(Box<Transaction>),
OutputMetadataSignatureUpdated,
RecipientTransactionGenerated(ReceiverTransactionProtocol),
EncumberAggregateUtxo(Transaction),
CoinbaseTransaction(Transaction),
OutputConfirmed,
PendingTransactionConfirmed,
Expand Down Expand Up @@ -850,6 +869,38 @@ impl OutputManagerHandle {
}
}

pub async fn encumber_aggregate_utxo(
&mut self,
tx_id: TxId,
fee_per_gram: MicroTari,
output_hash: String,
signatures: Vec<Signature>,
total_script_pubkey: PublicKey,
total_offset_pubkey: PublicKey,
total_signature_nonce: PublicKey,
metadata_signature_nonce: PublicKey,
wallet_script_secret_key: String,
) -> Result<Transaction, OutputManagerError> {
match self
.handle
.call(OutputManagerRequest::EncumberAggregateUtxo {
tx_id,
fee_per_gram,
output_hash,
signatures,
total_script_pubkey,
total_offset_pubkey,
total_signature_nonce,
metadata_signature_nonce,
wallet_script_secret_key,
})
.await??
{
OutputManagerResponse::EncumberAggregateUtxo(transaction) => Ok(transaction),
_ => Err(OutputManagerError::UnexpectedApiResponse),
}
}

pub async fn create_pay_to_self_transaction(
&mut self,
tx_id: TxId,
Expand Down
Loading