use thiserror::Error;
pub const PROTOCOL_VERSION: u8 = 0x01;
pub const PROTOCOL_ID: u8 = 0x01;
pub const HEADER_SIZE: usize = 126;
pub const TAG_SIZE: usize = 16;
pub const ENCRYPTED_SENDER_KEY_SIZE: usize = 48;
pub const MAX_PAYLOAD_SIZE: usize = 882;
pub const NONCE_SIZE: usize = 12;
pub const PUBLIC_KEY_SIZE: usize = 32;
pub const KEY_DERIVATION_SALT: &[u8] = b"AlgoChat-v1-encryption";
pub const KEY_DERIVATION_INFO: &[u8] = b"x25519-key";
pub const ENCRYPTION_INFO_PREFIX: &[u8] = b"AlgoChatV1";
pub const SENDER_KEY_INFO_PREFIX: &[u8] = b"AlgoChatV1-SenderKey";
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DecryptedContent {
pub text: String,
pub reply_to_id: Option<String>,
pub reply_to_preview: Option<String>,
}
impl DecryptedContent {
pub fn new(text: impl Into<String>) -> Self {
Self {
text: text.into(),
reply_to_id: None,
reply_to_preview: None,
}
}
}
#[derive(Error, Debug)]
pub enum AlgoChatError {
#[error("Invalid seed length: expected 32 bytes, got {0}")]
InvalidSeedLength(usize),
#[error("Message too large: {0} bytes (max {MAX_PAYLOAD_SIZE})")]
MessageTooLarge(usize),
#[error("Encryption failed: {0}")]
EncryptionError(String),
#[error("Decryption failed: {0}")]
DecryptionError(String),
#[error("Encoding failed: {0}")]
EncodingError(String),
#[error("Random generation failed")]
RandomGenerationFailed,
#[error("Invalid public key: {0}")]
InvalidPublicKey(String),
#[error("Key derivation failed: {0}")]
KeyDerivationFailed(String),
#[error("Invalid signature: {0}")]
InvalidSignature(String),
#[error("Invalid envelope: {0}")]
InvalidEnvelope(String),
#[error("Unknown protocol version: {0}")]
UnknownVersion(u8),
#[error("Unknown protocol ID: {0}")]
UnknownProtocolId(u8),
#[error("Indexer not configured")]
IndexerNotConfigured,
#[error("Public key not found for address: {0}")]
PublicKeyNotFound(String),
#[error("Invalid recipient: {0}")]
InvalidRecipient(String),
#[error("Transaction failed: {0}")]
TransactionFailed(String),
#[error("Insufficient balance: need {required} microAlgos, have {available}")]
InsufficientBalance { required: u64, available: u64 },
#[error("Key not found for address: {0}")]
KeyNotFound(String),
#[error("Storage failed: {0}")]
StorageFailed(String),
#[error("Message not found: {0}")]
MessageNotFound(String),
}
pub type Result<T> = std::result::Result<T, AlgoChatError>;
pub const SIGNATURE_SIZE: usize = 64;
pub const MINIMUM_PAYMENT: u64 = 1000;