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

chore: refactor key manager names #6411

Merged
merged 4 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
32 changes: 14 additions & 18 deletions applications/minotari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,14 +807,10 @@ pub async fn command_runner(
continue;
}

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) = key_manager_service.get_random_key().await?;
let (sender_offset_key_id, public_sender_offset_key) = key_manager_service.get_random_key().await?;
let (sender_offset_nonce_key_id, public_sender_offset_nonce_key) =
key_manager_service.get_random_key().await?;
let wallet_spend_key = wallet.key_manager_service.get_spend_key().await?;
let script_nonce_key = key_manager_service.get_random_key().await?;
let sender_offset_key = key_manager_service.get_random_key().await?;
let sender_offset_nonce = key_manager_service.get_random_key().await?;

// Read session info
let session_info = read_session_info(args.input_file.clone())?;
Expand All @@ -827,7 +823,7 @@ pub async fn command_runner(
.into();
let shared_secret = key_manager_service
.get_diffie_hellman_shared_secret(
&sender_offset_key_id,
&sender_offset_key.key_id,
session_info
.recipient_address
.public_view_key()
Expand All @@ -837,16 +833,16 @@ pub async fn command_runner(
let shared_secret_public_key = PublicKey::from_canonical_bytes(shared_secret.as_bytes())?;

let script_input_signature = key_manager_service
.sign_script_message(&wallet_spend_key_id, &commitment_hash)
.sign_script_message(&wallet_spend_key.key_id, &commitment_hash)
.await?;

let out_dir = out_dir(&session_info.session_id)?;
let step_2_outputs_for_leader = Step2OutputsForLeader {
script_input_signature,
wallet_public_spend_key,
public_script_nonce_key,
public_sender_offset_key,
public_sender_offset_nonce_key,
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,
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 All @@ -855,10 +851,10 @@ pub async fn command_runner(

let step_2_outputs_for_self = Step2OutputsForSelf {
alias: args.alias.clone(),
wallet_spend_key_id,
script_nonce_key_id,
sender_offset_key_id,
sender_offset_nonce_key_id,
wallet_spend_key_id: wallet_spend_key.key_id,
script_nonce_key_id: script_nonce_key.key_id,
sender_offset_key_id: sender_offset_key.key_id,
sender_offset_nonce_key_id: sender_offset_nonce.key_id,
};
let out_file_self = out_dir.join(get_file_name(STEP_2_SELF, None));
write_json_object_to_file_as_line(&out_file_self, true, session_info.clone())?;
Expand Down
12 changes: 6 additions & 6 deletions applications/minotari_node/src/grpc/base_node_grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,13 +866,13 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
.await
.map_err(|e| obscure_error_if_true(report_error_flag, Status::internal(e.to_string())))?;
new_template.body.add_output(coinbase_output);
let (new_private_nonce, pub_nonce) = key_manager
let new_nonce = key_manager
.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 + &pub_nonce;
total_nonce = &total_nonce + &new_nonce.key;
total_excess = &total_excess + &coinbase_kernel.excess;
private_keys.push((wallet_output.spending_key_id, new_private_nonce));
private_keys.push((wallet_output.spending_key_id, new_nonce.key_id));
kernel_message = TransactionKernel::build_kernel_signature_message(
&TransactionKernelVersion::get_current_version(),
coinbase_kernel.fee,
Expand Down Expand Up @@ -1063,13 +1063,13 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
.await
.map_err(|e| obscure_error_if_true(report_error_flag, Status::internal(e.to_string())))?;
block_template.body.add_output(coinbase_output);
let (new_private_nonce, pub_nonce) = key_manager
let new_nonce = key_manager
.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 + &pub_nonce;
total_nonce = &total_nonce + &new_nonce.key;
total_excess = &total_excess + &coinbase_kernel.excess;
private_keys.push((wallet_output.spending_key_id, new_private_nonce));
private_keys.push((wallet_output.spending_key_id, new_nonce.key_id));
SWvheerden marked this conversation as resolved.
Show resolved Hide resolved
kernel_message = TransactionKernel::build_kernel_signature_message(
&TransactionKernelVersion::get_current_version(),
coinbase_kernel.fee,
Expand Down
12 changes: 6 additions & 6 deletions base_layer/common_types/src/wallet_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,29 @@ use crate::types::{PrivateKey, PublicKey};
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub enum WalletType {
#[default]
Software,
DerivedKeys,
Ledger(LedgerWallet),
Imported(ImportedWallet),
ProvidedKeys(ProvidedKeysWallet),
}

impl Display for WalletType {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
WalletType::Software => write!(f, "Software"),
WalletType::DerivedKeys => write!(f, "Derived wallet"),
WalletType::Ledger(ledger_wallet) => write!(f, "Ledger({ledger_wallet})"),
WalletType::Imported(imported_wallet) => write!(f, "Imported({imported_wallet})"),
WalletType::ProvidedKeys(provided_keys_wallet) => write!(f, "Provided Keys ({provided_keys_wallet})"),
}
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ImportedWallet {
pub struct ProvidedKeysWallet {
pub public_spend_key: PublicKey,
pub private_spend_key: Option<PrivateKey>,
pub view_key: PrivateKey,
}

impl Display for ImportedWallet {
impl Display for ProvidedKeysWallet {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "public spend key {}", self.public_spend_key)?;
write!(f, "public view key{}", PublicKey::from_secret_key(&self.view_key))?;
Expand Down
25 changes: 16 additions & 9 deletions base_layer/core/src/blocks/faucets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,23 @@ mod test {
let mut total_private_key = PrivateKey::default();

for _ in 0..num_faucets {
let (spend_key_id, _spend_key_pk, script_key_id, _script_key_pk) =
key_manager.get_next_spend_and_script_key_ids().await.unwrap();
total_private_key = total_private_key + &key_manager.get_private_key(&spend_key_id).await.unwrap();
let commitment = key_manager.get_commitment(&spend_key_id, &amount.into()).await.unwrap();
let (commitment_mask_key_id, script_key) =
SWvheerden marked this conversation as resolved.
Show resolved Hide resolved
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.key_id)
SWvheerden marked this conversation as resolved.
Show resolved Hide resolved
.await
.unwrap();
let commitment = key_manager
.get_commitment(&commitment_mask_key_id.key_id, &amount.into())
SWvheerden marked this conversation as resolved.
Show resolved Hide resolved
.await
.unwrap();
let com_hash: [u8; 32] = DomainSeparatedConsensusHasher::<FaucetHashDomain, Blake2b<U32>>::new("com_hash")
.chain(&commitment)
.finalize()
.into();

let (sender_offset_key_id, sender_offset_key_pk) = key_manager
let sender_offset_key = key_manager
.get_next_key(TransactionKeyManagerBranch::SenderOffset.get_branch_key())
.await
.unwrap();
Expand All @@ -103,7 +110,7 @@ mod test {
list_of_spend_keys.clone(),
Box::new(com_hash),
)]);
let output = WalletOutputBuilder::new(amount, spend_key_id)
let output = WalletOutputBuilder::new(amount, commitment_mask_key_id.key_id)
.with_features(OutputFeatures::new(
OutputFeaturesVersion::get_current_version(),
OutputType::Standard,
Expand All @@ -118,10 +125,10 @@ mod test {
.unwrap()
.with_input_data(ExecutionStack::default())
.with_version(TransactionOutputVersion::get_current_version())
.with_sender_offset_public_key(sender_offset_key_pk)
.with_script_key(script_key_id)
.with_sender_offset_public_key(sender_offset_key.key)
.with_script_key(script_key.key_id)
.with_minimum_value_promise(amount)
.sign_as_sender_and_receiver(&key_manager, &sender_offset_key_id)
.sign_as_sender_and_receiver(&key_manager, &sender_offset_key.key_id)
.await
.unwrap()
.try_build(&key_manager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ mod test {
TariScript::default(),
ExecutionStack::default(),
change.script_key_id.clone(),
change.spend_key_id.clone(),
change.commitment_mask_key_id.clone(),
Covenant::default(),
);

Expand Down
Loading
Loading