v0.2.6-pre.012

This commit is contained in:
2026-08-21 16:22:16 +02:00
parent 8ba554306a
commit ecbd6b746d
21 changed files with 634 additions and 94 deletions

View File

@@ -1,65 +1,18 @@
// file: crates/ksp-app-wallet-desk/src/wallet_import.rs
// version: 2
// version: 3
//! Native-picker transfer import staging with bounded secret material kept only in Rust.
use tokio::io::AsyncReadExt; // rust-rules: trait-import
use ts_rs::TS; // rust-rules: trait-import
/// Transfer format selected before opening the native import picker.
#[derive(Clone, Copy, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize, TS)]
#[serde(rename_all = "snake_case")]
#[ts(export, export_to = "../frontend/ts/bindings/ksp_app_wallet_desk/wallet_import/WalletTransferFormatDto.ts")]
pub(crate) enum WalletTransferFormatDto {
/// Standard Solana CLI keypair JSON array containing 64 byte values.
SolanaCliJson,
/// Canonical Base58 encoding of the complete 64-byte Solana keypair.
SolanaKeypairBase58,
}
impl WalletTransferFormatDto {
/// Maps the desktop DTO to the stable Wallet transfer format.
#[must_use]
pub(crate) const fn wallet_format(self) -> ksp_wallet_lib::WalletTransferFormat {
return match self {
Self::SolanaCliJson => ksp_wallet_lib::WalletTransferFormat::SolanaCliJson,
Self::SolanaKeypairBase58 => ksp_wallet_lib::WalletTransferFormat::SolanaKeypairBase58,
};
}
/// Returns the native picker extension used as a convenience filter.
#[must_use]
pub(crate) const fn default_extension(self) -> &'static str {
return match self {
Self::SolanaCliJson => "json",
Self::SolanaKeypairBase58 => "txt",
};
}
/// Returns the stable transfer format code used by safe diagnostics.
#[must_use]
pub(crate) const fn code(self) -> &'static str {
return match self {
Self::SolanaCliJson => "solana_cli_json",
Self::SolanaKeypairBase58 => "solana_keypair_base58",
};
}
const fn maximum_source_bytes(self) -> usize {
return match self {
Self::SolanaCliJson => ksp_wallet_lib::KSPWALLET_TRANSFER_MAX_SOLANA_CLI_JSON_BYTES,
Self::SolanaKeypairBase58 => ksp_wallet_lib::KSPWALLET_TRANSFER_MAX_BASE58_BYTES,
};
}
}
/// Request that chooses only the transfer format; the source path comes from the native Rust picker.
#[derive(serde::Deserialize, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export, export_to = "../frontend/ts/bindings/ksp_app_wallet_desk/wallet_import/WalletImportSourceRequestDto.ts")]
pub(crate) struct WalletImportSourceRequestDto {
/// Transfer encoding expected for the selected external file.
pub(crate) format: WalletTransferFormatDto,
pub(crate) format: crate::WalletTransferFormatDto,
}
/// Safe projection returned after validating one native-picker import source.
@@ -68,7 +21,7 @@ pub(crate) struct WalletImportSourceRequestDto {
#[ts(export, export_to = "../frontend/ts/bindings/ksp_app_wallet_desk/wallet_import/WalletTransferInspectionDto.ts")]
pub(crate) struct WalletTransferInspectionDto {
/// Transfer format used to validate the secret source.
pub(crate) format: WalletTransferFormatDto,
pub(crate) format: crate::WalletTransferFormatDto,
/// Public identity derived from the imported keypair.
pub(crate) pubkey: String,
/// Basename only; no parent path is ever projected.
@@ -95,7 +48,7 @@ pub(crate) struct WalletImportRequestDto {
/// Rust-only staged transfer source. Secret bytes are bounded and zeroized on drop.
pub(crate) struct PendingWalletImport {
bytes: zeroize::Zeroizing<std::vec::Vec<u8>>,
format: WalletTransferFormatDto,
format: crate::WalletTransferFormatDto,
inspection: WalletTransferInspectionDto,
}
@@ -120,7 +73,10 @@ impl PendingWalletImport {
}
/// Reads, bounds and validates one native-picker transfer source while retaining no external path.
pub(crate) async fn stage_wallet_import_source(source: std::path::PathBuf, format: WalletTransferFormatDto) -> ksp_core_lib::Result<PendingWalletImport> {
pub(crate) async fn stage_wallet_import_source(
source: std::path::PathBuf,
format: crate::WalletTransferFormatDto,
) -> ksp_core_lib::Result<PendingWalletImport> {
let metadata = tokio::fs::symlink_metadata(source.as_path()).await;
let metadata = match metadata {
std::result::Result::Ok(value) => value,