Merge pull request #119 from zcash/anchor-serialization

Anchor serialization APIs
This commit is contained in:
str4d 2021-06-15 16:25:36 +01:00 committed by GitHub
commit 37b1b7f357
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 2 deletions

View File

@ -7,12 +7,12 @@ use crate::{
};
use pasta_curves::pallas;
use ff::{Field, PrimeFieldBits};
use ff::{Field, PrimeField, PrimeFieldBits};
use rand::RngCore;
use std::iter;
/// The root of an Orchard commitment tree.
#[derive(Eq, PartialEq, Clone, Debug)]
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
pub struct Anchor(pallas::Base);
impl From<pallas::Base> for Anchor {
@ -21,6 +21,18 @@ impl From<pallas::Base> for Anchor {
}
}
impl Anchor {
/// Parses an Orchard anchor from a byte encoding.
pub fn from_bytes(bytes: [u8; 32]) -> Option<Anchor> {
pallas::Base::from_repr(bytes).map(Anchor)
}
/// Returns the byte encoding of this anchor.
pub fn to_bytes(self) -> [u8; 32] {
self.0.to_repr()
}
}
#[derive(Debug)]
pub struct MerklePath {
position: u32,