v0.2.6-pre.006

This commit is contained in:
2026-08-21 10:01:11 +02:00
parent 63e711629f
commit a207cf7161
21 changed files with 1136 additions and 63 deletions

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-app-wallet-desk/src/app_state.rs
// version: 6
// version: 7
//! Shared backend state owned by the Wallet Desk Tauri application.
@@ -102,7 +102,7 @@ impl AppState {
effective_wallets_directory_created_on_startup: self.wallet_config_startup.effective_directory_created_on_startup(),
fallback_logging_active: runtime.fallback_active,
root_wallets_directory_created_on_startup: self.wallet_config_startup.root_directory_created_on_startup(),
shell_phase: "pre.005-wallet-session-create".to_owned(),
shell_phase: "pre.006-wallet-unlock".to_owned(),
startup_diagnostic: runtime.startup_diagnostic.clone(),
wallets_directory: resolved.wallets_directory().to_string_lossy().into_owned(),
wallets_subdirectory,
@@ -123,10 +123,11 @@ impl AppState {
}
let root = self.wallet_inventory_root().to_path_buf();
let resolved = crate::resolve_locked_wallet(root.as_path(), request.wallet_id).await;
let (path, locked_info, dto) = match resolved {
let (path, locked_info, mut dto) = match resolved {
std::result::Result::Ok(value) => value,
std::result::Result::Err(error) => return std::result::Result::Err(error),
};
dto.configured_secret_candidate_count = self.secret_candidate_count_or_zero(dto.wallet_id.as_str());
let session = self.wallet_session.lock();
let mut session = match session {
std::result::Result::Ok(value) => value,
@@ -180,7 +181,8 @@ impl AppState {
return std::result::Result::Err(error);
},
};
let dto = crate::owner_projection(filename.as_str(), view_enabled, &owner);
let configured_secret_candidate_count = self.secret_candidate_count_or_zero(filename.as_str());
let dto = crate::owner_projection(filename.as_str(), view_enabled, configured_secret_candidate_count, &owner);
let session = self.wallet_session.lock();
let mut session = match session {
std::result::Result::Ok(value) => value,
@@ -191,6 +193,144 @@ impl AppState {
return std::result::Result::Ok(dto);
}
/// Opens the selected locked Wallet with one manual VIEW password supplied frontend -> Rust.
pub(crate) async fn unlock_wallet_view_manual(&self, request: crate::WalletUnlockRequestDto) -> ksp_core_lib::Result<crate::WalletAuthorizedDto> {
let context = self.begin_unlock_operation(crate::WalletUnlockCapability::View);
let 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 opened = ksp_wallet_lib::open_wallet_view_file_v1(context.path.as_path(), password).await;
let view = match opened {
std::result::Result::Ok(value) => value,
std::result::Result::Err(error) => {
self.restore_locked_after_unlock_failure(&context);
ksp_logging_lib::warn!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_WALLET_SESSION, wallet_id = context.wallet_id.as_str(), capability = context.capability.label(), error_domain = error.code().domain(), error_code = error.code().code(), "Manual Wallet unlock failed");
return std::result::Result::Err(error);
},
};
return self.finish_view_unlock(context, view);
}
/// Opens the selected locked Wallet with one manual OWNER password supplied frontend -> Rust.
pub(crate) async fn unlock_wallet_owner_manual(&self, request: crate::WalletUnlockRequestDto) -> ksp_core_lib::Result<crate::WalletAuthorizedDto> {
let context = self.begin_unlock_operation(crate::WalletUnlockCapability::Owner);
let 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::OwnerPassword::new(request.password);
let opened = ksp_wallet_lib::open_wallet_owner_file_v1(context.path.as_path(), password).await;
let owner = match opened {
std::result::Result::Ok(value) => value,
std::result::Result::Err(error) => {
self.restore_locked_after_unlock_failure(&context);
ksp_logging_lib::warn!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_WALLET_SESSION, wallet_id = context.wallet_id.as_str(), capability = context.capability.label(), error_domain = error.code().domain(), error_code = error.code().code(), "Manual Wallet unlock failed");
return std::result::Result::Err(error);
},
};
return self.finish_owner_unlock(context, owner);
}
/// Explicitly attempts Config-owned Wallet password candidates until VIEW unlock succeeds or candidates are exhausted.
pub(crate) async fn unlock_wallet_view_configured(&self) -> ksp_core_lib::Result<crate::WalletAuthorizedDto> {
let context = self.begin_unlock_operation(crate::WalletUnlockCapability::View);
let context = match context {
std::result::Result::Ok(value) => value,
std::result::Result::Err(error) => return std::result::Result::Err(error),
};
let candidates = crate::discover_wallet_secret_candidates(&self.config_management, context.wallet_id.as_str());
let candidates = match candidates {
std::result::Result::Ok(value) => value,
std::result::Result::Err(error) => {
self.restore_locked_after_unlock_failure(&context);
return std::result::Result::Err(error);
},
};
let candidate_count = candidates.len();
if candidate_count == 0 {
self.restore_locked_after_unlock_failure(&context);
return std::result::Result::Err(configured_secret_missing_error());
}
ksp_logging_lib::debug!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_WALLET_SECRET, wallet_id = context.wallet_id.as_str(), capability = context.capability.label(), candidate_count, "Explicit configured-secret Wallet unlock started");
let mut last_error = std::option::Option::None;
for candidate in candidates {
let secret = candidate.reveal(&self.config_management);
let secret = match secret {
std::result::Result::Ok(std::option::Option::Some(value)) => value,
std::result::Result::Ok(std::option::Option::None) => continue,
std::result::Result::Err(error) => {
self.restore_locked_after_unlock_failure(&context);
return std::result::Result::Err(error);
},
};
let opened = ksp_wallet_lib::open_wallet_view_file_v1(context.path.as_path(), ksp_wallet_lib::ViewPassword::new(secret)).await;
match opened {
std::result::Result::Ok(view) => {
ksp_logging_lib::info!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_WALLET_SECRET, wallet_id = context.wallet_id.as_str(), capability = context.capability.label(), candidate_count, "Configured-secret Wallet unlock succeeded");
return self.finish_view_unlock_with_count(context, view, candidate_count);
},
std::result::Result::Err(error) => last_error = std::option::Option::Some(error),
}
}
self.restore_locked_after_unlock_failure(&context);
ksp_logging_lib::warn!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_WALLET_SECRET, wallet_id = context.wallet_id.as_str(), capability = context.capability.label(), candidate_count, "Configured-secret Wallet unlock exhausted all candidates");
return match last_error {
std::option::Option::Some(error) => std::result::Result::Err(error),
std::option::Option::None => std::result::Result::Err(configured_secret_missing_error()),
};
}
/// Explicitly attempts Config-owned Wallet password candidates until OWNER unlock succeeds or candidates are exhausted.
pub(crate) async fn unlock_wallet_owner_configured(&self) -> ksp_core_lib::Result<crate::WalletAuthorizedDto> {
let context = self.begin_unlock_operation(crate::WalletUnlockCapability::Owner);
let context = match context {
std::result::Result::Ok(value) => value,
std::result::Result::Err(error) => return std::result::Result::Err(error),
};
let candidates = crate::discover_wallet_secret_candidates(&self.config_management, context.wallet_id.as_str());
let candidates = match candidates {
std::result::Result::Ok(value) => value,
std::result::Result::Err(error) => {
self.restore_locked_after_unlock_failure(&context);
return std::result::Result::Err(error);
},
};
let candidate_count = candidates.len();
if candidate_count == 0 {
self.restore_locked_after_unlock_failure(&context);
return std::result::Result::Err(configured_secret_missing_error());
}
ksp_logging_lib::debug!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_WALLET_SECRET, wallet_id = context.wallet_id.as_str(), capability = context.capability.label(), candidate_count, "Explicit configured-secret Wallet unlock started");
let mut last_error = std::option::Option::None;
for candidate in candidates {
let secret = candidate.reveal(&self.config_management);
let secret = match secret {
std::result::Result::Ok(std::option::Option::Some(value)) => value,
std::result::Result::Ok(std::option::Option::None) => continue,
std::result::Result::Err(error) => {
self.restore_locked_after_unlock_failure(&context);
return std::result::Result::Err(error);
},
};
let opened = ksp_wallet_lib::open_wallet_owner_file_v1(context.path.as_path(), ksp_wallet_lib::OwnerPassword::new(secret)).await;
match opened {
std::result::Result::Ok(owner) => {
ksp_logging_lib::info!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_WALLET_SECRET, wallet_id = context.wallet_id.as_str(), capability = context.capability.label(), candidate_count, "Configured-secret Wallet unlock succeeded");
return self.finish_owner_unlock_with_count(context, owner, candidate_count);
},
std::result::Result::Err(error) => last_error = std::option::Option::Some(error),
}
}
self.restore_locked_after_unlock_failure(&context);
ksp_logging_lib::warn!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_WALLET_SECRET, wallet_id = context.wallet_id.as_str(), capability = context.capability.label(), candidate_count, "Configured-secret Wallet unlock exhausted all candidates");
return match last_error {
std::option::Option::Some(error) => std::result::Result::Err(error),
std::option::Option::None => std::result::Result::Err(configured_secret_missing_error()),
};
}
/// Drops an authorized handle, re-inspects the selected file and returns the session to `Locked`.
pub(crate) async fn lock_wallet(&self) -> ksp_core_lib::Result<crate::LockedWalletDto> {
let previous = {
@@ -206,7 +346,23 @@ impl AppState {
return std::result::Result::Err(ksp_core_lib::Error::new(crate::ERROR_CODE_WALLET_SESSION_INVALID, "No Wallet is selected to lock"));
},
crate::WalletSession::Locked { wallet_id, path, .. } => (wallet_id, path),
crate::WalletSession::Owner { wallet_id, path, wallet } => {
crate::WalletSession::PrivilegedOperation { wallet_id, path, locked_info, capability } => {
let session = self.wallet_session.lock();
let mut session = match session {
std::result::Result::Ok(value) => value,
std::result::Result::Err(_) => return std::result::Result::Err(session_lock_error()),
};
*session = crate::WalletSession::PrivilegedOperation { wallet_id, path, locked_info, capability };
return std::result::Result::Err(ksp_core_lib::Error::new(
crate::ERROR_CODE_WALLET_SESSION_INVALID,
"Wallet unlock operation is already in progress",
));
},
crate::WalletSession::View { wallet_id, path, wallet, .. } => {
drop(wallet);
(wallet_id, path)
},
crate::WalletSession::Owner { wallet_id, path, wallet, .. } => {
drop(wallet);
(wallet_id, path)
},
@@ -216,7 +372,9 @@ impl AppState {
std::result::Result::Ok(value) => value,
std::result::Result::Err(error) => return std::result::Result::Err(error),
};
let configured_secret_candidate_count = self.secret_candidate_count_or_zero(wallet_id.as_str());
let dto = crate::LockedWalletDto {
configured_secret_candidate_count,
filename: wallet_id.clone(),
format_version: locked.format_version(),
wallet_id: wallet_id.clone(),
@@ -232,6 +390,140 @@ impl AppState {
return std::result::Result::Ok(dto);
}
fn begin_unlock_operation(&self, capability: crate::WalletUnlockCapability) -> ksp_core_lib::Result<WalletUnlockContext> {
let session = self.wallet_session.lock();
let mut session = match session {
std::result::Result::Ok(value) => value,
std::result::Result::Err(_) => return std::result::Result::Err(session_lock_error()),
};
let previous = std::mem::replace(&mut *session, crate::WalletSession::no_selection());
let (wallet_id, path, locked_info) = match previous {
crate::WalletSession::Locked { wallet_id, path, locked_info } => (wallet_id, path, locked_info),
other => {
*session = other;
return std::result::Result::Err(ksp_core_lib::Error::new(
crate::ERROR_CODE_WALLET_SESSION_INVALID,
"Wallet must be selected and locked before unlock",
));
},
};
if capability == crate::WalletUnlockCapability::View && !locked_info.view_enabled() {
*session = crate::WalletSession::Locked { wallet_id, path, locked_info };
return std::result::Result::Err(ksp_core_lib::Error::new(
crate::ERROR_CODE_WALLET_VIEW_DISABLED,
"Selected Wallet does not expose an enabled VIEW capability",
));
}
let context = WalletUnlockContext { capability, path: path.clone(), wallet_id: wallet_id.clone() };
*session = crate::WalletSession::PrivilegedOperation { capability, wallet_id, path, locked_info };
ksp_logging_lib::debug!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_WALLET_SESSION, wallet_id = context.wallet_id.as_str(), capability = context.capability.label(), "Explicit Wallet unlock operation started");
return std::result::Result::Ok(context);
}
fn restore_locked_after_unlock_failure(&self, context: &WalletUnlockContext) {
let session = self.wallet_session.lock();
let mut session = match session {
std::result::Result::Ok(value) => value,
std::result::Result::Err(_) => return,
};
let previous = std::mem::replace(&mut *session, crate::WalletSession::no_selection());
match previous {
crate::WalletSession::PrivilegedOperation { capability, wallet_id, path, locked_info }
if capability == context.capability && wallet_id == context.wallet_id && path == context.path =>
{
*session = crate::WalletSession::Locked { wallet_id, path, locked_info };
},
other => *session = other,
}
}
fn finish_view_unlock(&self, context: WalletUnlockContext, view: ksp_wallet_lib::WalletView) -> ksp_core_lib::Result<crate::WalletAuthorizedDto> {
let candidate_count = self.secret_candidate_count_or_zero(context.wallet_id.as_str());
return self.finish_view_unlock_with_count(context, view, candidate_count);
}
fn finish_view_unlock_with_count(
&self,
context: WalletUnlockContext,
view: ksp_wallet_lib::WalletView,
configured_secret_candidate_count: usize,
) -> ksp_core_lib::Result<crate::WalletAuthorizedDto> {
let session = self.wallet_session.lock();
let mut session = match session {
std::result::Result::Ok(value) => value,
std::result::Result::Err(_) => return std::result::Result::Err(session_lock_error()),
};
let previous = std::mem::replace(&mut *session, crate::WalletSession::no_selection());
let (wallet_id, path, view_enabled) = match previous {
crate::WalletSession::PrivilegedOperation { capability, wallet_id, path, locked_info }
if capability == context.capability && wallet_id == context.wallet_id && path == context.path =>
{
(wallet_id, path, locked_info.view_enabled())
},
other => {
*session = other;
drop(view);
return std::result::Result::Err(ksp_core_lib::Error::new(
crate::ERROR_CODE_WALLET_SESSION_INVALID,
"Wallet unlock completion no longer owns the selected session",
));
},
};
let dto = crate::view_projection(wallet_id.as_str(), view_enabled, configured_secret_candidate_count, &view);
*session = crate::WalletSession::View { wallet_id: wallet_id.clone(), path, wallet: std::boxed::Box::new(view) };
ksp_logging_lib::info!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_WALLET_SESSION, wallet_id = wallet_id.as_str(), capability = "view", "Wallet VIEW session opened");
return std::result::Result::Ok(dto);
}
fn finish_owner_unlock(&self, context: WalletUnlockContext, owner: ksp_wallet_lib::WalletOwner) -> ksp_core_lib::Result<crate::WalletAuthorizedDto> {
let candidate_count = self.secret_candidate_count_or_zero(context.wallet_id.as_str());
return self.finish_owner_unlock_with_count(context, owner, candidate_count);
}
fn finish_owner_unlock_with_count(
&self,
context: WalletUnlockContext,
owner: ksp_wallet_lib::WalletOwner,
configured_secret_candidate_count: usize,
) -> ksp_core_lib::Result<crate::WalletAuthorizedDto> {
let session = self.wallet_session.lock();
let mut session = match session {
std::result::Result::Ok(value) => value,
std::result::Result::Err(_) => return std::result::Result::Err(session_lock_error()),
};
let previous = std::mem::replace(&mut *session, crate::WalletSession::no_selection());
let (wallet_id, path, view_enabled) = match previous {
crate::WalletSession::PrivilegedOperation { capability, wallet_id, path, locked_info }
if capability == context.capability && wallet_id == context.wallet_id && path == context.path =>
{
(wallet_id, path, locked_info.view_enabled())
},
other => {
*session = other;
drop(owner);
return std::result::Result::Err(ksp_core_lib::Error::new(
crate::ERROR_CODE_WALLET_SESSION_INVALID,
"Wallet unlock completion no longer owns the selected session",
));
},
};
let dto = crate::owner_projection(wallet_id.as_str(), view_enabled, configured_secret_candidate_count, &owner);
*session = crate::WalletSession::Owner { wallet_id: wallet_id.clone(), path, wallet: std::boxed::Box::new(owner) };
ksp_logging_lib::info!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_WALLET_SESSION, wallet_id = wallet_id.as_str(), capability = "owner", "Wallet OWNER session opened");
return std::result::Result::Ok(dto);
}
fn secret_candidate_count_or_zero(&self, wallet_id: &str) -> usize {
let count = crate::wallet_secret_candidate_count(&self.config_management, wallet_id);
return match count {
std::result::Result::Ok(value) => value,
std::result::Result::Err(error) => {
ksp_logging_lib::warn!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_WALLET_SECRET, wallet_id, error_domain = error.code().domain(), error_code = error.code().code(), "Wallet configured-secret candidate count is unavailable");
0
},
};
}
/// Returns the resolved common splash timings captured during bootstrap.
#[must_use]
pub(crate) const fn splash_settings(&self) -> crate::SplashSettings {
@@ -260,6 +552,16 @@ fn session_lock_error() -> ksp_core_lib::Error {
return ksp_core_lib::Error::new(crate::ERROR_CODE_APP_STATE_LOCK_FAILED, "Wallet Desk Wallet session state lock is poisoned");
}
struct WalletUnlockContext {
capability: crate::WalletUnlockCapability,
path: std::path::PathBuf,
wallet_id: String,
}
fn configured_secret_missing_error() -> ksp_core_lib::Error {
return ksp_core_lib::Error::new(crate::ERROR_CODE_WALLET_SECRET_CANDIDATES_MISSING, "No effective Config-owned Wallet password candidate is available");
}
struct LoggingRuntimeState {
guard: ksp_logging_lib::LoggingGuard,
active_profile_id: std::option::Option<String>,

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-app-wallet-desk/src/constants.rs
// version: 4
// version: 5
//! Logging targets, domains and composite component identifiers owned by Wallet Desk.
@@ -19,7 +19,9 @@ pub(crate) const TRACING_DOMAIN_SHELL: &str = "wallet.shell";
pub(crate) const TRACING_DOMAIN_WALLET_CONFIG: &str = "wallet.config";
/// Structured domain used while enumerating and inspecting locked Wallet files.
pub(crate) const TRACING_DOMAIN_WALLET_INVENTORY: &str = "wallet.inventory";
/// Structured domain used by durable Wallet session and creation operations.
/// Structured domain used by Config-owned Wallet password candidate operations.
pub(crate) const TRACING_DOMAIN_WALLET_SECRET: &str = "wallet.secret";
/// Structured domain used by durable Wallet session, creation and unlock operations.
pub(crate) const TRACING_DOMAIN_WALLET_SESSION: &str = "wallet.session";
/// Structured domain used by Tauri window lifecycle operations.
pub(crate) const TRACING_DOMAIN_WINDOWS: &str = "desktop.window";

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-app-wallet-desk/src/errors.rs
// version: 4
// version: 5
//! Application-local error codes for Wallet Desk composition and desktop runtime surfaces.
@@ -33,7 +33,12 @@ pub(crate) const ERROR_CODE_WALLET_DIRECTORY_PREPARE_FAILED: ksp_core_lib::Error
ksp_core_lib::ErrorCode::new("wallet_desk", "wallet_directory_prepare_failed");
/// Wallet Desk cannot enumerate or inspect its effective Wallet inventory directory.
pub(crate) const ERROR_CODE_WALLET_INVENTORY_FAILED: ksp_core_lib::ErrorCode = ksp_core_lib::ErrorCode::new("wallet_desk", "wallet_inventory_failed");
/// No effective Config-owned Wallet password candidate is available for the explicit configured-secret unlock action.
pub(crate) const ERROR_CODE_WALLET_SECRET_CANDIDATES_MISSING: ksp_core_lib::ErrorCode =
ksp_core_lib::ErrorCode::new("wallet_desk", "wallet_secret_candidates_missing");
/// A requested Wallet inventory identifier is unsafe or does not resolve to an eligible regular `.kspwallet` file.
pub(crate) const ERROR_CODE_WALLET_SELECTION_INVALID: ksp_core_lib::ErrorCode = ksp_core_lib::ErrorCode::new("wallet_desk", "wallet_selection_invalid");
/// A Wallet session lifecycle operation is incompatible with the current state.
pub(crate) const ERROR_CODE_WALLET_SESSION_INVALID: ksp_core_lib::ErrorCode = ksp_core_lib::ErrorCode::new("wallet_desk", "wallet_session_invalid");
/// The selected Wallet does not expose an enabled VIEW capability.
pub(crate) const ERROR_CODE_WALLET_VIEW_DISABLED: ksp_core_lib::ErrorCode = ksp_core_lib::ErrorCode::new("wallet_desk", "wallet_view_disabled");

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-app-wallet-desk/src/lib.rs
// version: 5
// version: 6
//! Tauri desktop application shell for KSP Wallet management and inspection.
@@ -20,6 +20,7 @@ mod tw_main;
mod tw_splash;
mod wallet_config;
mod wallet_inventory;
mod wallet_secrets;
mod wallet_session;
/// Runs the KSP wallet desktop application.
@@ -53,7 +54,9 @@ pub(crate) use self::constants::TRACING_DOMAIN_SHELL;
pub(crate) use self::constants::TRACING_DOMAIN_WALLET_CONFIG;
/// Structured domain used while enumerating and inspecting locked Wallet files.
pub(crate) use self::constants::TRACING_DOMAIN_WALLET_INVENTORY;
/// Structured domain used by durable Wallet session and creation operations.
/// Structured domain used by Config-owned Wallet password candidate operations.
pub(crate) use self::constants::TRACING_DOMAIN_WALLET_SECRET;
/// Structured domain used by durable Wallet session, creation and unlock operations.
pub(crate) use self::constants::TRACING_DOMAIN_WALLET_SESSION;
/// Structured domain used by Tauri window lifecycle operations.
pub(crate) use self::constants::TRACING_DOMAIN_WINDOWS;
@@ -99,10 +102,14 @@ pub(crate) use self::errors::ERROR_CODE_WALLET_DIRECTORY_INVALID;
pub(crate) use self::errors::ERROR_CODE_WALLET_DIRECTORY_PREPARE_FAILED;
/// Wallet inventory filesystem operation failed.
pub(crate) use self::errors::ERROR_CODE_WALLET_INVENTORY_FAILED;
/// No effective Config-owned Wallet password candidate is available.
pub(crate) use self::errors::ERROR_CODE_WALLET_SECRET_CANDIDATES_MISSING;
/// Wallet selection identifier is invalid or no longer eligible.
pub(crate) use self::errors::ERROR_CODE_WALLET_SELECTION_INVALID;
/// Wallet session lifecycle operation is incompatible with the current state.
pub(crate) use self::errors::ERROR_CODE_WALLET_SESSION_INVALID;
/// Selected Wallet does not expose an enabled VIEW capability.
pub(crate) use self::errors::ERROR_CODE_WALLET_VIEW_DISABLED;
/// Log payload sent by Wallet Desk frontend scripts.
pub(crate) use self::frontend_logging::FrontendLogPayloadDto;
/// Emits one validated frontend event through the KSP Logging facade.
@@ -146,6 +153,10 @@ pub(crate) use self::wallet_inventory::resolve_locked_wallet;
/// Re-inspects one root-scoped Wallet selection in crate unit tests.
#[cfg(test)]
pub(crate) use self::wallet_inventory::select_locked_wallet;
/// Discovers Config-owned Wallet password candidates without exposing their names or values.
pub(crate) use self::wallet_secrets::discover_wallet_secret_candidates;
/// Returns the configured Wallet password candidate count without exposing their names or values.
pub(crate) use self::wallet_secrets::wallet_secret_candidate_count;
/// Authorized OWNER projection exposed only after successful creation.
pub(crate) use self::wallet_session::WalletAuthorizedDto;
/// Create request whose password strings move frontend -> Rust only.
@@ -157,5 +168,11 @@ pub(crate) use self::wallet_session::WalletSessionDto;
/// Safe state code for the durable Wallet session in crate unit tests.
#[cfg(test)]
pub(crate) use self::wallet_session::WalletSessionStateDto;
/// Capability targeted by one explicit unlock operation.
pub(crate) use self::wallet_session::WalletUnlockCapability;
/// Manual unlock request whose password moves frontend -> Rust only.
pub(crate) use self::wallet_session::WalletUnlockRequestDto;
/// Builds an authorized OWNER DTO from a Rust-only Wallet handle.
pub(crate) use self::wallet_session::owner_projection;
/// Builds an authorized VIEW DTO from a Rust-only Wallet handle.
pub(crate) use self::wallet_session::view_projection;

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-app-wallet-desk/src/tauri.rs
// version: 3
// version: 4
//! Tauri runtime assembly for the KSP wallet desktop application.
@@ -47,6 +47,10 @@ fn configure_commands(builder: tauri::Builder<tauri::Wry>) -> tauri::Builder<tau
refresh_wallets,
select_wallet,
splash_frontend_ready,
unlock_wallet_owner_configured,
unlock_wallet_owner_manual,
unlock_wallet_view_configured,
unlock_wallet_view_manual,
]);
}
@@ -163,3 +167,45 @@ async fn splash_frontend_ready(
std::result::Result::Err(error) => std::result::Result::Err(crate::CommandErrorDto::from_error(&error)),
};
}
#[tauri::command]
async fn unlock_wallet_owner_configured(state: tauri::State<'_, crate::AppState>) -> std::result::Result<crate::WalletAuthorizedDto, crate::CommandErrorDto> {
let result = state.unlock_wallet_owner_configured().await;
return match result {
std::result::Result::Ok(value) => std::result::Result::Ok(value),
std::result::Result::Err(error) => std::result::Result::Err(crate::CommandErrorDto::from_error(&error)),
};
}
#[tauri::command]
async fn unlock_wallet_owner_manual(
request: crate::WalletUnlockRequestDto,
state: tauri::State<'_, crate::AppState>,
) -> std::result::Result<crate::WalletAuthorizedDto, crate::CommandErrorDto> {
let result = state.unlock_wallet_owner_manual(request).await;
return match result {
std::result::Result::Ok(value) => std::result::Result::Ok(value),
std::result::Result::Err(error) => std::result::Result::Err(crate::CommandErrorDto::from_error(&error)),
};
}
#[tauri::command]
async fn unlock_wallet_view_configured(state: tauri::State<'_, crate::AppState>) -> std::result::Result<crate::WalletAuthorizedDto, crate::CommandErrorDto> {
let result = state.unlock_wallet_view_configured().await;
return match result {
std::result::Result::Ok(value) => std::result::Result::Ok(value),
std::result::Result::Err(error) => std::result::Result::Err(crate::CommandErrorDto::from_error(&error)),
};
}
#[tauri::command]
async fn unlock_wallet_view_manual(
request: crate::WalletUnlockRequestDto,
state: tauri::State<'_, crate::AppState>,
) -> std::result::Result<crate::WalletAuthorizedDto, crate::CommandErrorDto> {
let result = state.unlock_wallet_view_manual(request).await;
return match result {
std::result::Result::Ok(value) => std::result::Result::Ok(value),
std::result::Result::Err(error) => std::result::Result::Err(crate::CommandErrorDto::from_error(&error)),
};
}

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-app-wallet-desk/src/wallet_inventory.rs
// version: 2
// version: 3
//! Root-scoped Wallet inventory and locked-file selection for Wallet Desk.
@@ -53,6 +53,8 @@ pub(crate) struct WalletInventoryEntryDto {
#[serde(rename_all = "camelCase")]
#[ts(export, export_to = "../frontend/ts/bindings/ksp_app_wallet_desk/wallet_inventory/LockedWalletDto.ts")]
pub(crate) struct LockedWalletDto {
/// Number of effective Config-owned Wallet password candidates without their names or values.
pub(crate) configured_secret_candidate_count: usize,
/// Native Wallet filename without its parent path.
pub(crate) filename: String,
/// Native Wallet format version.
@@ -159,6 +161,7 @@ pub(crate) async fn resolve_locked_wallet(
std::result::Result::Err(error) => return std::result::Result::Err(error),
};
let dto = LockedWalletDto {
configured_secret_candidate_count: 0,
filename: wallet_id.clone(),
format_version: locked.format_version(),
wallet_id: wallet_id.clone(),

View File

@@ -0,0 +1,96 @@
// file: crates/ksp-app-wallet-desk/src/wallet_secrets.rs
// version: 1
//! Config-owned Wallet password candidate discovery for explicit unlock operations.
const WALLET_SECRET_PREFIX: &str = "KSP_SECRET_WALLET_PASS_";
/// One Config-owned secret candidate retained only inside Rust.
pub(crate) struct WalletSecretCandidate {
variable_name: String,
}
impl WalletSecretCandidate {
/// Explicitly reveals this candidate through Config's privileged management boundary.
pub(crate) fn reveal(self, management: &ksp_config_lib::ConfigManagement) -> ksp_core_lib::Result<std::option::Option<String>> {
return management.reveal_effective_environment_value(self.variable_name.as_str());
}
}
/// Discovers configured Wallet password candidates without revealing values.
pub(crate) fn discover_wallet_secret_candidates(
management: &ksp_config_lib::ConfigManagement,
wallet_id: &str,
) -> ksp_core_lib::Result<std::vec::Vec<WalletSecretCandidate>> {
let reports = management.environment_report();
let reports = match reports {
std::result::Result::Ok(value) => value,
std::result::Result::Err(error) => return std::result::Result::Err(error),
};
let mut names = reports
.into_iter()
.filter(|report| {
return report.sensitivity() == ksp_config_lib::ConfigSensitivity::Secret
&& report.effective_source().is_some()
&& report.variable_name().starts_with(WALLET_SECRET_PREFIX)
&& report.variable_name().len() > WALLET_SECRET_PREFIX.len();
})
.map(|report| return report.variable_name().to_owned())
.collect::<std::vec::Vec<_>>();
order_wallet_secret_candidate_names(wallet_id, names.as_mut_slice());
return std::result::Result::Ok(names.into_iter().map(|variable_name| return WalletSecretCandidate { variable_name }).collect());
}
/// Returns the number of effective configured Wallet password candidates without revealing names or values.
pub(crate) fn wallet_secret_candidate_count(management: &ksp_config_lib::ConfigManagement, wallet_id: &str) -> ksp_core_lib::Result<usize> {
let candidates = discover_wallet_secret_candidates(management, wallet_id);
return candidates.map(|values| return values.len());
}
/// Normalizes a native Wallet filename to the deterministic Config secret label candidate.
#[must_use]
fn normalize_wallet_secret_label(wallet_id: &str) -> String {
let stem = wallet_id.strip_suffix(crate::WALLET_FILE_SUFFIX).unwrap_or(wallet_id);
let mut output = String::new();
let mut previous_separator = false;
for byte in stem.bytes() {
let normalized = if byte.is_ascii_alphanumeric() { byte.to_ascii_uppercase() as char } else { '_' };
if normalized == '_' {
if output.is_empty() || previous_separator {
continue;
}
output.push('_');
previous_separator = true;
} else {
output.push(normalized);
previous_separator = false;
}
}
while output.ends_with('_') {
output.pop();
}
return output;
}
fn order_wallet_secret_candidate_names(wallet_id: &str, names: &mut [String]) {
let normalized = normalize_wallet_secret_label(wallet_id);
names.sort_by(|left, right| {
return wallet_secret_sort_key(left.as_str(), normalized.as_str()).cmp(&wallet_secret_sort_key(right.as_str(), normalized.as_str()));
});
}
fn wallet_secret_sort_key(variable_name: &str, normalized_filename: &str) -> (u8, u64, String) {
let suffix = variable_name.strip_prefix(WALLET_SECRET_PREFIX).unwrap_or(variable_name);
if suffix == normalized_filename && !normalized_filename.is_empty() {
return (0, 0, suffix.to_owned());
}
if !suffix.is_empty() && suffix.bytes().all(|byte| return byte.is_ascii_digit()) {
let parsed = suffix.parse::<u64>().unwrap_or(u64::MAX);
return (1, parsed, suffix.to_owned());
}
return (2, 0, suffix.to_owned());
}
#[cfg(test)]
#[path = "../unit_tests/wallet_secrets.rs"]
mod tests;

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-app-wallet-desk/src/wallet_session.rs
// version: 2
// version: 3
//! Durable root-scoped Wallet session lifecycle for Wallet Desk.
@@ -14,6 +14,10 @@ pub(crate) enum WalletSessionStateDto {
NoSelection,
/// One Wallet is selected but remains locked.
Locked,
/// One explicit unlock operation is running in Rust.
PrivilegedOperation,
/// One Wallet is open with VIEW capability.
ViewOpen,
/// One Wallet is open with OWNER capability.
OwnerOpen,
}
@@ -42,7 +46,7 @@ pub(crate) struct WalletNoteDto {
pub(crate) text: String,
}
/// Authorized Wallet projection returned after creation with OWNER capability.
/// Authorized Wallet projection returned after explicit VIEW/OWNER authorization.
#[derive(serde::Serialize, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export, export_to = "../frontend/ts/bindings/ksp_app_wallet_desk/wallet_session/WalletAuthorizedDto.ts")]
@@ -51,17 +55,19 @@ pub(crate) struct WalletAuthorizedDto {
pub(crate) alias: std::option::Option<String>,
/// Capability that produced this projection.
pub(crate) capability: String,
/// Number of effective Config-owned Wallet password candidates without their names or values.
pub(crate) configured_secret_candidate_count: usize,
/// Native Wallet filename without its parent path.
pub(crate) filename: String,
/// Native Wallet format version.
pub(crate) format_version: u32,
/// Protected notes available to the OWNER session.
/// Protected notes available to the authorized session.
pub(crate) notes: std::vec::Vec<WalletNoteDto>,
/// Authorized Solana public key.
pub(crate) pubkey: String,
/// Root-scoped identifier accepted by later Wallet Desk operations.
pub(crate) wallet_id: String,
/// Whether the created Wallet has an enabled VIEW slot.
/// Whether the Wallet has an enabled VIEW slot.
pub(crate) view_enabled: bool,
}
@@ -82,7 +88,36 @@ pub(crate) struct WalletCreateRequestDto {
pub(crate) view_password: std::option::Option<String>,
}
/// Backend Wallet session. Full paths and authorized handles never cross IPC.
/// Manual unlock request whose password exists only for the explicit frontend -> Rust call.
#[derive(serde::Deserialize, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export, export_to = "../frontend/ts/bindings/ksp_app_wallet_desk/wallet_session/WalletUnlockRequestDto.ts")]
pub(crate) struct WalletUnlockRequestDto {
/// Manual password transported only frontend -> Rust.
pub(crate) password: String,
}
/// Capability targeted by one explicit unlock operation.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) enum WalletUnlockCapability {
/// VIEW metadata-only authorization.
View,
/// OWNER full authorization.
Owner,
}
impl WalletUnlockCapability {
/// Returns a safe lowercase capability label for logs and projections.
#[must_use]
pub(crate) const fn label(self) -> &'static str {
return match self {
Self::View => "view",
Self::Owner => "owner",
};
}
}
/// Backend Wallet session. Full paths, configured secret names and authorized handles never cross IPC.
pub(crate) enum WalletSession {
/// No current Wallet selection.
NoSelection,
@@ -95,6 +130,26 @@ pub(crate) enum WalletSession {
/// Locked information re-inspected from the file.
locked_info: ksp_wallet_lib::LockedWalletInfo,
},
/// One explicit unlock operation currently owns the selected locked state.
PrivilegedOperation {
/// Capability being attempted.
capability: WalletUnlockCapability,
/// Native Wallet filename / root-scoped identifier.
wallet_id: String,
/// Full root-scoped filesystem path retained only in Rust.
path: std::path::PathBuf,
/// Locked information retained so a failed attempt can return to `Locked` without another KDF.
locked_info: ksp_wallet_lib::LockedWalletInfo,
},
/// One Wallet kept open with VIEW capability.
View {
/// Native Wallet filename / root-scoped identifier.
wallet_id: String,
/// Full root-scoped filesystem path retained only in Rust.
path: std::path::PathBuf,
/// Authorized VIEW handle retaining metadata capability only in Rust.
wallet: std::boxed::Box<ksp_wallet_lib::WalletView>,
},
/// One Wallet kept open with OWNER capability.
Owner {
/// Native Wallet filename / root-scoped identifier.
@@ -130,6 +185,16 @@ impl WalletSession {
wallet_id: std::option::Option::Some(wallet_id.clone()),
}
},
Self::PrivilegedOperation { wallet_id, .. } => WalletSessionDto {
filename: std::option::Option::Some(wallet_id.clone()),
state: WalletSessionStateDto::PrivilegedOperation,
wallet_id: std::option::Option::Some(wallet_id.clone()),
},
Self::View { wallet_id, .. } => WalletSessionDto {
filename: std::option::Option::Some(wallet_id.clone()),
state: WalletSessionStateDto::ViewOpen,
wallet_id: std::option::Option::Some(wallet_id.clone()),
},
Self::Owner { wallet_id, .. } => WalletSessionDto {
filename: std::option::Option::Some(wallet_id.clone()),
state: WalletSessionStateDto::OwnerOpen,
@@ -140,8 +205,32 @@ impl WalletSession {
}
/// Converts an OWNER handle into the authorized response DTO without exposing secret key material.
pub(crate) fn owner_projection(wallet_id: &str, view_enabled: bool, owner: &ksp_wallet_lib::WalletOwner) -> WalletAuthorizedDto {
let info = owner.info();
pub(crate) fn owner_projection(
wallet_id: &str,
view_enabled: bool,
configured_secret_candidate_count: usize,
owner: &ksp_wallet_lib::WalletOwner,
) -> WalletAuthorizedDto {
return authorized_projection(wallet_id, view_enabled, configured_secret_candidate_count, "owner", owner.info());
}
/// Converts a VIEW handle into the authorized response DTO without exposing OWNER material.
pub(crate) fn view_projection(
wallet_id: &str,
view_enabled: bool,
configured_secret_candidate_count: usize,
view: &ksp_wallet_lib::WalletView,
) -> WalletAuthorizedDto {
return authorized_projection(wallet_id, view_enabled, configured_secret_candidate_count, "view", view.info());
}
fn authorized_projection(
wallet_id: &str,
view_enabled: bool,
configured_secret_candidate_count: usize,
capability: &str,
info: &ksp_wallet_lib::WalletInfo,
) -> WalletAuthorizedDto {
let notes = info
.notes()
.iter()
@@ -151,7 +240,8 @@ pub(crate) fn owner_projection(wallet_id: &str, view_enabled: bool, owner: &ksp_
.collect();
return WalletAuthorizedDto {
alias: info.alias().map(|value| return value.to_owned()),
capability: "owner".to_owned(),
capability: capability.to_owned(),
configured_secret_candidate_count,
filename: wallet_id.to_owned(),
format_version: info.format_version(),
notes,