v0.2.6-pre.012
This commit is contained in:
59
crates/ksp-app-wallet-desk/src/wallet_transfer.rs
Normal file
59
crates/ksp-app-wallet-desk/src/wallet_transfer.rs
Normal file
@@ -0,0 +1,59 @@
|
||||
// file: crates/ksp-app-wallet-desk/src/wallet_transfer.rs
|
||||
// version: 1
|
||||
|
||||
//! Shared Wallet Desk transfer format contract used by import and OWNER export workflows.
|
||||
|
||||
use ts_rs::TS; // rust-rules: trait-import
|
||||
|
||||
/// Explicit Solana keypair transfer format selected by Wallet Desk.
|
||||
#[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_transfer/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/save 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",
|
||||
};
|
||||
}
|
||||
|
||||
/// Returns the maximum accepted import source size for this transfer encoding.
|
||||
#[must_use]
|
||||
pub(crate) 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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../unit_tests/wallet_transfer.rs"]
|
||||
mod tests;
|
||||
Reference in New Issue
Block a user