1#![no_std]
12#![deny(missing_docs)]
13#![doc = include_str!("../README.md")]
14
15#[cfg(feature = "alloc")]
18#[macro_use]
19extern crate alloc;
20#[cfg(feature = "std")]
21extern crate std;
22
23#[cfg(feature = "alloc")]
24pub mod batch;
25mod constants;
26mod error;
27#[cfg(feature = "frost")]
28pub mod frost;
29mod hash;
30pub mod orchard;
31pub mod sapling;
32#[cfg(feature = "alloc")]
33mod scalar_mul;
34pub(crate) mod signature;
35mod signing_key;
36mod verification_key;
37
38pub type Randomizer<S> = <S as private::Sealed<S>>::Scalar;
40
41use hash::HStar;
42
43pub use error::Error;
44pub use signature::Signature;
45pub use signing_key::SigningKey;
46pub use verification_key::{VerificationKey, VerificationKeyBytes};
47
48pub trait SigType: private::Sealed<Self> {}
61
62pub trait Binding: SigType {}
64
65pub trait SpendAuth: SigType {}
67
68pub(crate) mod private {
69 use super::*;
70
71 pub trait SealedScalar {
72 fn from_bytes_wide(bytes: &[u8; 64]) -> Self;
73 fn from_raw(val: [u64; 4]) -> Self;
74 }
75
76 impl SealedScalar for jubjub::Scalar {
77 fn from_bytes_wide(bytes: &[u8; 64]) -> Self {
78 jubjub::Scalar::from_bytes_wide(bytes)
79 }
80 fn from_raw(val: [u64; 4]) -> Self {
81 jubjub::Scalar::from_raw(val)
82 }
83 }
84
85 pub trait Sealed<T: SigType>:
86 Copy + Clone + Default + Eq + PartialEq + core::fmt::Debug
87 {
88 const H_STAR_PERSONALIZATION: &'static [u8; 16];
89 type Scalar: group::ff::PrimeField + SealedScalar;
90
91 #[cfg(feature = "alloc")]
94 type Point: group::cofactor::CofactorCurve<Scalar = Self::Scalar>
95 + scalar_mul::VartimeMultiscalarMul<Scalar = Self::Scalar, Point = Self::Point>;
96 #[cfg(not(feature = "alloc"))]
97 type Point: group::cofactor::CofactorCurve<Scalar = Self::Scalar>;
98
99 fn basepoint() -> T::Point;
100 }
101 impl Sealed<sapling::Binding> for sapling::Binding {
102 const H_STAR_PERSONALIZATION: &'static [u8; 16] = b"Zcash_RedJubjubH";
103 type Point = jubjub::ExtendedPoint;
104 type Scalar = jubjub::Scalar;
105
106 fn basepoint() -> jubjub::ExtendedPoint {
107 jubjub::AffinePoint::from_bytes(constants::BINDINGSIG_BASEPOINT_BYTES)
108 .unwrap()
109 .into()
110 }
111 }
112 impl Sealed<sapling::SpendAuth> for sapling::SpendAuth {
113 const H_STAR_PERSONALIZATION: &'static [u8; 16] = b"Zcash_RedJubjubH";
114 type Point = jubjub::ExtendedPoint;
115 type Scalar = jubjub::Scalar;
116
117 fn basepoint() -> jubjub::ExtendedPoint {
118 jubjub::AffinePoint::from_bytes(constants::SPENDAUTHSIG_BASEPOINT_BYTES)
119 .unwrap()
120 .into()
121 }
122 }
123}
124
125#[cfg(feature = "alloc")]
127pub(crate) fn hex_if_possible(bytes: &[u8]) -> alloc::string::String {
128 hex::encode(bytes)
129}
130
131#[cfg(not(feature = "alloc"))]
133pub(crate) fn hex_if_possible(bytes: &[u8]) -> &[u8] {
134 bytes
135}