-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(examples): fix examples for alpha.7 release (#603)
* doc: Fix examples for alpha7 release + Use secp256k1 key for notary server fixture + fix tower issue + Fixed doctes issues (Avoid doc test failures when ignored tests are run) + Run wasm tests in incognitto mode to avoid chromiumoxide ws errors * Added comment * minor improvements * formatting * polish attestation example * use shorthand fs write * clean * simplify discord example --------- Co-authored-by: sinu <[email protected]>
- Loading branch information
Showing
22 changed files
with
408 additions
and
570 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Ignore files from examples. | ||
*.tlsn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// This example demonstrates how to build a verifiable presentation from an | ||
// attestation and the corresponding connection secrets. See the `prove.rs` | ||
// example to learn how to acquire an attestation from a Notary. | ||
|
||
use tlsn_core::{attestation::Attestation, presentation::Presentation, CryptoProvider, Secrets}; | ||
use tlsn_formats::http::HttpTranscript; | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
// Read attestation from disk. | ||
let attestation: Attestation = | ||
bincode::deserialize(&std::fs::read("example.attestation.tlsn")?)?; | ||
|
||
// Read secrets from disk. | ||
let secrets: Secrets = bincode::deserialize(&std::fs::read("example.secrets.tlsn")?)?; | ||
|
||
// Parse the HTTP transcript. | ||
let transcript = HttpTranscript::parse(secrets.transcript())?; | ||
|
||
// Build a transcript proof. | ||
let mut builder = secrets.transcript_proof_builder(); | ||
|
||
let request = &transcript.requests[0]; | ||
// Reveal the structure of the request without the headers or body. | ||
builder.reveal_sent(&request.without_data())?; | ||
// Reveal the request target. | ||
builder.reveal_sent(&request.request.target)?; | ||
// Reveal all headers except the value of the User-Agent header. | ||
for header in &request.headers { | ||
if !header.name.as_str().eq_ignore_ascii_case("User-Agent") { | ||
builder.reveal_sent(header)?; | ||
} else { | ||
builder.reveal_sent(&header.without_value())?; | ||
} | ||
} | ||
// Reveal the entire response. | ||
builder.reveal_recv(&transcript.responses[0])?; | ||
|
||
let transcript_proof = builder.build()?; | ||
|
||
// Use default crypto provider to build the presentation. | ||
let provider = CryptoProvider::default(); | ||
|
||
let mut builder = attestation.presentation_builder(&provider); | ||
|
||
builder | ||
.identity_proof(secrets.identity_proof()) | ||
.transcript_proof(transcript_proof); | ||
|
||
let presentation: Presentation = builder.build()?; | ||
|
||
// Write the presentation to disk. | ||
std::fs::write( | ||
"example.presentation.tlsn", | ||
bincode::serialize(&presentation)?, | ||
)?; | ||
|
||
println!("Presentation built successfully!"); | ||
println!("The presentation has been written to `example.presentation.tlsn`."); | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.
dfc1629
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.