From 5cf7128db57d361a519eef7dfd0c973e52fb4f5f Mon Sep 17 00:00:00 2001 From: yuroitaki <> Date: Thu, 28 Nov 2024 19:18:23 +0800 Subject: [PATCH] Add reveal groups of ranges. --- crates/core/src/transcript/proof.rs | 32 ++++++++++++++++++++++++++ crates/examples/attestation/present.rs | 32 +++++++++++++++++--------- 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/crates/core/src/transcript/proof.rs b/crates/core/src/transcript/proof.rs index ae9a68dc1e..43cda73d63 100644 --- a/crates/core/src/transcript/proof.rs +++ b/crates/core/src/transcript/proof.rs @@ -281,6 +281,22 @@ impl<'a> TranscriptProofBuilder<'a> { self.reveal(ranges, Direction::Sent) } + /// Reveals multiple groups of ranges given in the sent transcript using the + /// default kind of commitment. + /// + /// # Arguments + /// + /// * `ranges_groups` - Groups of ranges to reveal. + pub fn reveal_sent_multi( + &mut self, + ranges_groups: &[&dyn ToRangeSet], + ) -> Result<&mut Self, TranscriptProofBuilderError> { + for ranges in ranges_groups.iter() { + self.reveal(*ranges, Direction::Sent)?; + } + Ok(self) + } + /// Reveals the given ranges in the received transcript using the default /// kind of commitment. /// @@ -294,6 +310,22 @@ impl<'a> TranscriptProofBuilder<'a> { self.reveal(ranges, Direction::Received) } + /// Reveals multiple groups of ranges given in the received transcript using + /// the default kind of commitment. + /// + /// # Arguments + /// + /// * `ranges_groups` - Groups of ranges to reveal. + pub fn reveal_recv_multi( + &mut self, + ranges_groups: &[&dyn ToRangeSet], + ) -> Result<&mut Self, TranscriptProofBuilderError> { + for ranges in ranges_groups.iter() { + self.reveal(*ranges, Direction::Received)?; + } + Ok(self) + } + /// Builds the transcript proof. pub fn build(self) -> Result { let encoding_proof = if !self.encoding_proof_idxs.is_empty() { diff --git a/crates/examples/attestation/present.rs b/crates/examples/attestation/present.rs index a798f593b8..7d9efb361e 100644 --- a/crates/examples/attestation/present.rs +++ b/crates/examples/attestation/present.rs @@ -8,6 +8,7 @@ use tlsn_examples::ExampleType; use tlsn_formats::http::HttpTranscript; use clap::Parser; +use utils::range::ToRangeSet; #[derive(Parser, Debug)] #[command(version, about, long_about = None)] @@ -41,10 +42,11 @@ async fn create_presentation(example_type: &ExampleType) -> Result<(), Box Result<(), Box> = Vec::new(); + let response = &transcript.responses[0]; - builder.reveal_recv(&response.without_data())?; + let response_without_data = &response.without_data(); + recv_ranges.push(response_without_data); + for header in &response.headers { - builder.reveal_recv(header)?; + recv_ranges.push(header); } let content = &response.body.as_ref().unwrap().content; @@ -75,19 +83,21 @@ async fn create_presentation(example_type: &ExampleType) -> Result<(), Box { - builder.reveal_recv(span)?; + recv_ranges.push(span); } _ => {} } + builder.reveal_recv_multi(&recv_ranges)?; + let transcript_proof = builder.build()?; // Use default crypto provider to build the presentation.