solana_zk_token_sdk/zk_token_elgamal/pod/
pedersen.rs#[cfg(not(target_os = "solana"))]
use {
crate::encryption::{elgamal::ElGamalError, pedersen as decoded},
curve25519_dalek::ristretto::CompressedRistretto,
};
use {
crate::{
zk_token_elgamal::pod::{Pod, Zeroable},
RISTRETTO_POINT_LEN,
},
std::fmt,
};
pub(crate) const PEDERSEN_COMMITMENT_LEN: usize = RISTRETTO_POINT_LEN;
#[derive(Clone, Copy, Default, Pod, Zeroable, PartialEq, Eq)]
#[repr(transparent)]
pub struct PedersenCommitment(pub [u8; PEDERSEN_COMMITMENT_LEN]);
impl fmt::Debug for PedersenCommitment {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self.0)
}
}
#[cfg(not(target_os = "solana"))]
impl From<decoded::PedersenCommitment> for PedersenCommitment {
fn from(decoded_commitment: decoded::PedersenCommitment) -> Self {
Self(decoded_commitment.to_bytes())
}
}
#[cfg(not(target_os = "solana"))]
impl From<PedersenCommitment> for CompressedRistretto {
fn from(pod_commitment: PedersenCommitment) -> Self {
Self(pod_commitment.0)
}
}
#[cfg(not(target_os = "solana"))]
impl TryFrom<PedersenCommitment> for decoded::PedersenCommitment {
type Error = ElGamalError;
fn try_from(pod_commitment: PedersenCommitment) -> Result<Self, Self::Error> {
Self::from_bytes(&pod_commitment.0).ok_or(ElGamalError::CiphertextDeserialization)
}
}