v0.2.6-pre.006
This commit is contained in:
@@ -40,9 +40,9 @@
|
||||
<div class="d-flex align-items-center justify-content-between mb-4">
|
||||
<div>
|
||||
<h1 id="viewTitle" class="h3 mb-1">Dashboard</h1>
|
||||
<p class="text-body-secondary mb-0">Inventaire `.kspwallet` root-scoped et inspection locked actifs.</p>
|
||||
<p class="text-body-secondary mb-0">Création native, sessions durables et unlock explicite VIEW/OWNER actifs.</p>
|
||||
</div>
|
||||
<span class="badge text-bg-secondary">0.2.6-pre.005</span>
|
||||
<span class="badge text-bg-secondary">0.2.6-pre.006</span>
|
||||
</div>
|
||||
<section data-view-panel="dashboard">
|
||||
<div class="row g-3">
|
||||
@@ -76,6 +76,7 @@
|
||||
<dt class="col-5">État</dt><dd id="currentWalletState" class="col-7">—</dd>
|
||||
<dt class="col-5">Format</dt><dd id="currentWalletFormat" class="col-7">—</dd>
|
||||
<dt class="col-5">VIEW</dt><dd id="currentWalletView" class="col-7">—</dd>
|
||||
<dt class="col-5">Secrets Config</dt><dd id="currentWalletSecretCandidates" class="col-7">0</dd>
|
||||
<dt class="col-5">Pubkey</dt><dd id="currentWalletPubkey" class="col-7 text-break">—</dd>
|
||||
<dt class="col-5">Alias</dt><dd id="currentWalletAlias" class="col-7 text-break">—</dd>
|
||||
<dt class="col-5">Notes</dt><dd id="currentWalletNotes" class="col-7 text-break">—</dd>
|
||||
@@ -159,14 +160,57 @@
|
||||
</div>
|
||||
</section>
|
||||
<section data-view-panel="details" hidden><div class="app-placeholder"><i class="fa-solid fa-id-card"></i><p>Les détails protégés seront affichés uniquement après VIEW/OWNER.</p></div></section>
|
||||
<section data-view-panel="security" hidden><div class="app-placeholder"><i class="fa-solid fa-shield-halved"></i><p>Les opérations OWNER seront ajoutées après le MVP identité + balance.</p></div></section>
|
||||
<section data-view-panel="security" hidden>
|
||||
<div class="row g-3">
|
||||
<div class="col-xl-7">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header fw-semibold">Unlock manuel du wallet sélectionné</div>
|
||||
<div class="card-body">
|
||||
<p class="text-body-secondary">Chaque tentative Argon2 est explicite et peut prendre plusieurs secondes. Le password est envoyé uniquement frontend → Rust puis purgé.</p>
|
||||
<div class="row g-3">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label" for="unlockWalletViewPassword">VIEW password</label>
|
||||
<div class="input-group">
|
||||
<input id="unlockWalletViewPassword" class="form-control" type="password" autocomplete="current-password">
|
||||
<button id="unlockViewManual" class="btn btn-outline-primary" type="button" disabled>Unlock VIEW</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label" for="unlockWalletOwnerPassword">OWNER password</label>
|
||||
<div class="input-group">
|
||||
<input id="unlockWalletOwnerPassword" class="form-control" type="password" autocomplete="current-password">
|
||||
<button id="unlockOwnerManual" class="btn btn-outline-danger" type="button" disabled>Unlock OWNER</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xl-5">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header fw-semibold">Secrets configurés</div>
|
||||
<div class="card-body">
|
||||
<p class="mb-2">Candidats effectifs : <strong id="unlockSecretCandidateCount">0</strong></p>
|
||||
<p class="small text-body-secondary">Les noms, suffixes et valeurs des secrets Wallet configurés restent exclusivement côté Rust/Config. Cette action tente les candidats uniquement sur demande.</p>
|
||||
<div class="d-grid gap-2">
|
||||
<button id="unlockViewConfigured" class="btn btn-outline-primary" type="button" disabled>Unlock VIEW avec secret configuré</button>
|
||||
<button id="unlockOwnerConfigured" class="btn btn-outline-danger" type="button" disabled>Unlock OWNER avec secret configuré</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<div id="unlockStatus" class="alert alert-secondary mb-0" role="status">Sélectionner un wallet verrouillé.</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section data-view-panel="diagnostics" hidden><div class="app-placeholder"><i class="fa-solid fa-stethoscope"></i><p>Les diagnostics Config/Wallet/Transport seront enrichis progressivement.</p></div></section>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
<footer class="app-footer bg-dark text-white-50 d-flex align-items-center px-4">
|
||||
<span>KSP Wallet Desk · create + session lifecycle pre.005</span>
|
||||
<span>KSP Wallet Desk · manual/configured unlock pre.006</span>
|
||||
</footer>
|
||||
<script type="module" src="./ts/main.ts"></script>
|
||||
</body>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-app-wallet-desk/frontend/ts/main.ts
|
||||
// version: 5
|
||||
// version: 6
|
||||
|
||||
import "bootstrap";
|
||||
import DataTable from "datatables.net-bs5";
|
||||
@@ -14,6 +14,7 @@ import type { WalletSelectionRequestDto } from "./bindings/ksp_app_wallet_desk/w
|
||||
import type { WalletAuthorizedDto } from "./bindings/ksp_app_wallet_desk/wallet_session/WalletAuthorizedDto.ts";
|
||||
import type { WalletCreateRequestDto } from "./bindings/ksp_app_wallet_desk/wallet_session/WalletCreateRequestDto.ts";
|
||||
import type { WalletSessionDto } from "./bindings/ksp_app_wallet_desk/wallet_session/WalletSessionDto.ts";
|
||||
import type { WalletUnlockRequestDto } from "./bindings/ksp_app_wallet_desk/wallet_session/WalletUnlockRequestDto.ts";
|
||||
import { frontendDebug, frontendInfo, frontendTrace, frontendWarn, installFrontendConsoleBridge } from "./frontend_log";
|
||||
import { invokeKsp } from "./invoke";
|
||||
import "../sass/main.scss";
|
||||
@@ -22,7 +23,8 @@ import "../sass/main.scss";
|
||||
installFrontendConsoleBridge("main");
|
||||
|
||||
type ViewId = "dashboard" | "wallets" | "create-import" | "details" | "security" | "diagnostics";
|
||||
type ActiveSessionState = "no_selection" | "locked" | "owner_open";
|
||||
type ActiveSessionState = "no_selection" | "locked" | "privileged_operation" | "view_open" | "owner_open";
|
||||
type UnlockCapability = "view" | "owner";
|
||||
|
||||
const viewTitles: Record<ViewId, string> = {
|
||||
dashboard: "Dashboard",
|
||||
@@ -35,6 +37,8 @@ const viewTitles: Record<ViewId, string> = {
|
||||
|
||||
let activeWalletId: string | null = null;
|
||||
let activeSessionState: ActiveSessionState = "no_selection";
|
||||
let activeViewEnabled = false;
|
||||
let configuredSecretCandidateCount = 0;
|
||||
|
||||
function isViewId(value: string): value is ViewId {
|
||||
return value in viewTitles;
|
||||
@@ -121,8 +125,8 @@ function renderWalletInventoryRow(entry: WalletInventoryEntryDto): HTMLTableRowE
|
||||
row.dataset.inspectionStatus = entry.inspectionStatus;
|
||||
const state = document.createElement("td");
|
||||
if (entry.state === "locked") {
|
||||
if (activeWalletId === entry.walletId && activeSessionState === "owner_open") {
|
||||
appendIconText(state, "fa-lock-open", "OWNER");
|
||||
if (activeWalletId === entry.walletId && (activeSessionState === "view_open" || activeSessionState === "owner_open")) {
|
||||
appendIconText(state, "fa-lock-open", activeSessionState === "view_open" ? "VIEW" : "OWNER");
|
||||
} else {
|
||||
appendIconText(state, "fa-lock", "Locked");
|
||||
}
|
||||
@@ -165,7 +169,7 @@ function initializeWalletTable(): void {
|
||||
zeroRecords: "Aucun wallet correspondant.",
|
||||
},
|
||||
});
|
||||
frontendDebug("main", "Wallet inventory DataTable initialized", { phase: "pre.005-wallet-session-create" });
|
||||
frontendDebug("main", "Wallet inventory DataTable initialized", { phase: "pre.006-wallet-unlock" });
|
||||
}
|
||||
|
||||
function renderWalletInventory(entries: WalletInventoryEntryDto[]): void {
|
||||
@@ -192,11 +196,33 @@ function updateSessionActions(): void {
|
||||
const lock = document.querySelector<HTMLButtonElement>('[data-shell-action="lock"]');
|
||||
const deselect = document.querySelector<HTMLButtonElement>('[data-shell-action="deselect"]');
|
||||
if (lock) {
|
||||
lock.disabled = activeSessionState !== "owner_open";
|
||||
lock.disabled = activeSessionState !== "view_open" && activeSessionState !== "owner_open";
|
||||
}
|
||||
if (deselect) {
|
||||
deselect.disabled = activeSessionState === "no_selection";
|
||||
deselect.disabled = activeSessionState === "no_selection" || activeSessionState === "privileged_operation";
|
||||
}
|
||||
updateUnlockActions();
|
||||
}
|
||||
|
||||
function updateUnlockActions(): void {
|
||||
const locked = activeSessionState === "locked";
|
||||
const viewManual = document.querySelector<HTMLButtonElement>("#unlockViewManual");
|
||||
const ownerManual = document.querySelector<HTMLButtonElement>("#unlockOwnerManual");
|
||||
const viewConfigured = document.querySelector<HTMLButtonElement>("#unlockViewConfigured");
|
||||
const ownerConfigured = document.querySelector<HTMLButtonElement>("#unlockOwnerConfigured");
|
||||
if (viewManual) {
|
||||
viewManual.disabled = !locked || !activeViewEnabled;
|
||||
}
|
||||
if (ownerManual) {
|
||||
ownerManual.disabled = !locked;
|
||||
}
|
||||
if (viewConfigured) {
|
||||
viewConfigured.disabled = !locked || !activeViewEnabled || configuredSecretCandidateCount === 0;
|
||||
}
|
||||
if (ownerConfigured) {
|
||||
ownerConfigured.disabled = !locked || configuredSecretCandidateCount === 0;
|
||||
}
|
||||
setText("#unlockSecretCandidateCount", configuredSecretCandidateCount.toString());
|
||||
}
|
||||
|
||||
function clearCreateFormSensitiveInputs(): void {
|
||||
@@ -218,16 +244,30 @@ function clearCreateFormSensitiveInputs(): void {
|
||||
}
|
||||
}
|
||||
|
||||
function clearUnlockSensitiveInputs(): void {
|
||||
const viewPassword = document.querySelector<HTMLInputElement>("#unlockWalletViewPassword");
|
||||
const ownerPassword = document.querySelector<HTMLInputElement>("#unlockWalletOwnerPassword");
|
||||
if (viewPassword) {
|
||||
viewPassword.value = "";
|
||||
}
|
||||
if (ownerPassword) {
|
||||
ownerPassword.value = "";
|
||||
}
|
||||
}
|
||||
|
||||
function clearAuthorizedProjection(): void {
|
||||
setText("#currentWalletPubkey", "—");
|
||||
setText("#currentWalletAlias", "—");
|
||||
setText("#currentWalletNotes", "—");
|
||||
clearCreateFormSensitiveInputs();
|
||||
clearUnlockSensitiveInputs();
|
||||
}
|
||||
|
||||
function clearSelectedWallet(): void {
|
||||
activeWalletId = null;
|
||||
activeSessionState = "no_selection";
|
||||
activeViewEnabled = false;
|
||||
configuredSecretCandidateCount = 0;
|
||||
const icon = document.querySelector<HTMLElement>("#currentWalletIcon");
|
||||
if (icon) {
|
||||
icon.className = "fa-solid fa-lock fa-2x mb-3 text-body-secondary";
|
||||
@@ -236,6 +276,8 @@ function clearSelectedWallet(): void {
|
||||
setText("#currentWalletState", "—");
|
||||
setText("#currentWalletFormat", "—");
|
||||
setText("#currentWalletView", "—");
|
||||
setText("#currentWalletSecretCandidates", "0");
|
||||
setText("#unlockStatus", "Sélectionner un wallet verrouillé.");
|
||||
clearAuthorizedProjection();
|
||||
updateSessionActions();
|
||||
}
|
||||
@@ -243,6 +285,8 @@ function clearSelectedWallet(): void {
|
||||
function renderLockedWallet(wallet: LockedWalletDto): void {
|
||||
activeWalletId = wallet.walletId;
|
||||
activeSessionState = "locked";
|
||||
activeViewEnabled = wallet.viewEnabled;
|
||||
configuredSecretCandidateCount = wallet.configuredSecretCandidateCount;
|
||||
clearAuthorizedProjection();
|
||||
const icon = document.querySelector<HTMLElement>("#currentWalletIcon");
|
||||
if (icon) {
|
||||
@@ -252,26 +296,45 @@ function renderLockedWallet(wallet: LockedWalletDto): void {
|
||||
setText("#currentWalletState", "Locked");
|
||||
setText("#currentWalletFormat", wallet.formatVersion.toString());
|
||||
setText("#currentWalletView", wallet.viewEnabled ? "enabled" : "disabled");
|
||||
setText("#currentWalletSecretCandidates", configuredSecretCandidateCount.toString());
|
||||
setText("#unlockStatus", "Prêt pour une tentative explicite. Argon2 peut prendre plusieurs secondes.");
|
||||
updateSessionActions();
|
||||
frontendDebug("main", "Locked Wallet selection rendered", { walletId: wallet.walletId, formatVersion: wallet.formatVersion, viewEnabled: wallet.viewEnabled });
|
||||
frontendDebug("main", "Locked Wallet selection rendered", {
|
||||
configuredSecretCandidateCount,
|
||||
formatVersion: wallet.formatVersion,
|
||||
viewEnabled: wallet.viewEnabled,
|
||||
walletId: wallet.walletId,
|
||||
});
|
||||
}
|
||||
|
||||
function renderAuthorizedWallet(wallet: WalletAuthorizedDto): void {
|
||||
activeWalletId = wallet.walletId;
|
||||
activeSessionState = "owner_open";
|
||||
activeSessionState = wallet.capability === "view" ? "view_open" : "owner_open";
|
||||
activeViewEnabled = wallet.viewEnabled;
|
||||
configuredSecretCandidateCount = wallet.configuredSecretCandidateCount;
|
||||
clearUnlockSensitiveInputs();
|
||||
const icon = document.querySelector<HTMLElement>("#currentWalletIcon");
|
||||
if (icon) {
|
||||
icon.className = "fa-solid fa-lock-open fa-2x mb-3 text-success";
|
||||
}
|
||||
const capabilityLabel = wallet.capability === "view" ? "VIEW" : "OWNER";
|
||||
setText("#currentWalletFilename", wallet.filename);
|
||||
setText("#currentWalletState", "OWNER open");
|
||||
setText("#currentWalletState", `${capabilityLabel} open`);
|
||||
setText("#currentWalletFormat", wallet.formatVersion.toString());
|
||||
setText("#currentWalletView", wallet.viewEnabled ? "enabled" : "disabled");
|
||||
setText("#currentWalletSecretCandidates", configuredSecretCandidateCount.toString());
|
||||
setText("#currentWalletPubkey", wallet.pubkey);
|
||||
setText("#currentWalletAlias", wallet.alias ?? "—");
|
||||
setText("#currentWalletNotes", wallet.notes.length === 0 ? "—" : wallet.notes.map(note => note.text).join(" · "));
|
||||
setText("#unlockStatus", `${capabilityLabel} ouvert. Lock pour purger le handle autorisé.`);
|
||||
updateSessionActions();
|
||||
frontendDebug("main", "OWNER Wallet session rendered after creation", { walletId: wallet.walletId, viewEnabled: wallet.viewEnabled, noteCount: wallet.notes.length });
|
||||
frontendDebug("main", "Authorized Wallet session rendered", {
|
||||
capability: wallet.capability,
|
||||
configuredSecretCandidateCount,
|
||||
noteCount: wallet.notes.length,
|
||||
viewEnabled: wallet.viewEnabled,
|
||||
walletId: wallet.walletId,
|
||||
});
|
||||
}
|
||||
|
||||
async function selectWallet(walletId: string): Promise<void> {
|
||||
@@ -395,6 +458,94 @@ function bindCreateWalletForm(): void {
|
||||
frontendTrace("main", "Create Wallet form handlers installed");
|
||||
}
|
||||
|
||||
function beginFrontendUnlock(capability: UnlockCapability, provider: "manual" | "configured"): string | null {
|
||||
if (activeSessionState !== "locked" || !activeWalletId) {
|
||||
return null;
|
||||
}
|
||||
const walletId = activeWalletId;
|
||||
activeSessionState = "privileged_operation";
|
||||
setText("#currentWalletState", `Unlock ${capability.toUpperCase()}…`);
|
||||
setText("#unlockStatus", provider === "manual" ? "Dérivation Argon2 en cours…" : `Tentative explicite sur ${configuredSecretCandidateCount} secret(s) configuré(s)…`);
|
||||
updateSessionActions();
|
||||
return walletId;
|
||||
}
|
||||
|
||||
function restoreFrontendLockedAfterUnlockFailure(walletId: string): void {
|
||||
if (activeWalletId !== walletId) {
|
||||
return;
|
||||
}
|
||||
activeSessionState = "locked";
|
||||
clearAuthorizedProjection();
|
||||
const icon = document.querySelector<HTMLElement>("#currentWalletIcon");
|
||||
if (icon) {
|
||||
icon.className = "fa-solid fa-lock fa-2x mb-3";
|
||||
}
|
||||
setText("#currentWalletState", "Locked");
|
||||
setText("#unlockStatus", "Unlock refusé. Le wallet reste verrouillé.");
|
||||
updateSessionActions();
|
||||
}
|
||||
|
||||
async function unlockManual(capability: UnlockCapability): Promise<void> {
|
||||
const input = document.querySelector<HTMLInputElement>(capability === "view" ? "#unlockWalletViewPassword" : "#unlockWalletOwnerPassword");
|
||||
if (!input || input.value.length === 0) {
|
||||
setText("#unlockStatus", "Password manuel requis.");
|
||||
return;
|
||||
}
|
||||
const request: WalletUnlockRequestDto = { password: input.value };
|
||||
const walletId = beginFrontendUnlock(capability, "manual");
|
||||
if (!walletId) {
|
||||
clearUnlockSensitiveInputs();
|
||||
return;
|
||||
}
|
||||
const command = capability === "view" ? "unlock_wallet_view_manual" : "unlock_wallet_owner_manual";
|
||||
frontendDebug("main", "Manual Wallet unlock requested", { capability, walletId });
|
||||
try {
|
||||
const wallet = await invokeKsp<WalletAuthorizedDto>("main", command, { request });
|
||||
clearUnlockSensitiveInputs();
|
||||
renderAuthorizedWallet(wallet);
|
||||
await loadWalletInventory("list_wallets", false);
|
||||
activateView("dashboard", "user");
|
||||
} catch {
|
||||
clearUnlockSensitiveInputs();
|
||||
restoreFrontendLockedAfterUnlockFailure(walletId);
|
||||
frontendWarn("main", "Manual Wallet unlock failed", { capability, walletId });
|
||||
}
|
||||
}
|
||||
|
||||
async function unlockConfigured(capability: UnlockCapability): Promise<void> {
|
||||
const walletId = beginFrontendUnlock(capability, "configured");
|
||||
if (!walletId) {
|
||||
return;
|
||||
}
|
||||
const command = capability === "view" ? "unlock_wallet_view_configured" : "unlock_wallet_owner_configured";
|
||||
frontendDebug("main", "Configured-secret Wallet unlock requested", { capability, configuredSecretCandidateCount, walletId });
|
||||
try {
|
||||
const wallet = await invokeKsp<WalletAuthorizedDto>("main", command);
|
||||
renderAuthorizedWallet(wallet);
|
||||
await loadWalletInventory("list_wallets", false);
|
||||
activateView("dashboard", "user");
|
||||
} catch {
|
||||
restoreFrontendLockedAfterUnlockFailure(walletId);
|
||||
frontendWarn("main", "Configured-secret Wallet unlock failed", { capability, configuredSecretCandidateCount, walletId });
|
||||
}
|
||||
}
|
||||
|
||||
function bindUnlockActions(): void {
|
||||
document.querySelector<HTMLButtonElement>("#unlockViewManual")?.addEventListener("click", () => {
|
||||
void unlockManual("view");
|
||||
});
|
||||
document.querySelector<HTMLButtonElement>("#unlockOwnerManual")?.addEventListener("click", () => {
|
||||
void unlockManual("owner");
|
||||
});
|
||||
document.querySelector<HTMLButtonElement>("#unlockViewConfigured")?.addEventListener("click", () => {
|
||||
void unlockConfigured("view");
|
||||
});
|
||||
document.querySelector<HTMLButtonElement>("#unlockOwnerConfigured")?.addEventListener("click", () => {
|
||||
void unlockConfigured("owner");
|
||||
});
|
||||
frontendTrace("main", "Wallet unlock action handlers installed");
|
||||
}
|
||||
|
||||
async function lockCurrentWallet(): Promise<void> {
|
||||
clearAuthorizedProjection();
|
||||
try {
|
||||
@@ -431,7 +582,7 @@ function renderRuntimeStatus(status: RuntimeStatusDto): void {
|
||||
setText("#runtimeEffectiveWalletsDirectory", status.effectiveWalletsDirectory);
|
||||
setText("#runtimeWalletDirectoryCreated", status.effectiveWalletsDirectoryCreatedOnStartup ? "oui" : "non, déjà présent");
|
||||
setText("#runtimeShellPhase", status.shellPhase);
|
||||
setText("#shellStatus", "Config résolue ; création et session Wallet prêtes.");
|
||||
setText("#shellStatus", "Config résolue ; création et unlock VIEW/OWNER prêts.");
|
||||
frontendTrace("main", "Wallet Desk runtime status rendered", {
|
||||
compositeProfile: status.activeCompositeProfile,
|
||||
fallbackLoggingActive: status.fallbackLoggingActive,
|
||||
@@ -477,6 +628,7 @@ async function initializeMain(): Promise<void> {
|
||||
bindNavigation();
|
||||
bindWalletTableSelection();
|
||||
bindCreateWalletForm();
|
||||
bindUnlockActions();
|
||||
bindShellActions();
|
||||
clearSelectedWallet();
|
||||
activateView("dashboard", "startup");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ksp-app-wallet-desk",
|
||||
"private": true,
|
||||
"version": "0.2.6-pre.5.fix.1",
|
||||
"version": "0.2.6-pre.6",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -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>,
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
|
||||
96
crates/ksp-app-wallet-desk/src/wallet_secrets.rs
Normal file
96
crates/ksp-app-wallet-desk/src/wallet_secrets.rs
Normal 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;
|
||||
@@ -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,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "KSP Wallet Desk",
|
||||
"version": "0.2.6-pre.5.fix.1",
|
||||
"version": "0.2.6-pre.6",
|
||||
"identifier": "com.sasedev.ksp-app-wallet-desk",
|
||||
"build": {
|
||||
"beforeDevCommand": "npm run dev",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-app-wallet-desk/tests/desktop_contract.rs
|
||||
// version: 5
|
||||
// version: 6
|
||||
|
||||
//! Desktop build, shell and Config-status contract audits for Wallet Desk.
|
||||
|
||||
@@ -141,5 +141,34 @@ fn pre_005_create_and_session_lifecycle_are_backend_owned() {
|
||||
assert!(html.contains("id=\"createWalletOwnerPassword\""));
|
||||
assert!(html.contains("id=\"createWalletViewPassword\""));
|
||||
assert!(main.contains("clearCreateFormSensitiveInputs"));
|
||||
assert!(main.contains("OWNER Wallet session rendered after creation"));
|
||||
assert!(main.contains("Authorized Wallet session rendered"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pre_006_unlock_surface_is_explicit_backend_owned_and_supports_view_owner() {
|
||||
let root = app_root();
|
||||
let state = read_text(root.join("src/app_state.rs").as_path());
|
||||
let secrets = read_text(root.join("src/wallet_secrets.rs").as_path());
|
||||
let session = read_text(root.join("src/wallet_session.rs").as_path());
|
||||
let tauri = read_text(root.join("src/tauri.rs").as_path());
|
||||
let html = read_text(root.join("frontend/main.html").as_path());
|
||||
let main = read_text(root.join("frontend/ts/main.ts").as_path());
|
||||
assert!(state.contains("open_wallet_view_file_v1"));
|
||||
assert!(state.contains("open_wallet_owner_file_v1"));
|
||||
assert!(state.contains("WalletSession::PrivilegedOperation"));
|
||||
assert!(state.contains("WalletSession::View"));
|
||||
assert!(secrets.contains("environment_report"));
|
||||
assert!(secrets.contains("reveal_effective_environment_value"));
|
||||
assert!(secrets.contains("normalize_wallet_secret_label"));
|
||||
assert!(session.contains("WalletUnlockRequestDto"));
|
||||
assert!(tauri.contains("unlock_wallet_view_manual"));
|
||||
assert!(tauri.contains("unlock_wallet_owner_manual"));
|
||||
assert!(tauri.contains("unlock_wallet_view_configured"));
|
||||
assert!(tauri.contains("unlock_wallet_owner_configured"));
|
||||
assert!(html.contains("id=\"unlockViewManual\""));
|
||||
assert!(html.contains("id=\"unlockOwnerManual\""));
|
||||
assert!(html.contains("id=\"unlockViewConfigured\""));
|
||||
assert!(html.contains("id=\"unlockOwnerConfigured\""));
|
||||
assert!(main.contains("beginFrontendUnlock"));
|
||||
assert!(main.contains("configuredSecretCandidateCount"));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-app-wallet-desk/tests/desktop_security.rs
|
||||
// version: 4
|
||||
// version: 5
|
||||
|
||||
//! Static desktop security contracts for the Wallet Desk pre.002 shell.
|
||||
|
||||
@@ -66,3 +66,37 @@ fn create_passwords_are_request_only_and_protected_projection_is_purged() {
|
||||
assert!(!main.contains("frontendDebug(\"main\", request.ownerPassword"));
|
||||
assert!(!main.contains("frontendTrace(\"main\", request.viewPassword"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unlock_passwords_and_config_secret_names_never_cross_rust_to_frontend() {
|
||||
let root = app_root();
|
||||
let session = read_text(root.join("src/wallet_session.rs").as_path());
|
||||
let main = read_text(root.join("frontend/ts/main.ts").as_path());
|
||||
let html = read_text(root.join("frontend/main.html").as_path());
|
||||
let authorized = session.split("pub(crate) struct WalletAuthorizedDto").nth(1);
|
||||
assert!(authorized.is_some());
|
||||
let authorized = authorized.unwrap_or_default().split("}\n\n/// Create request").next().unwrap_or_default();
|
||||
assert!(!authorized.contains("password"));
|
||||
let unlock_request = session.find("pub(crate) struct WalletUnlockRequestDto");
|
||||
assert!(unlock_request.is_some());
|
||||
assert!(session[unlock_request.unwrap_or_default()..].contains("password: String"));
|
||||
assert!(main.contains("clearUnlockSensitiveInputs"));
|
||||
assert!(!main.contains("KSP_SECRET_WALLET_PASS_"));
|
||||
assert!(!html.contains("KSP_SECRET_WALLET_PASS_"));
|
||||
assert!(!main.contains("variableName"));
|
||||
assert!(!main.contains("effectiveSource"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wallet_selection_does_not_auto_unlock_configured_secrets() {
|
||||
let root = app_root();
|
||||
let main = read_text(root.join("frontend/ts/main.ts").as_path());
|
||||
let selection_start = main.find("async function selectWallet");
|
||||
let selection_end = main.find("function bindWalletTableSelection");
|
||||
assert!(selection_start.is_some());
|
||||
assert!(selection_end.is_some());
|
||||
let selection = &main[selection_start.unwrap_or_default()..selection_end.unwrap_or(main.len())];
|
||||
assert!(selection.contains("select_wallet"));
|
||||
assert!(!selection.contains("unlock_wallet_view_configured"));
|
||||
assert!(!selection.contains("unlock_wallet_owner_configured"));
|
||||
}
|
||||
|
||||
34
crates/ksp-app-wallet-desk/unit_tests/wallet_secrets.rs
Normal file
34
crates/ksp-app-wallet-desk/unit_tests/wallet_secrets.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
// file: crates/ksp-app-wallet-desk/unit_tests/wallet_secrets.rs
|
||||
// version: 1
|
||||
|
||||
#[test]
|
||||
fn filename_secret_label_normalization_is_deterministic_and_never_uses_internal_alias() {
|
||||
assert_eq!(super::normalize_wallet_secret_label("wallet-01.kspwallet"), "WALLET_01");
|
||||
assert_eq!(super::normalize_wallet_secret_label(" treasury.main .kspwallet"), "TREASURY_MAIN");
|
||||
assert_eq!(super::normalize_wallet_secret_label("a___b...c.kspwallet"), "A_B_C");
|
||||
assert_eq!(super::normalize_wallet_secret_label(".kspwallet"), "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn candidate_order_prefers_filename_then_numeric_then_named_labels() {
|
||||
let mut names = vec![
|
||||
format!("{}TREASURY", super::WALLET_SECRET_PREFIX),
|
||||
format!("{}10", super::WALLET_SECRET_PREFIX),
|
||||
format!("{}WALLET_01", super::WALLET_SECRET_PREFIX),
|
||||
format!("{}02", super::WALLET_SECRET_PREFIX),
|
||||
format!("{}01", super::WALLET_SECRET_PREFIX),
|
||||
format!("{}ALPHA", super::WALLET_SECRET_PREFIX),
|
||||
];
|
||||
super::order_wallet_secret_candidate_names("wallet-01.kspwallet", names.as_mut_slice());
|
||||
assert_eq!(
|
||||
names,
|
||||
vec![
|
||||
format!("{}WALLET_01", super::WALLET_SECRET_PREFIX),
|
||||
format!("{}01", super::WALLET_SECRET_PREFIX),
|
||||
format!("{}02", super::WALLET_SECRET_PREFIX),
|
||||
format!("{}10", super::WALLET_SECRET_PREFIX),
|
||||
format!("{}ALPHA", super::WALLET_SECRET_PREFIX),
|
||||
format!("{}TREASURY", super::WALLET_SECRET_PREFIX),
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
// file: crates/ksp-app-wallet-desk/unit_tests/wallet_session.rs
|
||||
// version: 1
|
||||
// version: 2
|
||||
|
||||
//! Unit tests for Wallet Desk session DTOs and OWNER projection.
|
||||
//! Unit tests for Wallet Desk session DTOs and password request boundaries.
|
||||
|
||||
#[test]
|
||||
fn no_selection_projection_contains_no_wallet_identity() {
|
||||
@@ -24,3 +24,16 @@ fn create_request_does_not_require_debug_or_clone_password_contracts() {
|
||||
};
|
||||
accepts_request(request);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unlock_request_does_not_require_debug_or_clone_password_contracts() {
|
||||
fn accepts_request(_: crate::WalletUnlockRequestDto) {}
|
||||
let request = crate::WalletUnlockRequestDto { password: "operator-test-unlock".to_owned() };
|
||||
accepts_request(request);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn session_state_contract_includes_view_owner_and_privileged_operation() {
|
||||
assert_ne!(crate::WalletSessionStateDto::ViewOpen, crate::WalletSessionStateDto::OwnerOpen);
|
||||
assert_ne!(crate::WalletSessionStateDto::PrivilegedOperation, crate::WalletSessionStateDto::Locked);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user