mirror of
https://github.com/tlsnotary/tlsn-js.git
synced 2026-01-09 20:47:55 -05:00
interactive verifier typescript: readme + cleanup
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
# 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 MPC-TLS session and then confirming the correctness of the data.
|
||||
|
||||
In this example, the Verifier connects to <https://swapi.dev> and proves data to the verifier.
|
||||
|
||||
# Run example on a single computer
|
||||
|
||||
You can run both the verifier and prover with:
|
||||
```sh
|
||||
cargo run -release --example interactive_networked
|
||||
```
|
||||
|
||||
# Run example on two different computers
|
||||
|
||||
To run the example on two different computers, start the verifier first on machine 1:
|
||||
```sh
|
||||
cd verifier
|
||||
cargo run --release
|
||||
```
|
||||
Note: make sure port `9816` is open if you run a firewall.
|
||||
|
||||
Next, on machine 2:
|
||||
1. Update the (ip address of the verifier on machine 1)[file:./prover/src/main.rs]
|
||||
2. Run:
|
||||
```sh
|
||||
cd prover
|
||||
cargo run --release
|
||||
```
|
||||
@@ -1,76 +0,0 @@
|
||||
use std::{
|
||||
io::{BufRead, BufReader},
|
||||
path::Path,
|
||||
process::{Child, Command, Stdio},
|
||||
thread,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
let examples_folder = Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||
let verifier_dir = examples_folder.join(Path::new("interactive-networked/verifier"));
|
||||
let prover_dir = examples_folder.join(Path::new("interactive-networked/prover"));
|
||||
|
||||
const SLEEP_TIME_SECS: u64 = 2; // allow the verifier some extra seconds to start and stop
|
||||
|
||||
// Run the verifier in the background
|
||||
println!("Starting the verifier...");
|
||||
let mut verifier = run(&verifier_dir, "cargo", &["run", "--release"], "VERIFIER")?;
|
||||
|
||||
// Allow the verifier some time to start
|
||||
thread::sleep(Duration::from_secs(SLEEP_TIME_SECS));
|
||||
|
||||
// Run the prover in the foreground
|
||||
println!("Starting the prover...");
|
||||
let prover_status = run(&prover_dir, "cargo", &["run", "--release"], "PROVER")?.wait()?;
|
||||
|
||||
if prover_status.success() {
|
||||
println!("Prover finished successfully.");
|
||||
} else {
|
||||
eprintln!("Prover finished with errors.");
|
||||
}
|
||||
|
||||
// Allow the verifier some time to finish the verification
|
||||
thread::sleep(Duration::from_secs(SLEEP_TIME_SECS));
|
||||
|
||||
// Stop the verifier after the prover finishes
|
||||
println!("Stopping the verifier...");
|
||||
verifier.kill()?;
|
||||
println!("Verifier stopped. Script finished.");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn run(working_dir: &Path, cmd: &str, args: &[&str], prefix: &str) -> std::io::Result<Child> {
|
||||
let mut process = Command::new(cmd)
|
||||
.args(args)
|
||||
.current_dir(working_dir)
|
||||
.stdout(Stdio::piped()) // Capture stdout
|
||||
.stderr(Stdio::piped()) // Capture stderr
|
||||
.spawn()?;
|
||||
|
||||
// Helper function to handle reading from a stream and prefixing its output
|
||||
fn handle_output<R: std::io::Read + Send + 'static, F>(stream: R, prefix: String, print_fn: F)
|
||||
where
|
||||
F: Fn(String) + Send + 'static,
|
||||
{
|
||||
thread::spawn(move || {
|
||||
BufReader::new(stream)
|
||||
.lines()
|
||||
.map_while(Result::ok)
|
||||
.for_each(|line| print_fn(format!("[{}] {}", prefix, line)));
|
||||
});
|
||||
}
|
||||
|
||||
// Prefix stdout
|
||||
if let Some(stdout) = process.stdout.take() {
|
||||
handle_output(stdout, prefix.to_string(), |line| println!("{}", line));
|
||||
}
|
||||
|
||||
// Prefix stderr
|
||||
if let Some(stderr) = process.stderr.take() {
|
||||
handle_output(stderr, prefix.to_string(), |line| eprintln!("{}", line));
|
||||
}
|
||||
|
||||
Ok(process)
|
||||
}
|
||||
@@ -19,7 +19,6 @@ root.render(<App />);
|
||||
function App(): ReactElement {
|
||||
const [processing, setProcessing] = useState(false);
|
||||
const [result, setResult] = useState<String | null>(null);
|
||||
const [proofHex, setProofHex] = useState<null | string>(null);
|
||||
|
||||
const onClick = useCallback(async () => {
|
||||
setProcessing(true);
|
||||
@@ -99,8 +98,7 @@ function App(): ReactElement {
|
||||
<div>
|
||||
<h1>TLSNotary interactive prover demo</h1>
|
||||
<div>
|
||||
Before clicking the start button, make sure the <i>interactive verifier</i> is running: <pre>cd interactive-demo/verifier; cargo run --release</pre>
|
||||
You also need a websocket proxy.
|
||||
Before clicking the start button, make sure the <i>interactive verifier</i> and the <i>web socket proxy</i> are running. Check the README for the details.
|
||||
</div>
|
||||
|
||||
<br />
|
||||
|
||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -9,7 +9,7 @@
|
||||
"version": "0.1.0-alpha.7.1",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"tlsn-wasm": "0.1.0-alpha.7.2"
|
||||
"tlsn-wasm": "^0.1.0-alpha.7.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/expect": "^24.3.0",
|
||||
|
||||
Reference in New Issue
Block a user