mirror of https://github.com/zcash/halo2.git
Merge pull request #119 from zcash/anchor-serialization
Anchor serialization APIs
This commit is contained in:
commit
37b1b7f357
16
src/tree.rs
16
src/tree.rs
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue