Skip to main content

orchard/
lib.rs

1//! # orchard
2//!
3//! ## Nomenclature
4//!
5//! All types in the `orchard` crate, unless otherwise specified, are Orchard-specific
6//! types. For example, [`Address`] is documented as being a shielded payment address; we
7//! implicitly mean it is an Orchard payment address (as opposed to e.g. a Sapling payment
8//! address, which is also shielded).
9
10#![no_std]
11#![cfg_attr(docsrs, feature(doc_cfg))]
12// Temporary until we have more of the crate implemented.
13#![allow(dead_code)]
14// Catch documentation errors caused by code changes.
15#![deny(rustdoc::broken_intra_doc_links)]
16#![deny(missing_debug_implementations)]
17#![deny(missing_docs)]
18#![deny(unsafe_code)]
19
20#[macro_use]
21extern crate alloc;
22
23#[cfg(feature = "std")]
24extern crate std;
25
26use alloc::vec::Vec;
27
28mod action;
29mod address;
30pub mod builder;
31pub mod bundle;
32#[cfg(feature = "circuit")]
33pub mod circuit;
34#[allow(missing_docs)]
35pub mod constants;
36pub mod keys;
37pub mod note;
38pub mod note_encryption;
39pub mod pczt;
40pub mod primitives;
41#[allow(missing_docs)]
42pub mod spec;
43pub mod tree;
44pub mod value;
45pub mod zip32;
46
47#[cfg(test)]
48mod test_vectors;
49
50pub use action::Action;
51pub use address::Address;
52pub use bundle::Bundle;
53pub use constants::MERKLE_DEPTH_ORCHARD as NOTE_COMMITMENT_TREE_DEPTH;
54pub use note::Note;
55pub use tree::Anchor;
56
57/// A proof of the validity of an Orchard [`Bundle`].
58///
59/// [`Bundle`]: crate::bundle::Bundle
60#[derive(Clone)]
61pub struct Proof(Vec<u8>);
62
63impl core::fmt::Debug for Proof {
64    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65        if f.alternate() {
66            f.debug_tuple("Proof").field(&self.0).finish()
67        } else {
68            // By default, only show the proof length, not its contents.
69            f.debug_tuple("Proof")
70                .field(&format_args!("{} bytes", self.0.len()))
71                .finish()
72        }
73    }
74}
75
76impl AsRef<[u8]> for Proof {
77    fn as_ref(&self) -> &[u8] {
78        &self.0
79    }
80}
81
82impl memuse::DynamicUsage for Proof {
83    fn dynamic_usage(&self) -> usize {
84        self.0.dynamic_usage()
85    }
86
87    fn dynamic_usage_bounds(&self) -> (usize, Option<usize>) {
88        self.0.dynamic_usage_bounds()
89    }
90}
91
92impl Proof {
93    /// Constructs a new Proof value.
94    pub fn new(bytes: Vec<u8>) -> Self {
95        Proof(bytes)
96    }
97}