Skip to content

Commit

Permalink
eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
heeckhau committed Oct 29, 2024
1 parent 8556ffc commit cb42b49
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions interactive-demo/prover-ts/app.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import React, { ReactElement, useCallback, useEffect, useState } from 'react';
import React, { ReactElement, useCallback, useState } from 'react';
import { createRoot } from 'react-dom/client';
import * as Comlink from 'comlink';
import { Watch } from 'react-loader-spinner';
import {
Prover as TProver,
} from 'tlsn-js';
import { Prover as TProver } from 'tlsn-js';
import { type Method } from 'tlsn-wasm';

const { init, Prover, NotarizedSession, TlsProof }: any = Comlink.wrap(
const { init, Prover }: any = Comlink.wrap(
new Worker(new URL('./worker.ts', import.meta.url)),
);

Expand All @@ -18,45 +16,46 @@ root.render(<App />);

function App(): ReactElement {
const [processing, setProcessing] = useState(false);
const [result, setResult] = useState<String | null>(null);
const [result, setResult] = useState<string | null>(null);

const onClick = useCallback(async () => {
setProcessing(true);

let url = "https://swapi.dev/api/people/1";
let method: Method = 'GET';
let headers = {
'secret': "TLSNotary's private key",
const url = 'https://swapi.dev/api/people/1';
const method: Method = 'GET';
const headers = {
secret: "TLSNotary's private key",
'Content-Type': 'application/json',
};
let body = {};
const body = {};
// let websocketProxyUrl = 'wss://notary.pse.dev/proxy';
let websocketProxyUrl = 'ws://localhost:55688';
let verifierProxyUrl = 'ws://localhost:9816/verify';
const websocketProxyUrl = 'ws://localhost:55688';
const verifierProxyUrl = 'ws://localhost:9816/verify';
const hostname = new URL(url).hostname;

console.time('setup');

await init({ loggingLevel: 'Info' });

console.log("Setting up Prover for", hostname)
const prover = await new Prover({ serverDns: hostname }) as TProver;
console.log("Setting up Prover: 1/2")
console.log('Setting up Prover for', hostname);
const prover = (await new Prover({ serverDns: hostname })) as TProver;
console.log('Setting up Prover: 1/2');
await prover.setup(verifierProxyUrl);
console.log("Setting up Prover: done")
console.log('Setting up Prover: done');

console.timeEnd('setup');

console.time('request');
console.log("Sending request to proxy")
console.log('Sending request to proxy');
const resp = await prover.sendRequest(
`${websocketProxyUrl}?token=${hostname}`, { url, method, headers, body, }
`${websocketProxyUrl}?token=${hostname}`,
{ url, method, headers, body },
);
console.log("Response:", resp);
console.log('Response:', resp);

console.log("Wait for transcript")
console.log('Wait for transcript');
const transcript = await prover.transcript();
console.log("Transcript:", transcript);
console.log('Transcript:', transcript);

console.timeEnd('request');

Expand All @@ -81,15 +80,18 @@ function App(): ReactElement {
...transcript.ranges.recv.lineBreaks,
],
};
console.log("Start reveal:", reveal);
console.log('Start reveal:', reveal);
await prover.reveal(reveal);
console.timeEnd('reveal');

console.log("Ready");
console.log('Ready');

console.log("Unredacted data:", { sent: transcript.sent, received: transcript.recv })
console.log('Unredacted data:', {
sent: transcript.sent,
received: transcript.recv,
});

setResult("Unredacted data successfully revealed to Verifier.");
setResult('Unredacted data successfully revealed to Verifier.');

setProcessing(false);
}, [setResult, setProcessing]);
Expand All @@ -98,7 +100,9 @@ function App(): ReactElement {
<div>
<h1>TLSNotary interactive prover demo</h1>
<div>
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.
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 />
Expand Down

0 comments on commit cb42b49

Please sign in to comment.