1212// You should have received a copy of the Apache 2.0 License along with this
1313// software. If not, see <https://opensource.org/licenses/Apache-2.0>.
1414
15+ #![ allow( unused_braces) ]
16+
1517use std:: cmp:: Ordering ;
1618use std:: collections:: { BTreeMap , BTreeSet } ;
1719use std:: io:: Write ;
@@ -24,8 +26,8 @@ use crate::id::CommitmentId;
2426use crate :: merkle:: MerkleNode ;
2527use crate :: mpc:: atoms:: Leaf ;
2628use crate :: mpc:: tree:: protocol_id_pos;
27- use crate :: mpc:: { Commitment , MerkleTree , Message , ProtocolId , LNPBP4_TAG } ;
28- use crate :: { CommitEncode , Conceal } ;
29+ use crate :: mpc:: { Commitment , MerkleTree , Message , Proof , ProtocolId , LNPBP4_TAG } ;
30+ use crate :: { CommitEncode , Conceal , LIB_NAME_COMMIT_VERIFY } ;
2931
3032/// commitment under protocol id {_0} is absent from the known part of a given
3133/// LNPBP-4 Merkle block.
@@ -40,6 +42,12 @@ pub struct UnrelatedProof;
4042
4143/// LNPBP-4 Merkle tree node.
4244#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
45+ #[ derive( StrictType , StrictDumb , StrictEncode , StrictDecode ) ]
46+ #[ strict_type(
47+ lib = LIB_NAME_COMMIT_VERIFY ,
48+ tags = order,
49+ dumb = { TreeNode :: ConcealedNode { depth: u4:: ZERO , hash: [ 0u8 ; 32 ] . into( ) } }
50+ ) ]
4351#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) , serde( crate = "serde_crate" ) ) ]
4452enum TreeNode {
4553 /// A node of the tree with concealed leaf or tree branch information.
@@ -90,6 +98,8 @@ impl TreeNode {
9098
9199/// Partially-concealed merkle tree data.
92100#[ derive( Getters , Clone , PartialEq , Eq , Hash , Debug , Default ) ]
101+ #[ derive( StrictType , StrictEncode , StrictDecode ) ]
102+ #[ strict_type( lib = LIB_NAME_COMMIT_VERIFY ) ]
93103#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) , serde( crate = "serde_crate" ) ) ]
94104pub struct MerkleBlock {
95105 /// Tree depth (up to 16).
@@ -106,6 +116,8 @@ pub struct MerkleBlock {
106116 entropy : Option < u64 > ,
107117}
108118
119+ impl Proof for MerkleBlock { }
120+
109121impl From < & MerkleTree > for MerkleBlock {
110122 fn from ( tree : & MerkleTree ) -> Self {
111123 let map = & tree. map ;
@@ -454,6 +466,8 @@ impl CommitmentId for MerkleBlock {
454466
455467/// A proof of the merkle commitment.
456468#[ derive( Getters , Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Debug , Default ) ]
469+ #[ derive( StrictType , StrictEncode , StrictDecode ) ]
470+ #[ strict_type( lib = LIB_NAME_COMMIT_VERIFY ) ]
457471#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) , serde( crate = "serde_crate" ) ) ]
458472pub struct MerkleProof {
459473 /// Position of the leaf in the tree.
@@ -468,6 +482,8 @@ pub struct MerkleProof {
468482 path : SmallVec < MerkleNode > ,
469483}
470484
485+ impl Proof for MerkleProof { }
486+
471487impl MerkleProof {
472488 /// Computes the depth of the merkle tree.
473489 pub fn depth ( & self ) -> u8 { self . path . len ( ) as u8 }
0 commit comments