From 7f4659606864764b5af82886dad8f02b3374bc37 Mon Sep 17 00:00:00 2001 From: Hendrik Eeckhaut Date: Fri, 2 Aug 2024 12:28:51 +0200 Subject: [PATCH] docs: fix and improve interactive example (#552) #551 --- crates/examples/Cargo.toml | 1 - crates/examples/interactive/README.md | 2 +- crates/examples/interactive/interactive.rs | 27 +++++++++++----------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/crates/examples/Cargo.toml b/crates/examples/Cargo.toml index 091ff6470..fe7fc2017 100644 --- a/crates/examples/Cargo.toml +++ b/crates/examples/Cargo.toml @@ -18,7 +18,6 @@ http-body-util = { workspace = true } hyper = { workspace = true, features = ["client", "http1"] } hyper-util = { workspace = true, features = ["full"] } p256 = { workspace = true, features = ["ecdsa"] } -regex = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } tokio = { workspace = true, features = [ diff --git a/crates/examples/interactive/README.md b/crates/examples/interactive/README.md index ebafc318d..bed068da4 100644 --- a/crates/examples/interactive/README.md +++ b/crates/examples/interactive/README.md @@ -1,5 +1,5 @@ ## Simple Interactive Verifier: Verifying Data from an API in Rust -This example demonstrates how to use TLSNotary in a simple interactive session between a Prover and a Verifier. It involves the Verifier first verifying the TLS-MPC session and then confirming the correctness of the data. +This example demonstrates how to use TLSNotary in a simple interactive session between a Prover and a Verifier. It involves the Verifier first verifying the MPC-TLS session and then confirming the correctness of the data. Note: In this example, the Prover and the Verifier run on the same machine. In real-world scenarios, the Prover and Verifier would be separate entities. diff --git a/crates/examples/interactive/interactive.rs b/crates/examples/interactive/interactive.rs index f335cad56..acf0bdc8b 100644 --- a/crates/examples/interactive/interactive.rs +++ b/crates/examples/interactive/interactive.rs @@ -1,7 +1,6 @@ use http_body_util::Empty; use hyper::{body::Bytes, Request, StatusCode, Uri}; use hyper_util::rt::TokioIo; -use regex::Regex; use tlsn_core::{proof::SessionInfo, Direction, RedactedTranscript}; use tlsn_prover::tls::{state::Prove, Prover, ProverConfig}; use tlsn_verifier::tls::{Verifier, VerifierConfig}; @@ -10,13 +9,13 @@ use tokio_util::compat::{FuturesAsyncReadCompatExt, TokioAsyncReadCompatExt}; use tracing::instrument; const SECRET: &str = "TLSNotary's private key 🤡"; -const SERVER_DOMAIN: &str = "notary.pse.dev"; +const SERVER_DOMAIN: &str = "example.com"; #[tokio::main] async fn main() { tracing_subscriber::fmt::init(); - let uri = "https://notary.pse.dev/info"; + let uri = "https://example.com"; let id = "interactive verifier demo"; // Connect prover and verifier. @@ -137,8 +136,8 @@ async fn verifier( let response = String::from_utf8(received.data().to_vec()).expect("Verifier expected received data"); response - .find("BEGIN PUBLIC KEY") - .expect("Expected valid public key in JSON response"); + .find("Example Domain") + .expect("Expected valid data from example.com"); // Check Session info: server name. assert_eq!(session_info.server_name.as_str(), SERVER_DOMAIN); @@ -150,17 +149,17 @@ async fn verifier( fn redact_and_reveal_received_data(prover: &mut Prover) { let recv_transcript_len = prover.recv_transcript().data().len(); - // Get the commit hash from the received data. + // Get the received data as a string. let received_string = String::from_utf8(prover.recv_transcript().data().to_vec()).unwrap(); - let re = Regex::new(r#""gitCommitHash"\s?:\s?"(.*?)""#).unwrap(); - let commit_hash_match = re.captures(&received_string).unwrap().get(1).unwrap(); + // Find the substring "illustrative". + let start = received_string + .find("illustrative") + .expect("Error: The substring 'illustrative' was not found in the received data."); + let end = start + "illustrative".len(); - // Reveal everything except for the commit hash. - _ = prover.reveal(0..commit_hash_match.start(), Direction::Received); - _ = prover.reveal( - commit_hash_match.end()..recv_transcript_len, - Direction::Received, - ); + // Reveal everything except for the substring "illustrative". + _ = prover.reveal(0..start, Direction::Received); + _ = prover.reveal(end..recv_transcript_len, Direction::Received); } /// Redacts and reveals sent data to the verifier.