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: creates a wallet command to create a signature and a nonce from a private key and challenge #4776

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 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
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
8ba21a8
Merge branch 'feature-m-of-n' into ja-multisig-sign-message
jorgeantonio21 Oct 10, 2022
3b32629
Update applications/tari_console_wallet/src/automation/commands.rs
stringhandler Oct 12, 2022
c2b9713
Update applications/tari_console_wallet/src/automation/commands.rs
stringhandler Oct 12, 2022
558351b
Apply suggestions from code review
stringhandler 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
28 changes: 27 additions & 1 deletion applications/tari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ use chrono::{DateTime, Utc};
use digest::Digest;
use futures::FutureExt;
use log::*;
use rand::rngs::OsRng;
use serde::{de::DeserializeOwned, Serialize};
use sha2::Sha256;
use strum_macros::{Display, EnumIter, EnumString};
use tari_app_grpc::authentication::salted_password::create_salted_hashed_password;
use tari_common_types::{
emoji::EmojiId,
transaction::TxId,
types::{CommitmentFactory, FixedHash, PublicKey},
types::{CommitmentFactory, FixedHash, PrivateKey, PublicKey, Signature},
};
use tari_comms::{
connectivity::{ConnectivityEvent, ConnectivityRequester},
Expand All @@ -53,6 +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_utilities::{hex::Hex, ByteArray};
use tari_wallet::{
connectivity_service::WalletConnectivityInterface,
Expand Down Expand Up @@ -87,6 +89,7 @@ pub enum WalletCommand {
SendOneSided,
CreateKeyPair,
CreateAggregateSignatureUtxo,
SignMessage,
MakeItRain,
CoinSplit,
DiscoverPeer,
Expand Down Expand Up @@ -272,6 +275,17 @@ pub async fn coin_split(
Ok(tx_id)
}

pub fn sign_message(private_key: String, challenge: String) -> Result<Signature, CommandError> {
let private_key =
PrivateKey::from_hex(private_key.as_str()).map_err(|e| CommandError::InvalidArgument(e.to_string()))?;
let challenge = challenge.as_bytes();

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

Ok(signature)
}

async fn wait_for_comms(connectivity_requester: &ConnectivityRequester) -> Result<(), CommandError> {
let mut connectivity = connectivity_requester.get_event_subscription();
print!("Waiting for connectivity... ");
Expand Down Expand Up @@ -697,6 +711,18 @@ pub async fn command_runner(
},
Err(e) => eprintln!("CreateAggregateSignatureUtxo error! {}", e),
},
SignMessage(args) => match sign_message(args.private_key, args.challenge) {
Ok(sgn) => {
println!(
"Sign message:
1. signature: {},
2. public key: {}",
sgn.get_signature().to_hex(),
sgn.get_public_nonce().to_hex(),
)
},
Err(e) => eprintln!("SignMessage error! {}", e),
},
SendTari(args) => {
match send_tari(
transaction_service.clone(),
Expand Down
3 changes: 3 additions & 0 deletions applications/tari_console_wallet/src/automation/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use log::*;
use tari_common::exit_codes::{ExitCode, ExitError};
use tari_common_types::types::FixedHashSizeError;
use tari_core::transactions::{tari_amount::MicroTariError, transaction_components::TransactionError};
use tari_crypto::signatures::SchnorrSignatureError;
use tari_utilities::hex::HexError;
use tari_wallet::{
error::{WalletError, WalletStorageError},
Expand Down Expand Up @@ -82,6 +83,8 @@ pub enum CommandError {
General(String),
#[error("FixedHash size error `{0}`")]
FixedHashSizeError(#[from] FixedHashSizeError),
#[error("Invalid signature: `{0}`")]
FailedSignature(#[from] SchnorrSignatureError),
}

impl From<CommandError> for ExitError {
Expand Down
7 changes: 7 additions & 0 deletions applications/tari_console_wallet/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ pub enum CliCommands {
BurnTari(BurnTariArgs),
CreateKeyPair(CreateKeyPairArgs),
CreateAggregateSignatureUtxo(CreateAggregateSignatureUtxoArgs),
SignMessage(SignMessageArgs),
SendOneSided(SendTariArgs),
SendOneSidedToStealthAddress(SendTariArgs),
MakeItRain(MakeItRainArgs),
Expand Down Expand Up @@ -173,6 +174,12 @@ pub struct CreateAggregateSignatureUtxoArgs {
pub public_keys: Vec<UniPublicKey>,
}

#[derive(Debug, Args, Clone)]
pub struct SignMessageArgs {
pub private_key: String,
pub challenge: String,
}

#[derive(Debug, Args, Clone)]
pub struct MakeItRainArgs {
pub destination: UniPublicKey,
Expand Down
5 changes: 5 additions & 0 deletions applications/tari_console_wallet/src/wallet_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ mod test {
--public-keys=5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d61 \
--public-keys=f6b2ca781342a3ebe30ee1643655c96f1d7c14f4d49f077695395de98ae73665

sign-message 5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d61 my_challenge!

coin-split --message Make_many_dust_UTXOs! --fee-per-gram 2 0.001T 499

make-it-rain --duration 100 --transactions-per-second 10 --start-amount 0.009200T --increase-amount 0T \
Expand All @@ -450,6 +452,7 @@ mod test {
let mut burn_tari = false;
let mut create_key_pair = false;
let mut create_aggregate_signature_utxo = false;
let mut sign_message = false;
let mut make_it_rain = false;
let mut coin_split = false;
let mut discover_peer = false;
Expand All @@ -461,6 +464,7 @@ mod test {
CliCommands::BurnTari(_) => burn_tari = true,
CliCommands::CreateKeyPair(_) => create_key_pair = true,
CliCommands::CreateAggregateSignatureUtxo(_) => create_aggregate_signature_utxo = true,
CliCommands::SignMessage(_) => sign_message = true,
CliCommands::SendOneSided(_) => {},
CliCommands::SendOneSidedToStealthAddress(_) => {},
CliCommands::MakeItRain(_) => make_it_rain = true,
Expand All @@ -486,6 +490,7 @@ mod test {
burn_tari &&
create_key_pair &&
create_aggregate_signature_utxo &&
sign_message &&
make_it_rain &&
coin_split &&
discover_peer &&
Expand Down
8 changes: 4 additions & 4 deletions infrastructure/tari_script/src/op_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,10 @@ impl fmt::Display for Opcode {
(*msg).to_hex()
))
},
Return => fmt.write_str("Return"),
IfThen => fmt.write_str("IfThen"),
Else => fmt.write_str("Else"),
EndIf => fmt.write_str("EndIf"),
Return => write!(fmt, "Return"),
IfThen => write!(fmt, "IfThen"),
Else => write!(fmt, "Else"),
EndIf => write!(fmt, "EndIf"),
}
}
}
Expand Down