This example demonstrates the simplest possible use case for TLSNotary. A Prover notarizes data from a local test server with a local Notary.
Overview:
- Notarize a request and response from the test server and acquire an attestation of its content.
- Create a redacted, verifiable presentation using the attestation.
- Verify the presentation.
Before starting the notarization, set up the local test server and local notary.
- Run the test server:
PORT=4000 cargo run --bin tlsn-server-fixture
- Run the notary server:
cd crates/notary/server cargo run -r -- --tls-enabled false
- Run the prove example:
SERVER_PORT=4000 cargo run --release --example attestation_prove
To see more details, run with additional debug information:
RUST_LOG=debug,yamux=info,uid_mux=info SERVER_PORT=4000 cargo run --release --example attestation_prove
If notarization is successful, you should see the following output in the console:
Starting an MPC TLS connection with the server
Got a response from the server: 200 OK
Notarization complete!
Notarization completed successfully!
The attestation has been written to `example-json.attestation.tlsn` and the corresponding secrets to `example-json.secrets.tlsn`.
This step creates a verifiable presentation with optional redactions, which can be shared with any verifier.
Run the present example:
cargo run --release --example attestation_present
If successful, you’ll see this output in the console:
Presentation built successfully!
The presentation has been written to `example-json.presentation.tlsn`.
You can create multiple presentations from the attestation and secrets in the notarization step, each with customized data redactions. You are invited to experiment!
This step reads the presentation created above, verifies it, and prints the disclosed data to the console.
Run the verify binary:
cargo run --release --example attestation_verify
Upon success, you should see output similar to:
Verifying presentation with {key algorithm} key: { hex encoded key }
**Ask yourself, do you trust this key?**
-------------------------------------------------------------------
Successfully verified that the data below came from a session with test-server.io at { time }.
Note that the data which the Prover chose not to disclose are shown as X.
Data sent:
...
In the example above, we notarized a JSON response. TLSNotary also supports notarizing HTML content. To run an HTML example, use:
# notarize
SERVER_PORT=4000 cargo run --release --example attestation_prove -- html
# present
cargo run --release --example attestation_present -- html
# verify
cargo run --release --example attestation_verify -- html
The examples above demonstrate how to use TLSNotary with publicly accessible data. TLSNotary can also be utilized for private data that requires authentication. To access this data, you can add the necessary headers (such as an authentication token) or cookies to your request. To run an example that uses an authentication token, execute the following command:
# notarize
SERVER_PORT=4000 cargo run --release --example attestation_prove -- authenticated
# present
cargo run --release --example attestation_present -- authenticated
# verify
cargo run --release --example attestation_verify -- authenticated