v0.2.6-pre.009

This commit is contained in:
2026-08-21 12:35:01 +02:00
parent 7d03825ec6
commit 2b7afab663
17 changed files with 970 additions and 41 deletions

View File

@@ -252,6 +252,40 @@
<div id="balanceStatus" class="alert alert-secondary mb-0" role="status">Unlock VIEW ou OWNER pour interroger getBalance.</div>
</div>
</div>
<div class="card shadow-sm mt-3">
<div class="card-header fw-semibold">Administration metadata OWNER</div>
<div class="card-body">
<p class="text-body-secondary">Alias et notes sont protégés dans le wallet. Les contrôles restent désactivés tant quune session OWNER nest pas ouverte.</p>
<div class="row g-3">
<div class="col-lg-6">
<label class="form-label" for="ownerWalletAlias">Alias interne</label>
<div class="input-group">
<input id="ownerWalletAlias" class="form-control" type="text" autocomplete="off" data-owner-metadata-control disabled>
<button id="saveOwnerAlias" class="btn btn-outline-primary" type="button" data-owner-metadata-control disabled>Save</button>
<button id="clearOwnerAlias" class="btn btn-outline-secondary" type="button" data-owner-metadata-control disabled>Clear</button>
</div>
<div class="form-text">Limite V1 : 256 octets UTF-8. La validation autoritative reste dans ksp-wallet-lib.</div>
</div>
<div class="col-lg-6">
<label class="form-label" for="ownerNewNote">Nouvelle note</label>
<div class="input-group">
<textarea id="ownerNewNote" class="form-control" rows="2" autocomplete="off" data-owner-metadata-control disabled></textarea>
<button id="addOwnerNote" class="btn btn-outline-primary" type="button" data-owner-metadata-control disabled>Add note</button>
</div>
</div>
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-2">
<span class="fw-semibold">Notes autorisées</span>
<small class="text-body-secondary">64 notes maximum en V1</small>
</div>
<div id="ownerNotesList" class="vstack gap-2"><span class="text-body-secondary">Ouvrir OWNER pour administrer les notes.</span></div>
</div>
<div class="col-12">
<div id="ownerMetadataStatus" class="alert alert-secondary mb-0" role="status">Session OWNER requise.</div>
</div>
</div>
</div>
</div>
</section>
<section data-view-panel="security" hidden>
<div class="row g-3">
@@ -310,8 +344,23 @@
</section>
</div>
</main>
<div class="modal fade" id="deleteWalletNoteModal" tabindex="-1" aria-labelledby="deleteWalletNoteModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h2 class="modal-title fs-5" id="deleteWalletNoteModalLabel">Supprimer la note protégée ?</h2>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">Cette mutation OWNER est définitive pour la note sélectionnée. Le contenu protégé nest pas recopié dans la confirmation.</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button id="confirmDeleteWalletNote" type="button" class="btn btn-danger">Delete note</button>
</div>
</div>
</div>
</div>
<footer class="app-footer bg-dark text-white-50 d-flex align-items-center px-4">
<span>KSP Wallet Desk · native transfer import pre.008</span>
<span>KSP Wallet Desk · OWNER metadata pre.009</span>
</footer>
<script type="module" src="./ts/main.ts"></script>
</body>

View File

@@ -1,13 +1,14 @@
// file: crates/ksp-app-wallet-desk/frontend/ts/main.ts
// version: 8
// version: 9
import "bootstrap";
import { Modal } from "bootstrap";
import DataTable from "datatables.net-bs5";
import "datatables.net-select-bs5";
import ResizeObserver from "resize-observer-polyfill";
import "simplebar";
import { getCurrentWindow } from "@tauri-apps/api/window";
import type { WalletBalanceDto } from "./bindings/ksp_app_wallet_desk/wallet_balance/WalletBalanceDto.ts";
import type { CommandErrorDto } from "./bindings/ksp_app_wallet_desk/dto_common/CommandErrorDto.ts";
import type { RuntimeStatusDto } from "./bindings/ksp_app_wallet_desk/dto_common/RuntimeStatusDto.ts";
import type { WalletImportRequestDto } from "./bindings/ksp_app_wallet_desk/wallet_import/WalletImportRequestDto.ts";
import type { WalletImportSourceRequestDto } from "./bindings/ksp_app_wallet_desk/wallet_import/WalletImportSourceRequestDto.ts";
@@ -16,6 +17,10 @@ import type { WalletTransferInspectionDto } from "./bindings/ksp_app_wallet_desk
import type { LockedWalletDto } from "./bindings/ksp_app_wallet_desk/wallet_inventory/LockedWalletDto.ts";
import type { WalletInventoryEntryDto } from "./bindings/ksp_app_wallet_desk/wallet_inventory/WalletInventoryEntryDto.ts";
import type { WalletSelectionRequestDto } from "./bindings/ksp_app_wallet_desk/wallet_inventory/WalletSelectionRequestDto.ts";
import type { WalletAliasUpdateRequestDto } from "./bindings/ksp_app_wallet_desk/wallet_metadata/WalletAliasUpdateRequestDto.ts";
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 { 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";
@@ -43,7 +48,10 @@ const viewTitles: Record<ViewId, string> = {
let activeWalletId: string | null = null;
let activeSessionState: ActiveSessionState = "no_selection";
let activeViewEnabled = false;
let authorizedWalletProjection: WalletAuthorizedDto | null = null;
let configuredSecretCandidateCount = 0;
let deleteNoteModal: Modal | null = null;
let pendingDeleteNoteId: string | null = null;
let stagedImportSource: WalletTransferInspectionDto | null = null;
function isViewId(value: string): value is ViewId {
@@ -212,6 +220,14 @@ function updateSessionActions(): void {
refreshBalance.disabled = activeSessionState !== "view_open" && activeSessionState !== "owner_open";
}
updateUnlockActions();
updateOwnerMetadataActions();
}
function updateOwnerMetadataActions(): void {
const ownerOpen = activeSessionState === "owner_open";
document.querySelectorAll<HTMLInputElement | HTMLTextAreaElement | HTMLButtonElement>("[data-owner-metadata-control]").forEach(control => {
control.disabled = !ownerOpen;
});
}
function updateUnlockActions(): void {
@@ -314,6 +330,8 @@ function clearBalanceProjection(): void {
}
function clearAuthorizedProjection(): void {
authorizedWalletProjection = null;
clearOwnerMetadataProjection();
setText("#currentWalletPubkey", "—");
setText("#currentWalletAlias", "—");
setText("#currentWalletNotes", "—");
@@ -371,6 +389,7 @@ function renderLockedWallet(wallet: LockedWalletDto): void {
function renderAuthorizedWallet(wallet: WalletAuthorizedDto): void {
activeWalletId = wallet.walletId;
authorizedWalletProjection = wallet;
activeSessionState = wallet.capability === "view" ? "view_open" : "owner_open";
activeViewEnabled = wallet.viewEnabled;
configuredSecretCandidateCount = wallet.configuredSecretCandidateCount;
@@ -392,6 +411,7 @@ function renderAuthorizedWallet(wallet: WalletAuthorizedDto): void {
setText("#detailsWalletPubkey", wallet.pubkey);
setText("#detailsWalletAlias", wallet.alias ?? "—");
setText("#detailsWalletNotes", notesText);
renderOwnerMetadataProjection(wallet);
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é.`);
@@ -405,6 +425,195 @@ function renderAuthorizedWallet(wallet: WalletAuthorizedDto): void {
});
}
function clearOwnerMetadataProjection(): void {
pendingDeleteNoteId = null;
const alias = document.querySelector<HTMLInputElement>("#ownerWalletAlias");
const newNote = document.querySelector<HTMLTextAreaElement>("#ownerNewNote");
const list = document.querySelector<HTMLElement>("#ownerNotesList");
if (alias) {
alias.value = "";
}
if (newNote) {
newNote.value = "";
}
if (list) {
const empty = document.createElement("span");
empty.className = "text-body-secondary";
empty.textContent = "Ouvrir OWNER pour administrer les notes.";
list.replaceChildren(empty);
}
setText("#ownerMetadataStatus", "Session OWNER requise.");
}
function renderOwnerMetadataProjection(wallet: WalletAuthorizedDto): void {
const alias = document.querySelector<HTMLInputElement>("#ownerWalletAlias");
const list = document.querySelector<HTMLElement>("#ownerNotesList");
if (alias) {
alias.value = wallet.alias ?? "";
}
if (list) {
if (wallet.notes.length === 0) {
const empty = document.createElement("span");
empty.className = "text-body-secondary";
empty.textContent = wallet.capability === "owner" ? "Aucune note protégée." : "Les notes sont visibles en VIEW mais modifiables uniquement en OWNER.";
list.replaceChildren(empty);
} else {
const rows = wallet.notes.map(note => {
const row = document.createElement("div");
row.className = "border rounded p-2";
const textarea = document.createElement("textarea");
textarea.className = "form-control mb-2";
textarea.rows = 2;
textarea.value = note.text;
textarea.disabled = wallet.capability !== "owner";
textarea.autocomplete = "off";
textarea.dataset.ownerMetadataControl = "true";
const actions = document.createElement("div");
actions.className = "d-flex gap-2 justify-content-end";
const save = document.createElement("button");
save.className = "btn btn-outline-primary btn-sm";
save.type = "button";
save.textContent = "Save note";
save.disabled = wallet.capability !== "owner";
save.dataset.ownerMetadataControl = "true";
save.addEventListener("click", () => {
const request: WalletNoteUpdateRequestDto = { noteId: note.id, text: textarea.value };
void runOwnerMetadataMutation("update_wallet_note", { request }, "Mise à jour de la note…", "Note mise à jour.");
});
const remove = document.createElement("button");
remove.className = "btn btn-outline-danger btn-sm";
remove.type = "button";
remove.textContent = "Delete";
remove.disabled = wallet.capability !== "owner";
remove.dataset.ownerMetadataControl = "true";
remove.addEventListener("click", () => {
pendingDeleteNoteId = note.id;
deleteNoteModal?.show();
frontendDebug("main", "OWNER note delete confirmation opened", { walletId: wallet.walletId });
});
actions.append(save, remove);
row.append(textarea, actions);
return row;
});
list.replaceChildren(...rows);
}
}
setText("#ownerMetadataStatus", wallet.capability === "owner" ? "OWNER ouvert : metadata modifiable." : "VIEW ouvert : metadata en lecture seule.");
updateOwnerMetadataActions();
}
function isWalletStateConflict(caughtError: unknown): boolean {
if (typeof caughtError !== "object" || caughtError === null) {
return false;
}
const error = caughtError as Partial<CommandErrorDto>;
return error.domain === "wallet" && error.code === "state_conflict";
}
async function recoverOwnerMetadataStateConflict(walletId: string): Promise<void> {
clearAuthorizedProjection();
clearBalanceProjection();
const request: WalletSelectionRequestDto = { walletId };
try {
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("#unlockStatus", "Conflit détat détecté : wallet réinspecté et reverrouillé. Réautoriser OWNER explicitement.");
await loadWalletInventory("list_wallets", false);
activateView("security", "user");
frontendWarn("main", "Wallet state conflict forced OWNER reauthorization", { walletId });
} catch {
clearSelectedWallet();
setText("#ownerMetadataStatus", "Conflit détat détecté et réinspection impossible. Resélectionner le wallet depuis linventaire.");
frontendWarn("main", "Wallet state conflict recovery failed", { walletId });
}
}
async function runOwnerMetadataMutation(
command: "add_wallet_note" | "delete_wallet_note" | "update_wallet_alias" | "update_wallet_note",
args: Record<string, unknown>,
pendingMessage: string,
successMessage: string,
): Promise<boolean> {
if (activeSessionState !== "owner_open" || !activeWalletId || authorizedWalletProjection?.capability !== "owner") {
setText("#ownerMetadataStatus", "Session OWNER requise.");
return false;
}
const walletId = activeWalletId;
activeSessionState = "privileged_operation";
setText("#currentWalletState", "OWNER mutation…");
setText("#ownerMetadataStatus", pendingMessage);
updateSessionActions();
frontendDebug("main", "OWNER metadata mutation requested", { command, walletId });
try {
const wallet = await invokeKsp<WalletAuthorizedDto>("main", command, args);
if (activeWalletId !== walletId) {
frontendWarn("main", "Stale OWNER metadata response ignored", { command, walletId });
return false;
}
renderAuthorizedWallet(wallet);
setText("#ownerMetadataStatus", successMessage);
await loadWalletInventory("list_wallets", false);
return true;
} catch (caughtError) {
if (isWalletStateConflict(caughtError)) {
await recoverOwnerMetadataStateConflict(walletId);
return false;
}
if (activeWalletId === walletId) {
activeSessionState = "owner_open";
setText("#currentWalletState", "OWNER open");
setText("#ownerMetadataStatus", "Mutation refusée ; la session OWNER reste ouverte.");
updateSessionActions();
}
frontendWarn("main", "OWNER metadata mutation failed", { command, walletId });
return false;
}
}
function bindOwnerMetadataActions(): void {
const modalElement = document.querySelector<HTMLElement>("#deleteWalletNoteModal");
if (modalElement) {
deleteNoteModal = new Modal(modalElement);
}
document.querySelector<HTMLButtonElement>("#saveOwnerAlias")?.addEventListener("click", () => {
const alias = document.querySelector<HTMLInputElement>("#ownerWalletAlias");
if (!alias) {
return;
}
const request: WalletAliasUpdateRequestDto = { alias: alias.value.length === 0 ? null : alias.value };
void runOwnerMetadataMutation("update_wallet_alias", { request }, "Mise à jour de lalias…", "Alias mis à jour.");
});
document.querySelector<HTMLButtonElement>("#clearOwnerAlias")?.addEventListener("click", () => {
const request: WalletAliasUpdateRequestDto = { alias: null };
void runOwnerMetadataMutation("update_wallet_alias", { request }, "Suppression de lalias…", "Alias supprimé.");
});
document.querySelector<HTMLButtonElement>("#addOwnerNote")?.addEventListener("click", () => {
const text = document.querySelector<HTMLTextAreaElement>("#ownerNewNote");
if (!text || text.value.length === 0) {
setText("#ownerMetadataStatus", "Texte de note requis.");
return;
}
const request: WalletNoteAddRequestDto = { text: text.value };
void runOwnerMetadataMutation("add_wallet_note", { request }, "Ajout de la note…", "Note ajoutée.").then(succeeded => {
if (succeeded && activeSessionState === "owner_open") {
text.value = "";
}
});
});
document.querySelector<HTMLButtonElement>("#confirmDeleteWalletNote")?.addEventListener("click", () => {
const noteId = pendingDeleteNoteId;
pendingDeleteNoteId = null;
deleteNoteModal?.hide();
if (!noteId) {
return;
}
const request: WalletNoteDeleteRequestDto = { noteId };
void runOwnerMetadataMutation("delete_wallet_note", { request }, "Suppression de la note…", "Note supprimée.");
});
frontendTrace("main", "OWNER metadata action handlers installed");
}
async function selectWallet(walletId: string): Promise<void> {
clearSelectedWallet();
const request: WalletSelectionRequestDto = { walletId };
@@ -824,7 +1033,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 natif, VIEW/OWNER et getBalance prêts.");
setText("#shellStatus", "Config/Transport résolus ; import, VIEW/OWNER, metadata OWNER et getBalance prêts.");
frontendTrace("main", "Wallet Desk runtime status rendered", {
compositeProfile: status.activeCompositeProfile,
fallbackLoggingActive: status.fallbackLoggingActive,
@@ -875,6 +1084,7 @@ async function initializeMain(): Promise<void> {
bindImportWalletForm();
bindUnlockActions();
bindBalanceActions();
bindOwnerMetadataActions();
bindShellActions();
clearSelectedWallet();
activateView("dashboard", "startup");