Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hansieodendaal committed Jul 10, 2024
1 parent 3255cf0 commit e3068d1
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 132 deletions.
148 changes: 80 additions & 68 deletions applications/minotari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ use tari_core::{
},
},
};
use tari_crypto::ristretto::RistrettoSecretKey;
use tari_crypto::ristretto::{pedersen::PedersenCommitment, RistrettoSecretKey};
use tari_key_manager::key_manager_service::KeyManagerInterface;
use tari_script::{script, ExecutionStack, TariScript};
use tari_utilities::{hex::Hex, ByteArray};
Expand Down Expand Up @@ -167,6 +167,7 @@ async fn encumber_aggregate_utxo(
mut wallet_transaction_service: TransactionServiceHandle,
fee_per_gram: MicroMinotari,
output_hash: String,
expected_commitment: PedersenCommitment,
script_input_shares: Vec<Signature>,
script_public_key_shares: Vec<PublicKey>,
script_signature_public_nonces: Vec<PublicKey>,
Expand All @@ -179,6 +180,7 @@ async fn encumber_aggregate_utxo(
.encumber_aggregate_utxo(
fee_per_gram,
output_hash,
expected_commitment,
script_input_shares,
script_public_key_shares,
script_signature_public_nonces,
Expand Down Expand Up @@ -734,19 +736,19 @@ pub async fn command_runner(
Err(e) => eprintln!("BurnMinotari error! {}", e),
}
},
CreateKeyPair(args) => match key_manager_service.create_key_pair(args.key_branch).await {
FaucetCreateKeyPair(args) => match key_manager_service.create_key_pair(args.key_branch).await {
Ok((key_id, pk)) => {
println!(
"New key pair:
1. key id : {},
2. public key: {}",
1. key id : {},
2. public key: {}",
key_id,
pk.to_hex()
)
},
Err(e) => eprintln!("CreateKeyPair error! {}", e),
},
CreateAggregateSignatureUtxo(args) => match create_aggregate_signature_utxo(
FaucetCreateAggregateSignatureUtxo(args) => match create_aggregate_signature_utxo(
transaction_service.clone(),
args.amount,
args.fee_per_gram,
Expand All @@ -763,7 +765,7 @@ pub async fn command_runner(
{
Ok((tx_id, output_hash)) => {
println!(
"Created an utxo with n-of-m aggregate public key, with:
"Created a UTXO with n-of-m aggregate public key, with:
1. n = {},
2. m = {},
3. tx id = {},
Expand All @@ -773,17 +775,17 @@ pub async fn command_runner(
},
Err(e) => eprintln!("CreateAggregateSignatureUtxo error! {}", e),
},
SignMessage(args) => {
FaucetSignMessage(args) => {
match key_manager_service
.sign_script_message(&args.private_key_id, args.challenge.as_bytes())
.await
{
// 1. What is the message/challenge? => commitment
Ok(sgn) => {
println!(
"Sign message:
1. signature: {},
2. public nonce: {}",
"Signed message:
1. signature: {},
2. public nonce: {}",
sgn.get_signature().to_hex(),
sgn.get_public_nonce().to_hex(),
)
Expand All @@ -792,63 +794,69 @@ pub async fn command_runner(
}
},
FaucetCreatePartyDetails(args) => {
let spend_key = wallet.get_wallet_id().await?.wallet_node_key_id.clone();
let public_spend_key = key_manager_service.get_public_key_at_key_id(&spend_key).await?;
let (script_nonce, public_script_nonce) = key_manager_service.get_random_key().await?;
let wallet_spend_key_id = wallet.get_wallet_id().await?.wallet_node_key_id.clone();
let wallet_public_spend_key = key_manager_service
.get_public_key_at_key_id(&wallet_spend_key_id)
.await?;
let (script_nonce_key_id, public_script_nonce) = key_manager_service.get_random_key().await?;

let (sender_offset_key, public_sender_offset_key) = key_manager_service
let (sender_offset_key_id, public_sender_offset_key) = key_manager_service
.get_next_key(TransactionKeyManagerBranch::SenderOffset.get_branch_key())
.await?;
let (sender_offset_nonce, public_sender_offset_nonce) = key_manager_service.get_random_key().await?;
let (sender_offset_nonce_key_id, public_sender_offset_nonce) =
key_manager_service.get_random_key().await?;

let commitment = Commitment::from_hex(&args.commitment)?;
let com_hash: [u8; 32] =
let commitment_hash: [u8; 32] =
DomainSeparatedConsensusHasher::<FaucetHashDomain, Blake2b<U32>>::new("com_hash")
.chain(&commitment)
.finalize()
.into();
let shared_secret = key_manager_service
.get_diffie_hellman_shared_secret(
&sender_offset_key,
args.destination
&sender_offset_key_id,
args.recipient_address
.public_view_key()
.ok_or(CommandError::InvalidArgument("Missing public view key".to_string()))?,
)
.await?;
let shared_secret_key = PublicKey::from_canonical_bytes(shared_secret.as_bytes())?;
let shared_secret_public_key = PublicKey::from_canonical_bytes(shared_secret.as_bytes())?;

let signature = key_manager_service.sign_script_message(&spend_key, &com_hash).await?;
let script_input_signature = key_manager_service
.sign_script_message(&wallet_spend_key_id, &commitment_hash)
.await?;

println!(
"Sign message:
1. signature: ({},{}),
2. public spend key: {},
2. public spend key_id: {},
4. spend nonce key: {},
5. public spend nonce key: {},
6. sender offset key: {},
7. public sender offset key: {},
8. sender offset nonce key: {},
9. public sender offset nonce key: {},
10. shared secret: {}",
signature.get_signature().to_hex(),
signature.get_public_nonce().to_hex(),
public_spend_key,
spend_key,
script_nonce,
"Party details created with:
1. script input signature: ({},{}),
2. wallet public spend key: {},
3. wallet public spend key_id: {},
4. spend nonce key_id: {},
5. public spend nonce key: {},
6. sender offset key_id: {},
7. public sender offset key: {},
8. sender offset nonce key_id: {},
9. public sender offset nonce key: {},
10. public shared secret: {}",
script_input_signature.get_signature().to_hex(),
script_input_signature.get_public_nonce().to_hex(),
wallet_public_spend_key,
wallet_spend_key_id,
script_nonce_key_id,
public_script_nonce,
sender_offset_key,
sender_offset_key_id,
public_sender_offset_key,
sender_offset_nonce,
sender_offset_nonce_key_id,
public_sender_offset_nonce,
shared_secret_key
shared_secret_public_key
);
},
EncumberAggregateUtxo(args) => {
FaucetEncumberAggregateUtxo(args) => {
match encumber_aggregate_utxo(
transaction_service.clone(),
args.fee_per_gram,
args.output_hash,
Commitment::from_hex(&args.commitment)?,
args.script_input_shares
.iter()
.map(|v| v.clone().into())
Expand Down Expand Up @@ -885,22 +893,22 @@ pub async fn command_runner(
total_script_nonce,
)) => {
println!(
"Encumber aggregate utxo:
1. Tx_id: {}
2. input_commitment: {},
3. input_stack: {},
4. input_script: {},
5. total_script_key: {},
6. script_signature_ephemeral_commitment: {},
7. script_signature_ephemeral_pubkey: {},
8. output_commitment: {},
9. output_hash: {},
10. sender_offset_pubkey: {},
11. meta_signature_ephemeral_commitment: {},
12. meta_signature_ephemeral_pubkey: {},
13. total_public_offset: {},
14. encrypted_data: {},
15. output_features: {}",
"Encumbered aggregate UTXO:
1. tx_id: {},
2. input_commitment: {},
3. input_stack: {},
4. input_script: {},
5. total_script_key: {},
6. script_signature_ephemeral_commitment: {},
7. script_signature_ephemeral_pubkey: {},
8. output_commitment: {},
9. output_hash: {},
10. sender_offset_pubkey: {},
11. meta_signature_ephemeral_commitment: {},
12. meta_signature_ephemeral_pubkey: {},
13. total_public_offset: {},
14. encrypted_data: {},
15. output_features: {}",
tx_id,
transaction.body.inputs()[0].commitment().unwrap().to_hex(),
transaction.body.inputs()[0].input_data.to_hex(),
Expand Down Expand Up @@ -928,7 +936,7 @@ pub async fn command_runner(
Err(e) => println!("Encumber aggregate transaction error! {}", e),
}
},
SpendAggregateUtxo(args) => {
FaucetSpendAggregateUtxo(args) => {
let mut offset = PrivateKey::default();
for key in args.script_offset_keys {
let secret_key =
Expand All @@ -955,7 +963,7 @@ pub async fn command_runner(
Err(e) => println!("Error completing transaction! {}", e),
}
},
CreateScriptSig(args) => {
FaucetCreateScriptSig(args) => {
let script = TariScript::from_hex(&args.input_script)
.map_err(|e| CommandError::InvalidArgument(e.to_string()))?;
let input_data = ExecutionStack::from_hex(&args.input_stack)
Expand All @@ -976,12 +984,12 @@ pub async fn command_runner(
);

match key_manager_service
.sign_with_nonce_and_message(&args.private_key_id, &args.secret_nonce, &challenge)
.sign_with_nonce_and_message(&args.private_key_id, &args.secret_nonce_key_id, &challenge)
.await
{
Ok(signature) => {
println!(
"Sign script sig:
"Script signature created:
1. signature: ({},{})",
signature.get_signature().to_hex(),
signature.get_public_nonce().to_hex(),
Expand All @@ -990,10 +998,10 @@ pub async fn command_runner(
Err(e) => eprintln!("SignMessage error! {}", e),
}
},
CreateMetaSig(args) => {
FaucetCreateMetaSig(args) => {
let offset = key_manager_service
.get_script_offset(&vec![args.secret_script_key], &vec![args
.secret_sender_offset_key
.get_script_offset(&vec![args.secret_script_key_id], &vec![args
.secret_sender_offset_key_id
.clone()])
.await?;
let script = script!(PushPubKey(Box::new(args.recipient_address.public_spend_key().clone())));
Expand Down Expand Up @@ -1036,16 +1044,20 @@ pub async fn command_runner(
&encrypted_data,
minimum_value_promise,
);
trace!(target: LOG_TARGET, "meta challange: {:?}", challenge);
trace!(target: LOG_TARGET, "meta challenge: {:?}", challenge);
match key_manager_service
.sign_with_nonce_and_message(&args.secret_sender_offset_key, &args.secret_nonce, &challenge)
.sign_with_nonce_and_message(
&args.secret_sender_offset_key_id,
&args.secret_nonce_key_id,
&challenge,
)
.await
{
Ok(signature) => {
println!(
"1. Meta sig:
signature: ({},{}),
2. Script offset: {}",
"Metadata signature created:
1. signature: ({},{}),
2. script offset: {}",
signature.get_signature().to_hex(),
signature.get_public_nonce().to_hex(),
offset.to_hex(),
Expand Down
40 changes: 21 additions & 19 deletions applications/minotari_console_wallet/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ pub enum CliCommands {
GetBalance,
SendMinotari(SendMinotariArgs),
BurnMinotari(BurnMinotariArgs),
CreateKeyPair(CreateKeyPairArgs),
CreateAggregateSignatureUtxo(CreateAggregateSignatureUtxoArgs),
EncumberAggregateUtxo(EncumberAggregateUtxoArgs),
SpendAggregateUtxo(SpendAggregateUtxoArgs),
SignMessage(SignMessageArgs),
FaucetCreateKeyPair(FaucetCreateKeyPairArgs),
FaucetCreateAggregateSignatureUtxo(FaucetCreateAggregateSignatureUtxoArgs),
FaucetEncumberAggregateUtxo(FaucetEncumberAggregateUtxoArgs),
FaucetSpendAggregateUtxo(FaucetSpendAggregateUtxoArgs),
FaucetSignMessage(FaucetSignMessageArgs),
FaucetCreatePartyDetails(FaucetCreatePartyDetailsArgs),
CreateScriptSig(CreateScriptSigArgs),
CreateMetaSig(CreateMetaSigArgs),
FaucetCreateScriptSig(FaucetCreateScriptSigArgs),
FaucetCreateMetaSig(FaucetCreateMetaSigArgs),
SendOneSidedToStealthAddress(SendMinotariArgs),
MakeItRain(MakeItRainArgs),
CoinSplit(CoinSplitArgs),
Expand Down Expand Up @@ -169,13 +169,13 @@ pub struct BurnMinotariArgs {
}

#[derive(Debug, Args, Clone)]
pub struct CreateKeyPairArgs {
pub struct FaucetCreateKeyPairArgs {
#[clap(long)]
pub key_branch: String,
}

#[derive(Debug, Args, Clone)]
pub struct CreateAggregateSignatureUtxoArgs {
pub struct FaucetCreateAggregateSignatureUtxoArgs {
#[clap(long)]
pub amount: MicroMinotari,
#[clap(long)]
Expand All @@ -197,22 +197,24 @@ pub struct FaucetCreatePartyDetailsArgs {
#[clap(long)]
pub commitment: String,
#[clap(long)]
pub destination: TariAddress,
pub recipient_address: TariAddress,
}

#[derive(Debug, Args, Clone)]
pub struct SignMessageArgs {
pub struct FaucetSignMessageArgs {
#[clap(long)]
pub private_key_id: TariKeyId,
#[clap(long)]
pub challenge: String,
}

#[derive(Debug, Args, Clone)]
pub struct EncumberAggregateUtxoArgs {
pub struct FaucetEncumberAggregateUtxoArgs {
#[clap(long)]
pub fee_per_gram: MicroMinotari,
#[clap(long)]
pub commitment: String,
#[clap(long)]
pub output_hash: String,
#[clap(long)]
pub script_input_shares: Vec<UniSignature>,
Expand All @@ -231,7 +233,7 @@ pub struct EncumberAggregateUtxoArgs {
}

#[derive(Debug, Args, Clone)]
pub struct SpendAggregateUtxoArgs {
pub struct FaucetSpendAggregateUtxoArgs {
#[clap(long)]
pub tx_id: u64,
#[clap(long)]
Expand All @@ -243,11 +245,11 @@ pub struct SpendAggregateUtxoArgs {
}

#[derive(Debug, Args, Clone)]
pub struct CreateScriptSigArgs {
pub struct FaucetCreateScriptSigArgs {
#[clap(long)]
pub private_key_id: TariKeyId,
#[clap(long)]
pub secret_nonce: TariKeyId,
pub secret_nonce_key_id: TariKeyId,
#[clap(long)]
pub input_script: String,
#[clap(long)]
Expand All @@ -263,13 +265,13 @@ pub struct CreateScriptSigArgs {
}

#[derive(Debug, Args, Clone)]
pub struct CreateMetaSigArgs {
pub struct FaucetCreateMetaSigArgs {
#[clap(long)]
pub secret_script_key: TariKeyId,
pub secret_script_key_id: TariKeyId,
#[clap(long)]
pub secret_sender_offset_key: TariKeyId,
pub secret_sender_offset_key_id: TariKeyId,
#[clap(long)]
pub secret_nonce: TariKeyId,
pub secret_nonce_key_id: TariKeyId,
#[clap(long)]
pub ephemeral_commitment: String,
#[clap(long)]
Expand Down
Loading

0 comments on commit e3068d1

Please sign in to comment.