1
- import React , {
2
- ReactElement ,
3
- ReactNode ,
4
- useCallback ,
5
- useEffect ,
6
- useState ,
7
- } from 'react' ;
1
+ import React , { ReactElement , useCallback , useEffect , useState } from 'react' ;
8
2
import { createRoot } from 'react-dom/client' ;
9
3
import * as Comlink from 'comlink' ;
10
4
import {
11
5
Prover as TProver ,
12
6
Verifier as TVerifier ,
13
- Presentation as TPresentation ,
14
7
Commit ,
15
- NotaryServer ,
16
8
Transcript ,
17
9
} from 'tlsn-js' ;
18
- import { PresentationJSON } from 'tlsn-js/build/types' ;
19
10
import './app.scss' ;
11
+ import WebscoketStream from './stream' ;
20
12
21
- const { init, Prover, Presentation , Verifier } : any = Comlink . wrap (
13
+ const { init, Prover, Verifier } : any = Comlink . wrap (
22
14
new Worker ( new URL ( './worker.ts' , import . meta. url ) ) ,
23
15
) ;
24
16
@@ -43,6 +35,37 @@ function App(): ReactElement {
43
35
} ) ( ) ;
44
36
} , [ ] ) ;
45
37
38
+ useEffect ( ( ) => {
39
+ ( async ( ) => {
40
+ // Set up stream for prover
41
+ ( async ( ) => {
42
+ const proverStream = new WebscoketStream (
43
+ 'ws://localhost:3001?id=prover' ,
44
+ ) ;
45
+ const reader = await proverStream . reader ( ) ;
46
+ while ( true ) {
47
+ const { done, value } = await reader . read ( ) ;
48
+ if ( done ) {
49
+ console . log ( 'stream finished' ) ;
50
+ break ;
51
+ }
52
+ console . log ( `Received data from stream:` , await value . text ( ) ) ;
53
+ }
54
+ } ) ( ) ;
55
+
56
+ // Set up stream for verifier
57
+ ( async ( ) => {
58
+ const verifierStream = new WebscoketStream (
59
+ 'ws://localhost:3001?id=verifier' ,
60
+ ) ;
61
+ const writer = await verifierStream . writer ( ) ;
62
+ writer . write ( 'Hello' ) ;
63
+ writer . write ( 'World!' ) ;
64
+ writer . close ( ) ;
65
+ } ) ( ) ;
66
+ } ) ( ) ;
67
+ } , [ ] ) ;
68
+
46
69
const addProverLog = useCallback ( ( log : string ) => {
47
70
pLogs = pLogs . concat ( `${ new Date ( ) . toLocaleTimeString ( ) } - ${ log } ` ) ;
48
71
setProverMessages ( pLogs ) ;
@@ -102,7 +125,7 @@ function App(): ReactElement {
102
125
} ) ;
103
126
addProverLog ( 'request sent' ) ;
104
127
const transcript = await prover . transcript ( ) ;
105
- console . log ( transcript ) ;
128
+
106
129
addProverLog ( 'response received' ) ;
107
130
addProverLog ( 'transcript.sent' ) ;
108
131
addProverLog ( transcript . sent ) ;
0 commit comments