v0.2.6-pre.011
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-app-wallet-desk/src/app_state.rs
|
||||
// version: 14
|
||||
// version: 15
|
||||
|
||||
//! Shared backend state owned by the Wallet Desk Tauri application.
|
||||
|
||||
@@ -722,6 +722,46 @@ impl AppState {
|
||||
return self.finish_owner_operation(context, result).await;
|
||||
}
|
||||
|
||||
/// Strongly disables VIEW from the current OWNER session while preserving OWNER authorization.
|
||||
pub(crate) async fn disable_wallet_view(&self) -> ksp_core_lib::Result<crate::WalletViewSecurityStatusDto> {
|
||||
let context = self.begin_owner_operation("view_disable");
|
||||
let mut context = match context {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
||||
};
|
||||
let result = context.owner.disable_view(context.path.as_path()).await;
|
||||
if result.is_ok() {
|
||||
context.result_view_enabled = false;
|
||||
}
|
||||
let wallet = self.finish_owner_operation(context, result).await;
|
||||
return match wallet {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(crate::view_security_status_from_authorized(&value)),
|
||||
std::result::Result::Err(error) => std::result::Result::Err(error),
|
||||
};
|
||||
}
|
||||
|
||||
/// Strongly recreates VIEW from the current OWNER session with a fresh metadata key, slot and password.
|
||||
pub(crate) async fn recreate_wallet_view(
|
||||
&self,
|
||||
request: crate::WalletPasswordRotationRequestDto,
|
||||
) -> ksp_core_lib::Result<crate::WalletViewSecurityStatusDto> {
|
||||
let context = self.begin_owner_operation("view_recreate");
|
||||
let mut context = match context {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
||||
};
|
||||
let password = ksp_wallet_lib::ViewPassword::new(request.password);
|
||||
let result = context.owner.recreate_view(context.path.as_path(), password).await;
|
||||
if result.is_ok() {
|
||||
context.result_view_enabled = true;
|
||||
}
|
||||
let wallet = self.finish_owner_operation(context, result).await;
|
||||
return match wallet {
|
||||
std::result::Result::Ok(value) => std::result::Result::Ok(crate::view_security_status_from_authorized(&value)),
|
||||
std::result::Result::Err(error) => std::result::Result::Err(error),
|
||||
};
|
||||
}
|
||||
|
||||
/// Rotates the OWNER password while preserving the current authorized identity and metadata projection.
|
||||
pub(crate) async fn rotate_owner_password(&self, request: crate::WalletPasswordRotationRequestDto) -> ksp_core_lib::Result<crate::WalletAuthorizedDto> {
|
||||
let context = self.begin_owner_operation("owner_password_rotate");
|
||||
@@ -894,7 +934,15 @@ impl AppState {
|
||||
},
|
||||
};
|
||||
let pubkey = owner.pubkey().to_owned();
|
||||
let context = OwnerOperationContext { operation, owner, path: path.clone(), pubkey, view_enabled, wallet_id: wallet_id.clone() };
|
||||
let context = OwnerOperationContext {
|
||||
operation,
|
||||
owner,
|
||||
path: path.clone(),
|
||||
pubkey,
|
||||
result_view_enabled: view_enabled,
|
||||
view_enabled,
|
||||
wallet_id: wallet_id.clone(),
|
||||
};
|
||||
*session = crate::WalletSession::OwnerOperation { wallet_id, path, pubkey, view_enabled };
|
||||
ksp_logging_lib::debug!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_WALLET_SESSION, wallet_id = context.wallet_id.as_str(), operation, "Wallet OWNER privileged operation started");
|
||||
return std::result::Result::Ok(context);
|
||||
@@ -917,9 +965,9 @@ impl AppState {
|
||||
}
|
||||
|
||||
fn install_owner_after_operation_success(&self, context: OwnerOperationContext) -> ksp_core_lib::Result<crate::WalletAuthorizedDto> {
|
||||
let OwnerOperationContext { operation, owner, path, pubkey, view_enabled, wallet_id } = context;
|
||||
let OwnerOperationContext { operation, owner, path, pubkey, result_view_enabled, view_enabled, wallet_id } = context;
|
||||
let configured_secret_candidate_count = self.secret_candidate_count_or_zero(wallet_id.as_str());
|
||||
let dto = crate::owner_projection(wallet_id.as_str(), view_enabled, configured_secret_candidate_count, &owner);
|
||||
let dto = crate::owner_projection(wallet_id.as_str(), result_view_enabled, configured_secret_candidate_count, &owner);
|
||||
let session = self.wallet_session.lock();
|
||||
let mut session = match session {
|
||||
std::result::Result::Ok(value) => value,
|
||||
@@ -933,7 +981,7 @@ impl AppState {
|
||||
pubkey: reserved_pubkey,
|
||||
view_enabled: reserved_view_enabled,
|
||||
} if reserved_wallet_id == wallet_id && reserved_path == path && reserved_pubkey == pubkey && reserved_view_enabled == view_enabled => {
|
||||
*session = crate::WalletSession::Owner { wallet_id: wallet_id.clone(), path, view_enabled, wallet: owner };
|
||||
*session = crate::WalletSession::Owner { wallet_id: wallet_id.clone(), path, view_enabled: result_view_enabled, wallet: owner };
|
||||
ksp_logging_lib::info!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_WALLET_SESSION, wallet_id = wallet_id.as_str(), operation, "Wallet OWNER privileged operation completed");
|
||||
return std::result::Result::Ok(dto);
|
||||
},
|
||||
@@ -949,7 +997,7 @@ impl AppState {
|
||||
}
|
||||
|
||||
fn restore_owner_after_operation_failure(&self, context: OwnerOperationContext) {
|
||||
let OwnerOperationContext { operation, owner, path, pubkey, view_enabled, wallet_id } = context;
|
||||
let OwnerOperationContext { operation, owner, path, pubkey, result_view_enabled: _, view_enabled, wallet_id } = context;
|
||||
let session = self.wallet_session.lock();
|
||||
let mut session = match session {
|
||||
std::result::Result::Ok(value) => value,
|
||||
@@ -974,7 +1022,7 @@ impl AppState {
|
||||
}
|
||||
|
||||
async fn recover_owner_state_conflict(&self, context: OwnerOperationContext) {
|
||||
let OwnerOperationContext { operation, owner, path, pubkey, view_enabled, wallet_id } = context;
|
||||
let OwnerOperationContext { operation, owner, path, pubkey, result_view_enabled: _, view_enabled, wallet_id } = context;
|
||||
drop(owner);
|
||||
let inspected = ksp_wallet_lib::inspect_locked_wallet_file_v1(path.as_path()).await;
|
||||
let session = self.wallet_session.lock();
|
||||
@@ -1144,6 +1192,7 @@ struct OwnerOperationContext {
|
||||
owner: std::boxed::Box<ksp_wallet_lib::WalletOwner>,
|
||||
path: std::path::PathBuf,
|
||||
pubkey: ksp_core_lib::Pubkey,
|
||||
result_view_enabled: bool,
|
||||
view_enabled: bool,
|
||||
wallet_id: String,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user