diff --git a/curves/curve25519/src/errors.rs b/curves/curve25519/src/errors.rs index 2b43a12145ab42..2aabc732a39006 100644 --- a/curves/curve25519/src/errors.rs +++ b/curves/curve25519/src/errors.rs @@ -5,21 +5,3 @@ pub enum Curve25519Error { #[error("pod conversion failed")] PodConversion, } - -#[derive(Error, Clone, Debug, Eq, PartialEq)] -pub enum ElGamalError { - #[error("key derivation method not supported")] - DerivationMethodNotSupported, - #[error("seed length too short for derivation")] - SeedLengthTooShort, - #[error("seed length too long for derivation")] - SeedLengthTooLong, - #[error("failed to deserialize ciphertext")] - CiphertextDeserialization, - #[error("failed to deserialize public key")] - PubkeyDeserialization, - #[error("failed to deserialize keypair")] - KeypairDeserialization, - #[error("failed to deserialize secret key")] - SecretKeyDeserialization, -} diff --git a/curves/curve25519/src/scalar.rs b/curves/curve25519/src/scalar.rs index 1aa507fa6c741b..eff4547984206f 100644 --- a/curves/curve25519/src/scalar.rs +++ b/curves/curve25519/src/scalar.rs @@ -6,11 +6,7 @@ pub struct PodScalar(pub [u8; 32]); #[cfg(not(target_os = "solana"))] mod target_arch { - use { - super::*, - crate::errors::{Curve25519Error, ElGamalError}, - curve25519_dalek::scalar::Scalar, - }; + use {super::*, crate::errors::Curve25519Error, curve25519_dalek::scalar::Scalar}; impl From<&Scalar> for PodScalar { fn from(scalar: &Scalar) -> Self { @@ -35,7 +31,7 @@ mod target_arch { } impl TryFrom for Scalar { - type Error = ElGamalError; + type Error = Curve25519Error; fn try_from(pod: PodScalar) -> Result { Scalar::from_canonical_bytes(pod.0) diff --git a/zk-token-sdk/src/encryption/elgamal.rs b/zk-token-sdk/src/encryption/elgamal.rs index 7bd5bc8aafb258..ac7f765bedafa6 100644 --- a/zk-token-sdk/src/encryption/elgamal.rs +++ b/zk-token-sdk/src/encryption/elgamal.rs @@ -21,6 +21,7 @@ use { Pedersen, PedersenCommitment, PedersenOpening, G, H, PEDERSEN_COMMITMENT_LEN, }, }, + errors::ElGamalError, RISTRETTO_POINT_LEN, SCALAR_LEN, }, base64::{prelude::BASE64_STANDARD, Engine}, @@ -31,7 +32,6 @@ use { traits::Identity, }, serde::{Deserialize, Serialize}, - solana_curve25519::errors::ElGamalError, solana_sdk::{ derivation_path::DerivationPath, signature::Signature, diff --git a/zk-token-sdk/src/errors.rs b/zk-token-sdk/src/errors.rs index 98a36c585ba045..e2c6c78721658a 100644 --- a/zk-token-sdk/src/errors.rs +++ b/zk-token-sdk/src/errors.rs @@ -3,10 +3,27 @@ use crate::range_proof::errors::RangeProofGenerationError; use { crate::{range_proof::errors::RangeProofVerificationError, sigma_proofs::errors::*}, - solana_curve25519::errors::ElGamalError, thiserror::Error, }; +#[derive(Error, Clone, Debug, Eq, PartialEq)] +pub enum ElGamalError { + #[error("key derivation method not supported")] + DerivationMethodNotSupported, + #[error("seed length too short for derivation")] + SeedLengthTooShort, + #[error("seed length too long for derivation")] + SeedLengthTooLong, + #[error("failed to deserialize ciphertext")] + CiphertextDeserialization, + #[error("failed to deserialize public key")] + PubkeyDeserialization, + #[error("failed to deserialize keypair")] + KeypairDeserialization, + #[error("failed to deserialize secret key")] + SecretKeyDeserialization, +} + #[derive(Error, Clone, Debug, Eq, PartialEq)] pub enum AuthenticatedEncryptionError { #[error("key derivation method not supported")] diff --git a/zk-token-sdk/src/zk_token_elgamal/pod/elgamal.rs b/zk-token-sdk/src/zk_token_elgamal/pod/elgamal.rs index 8a329949a984d5..64c3e794b4816b 100644 --- a/zk-token-sdk/src/zk_token_elgamal/pod/elgamal.rs +++ b/zk-token-sdk/src/zk_token_elgamal/pod/elgamal.rs @@ -2,9 +2,11 @@ #[cfg(not(target_os = "solana"))] use { - crate::encryption::elgamal::{self as decoded}, + crate::{ + encryption::elgamal::{self as decoded}, + errors::ElGamalError, + }, curve25519_dalek::ristretto::CompressedRistretto, - solana_curve25519::errors::ElGamalError, }; use { crate::{ diff --git a/zk-token-sdk/src/zk_token_elgamal/pod/grouped_elgamal.rs b/zk-token-sdk/src/zk_token_elgamal/pod/grouped_elgamal.rs index 8f7e6540acd543..c7e820fcd04508 100644 --- a/zk-token-sdk/src/zk_token_elgamal/pod/grouped_elgamal.rs +++ b/zk-token-sdk/src/zk_token_elgamal/pod/grouped_elgamal.rs @@ -3,12 +3,14 @@ #[cfg(not(target_os = "solana"))] use crate::encryption::grouped_elgamal::GroupedElGamalCiphertext; use { - crate::zk_token_elgamal::pod::{ - elgamal::{ElGamalCiphertext, DECRYPT_HANDLE_LEN, ELGAMAL_CIPHERTEXT_LEN}, - pedersen::{PedersenCommitment, PEDERSEN_COMMITMENT_LEN}, - Pod, Zeroable, + crate::{ + errors::ElGamalError, + zk_token_elgamal::pod::{ + elgamal::{ElGamalCiphertext, DECRYPT_HANDLE_LEN, ELGAMAL_CIPHERTEXT_LEN}, + pedersen::{PedersenCommitment, PEDERSEN_COMMITMENT_LEN}, + Pod, Zeroable, + }, }, - solana_curve25519::errors::ElGamalError, std::fmt, }; diff --git a/zk-token-sdk/src/zk_token_elgamal/pod/instruction.rs b/zk-token-sdk/src/zk_token_elgamal/pod/instruction.rs index 6a763633b3eb13..e29e3a500551ee 100644 --- a/zk-token-sdk/src/zk_token_elgamal/pod/instruction.rs +++ b/zk-token-sdk/src/zk_token_elgamal/pod/instruction.rs @@ -3,7 +3,7 @@ use crate::zk_token_elgamal::pod::{ Zeroable, }; #[cfg(not(target_os = "solana"))] -use {crate::instruction::transfer as decoded, solana_curve25519::errors::ElGamalError}; +use crate::{errors::ElGamalError, instruction::transfer as decoded}; #[derive(Clone, Copy, Pod, Zeroable)] #[repr(C)] diff --git a/zk-token-sdk/src/zk_token_elgamal/pod/pedersen.rs b/zk-token-sdk/src/zk_token_elgamal/pod/pedersen.rs index 831bb7ce75ea95..d27f307f43df2c 100644 --- a/zk-token-sdk/src/zk_token_elgamal/pod/pedersen.rs +++ b/zk-token-sdk/src/zk_token_elgamal/pod/pedersen.rs @@ -2,8 +2,8 @@ #[cfg(not(target_os = "solana"))] use { - crate::encryption::pedersen as decoded, curve25519_dalek::ristretto::CompressedRistretto, - solana_curve25519::errors::ElGamalError, + crate::{encryption::pedersen as decoded, errors::ElGamalError}, + curve25519_dalek::ristretto::CompressedRistretto, }; use { crate::{