libzeropool_zkbob/native/
note.rs1use fawkes_crypto::{ff_uint::{Num, PrimeField},native::poseidon::poseidon};
2use crate::constants;
3use crate::native::{boundednum::BoundedNum, params::PoolParams};
4use std::fmt::Debug;
5
6
7#[derive(Clone, Debug, Serialize, Deserialize)]
8#[serde(bound(serialize = "", deserialize = ""))]
9pub struct Note<Fr:PrimeField> {
10 pub d: BoundedNum<Fr, { constants::DIVERSIFIER_SIZE_BITS }>,
11 pub p_d: Num<Fr>,
12 pub b: BoundedNum<Fr, { constants::BALANCE_SIZE_BITS }>,
13 pub t: BoundedNum<Fr, { constants::SALT_SIZE_BITS }>,
14}
15
16impl<Fr:PrimeField> Note<Fr> {
17 pub fn hash<P:PoolParams<Fr=Fr>>(&self, params:&P) -> Num<Fr> {
18 poseidon(&[self.d.to_num(), self.p_d, self.b.to_num(), self.t.to_num()], params.note())
19 }
20}
21
22impl<Fr:PrimeField> Copy for Note<Fr> {}
23
24impl<Fr:PrimeField> Eq for Note<Fr> {}
25
26impl<Fr:PrimeField> PartialEq for Note<Fr> {
27 #[inline]
28 fn eq(&self, other: &Self) -> bool {
29 self.d.eq(&other.d) &&
30 self.p_d.eq(&other.p_d) &&
31 self.b.eq(&other.b) &&
32 self.t.eq(&other.t)
33 }
34}