use x25519_dalek::PublicKey;

use crate::error::{HermesError, Result};

/// Helper struct wrapping an X25519 Public Key retrieved from the AccountProfile pallet.
#[derive(Clone, Debug, PartialEq)]
pub struct EncryptionPubKey(pub Vec<u8>);

impl EncryptionPubKey {
    pub fn as_x25519(&self) -> Result<PublicKey> {
        if self.0.len() != 32 {
            return Err(HermesError::Encryption(format!(
                "Invalid public key length: expected 32, got {}",
                self.0.len()
            )));
        }
        let mut arr = [0u8; 32];
        arr.copy_from_slice(&self.0);
        Ok(PublicKey::from(arr))
    }
}
