Anchor::{from_bytes, to_bytes}

This commit is contained in:
Jack Grigg 2021-06-15 15:41:33 +01:00
parent e412a5a25b
commit 019ae7da8e
1 changed files with 13 additions and 1 deletions

View File

@ -7,7 +7,7 @@ use crate::{
};
use pasta_curves::pallas;
use ff::{Field, PrimeFieldBits};
use ff::{Field, PrimeField, PrimeFieldBits};
use rand::RngCore;
use std::iter;
@ -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,