From 019ae7da8e01eab6f9eb90aa96b38b949f3f0af4 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 15 Jun 2021 15:41:33 +0100 Subject: [PATCH] Anchor::{from_bytes, to_bytes} --- src/tree.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/tree.rs b/src/tree.rs index 11597702..c92f946e 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -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 for Anchor { } } +impl Anchor { + /// Parses an Orchard anchor from a byte encoding. + pub fn from_bytes(bytes: [u8; 32]) -> Option { + 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,