zebra_chain/sprout/note/
nullifiers.rs

1//! Sprout nullifiers.
2
3use serde::{Deserialize, Serialize};
4
5use crate::fmt::HexDebug;
6
7/// Nullifier seed, named rho in the [spec][ps].
8///
9/// [ps]: https://zips.z.cash/protocol/protocol.pdf#sproutkeycomponents
10
11#[derive(Clone, Copy, Debug)]
12#[cfg_attr(
13    any(test, feature = "proptest-impl"),
14    derive(proptest_derive::Arbitrary)
15)]
16pub struct NullifierSeed(pub(crate) HexDebug<[u8; 32]>);
17
18impl AsRef<[u8]> for NullifierSeed {
19    fn as_ref(&self) -> &[u8] {
20        self.0.as_ref()
21    }
22}
23
24impl From<[u8; 32]> for NullifierSeed {
25    fn from(bytes: [u8; 32]) -> Self {
26        Self(bytes.into())
27    }
28}
29
30impl From<NullifierSeed> for [u8; 32] {
31    fn from(rho: NullifierSeed) -> Self {
32        *rho.0
33    }
34}
35
36/// A Nullifier for Sprout transactions
37#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Hash)]
38#[cfg_attr(
39    any(test, feature = "proptest-impl"),
40    derive(proptest_derive::Arbitrary)
41)]
42pub struct Nullifier(pub HexDebug<[u8; 32]>);
43
44impl From<[u8; 32]> for Nullifier {
45    fn from(bytes: [u8; 32]) -> Self {
46        Self(bytes.into())
47    }
48}
49
50impl From<Nullifier> for [u8; 32] {
51    fn from(n: Nullifier) -> Self {
52        *n.0
53    }
54}
55
56impl From<&Nullifier> for [u8; 32] {
57    fn from(n: &Nullifier) -> Self {
58        *n.0
59    }
60}