v0.2.6-pre.010
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-app-wallet-desk/frontend/ts/main.ts
|
||||
// version: 9
|
||||
// version: 10
|
||||
|
||||
import { Modal } from "bootstrap";
|
||||
import DataTable from "datatables.net-bs5";
|
||||
@@ -21,6 +21,7 @@ import type { WalletAliasUpdateRequestDto } from "./bindings/ksp_app_wallet_desk
|
||||
import type { WalletNoteAddRequestDto } from "./bindings/ksp_app_wallet_desk/wallet_metadata/WalletNoteAddRequestDto.ts";
|
||||
import type { WalletNoteDeleteRequestDto } from "./bindings/ksp_app_wallet_desk/wallet_metadata/WalletNoteDeleteRequestDto.ts";
|
||||
import type { WalletNoteUpdateRequestDto } from "./bindings/ksp_app_wallet_desk/wallet_metadata/WalletNoteUpdateRequestDto.ts";
|
||||
import type { WalletPasswordRotationRequestDto } from "./bindings/ksp_app_wallet_desk/wallet_security/WalletPasswordRotationRequestDto.ts";
|
||||
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";
|
||||
@@ -183,7 +184,7 @@ function initializeWalletTable(): void {
|
||||
zeroRecords: "Aucun wallet correspondant.",
|
||||
},
|
||||
});
|
||||
frontendDebug("main", "Wallet inventory DataTable initialized", { phase: "pre.008-wallet-import" });
|
||||
frontendDebug("main", "Wallet inventory DataTable initialized", { phase: "pre.010-credential-rotation" });
|
||||
}
|
||||
|
||||
function renderWalletInventory(entries: WalletInventoryEntryDto[]): void {
|
||||
@@ -221,6 +222,7 @@ function updateSessionActions(): void {
|
||||
}
|
||||
updateUnlockActions();
|
||||
updateOwnerMetadataActions();
|
||||
updateSecurityRotationActions();
|
||||
}
|
||||
|
||||
function updateOwnerMetadataActions(): void {
|
||||
@@ -230,6 +232,17 @@ function updateOwnerMetadataActions(): void {
|
||||
});
|
||||
}
|
||||
|
||||
function updateSecurityRotationActions(): void {
|
||||
const ownerOpen = activeSessionState === "owner_open" && authorizedWalletProjection?.capability === "owner";
|
||||
document.querySelectorAll<HTMLInputElement | HTMLButtonElement>("[data-owner-rotation-control]").forEach(control => {
|
||||
control.disabled = !ownerOpen;
|
||||
});
|
||||
const viewControls = document.querySelectorAll<HTMLInputElement | HTMLButtonElement>("[data-view-rotation-control]");
|
||||
viewControls.forEach(control => {
|
||||
control.disabled = !ownerOpen || !activeViewEnabled;
|
||||
});
|
||||
}
|
||||
|
||||
function updateUnlockActions(): void {
|
||||
const locked = activeSessionState === "locked";
|
||||
const viewManual = document.querySelector<HTMLButtonElement>("#unlockViewManual");
|
||||
@@ -319,6 +332,15 @@ function clearUnlockSensitiveInputs(): void {
|
||||
}
|
||||
}
|
||||
|
||||
function clearRotationSensitiveInputs(): void {
|
||||
for (const selector of ["#rotateOwnerPassword", "#rotateOwnerPasswordConfirm", "#rotateViewPassword", "#rotateViewPasswordConfirm"]) {
|
||||
const input = document.querySelector<HTMLInputElement>(selector);
|
||||
if (input) {
|
||||
input.value = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function clearBalanceProjection(): void {
|
||||
setText("#currentWalletBalanceSol", "—");
|
||||
setText("#detailsBalanceLamports", "—");
|
||||
@@ -340,7 +362,9 @@ function clearAuthorizedProjection(): void {
|
||||
setText("#detailsWalletNotes", "—");
|
||||
clearBalanceProjection();
|
||||
clearCreateFormSensitiveInputs();
|
||||
clearRotationSensitiveInputs();
|
||||
clearUnlockSensitiveInputs();
|
||||
setText("#rotationStatus", "Session OWNER requise.");
|
||||
}
|
||||
|
||||
function clearSelectedWallet(): void {
|
||||
@@ -415,6 +439,12 @@ function renderAuthorizedWallet(wallet: WalletAuthorizedDto): void {
|
||||
clearBalanceProjection();
|
||||
setText("#balanceStatus", "Session autorisée. Refresh balance appelle getBalance avec la Pubkey détenue par Rust.");
|
||||
setText("#unlockStatus", `${capabilityLabel} ouvert. Lock pour purger le handle autorisé.`);
|
||||
setText(
|
||||
"#rotationStatus",
|
||||
wallet.capability === "owner"
|
||||
? "OWNER ouvert. Une rotation modifie le fichier Wallet uniquement ; les secrets Config restent inchangés."
|
||||
: "Session OWNER requise pour effectuer une rotation de credential.",
|
||||
);
|
||||
updateSessionActions();
|
||||
frontendDebug("main", "Authorized Wallet session rendered", {
|
||||
capability: wallet.capability,
|
||||
@@ -510,7 +540,7 @@ function isWalletStateConflict(caughtError: unknown): boolean {
|
||||
return error.domain === "wallet" && error.code === "state_conflict";
|
||||
}
|
||||
|
||||
async function recoverOwnerMetadataStateConflict(walletId: string): Promise<void> {
|
||||
async function recoverOwnerStateConflict(walletId: string): Promise<void> {
|
||||
clearAuthorizedProjection();
|
||||
clearBalanceProjection();
|
||||
const request: WalletSelectionRequestDto = { walletId };
|
||||
@@ -518,6 +548,7 @@ async function recoverOwnerMetadataStateConflict(walletId: string): Promise<void
|
||||
const wallet = await invokeKsp<LockedWalletDto>("main", "select_wallet", { request });
|
||||
renderLockedWallet(wallet);
|
||||
setText("#ownerMetadataStatus", "Le fichier wallet a changé hors de cette session. Le handle OWNER stale a été purgé ; unlock OWNER requis avant toute nouvelle mutation.");
|
||||
setText("#rotationStatus", "Conflit d’état : rotation interrompue, wallet reverrouillé et réautorisation OWNER obligatoire.");
|
||||
setText("#unlockStatus", "Conflit d’état détecté : wallet réinspecté et reverrouillé. Réautoriser OWNER explicitement.");
|
||||
await loadWalletInventory("list_wallets", false);
|
||||
activateView("security", "user");
|
||||
@@ -525,6 +556,7 @@ async function recoverOwnerMetadataStateConflict(walletId: string): Promise<void
|
||||
} catch {
|
||||
clearSelectedWallet();
|
||||
setText("#ownerMetadataStatus", "Conflit d’état détecté et réinspection impossible. Resélectionner le wallet depuis l’inventaire.");
|
||||
setText("#rotationStatus", "Conflit d’état détecté ; la réinspection du wallet a échoué.");
|
||||
frontendWarn("main", "Wallet state conflict recovery failed", { walletId });
|
||||
}
|
||||
}
|
||||
@@ -557,7 +589,7 @@ async function runOwnerMetadataMutation(
|
||||
return true;
|
||||
} catch (caughtError) {
|
||||
if (isWalletStateConflict(caughtError)) {
|
||||
await recoverOwnerMetadataStateConflict(walletId);
|
||||
await recoverOwnerStateConflict(walletId);
|
||||
return false;
|
||||
}
|
||||
if (activeWalletId === walletId) {
|
||||
@@ -930,6 +962,79 @@ async function unlockConfigured(capability: UnlockCapability): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
async function rotateWalletPassword(capability: UnlockCapability): Promise<void> {
|
||||
if (activeSessionState !== "owner_open" || !activeWalletId || authorizedWalletProjection?.capability !== "owner") {
|
||||
clearRotationSensitiveInputs();
|
||||
setText("#rotationStatus", "Session OWNER requise.");
|
||||
return;
|
||||
}
|
||||
if (capability === "view" && !activeViewEnabled) {
|
||||
clearRotationSensitiveInputs();
|
||||
setText("#rotationStatus", "VIEW est désactivé ; aucune rotation VIEW n’est possible.");
|
||||
return;
|
||||
}
|
||||
const passwordSelector = capability === "owner" ? "#rotateOwnerPassword" : "#rotateViewPassword";
|
||||
const confirmationSelector = capability === "owner" ? "#rotateOwnerPasswordConfirm" : "#rotateViewPasswordConfirm";
|
||||
const password = document.querySelector<HTMLInputElement>(passwordSelector);
|
||||
const confirmation = document.querySelector<HTMLInputElement>(confirmationSelector);
|
||||
if (!password || !confirmation || password.value.length === 0) {
|
||||
clearRotationSensitiveInputs();
|
||||
setText("#rotationStatus", "Nouveau password et confirmation requis.");
|
||||
return;
|
||||
}
|
||||
if (password.value !== confirmation.value) {
|
||||
clearRotationSensitiveInputs();
|
||||
setText("#rotationStatus", "La confirmation ne correspond pas au nouveau password.");
|
||||
return;
|
||||
}
|
||||
const walletId = activeWalletId;
|
||||
const request: WalletPasswordRotationRequestDto = { password: password.value };
|
||||
const command = capability === "owner" ? "rotate_owner_password" : "rotate_view_password";
|
||||
activeSessionState = "privileged_operation";
|
||||
setText("#currentWalletState", `Rotation ${capability.toUpperCase()}…`);
|
||||
setText("#rotationStatus", "Rotation Argon2 en cours…");
|
||||
updateSessionActions();
|
||||
frontendDebug("main", "Wallet credential rotation requested", { capability, walletId });
|
||||
try {
|
||||
const wallet = await invokeKsp<WalletAuthorizedDto>("main", command, { request });
|
||||
clearRotationSensitiveInputs();
|
||||
if (activeWalletId !== walletId) {
|
||||
frontendWarn("main", "Stale Wallet credential rotation response ignored", { capability, walletId });
|
||||
return;
|
||||
}
|
||||
renderAuthorizedWallet(wallet);
|
||||
setText(
|
||||
"#rotationStatus",
|
||||
`${capability.toUpperCase()} password rotated. Les secrets Config (${configuredSecretCandidateCount} candidat(s)) ne sont pas modifiés automatiquement.`,
|
||||
);
|
||||
await loadWalletInventory("list_wallets", false);
|
||||
frontendInfo("main", "Wallet credential rotation completed", { capability, walletId });
|
||||
} catch (caughtError) {
|
||||
clearRotationSensitiveInputs();
|
||||
if (isWalletStateConflict(caughtError)) {
|
||||
await recoverOwnerStateConflict(walletId);
|
||||
return;
|
||||
}
|
||||
if (activeWalletId === walletId) {
|
||||
activeSessionState = "owner_open";
|
||||
setText("#currentWalletState", "OWNER open");
|
||||
setText("#rotationStatus", "Rotation refusée ; la session OWNER reste ouverte.");
|
||||
updateSessionActions();
|
||||
}
|
||||
frontendWarn("main", "Wallet credential rotation failed", { capability, walletId });
|
||||
}
|
||||
}
|
||||
|
||||
function bindRotationActions(): void {
|
||||
document.querySelector<HTMLButtonElement>("#rotateOwnerPasswordSubmit")?.addEventListener("click", () => {
|
||||
void rotateWalletPassword("owner");
|
||||
});
|
||||
document.querySelector<HTMLButtonElement>("#rotateViewPasswordSubmit")?.addEventListener("click", () => {
|
||||
void rotateWalletPassword("view");
|
||||
});
|
||||
frontendTrace("main", "Wallet credential rotation handlers installed");
|
||||
}
|
||||
|
||||
function bindUnlockActions(): void {
|
||||
document.querySelector<HTMLButtonElement>("#unlockViewManual")?.addEventListener("click", () => {
|
||||
void unlockManual("view");
|
||||
@@ -1033,7 +1138,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/Transport résolus ; import, VIEW/OWNER, metadata OWNER et getBalance prêts.");
|
||||
setText("#shellStatus", "Config/Transport résolus ; import, VIEW/OWNER, metadata, rotations et getBalance prêts.");
|
||||
frontendTrace("main", "Wallet Desk runtime status rendered", {
|
||||
compositeProfile: status.activeCompositeProfile,
|
||||
fallbackLoggingActive: status.fallbackLoggingActive,
|
||||
@@ -1085,6 +1190,7 @@ async function initializeMain(): Promise<void> {
|
||||
bindUnlockActions();
|
||||
bindBalanceActions();
|
||||
bindOwnerMetadataActions();
|
||||
bindRotationActions();
|
||||
bindShellActions();
|
||||
clearSelectedWallet();
|
||||
activateView("dashboard", "startup");
|
||||
|
||||
Reference in New Issue
Block a user