1#![deny(clippy::all)]
7#![warn(clippy::pedantic)]
8#![warn(missing_docs)]
9
10pub mod ecdh;
11pub mod ecdsa; pub mod keyimage;
13pub mod pedersen;
14pub mod borromean;
15pub mod rangeproof;
16pub mod mlsag; pub mod utils; pub use ecdh::ecdh_veil;
23pub use ecdsa::{ecdsa_sign, ecdsa_sign_compact, ecdsa_get_public_key};
24pub use keyimage::get_keyimage;
25pub use pedersen::{pedersen_blind_sum, pedersen_commit};
26pub use borromean::{borromean_hash, borromean_sign, borromean_verify};
27pub use rangeproof::{rangeproof_sign, rangeproof_verify, rangeproof_rewind, RangeProofSignResult, RangeProofVerifyResult, RangeProofRewindResult};
28pub use mlsag::{prepare_mlsag, generate_mlsag, verify_mlsag, PrepareMlsagResult, GenerateMlsagResult};
29pub use utils::{derive_pubkey, point_add_scalar, point_multiply, private_add};
30
31pub use k256::{PublicKey, SecretKey};
33
34#[derive(Debug, Clone, PartialEq, Eq)]
36pub enum VeilCryptoError {
37 InvalidPublicKey,
39 InvalidSecretKey,
41 InvalidSignature,
43 InvalidCommitment,
45 InvalidRangeProof,
47 MlsagGenerationFailed,
49 MlsagVerificationFailed,
51 InvalidInput(String),
53 SignatureError(String),
55 Other(String),
57}
58
59impl std::fmt::Display for VeilCryptoError {
60 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61 match self {
62 Self::InvalidPublicKey => write!(f, "Invalid public key"),
63 Self::InvalidSecretKey => write!(f, "Invalid secret key"),
64 Self::InvalidSignature => write!(f, "Invalid signature"),
65 Self::InvalidCommitment => write!(f, "Invalid commitment"),
66 Self::InvalidRangeProof => write!(f, "Invalid range proof"),
67 Self::MlsagGenerationFailed => write!(f, "MLSAG generation failed"),
68 Self::MlsagVerificationFailed => write!(f, "MLSAG verification failed"),
69 Self::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
70 Self::SignatureError(msg) => write!(f, "Signature error: {}", msg),
71 Self::Other(msg) => write!(f, "{}", msg),
72 }
73 }
74}
75
76impl std::error::Error for VeilCryptoError {}
77
78pub type Result<T> = std::result::Result<T, VeilCryptoError>;
80
81#[cfg(test)]
82mod tests {
83 use super::*;
84
85 #[test]
86 fn test_error_display() {
87 let err = VeilCryptoError::InvalidPublicKey;
88 assert_eq!(format!("{}", err), "Invalid public key");
89 }
90}