diff --git a/commit_verify/src/mpc/block.rs b/commit_verify/src/mpc/block.rs index 5135f23c..a7125ec2 100644 --- a/commit_verify/src/mpc/block.rs +++ b/commit_verify/src/mpc/block.rs @@ -601,6 +601,13 @@ Changed commitment id: {}", /// `2 ^ depth - cofactor`. pub fn factored_width(&self) -> u32 { self.width_limit() - self.cofactor as u32 } + pub fn known_protocol_ids(&self) -> impl Iterator + '_ { + self.cross_section.iter().filter_map(|item| match item { + TreeNode::ConcealedNode { .. } => None, + TreeNode::CommitmentLeaf { protocol_id, .. } => Some(*protocol_id), + }) + } + /// Constructs [`MessageMap`] for revealed protocols and messages. pub fn to_known_message_map(&self) -> MessageMap { Confined::try_from_iter( @@ -617,6 +624,18 @@ Changed commitment id: {}", ) .expect("same collection size") } + + pub fn into_known_proofs(self) -> impl Iterator { + self.known_protocol_ids() + .collect::>() + .into_iter() + .map(move |id| { + let proof = self + .to_merkle_proof(id) + .expect("protocol ids must strictly match"); + (id, proof) + }) + } } impl Conceal for MerkleBlock { diff --git a/commit_verify/src/mpc/tree.rs b/commit_verify/src/mpc/tree.rs index 3a7debda..f1999fc9 100644 --- a/commit_verify/src/mpc/tree.rs +++ b/commit_verify/src/mpc/tree.rs @@ -27,7 +27,8 @@ pub use self::commit::Error; use crate::merkle::MerkleHash; use crate::mpc::atoms::Leaf; use crate::mpc::{ - Commitment, MerkleBlock, MerkleConcealed, Message, MessageMap, Method, Proof, ProtocolId, + Commitment, MerkleBlock, MerkleConcealed, MerkleProof, Message, MessageMap, Method, Proof, + ProtocolId, }; use crate::{CommitId, Conceal, LIB_NAME_COMMIT_VERIFY}; @@ -205,6 +206,11 @@ impl MerkleTree { pub fn cofactor(&self) -> u16 { self.cofactor } pub fn entropy(&self) -> u64 { self.entropy } + + pub fn into_proofs(self) -> impl Iterator { + let block = MerkleBlock::from(self); + block.into_known_proofs() + } } #[cfg(test)]