From<Nullifier> for [u8; 32]

This commit is contained in:
Deirdre Connolly 2020-08-05 03:08:23 -04:00 committed by Deirdre Connolly
parent b2584c4a8f
commit 68871c5bd4
1 changed files with 18 additions and 6 deletions

View File

@ -43,7 +43,7 @@ fn prf_nf(a_sk: [u8; 32], rho: [u8; 32]) -> [u8; 32] {
/// [ps]: https://zips.z.cash/protocol/protocol.pdf#sproutkeycomponents
#[derive(Clone, Copy, Debug)]
#[cfg_attr(test, derive(proptest_derive::Arbitrary))]
pub struct NullifierSeed([u8; 32]);
pub struct NullifierSeed(pub(crate) [u8; 32]);
impl AsRef<[u8]> for NullifierSeed {
fn as_ref(&self) -> &[u8] {
@ -57,23 +57,35 @@ impl From<[u8; 32]> for NullifierSeed {
}
}
/// A Nullifier for Sprout transactions
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(test, derive(proptest_derive::Arbitrary))]
pub struct Nullifier([u8; 32]);
impl From<NullifierSeed> for [u8; 32] {
fn from(rho: NullifierSeed) -> Self {
rho.0
}
}
/// A Nullifier for Sprout transactions
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(test, derive(proptest_derive::Arbitrary))]
pub struct Nullifier(pub(crate) [u8; 32]);
impl From<[u8; 32]> for Nullifier {
fn from(bytes: [u8; 32]) -> Self {
Self(bytes)
}
}
impl From<(SpendingKey, NullifierSeed)> for Nullifier {
fn from((a_sk, rho): (SpendingKey, NullifierSeed)) -> Self {
Self(prf_nf(a_sk.into(), rho.into()))
}
}
impl From<Nullifier> for [u8; 32] {
fn from(n: Nullifier) -> Self {
n.0
}
}
impl ZcashDeserialize for Nullifier {
fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> {
let bytes = reader.read_32_bytes()?;