nam_redjubjub/
lib.rs

1// -*- mode: rust; -*-
2//
3// This file is part of redjubjub.
4// Copyright (c) 2019-2021 Zcash Foundation
5// See LICENSE for licensing information.
6//
7// Authors:
8// - Deirdre Connolly <deirdre@zfnd.org>
9// - Henry de Valence <hdevalence@hdevalence.ca>
10
11#![deny(missing_docs)]
12#![doc = include_str!("../README.md")]
13#![no_std]
14
15#[cfg(feature = "std")]
16extern crate std;
17
18pub mod batch;
19mod error;
20pub(crate) mod signature;
21mod signing_key;
22mod verification_key;
23
24use reddsa::sapling;
25
26/// An element of the JubJub scalar field used for randomization of public and secret keys.
27pub type Randomizer = reddsa::Randomizer<sapling::SpendAuth>;
28
29pub use error::Error;
30pub use signature::Signature;
31pub use signing_key::SigningKey;
32pub use verification_key::{VerificationKey, VerificationKeyBytes};
33
34/// Abstracts over different RedJubJub parameter choices, [`Binding`]
35/// and [`SpendAuth`].
36///
37/// As described [at the end of ยง5.4.6][concretereddsa] of the Zcash
38/// protocol specification, the generator used in RedJubjub is left as
39/// an unspecified parameter, chosen differently for each of
40/// `BindingSig` and `SpendAuthSig`.
41///
42/// To handle this, we encode the parameter choice as a genuine type
43/// parameter.
44///
45/// [concretereddsa]: https://zips.z.cash/protocol/protocol.pdf#concretereddsa
46pub trait SigType: private::Sealed {}
47
48/// A type variable corresponding to Zcash's `BindingSig`.
49#[derive(Copy, Clone, PartialEq, Eq, Debug)]
50pub enum Binding {}
51impl SigType for Binding {}
52
53/// A type variable corresponding to Zcash's `SpendAuthSig`.
54#[derive(Copy, Clone, PartialEq, Eq, Debug)]
55pub enum SpendAuth {}
56impl SigType for SpendAuth {}
57
58pub(crate) mod private {
59    use super::*;
60    pub trait Sealed: Copy + Clone + Eq + PartialEq + core::fmt::Debug {
61        type RedDSASigType: reddsa::SigType;
62    }
63    impl Sealed for Binding {
64        type RedDSASigType = sapling::Binding;
65    }
66    impl Sealed for SpendAuth {
67        type RedDSASigType = sapling::SpendAuth;
68    }
69}