From ce4697aca54e655729a772ae729de804bd155504 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Thu, 17 Jun 2021 08:34:09 -0600 Subject: [PATCH] Add construction of OrchardIncrementalTreeDigest --- src/lib.rs | 2 +- src/tree.rs | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3b46ae84..3bc712e8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,7 +26,7 @@ pub mod note; mod note_encryption; pub mod primitives; mod spec; -mod tree; +pub mod tree; pub mod value; #[cfg(test)] diff --git a/src/tree.rs b/src/tree.rs index f4a18ee0..ace8906b 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -1,3 +1,5 @@ +//! Types related to Orchard note commitment trees and anchors. + use crate::{ constants::{ util::gen_const_array, L_ORCHARD_MERKLE, MERKLE_CRH_PERSONALIZATION, MERKLE_DEPTH_ORCHARD, @@ -35,6 +37,8 @@ impl Anchor { } } +/// The Merkle path from a leaf of the note commitment tree +/// to its anchor. #[derive(Debug)] pub struct MerklePath { position: u32, @@ -132,8 +136,18 @@ fn hash_layer(l_star: usize, pair: Pair) -> CtOption { ) } -#[derive(Clone)] -struct OrchardIncrementalTreeDigest(CtOption); +/// A newtype wrapper for leaves and internal nodes in the Orchard +/// incremental note commitment tree. +#[derive(Clone, Debug)] +pub struct OrchardIncrementalTreeDigest(CtOption); + +impl OrchardIncrementalTreeDigest { + /// Parses a incremental tree leaf digest from the bytes of + /// a note commitment. + pub fn from_bytes(bytes: &[u8; 32]) -> Self { + OrchardIncrementalTreeDigest(pallas::Base::from_bytes(bytes)) + } +} impl Hashable for OrchardIncrementalTreeDigest { fn empty_leaf() -> Self {