v0.2.6-pre.009
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-app-wallet-desk/src/app_state.rs
|
||||
// version: 10
|
||||
// version: 11
|
||||
|
||||
//! Shared backend state owned by the Wallet Desk Tauri application.
|
||||
|
||||
@@ -126,7 +126,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.008-wallet-import".to_owned(),
|
||||
shell_phase: "pre.009-owner-metadata".to_owned(),
|
||||
startup_diagnostic: runtime.startup_diagnostic.clone(),
|
||||
transport_available_endpoint_count,
|
||||
transport_clusters: self.transport_runtime.clusters(),
|
||||
@@ -217,7 +217,7 @@ impl AppState {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_) => return std::result::Result::Err(session_lock_error()),
|
||||
};
|
||||
*session = crate::WalletSession::Owner { wallet_id: filename.clone(), path: destination, wallet: std::boxed::Box::new(owner) };
|
||||
*session = crate::WalletSession::Owner { wallet_id: filename.clone(), path: destination, view_enabled, wallet: std::boxed::Box::new(owner) };
|
||||
ksp_logging_lib::info!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_WALLET_SESSION, wallet_id = filename.as_str(), view_enabled, "Wallet created and OWNER session opened");
|
||||
return std::result::Result::Ok(dto);
|
||||
}
|
||||
@@ -313,7 +313,7 @@ impl AppState {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_) => return std::result::Result::Err(session_lock_error()),
|
||||
};
|
||||
*session = crate::WalletSession::Owner { wallet_id: filename.clone(), path: destination, wallet: std::boxed::Box::new(owner) };
|
||||
*session = crate::WalletSession::Owner { wallet_id: filename.clone(), path: destination, view_enabled, wallet: std::boxed::Box::new(owner) };
|
||||
ksp_logging_lib::info!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_WALLET_IMPORT, wallet_id = filename.as_str(), transfer_format = transfer_format.code(), view_enabled, "Wallet transfer imported and OWNER session opened");
|
||||
return std::result::Result::Ok(dto);
|
||||
}
|
||||
@@ -483,6 +483,18 @@ impl AppState {
|
||||
"Wallet unlock operation is already in progress",
|
||||
));
|
||||
},
|
||||
crate::WalletSession::OwnerOperation { wallet_id, path, pubkey, view_enabled } => {
|
||||
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::OwnerOperation { wallet_id, path, pubkey, view_enabled };
|
||||
return std::result::Result::Err(ksp_core_lib::Error::new(
|
||||
crate::ERROR_CODE_WALLET_SESSION_INVALID,
|
||||
"Wallet OWNER metadata operation is already in progress",
|
||||
));
|
||||
},
|
||||
crate::WalletSession::View { wallet_id, path, wallet, .. } => {
|
||||
drop(wallet);
|
||||
(wallet_id, path)
|
||||
@@ -595,7 +607,7 @@ impl AppState {
|
||||
},
|
||||
};
|
||||
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) };
|
||||
*session = crate::WalletSession::View { wallet_id: wallet_id.clone(), path, view_enabled, 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);
|
||||
}
|
||||
@@ -633,7 +645,7 @@ impl AppState {
|
||||
},
|
||||
};
|
||||
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) };
|
||||
*session = crate::WalletSession::Owner { wallet_id: wallet_id.clone(), path, view_enabled, 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);
|
||||
}
|
||||
@@ -649,6 +661,178 @@ impl AppState {
|
||||
};
|
||||
}
|
||||
|
||||
/// Updates or clears the protected alias through the current OWNER handle.
|
||||
pub(crate) async fn update_wallet_alias(&self, request: crate::WalletAliasUpdateRequestDto) -> ksp_core_lib::Result<crate::WalletAuthorizedDto> {
|
||||
let context = self.begin_owner_metadata_operation("alias_update");
|
||||
let mut context = match context {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
||||
};
|
||||
let alias = normalize_optional_text(request.alias);
|
||||
let result = context.owner.update_alias(context.path.as_path(), alias).await;
|
||||
return self.finish_owner_metadata_operation(context, result).await;
|
||||
}
|
||||
|
||||
/// Appends one protected note through the current OWNER handle.
|
||||
pub(crate) async fn add_wallet_note(&self, request: crate::WalletNoteAddRequestDto) -> ksp_core_lib::Result<crate::WalletAuthorizedDto> {
|
||||
let context = self.begin_owner_metadata_operation("note_add");
|
||||
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.add_note(context.path.as_path(), request.text).await;
|
||||
let result = match result {
|
||||
std::result::Result::Ok(_) => std::result::Result::Ok(()),
|
||||
std::result::Result::Err(error) => std::result::Result::Err(error),
|
||||
};
|
||||
return self.finish_owner_metadata_operation(context, result).await;
|
||||
}
|
||||
|
||||
/// Updates one protected note through the current OWNER handle.
|
||||
pub(crate) async fn update_wallet_note(&self, request: crate::WalletNoteUpdateRequestDto) -> ksp_core_lib::Result<crate::WalletAuthorizedDto> {
|
||||
let context = self.begin_owner_metadata_operation("note_update");
|
||||
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.update_note(context.path.as_path(), request.note_id.as_str(), request.text).await;
|
||||
return self.finish_owner_metadata_operation(context, result).await;
|
||||
}
|
||||
|
||||
/// Deletes one protected note through the current OWNER handle.
|
||||
pub(crate) async fn delete_wallet_note(&self, request: crate::WalletNoteDeleteRequestDto) -> ksp_core_lib::Result<crate::WalletAuthorizedDto> {
|
||||
let context = self.begin_owner_metadata_operation("note_delete");
|
||||
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.delete_note(context.path.as_path(), request.note_id.as_str()).await;
|
||||
return self.finish_owner_metadata_operation(context, result).await;
|
||||
}
|
||||
|
||||
fn begin_owner_metadata_operation(&self, operation: &'static str) -> ksp_core_lib::Result<OwnerMetadataContext> {
|
||||
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, owner) = match previous {
|
||||
crate::WalletSession::Owner { wallet_id, path, view_enabled, wallet } => (wallet_id, path, view_enabled, wallet),
|
||||
other => {
|
||||
*session = other;
|
||||
return std::result::Result::Err(ksp_core_lib::Error::new(
|
||||
crate::ERROR_CODE_WALLET_AUTHORIZATION_REQUIRED,
|
||||
"Wallet metadata administration requires an authorized OWNER session",
|
||||
));
|
||||
},
|
||||
};
|
||||
let pubkey = owner.pubkey().to_owned();
|
||||
let context = OwnerMetadataContext { operation, owner, path: path.clone(), pubkey, 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 metadata operation started");
|
||||
return std::result::Result::Ok(context);
|
||||
}
|
||||
|
||||
async fn finish_owner_metadata_operation(
|
||||
&self,
|
||||
context: OwnerMetadataContext,
|
||||
operation_result: ksp_core_lib::Result<()>,
|
||||
) -> ksp_core_lib::Result<crate::WalletAuthorizedDto> {
|
||||
if let std::result::Result::Err(error) = operation_result {
|
||||
if error.code() == ksp_wallet_lib::ERROR_CODE_STATE_CONFLICT {
|
||||
self.recover_owner_metadata_state_conflict(context).await;
|
||||
return std::result::Result::Err(error);
|
||||
}
|
||||
self.restore_owner_after_metadata_failure(context);
|
||||
return std::result::Result::Err(error);
|
||||
}
|
||||
return self.install_owner_after_metadata_success(context);
|
||||
}
|
||||
|
||||
fn install_owner_after_metadata_success(&self, context: OwnerMetadataContext) -> ksp_core_lib::Result<crate::WalletAuthorizedDto> {
|
||||
let OwnerMetadataContext { operation, owner, path, pubkey, 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 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());
|
||||
match previous {
|
||||
crate::WalletSession::OwnerOperation {
|
||||
wallet_id: reserved_wallet_id,
|
||||
path: reserved_path,
|
||||
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 };
|
||||
ksp_logging_lib::info!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_WALLET_SESSION, wallet_id = wallet_id.as_str(), operation, "Wallet OWNER metadata operation completed");
|
||||
return std::result::Result::Ok(dto);
|
||||
},
|
||||
other => {
|
||||
*session = other;
|
||||
drop(owner);
|
||||
return std::result::Result::Err(ksp_core_lib::Error::new(
|
||||
crate::ERROR_CODE_WALLET_SESSION_INVALID,
|
||||
"Wallet metadata completion no longer owns the selected OWNER session",
|
||||
));
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn restore_owner_after_metadata_failure(&self, context: OwnerMetadataContext) {
|
||||
let OwnerMetadataContext { operation, owner, path, pubkey, view_enabled, wallet_id } = context;
|
||||
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::OwnerOperation {
|
||||
wallet_id: reserved_wallet_id,
|
||||
path: reserved_path,
|
||||
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 };
|
||||
ksp_logging_lib::debug!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_WALLET_SESSION, wallet_id = wallet_id.as_str(), operation, "Wallet OWNER metadata operation failed without invalidating the authenticated handle");
|
||||
},
|
||||
other => {
|
||||
*session = other;
|
||||
drop(owner);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
async fn recover_owner_metadata_state_conflict(&self, context: OwnerMetadataContext) {
|
||||
let OwnerMetadataContext { operation, owner, path, pubkey, 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();
|
||||
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::OwnerOperation {
|
||||
wallet_id: reserved_wallet_id,
|
||||
path: reserved_path,
|
||||
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 => {
|
||||
if let std::result::Result::Ok(locked_info) = inspected {
|
||||
*session = crate::WalletSession::Locked { wallet_id: wallet_id.clone(), path, locked_info };
|
||||
}
|
||||
ksp_logging_lib::warn!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_WALLET_SESSION, wallet_id = wallet_id.as_str(), operation, "Wallet OWNER metadata state conflict purged the stale handle and forced reauthorization");
|
||||
},
|
||||
other => *session = other,
|
||||
}
|
||||
}
|
||||
|
||||
/// Refreshes the native SOL balance for the currently authorized VIEW/OWNER Wallet.
|
||||
pub(crate) async fn refresh_wallet_balance(&self) -> ksp_core_lib::Result<crate::WalletBalanceDto> {
|
||||
let context = self.authorized_balance_context();
|
||||
@@ -702,10 +886,12 @@ impl AppState {
|
||||
crate::WalletSession::Owner { wallet_id, wallet, .. } => {
|
||||
std::result::Result::Ok(WalletBalanceContext { capability: "owner", pubkey: wallet.pubkey().to_owned(), wallet_id: wallet_id.clone() })
|
||||
},
|
||||
crate::WalletSession::PrivilegedOperation { .. } => std::result::Result::Err(ksp_core_lib::Error::new(
|
||||
crate::ERROR_CODE_WALLET_SESSION_INVALID,
|
||||
"Wallet balance is unavailable while a privileged Wallet operation is running",
|
||||
)),
|
||||
crate::WalletSession::OwnerOperation { .. } | crate::WalletSession::PrivilegedOperation { .. } => {
|
||||
std::result::Result::Err(ksp_core_lib::Error::new(
|
||||
crate::ERROR_CODE_WALLET_SESSION_INVALID,
|
||||
"Wallet balance is unavailable while a privileged Wallet operation is running",
|
||||
))
|
||||
},
|
||||
crate::WalletSession::Locked { .. } | crate::WalletSession::NoSelection => std::result::Result::Err(ksp_core_lib::Error::new(
|
||||
crate::ERROR_CODE_WALLET_AUTHORIZATION_REQUIRED,
|
||||
"Wallet balance requires an authorized VIEW or OWNER session",
|
||||
@@ -726,7 +912,10 @@ impl AppState {
|
||||
crate::WalletSession::Owner { wallet_id, wallet, .. } => {
|
||||
context.capability == "owner" && wallet_id == &context.wallet_id && wallet.pubkey() == &context.pubkey
|
||||
},
|
||||
crate::WalletSession::NoSelection | crate::WalletSession::Locked { .. } | crate::WalletSession::PrivilegedOperation { .. } => false,
|
||||
crate::WalletSession::NoSelection
|
||||
| crate::WalletSession::Locked { .. }
|
||||
| crate::WalletSession::OwnerOperation { .. }
|
||||
| crate::WalletSession::PrivilegedOperation { .. } => false,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -772,6 +961,15 @@ 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 OwnerMetadataContext {
|
||||
operation: &'static str,
|
||||
owner: std::boxed::Box<ksp_wallet_lib::WalletOwner>,
|
||||
path: std::path::PathBuf,
|
||||
pubkey: ksp_core_lib::Pubkey,
|
||||
view_enabled: bool,
|
||||
wallet_id: String,
|
||||
}
|
||||
|
||||
struct WalletBalanceContext {
|
||||
capability: &'static str,
|
||||
pubkey: ksp_core_lib::Pubkey,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-app-wallet-desk/src/lib.rs
|
||||
// version: 8
|
||||
// version: 9
|
||||
|
||||
//! Tauri desktop application shell for KSP Wallet management and inspection.
|
||||
|
||||
@@ -23,6 +23,7 @@ mod wallet_balance;
|
||||
mod wallet_config;
|
||||
mod wallet_import;
|
||||
mod wallet_inventory;
|
||||
mod wallet_metadata;
|
||||
mod wallet_secrets;
|
||||
mod wallet_session;
|
||||
|
||||
@@ -186,6 +187,14 @@ 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;
|
||||
/// OWNER alias update request carrying protected metadata only frontend -> Rust.
|
||||
pub(crate) use self::wallet_metadata::WalletAliasUpdateRequestDto;
|
||||
/// OWNER note append request carrying protected metadata only frontend -> Rust.
|
||||
pub(crate) use self::wallet_metadata::WalletNoteAddRequestDto;
|
||||
/// OWNER note delete request selecting one authorized stable note identifier.
|
||||
pub(crate) use self::wallet_metadata::WalletNoteDeleteRequestDto;
|
||||
/// OWNER note update request carrying protected metadata only frontend -> Rust.
|
||||
pub(crate) use self::wallet_metadata::WalletNoteUpdateRequestDto;
|
||||
/// 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.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-app-wallet-desk/src/tauri.rs
|
||||
// version: 6
|
||||
// version: 7
|
||||
|
||||
//! Tauri runtime assembly for the KSP wallet desktop application.
|
||||
|
||||
@@ -40,8 +40,10 @@ fn configure_plugins(builder: tauri::Builder<tauri::Wry>) -> tauri::Builder<taur
|
||||
#[allow(clippy::question_mark_used)] // Tauri generates the question-mark operator internally for async command dispatch.
|
||||
fn configure_commands(builder: tauri::Builder<tauri::Wry>) -> tauri::Builder<tauri::Wry> {
|
||||
return builder.invoke_handler(tauri::generate_handler![
|
||||
add_wallet_note,
|
||||
clear_import_source,
|
||||
create_wallet,
|
||||
delete_wallet_note,
|
||||
deselect_wallet,
|
||||
emit_frontend_log,
|
||||
get_runtime_status,
|
||||
@@ -57,6 +59,8 @@ fn configure_commands(builder: tauri::Builder<tauri::Wry>) -> tauri::Builder<tau
|
||||
unlock_wallet_owner_manual,
|
||||
unlock_wallet_view_configured,
|
||||
unlock_wallet_view_manual,
|
||||
update_wallet_alias,
|
||||
update_wallet_note,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -75,6 +79,18 @@ fn configure_setup(builder: tauri::Builder<tauri::Wry>) -> tauri::Builder<tauri:
|
||||
});
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn add_wallet_note(
|
||||
request: crate::WalletNoteAddRequestDto,
|
||||
state: tauri::State<'_, crate::AppState>,
|
||||
) -> std::result::Result<crate::WalletAuthorizedDto, crate::CommandErrorDto> {
|
||||
let result = state.add_wallet_note(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]
|
||||
fn clear_import_source(state: tauri::State<'_, crate::AppState>) -> std::result::Result<(), crate::CommandErrorDto> {
|
||||
let result = state.clear_import_source();
|
||||
@@ -96,6 +112,18 @@ async fn create_wallet(
|
||||
};
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn delete_wallet_note(
|
||||
request: crate::WalletNoteDeleteRequestDto,
|
||||
state: tauri::State<'_, crate::AppState>,
|
||||
) -> std::result::Result<crate::WalletAuthorizedDto, crate::CommandErrorDto> {
|
||||
let result = state.delete_wallet_note(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]
|
||||
fn deselect_wallet(state: tauri::State<'_, crate::AppState>) -> std::result::Result<crate::WalletSessionDto, crate::CommandErrorDto> {
|
||||
let result = state.deselect_wallet();
|
||||
@@ -286,3 +314,27 @@ async fn unlock_wallet_view_manual(
|
||||
std::result::Result::Err(error) => std::result::Result::Err(crate::CommandErrorDto::from_error(&error)),
|
||||
};
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn update_wallet_alias(
|
||||
request: crate::WalletAliasUpdateRequestDto,
|
||||
state: tauri::State<'_, crate::AppState>,
|
||||
) -> std::result::Result<crate::WalletAuthorizedDto, crate::CommandErrorDto> {
|
||||
let result = state.update_wallet_alias(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 update_wallet_note(
|
||||
request: crate::WalletNoteUpdateRequestDto,
|
||||
state: tauri::State<'_, crate::AppState>,
|
||||
) -> std::result::Result<crate::WalletAuthorizedDto, crate::CommandErrorDto> {
|
||||
let result = state.update_wallet_note(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)),
|
||||
};
|
||||
}
|
||||
|
||||
48
crates/ksp-app-wallet-desk/src/wallet_metadata.rs
Normal file
48
crates/ksp-app-wallet-desk/src/wallet_metadata.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
// file: crates/ksp-app-wallet-desk/src/wallet_metadata.rs
|
||||
// version: 1
|
||||
|
||||
//! OWNER-only protected metadata administration contracts for Wallet Desk.
|
||||
|
||||
use ts_rs::TS; // rust-rules: trait-import
|
||||
|
||||
/// OWNER request that updates or clears the protected internal Wallet alias.
|
||||
#[derive(serde::Deserialize, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export, export_to = "../frontend/ts/bindings/ksp_app_wallet_desk/wallet_metadata/WalletAliasUpdateRequestDto.ts")]
|
||||
pub(crate) struct WalletAliasUpdateRequestDto {
|
||||
/// New protected alias, or `None` to clear it.
|
||||
pub(crate) alias: std::option::Option<String>,
|
||||
}
|
||||
|
||||
/// OWNER request that appends one protected Wallet note.
|
||||
#[derive(serde::Deserialize, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export, export_to = "../frontend/ts/bindings/ksp_app_wallet_desk/wallet_metadata/WalletNoteAddRequestDto.ts")]
|
||||
pub(crate) struct WalletNoteAddRequestDto {
|
||||
/// Protected note text transported only for the explicit mutation call.
|
||||
pub(crate) text: String,
|
||||
}
|
||||
|
||||
/// OWNER request that updates one protected Wallet note by stable identifier.
|
||||
#[derive(serde::Deserialize, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export, export_to = "../frontend/ts/bindings/ksp_app_wallet_desk/wallet_metadata/WalletNoteUpdateRequestDto.ts")]
|
||||
pub(crate) struct WalletNoteUpdateRequestDto {
|
||||
/// Stable note identifier returned by the authorized Wallet projection.
|
||||
pub(crate) note_id: String,
|
||||
/// Replacement protected note text transported only for the explicit mutation call.
|
||||
pub(crate) text: String,
|
||||
}
|
||||
|
||||
/// OWNER request that deletes one protected Wallet note by stable identifier.
|
||||
#[derive(serde::Deserialize, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export, export_to = "../frontend/ts/bindings/ksp_app_wallet_desk/wallet_metadata/WalletNoteDeleteRequestDto.ts")]
|
||||
pub(crate) struct WalletNoteDeleteRequestDto {
|
||||
/// Stable note identifier returned by the authorized Wallet projection.
|
||||
pub(crate) note_id: String,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../unit_tests/wallet_metadata.rs"]
|
||||
mod tests;
|
||||
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-app-wallet-desk/src/wallet_session.rs
|
||||
// version: 3
|
||||
// version: 4
|
||||
|
||||
//! Durable root-scoped Wallet session lifecycle for Wallet Desk.
|
||||
|
||||
@@ -149,6 +149,8 @@ pub(crate) enum WalletSession {
|
||||
path: std::path::PathBuf,
|
||||
/// Authorized VIEW handle retaining metadata capability only in Rust.
|
||||
wallet: std::boxed::Box<ksp_wallet_lib::WalletView>,
|
||||
/// Whether the authenticated Wallet currently exposes a VIEW slot.
|
||||
view_enabled: bool,
|
||||
},
|
||||
/// One Wallet kept open with OWNER capability.
|
||||
Owner {
|
||||
@@ -158,6 +160,19 @@ pub(crate) enum WalletSession {
|
||||
path: std::path::PathBuf,
|
||||
/// Authorized OWNER handle retaining secret material only in Rust.
|
||||
wallet: std::boxed::Box<ksp_wallet_lib::WalletOwner>,
|
||||
/// Whether the authenticated Wallet currently exposes a VIEW slot.
|
||||
view_enabled: bool,
|
||||
},
|
||||
/// One OWNER metadata mutation temporarily owns the authorized handle outside the session mutex.
|
||||
OwnerOperation {
|
||||
/// Native Wallet filename / root-scoped identifier.
|
||||
wallet_id: String,
|
||||
/// Full root-scoped filesystem path retained only in Rust.
|
||||
path: std::path::PathBuf,
|
||||
/// Authorized Solana identity used only to reject stale completion.
|
||||
pubkey: ksp_core_lib::Pubkey,
|
||||
/// Whether the authenticated Wallet currently exposes a VIEW slot.
|
||||
view_enabled: bool,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -200,6 +215,11 @@ impl WalletSession {
|
||||
state: WalletSessionStateDto::OwnerOpen,
|
||||
wallet_id: std::option::Option::Some(wallet_id.clone()),
|
||||
},
|
||||
Self::OwnerOperation { wallet_id, .. } => WalletSessionDto {
|
||||
filename: std::option::Option::Some(wallet_id.clone()),
|
||||
state: WalletSessionStateDto::PrivilegedOperation,
|
||||
wallet_id: std::option::Option::Some(wallet_id.clone()),
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user