noah_algebra/
lib.rs

1//! The crate for algebra for the Noah library, which unifies the interfaces of different curves
2#![cfg_attr(not(feature = "std"), no_std)]
3#![deny(unused_import_braces, unused_qualifications, trivial_casts)]
4#![deny(trivial_numeric_casts, private_in_public)]
5#![deny(stable_features, unreachable_pub, non_shorthand_field_patterns)]
6#![deny(unused_attributes, unused_imports, unused_mut, missing_docs)]
7#![deny(renamed_and_removed_lints, stable_features, unused_allocation)]
8#![deny(unused_comparisons, bare_trait_objects, unused_must_use)]
9#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/74745723?s=200&v=4")]
10#![doc(html_playground_url = "https://play.rust-lang.org")]
11#![forbid(unsafe_code)]
12#![warn(
13    unused,
14    future_incompatible,
15    nonstandard_style,
16    rust_2018_idioms,
17    rust_2021_compatibility
18)]
19#![allow(
20    clippy::op_ref,
21    clippy::suspicious_op_assign_impl,
22    clippy::upper_case_acronyms
23)]
24
25#[macro_use]
26extern crate serde_derive;
27
28/// Module for the BLS12-381 curve
29pub mod bls12_381;
30
31/// Module for the secq256k1 curve
32pub mod secq256k1;
33
34/// Module for the secp256k1 curve
35pub mod secp256k1;
36
37/// Module for the Jubjub curve
38pub mod jubjub;
39
40/// Module for the Zorro curve
41pub mod zorro;
42
43/// Module for the ed25519 curve used to work with the Zorro curve in address folding
44pub mod ed25519;
45
46/// Module for the Ristretto group
47pub mod ristretto;
48
49/// Module for error handling
50pub mod errors;
51
52/// Module for traits
53pub mod traits;
54
55/// Module for serialization of scalars and group elements
56pub mod serialization;
57
58/// Module for utils
59pub mod utils;
60
61/// Module for prelude
62#[doc(hidden)]
63pub mod prelude;
64
65/// Module for test rng
66pub mod rand_helper;
67
68#[doc(hidden)]
69pub use ark_std::{
70    borrow, cfg_into_iter, cmp, collections, end_timer, fmt, fs, hash, io, iter, ops, path, rand,
71    result, start_timer, str, One, UniformRand, Zero,
72};
73
74/// check if the error messages equal
75#[macro_export]
76macro_rules! msg_eq {
77    ($noah_err: expr, $ruc_err: expr $(,)?) => {
78        assert!($ruc_err.msg_has_overloop(ruc::eg!($noah_err).as_ref()));
79    };
80    ($noah_err: expr, $ruc_err: expr, $msg: expr $(,)?) => {
81        assert!(
82            $ruc_err.msg_has_overloop(ruc::eg!($noah_err).as_ref()),
83            $msg
84        );
85    };
86}
87
88/// Implement serialization and deserialization
89#[macro_export]
90macro_rules! serialize_deserialize {
91    ($t:ident) => {
92        impl serde::Serialize for $t {
93            fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
94            where
95                S: Serializer,
96            {
97                if serializer.is_human_readable() {
98                    serializer.serialize_str(&b64enc(&self.noah_to_bytes()))
99                } else {
100                    serializer.serialize_bytes(&self.noah_to_bytes())
101                }
102            }
103        }
104
105        impl<'de> serde::Deserialize<'de> for $t {
106            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
107            where
108                D: serde::Deserializer<'de>,
109            {
110                let bytes = if deserializer.is_human_readable() {
111                    deserializer.deserialize_str(noah_obj_serde::BytesVisitor)?
112                } else {
113                    deserializer.deserialize_bytes(noah_obj_serde::BytesVisitor)?
114                };
115                $t::noah_from_bytes(bytes.as_slice()).map_err(serde::de::Error::custom)
116            }
117        }
118    };
119}