Skip to content

Commit

Permalink
Also redact some received data in simple_prover (#370)
Browse files Browse the repository at this point in the history
Also redact some received data in simple_prover
  • Loading branch information
heeckhau authored Oct 23, 2023
1 parent ce80e75 commit bfcb308
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions tlsn/examples/simple/simple_prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,35 @@ async fn main() {
let mut prover = prover.start_notarize();

// Identify the ranges in the outbound data which contain data which we want to disclose
let (public_ranges, _) = find_ranges(
let (sent_public_ranges, _) = find_ranges(
prover.sent_transcript().data(),
&[
// Redact the value of the "User-Agent" header. It will NOT be disclosed.
USER_AGENT.as_bytes(),
],
);

let recv_len = prover.recv_transcript().data().len();
// Identify the ranges in the inbound data which contain data which we want to disclose
let (recv_public_ranges, _) = find_ranges(
prover.recv_transcript().data(),
&[
// Redact the value of the title. It will NOT be disclosed.
"Example Domain".as_bytes(),
],
);

let builder = prover.commitment_builder();

// Commit to each range of the public outbound data which we want to disclose
let sent_commitments: Vec<_> = public_ranges
let sent_commitments: Vec<_> = sent_public_ranges
.iter()
.map(|r| builder.commit_sent(r.clone()).unwrap())
.collect();

// Commit to all inbound data in one shot, as we don't need to redact anything in it
let recv_commitment = builder.commit_recv(0..recv_len).unwrap();
// Commit to each range of the public inbound data which we want to disclose
let recv_commitments: Vec<_> = recv_public_ranges
.iter()
.map(|r| builder.commit_recv(r.clone()).unwrap())
.collect();

// Finalize, returning the notarized session
let notarized_session = prover.finalize().await.unwrap();
Expand All @@ -130,7 +139,9 @@ async fn main() {
for commitment_id in sent_commitments {
proof_builder.reveal(commitment_id).unwrap();
}
proof_builder.reveal(recv_commitment).unwrap();
for commitment_id in recv_commitments {
proof_builder.reveal(commitment_id).unwrap();
}

let substrings_proof = proof_builder.build().unwrap();

Expand Down

0 comments on commit bfcb308

Please sign in to comment.