Files
khadhroony-bot3/ks-wallet/src/constants.rs
2026-08-10 16:43:19 +02:00

69 lines
3.4 KiB
Rust

// file: ks-wallet/src/constants.rs
// version: 6
//! Local constants for the `ks-wallet` crate.
/// Canonical tracing target for this crate.
pub(crate) const TRACING_TARGET: &str = "ks-wallet";
/// Native wallet file extension without the leading dot.
pub const KSWALLET_FILE_EXTENSION: &str = "kswallet";
/// Native wallet format identification magic.
pub(crate) const KSWALLET_MAGIC: &[u8; 8] = b"KSWALLET";
/// Native wallet format version.
pub(crate) const KSWALLET_FORMAT_VERSION: u16 = 1;
/// Fixed version-one header length before the variable alias bytes.
pub(crate) const KSWALLET_FIXED_HEADER_LENGTH: usize = 72;
/// Maximum wallet alias length encoded by version one.
pub(crate) const KSWALLET_MAX_ALIAS_LENGTH: usize = 64;
/// Native version-one flag value when no optional feature is enabled.
pub(crate) const KSWALLET_FLAGS_NONE: u16 = 0;
/// Version-one KDF identifier for Argon2id.
pub(crate) const KSWALLET_KDF_ARGON2ID: u8 = 1;
/// Argon2 version 19 identifier required by version one.
pub(crate) const KSWALLET_ARGON2_VERSION: u8 = 0x13;
/// Version-one AEAD identifier for XChaCha20-Poly1305.
pub(crate) const KSWALLET_AEAD_XCHACHA20_POLY1305: u8 = 1;
/// Salt length used by the version-one Argon2id profile.
pub(crate) const KSWALLET_SALT_LENGTH: usize = 16;
/// Nonce length used by XChaCha20-Poly1305.
pub(crate) const KSWALLET_NONCE_LENGTH: usize = 24;
/// Encryption-key length required by XChaCha20-Poly1305.
pub(crate) const KSWALLET_AEAD_KEY_LENGTH: usize = 32;
/// Authentication tag length appended by XChaCha20-Poly1305.
const KSWALLET_AEAD_TAG_LENGTH: usize = 16;
/// Default Argon2id memory cost in KiB used for new native wallets.
pub(crate) const KSWALLET_ARGON2_DEFAULT_MEMORY_KIB: u32 = 65_536;
/// Default Argon2id pass count used for new native wallets.
pub(crate) const KSWALLET_ARGON2_DEFAULT_ITERATIONS: u32 = 3;
/// Default Argon2id lane count used for new native wallets.
pub(crate) const KSWALLET_ARGON2_DEFAULT_PARALLELISM: u32 = 4;
/// Minimum accepted Argon2id memory cost in KiB.
pub(crate) const KSWALLET_ARGON2_MIN_MEMORY_KIB: u32 = 65_536;
/// Maximum accepted Argon2id memory cost in KiB.
pub(crate) const KSWALLET_ARGON2_MAX_MEMORY_KIB: u32 = 262_144;
/// Minimum accepted Argon2id pass count.
pub(crate) const KSWALLET_ARGON2_MIN_ITERATIONS: u32 = 3;
/// Maximum accepted Argon2id pass count.
pub(crate) const KSWALLET_ARGON2_MAX_ITERATIONS: u32 = 10;
/// Minimum accepted Argon2id lane count.
pub(crate) const KSWALLET_ARGON2_MIN_PARALLELISM: u32 = 1;
/// Maximum accepted Argon2id lane count.
pub(crate) const KSWALLET_ARGON2_MAX_PARALLELISM: u32 = 8;
/// Number of bytes stored by the standard Solana keypair JSON format.
pub(crate) const SOLANA_KEYPAIR_LENGTH: usize = 64;
/// Exact ciphertext length for one 64-byte keypair plus the AEAD tag.
pub(crate) const KSWALLET_CIPHERTEXT_LENGTH: usize =
SOLANA_KEYPAIR_LENGTH + KSWALLET_AEAD_TAG_LENGTH;
/// Minimum complete version-one file length with a one-byte alias.
pub(crate) const KSWALLET_MIN_FILE_LENGTH: usize = KSWALLET_FIXED_HEADER_LENGTH
+ 1
+ KSWALLET_SALT_LENGTH
+ KSWALLET_NONCE_LENGTH
+ KSWALLET_CIPHERTEXT_LENGTH;
/// Maximum complete version-one file length with the longest supported alias.
pub(crate) const KSWALLET_MAX_FILE_LENGTH: usize = KSWALLET_FIXED_HEADER_LENGTH
+ KSWALLET_MAX_ALIAS_LENGTH
+ KSWALLET_SALT_LENGTH
+ KSWALLET_NONCE_LENGTH
+ KSWALLET_CIPHERTEXT_LENGTH;