Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
SWvheerden committed Jul 18, 2024
1 parent 6ccfd12 commit 5a6a2d9
Show file tree
Hide file tree
Showing 23 changed files with 119 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -839,10 +839,10 @@ pub async fn command_runner(
let out_dir = out_dir(&session_info.session_id)?;
let step_2_outputs_for_leader = Step2OutputsForLeader {
script_input_signature,
wallet_public_spend_key: wallet_spend_key.key,
public_script_nonce_key: script_nonce_key.key,
public_sender_offset_key: sender_offset_key.key,
public_sender_offset_nonce_key: sender_offset_nonce.key,
wallet_public_spend_key: wallet_spend_key.pub_key,
public_script_nonce_key: script_nonce_key.pub_key,
public_sender_offset_key: sender_offset_key.pub_key,
public_sender_offset_nonce_key: sender_offset_nonce.pub_key,
dh_shared_secret_public_key: shared_secret_public_key,
};
let out_file_leader = out_dir.join(get_file_name(STEP_2_LEADER, Some(args.alias.clone())));
Expand Down
4 changes: 2 additions & 2 deletions applications/minotari_node/src/grpc/base_node_grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
.get_next_key(TransactionKeyManagerBranch::KernelNonce.get_branch_key())
.await
.map_err(|e| obscure_error_if_true(report_error_flag, Status::internal(e.to_string())))?;
total_nonce = &total_nonce + &new_nonce.key;
total_nonce = &total_nonce + &new_nonce.pub_key;
total_excess = &total_excess + &coinbase_kernel.excess;
private_keys.push((wallet_output.spending_key_id, new_nonce.key_id));
kernel_message = TransactionKernel::build_kernel_signature_message(
Expand Down Expand Up @@ -1067,7 +1067,7 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
.get_next_key(TransactionKeyManagerBranch::KernelNonce.get_branch_key())
.await
.map_err(|e| obscure_error_if_true(report_error_flag, Status::internal(e.to_string())))?;
total_nonce = &total_nonce + &new_nonce.key;
total_nonce = &total_nonce + &new_nonce.pub_key;
total_excess = &total_excess + &coinbase_kernel.excess;
private_keys.push((wallet_output.spending_key_id, new_nonce.key_id));
kernel_message = TransactionKernel::build_kernel_signature_message(
Expand Down
18 changes: 7 additions & 11 deletions base_layer/core/src/blocks/faucets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,9 @@ mod test {
let mut total_private_key = PrivateKey::default();

for _ in 0..num_faucets {
let (commitment_mask, script_key) =
key_manager.get_next_commitment_mask_and_script_key().await.unwrap();
total_private_key = total_private_key +
&key_manager
.get_private_key(&commitment_mask.key_id)
.await
.unwrap();
let (commitment_mask, script_key) = key_manager.get_next_commitment_mask_and_script_key().await.unwrap();
total_private_key =
total_private_key + &key_manager.get_private_key(&commitment_mask.key_id).await.unwrap();
let commitment = key_manager
.get_commitment(&commitment_mask.key_id, &amount.into())
.await
Expand All @@ -100,7 +96,7 @@ mod test {
.finalize()
.into();

let sender_offset_key = key_manager
let sender_offset = key_manager
.get_next_key(TransactionKeyManagerBranch::SenderOffset.get_branch_key())
.await
.unwrap();
Expand All @@ -110,7 +106,7 @@ mod test {
list_of_spend_keys.clone(),
Box::new(com_hash),
)]);
let output = WalletOutputBuilder::new(amount, commitment_mask_key_id.key_id)
let output = WalletOutputBuilder::new(amount, commitment_mask.key_id)
.with_features(OutputFeatures::new(
OutputFeaturesVersion::get_current_version(),
OutputType::Standard,
Expand All @@ -125,10 +121,10 @@ mod test {
.unwrap()
.with_input_data(ExecutionStack::default())
.with_version(TransactionOutputVersion::get_current_version())
.with_sender_offset_public_key(sender_offset_key.key)
.with_sender_offset_public_key(sender_offset.pub_key)
.with_script_key(script_key.key_id)
.with_minimum_value_promise(amount)
.sign_as_sender_and_receiver(&key_manager, &sender_offset_key.key_id)
.sign_as_sender_and_receiver(&key_manager, &sender_offset.key_id)
.await
.unwrap()
.try_build(&key_manager)
Expand Down
8 changes: 4 additions & 4 deletions base_layer/core/src/transactions/coinbase_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ where TKeyManagerInterface: TransactionKeyManagerInterface
.get_partial_txo_kernel_signature(
&commitment_mask_key_id,
&public_nonce.key_id,
&public_nonce.key,
&public_nonce.pub_key,
&public_commitment_mask_key,
&kernel_version,
&kernel_message,
Expand Down Expand Up @@ -862,7 +862,7 @@ mod test {
.get_partial_txo_kernel_signature(
&output.spending_key_id,
&new_nonce.key_id,
&new_nonce.key,
&new_nonce.pub_key,
&excess,
&TransactionKernelVersion::get_current_version(),
&kernel_message,
Expand All @@ -878,7 +878,7 @@ mod test {
.unwrap();
let sig_challenge = TransactionKernel::finalize_kernel_signature_challenge(
&TransactionKernelVersion::get_current_version(),
&new_nonce.key,
&new_nonce.pub_key,
&excess,
&kernel_message,
);
Expand Down Expand Up @@ -1005,7 +1005,7 @@ mod test {
.get_next_key(TransactionKeyManagerBranch::KernelNonce.get_branch_key())
.await
.unwrap();
let nonce = &new_nonce1.key + &new_nonce2.key;
let nonce = &new_nonce1.pub_key + &new_nonce2.pub_key;
let kernel_message = TransactionKernel::build_kernel_signature_message(
&TransactionKernelVersion::get_current_version(),
kernel_1.fee,
Expand Down
16 changes: 8 additions & 8 deletions base_layer/core/src/transactions/key_manager/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ where TBackend: KeyManagerBackend<PublicKey> + 'static
index,
};
let key = self.get_public_key_at_key_id(&key_id).await?;
Ok(KeyAndId { key_id, key })
Ok(KeyAndId { key_id, pub_key: key })
}

pub async fn get_random_key(&self) -> Result<KeyAndId<PublicKey>, KeyManagerServiceError> {
Expand All @@ -187,7 +187,7 @@ where TBackend: KeyManagerBackend<PublicKey> + 'static
let public_key = self.get_public_key_at_key_id(&key_id).await?;
Ok(KeyAndId {
key_id,
key: public_key,
pub_key: public_key,
})
}

Expand Down Expand Up @@ -258,7 +258,7 @@ where TBackend: KeyManagerBackend<PublicKey> + 'static
Ok(km.derive_public_key(*index)?.key)
},
KeyId::Derived { branch, label, index } => {
let public_alpha = self.get_spend_key().await?.key;
let public_alpha = self.get_spend_key().await?.pub_key;
let km = self
.key_managers
.get(branch)
Expand Down Expand Up @@ -387,7 +387,7 @@ where TBackend: KeyManagerBackend<PublicKey> + 'static
index: 0,
};
let key = PublicKey::from_secret_key(&self.get_private_view_key().await?);
Ok(KeyAndId { key_id, key })
Ok(KeyAndId { key_id, pub_key: key })
}

pub async fn get_spend_key(&self) -> Result<KeyAndId<PublicKey>, KeyManagerServiceError> {
Expand All @@ -406,7 +406,7 @@ where TBackend: KeyManagerBackend<PublicKey> + 'static
))?,
WalletType::ProvidedKeys(wallet) => wallet.public_spend_key.clone(),
};
Ok(KeyAndId { key_id, key })
Ok(KeyAndId { key_id, pub_key: key })
}

pub async fn get_comms_key(&self) -> Result<KeyAndId<PublicKey>, KeyManagerServiceError> {
Expand All @@ -416,7 +416,7 @@ where TBackend: KeyManagerBackend<PublicKey> + 'static
};
let private_key = self.get_private_comms_key().await?;
let key = PublicKey::from_secret_key(&private_key);
Ok(KeyAndId { key_id, key })
Ok(KeyAndId { key_id, pub_key: key })
}

pub async fn get_next_commitment_mask_and_script_key(
Expand All @@ -437,7 +437,7 @@ where TBackend: KeyManagerBackend<PublicKey> + 'static
let script_public_key = self.get_public_key_at_key_id(&script_key_id).await?;
Ok((commitment_mask, KeyAndId {
key_id: script_key_id,
key: script_public_key,
pub_key: script_public_key,
}))
}

Expand Down Expand Up @@ -1177,7 +1177,7 @@ where TBackend: KeyManagerBackend<PublicKey> + 'static
spending_key_id,
value_as_private_key,
&sender_offset_public_key,
&ephemeral_pubkey.key,
&ephemeral_pubkey.pub_key,
txo_version,
metadata_signature_message,
range_proof_type,
Expand Down
50 changes: 25 additions & 25 deletions base_layer/core/src/transactions/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl TestParams {
.get_next_key(TransactionKeyManagerBranch::KernelNonce.get_branch_key())
.await
.unwrap();
let public_noncey = key_manager
let public_nonce = key_manager
.get_next_key(TransactionKeyManagerBranch::Nonce.get_branch_key())
.await
.unwrap();
Expand All @@ -134,15 +134,15 @@ impl TestParams {
Self {
commitment_mask_key_id: commitment_mask_key.key_id,
script_key_id: script_key.key_id,
script_key_pk: script_key.key,
sender_offset_key_id: sender_offset_key.key_id,
sender_offset_key_pk: sender_offset_key.key,
kernel_nonce_key_id: kernel_nonce_key.key_id,
kernel_nonce_key_pk: kernel_nonce_key.key,
public_nonce_key_id: public_nonce_key.key_id,
public_nonce_key_pk: public_nonce_key.key,
script_key_pk: script_key.pub_key,
sender_offset_key_id: sender_offset.key_id,
sender_offset_key_pk: sender_offset.pub_key,
kernel_nonce_key_id: kernel_nonce.key_id,
kernel_nonce_key_pk: kernel_nonce.pub_key,
public_nonce_key_id: public_nonce.key_id,
public_nonce_key_pk: public_nonce.pub_key,
ephemeral_public_nonce_key_id: ephemeral_public_nonce.key_id,
ephemeral_public_nonce_key_pk: ephemeral_public_nonce.key,
ephemeral_public_nonce_key_pk: ephemeral_public_nonce.pub_key,
transaction_weight: TransactionWeight::v1(),
}
}
Expand Down Expand Up @@ -308,7 +308,7 @@ pub async fn create_random_signature_from_secret_key(
.get_partial_txo_kernel_signature(
&secret_key_id,
&total_nonce.key_id,
&total_nonce.key,
&total_nonce.pub_key,
&total_excess,
&kernel_version,
&kernel_message,
Expand Down Expand Up @@ -736,7 +736,7 @@ pub async fn create_stx_protocol_internal(
let script_key_id = KeyId::Derived {
branch: TransactionKeyManagerBranch::CommitmentMask.get_branch_key(),
label: TransactionKeyManagerLabel::ScriptKey.get_branch_key(),
index: commitment_mask_key.key_id.managed_index().unwrap(),
index: commitment_mask.key_id.managed_index().unwrap(),
};
let script_public_key = key_manager.get_public_key_at_key_id(&script_key_id).await.unwrap();
let input_data = match &schema.input_data {
Expand All @@ -747,7 +747,7 @@ pub async fn create_stx_protocol_internal(
Some(data) => data,
None => TransactionOutputVersion::get_current_version(),
};
let output = WalletOutputBuilder::new(val, commitment_mask_key.key_id)
let output = WalletOutputBuilder::new(val, commitment_mask.key_id)
.with_features(schema.features.clone())
.with_script(schema.script.clone())
.encrypt_data_for_recovery(key_manager, None, PaymentId::Empty)
Expand All @@ -756,17 +756,17 @@ pub async fn create_stx_protocol_internal(
.with_input_data(input_data)
.with_covenant(schema.covenant.clone())
.with_version(version)
.with_sender_offset_public_key(sender_offset_key.key)
.with_sender_offset_public_key(sender_offset.pub_key)
.with_script_key(script_key_id.clone())
.sign_as_sender_and_receiver(key_manager, &sender_offset_key.key_id)
.sign_as_sender_and_receiver(key_manager, &sender_offset.key_id)
.await
.unwrap()
.try_build(key_manager)
.await
.unwrap();

outputs.push(output.clone());
stx_builder.with_output(output, sender_offset_key.key_id).await.unwrap();
stx_builder.with_output(output, sender_offset.key_id).await.unwrap();
}
for mut utxo in schema.to_outputs {
let sender_offset = key_manager
Expand All @@ -778,15 +778,15 @@ pub async fn create_stx_protocol_internal(
.get_metadata_signature(
&utxo.spending_key_id,
&utxo.value.into(),
&sender_offset_key.key_id,
&sender_offset.key_id,
&utxo.version,
&metadata_message,
utxo.features.range_proof_type,
)
.await
.unwrap();

stx_builder.with_output(utxo, sender_offset_key.key_id).await.unwrap();
stx_builder.with_output(utxo, sender_offset.key_id).await.unwrap();
}

stx_builder
Expand All @@ -813,7 +813,7 @@ pub async fn create_coinbase_kernel(
.get_partial_txo_kernel_signature(
commitment_mask_key_id,
&public_nonce.key_id,
&public_nonce.key,
&public_nonce.pub_key,
&public_commitment_mask,
&kernel_version,
&kernel_message,
Expand Down Expand Up @@ -858,7 +858,7 @@ pub async fn create_utxo(
.await
.unwrap();
let encrypted_data = key_manager
.encrypt_data_for_recovery(&commitment_mask_key.key_id, None, value.into(), PaymentId::Empty)
.encrypt_data_for_recovery(&commitment_mask.key_id, None, value.into(), PaymentId::Empty)
.await
.unwrap();
let sender_offset = key_manager
Expand All @@ -875,23 +875,23 @@ pub async fn create_utxo(
);
let metadata_sig = key_manager
.get_metadata_signature(
&commitment_mask_key.key_id,
&commitment_mask.key_id,
&value.into(),
&sender_offset_key.key_id,
&sender_offset.key_id,
&TransactionOutputVersion::get_current_version(),
&metadata_message,
features.range_proof_type,
)
.await
.unwrap();
let commitment = key_manager
.get_commitment(&commitment_mask_key.key_id, &value.into())
.get_commitment(&commitment_mask.key_id, &value.into())
.await
.unwrap();
let proof = if features.range_proof_type == RangeProofType::BulletProofPlus {
Some(
key_manager
.construct_range_proof(&commitment_mask_key.key_id, value.into(), minimum_value_promise.into())
.construct_range_proof(&commitment_mask.key_id, value.into(), minimum_value_promise.into())
.await
.unwrap(),
)
Expand All @@ -904,15 +904,15 @@ pub async fn create_utxo(
commitment,
proof,
script.clone(),
sender_offset_key.key,
sender_offset.pub_key,
metadata_sig,
covenant.clone(),
encrypted_data,
minimum_value_promise,
);
utxo.verify_range_proof(&CryptoFactories::default().range_proof)
.unwrap();
(utxo, commitment_mask_key.key_id, sender_offset_key.key_id)
(utxo, commitment_mask.key_id, sender_offset.key_id)
}

pub async fn schema_to_transaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl WalletOutput {
let script_public_key_self = key_manager.get_public_key_at_key_id(&self.script_key_id).await?;
let script_public_key = aggregated_script_public_key_shares + script_public_key_self;

let total_ephemeral_public_key = aggregated_script_signature_public_nonces + &ephemeral_public_key_self.key;
let total_ephemeral_public_key = aggregated_script_signature_public_nonces + &ephemeral_public_key_self.pub_key;
let commitment_partial_script_signature = key_manager
.get_partial_script_signature(
&self.spending_key_id,
Expand Down
Loading

0 comments on commit 5a6a2d9

Please sign in to comment.