mirror of
https://github.com/tlsnotary/tlsn-js.git
synced 2026-04-02 03:00:18 -04:00
* fix(wasm): change commit_sent to commit_recv * fix: fix tests (alpha4) * test: Test redactions * fix: skip puppeteer chrome install * chore: fix linter --------- Co-authored-by: Hendrik Eeckhaut <hendrik@eeckhaut.org>
89 lines
2.2 KiB
TypeScript
89 lines
2.2 KiB
TypeScript
import React, { ReactElement, useCallback, useEffect, useState } from 'react';
|
|
import { createRoot } from 'react-dom/client';
|
|
import { prove, verify } from 'tlsn-js';
|
|
import { Proof } from 'tlsn-js/build/types';
|
|
import { Watch } from 'react-loader-spinner';
|
|
|
|
const container = document.getElementById('root');
|
|
const root = createRoot(container!);
|
|
|
|
root.render(<App />);
|
|
|
|
function App(): ReactElement {
|
|
const [processing, setProcessing] = useState(false);
|
|
const [result, setResult] = useState<{
|
|
time: number;
|
|
sent: string;
|
|
recv: string;
|
|
notaryUrl: string;
|
|
} | null>(null);
|
|
const [proof, setProof] = useState<Proof | null>(null);
|
|
|
|
const onClick = useCallback(async () => {
|
|
setProcessing(true);
|
|
const p = await prove('https://swapi.dev/api/people/1', {
|
|
method: 'GET',
|
|
maxTranscriptSize: 16384,
|
|
notaryUrl: 'http://localhost:7047',
|
|
websocketProxyUrl: 'ws://localhost:55688',
|
|
});
|
|
setProof(p);
|
|
}, [setProof, setProcessing]);
|
|
|
|
useEffect(() => {
|
|
(async () => {
|
|
if (proof) {
|
|
const r = await verify(proof);
|
|
setResult(r);
|
|
setProcessing(false);
|
|
}
|
|
})();
|
|
}, [proof, setResult]);
|
|
|
|
return (
|
|
<div>
|
|
<button onClick={!processing ? onClick : undefined} disabled={processing}>
|
|
Start demo
|
|
</button>
|
|
<div>
|
|
<b>Proof: </b>
|
|
{!processing && !proof ? (
|
|
<i>not started</i>
|
|
) : !proof ? (
|
|
<>
|
|
Proving data from swapi...
|
|
<Watch
|
|
visible={true}
|
|
height="40"
|
|
width="40"
|
|
radius="48"
|
|
color="#000000"
|
|
ariaLabel="watch-loading"
|
|
wrapperStyle={{}}
|
|
wrapperClass=""
|
|
/>
|
|
Open <i>Developer tools</i> to follow progress
|
|
</>
|
|
) : (
|
|
<>
|
|
<details>
|
|
<summary>View Proof</summary>
|
|
<pre>{JSON.stringify(proof, null, 2)}</pre>
|
|
</details>
|
|
</>
|
|
)}
|
|
</div>
|
|
<div>
|
|
<b>Verification: </b>
|
|
{!proof ? (
|
|
<i>not started</i>
|
|
) : !result ? (
|
|
<i>verifying</i>
|
|
) : (
|
|
<pre>{JSON.stringify(result, null, 2)}</pre>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|